Two-gram is a ordered pair (i.e. string of length) of capital Latin letters. For example, "AZ", "AA", "ZA"-three distinct two-grams.
You is given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. both consecutive characters of the Str ing) maximal number of times. For example, for string s = "Bbaabbba" The answer is Two-gram "BB", which contained in S
three times. In the other words, find any to most frequent two-gram.
Note that occurrences of the two-gram can overlap with each other. Input
The first line of the input contains integer number n (2≤n≤100)-the length of string s. The second line of the input contains the string s consisting of n
Capital Latin Letters. Output
Print the only line containing exactly, Latin Letters-any Two-gram contained in the given string s
As a substring (i.e. consecutive characters of the string) maximal number of times. Examples Input
7
Abacaba
Output
Ab
Input
5
Zzzaa
Output
Zz
Note
In the first example "BA" is also valid answer.
The second example the only Two-gram "ZZ" can is printed because it contained in the string "Zzzaa" The Times. Test instructions: Find the most occurrences Multi-Two-gram substring, a two-gram string refers to the two consecutive letters appearing in the original string
Idea: Open a two-dimensional array dp[x][y] representing the number of occurrences of Two-gram string str[x]str[y]
Code:
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int dp[30][30];
int main () {
int n;
String str;
cin>>n>>str;
for (int i=0;i<n-1;i++) {
int x=str[i]-' A ';
int y=str[i+1]-' A ';
dp[x][y]++;
}
int maxt=0,last=0,next=0;
for (int i=0;i<26;i++) for
(int j=0;j<26;j++) {
if (Maxt<dp[i][j]) {
last=i;
Next=j;
MAXT=DP[I][J];
}
}
printf ("%c%c\n", last+ ' a ', next+ ' a ');
return 0;
}