B. Two-gram

Codeforces
IDCF977B
Time1000ms
Memory256MB
Difficulty
implementationstrings
Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "_AZ_", "_AA_", "_ZA_" — three distinct two-grams. You are 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. two consecutive characters of the string) maximal number of times. For example, for string $s$ = "_BBAABBBA_" the answer is two-gram "_BB_", which contained in $s$ three times. In other words, find any 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 \le n \le 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 two capital Latin letters — **any** two-gram contained in the given string $s$ **as a substring** (i.e. two consecutive characters of the string) maximal number of times. [samples] ## Note In the first example "_BA_" is also valid answer. In the second example the only two-gram "_ZZ_" can be printed because it contained in the string "_ZZZAA_" two times.
Samples
Input #1
7
ABACABA
Output #1
AB
Input #2
5
ZZZAA
Output #2
ZZ
API Response (JSON)
{
  "problem": {
    "name": "B. Two-gram",
    "description": {
      "content": "Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, \"_AZ_\", \"_AA_\", \"_ZA_\" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF977B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, \"_AZ_\", \"_AA_\", \"_ZA_\" — three distinct two-grams.\n\nYou are given a string $s$ consisting of $n$ capital ...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments