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.

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.

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.

NoteIn 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.

fun main(args: Array<String>) {
    val array = Array(27, { IntArray(27) })
    val length = readLine()!!.toInt()
    var lastChar = 's'
    var max = 0
    var str = StringBuilder()
    val string = readLine()!!
    string.toCharArray().forEachIndexed { i, c ->
        if (i != 0) {
            array[lastChar.toInt() - 65][c.toInt() - 65]++
            if (array[lastChar.toInt() - 65][c.toInt() - 65] > max) {
                max = array[lastChar.toInt() - 65][c.toInt() - 65]
                str = StringBuilder()
                str.append(lastChar)
                str.append(c)
            }
        }
        lastChar = c
    }
    println(str.toString())

}

fun main() {
    val n = readLine()!!.toInt()
    val input = readLine()!!.substring(0, n)

    println(twoGram(input))
}

fun twoGram(input: String): String {
    val map = HashMap<String, Int>()

    var maxCount = 0
    var maxGram = ""

    for(i in 0..(input.length - 2)) {
        val key = "${input[i]}${input[i+1]}"
        map[key] = (map[key]?:0).plus(1)

        if(map[key]?.compareTo(maxCount)?:0 > 0) {
            maxCount = map[key]?:0
            maxGram = key
        }
    }

    return maxGram
}

private fun readLnString() = readLine()!! // string line
private fun readInt() = readLnString().toInt() // single int
private fun readStrings() = readLnString().split(" ") // list of strings
private fun readIntList() = readStrings().map { it.toInt() } // list of ints
private fun readLongList() = readStrings().map { it.toLong() } // list of longs
private fun readStringPair() = readStrings().zipWithNext()[0]
private fun readIntPair() = readStrings().map { it.toInt() }.zipWithNext()[0]

//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.

//7
//ABACABA
//AB
fun main() {
    val size = readInt()
    val string = readLnString()

    val map = mutableMapOf<String, Int>()

    for (index in 0..string.length - 2) {
        val substring = string.substring(index, index + 2)

        if (map.containsKey(substring))
            map[substring] = map.getOrDefault(substring, 1) + 1
        else
            map[substring] = 1
    }

    println(map.maxBy { entry -> entry.value}?.component1())
}

fun main() {
    val n = (readLine() as String).toInt()
    val s = readLine() as String
    test(n, s)
}

fun test(n: Int, s: String) {
    val results = mutableMapOf<String, Int>()

    (0 until n -1).forEach {
        val twoGram = "${s[it]}${s[it + 1]}"
        results.compute(twoGram) { key, v ->
            (v ?: 0) + 1
        }
    }

    val result = results.maxBy { it.value }!!

    //val result = results.entries.reduce { e1, e2 -> if (e1.value >= e2.value) e1 else e2  }
    println(result.key)
}

fun main() {
    val n = (readLine() as String).toInt()
    val s = readLine() as String
    test(n, s)
}

fun test(n: Int, s: String) {
    val results = mutableMapOf<String, Int>()
    (0 until n -1).forEach {
        val twoGram = "${s[it]}${s[it + 1]}"
        results.compute(twoGram) { key, v ->
            (v ?: 0) + 1
        }

    }
    val result = results.entries.reduce { e1, e2 -> if (e1.value >= e2.value) e1 else e2  }
    println(result.key)
}

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val str = sc.next()

    var mm = mutableMapOf<String, Int>()
    var maxa = 0
    var res = ""
    for (i in 0 until n-1) {
        val temp = str.substring(i, i+2)
        mm[temp] = (mm[temp] ?: 0)+1
    }
    for ((key, value) in mm) {
        if (value > maxa) {
            maxa = value
            res = key
        }
    }
    println(res)

}

import java.util.HashMap
import java.util.concurrent.atomic.AtomicInteger

/**
 * Created by azhdanov on 07.09.2019.
 */
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val n = readInt()
    val s = readLn()
    val map = HashMap<String, Int>()
    for (i in 0 .. n - 2) {
        val candidate = s.substring(i, i + 2)
        map[candidate] = (map[candidate] ?: 0) + 1
    }
    println(map.maxBy { it.value }?.key)
}

val occur = HashMap<String, Int>()

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    for(i in 0 until n-1) {
        val t = s.substring(i, i+2)
        if(t in occur)
            occur[t] = occur[t]!! + 1
        else
            occur[t] = 1
    }
    println(occur.maxBy { it.value }!!.key)
}

import java.util.*

/**
 * Kotlin Heroes: Practice 2
 * B. Двуграмма
 * http://codeforces.com/contest/1212/problem/B
 * */
class B

fun main() {
    readLine()
    val s = readLine()!!.toCharArray()
    val arr = Array(pos('Z', 'Z') + 1) { 0 }

    var max = 0
    var maxS = ""
    for (i in 1 until s.size) {
        val pos = pos(s[i - 1], s[i])
        if (++arr[pos] > max) {
            max = arr[pos]
            maxS = "${s[i - 1]}${s[i]}"
        }
    }
    println(maxS)
}

fun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')

fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key

fun main() {
    readLine()
    println(readLine()?.let { twoGram(it) })
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints

var m = HashMap<String, Int>();

fun main(){
    var n:Int = readInt()
    var s: String = readLn()
    for(i in 0..n-2){
        m[s.substring(i, i+2)] = m.getOrDefault(s.substring(i, i+2), 0) + 1;
    }
    // println(m);
    var temp = 0;
    var ans:String? = null;
    for(e in m){
        if(e.value > temp){
            temp = e.value;
            ans = e.key
        }
    }
    println(ans)
}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    scanner.nextInt()
    val str = scanner.next()
    val d = IntArray(676)
    var c = str[0]
    for (i in 1 until str.length) {
        d[(c - 'A') * 26 + (str[i] - 'A')]++
        c = str[i]
    }
    val a = d.indexOf(d.max()!!)
    println("${'A' + a / 26}${('A' + a % 26)}")
}

import java.security.InvalidAlgorithmParameterException

/**
 * Created by patrick on 31.08.19.
 * (c) Patrick Scheibe 2019
 */

fun main() {
    contest1212problemB()
}

fun contest1212problemB() {
    val n = readLine()!!.toInt()
    val s = readLine()!!.substring(0, n)
    val grams = mutableListOf<String>()
    for (i in 0..n - 2) {
            grams.add(s.substring(i,i+2))
    }
    val maxElm = grams.groupingBy { it }.eachCount().maxBy { it.value }
    if (maxElm != null) {
        print(maxElm.key)
    } else {
        throw InvalidAlgorithmParameterException("No max ngram. Shouldn't happen")
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map{it.toLong()}
//const val MOD = 1000000007

fun main(args:Array<String>){
    val n = readInt()
    val s = readLn()

    val skipString = s.substring(1, s.length)

    val list = s.asSequence()
            .chunked(2).map { it.joinToString("") }.toList()

    val skiplist = skipString.asSequence()
            .chunked(2).map { it.joinToString("") }.toList()

    val map = mutableMapOf<String, Int>()

    countGram(list, map)
    countGram(skiplist, map)

    var max = -1
    var key = ""
    map.forEach { t, u ->
        if (u>max && t.length==2){
            max = u
            key = t
        }
    }
    println(key)

}

fun countGram(list: List<String>, map: MutableMap<String, Int>) {
    list.forEach {
        if (map.contains(it)) {
            val count = map[it]!!
            map[it] = count + 1
        } else {
            map[it] = 1
        }
    }
}

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val tgc = ByteArray(836)

    var i = s[0] - 'A'
    for(j in 1 until n) {
        val k = s[j] - 'A'
        tgc[i shl 5 or k]++
        i = k
    }
    var max = tgc[0]
    i = 0
    for (j in 1 until tgc.size) {
        val v = tgc[j]
        if (v > max) {
            max = v
            i = j
        }
    }
    println("${'A' + (i shr 5)}${'A' + (i and 31)}")
}

import kotlin.system.measureTimeMillis

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val counts = mutableMapOf<String, Int>()
    for(i in 0 until s.length - 1) {
        val sub = s.substring(i, i + 2)
        counts[sub] = counts.getOrDefault(sub, 0) + 1
    }
    println(counts.maxBy { it.value }!!.key)
}

fun main(args: Array<String>) {
    readLine()
    val s = readLine()!!
    val map = HashMap<String, Int>()
    s.windowed(2).forEach { substr ->
        map[substr] = map.getOrDefault(substr, 0) + 1
    }
    val maxL = map.values.max()!!
    println(map.entries.find { it.value == maxL }!!.key)
}

import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    sc.nextLine()
    val s = sc.nextLine()
    s.zipWithNext()
        .groupingBy { it }
        .eachCount()
        .maxBy { it.value }
        ?.key
        ?.run { println("$first$second") }
}

/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */
val scan = java.util.Scanner(System.`in`)
fun main() {
    scan.nextInt()
    var s = scan.next()
    var maxTwogram = ""
    var maxCount = 0
    for(i in 0 until s.length-1) {
        val twogram = s.substring(i, i+2)
        var count = 0
        for (j in i until s.length-1) {
            if(s.substring(j).startsWith(twogram)) count ++
        }
        if(maxCount < count) {
            maxTwogram = twogram
            maxCount = count
        }
    }
    println(maxTwogram)
}

import kotlin.system.measureTimeMillis

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val counts = mutableMapOf<String, Int>()
    for(i in 0 until s.length - 1) {
        val sub = s.substring(i, i + 2)
        counts[sub] = (counts[sub] ?: 0) + 1
    }
    println(counts.maxBy { it.value }!!.key)
}

import java.util.StringTokenizer
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.InputStream
import java.util.HashMap
import kotlin.math.max

fun main() {

    R.init(System.`in`)
    var n = R.nextInt()
    var s = R.next()
    val map:HashMap<String,Int> = HashMap<String,Int>();
    var max=0
    var ans=""
    for(i in 0..n-2){
        var x = s.substring(i,i+2)
        if(map.containsKey(x)){
            map.put(x,map.getValue(x)+1)
        }
        else{
            map.put(x,1);
        }
        if(max<map.getValue(x)){
            ans=x
            max=map.getValue(x)
        }

    }
    println(ans)

}

internal object R {
    private lateinit var reader: BufferedReader
    private lateinit var tokenizer: StringTokenizer
    fun init(input: InputStream) {
        reader = BufferedReader(InputStreamReader(input))
        tokenizer = StringTokenizer("")
    }

    fun next(): String {
        while (!tokenizer.hasMoreTokens()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextDouble() = next().toDouble()
    fun nextLong() = next().toLong();
}

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val valueToCount = HashMap<String, Int>()

    for (i in 0 until n - 1) {
        val value = "${s[i]}${s[i + 1]}"
        valueToCount[value] = (valueToCount[value] ?: 0) + 1
    }

    val entry = valueToCount.maxBy { (_, value) -> value }
    println(entry!!.key)
}

import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Scanner
import java.util.HashMap

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author maxkibble
 */

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = Scanner(inputStream)
    val out = PrintWriter(outputStream)
    solve(1, `in`, out)
    out.close()
}

fun solve(testNumber: Int, `in`: Scanner, out: PrintWriter) {
    val n = `in`.nextInt()
    val s = `in`.next()
    var m = HashMap<String, Int>()
    var ans = ""
    var ans_x = 0
    for (i in 0 until n - 1) {
        val ss = s.substring(i, i + 2)
        val x = m.getOrDefault(ss, 0)
        m.put(ss, x + 1)
        if (x + 1 > ans_x) {
            ans = ss
            ans_x = x + 1
        }
    }
    out.println(ans)
}

fun String.twoGrams(): Map<String, Int> = this.zipWithNext { a, b -> "$a$b" }.groupingBy { it }.eachCount()

