#include<iostream>
#include<sstream>
#include<fstream>
#include<map>
#include<vector>
#include<stdio.h>
#include <queue>

using namespace std;

int main(int argc,char** argv){
  const long del=100;
  const int okno=77;
  const int kontext=3;
  long sek=0;
  long d=1;
  for(int t=0;t<kontext;t++) d=d*4;
  queue<char> f1;
  queue<char> f2;
  const int poc_stavov=19;
  long frek[4];
  for(int i=0;i<4;i++) frek[i]=0;
  ifstream subor1(argv[1], ifstream::in);//subor so sekvenciou
  ifstream subor2(argv[2], ifstream::in);//subor s DNA abecedou
  map<char,int> abeceda;
  char z;
  int c;
  while(subor2 >> z >> c) abeceda.insert(make_pair(z,c));
  priority_queue<double> priemery[poc_stavov][d][4];
  priority_queue<double> prechody[poc_stavov][poc_stavov];
  double pocty[poc_stavov];
  double poctyr[d][poc_stavov];
  double sumy[poc_stavov][d][4];
  double stavy[poc_stavov][poc_stavov];
  for(int i=0;i<poc_stavov;i++){
    pocty[i]=0;
    for(long s=0;s<d;s++){
      poctyr[s][i]=0;
    for(int pis=0;pis<4;pis++){
      sumy[i][s][pis]=0; 
      priemery[i][s][pis].push(0.25);
      priemery[i][s][pis].pop();
    }
    }
    //pocty[i]=0;
    for(int j=0;j<poc_stavov;j++){
      stavy[i][j]=0;
      prechody[i][j].push(1.0/poc_stavov);
       prechody[i][j].pop();
    }
  
  }
 
  
  int predch=0;
  string zahod;
  char c1;
  
  cerr << "kontrola 1" << endl;
  for(int i=0;i<okno;i++){/*nalavo bude 49, napravo 50
    sprava vezmeme priradime stavu a supneme dolava
    */
    subor1 >> c1;
    if (c1=='>') {
      subor1 >> zahod;
      subor1 >> c1;
    }
    f1.push(c1);
    frek[abeceda[c1]]++;
    sek=(sek*4+abeceda[c1])%d;
  }
  cerr << "kontrola 2" << endl; 
  for(int i=0;i<okno;i++){
    subor1 >> c1;
    if (c1=='>') {
      subor1 >> zahod;
      subor1 >> c1;
    }
    f2.push(c1);
    frek[abeceda[c1]]++;
    sek=(sek*4+abeceda[c1])%d;
  }
  cerr  << frek[abeceda['a']] << " " << frek[abeceda['t']] << " " << frek[abeceda['g']] << " " << frek[abeceda['c']]<< endl;
  cerr << "kontrola 3" << endl; 
  while((subor1 >> c1)){
    if (c1=='>') {
      subor1 >> zahod;
    }//zahodi riadok
    else{
      f1.push(c1);//vlozis do fronty
      sek=(sek*4+abeceda[c1])%d;
      char q=f1.front();//vyberies z fronty
      f1.pop();
      int stav=0;
      char b=f2.front();
      frek[abeceda[b]]--;
      frek[abeceda[c1]]++;
      //   cerr << frek[abeceda['a']] << " " << frek[abeceda['t']] << " " << frek[abeceda['g']] << " " << frek[abeceda['c']]<< endl;
      f2.pop();
      f2.push(q);
      double pomer=((1.0*(frek[abeceda['g']]+frek[abeceda['c']]))/(1.0*(frek[abeceda['a']]+frek[abeceda['t']]+frek[abeceda['g']]+frek[abeceda['c']])));//spocitas pomer
      if(pomer>0.5){
      if(pomer>0.1){
	if(pomer>0.15){
	if(pomer>0.2){
	  if(pomer>0.25){
	  if(pomer>0.3){
	    if(pomer>0.35){
	    if(pomer>0.4){
	      if(pomer>0.45){
	      if(pomer>0.5){
		if(pomer>0.55){
		if(pomer>0.6){
		  if(pomer>0.65){
		  if(pomer>0.7){
		    if(pomer>0.75){
		    if(pomer>0.8){
		      if(pomer>0.85){
		      if(pomer>0.9){
			if(pomer>0.95){
			
			stav=19;
		      }
		      stav=18;
		      }
		      else
			stav=17;
		      }
		      else
			stav=16;
		      }
		      else
			stav=15;
		      }
		      else
			stav=14;
		      }
		      else
			stav=13;
		      }
		      else
			stav=12;
		      }
		      else
			stav=11;
		      }
		      else
			stav=10;
		      }
		      
		      
			
		      else
			stav=9;
		    }
		    else
		      stav=8;
		  }
		  else
		    stav=7;
		}else
		  stav=6;}
		  else
		    stav=5;}
		    else
		      stav=4;}
		      else
			stav=3;}
			else stav=2;}
			else stav=1;
			//cerr << "aha" << pomer << endl;
      }
      
      //cerr << "lalaho papluha" << endl;
    //nastavis stav
    // cerr << pomer << " hu " << stav << " " << frek[abeceda['a']] << " " << frek[abeceda['t']] << " " << frek[abeceda['g']] << " " << frek[abeceda['c']]<< endl;
    if(pocty[stav]>del-1){       
      /*for(long s=0;s<d;s++){
      for(int j=0;j<4;j++){
	
	priemery[stav][s][j].push(sumy[stav][s][j]/poctyr[s][stav]);
	sumy[stav][s][j]=0;
	}
	poctyr[s][stav]=0;
      }*/
      
      for(int i=0;i<poc_stavov;i++){
	//if((i==1)&&((stavy[stav][i]/pocty[stav])!=0)) cerr << "dsaswed" << endl;
	prechody[stav][i].push(stavy[stav][i]/pocty[stav]);
	stavy[stav][i]=0;
      }
      pocty[stav]=0;
    }
    
    if(poctyr[sek][stav]>del-1){       

      for(int j=0;j<4;j++){
	
	priemery[stav][sek][j].push(sumy[stav][sek][j]/poctyr[sek][stav]);
	sumy[stav][sek][j]=0;
	}
	poctyr[sek][stav]=0;
      
    }
    
    
    sumy[stav][sek][abeceda[q]]++;
    stavy[predch][stav]++;
    predch=stav;
    pocty[stav]++;
    poctyr[sek][stav]++;
    // cerr << b << " " << q << " " << c1 << endl; 
  }
  
}
cerr << "kontrola 4" << endl;  
cout << poc_stavov << " " << 4 << " " << 1 << endl;
cout << 1.0;
for(int i=1;i<poc_stavov;i++) cout << " " << 0.0;
cout << endl;

 //if (!prechody[0][1].empty()) cerr  <<" jsdc" << endl;

for(int stav=0;stav<poc_stavov;stav++){
 // if (stavy[stav][1]>0) cerr << stav <<" jsdc" << endl;
  //   cerr << stav << endl;
  cout << endl;
  bool t=false;
  for(int i=0;i<poc_stavov;i++){
  if (!prechody[stav][i].empty()){ 
    
    t=true;} else cerr << stav << " " << i << " k   ";
  }
//  cerr << endl;
 // cerr << stav << " s " << pocty[stav] << endl;
  if((pocty[stav]>0)||t){
    for(int i=0;i<poc_stavov;i++){
      // cerr << "stav " << stav << " i " << i << endl;
      double poc=0;
      double sum=0;
      
      if(pocty[stav]>0) prechody[stav][i].push(stavy[stav][i]/del);
      poc=poc+pocty[stav]/del;
      if(prechody[stav][i].empty()) sum=0; 
      else{ sum=prechody[stav][i].top();
      prechody[stav][i].pop();}
      while(!prechody[stav][i].empty()) {
	double pom=prechody[stav][i].top();
	prechody[stav][i].pop();
	prechody[stav][i].push(sum+pom);
	sum=prechody[stav][i].top();
	prechody[stav][i].pop();
	poc=poc+1;	  
	//if((i==1)&&(sum>0)) cerr << stav << " " << sum << endl;
      }
      cerr << stav << " " << i << "  p " << poc << " "<< sum << endl;  
      if(poc>0){sum=sum/poc;}else sum=0;
      printf("%f  ", sum);
    }
    cout << endl;}
    else for(int j=0;j<poc_stavov;j++) cout << 1.0/poc_stavov << " ";
    cout << endl;
}


//cerr << "kontrola 5" << endl;  

cerr << endl << endl << endl;

for(int stav=0;stav<poc_stavov;stav++){
  cout << kontext << endl;
  
  
  for(long s=0;s<d;s++){
    bool t=false;
  for(int pis=0;pis<4;pis++){
    if (!priemery[stav][s][pis].empty()) t=true;
  }
  if (t){
    
    for(int pis=0;pis<4;pis++){
      double poc=0;
      double sum=0;
      priemery[stav][s][pis].push(sumy[stav][s][pis]/del);
      //cerr << stav << " " << pis << " " << sumy[stav][pis] << endl;
      poc=poc+poctyr[s][stav]/del;
      if (priemery[stav][s][pis].empty())  sum=0; else {sum=priemery[stav][s][pis].top();
      priemery[stav][s][pis].pop();}
      while(!priemery[stav][s][pis].empty()) {
	double pom=priemery[stav][s][pis].top();
	// cerr << pom << " l"<<endl;
	priemery[stav][s][pis].pop();
	priemery[stav][s][pis].push(sum+pom);
	sum=priemery[stav][s][pis].top();
	priemery[stav][s][pis].pop();
	poc=poc+1;
      }
      cerr << "p2 " << poc << " "<< sum << endl;  
      if(poc>0)sum=sum/poc;else sum=0;
      printf(" %f ", double(sum));
      cerr << stav << " " << s << " " << pis << "     " << poc << endl;
      
    }
    cout << endl;
    cerr <<  endl;
    
    
  } else cout << 0.25 << " " << 0.25 << " " << 0.25 << " " << 0.25 << endl;
  }
  cerr << endl << endl << endl;
  cout << endl << endl;
}



return 0;
}


