Problem:
Kanglish : Analysis on Artificial Language
The late Prof. Kanazawa made an artificial language named Kanglish, which is 
similar to English, for studying mythology. Words and sentences of Kanglish are 
written with its own special characters called "Kan-characters". The size of the 
set of the Kan-characters is 38, i.e., there are 38 different Kan-characters in 
the set. Since Kan-characters cannot be directly stored in a computer because of 
the lack of a coded character set, Prof. Kanazawa devised a way to represent 
each Kan-character as an alphabetical letter or an ordered combination of two 
alphabetical letters. Thus, each Kan-character is represented as one of the 
following 26 letters
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 
  "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", and "z",
or one of the following 12 combinations of letters
"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", 
  and "ts".
In addition, the Kan-characters are ordered according to  
the above alphabetical representation. The order is named Kan-order in which the  
Kan-character represented by "a" is the first one, that by "b" is the second,  
that by "z" is the 26th, that by "ld" is the 27th, and that by "ts" is the 38th  
(the last).
The representations of words in Kanglish are separated by spaces. Each 
sentence is written in one line, so there are no periods or full stops in 
Kanglish. All alphabetical letters are in lower case, i.e., there are no 
capitalizations.
We currently have many documents written in Kanglish with the alphabetical 
representation. However, we have lost most of Prof. Kanazawa's work on how they 
can be translated. To recognize his work, we have decided to first analyze them 
statistically. The first analysis is to check sequences of consecutive 
Kan-characters in words.
For example, a substring "ic" in a word "quice" indicates an ordered pair of 
two adjacent Kan-characters that are represented by "i" and "c". For simplicity, 
we make a rule that, in the alphabetical representation of a word, a 
Kan-character is recognized as the longest possible alphabetical representation 
from left to right. Thus, a substring "ncw" should be considered as a pair of 
"nc" and "w". It does not consist of "n" and "cw", nor "n", "c", and "w".
For each Kan-character, there are 38 possible pairs of that Kan-character and 
another Kan-character, e.g. "aa", "ab", ..., "az", "ald", ..., "ats". Thus, 
mathematically, there is a total of 1444 (i.e., 38x38) possible pairs, including 
pairs such as "n" and "cw", which is actually not allowed according to the above 
rule.
Your job is to write a program that counts how many times each pair occurs in 
input data. For example, in the sentence
qua ist qda quang quice
the Kan-character represented by "qu" appears  
three times. There are two occurrences of the pair of "qu" and "a", and one  
occurrence of the pair of "qu" and "i". Note that the alphabetical letter "q"  
ap
...(truncated)

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<string> kan{
    "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
    "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
    "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts",
};