fun Map<String, Int>.max(): String? = this.maxBy { it.value }?.key

fun main() {
    val n = readLine()?.toIntOrNull() ?: error("n not valid")
    val s = readLine()?.substring(0 until n) ?: error("s not valid")

    println(s.twoGrams().max())
}

        fun main(){
            readLine();
            val characters = readLine()!!;

            var best_count = -1;
            var best_index = -1;

            var i = 0;
            while(i < characters.length - 1){
                var count = 0;

                val reference1 = characters.get(i);
                val reference2 = characters.get(i + 1);

                var j = i;
                while(j < characters.length - 1){
                    val character1 = characters.get(j);
                    val character2 = characters.get(j + 1);

                    if(character1 == reference1 && character2 == reference2){
                        count = count + 1;
                    }

                    j = j + 1;
                }

                if(count > best_count){
                    best_count = count;
                    best_index = i;
                }

                i = i + 1;
            }

            println(characters.substring(best_index, best_index + 2));
        }

fun main(args: Array<String>) {
  val nbCharacters: Int = readLine()!!.toInt()
  val word: String = readLine()!!
  val map: MutableMap<String, Int> = mutableMapOf()
  for (i in 0 .. nbCharacters-2) {
    val w = word.substring(i, i+2)
    val value = map.getOrElse(w) {0} + 1
    map.put(w, value )
  }

  var maxVal = -1
  var comb = ""
  map.forEach { k, v ->
    if (v > maxVal) {
      comb = k
      maxVal = v
    }
  }
  print(comb)
}

import kotlin.math.*

private fun readLn() = readLine()!!
private fun readInt() = readLn().toInt()
private fun readStrings() = readLn().split(" ")
private fun readInts() = readStrings().map { it.toInt() }
private fun Boolean.toInt() = if (this) 1 else 0

private fun isPalindrome(s: String): Int {
    val n = s.length
    for(i in 0..n/2-1){
        if (s[i] != s[n-i-1]){
            return 0
        }
    }
    return 1
}

fun main(args : Array<String>) {
    var n = readInt()
    var s = readLn()
    var cnt = mutableMapOf<String, Int>()
    for(i in 1..n-1){
        var key = s.substring(i-1,i+1)
        if (cnt[key] == null){
            cnt[key] = 1
        }
        else {
            cnt[key] = cnt[key]!! + 1
        }
    }
    var dg = "##"
    var c = 0
    for((k,v) in cnt){
        if (v > c){
            dg = k
            c = v
        }
    }
    print(dg)
}

import java.util.*
import kotlin.collections.ArrayList

fun main() {
    val input = Scanner(System.`in`)
    val n = input.nextInt()
    val s = input.next()

    val letters = s.split("")
    val iSize = letters.size - 3
    val dGrams: ArrayList<String> = ArrayList()
    for (i in 1..iSize) {
        dGrams.add("${letters[i]}${letters[i + 1]}")
    }

    var mGram = Int.MIN_VALUE
    var mIndex = 0
    val count: ArrayList<Pair<String, Int>> = ArrayList()
    for (i in dGrams) {
        var exists = false
        var gIndex = 0
        count.forEachIndexed { index, pair ->
            if (pair.first == i) {
                exists = true
                gIndex = index
                return@forEachIndexed
            }
        }
        if (!exists) {
            count.add(Pair(i, 1))
        } else {
            val num = count[gIndex].second + 1
            count[gIndex] = Pair(i, num)
            if (num > mGram) {
                mGram = num
                mIndex = gIndex
            }
        }
    }

    print(count[mIndex].first)
}

fun main() {
    val l = readLine()!!.toInt()
    val s = readLine()!!

    val r :HashMap<String, Int> = hashMapOf()

    for (i in 0 until l - 1) {
        val x = s.substring(i, i + 2)
        if (r.containsKey(x)) {
            r[x] = r[x]!!.plus(1)
        } else {
            r[x] = 0
        }
    }

    var z = -1
    var y = ""
    for (j in r) {
        if (j.value > z) {
            z = j.value
            y = j.key
        }
    }
    println(y)
}

fun main(args: Array<String>) {
    val t = 1 // readLine()!!.toInt()

    repeat(t) {
        val ma =  mutableMapOf<String, Int>()

        val n = readLine()!!.toInt()
        val s = readLine()!!

        var i=0
        while(i<n-1) {
            val ss = s.substring(i, i+2)

            if (!ma.containsKey(ss)) {
                ma.put(ss, 1)
            } else {
                // print("${ss} ${ma[ss]} => ")
                ma[ss] = ma[ss]!!.inc()
                // println("${ma[ss]}")
            }
            i++
        }

        var ssmax = ma.keys.first()
        // println("${ssmax} ${ma[ssmax]}")

        for (ss in ma.keys) {
            // println("${ss} ${ma[ss]!!} ${}")

            if ( ma[ss]!! > ma[ssmax]!! ) {
            // println("${ss} > ${ssmax}")
              ssmax = ss
            }
        }

        println(ssmax)

    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    var n = readInt()
    var s = readLn()
    var m = HashMap<String,Int>()

    for (i in 0..s.length-2) {
        var str = s[i].toString() + s[i + 1]
        if (m.containsKey(str))
            m[str] = m[str]!! + 1
        else
            m[str] = 1
    }
    var mx = Pair("", 0)
    for ((k,v) in m) {
        if (mx.second < v) {
            mx = Pair(k,v)
        }
    }
    print(mx.first)
}

import java.util.*
import kotlin.collections.HashMap

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val length = scanner.nextInt()
    val string = scanner.next()
    println(find(length, string))
}

fun find(length: Int, string: String): String {
    val map = HashMap<String, Int>()
    for (i in 0 until length - 1) {
        val str = string.substring(i, i + 2)
        if (map.containsKey(str)) {
            map[str] = map[str]!! + 1
        } else {
            map[str] = 1
        }
    }
    return map.maxBy { it.value }!!.key
}

import java.io.InputStream
import kotlin.math.max

const val A = 'A'.toInt()
const val Z = 'Z'.toInt()

fun main() {
    for (c in twoGram(System.`in`)) {
        print(c)
    }
}

fun twoGram(input: InputStream): CharArray {
    var len = 0
    var i: Int

    while (true) {
        i = input.read()
        if (i == System.lineSeparator()[0].toInt()) break

        len *= 10
        len += i - 0x30
    }

    input.skip((System.lineSeparator().length - 1).toLong())

    val size = Z - A + 1
    val result = Array(size) { IntArray(size) }

    var m = 0

    var c = input.read() - A

    for (j in 1 until len) {
        val cc = input.read() - A

        var v = result[c][cc]
        result[c][cc] = ++v
        m = max(m, v)
        c = cc
    }

    for (x in result.indices) {
        val arr = result[x]
        for (y in arr.indices) {
            if (arr[y] == m) {
                return charArrayOf((x + A).toChar(), (y + A).toChar())
            }
        }
    }

    return charArrayOf()
}

import java.util.Scanner
fun main() {

    val reader = Scanner(System.`in`)
    var size:Int=reader.nextInt()
    var s:String=reader.next()
    var i=0
    var mx=0
    var f:String=""
    while(i<size-1){
        var temp=s.substring(i,i+2)
        var count=0
        var k=0
        while(k<size-1){
            if(s.substring(k,k+2)==temp)
               count++;
            k++
        }
        if(mx<count){
            mx=count
            f=temp
        }
        i++;
    }
    println(f)
}

import java.io.PrintWriter
import java.util.*

/**
 * Created on : May 12, 2018
 * Author     : zetbaitsu
 * Name       : Zetra
 * GitHub     : https://github.com/zetbaitsu
 */

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val input = Scanner(inputStream)
    val output = PrintWriter(outputStream)
    val solver = Solver()
    solver.solve(input, output)
    output.close()
}

class Solver {
    fun solve(input: Scanner, output: PrintWriter) {
        val n = input.nextInt()
        input.nextLine()
        val s = input.nextLine()

        val map = mutableMapOf<String, Int>()
        (0 until n - 1)
                .map { "${s[it]}${s[it + 1]}" }
                .forEach {
                    if (map.containsKey(it)) {
                        val value = map[it]!!
                        map[it] = value + 1
                    } else {
                        map[it] = 1
                    }
                }

        output.println(map.entries.maxBy { it.value }?.key)
    }
}

fun main(): Unit {
    readLine()
    print(
        readLine()!!.asSequence()
            .windowed(2, 1)
            .map { "${it[0]}${it[1]}"}
            .groupBy { it }
            .maxBy { it.value.size }?.key
        )
}

fun main(args: Array<String>) {
    val numberOfLines = readLine()?.toInt() ?: 0
    var string = readLine()
    val substrings = string?.chunked(2)
    val entries = mutableMapOf<String, Int>()

    for (i in 0 until numberOfLines) {
        val firstEntry = string?.get(i)
        val secondEntry = if (i == numberOfLines - 1) "" else string?.get(i + 1)
        val finalKey = "$firstEntry$secondEntry"

        if (entries.containsKey(finalKey)) {
            entries.merge(finalKey, 1) { old, value ->
                old + value
            }
        } else {
            entries[finalKey] = 1
        }
    }

    val max = entries.maxBy { it.value }
    println(max?.key)
}

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt() // single int
fun readStrings() = readLn().split(" ") // list of strings
fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {
    var n = readInt()
    var s = readLn()
    val fre = Array(26, {IntArray(26){0}})
    for(i in 0..n-2){
        fre[s[i].toInt() - 'A'.toInt()][s[i+1].toInt()-'A'.toInt()]++
    }
    var mx = 0
    var an = ""
    for(i in 0..25){
        for(j in 0..25){
            if(fre[i][j] > mx){
                mx = fre[i][j]
                an=""+(i+'A'.toInt()).toChar()
                an+=(j+'A'.toInt()).toChar()
            }
        }
    }
    println(an)
}

import java.util.Scanner;

fun main() {
    val input = Scanner(System.`in`);

    var n = readLine()!!.toInt()
    var str = readLine()!!.toCharArray()

    var mp = mutableMapOf<String, Int>();

    for(i in 0..(n-2)) {
        var s = (str?.get(i)?.toString()) + str?.get(i+1)?.toString();
        if (mp.containsKey(s)) {
            mp[s] = mp.getValue(s)+1;
        } else {
            mp.put(s, 1);
        }
    }

    var ans: String = "";
    var num: Int = 0;

    for((str, count) in mp) {
        if (count > num) {
            num = count;
            ans = str;
        }
    }
    println(ans);
}

import java.util.*

fun main() {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    val m = hashMapOf<String, Int>()
    for (i in 0 until n - 1) {
        val x = s.substring(i, i + 2)
        m[x] = m.getOrDefault(x, 0) + 1
    }
    var cnt = 0
    var res: String? = null
    for (e in m) {
        if (cnt < e.value) {
            cnt = e.value
            res = e.key
        }
    }
    println(res)
}

import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.Scanner
import java.util.HashMap

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author maxkibble
 */

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val `in` = Scanner(inputStream)
    val out = PrintWriter(outputStream)
    solve(1, `in`, out)
    out.close()
}

fun solve(testNumber: Int, `in`: Scanner, out: PrintWriter) {
    val n = `in`.nextInt()
    val s = `in`.next()
    val m = HashMap<String, Int>()
    var ans = ""
    var ans_x = 0
    for (i in 0 until n - 1) {
        val ss = s.substring(i, i + 2)
        val x = m.getOrDefault(ss, 0)
        m.put(ss, x + 1)
        if (x + 1 > ans_x) {
            ans = ss
            ans_x = x + 1
        }
    }
    out.println(ans)
}

fun main() {
    val n = readLine()!!.toInt()
    val input = readLine()!!.substring(0, n)

    println(twoGram(input))
}

fun twoGram(input: String): String {
    val map = HashMap<String, Int>()

    var maxCount = 0
    var maxGram = ""

    for(i in 0..(input.length - 2)) {
        val key = "${input[i]}${input[i+1]}"
        map[key] = (map[key]?:0).plus(1)

        if(map[key]?.compareTo(maxCount)?:0 > 0) {
            maxCount = map[key]?:0
            maxGram = key
        }
    }

    return maxGram
}

fun main(args: Array<String>){
	val debug = false
	val k = readLine()!!.toInt()
	val stroka = readLine().toString()
	val mapa = mutableMapOf<String,Int>()

	for (i in 0..k-2){
		if (debug) println("Debug! $i ${stroka.substring(i,i+2)}")
		val digr = stroka.substring(i,i+2)
		if (mapa.containsKey(digr)){
			mapa.put(digr, mapa.getValue(digr) + 1)
		}else{
			mapa.put(digr,1)
		}
	}
	val sorted = mapa.toList().sortedBy{-it.second}
//	println(n)
	println(sorted[0].first)
	if (debug) println("Debug!")
}

fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key

fun main(args: Array<String>) {
    readLine()
    println(readLine()?.let { twoGram(it) })
}

import java.util.Scanner
import kotlin.collections.HashMap
import kotlin.collections.set
fun main() {
    val sc = Scanner(System.`in`)
    val map = HashMap<String, Int>()

    val n = Integer.parseInt(sc.nextLine())
    val str = sc.nextLine()

    for (i in 0 until n - 1) {
        val word = str.substring(i, i + 2)

        val count = map[word]

        if (count == null) map[word] = 1 else map[word] = count + 1
    }

    println(map.entries.stream().max { entry1, entry2 -> if (entry1.value > entry2.value) 1 else -1 }.get().key)
}

import java.util.*

fun readLn() = readLine()!!
fun readStrings() = readLn().split(" ")
fun readInts() = readStrings().map{ it.toInt() }

fun main() {
  var (n) = readInts()
  var (s) = readStrings()
  var mp = HashMap<String, Int>()
  for (i in 0..n - 2) {
    var t = s.substring(i, i + 2)
    mp[t] = mp.getOrDefault(t, 0) + 1
  }
  var ans = ""
  var mx = 0
  for ((key, value) in mp) {
    if (value > mx) {
      mx = value
      ans = key
    }
  }
  println(ans)
}

fun main(a:Array<String>){val l=readLine()!!.toInt();val s=readLine()!!;val m=HashMap<String,Int>();(0 until l-1).map{"${s[it]}${s[it +1]}"}.forEach{if(m.containsKey(it))m[it]=m[it]!!+1 else m[it]=1};println(m.maxBy{ it.value}!!.key)}

//package com.happypeople.codeforces.c1212

import java.io.ByteArrayInputStream
import java.io.InputStream
import java.util.*

fun main(args: Array<String>) {
    try {
        B1212().run()
    } catch (e: Throwable) {
        println("")
        e.printStackTrace()
    }
}

class B1212 {
    fun run() {
        val sc = Scanner(systemIn())
        val n=sc.nextInt()
        val str=sc.next()
        val dmap = mutableMapOf<String, Int>()
        for(i in 0..str.length-2) {
            val twogram=str.substring(i..i+1)
            val old=dmap.getOrDefault(twogram, 0);
            dmap.set(twogram, old+1);
        }
        println(dmap.toList().sortedByDescending { (_, value) -> value }.first().first)
    }

    companion object {
        var inputStr: String? = null

        fun systemIn(): InputStream {
            if (inputStr != null)
                return ByteArrayInputStream(inputStr!!.toByteArray())
            else
                return System.`in`
        }

        var printLog = false
        fun log(str: String) {
            if (printLog)
                println(str)
        }
    }
}