int main(){
    int n;
    cin >> n;
    vector<vector<int>> freq(kan.size(), vector<int>(kan.size(), 0));
    string s;
    while(cin >> s){
        int prev = -1;
        int p = 0;
        int idx = -1;
        while(p < (int)s.length()){
            for(int i=0; i<(int)kan.size(); i++){
                if(p +(int)kan[i].length() <= (int)s.length()
                        and s.substr(p, kan[i].length()) == kan[i]){
                    idx = i;
                }
            }
            if(prev != -1){
                freq[prev][idx]++;
            }
            p += kan[idx].length();
            prev = idx;
        }
    }
    for(int i=0; i<(int)kan.size(); i++){
        int idx = 0;
        for(int j=0; j<(int)kan.size(); j++){
            if(freq[i][j] > freq[i][idx]){
                idx = j;
            }
        }
        cout << kan[i] << " " << kan[idx] << " " << freq[i][idx] << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 3212
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

vector<string> split(string &str) {
    int prev = 0;
    vector<string> ans;
    for (int i = 0; i < str.size(); i++) {
	if (str[i] == ' ') {
	    ans.push_back(str.substr(prev, i - prev));
	    prev = i + 1;
	}
    }
    return ans;
}

string kanglish[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};


int main() {
    int n;
    cin >> n;
    vector<string> vec;
    string com = "";
    for (int i = 0; i < n;) {
	string str;
	getline(cin, str);
	if (str.size() == 0) continue;
	i++;
	if (com.size() && com[com.size() - 1] != ' ') {
	    com += " ";
	}
	com += str;
    }
    com += " ";
    vec = split(com);
    
    map<string, map<string, int>> cnt;
    for (auto str: vec) {
	int index = 0;
	vector<string> slist;
	while (index < str.size()) {
	    int nxt = index + 1;
	    for (auto kang: kanglish) {
		if (str.substr(index, kang.size()) == kang) {
		    nxt = index + kang.size();
		}
	    }
	    string word = str.substr(index, nxt - index);
	    slist.push_back(word);
	    index = nxt;
	}
	for (int i = 0; i < slist.size() - 1; i++) {
	    cnt[slist[i]][slist[i + 1]]++;
	}
    }
    for (auto &s1: kanglish) {
	int mx = -1;
	string ans = "";
	for (auto &s2: kanglish) {
	    if (cnt[s1][s2] > mx) {
		mx = cnt[s1][s2];
		ans = s2;
	    }
	}
	cout << s1 << " " << ans << " " << mx << endl;
    }
    
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3480
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
 
int main(){
  int n,slen;
  string s,d[38]={
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
    "u","v","w","x","y","z","ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"
  };
  map<P,int> m;
  vector<int> v;
  cin>>n;
  for(int i=0;i<38;i++)
    for(int j=0;j<38;j++)
      m.insert(make_pair(P(i,j),0));
  while(cin>>s){
    slen=s.size();
    s+="#####";    
    for(int i=0;i<slen;i++){
      string subs=s.substr(i,2);
      int f=0,ind;
      for(int j=0;j<38;j++){
    if(j<26&&s[i]==d[j][0])ind=j;
    if(subs==d[j]){
      f=1;
      i++;
      v.push_back(j);
    }
      }
      if(!f)v.push_back(ind);
    }
    for(int i=0;i<v.size()-1;i++)
      m[P(v[i],v[i+1])]++;
    v.clear();
  }
  map<P,int>::iterator ite;
  int ans1=0,ans2=0,ansmax=m[P(0,0)];
  for(ite=m.begin();ite!=m.end();ite++){
    if(ans1!=(*ite).first.first){
      cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
      ans1++;
      if(ansmax<(*ite).second){
    ans2=(*ite).first.second;
    ansmax=(*ite).second;
      }
      ans2=0,ansmax=m[P(ans1,0)];
    }else{
      if(ansmax<(*ite).second){
    ans2=(*ite).first.second;
    ansmax=(*ite).second;
      }
    }
  }
  cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
  
  m.clear();
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1336
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
int n;
string s;
vector<int> t;
map<string,int> mp;
string A[12]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};
int cnt[50][50];

string change(int x){
  string res="a";
  if(x<26){
    res[0]+=x;
    return res;
  }else return A[x-26];
}

int main(){
  for(int i=0;i<12;i++)mp[A[i]]=26+i;
  cin>>n;

  while(cin>>s){
    n=s.size();
    vector<int> v;
    for(int i=0;i<n;i++){
      string tmp="";
      if(i+1<n)tmp=s.substr(i,2);
      if(mp[tmp]!=0){
        v.push_back(mp[tmp]);
        i++;
      }else{
        v.push_back(s[i]-'a');
      }
    }
    for(int i=0;i+1<(int)v.size();i++){
      
      cnt[v[i]][v[i+1]]++;
    }
    
  }
  
  for(int i=0;i<38;i++){
    int maxid=0;
    for(int j=0;j<38;j++){
      if(cnt[i][j]>cnt[i][maxid])maxid=j;
    }
    cout<<change(i)<<' '<<change(maxid)<<' '<<cnt[i][maxid]<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1288
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n,slen;
  string s,d[38]={
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t",
    "u","v","w","x","y","z","ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"
  };
  map<P,int> m;
  vector<int> v;
  cin>>n;
  for(int i=0;i<38;i++)
    for(int j=0;j<38;j++)
      m.insert(make_pair(P(i,j),0));
  while(cin>>s){
    slen=s.size();
    s+="#####";    
    for(int i=0;i<slen;i++){
      string subs=s.substr(i,2);
      int f=0,ind;
      for(int j=0;j<38;j++){
	if(j<26&&s[i]==d[j][0])ind=j;
	if(subs==d[j]){
	  f=1;
	  i++;
	  v.push_back(j);
	}
      }
      if(!f)v.push_back(ind);
    }
    for(int i=0;i<v.size()-1;i++)
      m[P(v[i],v[i+1])]++;
    v.clear();
  }
  map<P,int>::iterator ite;
  int ans1=0,ans2=0,ansmax=m[P(0,0)];
  for(ite=m.begin();ite!=m.end();ite++){
    if(ans1!=(*ite).first.first){
      cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
      ans1++;
      if(ansmax<(*ite).second){
	ans2=(*ite).first.second;
	ansmax=(*ite).second;
      }
      ans2=0,ansmax=m[P(ans1,0)];
    }else{
      if(ansmax<(*ite).second){
	ans2=(*ite).first.second;
	ansmax=(*ite).second;
      }
    }
  }
  cout<<d[ans1]<<' '<<d[ans2]<<' '<<ansmax<<endl;
 
  m.clear();
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1340
final_rank: 9

code_snippet: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <vector>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for(auto i = (c).begin(); i != (c).end(); ++i)
#define BIT(n, m) (((n) >> (m)) & 1)

typedef long long ll;
typedef pair<int, int> PI;

const ll inf = 1e15;
const ll mod = 1000 * 1000 * 1000 + 7;
const double eps = 1e-9;

template <typename S, typename T> ostream &operator<<(ostream &out, const pair<S, T> &p) {
  out << "(" << p.first << ", " << p.second << ")";
  return out;
}

template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) {
  out << "[";
  REP(i, v.size()){
    if (i > 0) out << ", ";
    out << v[i];
  }
  out << "]";
  return out;
}



int main(){
  vector<string> alphabets;
  REP(i, 26) alphabets.push_back(string(1, 'a' + i));
  alphabets.push_back("ld");
  alphabets.push_back("mb");
  alphabets.push_back("mp");
  alphabets.push_back("nc");
  alphabets.push_back("nd");
  alphabets.push_back("ng");
  alphabets.push_back("nt");
  alphabets.push_back("nw");
  alphabets.push_back("ps");
  alphabets.push_back("qu");
  alphabets.push_back("cw");
  alphabets.push_back("ts");

  int n;
  string word;
  cin >> n; 
  map<int, int> counter[40];
  
  while (cin >> word){
    int p = 0;
    int m = word.size();
    vector<int> chs;
    while (p < m){
      string ch = string(1, word[p++]);
      if (p < m && find(ALL(alphabets), ch + word[p]) != alphabets.end()){
        ch += word[p++];
      }
      chs.push_back(find(ALL(alphabets), ch) - alphabets.begin());
    }
    REP(i, chs.size()){
      if (i > 0) counter[chs[i - 1]][chs[i]]++;
    }
  }
  
  REP(i, alphabets.size()){
    int ans = 0;
    REP(j, alphabets.size()) if (counter[i][j] > counter[i][ans]) ans = j;
    cout << alphabets[i] << " " << alphabets[ans] << " " << counter[i][ans] << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1312
final_rank: 6

code_snippet: #include <algorithm>
#include <cstdlib>
#include <iostream>
#include <sstream>
#include <unordered_map>
using namespace std;

string characters[38];

void init() {
	for(int i = 0; i < 26; ++i) {
		characters[i] = 'a' + i;
	}
	characters[26] = "ld";
	characters[27] = "mb";
	characters[28] = "mp";
	characters[29] = "nc";
	characters[30] = "nd";
	characters[31] = "ng";
	characters[32] = "nt";
	characters[33] = "nw";
	characters[34] = "ps";
	characters[35] = "qu";
	characters[36] = "cw";
	characters[37] = "ts";
}

string get_char(int &idx, const string &word) {
	if(idx + 1 < word.size()) {
		const string tmp = word.substr(idx, 2);
		if(find(begin(characters), end(characters), word.substr(idx, 2)) != end(characters)) {
			idx += 2;
			return tmp;
		}
	}

	return idx < word.size() ? string(1, word[idx++]) : "";
}

void calc_input(unordered_map<string, unordered_map<string, int>> &cnt) {
	string sentence;
	getline(cin, sentence);

	istringstream iss(sentence);
	for(string word; iss >> word;) {
		int idx = 0;
		string current = get_char(idx, word);
		string next;

		for(string next; (next = get_char(idx, word)) != "";) {
			++cnt[current][next];
			current = move(next);
		}
	}
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	init();

	int n;
	cin >> n;
	cin.ignore();

	unordered_map<string, unordered_map<string, int>> cnt;
	while(n--) calc_input(cnt);

	for(const auto &character : characters) {
		int max_cnt = 0;
		string max_char = "a";
		const auto &c_cnt = cnt[character];

		for(const auto &target : characters) {
			if(c_cnt.count(target) && max_cnt < c_cnt.at(target)) {
				max_cnt = c_cnt.at(target);
				max_char = target;
			}

		}

		cout << character << " " << max_char << " " << max_cnt << endl;
	}

	return EXIT_SUCCESS;
}
accuracy: 1
time_ms: 10
memory_kb: 1316
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <map>
#include <cctype>
#include <algorithm>
#include <set>
#include <cmath>
#include <cassert>

using namespace std;
string Kanglish[38];
string get_string(int &cur,string line){
  while(line[cur] == ' ') ++cur;

  string str;
  for(int j = 26;j < 38;j++){
	if(line[cur] == Kanglish[j][0] && line[cur+1] == Kanglish[j][1]){
	  cur+=2;
	  return Kanglish[j];
	}
  }
  for(int i = 0;i < 26;i++){
	if(line[cur] == Kanglish[i][0]){
	  cur++;
	  return Kanglish[i];
	}
  }	
  return " " ;
}


int main(){
  char tmp = 'a';
  for(int i = 0;i < 26;i++){
	Kanglish[i] = tmp++;
  }
  Kanglish[26]="ld";
  Kanglish[27]="mb";
  Kanglish[28]="mp";
  Kanglish[29]="nc";
  Kanglish[30]="nd";
  Kanglish[31]="ng";
  Kanglish[32]="nt";
  Kanglish[33]="nw";
  Kanglish[34]="ps";
  Kanglish[35]="qu";
  Kanglish[36]="cw";
  Kanglish[37]="ts";
  int n;
  cin >>n;
  cin.ignore();
  vector<map<string,int> > vec(38);
  for(int i =0;i < n;i++){
	string line;
	getline(cin,line);
	int cur = 0;
	string current = get_string(cur,line);
	const int len = line.size();
	line += "#";

	while(cur < len){
	  if(line[cur] == ' ') {
		current = get_string(cur, line);
		continue;
	  }
	  
	  string next = get_string(cur, line);
	  
	  for(int i =0 ;i < 38;i++){
		if(Kanglish[i] == current){
		  vec[i][next]++;
		  break;
		}
	  }
	
	  current = move(next);
	}
  }

  for(int i = 0;i < 38;i++){
	int max_number = 0;
	string max_str = "a";
	for(const auto &e:vec[i]){
	  if(e.second > max_number && e.first != " "){
		max_number = e.second;
		max_str = e.first;
	  }
	}
	cout << Kanglish[i] << " " << max_str << " " << max_number << endl;
  }
  
  
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1284
final_rank: 4

code_snippet: #include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
using namespace std;

const string kan[38] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};

int main() {
  int n;
  while(cin >> n) {
    cin.ignore();
    map<pair<int,int>, int> m;
    for(int i = 0; i < n; ++i) {
      string s;
      getline(cin, s);
      stringstream ss(s);
      while(ss >> s) {
        for(int j = 0, pre = -1; j < s.size(); ) {
          for(int k = 0; k < 38; ++k) {
            int nk = (k + 26) % 38;
            const string &t = kan[nk];
            if(s.substr(j, t.size()) == t) {
              j += t.size();
              if(pre != -1) {
                m[make_pair(pre, nk)] += 1;
              }
              pre = nk;
              break;
            }
          }
        }
      }
    }

    pair<int,int> maxi[38] = make_pair(0,0);
    for(map<pair<int,int>,int>::iterator it = m.begin();
        it != m.end(); ++it) {
      int a = it->first.first;
      int b = it->first.second;
      int c = it->second;
      maxi[a] = max(maxi[a], make_pair(c, -b));
    }
    for(int i = 0; i < 38; ++i) {
      cout << kan[i] << " " << kan[-maxi[i].second] << " " << maxi[i].first << endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1264
final_rank: 15

code_snippet: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<sstream>
#include<set>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)

using namespace std;
set<string> comb;
int T;
struct Kanglish
{
  vector<int> dict;
  Kanglish(){dict.resize(38,0);}
};


int getIndex(string s)
{
  if(s.size() == 1)return s[0]-'a';
  if(s == "ld")return 26;
  if(s == "mb")return 27;
  if(s == "mp")return 28;
  if(s == "nc")return 29;
  if(s == "nd")return 30;
  if(s == "ng")return 31;
  if(s == "nt")return 32;
  if(s == "nw")return 33;
  if(s == "ps")return 34;
  if(s == "qu")return 35;
  if(s == "cw")return 36;
  if(s == "ts")return 37;
  return -inf;
}

string toString(int index)
{
  if(0 <= index && index <= 25)return string(1,(char)('a'+index));
  if(index == 26)return "ld";
  if(index == 27)return "mb";
  if(index == 28)return "mp";
  if(index == 29)return "nc";
  if(index == 30)return "nd";
  if(index == 31)return "ng";
  if(index == 32)return "nt";
  if(index == 33)return "nw";
  if(index == 34)return "ps";
  if(index == 35)return "qu";
  if(index == 36)return "cw";
  if(index == 37)return "ts";
  assert(false);
}

void Convert(string *line)
{
  Kanglish vec[38];

  vector<string> sep;
  rep(i,T)
    {
      stringstream ss;
      ss << line[i];
      string s; 
      while(!(ss >> s).fail())
	{
	  int ssize = s.size();
	  rep(j,ssize)
	    {
	      if(j+1 < ssize && getIndex(s.substr(j,2)) != -inf)
		{
		  sep.push_back(s.substr(j,2));
		  j++;
		}
	      else 
		{
		  sep.push_back(s.substr(j,1));
		}
	    }
	  sep.push_back("$");
	}
    }
  rep(i,sep.size()-1)
    {
      //if(sep[i][0] == '$')cout << endl;
      //else cout << sep[i] << endl; 
      if(sep[i+1][0] == '$' || sep[i][0] == '$')continue;
      vec[getIndex(sep[i])].dict[getIndex(sep[i+1])]++;
    }

  //cout << "-----------" << endl;
  rep(i,38)
    {
      cout << toString(i) << " ";
      int p = 0;
      rep(j,vec[i].dict.size())
	{
	  if(vec[i].dict[p] < vec[i].dict[j])
	    {
	      p = j;
	    }
	}
      cout << toString(p) << " " << vec[i].dict[p] <<endl;
    }

}

int main()
{

  comb.insert("ld");
  comb.insert("mb");
  comb.insert("mp");
  comb.insert("nc");
  comb.insert("nd");
  comb.insert("ng");
  comb.insert("nt");
  comb.insert("nw");
  comb.insert("ps");
  comb.insert("qu");
  comb.insert("cw");
  comb.insert("ts");

  while(cin >> T)
    {
      cin.ignore();
      string line[T];
      rep(_,T)
	{
	  getline(cin,line[_]);
	}
      vector<Kanglish> vec[39];
      Convert(&line[0]);
    }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3652
final_rank: 17

code_snippet: #include<iostream>
#include<cstring>

using namespace std;

const int MAX = 40;

string kang[] = {"ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"};
int ans[MAX][MAX];

int kang2int(const string& s){
  // cout << " s " << s << endl;
  if(s.length()==1){
    char c = s[0];
    return c-'a';
  }
  for(int i = 0; i < 12; i++)
    if(s == kang[i]) return 27+i;

  return -1;
}

string int2kang(int n){
  if(n < 27){
    char c = 'a'+n;
    string s = "";
    s += c;
    return s;
  }
  return kang[n-27];
}

string getString(const string& s, int idx){
  if(kang2int(s.substr(idx,2)) != -1) return s.substr(idx,2);
  return s.substr(idx,1);
}

void solve(const string& s){

  int idx = 0;

  while(1){
    while(s[idx] == ' ') idx++;

    string s1 = getString(s,idx);
    idx += s1.length();

    if(idx >= (int)s.length()) break;
    if(s[idx] == ' ') continue;

    string s2 = getString(s,idx);
    // cout << s1 << " " << s2 << endl;
    // idx+=s2.length();
    ans[kang2int(s1)][kang2int(s2)]++;
  }

}

void print(){
  for(char c = 'a'; c <= 'z'; c++){
    string tmp = "";
    tmp += c;
    int pos = 0;
    int kpos = kang2int(tmp);
    for(int i = 0; i < MAX; i++) if(ans[kpos][pos] < ans[kpos][i]){pos = i;}
    cout << c << " " << int2kang(pos) << " " << ans[kpos][pos] << endl;
  }

  for(int i = 0; i < 12; i++){
    int kpos = kang2int(kang[i]);
    int pos = 0;
    for(int j = 0; j < MAX; j++) if(ans[kpos][pos] < ans[kpos][j]){pos = j;}
    cout << kang[i] << " " << int2kang(pos) << " " << ans[kpos][pos] << endl;
  }
}

int main(){

  
  memset(ans,0,sizeof(ans));
  int n;
  cin >> n;
  cin.ignore();
  while(n--){
    string s;
    getline(cin,s);
    solve(s);
  }
  print();
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 1220
final_rank: 10

code_snippet: //48
#include<iostream>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

string od(int x){
  if(x<26){
    return string(1,'a'+x);
  }else{
    string wc[]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};
    return wc[x-26];
  }
}

int main(){
  int n;
  cin>>n;
  cin.ignore();
  map<string,map<string,int> > m;
  while(n--){
    char l[60];
    cin.getline(l,60);
    string p;
    for(int i=0;l[i];){
      string c;
      string wc[]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};
      if(find(wc,wc+12,string(l+i,2))!=wc+12){
	c=string(l+i,2);
	i+=2;
      }else{
	c=l[i];
	i++;
      }
      if(p!=" "&&c!=" "){
	m[p][c]++;
      }
      p=c;
    }
  }
  for(int i=0;i<38;i++){
    string mf=string(1,'a');
    int c=0;
    for(int j=0;j<38;j++){
      if(m[od(i)][od(j)]>c){
	c=m[od(i)][od(j)];
	mf=od(j);
      }
    }
    cout<<od(i)<<' '<<mf<<' '<<c<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 1384
final_rank: 14

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <string,string> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;


static const string kang[] = {"a", "b", "c","d", "e", "f", "g", "h", "i","j", "k", "l","m","n", "o","p","q","r", "s","t", "u", "v", "w", "x", "y","z",
	"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};

int main(){
	string str;
	map<string,vector<string> > dubStr;
	dubStr["m"].push_back("mb");
	dubStr["m"].push_back("mp");

	dubStr["l"].push_back("ld");

	dubStr["n"].push_back("nc");
	dubStr["n"].push_back("nd");
	dubStr["n"].push_back("ng");
	dubStr["n"].push_back("nt");
	dubStr["n"].push_back("nw");

	dubStr["p"].push_back("ps");

	dubStr["q"].push_back("qu");

	dubStr["c"].push_back("cw");

	dubStr["t"].push_back("ts");

	int n;
	while(getline(cin,str)){

		n = atoi(str.c_str());

		map<P,int> kangPair;
		for(int line=0;line<n;line++){
			getline(cin,str);
			stringstream ss(str);
			while(ss >> str){
				map<string,int> freq;

				string prev = "";
				for(int s = 0; s<str.size();){

					string key = str.substr(s,1);
					string key2="";
					if(s<str.size()-1) key2 = str.substr(s,2);


					if(dubStr.find(key) != dubStr.end()){
						for(int i=0;i<dubStr[key].size();i++){
							if(key2 == dubStr[key][i]){

								if(prev != ""){
									kangPair[P(prev,key2)]++;
								}

								prev = key2;
								s+=2;
								goto next;
							}
						}

						if(prev != ""){
							kangPair[P(prev,key)]++;
						}
						prev = key;
						s+=1;
					}
					else{
						if(prev != ""){
							kangPair[P(prev,key)]++;
						}
						prev = key;
						s+=1;
					}
next:;
				}
			}
		}

		for(int i=0;i<38;i++){
			int maxv = 0;
			int to=0;
			for(int j=0;j<38;j++){
				map<P,int>::iterator it;
				if((it = kangPair.find(P(kang[i],kang[j]))) == kangPair.end()) continue;
				if(maxv < it->second){
					maxv = it->second;
					to = j;
				}
			}
			//cout << kang[i] << endl;
			if(maxv == 0) printf("%s %s %d\n",kang[i].c_str(),"a",0);
			else printf("%s %s %d\n",kang[i].c_str(),kang[to].c_str(),maxv);
		}
	}
}
accuracy: 1
time_ms: 30
memory_kb: 968
final_rank: 12

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <string,string> P;
typedef pair <int,P > PP;

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;


string kang[] = {"a", "b", "c","d", "e", "f", "g", "h", "i","j", "k", "l","m","n", "o","p","q","r", "s","t", "u", "v", "w", "x", "y","z",
	"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw","ts"};

int main(){
	string str;
	map<string,vector<string> > dubStr;
	dubStr["m"].push_back("mb");
	dubStr["m"].push_back("mp");

	dubStr["l"].push_back("ld");

	dubStr["n"].push_back("nc");
	dubStr["n"].push_back("nd");
	dubStr["n"].push_back("ng");
	dubStr["n"].push_back("nt");
	dubStr["n"].push_back("nw");

	dubStr["p"].push_back("ps");

	dubStr["q"].push_back("qu");

	dubStr["c"].push_back("cw");

	dubStr["t"].push_back("ts");

	int n;
	while(getline(cin,str)){

		n = atoi(str.c_str());

		map<P,int> kangPair;
		for(int line=0;line<n;line++){
			getline(cin,str);
			stringstream ss(str);
			while(ss >> str){
				map<string,int> freq;

				string prev = "";
				for(int s = 0; s<str.size();){

					string key = str.substr(s,1);
					string key2="";
					if(s<str.size()-1) key2 = str.substr(s,2);


					if(dubStr.find(key) != dubStr.end()){
						for(int i=0;i<dubStr[key].size();i++){
							if(key2 == dubStr[key][i]){

								if(prev != ""){
									kangPair[P(prev,key2)]++;
								}

								prev = key2;
								s+=2;
								goto next;
							}
						}

						if(prev != ""){
							kangPair[P(prev,key)]++;
						}
						prev = key;
						s+=1;
					}
					else{
						if(prev != ""){
							kangPair[P(prev,key)]++;
						}
						prev = key;
						s+=1;
					}
next:;
				}
			}
		}

		for(int i=0;i<38;i++){
			int maxv = 0;
			int to=0;
			for(int j=0;j<38;j++){
				map<P,int>::iterator it;
				if((it = kangPair.find(P(kang[i],kang[j]))) == kangPair.end()) continue;
				if(maxv < it->second){
					maxv = it->second;
					to = j;
				}
			}
			//cout << kang[i] << endl;
			if(maxv == 0) printf("%s %s %d\n",kang[i].c_str(),"a",0);
			else printf("%s %s %d\n",kang[i].c_str(),kang[to].c_str(),maxv);
		}
	}
}
accuracy: 1
time_ms: 30
memory_kb: 964
final_rank: 11

code_snippet: #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
string alphabet[] = {"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};
int toi(string s){
  if(s.size()==1){
    return s[0] -  'a';
  }else{
    REP(i,12)if(alphabet[i]==s)return 26 + i;
  }
  return -1;
}
string tos(int n){
  if(n < 0 || n >= 38) return "";
  string s = " ";
  if(n < 26) s[0] = 'a' + n;
  else s = alphabet[n-26];
  return s;
}

int main(){
  int n;
  cin>>n; cin.ignore();
  int cnt[38][38] = {};
  string s;
  while(getline(cin, s)){
    stringstream ss(s);
    string word;
    while(ss>>word){
      string prev = "";
      REP(i,word.size()){
        string s = "";
        s += word[i];
        if(i+1 < word.size() && toi(s + word[i+1]) != -1){
          s += word[++i];
        }
        if(prev != ""){
          cnt[toi(prev)][toi(s)]++;
        }
        prev = s;
      }
    }
  }
  REP(i,38){
    string from = tos(i);
    string to = "";
    int maxn = -1;
    REP(j,38)if(cnt[i][j]>maxn){
      to = tos(j);
      maxn = cnt[i][j];
    }
    printf("%s %s %d\n",from.c_str(), to.c_str(), maxn);
  }
  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 0
final_rank: 2

code_snippet: #include <iostream>
#include <string>
#include <algorithm>

using namespace std;

main(){
  int n;
  cin >> n;
  string in;
  int data[38][38];
  string kang[38];
  for(int i=0;i<26;i++){
    string tmp = "a";
    kang[i] = tmp[0] + i;
  }
  kang[26] = "ld";
  kang[27] = "mb";
  kang[28] = "mp";
  kang[29] = "nc";
  kang[30] = "nd";
  kang[31] = "ng";
  kang[32] = "nt";
  kang[33] = "nw";
  kang[34] = "ps";
  kang[35] = "qu";
  kang[36] = "cw";
  kang[37] = "ts";
  fill(data[0], data[38], 0);
  while(cin >> in){
    int a = -1;
    int p = 0;
    for(;;){
      int b = -1;
      for(int i=37;i>=0;i--){
        if((int)in.size()-p >= kang[i].size()){
          if(kang[i] == in.substr(p, kang[i].size())){
            b = i;
            p += kang[i].size();
            break;
          }
        }
      }
      if(b == -1) break;
      
      if(a != -1) data[a][b]++;
      a = b;
    }
  }
  for(int i=0;i<38;i++){
    cout << kang[i];
    int valM = -1;
    int idx;
    for(int j=0;j<38;j++){
      if(valM < data[i][j]){
        valM = data[i][j];
        idx = j;
      }
    }
    cout << ' ' << kang[idx] << ' ' << valM << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 896
final_rank: 18

code_snippet: #include<stdio.h>
#include<string.h>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct Cmp{bool operator()(const string&a, const string&b)
{
	if(a.size()-b.size())
		return a.size()<b.size();
	if(a=="cw")
		return b=="ts";
	if(b=="cw")
		return a!="ts";
	return a<b;
}};
string F(char c){string s;s+=c;return s;}
int main()
{
	typedef map<string,int,Cmp>M;
	typedef map<string,M,Cmp>MM;
	char str[512];
	MM mm;
	string kan[12]={"ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"}; 
	string s,t,u;
	vector<string>v;
	int i,j;
	for(scanf("%*d");~scanf("%s",str);)
	{
		s=str;
		v.clear();
		for(i=0;i<s.size();)
		{
			if(i+1<s.size()&&count(kan,kan+12,t=s.substr(i,2)))v.push_back(t),i+=2;
			else v.push_back(F(s[i])),++i;
		}
		for(i=0;i+1<v.size();++i)++mm[v[i]][v[i+1]];
	}
	string k[38];
	for(i=0;i<26;++i)k[i]=F(i+'a');
	for(i=0;i<12;++i)k[26+i]=kan[i];
	for(i=0;i<38;++i)
	{
		M&r=mm[k[i]];
		string a=F('a');
		int c=0;
		for(j=0;j<38;++j)
		{
			if(c<r[k[j]])
			{
				c=r[k[j]];
				a=k[j];
			}
		}
		printf("%s %s %d\n",k[i].c_str(),a.c_str(),c);
	}
}
accuracy: 1
time_ms: 40
memory_kb: 844
final_rank: 13

code_snippet: #include <iostream>
#include <vector>
#include <map>

using namespace std;

int main()
{
	string ls[]={"ld","mb","mp","nc","nd","ng","nt","nw","ps","qu","cw","ts"};
	int t[38][38]={};
	int n; cin>>n;
	for(string s;cin>>s;){
		vector<int> ws;
		for(int i=0;i<s.size();i++){
			bool two=false;
			for(int j=0;j<12;j++){
				if(s.substr(i,2)==ls[j]){
					ws.push_back(26+j);
					i++;
					two=true;
					break;
				}
			}
			if(!two)
				ws.push_back(s[i]-'a');
		}
		for(int i=1;i<ws.size();i++)
			t[ws[i-1]][ws[i]]++;
	}
	
	for(int i=0;i<38;i++){
		int j=0;
		for(int k=0;k<38;k++)
			if(t[i][k]>t[i][j])
				j=k;
		cout<<(i<26?string(1,'a'+i):ls[i-26])<<" ";
		cout<<(j<26?string(1,'a'+j):ls[j-26])<<" ";
		cout<<t[i][j]<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 896
final_rank: 16

code_snippet: #include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  cin >> n;
  string hoge="ldmbmpncndngntnwpsqucwts";
  map<string, int> mp;
  REP(i, 12) {
    mp[hoge.substr(2*i, 2)] = i+26;
  }
  int num[38][38];
  memset(num,0,sizeof(num));
  cin.ignore();
  while(n--) {
    string line;
    getline(cin, line);
    stringstream ss(line);
    string s;
    while(ss>>s) {
      int pre = -1;
      REP(i, s.size()) {
        int k;
        if (i<s.size()-1 && mp.count(s.substr(i, 2))) {
          k = mp[s.substr(i, 2)];
          i++;
        } else {
          k = s[i]-'a';
        }
        if (pre != -1)
          num[pre][k]++;
        pre = k;
      }
    }
  }
  string kan[38];
  REP(i, 38) {
    if (i<26) kan[i] = string(1, 'a' + i);
    else kan[i] = hoge.substr((i-26)*2, 2);
  }
  REP(i, 38) {
    int ma = max_element(num[i], num[i]+38) - num[i];
    cout << kan[i] << " " << kan[ma] << " " << num[i][ma] << endl;
  }
}
accuracy: 1
time_ms: 10
memory_kb: 0
final_rank: 1

code_snippet: #include <set>
#include <map>
#include <iostream>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

string kc[38]={
  "a", "b", "c", "d", "e", "f", "g",
  "h", "i", "j", "k", "l", "m", "n",
  "o", "p", "q", "r", "s", "t", "u",
  "v", "w", "x", "y", "z",
  "ld", "mb", "mp", "nc", "nd", "ng",
  "nt", "nw", "ps", "qu", "cw", "ts"
};

int main(){
  map<string, int> id;
  int n; cin >> n;
  string str;
  int ans[38][38];

  REP(i,38){
    id[kc[i]] = i;
    REP(j,38) ans[i][j] = 0;
  }

  while(cin >> str){
    vector<int> v;

    for(int i = 0; i < str.size(); ){
      if(i != str.size() - 1){
	string cand = str.substr(i, 2);
	if(id.count(cand)){
	  v.push_back(id[cand]);
	  i += 2;
	  continue;
	}
      }
      v.push_back(id[str.substr(i, 1)]);
      i++;
    }

    for(int i = 0; i < v.size() - 1; i++){
      ans[v[i]][v[i+1]]++;
    }
  }
  
  for(int i = 0; i < 38; i++){
    int cnt = 0;
    for(int j = 0; j < 38; j++){
      cnt = max(cnt, ans[i][j]);
    }

    for(int j = 0; j < 38; j++){
      if(ans[i][j] == cnt){
	printf("%s %s %d\n", kc[i].c_str(), kc[j].c_str(), cnt);
	break;
      }
    }
  }

  return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 0
final_rank: 2