fun main() {
    val inputLen = readLine()?.toInt()
    println(readLine()?.let { input ->
        val map = mutableMapOf<String, Int>()
        for (i in 0 until inputLen?.dec()!!) {
            input.substring(i, i.plus(2)).let { tg ->
                map[tg] = map[tg]?.inc() ?: 1
            }
        }
        map.maxBy {
            it.value
        }?.key
    })
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

private fun solve() {
    var mx = 0
    var ans = ""
    val n = readInt()
    val s = readLn()
    val ar = mutableListOf<String>()
    for (i in 1 until s.length){
        var temp: String = (s[i - 1]).toString()
        temp += s[i]
        ar.add(temp)
    }
    for (i in 0 until ar.size){
        var cnt = 0
        val cur = ar[i]
        for (j in 1 until s.length) {
            //println(s.substring(IntRange(j - 1, j)))
            if (s.substring(IntRange(j - 1, j)) == cur)
                cnt++
        }
        if (cnt > mx) {
            mx = cnt
            ans = cur
        }

    }
    println(ans)
}
fun main(args: Array<String>) {
    solve()
}

import javax.print.attribute.IntegerSyntax
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readDouble() = readLn().toDouble()
fun readLong() = readLn().toLong()
fun readStrings() = readLn().split(' ')
fun readInts() = readStrings().map { it.toInt() }
fun readDoubles() = readStrings().map { it.toDouble() }
fun readLongs() = readStrings().map { it.toLong() }

fun main(args: Array<String>) {
    val n = readInt()
    var s = readLn()

    val freq = mutableMapOf<String, Int>()

    for (i in 0 until n - 1) {
        val twoGram = s.substring(i, i + 2)
        freq[twoGram] = freq.getOrDefault(twoGram, 0) + 1
    }

    var result = ""
    var maxCount = 0
    for (item in freq) {
        if (item.value > maxCount) {
            maxCount = item.value
            result = item.key
        }
    }

    println(result)
}

import java.util.HashMap
import java.util.Scanner
 fun main(args:Array<String>) {
    val sc = Scanner(System.`in`)
    sc.nextInt()
    val s = sc.next()
    println(solve(s))
    sc.close()
  }
  internal fun solve(s:String):String {
    val twoGramToCount = HashMap<String, Int>()
    for (i in 0 until s.length - 1)
    {
      val twoGram = s.substring(i, i + 2)
      twoGramToCount.put(twoGram, (twoGramToCount as java.util.Map<String, Int>).getOrDefault(twoGram, 0) + 1)
    }
    val maxCount = twoGramToCount.values.stream().mapToInt({ x-> x }).max().getAsInt()
    return twoGramToCount.keys.stream().filter({ twoGram-> twoGramToCount.get(twoGram) == maxCount }).findAny()
    .get()
  }

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt() // single int
fun readStrings() = readLn().split(" ") // list of strings
fun readInts() = readStrings().map { it.toInt() } // list of ints

fun ctoi(c : Char): Int{
    return c.toInt() - 'A'.toInt()
}
fun itoc(c : Int): Char{
    return (c+'A'.toInt()).toChar()
}
fun main(args: Array<String>) {
    var n = readInt()
    var s = readLn()
    val fre = Array(26, {IntArray(26){0}})
    for(i in 0..n-2){
        fre[ctoi(s[i])][ctoi(s[i+1])]++
    }
    var mx = 0
    var an = ""
    for(i in 0..25){
        for(j in 0..25){
            if(fre[i][j] > mx){
                mx = fre[i][j]
                an=""+itoc(i)
                an+=itoc(j)
            }
        }
    }
    println(an)
}

fun main(){
    var n=readLine()!!.toInt()
    var str=readLine()!!
    val total=IntArray(700)
    for (x in 1..n-1){
        total[hash(str[x-1],str[x])]++
    }
    var most=0
    for (x in 0..699){
        if (total[x]>total[most]) most=x
    }
    print("${((most/26)+'A'.toInt()).toChar() }${((most%26)+'A'.toInt()).toChar()}\n")
}
fun hash(i:Char, j:Char):Int{
    return (i-'A')*26 + (j-'A')
}

import java.util.*

class Main : Runnable {
    private val scanner: Scanner = Scanner(System.`in`)

    override fun run() {
        scanner.nextInt()
        scanner.nextLine()
        val string = scanner.nextLine()
        val max =
            IntRange(0, string.length - 2)
                .groupingBy { string.substring(it, it + 2) }
                .eachCount()
                .maxBy { it.value }!!
        println(max.key)
    }

}

fun main() = Main().run()

fun main() {
    val count = readLine()!!.toInt()
    val str = readLine()!!

    var max = Int.MIN_VALUE
    var maxStr = str.subSequence(0, 2)
    for (i in 0 .. count - 2) {
        val subStr = str.substring(i, i + 2)
        var current = 0
        for (i in 0 .. count - 2) {
            val subStr2 = str.substring(i, i + 2)
            if (subStr == subStr2)
            current++
        }

        if (current > max) {
            max = current
            maxStr = subStr
        }
    }
    print(maxStr)
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main(args: Array<String>) {
    var n = readInt()
    var s = readLn()
    var m = HashMap<String, Int>()
    for (i in 0..n-2) {
        var t = s.substring(i, i + 2)
        if (m.containsKey(t)) {
            m.put(t, m.get(t)!! + 1)
        } else {
            m.put(t, 1)
        }
    }
    var mx = -1
    var res = ""
    for (t in m.keys) {
        if (m.get(t)!! > mx) {
            mx = m.get(t)!!
            res = t
        }
    }
    println(res)
}

import java.util.*
import kotlin.collections.HashMap
import kotlin.math.max

fun main() {

    val scan = Scanner(System.`in`)
    var n: Int = scan.nextLine().trim().toInt()
    val str: String = scan.nextLine().trim()

    val hashMap = HashMap<String, Int>()

    for (i in 0 until str.length - 1) {
        val diagram = str.substring(i, i + 2)
        if (hashMap.contains(diagram)) {
            val value = hashMap.getValue(diagram)
            hashMap.replace(diagram, value + 1)
        } else {
            hashMap[diagram] = 1
        }
    }

    val maxValue = hashMap.values.max()
    print(hashMap.filterValues { it == maxValue }.keys.toList()[0])

}

fun main(args : Array<String>) {
    var n = readLine()!!.toInt()
    var str = readLine()!!

    var map = mutableMapOf<String, Int>()
    for (i in 0..n - 2) {
        var sub = str.substring(i..i + 1)
        if (!map.contains(sub)) map[sub] = 1
        else map[sub] = map[sub]!! + 1
    }

    var max = 0
    var ans = ""
    map.forEach {
        if (it.value > max) {
            max = it.value
            ans = it.key
        }
    }
    println(ans)
}

import java.util.*

/**
 * Kotlin Heroes: Practice 2
 * B. Двуграмма
 * http://codeforces.com/contest/1212/problem/B
 * */
class B

fun main() {
    readLine()
    val s = readLine()!!.toCharArray()
    val arr = Array(pos('Z', 'Z') + 1) { 0 }

    var max = 0
    var maxS = ""
    for (i in 1 until s.size) {
        val pos = pos(s[i - 1], s[i])
        if (++arr[pos] > max) {
            max = arr[pos]
            maxS = "${s[i - 1]}${s[i]}"
        }
    }
    println(maxS)
}

fun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')

fun main() {
    readLine()
    val s = readLine()!!
    val res=s.zipWithNext { a, b -> a.toString() + b }
        .groupingBy { it }
        .eachCount()
        .maxBy { it.value }
        ?.key!!
    println(res)
}

import kotlin.math.max

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

val map = HashMap<CharSequence, Int>()
fun main() {
   val n = readInt()
    val k = readLn()
    findSequence(k, 0, n)
    val res = map.maxBy { it.value }
    println(res?.key.toString().capitalize())
}

fun findSequence(input: String, pos: Int, max: Int) {
    val sequence = input.subSequence(pos, pos + 2)
    if (map.containsKey(sequence)) {
        map[sequence] = map[sequence]!!.plus(1)
    } else {
        map[sequence] = 1
    }
    if (pos + 2 < max) {
        findSequence(input, pos + 1, max)
    }
}

fun main(args: Array<String>) {

    // reading the input and saving it
    val amountOfLetters = readLine()!!.toInt()
    val inputString = readLine()!!

    // the var will be the temporary string containing the two-gram to be checked while traversing through
    // the input String
    var tempString: String

    // the hashmap will contain the two-gram string along with the occurences
    // it will be initialied with the first two-gram and its counter value of 1
    var counterHashMap: MutableMap<String,Int> = mutableMapOf(inputString.subSequence(0,2).toString() to 1)

    // iterating over the string, saving each two-gram in a temporary string
    // checking if the two-gram exists in the hashmap
    // yes: increase the value, no: adding the two-gram to the hasmap and initializing the value to 1
    for((index,character) in inputString.withIndex()) {
        // to avoid the indexOutOfBounce exception, the index is being checked
        if(index == inputString.length-1) break
        // skip the first 2 letters as they have been added in the initialisation
        if(index == 0) continue;

        // concatenating two chars
        tempString = "" + character + inputString[index+1]
        // check if the two-gram is in the haspMap
        if(tempString in counterHashMap) {
            // increase the value if it does
            counterHashMap.set(tempString, counterHashMap.get(tempString)!!.plus(1))
        } else {
            // add the value to hashmap if it doesnt with value 1
            counterHashMap.put(tempString,1)
        }
    }
    println(counterHashMap.maxBy{it.value}.toString().subSequence(0,2))
}

fun main() {
    val numLetters = readLine()!!.toInt()
    val word = readLine()!!

    var twoGramFrequencies = mutableMapOf<String, Int>()
    for (i in 0 until numLetters - 1) {
        var currentTwoGram = word.substring(i..i + 1)
        if (twoGramFrequencies.containsKey(currentTwoGram)) {
            twoGramFrequencies.entries.filter { it.key == currentTwoGram }.map { it.setValue(it.value + 1) }
        } else {
            twoGramFrequencies[currentTwoGram] = 0
        }
    }

    println(twoGramFrequencies.maxBy { it.value }!!.key)
}

fun main(args: Array<String>) {
    val numberOfLines = readLine()?.toInt() ?: 0
    var string = readLine()
    val substrings = string?.chunked(2)
    val entries = mutableMapOf<String, Int>()

    for (i in 0 until numberOfLines) {
        val firstEntry = string?.get(i)
        val secondEntry = if (i == numberOfLines - 1) "" else string?.get(i + 1)
        val finalKey = "$firstEntry$secondEntry"

        if (entries.containsKey(finalKey)) {
            entries.merge(finalKey, 1) { old, value ->
                old + value
            }
        } else {
            entries[finalKey] = 1
        }
    }

    val max = entries.maxBy { it.value }
    println(max?.key)
}

import java.util.*

fun main() {
    val reader = Scanner(System.`in`)
    reader.nextInt()
    val s = reader.next().trim()
    val m = mutableMapOf<String, Int>()
    for (k in s.zipWithNext().map { "${it.first}${it.second}" })
        m[k] = m.getOrDefault(k, 0) + 1
    println(m.maxBy { it.value }?.key)
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val n = readInt()
    val s = readLn()
    val map = HashMap<String, Int>()
    for (i in 0 until s.length-1) {
        val sub = s[i].toString() + s[i + 1].toString()
        map[sub] = map.getOrDefault(sub, 0) + 1
    }
    println(map.maxBy { it.value }!!.key)
}

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val n = sc.nextInt()
    val str = sc.next()

    val map = HashMap<String, Int>()

    for (i in 0 until n - 1) {
        val dg = "${str[i]}${str[i+1]}"
        val dg2 = "ldksjflskdjflksdjf"
        if (!map.containsKey(dg)) {
            map[dg] = 0
        }
        if (!map.containsKey(dg2)) {
            //map[dg2] = 0
        }
        if (dg == dg2) {
            map[dg] = map[dg]!! + 1
        } else {
            map[dg] = map[dg]!! + 1
            //map[dg2] = map[dg2]!! + 1
        }
    }

    var max = -1
    var maxv = "sf"

    map.forEach({k, v ->
        if (v > max) {
            max = v
            maxv = k
        }
    })
    println(maxv)
}

import java.io.StreamTokenizer

fun main(args: Array<String>) {
    val tokenizer = StreamTokenizer(System.`in`)
    val n = tokenizer.nextInt()
    val s = tokenizer.nextString().toCharArray()
    val map = HashMap<Pair<Char, Char>, Int>()
    var max = 0
    var ans: Pair<Char, Char>? = null
    for (i in 0 until n - 1) {
        val p = Pair(s[i], s[i + 1])
        val v = (map[p] ?: 0) + 1
        map[p] = v
        if (v > max) {
            max = v
            ans = p
        }
    }
    println("${ans!!.first}${ans.second}")
}

fun StreamTokenizer.nextString(): String {
    return if (nextToken() == StreamTokenizer.TT_WORD) sval else ""
}

fun StreamTokenizer.nextInt(): Int {
    return if (nextToken() == StreamTokenizer.TT_NUMBER) nval.toInt() else -1
}

fun StreamTokenizer.nextDouble(): Double {
    return if (nextToken() == StreamTokenizer.TT_NUMBER) nval else 0.0
}

import java.util.*

fun main() {
    val input = Scanner(System.`in`)

    val n = input.nextLine().toInt()
    val s = input.nextLine().toString()
    var max = 0
    var sequence = ""

    s.windowed(2,1, false) { toTest ->
        var count = 0
        s.windowed(2,1, false) { toMatch ->
            if (toTest == toMatch) {
                count ++
            }
            if (count>max) {
                max = count
                sequence = toTest.toString()
            }
        }
    }

    println(sequence)
}

import java.util.Scanner
fun main(args: Array<String>){
    val input = Scanner(System.`in`)
    var pituus = readLine()!!
    var teksti = readLine()!!
    var maksimi: Int = 0
    var kirjaimet: String = ""
    for(i in 0..(teksti.length-2)){
        var kaksi: String = "" + teksti[i] + teksti[i+1]
        var luku: Int = 0
        for(j in 0..(teksti.length-2)){
            var uudetkaksi: String = "" + teksti[j] + teksti[j+1]
            if(kaksi.equals(uudetkaksi)){
                luku += 1
            }
        }
        if(luku > maksimi){
            maksimi = luku
            kirjaimet = kaksi
        }
    }
    println(kirjaimet)
}

fun String.twoGrams(): Map<String, Int> = this.zipWithNext { a, b -> "$a$b" }.groupingBy { it }.eachCount()

fun Map<String, Int>.max(): String? = this.maxBy { it.value }?.key

fun main() {
    val n = readLine()?.toIntOrNull() ?: error("n not valid")
    val s = readLine()?.substring(0 until n) ?: error("s not valid")

    println(s.twoGrams().max())
}

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg = Pair(-1, "")
        for(i in 0 until n-1){
            val sub = "${str[i]}${str[i+1]}"
            var count = 0
            for(i in 0 until str.length-1){
                if(str[i] == sub[0] && str[i+1] == sub[1]) count++
            }
            if(count > tg.first){
                tg = Pair(count, sub)
            }
        }
       return tg.second
    }

}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    var n = scanner.nextLine()
    val s = scanner.nextLine()

    val map: HashMap<String, Int> = hashMapOf()

    s.forEachIndexed { i, c ->
        if (i < s.length - 1) {
            val char0 = s[i]
            val char1 = s[i + 1]
            if (char0.isUpperCase() && char1.isUpperCase()) {
                val res = map.get("$char0$char1")

                if (res == null) {
                    map.put("$char0$char1", 1)
                } else {
                    map.put("$char0$char1", res + 1)
                }
            }
        }
    }
    var max = 0
    var result = ""
    map.forEach { ss, count ->
        if (count > max) {
            max = count
            result = ss
        }
    }

    println(result)

}

import java.util.*

fun main() {
    Scanner(System.`in`).use { scanner ->
        scanner.nextInt() // not needed for first approach...
        val string = scanner.next()
        println(TwoGramSolver.solve(string))
    }
}

private object TwoGramSolver {

    internal fun solve(string: String): String {
        val twoGrams = mutableMapOf<String, Int>()
        var maxTwoGram: Pair<String, Int>? = null

        string.windowed(2).forEach { twoGram ->
            val twoGramCount = (twoGrams[twoGram] ?: 0).inc()
            twoGrams[twoGram] = twoGramCount

            if (maxTwoGram == null) {
                maxTwoGram = twoGram to twoGramCount
                return@forEach
            }

            if (twoGramCount > maxTwoGram!!.second) {
                maxTwoGram = twoGram to twoGramCount
            }
        }

        return maxTwoGram!!.first
    }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    var n = readInt()
    var s = readLn()
    var m = HashMap<String,Int>()

    for (i in 0..s.length-2) {
        var str = s[i].toString() + s[i + 1]
        if (m.containsKey(str))
            m[str] = m[str]!! + 1
        else
            m[str] = 1
    }
    var mx = Pair("", 0)
    for ((k,v) in m) {
        if (mx.second < v) {
            mx = Pair(k,v)
        }
    }
    print(mx.first)
}

import java.security.InvalidAlgorithmParameterException

/**
 * Created by patrick on 31.08.19.
 * (c) Patrick Scheibe 2019
 */

fun main() {
    contest1212problemB()
}

fun contest1212problemB() {
    val n = readLine()!!.toInt()
    val s = readLine()!!.substring(0, n)
    val grams = mutableListOf<String>()
    for (i in 0..n - 2) {
            grams.add(s.substring(i,i+2))
    }
    val maxElm = grams.groupingBy { it }.eachCount().maxBy { it.value }
    if (maxElm != null) {
        print(maxElm.key)
    } else {
        throw InvalidAlgorithmParameterException("No max ngram. Shouldn't happen")
    }
}

import java.util.*

fun min(a:Double,b:Double) = if (a<b) a else b
fun max(a:Double,b:Double) = if (a>b) a else b
fun min(a:Int,b:Int) = if (a<b) a else b
fun max(a:Int,b:Int) = if (a>b) a else b
fun printD(d: Double) { print(d) }
fun printI(d:Int) { print(d) }
fun printS(d: String) { print(d) }
fun printL(d: Long) { print(d) }
class pair (var first:Int, var second:Int)

fun main() {
    val cin = Scanner(System.`in`)

    /* --------- */

   /*
   map[q] <=> map.getOrDefault(q,0)

   */
     var a=cin.nextInt()
     var s=cin.next()
     var max1=0;
     var ans="";
     //var m=IntArray
      var map=hashMapOf<String,Int>();

      for (i in 0..a-2) {
          var q=""; q+=s[i]; q+=s[i+1];
          map[q]=map.getOrDefault(q,0)+1;
          if (map.getOrDefault(q,0)>max1) {max1=map.getOrDefault(q,0); ans=q;  }
      }
      print(ans);

   /* --------- */

}

import java.util.Scanner;

fun main() {
    val input = Scanner(System.`in`);

    var n = readLine()!!.toInt()
    var str = readLine()!!.toCharArray()

    var mp = mutableMapOf<String, Int>();

    for(i in 0..(n-2)) {
        var s = (str?.get(i)?.toString()) + str?.get(i+1)?.toString();
        if (mp.containsKey(s)) {
            mp[s] = mp.getValue(s)+1;
        } else {
            mp.put(s, 1);
        }
    }

    var ans: String = "";
    var num: Int = 0;

    for((str, count) in mp) {
        if (count > num) {
            num = count;
            ans = str;
        }
    }
    println(ans);
}

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val xs = (0 until n.minus(1))
        .groupingBy { s.subSequence(it..(it+1)) }
        .eachCount()
        .maxBy { it.value }?.key!!
    print(xs)
}

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val xs = (0 until n.minus(1))
        .groupingBy { s.slice(it..(it+1)) }
        .eachCount()
        .maxBy { it.value }?.key!!
    print(xs)
}

fun main(args : Array<String>) {
    var n = readLine()!!.toInt()
    var str = readLine()!!

    var map = mutableMapOf<String, Int>()
    for (i in 0..n - 2) {
        var sub = str.substring(i..i + 1)
        if (!map.contains(sub)) map[sub] = 1
        else map[sub] = map[sub]!! + 1
    }

    var max = 0
    var ans = ""
    map.forEach {
        if (it.value > max) {
            max = it.value
            ans = it.key
        }
    }
    println(ans)
}

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val str = sc.next()

    var mm = mutableMapOf<String, Int>()
    var maxa = 0
    var res = ""
    for (i in 0 until n-1) {
        val temp = str.substring(i, i+2)
        mm[temp] = (mm[temp] ?: 0)+1
    }
    for ((key, value) in mm) {
        if (value > maxa) {
            maxa = value
            res = key
        }
    }
    println(res)

}

import kotlin.math.absoluteValue
import kotlin.math.pow

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var pattern = mutableListOf<String>()
    var pmap = mutableMapOf<String, Int>()
    if (n >= 2 && n <= 100) {

        for (i in 0..(n - 2)) {
            if (s.substring(i, i + 2) in pattern) {
                var count = pmap[s.substring(i, i + 2)]

                if (count != null) {
                    pmap[s.substring(i, i + 2)] = count + 1
                }
            } else {
                pattern.add(s.substring(i, i + 2))
                pmap.put(s.substring(i, i + 2), 1)
            }
        }
    }
    println(pmap.maxBy { it.value }?.key)
}

/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */
val scan = java.util.Scanner(System.`in`)
fun main() {
    scan.nextInt()
    var s = scan.next()
    var maxTwogram = ""
    var maxCount = 0
    for(i in 0 until s.length-1) {
        val twogram = s.substring(i, i+2)
        var count = 0
        for (j in i until s.length-1) {
            if(s.substring(j).startsWith(twogram)) count ++
        }
        if(maxCount < count) {
            maxTwogram = twogram
            maxCount = count
        }
    }
    println(maxTwogram)
}

val occur = HashMap<String, Int>()

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    for(i in 0 until n-1) {
        val t = s.substring(i, i+2)
        if(t in occur)
            occur[t] = occur[t]!! + 1
        else
            occur[t] = 1
    }
    println(occur.maxBy { it.value }!!.key)
}

import java.util.regex.Pattern

fun main(args: Array<String>) {
    val ss = twogram1()
    print(ss)
}

fun twogram1(): String?{
    val n = readLine()?.toInt() ?: 0
    val s = readLine().orEmpty()
    val chars = s.toList()
    return if(n == chars.size) {
        (0 until chars.size - 1).mapNotNull { i ->
            if (i + 1 < chars.size)
                chars[i].toString() + chars[i + 1].toString()
            else null
        }.groupBy { it }.maxBy { it.value.size }?.key
    } else ""
}

import java.util.*

/**
 * Kotlin Heroes: Practice 2
 * B. Двуграмма
 * http://codeforces.com/contest/1212/problem/B
 * */
class B

fun main() {
    readLine()
    val s = readLine()!!.toCharArray()
    val arr = Array(pos('Z', 'Z') + 1) { 0 }

    var max = 0
    var maxS = ""
    for (i in 1 until s.size) {
        val pos = pos(s[i - 1], s[i])
        if (++arr[pos] > max) {
            max = arr[pos]
            maxS = "${s[i - i]}${s[i]}"
        }
    }
    println(maxS)
}

fun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')

fun main() {
    val count = readLine()!!.toInt()
    val str = readLine()!!

    var max = Int.MIN_VALUE
    var maxStr = str.subSequence(0, 2)
    for (i in 0 .. count - 2) {
        val subStr = str.subSequence(i, i + 2)
        val count = subStr.count { subStr.contains(it) }
        if (count > max) {
            max = count
            maxStr = subStr
        }
    }
    print(maxStr)
}

import java.util.*

fun main() {
    val input = Scanner(System.`in`)

//    val n = input.nextLine().toInt()
    val s = input.nextLine().toString()
    var max = 0
    var sequence = ""

    s.windowed(2,1, false) { toTest ->
        var count = 0
        s.windowed(2,1, false) { toMatch ->
            if (toTest == toMatch) {
                count ++
            }
            if (count>max) {
                max = count
                sequence = toTest.toString()
            }
        }
    }

    println(sequence)
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map{it.toLong()}
//const val MOD = 1000000007

fun main(args:Array<String>){
    val n = readInt()
    val s = readLn()

    val skipString = s.substring(1, s.length-1)

    val list = s.asSequence()
            .chunked(2).map { it.joinToString("") }.toList()

    val skiplist = skipString.asSequence()
            .chunked(2).map { it.joinToString("") }.toList()

    val map = mutableMapOf<String, Int>()

    countGram(list, map)
    countGram(skiplist, map)

    var max = -1
    var key = ""
    map.forEach { t, u ->
        println("$t $u")
        if (u>max && t.length==2){
            max = u
            key = t
        }
    }
    println(key)

}

fun countGram(list: List<String>, map: MutableMap<String, Int>) {
    list.forEach {
        if (map.contains(it)) {
            val count = map[it]!!
            map[it] = count + 1
        } else {
            map[it] = 1
        }
    }
}

import java.util.*

fun main(args: Array<String>) {

    val reader = Scanner(System.`in`)

    fun twoGram(n: Int, s: String): String {
        var mostCommonTwoGram: Pair<String, Int> = Pair(s.substring(0, 1), 1)
        val twoGramOccurrences = mutableMapOf<String, Int>()
        for (i in 0..n - 2) {
            val twoGram = s.substring(i, i + 2)
            twoGramOccurrences[twoGram] = twoGramOccurrences.getOrDefault(twoGram, 0) + 1
            if (twoGramOccurrences[twoGram] ?: 0 > mostCommonTwoGram.second) {
                mostCommonTwoGram = Pair(twoGram, twoGramOccurrences[twoGram] ?: 0)
            }

        }
        return mostCommonTwoGram.first
    }
    println(twoGram(reader.nextInt(), reader.next()))
}

fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key

fun main(args: Array<String>) {
    println(args)
    println(args.size)
    if (args.size == 2) {
        val twoGram = twoGram(args[1])
        print(twoGram)
    }
}

fun main(args: Array<String>) {
    val t = 1 //readLine()!!.toInt()

    repeat(t) {
        val ma =  mutableMapOf<String, Int>()

        val n = readLine()!!.toInt()
        val s = readLine()!!

        var i=0
        while(i<n-1) {
            val ss = s.substring(i,i+2)

            if (!ma.containsKey(ss)) {
                ma.put(ss, 1)
            } else {
                 ma[ss]!!.plus(1)
            }
            i++
        }

        var ssmax = ""
        for (ss in ma.keys) {
            // println("${ss} ${ma[ss]}")
            if (!ma.containsKey(ssmax)) {
                ssmax = ss
            } else {
                if ( ma[ss]!! > ma[ssmax]!! ) ssmax=ss
            }
        }

        println(ssmax)

    }
}

fun readInts() = readLine()!!.split(' ').map(String::toInt)

fun main(){
    var n =  readLine()!!.toInt()
    var str = readLine()!!.toString()
    var ans = ""
    var ansCnt = 0
    for(i in 0 until (n - 1)){
        var curr = 0
        val newStr = str[i].toString() + str[i + 1].toString()
        for(j in (i + 1) until (n - 1)){
            val prStr = str[j].toString() + str[j + 1].toString()
            if(newStr == prStr){
                curr++
            }
        }
        if(curr > ansCnt){
            ansCnt = curr
            ans = newStr
        }
    }
    print(ans)
}

import java.util.regex.Pattern

fun main(args: Array<String>) {
    twogram()
}

fun twogram(): Pair<String, Int>?{
    val n = readLine()?.toInt() ?: 0
    val s = readLine().orEmpty()
    val chars = s.toList()
    if(chars.size == n) {
        val allPairs = chars.map { c ->
            chars.map {
                "$it" + "$c"
            }.distinct()
        }.flatten().distinct()
        val m = allPairs.map {
            val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower
            val matcher = pattern.matcher(s)
            var count = 0
            while (matcher.find()) count++
            it to count
        }.maxBy { it.second }
        return m
    }else return "" to 0
}

fun main(args: Array<String>) {
    val numberOfLines = readLine()?.toInt() ?: 0
    var string = readLine()
    val substrings = string?.chunked(2)
    val entries = mutableMapOf<String, Int>()

    for (i in 0 until numberOfLines) {
        val firstEntry = string?.get(i)
        val secondEntry = if (i == numberOfLines - 1) "" else string?.get(i + 1)
        val finalKey = "$firstEntry$secondEntry"

        if (entries.containsKey(finalKey)) {
            entries.merge(finalKey, 1) { old, value ->
                old + value
            }
        } else {
            entries[finalKey] = 1
        }
    }

    val max = entries.maxBy { it.value }
    println(max?.key)
    println(max?.value)
}

fun main(args: Array<String>) {
  val nbCharacters: Int = readLine()!!.toInt()
  val word: String = readLine()!!
  val map: MutableMap<String, Int> = mutableMapOf()
  for (i in 0 .. nbCharacters-2) {
    val w = word.substring(i, i+2)
    map.put(w, map.getOrElse(w) {0})
  }

  var maxVal = -1
  var comb = ""
  map.forEach { k, v ->
    if (v > maxVal) {
      comb = k
      maxVal = v
    }
  }
  print(comb)
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs

fun solve() {
    val n=readInt()
    val s=readLn().toCharArray()
    var m= mutableMapOf<String,Int>()
    for(i in 0..n-2) {
        val a=s[i].toString()+s[i+1].toString()
        m[a]=m[a]?:0+1
    }
    var maxx=0
    for(i in m){
        maxx= maxOf(i.value,maxx)
    }
    for(i in m){
        if(i.value==maxx){
            print(i.key)
            return
        }
    }
}

fun main() {
    var T=1
//    T = readInt()
    for (t in 1..T) { solve() }
}

import java.util.Scanner
fun main(args: Array<String>) {
    //creating Scanner object
    val read = Scanner(System.`in`)

   var num1 = Integer.valueOf(readLine())
   var num2 = readLine()!!
   val myMap = mutableMapOf<String,Int>()
   var x:Int = 1
   while(x < num1){
      var str = "${num2.get(x-1)}${num2.get(x)}"
      x++
      if(myMap.containsKey(str)){
         myMap.merge(str , 1 , Int::plus)
      }else{
         myMap.plus(Pair(str, 1))
      }
   }
   var fre:Int = 0
   var final_str = ""
   for(itr in myMap.iterator()){
      if(itr.value > fre){
         fre = itr.value
         final_str = itr.key
      }
   }
   print(final_str)

}

import java.util.HashMap
import java.util.concurrent.atomic.AtomicInteger

/**
 * Created by azhdanov on 07.09.2019.
 */
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val n = readInt()
    val s = readLn()
    val map = HashMap<String, AtomicInteger>()
    var maxCounts = 0;
    var twoGramma : String? = null
    for (i in 0 .. n - 2) {
        val candidate = s.subSequence(i, i + 2)
        val cnt = map.getOrDefault(candidate.toString(), AtomicInteger(0)).incrementAndGet()
        if (cnt > maxCounts) {
            maxCounts = cnt
            twoGramma = candidate.toString()
        }
    }
    if (twoGramma != null) {
        println(twoGramma)
    }
}

        fun main(arguments: Array<String>){
            val length = Integer.parseInt(readLine()!!);
            val string = readLine()!!;

            var best_index = 0;
            var best_count = 0;

            var i = 0;
            while(i < (length - 1)){
                var count = 1;
                val reference1 = string.get(i);
                val reference2 = string.get(i + 1);

                var j = i + 1;
                while(j < (length - 1)){
                    val char1 = string.get(j);
                    val char2 = string.get(j);

                    if(reference1 == char1 && reference2 == char2){
                        count = count +  1;
                    }

                    j = j + 1;
                }

                if(count > best_count){
                    best_count = count;
                    best_index = i;
                }

                i = i + 1;
            }

            println(string.substring(best_index, best_index + 2));
        }

fun main() {
    val inputLen = readLine()?.toInt()
    println(readLine()?.let { input ->
        val map = mutableMapOf<String, Int>()
        for (i in 0 until inputLen?.dec()!!) {
            input.substring(i, i.plus(2)).let { tg ->
                println("i=$i and tg=$tg")
                map[tg] = map[tg]?.inc() ?: 1
            }
        }
        map.maxBy {
            it.value
        }?.key
    })
}

val scan = java.util.Scanner(System.`in`)
fun main() {
    scan.nextInt()
    var s = scan.nextLine()
    var maxTwogram = ""
    var maxCount = 0
    for(i in 0 until s.length-1) {
        val twogram = s.substring(i, i+2)
        var count = 0
        for (j in i until s.length-1) {
            if(s.substring(j).startsWith(twogram)) count ++
        }
        if(maxCount < count) {
            maxTwogram = twogram
            maxCount = count
        }
    }
    print(maxTwogram)
}

import java.util.StringTokenizer
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.InputStream
import java.util.HashMap
import kotlin.math.max

fun main() {

    R.init(System.`in`)
    var n = R.nextInt()
    var s = R.next()
    val map:HashMap<String,Int> = HashMap<String,Int>();
    var ans=0
    var count=0
    for(i in 0..n-2){
        var x = s.substring(i,i+2)
        if(map.containsKey(x)){
            map.put(x,map.getValue(x)+1)
        }
        else{
            map.put(x,1);
        }
        ans  = maxOf(ans,map.getValue(x))
        count++
    }
    println(ans)

}

internal object R {
    private lateinit var reader: BufferedReader
    private lateinit var tokenizer: StringTokenizer
    fun init(input: InputStream) {
        reader = BufferedReader(InputStreamReader(input))
        tokenizer = StringTokenizer("")
    }

    fun next(): String {
        while (!tokenizer.hasMoreTokens()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextDouble() = next().toDouble()
    fun nextLong() = next().toLong();
}

fun twoGram(input: String) = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key

fun main(args: Array<String>) {
    if (args.size == 2) {
        val twoGram = twoGram(args[1])
        println(twoGram)
    }
}

fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var i = 0
    val h = HashMap<String, Int>()
    while (i <= n - 2) {
        val tg = s.take(2)
        h[tg] = (h[tg] ?: 0) + 1
        i++
    }
    var max = Int.MIN_VALUE
    var tg = ""
    for ((k,v) in h.entries) {
        if (v > max) {
            tg = k
            max = v
        }
    }
    println(tg)
}

fun main() {
    readLn()
    val s = readLn()
    val twoGrams = mutableMapOf<String, Int>()

    for (i in 0 until s.length - 1) {
        val twoGram = s.substring(i, i + 2)
        twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) (twoGrams[twoGram] ?: + 1) else 1
    }

    println(twoGrams.maxBy { it.value }?.key)
}

// Input Reader
private fun readLn() = readLine()!!

import java.util.*

fun main(args: Array<String>) {
    val cin = Scanner(System.`in`)
    val len = cin.nextInt()
    val str = cin.next()

    val dict = HashMap<String, Int?>()
    for (i in 0 until len - 2) {
        if (!dict.containsKey(str.substring(i, i + 2))) {
            dict[str.substring(i, i + 2)] = 0
        }
        dict[str.substring(i, i + 2)] = dict[str.substring(i, i + 2)]!! + 1
    }

    var ans = ""
    var topMatch = 0
    for (cur in dict) {
        if (cur.value!! > topMatch) {
            topMatch = cur.value!!
            ans = cur.key
        }
    }
    println(ans)
}

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg= Pair(0, "")
        str.forEach { f ->
            str.substring(1).forEach {s ->
                val match = "$f$s"
                val times = match.toRegex().findAll(str).count()
                if(times > tg.first)
                    tg = Pair(times, match)
            }
        }
       return tg.second
    }

}

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg= Pair(0, "")
        for(i in 0 until n-2){
            val match = str.substring(i, i+2)
            val times = match.toRegex().findAll(str).count()
            if(times > tg.first)
                tg = Pair(times, match)
        }
       return tg.second
    }

}

import java.util.*
import kotlin.collections.HashMap

fun main() {
    val scanner = Scanner(System.`in`)
    val input = scanner.nextLine().trim()

    var result: HashMap<String, Int> = HashMap()
    for(i in 0 until input.length - 2) {
        for(j in i + 1 until input.length) {
            if (input[i] == input[j]) {
                val key = String(charArrayOf(input[i], input[j]));
                var amount = result.get(key)
                if (amount == null) {
                    result.put(key, value = 1)
                } else {
                    result.put(key, amount + 1)
                }
            }
        }
    }
    val sorted = result.toSortedMap(compareBy { it })
    println(sorted)
}

fun main(args : Array<String>) {
    val length = readLine()!!.toInt()
    val input = readLine()!!
    val twoGramMap = mutableMapOf<String, Int>()
    for (i in 0..length-2) {
        val twoGram = input.subSequence(i, i+2).toString()
        if (twoGramMap.containsKey(twoGram)) twoGramMap[twoGram]!!.inc() else twoGramMap[twoGram] = 1
    }

    println(twoGramMap.entries.maxWith(Comparator { o1, o2 -> o1.value.compareTo(o2.value) })?.key)
}

import java.util.*

/**
 * Kotlin Heroes: Practice 2
 * B. Двуграмма
 * http://codeforces.com/contest/1212/problem/B
 * */
class B

fun main() {
    readLine()
    val s = readLine()!!.toCharArray()
    val arr = Array(pos('Z', 'Z') + 1) { 0 }

    var max = 0
    var maxS = ""
    for (i in 1 until s.size) {
        val pos = pos(s[i - 1], s[i])
        if (++arr[pos] > max) {
            max = arr[pos]
            maxS = "${s[i - i]}${s[i]}"
        }
    }
    println(maxS)
}

fun pos(a: Char, b: Char) = (a - 'A') * ('Z' - 'A' + 1) + (b - 'A')

fun main(args: Array<String>) {
    readLine()
    val s = readLine()!!
    println(s.windowed(2).groupingBy { it }.eachCount().values.max()!!)
}

import java.util.*
import kotlin.collections.HashMap

fun main() {
    val scanner = Scanner(System.`in`)
    val input = scanner.nextLine().trim()

    var result: HashMap<String, Int> = HashMap()
    for(i in 0 until input.length - 1) {
        val j = i + 1
        if (input[i] == input[j]) {
            val key = String(charArrayOf(input[i], input[j]));
            var amount = result.get(key)
            if (amount == null) {
                result.put(key, value = 1)
            } else {
                result.put(key, amount + 1)
            }
        }
    }
    println(result.maxBy { it.value })
}

fun twoGram(input: String) {
    val result = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key
    println(result)
}

fun main(args: Array<String>) {
    if (args.size == 2)
        twoGram(args[1])
}

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg= Pair(0, "")
        for(i in 0 until n-2){
            var sss = str
            val match = str.substring(i, i+2)
            var times = 0;
            while(true){
                val find = match.toRegex().find(sss)
                if(find != null && find?.range?.first!! > -1){
                    times++
                    sss = sss.removeRange(0, find.range.first+1)
                }else{
                    break;
                }
            }

            if(times > tg.first)
                tg = Pair(times, match)
        }
       return tg.second
    }

}

fun main() {
    readLine()
    val s = readLine()
    val mp = mutableMapOf<String, Int>()
    var ans = ""
    var mx = -1
    for (i in 1 until s!!.length) {
        val str = "" + s[i - 1] + s[i]
        if (str in mp) {
            mp[str]!!.plus(1)
        } else {
            mp[str] = 1
        }
        if (mp[str]!! > mx) {
            ans = str;
            mx = mp[str]!!
        }
    }
    println(ans)
}

fun main(args: Array<String>) {
        val ma =  mutableMapOf<String, Int>()

        val n = readLine()!!.toInt()
        val s = readLine()!!

        var i=0
        var ans = -1
        var sans: String = s
        while(i<n-1) {
            val ss = s.substring(i, i+2)

            if (!ma.containsKey(ss)) {
                ma.put(ss, 1)
            } else {
                    if(ma[ss]!! + 1 > ans){

                         ans = ma[ss]!! + 1
                         sans = ss
                    }
                 ma[ss]!!.plus(1)
            }
            i++
        }

     println(sans)

}

fun main() {
    readLn()
    val s = readLn()
    val twoGrams = mutableMapOf<String, Int>()

    for (i in 0 until s.length - 1) {
        val twoGram = s.substring(i, i + 2)
        twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) twoGrams[twoGram]?.plus(1)!! else 1
    }

    println(twoGrams)
    println(twoGrams.maxBy { it.value }?.key)
}

// Input Reader
private fun readLn() = readLine()!!

import java.util.*
import kotlin.collections.HashMap

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val length = scanner.nextInt()
    val string = scanner.next()
    println(find(length, string))
}

fun find(length: Int, string: String): String {
    val map = HashMap<String, Int>()
    for (i in 0 until length - 1) {
        val str = string.substring(i, i + 2)
        if (map.containsKey(str)) {
            map[str]!!.plus(1)
        } else {
            map[str] = 0
        }
    }
    return map.maxBy { it.value }!!.key
}

import java.util.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun readIntArr(): MutableList<Int> {
    val l = readLine()!!.split(" ").map { it.toInt() }
    var m : MutableList<Int> = ArrayList()
    for(x in l) m.add(x)
    return m
}

fun min(a: Int, b: Int) : Int {
    return if(a<b) a else b
}

fun max(a: Int, b: Int) : Int {
    return if(a>b) a else b
}

fun ispal(s: String): Boolean {
    var i = 0
    var j = s.length-1
    while(i<j){
        if(s[i++] != s[j--]) return false
    }
    return true
}

fun issame(s: String): Boolean {
    for(i in 1..s.length){
        if(s[0]!=s[i]) return false
    }
    return true
}

fun rot(s: String): String{
    return s.substring(1) + s[0]
}

fun main() {
    var n = readInt()
    var s = readLn()
    var m = mutableMapOf<String, Int>()

    for(i in 0..n-3){
        val ss = s.substring(i,i+2)
        if(!m.containsKey(ss)) m.set(ss,0)
        m.computeIfPresent(ss) { _, v -> v + 1 }
    }

    var best = 0
    for((k,v) in m){
        if(v>best){
            best = v
            s = k
        }
    }

    println(s);
}

import java.util.*

fun main() {
    Scanner(System.`in`).use { scanner ->
        val stringLength = scanner.nextInt()
        val string = scanner.next()
        val twoGram = TwoGramSolver.solve(stringLength, string)
        println("${twoGram[0]}${twoGram[1]}")
    }
}

private object TwoGramSolver {

    internal fun solve(stringLength: Int, string: String): Array<Char> {
        if (stringLength == 2 || stringLength == 3) {
            return arrayOf(string[0], string[1])
        }

        val twoGrams = mutableMapOf<Array<Char>, Int>()
        var maxTwoGram = arrayOf(string[0], string[1])
        var maxTwoGramValue = 1

        for (index in 1 until stringLength - 1) {
            val twoGram = arrayOf(string[index], string[index + 1])

            val twoGramCount = (twoGrams[twoGram] ?: 0).inc()
            twoGrams[twoGram] = twoGramCount

            if (twoGramCount > maxTwoGramValue) {
                maxTwoGram = twoGram
                maxTwoGramValue = twoGramCount
            }
        }

        return maxTwoGram
    }
}

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg= Pair(0, "")
        for(i in 0 until n-2){
            var sss = str.removeRange(0, i)
            val match = str.substring(i, i+2)
            var times = 0;
            while(true){
                val find = match.toRegex().find(sss)
                if(find != null && find?.range?.first!! > -1){
                    times++
                    sss = sss.removeRange(0, find.range.first+1)
                }else{
                    break;
                }
            }

            if(times >= tg.first)
                tg = Pair(times, match)
        }
       return tg.second
    }

}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs

fun solve() {
    val n=readInt()
    val s=readLn().toCharArray()
    var m= mutableMapOf<Int,Int>()
    for(i in 0..n-2) {
        val a=100*(s[i]).toInt()+(s[i+1]).toInt()
        m[a]=m[a]?:0+1
    }
    var maxx=0
    for(i in m){
        maxx= maxOf(i.value,maxx)
    }
    for(i in m){
        if(i.value==maxx){
            val c=(i.key%100).toChar()
            val d=(i.key/100).toChar()
            print(c)
            print(d)
            return
        }
    }
}

fun main() {
    var T=1
//    T = readInt()
    for (t in 1..T) { solve() }
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val n = readInt()
    val s = readLn()

    val ps = s.asSequence().zipWithNext().toList()

    val x = ps.sortedBy {
        if (it.first == it.second) {
            it.second
        } else {
            it.first
        }
    }
    var count = 1
    var max = 0
    var r = x[0]
    for (i in 0 until n - 2) {
        if (x[i] == x[i + 1]) {
            count++
        } else {
            max = if (max < count) {
                r = x[i]
                count
            } else {
                max
            }
            count = 1
        }
    }
    print(r.first)
    println(r.second)

}

/*
val (n, k)  = readInts()
val li: MutableList<Int> = readInts() as MutableList<Int>
li.sort()
println(li)
if(li[k - 1] == li[k]){
    println(-1)
} else {
    print(li[k - 1])
}
*/

import java.util.*

fun main() {
    val input = readLine()

    if (input == null) {
        return
    }

    val map = mutableMapOf<Pair<Char, Char>, Int>()

    input.zipWithNext().forEach {
        if (map.get(it) == null) {
            map.put(it, 1)
        } else {
            map.put(it, map.get(it)!! + 1)
        }
    }

    var maxPair: Pair<Char, Char>? = null
    var maxCount = 0

    for ((pair, count) in map) {
        if (count > maxCount) {
            maxPair = pair
            maxCount = count
        }
    }

    if (maxPair == null) {
        return
    }

    print(maxPair.component1())
    print(maxPair.component2())
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    var n = readInt()
    var s = readLn()
    var m = HashMap<String,Int>()

    for (i in 0..s.length-2) {
        var str = s[i].toString() + s[i + 1]
        if (m.containsKey(str))
            m[str] = m[str]!! + 1
        else
            m[str] = 0
    }
    var mx = Pair("", 0)
    for ((k,v) in m) {
        if (mx.second < v) {
            mx = Pair(k,v)
        }
    }
    print(mx.first)
}

import java.util.regex.Pattern

fun main(args: Array<String>) {
    val ss = twogram1()
    print(ss?.first)
}

fun twogram1(): Pair<String, Int>?{
    val n = readLine()?.toInt() ?: 0
    val s = readLine().orEmpty()
    val chars = s.toList()
    if(chars.size == n && chars.size > 1) {
        val allPairs = chars.map { c ->
            chars.map {
                "$it" + "$c"
            }.distinct()
        }.flatten().distinct()
        val m = allPairs.map {
            val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower
            val matcher = pattern.matcher(s)
            var count = 0
            while (matcher.find()) count++
            it to count
        }.maxBy { it.second }
        return m
    }else return s to 0
}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val value = scanner.nextInt()
    if (value in 2..100) {
        val text = scanner.next()
        if (text.length != value) {
            print("wrong")
        } else {
            var maxi = 0
            var gram = ""
            repeat(text.length - 1) { _times ->
                val sub = text.substring(_times, _times + 2)
                val temp = calll(sub, text)
                if (temp > maxi) {
                    maxi = temp
                    println("sonuc : $maxi")
                    gram = sub
                }
            }
            println(gram)
        }
    } else {
        print("Wrong")
    }
}

fun calll(sub: String, value: String): Int {
    var cnt = 0
    repeat(value.length - 1) { k ->
        if (value[k] == sub[0] && value[k + 1] == sub[1])
            cnt++
    }
    return cnt
}

fun main(args:Array<String>){
	var str = readLine()!!;
    var tm = mutableMapOf<String,Int>();
    for(i in 0..str.length-2){
        var tc = str[i].toString() + str[i+1].toString();
        tm[tc]=tm.getOrDefault(tc,0)+1;
    }
    var r = tm.maxBy({it.value});
    println(r?.key)
}

fun main(args : Array<String>) {
    var n = readLine()!!.toInt()
    var str = readLine()!!
    println(str.substring(0..1))
}

fun main() {
    val n = readLine()!!.toInt()
    val string = readLine()!!
    val grams = ArrayList<String>(n)
    for (i in 0 until n - 1) {
        grams.add(string.substring(i..i + 1))
    }
    print(grams.maxBy { grams.count { grams.contains(it) } })
}

fun main() {
    val l = readLine()!!.toInt()
    val s = readLine()!!

    val r :HashMap<String, Int> = hashMapOf()

    for (i in 0 until l - 1) {
        val x = s.substring(i, i + 2)
        if (r.containsKey(x)) {
            r[x] = r[x]!!.plus(1)
        } else {
            r[x] = 0
        }
    }

    val z = -1
    var y = ""
    for (j in r) {
        if (j.value > z) {
            y = j.key
        }
    }
    println(y)
}

import java.util.*
import kotlin.collections.ArrayList

fun main() {
    val input = Scanner(System.`in`)
    val n = input.nextInt()
    val s = input.next()

    val letters = s.split("")
    val iSize = letters.size - 2
    val dGrams: ArrayList<String> = ArrayList()
    for (i in 0..iSize) {
        dGrams.add("${letters[i]}${letters[i + 1]}")
    }

    var mGram = Int.MIN_VALUE
    var mIndex = 0
    val count: ArrayList<Pair<String, Int>> = ArrayList()
    for (i in dGrams) {
        var exists = false
        var gIndex = 0
        count.forEachIndexed { index, pair ->
            if (pair.first == i) {
                exists = true
                gIndex = index
                return@forEachIndexed
            }
        }
        if (!exists) {
            count.add(Pair(i, 1))
        } else {
            val num = count[gIndex].second + 1
            count[gIndex] = Pair(i, num)
            if (num > mGram) {
                mGram = num
                mIndex = gIndex
            }
        }
    }

    print(count[mIndex].first)
}

fun main() {
    val inputLen = readLine()?.toInt()
    println(readLine()?.let { input ->
        val map = mutableMapOf<String, Int>()
        for (i in 0 until inputLen?.dec()!!) {
            input.substring(i, i.plus(2)).let { tg ->
                println("i=$i and tg=$tg")
                map[tg] = map[tg]?.inc() ?: 1
            }
        }
        map.maxBy {
            it.value
        }?.key
    })
}

import java.util.Scanner
fun main(args: Array<String>) {
    //creating Scanner object
    val read = Scanner(System.`in`)

   var num1 = Integer.valueOf(readLine())
   var num2 = readLine()!!
   val myMap = mutableMapOf<String,Int>()
   var x:Int = 1
   while(x < num1){
      var str = "${num2.get(x-1)}${num2.get(x)}"
      x++
      if(myMap.containsKey(str)){
         myMap.merge(str , 1 , Int::plus)
      }else{
         myMap.plus(Pair(str, 1))
      }
   }
   var fre:Int = 0
   var final_str = ""
   for(itr in myMap.iterator()){
      if(itr.value > fre){
         fre = itr.value
         final_str = itr.key
      }
   }
   print(final_str)

}

fun twoGram(input: String) {
    val result = input.windowed(2).groupingBy { it }.eachCount().maxBy { it.value }?.key
    println(result)
}

fun main(args: Array<String>) {
//    if (args.size == 2)
//        twoGram(args[1])
    print("AB")
}

fun main() {
    readLine()
    val s = readLine()
    val mp = mutableMapOf<String, Int>()
    var ans = ""
    var mx = -1
    for (i in 1 until s!!.length) {
        val str = "" + s[i - 1] + s[i]
        if (str in mp) {
            mp[str]!!.plus(1)
        } else {
            mp[str] = 1
        }
        if (mp[str]!! > mx) {
            ans = str;
            mx = mp[str]!!
        }
    }
    println(ans)
}

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg= Pair(0, "")
        str.forEach { f ->
            str.substring(1).forEach {s ->
                val match = "$f$s"
                val times = match.toRegex().findAll(str).count()
                if(times > tg.first)
                    tg = Pair(times, match)
            }
        }
       return tg.second
    }

}

import java.util.Scanner

/*
	Scanner scanner_variable = Scanner(System.`in`)
	//Reading Int input
	scanner_variable.nextInt()
	//Reading Float Input
	scanner_variable.nextFloat()
	//Reading Double Input
	scanner_variable.nextDouble()
	//Reading Boolean Input
	scanner_variable.nextBoolean()
	//Reading Short Input
	scanner_variable.nextShort()
	//Reading Long Input
	scanner_variable.nextLong()
	//Reading String Input
	scanner_variable.nextLine()

	toChar() – To convert a type to Char type.
	toInt() – To convert a type to Int type.
	toLong() – To convert a type to Long type.
	toFloat() – To convert a type to Float type.
	toDouble() – To convert a type to Double type.
	toByte() – To convert a type to Byte type.
	toShort() – To convert a type to Short type.

	val parts = str.split(" ")

	fun meAjuda(L: List<String>) {
		for(s in L)
			println(s)
	}
*/

fun main() {
	val n = readLine()
	val str = readLine().toString()

	var cur = -1
	var ans = "AA"

	for(a in 'A'..'Z') {
		for(b in a..'Z') {
			var s = a.toString() + b.toString()
			var par = 0
			for(i in 1..(str.length-1))
				if(s == str.get(i - 1).toString() + str.get(i).toString())
					par++
			if(par > cur) {
				ans = s
				cur = par
			}
		}
	}
	println(ans)
}

import java.util.*

fun main() {
    val input = Scanner(System.`in`)

//    val n = input.nextLine().toInt()
    val s = input.nextLine().toString()
    var max = 0
    var sequence = ""

    s.windowed(2,1, false) { toTest ->
        var count = 0
        s.windowed(2,1, false) { toMatch ->
            if (toTest == toMatch) {
                count ++
            }
            if (count>max) {
                max = count
                sequence = toTest.toString()
            }
        }
    }

    println(sequence)
}

fun main(args: Array<String>) {
        val ma =  mutableMapOf<String, Int>()

        val n = readLine()!!.toInt()
        val s = readLine()!!

        var i=0
        var ans = -1
        var sans: String = s
        while(i<n-1) {
            val ss = s.substring(i, i+2)

            if (!ma.containsKey(ss)) {
                ma.put(ss, 1)
            } else {
                    if(ma[ss]!! + 1 > ans){

                         ans = ma[ss]!! + 1
                         sans = ss
                    }
                 ma[ss]!!.plus(1)
            }
            i++
        }

     println(sans)

}

fun main() {
    readLn()
    val s = readLn()
    val twoGrams = mutableMapOf<String, Int>()

    for (i in 0 until s.length - 1) {
        val twoGram = s.substring(i, i + 2)
        twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) (twoGrams[twoGram] ?: + 1) else 1
    }

    println(twoGrams.maxBy { it.value }?.key)
}

// Input Reader
private fun readLn() = readLine()!!

val scan = java.util.Scanner(System.`in`)
fun main() {
    scan.nextInt()
    var s = scan.nextLine()
    var maxTwogram = ""
    var maxCount = 0
    for(i in 0 until s.length-1) {
        val twogram = s.substring(i, i+2)
        var count = 0
        for (j in i until s.length-1) {
            if(s.substring(j).startsWith(twogram)) count ++
        }
        if(maxCount < count) {
            maxTwogram = twogram
            maxCount = count
        }
    }
    print(maxTwogram)
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val n = readInt()
    val s = readLn()

    val ps = s.asSequence().zipWithNext().toList()

    var max = 0
    var count = 1
    var r = ps[0]
    for(i in 0 until n - 2){
        if(ps[i] == ps[i + 1]){
            count++
        } else {
            max = if(max < count) {
                r = ps[i]
                count
            } else {
                max
            }
            count = 1
        }
    }
    print("${r.first}${r.second}")

}

import java.util.*

fun main() {
    Scanner(System.`in`).use { scanner ->
        val stringLength = scanner.nextInt()
        val string = scanner.next()
        println(TwoGramSolver.solve(stringLength, string))
    }
}

private object TwoGramSolver {

    internal fun solve(stringLength: Int, string: String): String {
        val twoGrams = mutableMapOf<String, Int>()
        var maxTwoGram: Pair<String, Int>? = null

        for (index in 0 until stringLength - 1) {
            val twoGramStringBuilder = StringBuffer(2)
            twoGramStringBuilder.append(string[index])
            twoGramStringBuilder.append(string[index + 1])
            val twoGram = twoGramStringBuilder.toString()

            val twoGramCount = (twoGrams[twoGram] ?: 0).inc()
            twoGrams[twoGram] = twoGramCount

            if (maxTwoGram == null) {
                maxTwoGram = twoGram to twoGramCount
                break
            }

            if (twoGramCount > maxTwoGram.second) {
                maxTwoGram = twoGram to twoGramCount
            }
        }

        return maxTwoGram!!.first
    }
}

import java.util.*
import kotlin.collections.HashMap

fun main() {
    val scanner = Scanner(System.`in`)
    val input = scanner.nextLine().trim()

    var result: HashMap<String, Int> = HashMap()
    for(i in 0 until input.length - 1) {
        val j = i + 1
        if (input[i] == input[j]) {
            val key = String(charArrayOf(input[i], input[j]));
            var amount = result.get(key)
            if (amount == null) {
                result.put(key, value = 1)
            } else {
                result.put(key, amount + 1)
            }
        }
    }
    println(result.maxBy { it.value })
}

import java.util.*

fun main(args: Array<String>) {
    val cin = Scanner(System.`in`)
    val len = cin.nextInt()
    val str = cin.next()

    val dict = HashMap<String, Int?>()
    for (i in 0 until len - 2) {
        if (!dict.containsKey(str.substring(i, i + 2))) {
            dict[str.substring(i, i + 2)] = 0
        }
        dict[str.substring(i, i + 2)] = dict[str.substring(i, i + 2)]!! + 1
    }

    var ans = ""
    var topMatch = 0
    for (cur in dict) {
        if (cur.value!! > topMatch) {
            topMatch = cur.value!!
            ans = cur.key
        }
    }
    println(ans)
}

fun main(args: Array<String>) {

    // reading the input and saving it
    val amountOfLetters = readLine()!!.toInt()
    val inputString = readLine()!!

    // the var will be the temporary string containing the two-gram to be checked while traversing through
    // the input String
    var tempString: String

    // the hashmap will contain the two-gram string along with the occurences
    // it will be initialied with the first two-gram and its counter value of 1
    var counterHashMap: MutableMap<String,Int> = mutableMapOf(inputString.subSequence(0,2).toString() to 1)

    // iterating over the string, saving each two-gram in a temporary string
    // checking if the two-gram exists in the hashmap
    // yes: increase the value, no: adding the two-gram to the hasmap and initializing the value to 1
    for((index,character) in inputString.withIndex()) {
        // to avoid the indexOutOfBounce exception, the index is being checked
        if(index == inputString.length-1) break
        // skip the first 2 letters as they have been added in the initialisation
        if(index == 0) continue;

        // concatenating two chars
        tempString = "" + character + inputString[index+1]
        println(tempString)
        // check if the two-gram is in the haspMap
        if(tempString in counterHashMap) {
            // increase the value if it does
            counterHashMap.set(tempString, counterHashMap.get(tempString)!!.plus(1))
        } else {
            // add the value to hashmap if it doesnt with value 1
            counterHashMap.put(tempString,1)
        }
    }
    println(counterHashMap.maxBy{it.value}.toString().subSequence(0,2))
}

import kotlin.io.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    var n = readInt()
    var str = readStrings()[0]

    var m = mutableMapOf<String, Int>()
    var setted = false
    var best = String()
    for(i in 0..str.length-2) {
        var s = str[i].toString()+str[i+1].toString();
        if(m.containsKey(s)) {
            m[s] = m[s]!!+1
            if(setted) {
                if(m[s]!!>m[best]!!) {
                    best=s
                }
            }else {
                best=s
            }
        }else {
            m[s]=1
        }
    }

    println("$best")
}

private fun f(str: String): String {
    val counts = (0..str.length - 2).fold(mutableMapOf<CharSequence, Int>()) { collector, i ->
        val twoGram = str.subSequence(i, i + 2)
        collector[twoGram] = collector.getOrDefault(twoGram, 0) + 1
        collector
    }
    return counts.maxBy { it.value }?.key.toString()
}

fun main() {
    val str = readLn()
    println(f(str))
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    var n = readInt()
    var s = readLn()
    var m = HashMap<String,Int>()

    for (i in 0..s.length-2) {
        var str = s[i].toString() + s[i + 1]
        if (m.containsKey(str))
            m[str] = m[str]!! + 1
        else
            m[str] = 0
    }
    var mx = Pair("", 0)
    for ((k,v) in m) {
        if (mx.second < v) {
            mx = Pair(k,v)
        }
    }
    print(mx.first)
}

fun main(args: Array<String>) {
  val nbCharacters: Int = readLine()!!.toInt()
  val word: String = readLine()!!
  val map: MutableMap<String, Int> = mutableMapOf()
  for (i in 0 .. nbCharacters-2) {
    val w = word.substring(i, i+2)
    map.put(w, map.getOrElse(w) {0})
  }

  var maxVal = -1
  var comb = ""
  map.forEach { k, v ->
    if (v > maxVal) {
      comb = k
      maxVal = v
    }
  }
  print(comb)
}

fun main() {
    val l = readLine()!!.toInt()
    val s = readLine()!!

    val r :HashMap<String, Int> = hashMapOf()

    for (i in 0 until l - 1) {
        val x = s.substring(i, i + 2)
        if (r.containsKey(x)) {
            r[x] = r[x]!!.plus(1)
        } else {
            r[x] = 0
        }
    }

    val z = 0
    var y = ""
    for (j in r) {
        if (j.value > z) {
            y = j.key
        }
    }
    println(y)
}

import java.util.regex.Pattern

fun main(args: Array<String>) {
    twogram()
}

fun twogram(): Pair<String, Int>?{
    val n = readLine()?.toInt() ?: 0
    val s = readLine().orEmpty()
    val chars = s.toList()
    if(chars.size == n) {
        val allPairs = chars.map { c ->
            chars.map {
                "$it" + "$c"
            }.distinct()
        }.flatten().distinct()
        val m = allPairs.map {
            val pattern = Pattern.compile(it) //case insensitive, use [g] for only lower
            val matcher = pattern.matcher(s)
            var count = 0
            while (matcher.find()) count++
            it to count
        }.maxBy { it.second }
        return m
    }else return "" to 0
}

import java.util.Scanner
fun main(args: Array<String>) {
    //creating Scanner object
    val read = Scanner(System.`in`)

   var num1 = Integer.valueOf(readLine())
   var num2 = readLine()!!
   val myMap = mutableMapOf<String,Int>()
   var x:Int = 1
   while(x < num1){
      var str = "${num2.get(x-1)}${num2.get(x)}"
      x++
      if(myMap.containsKey(str)){
         myMap.merge(str , 1 , Int::plus)
      }else{
         myMap.plus(Pair(str, 1))
      }
   }
   var fre:Int = 0
   var final_str = ""
   for(itr in myMap.iterator()){
      if(itr.value > fre){
         fre = itr.value
         final_str = itr.key
      }
   }
   print(final_str)

}

fun main() {
    val num = readLine()!!.toInt()
    val str = readLine()!!.take(num)
    println(bigramCountMax(str))
}

fun bigramCountMax(str: String): String {
    var maxCount = 0
    var leadSubstring = str.take(2)
    val leadChar = str[0]
    for ((index, value) in str.substring(1).withIndex()) {
        var count = 0
        if (leadChar == value) {
            count = countSubstring(leadChar + value.toString(), str)
        } else {
            count = countSubstring(leadChar + value.toString(), str) + countSubstring(value.toString() + leadChar, str)
        }
        if(count > maxCount) {
            maxCount = count
            leadSubstring = leadChar + value.toString()
        }
    }
    return leadSubstring
}

fun countSubstring(s: String, sub: String): Int = s.split(sub).size - 1

object programkt{
//object TwoGram {
    @JvmStatic
    fun main(vararg args: String){
        val n = readLine()!!.toInt()
        val str = readLine()!!
        val result = exec(n, str)
        println(result)
    }

    fun exec(n: Int, str: String): String {
        var tg= Pair(0, "")
        for(i in 0 until n-2){
            var sss = str
            val match = str.substring(i, i+2)
            var times = 0;
            while(true){
                val find = match.toRegex().find(sss)
                if(find != null && find?.range?.first!! > -1){
                    times++
                    sss = sss.removeRange(0, find.range.first+1)
                }else{
                    break;
                }
            }

            if(times >= tg.first)
                tg = Pair(times, match)
        }
       return tg.second
    }

}

fun main() {
    readLn()
    val s = readLn()
    val twoGrams = mutableMapOf<String, Int>()

    for (i in 0 until s.length - 1) {
        val twoGram = s.substring(i, i + 2)
        twoGrams[twoGram] = if (twoGrams.containsKey(twoGram)) (twoGrams[twoGram] ?: + 1) else 1
    }

    println(twoGrams.maxBy { it.value }?.key)
}

// Input Reader
private fun readLn() = readLine()!!

import java.util.*
import kotlin.collections.HashMap

fun main() {
    val scanner = Scanner(System.`in`)
    val input = scanner.nextLine().trim()

    var result: HashMap<String, Int> = HashMap()
    for(i in 0 until input.length - 1) {
        val j = i + 1
        val key = String(charArrayOf(input[i], input[j]));
        var amount = result.get(key)
        if (amount == null) {
            result.put(key, value = 1)
        } else {
            result.put(key, amount + 1)
        }
    }
    println(result.maxBy { it.value })
}