Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#!/usr/bin/env python3

(R, C, K), *D = [[*map(int,o.split())] for o in open(0)]
D = {(r - 1, c - 1) : v for r, c, v in D}

dp = [[[-1] * C for _ in [None] * R] for _ in [None] * 4]

dp[0][0][0] = 0
for r in range(R):
    for c in range(C):
        v = D.get((r, c), None)
        for i in range(4):
            if dp[i][r][c] > -1:
                if r < R - 1:
                    dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[i][r][c])
                if c < C - 1:
                    dp[i][r][c + 1] = max(dp[i][r][c + 1], dp[i][r][c])
                if i < 3 and v:
                    if r < R - 1:
                        dp[0][r + 1][c] = max(dp[0][r + 1][c], dp[i][r][c] + v)
                    if c < C - 1:
                        dp[i + 1][r][c + 1] = max(dp[i + 1][r][c + 1], dp[i][r][c] + v)

v = D.get((R - 1, C - 1), 0)
for i in range(3):
    dp[i][R - 1][C - 1] += v
print(max(dp[i][R - 1][C - 1] for i in range(4)))

### FIXED CODE ###

import sys

def solve():
    input = sys.stdin.readline
    R, C, K = map(int, input().split())
    item = [[0 for _ in range(C)] for r in range(R)]
    for _ in range(K):
        r, c, k = map(int, input().split())
        item[r-1][c-1] = k
    
    DP = [[[-1 for _ in range(C)] for r in range(R)] for i in range(4)]
    DP[0][0][0] = 0
    for r in range(R):
        for c in range(C):
            for i in range(4):
                if DP[i][r][c] > -1:
                    if r + 1 < R: 
                        DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c])
                    if c + 1 < C: 
                        DP[i][r][c+1] = max(DP[i][r][c+1], DP[i][r][c])
                    if i < 3 and item[r][c] > 0:
                        if r + 1 < R: DP[0][r+1][c] = max(DP[0][r+1][c], DP[i][r][c] + item[r][c])
                        if c + 1 < C: DP[i+1][r][c+1] = max(DP[i+1][r][c+1], DP[i][r][c] + item[r][c])

    ans = DP[3][R-1][C-1]
    for i in range(3): ans = max(ans, DP[i][R-1][C-1] + item[R-1][C-1])
    print(ans)
    return 0

if __name__ == "__main__":
    solve()
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
mylist=[]

for i in range(1,n+1):
    mylist.append(str(a.index(i)+1))
print(' '.join(mylist))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[a[i]-1]=i+1
print(*b)
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def check(m, k, vs):
    s = 0
    for x, y, v in vs:
        if v >= m:
            s += (v - m + y - 1) // y
    return s <= k


n, k = read_i()
ls0 = sorted(read_i())
ls1 = sorted(read_i(), reverse=True)
if sum(ls0) <= k:
    print(0)
    exit()

vs = [(x, y, x * y) for x, y in zip(ls0, ls1)]

lo = 0
hi = sum(v for _, _, v in vs)
while hi - lo > 1:
    mid = (lo + hi) // 2
    if check(mid, k, vs):
        hi = mid
    else:
        lo = mid
print(hi)

### FIXED CODE ###

import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def check(m, k, vs):
    s = 0
    for x, y, v in vs:
        if v >= m:
            s += (v - m + y - 1) // y
    return s <= k


n, k = read_i()
ls0 = sorted(read_i())
ls1 = sorted(read_i(), reverse=True)
if sum(ls0) <= k:
    print(0)
    exit()

vs = [(x, y, x * y) for x, y in zip(ls0, ls1)]

lo = 0
hi = sum(v for _, _, v in vs)
while hi - lo > 1:
    mid = (lo + hi) // 2
    if check(mid, k, vs):
        hi = mid
    else:
        lo = mid
print(hi)
### BUGGY CODE ###

n = int(input())
s = input()

an = 0
anl =[]
print(len([anl for i in range(1,n+1)
 for j in range(i+1,n+1)
 for k in range(j+1,n+1)
  if i<j and j<k and (j-i) != (k-j) and s[i-1]!=s[j-1] and s[i-1]!=s[k-1] and s[j-1]!=s[k-1]]))

### FIXED CODE ###

n = int(input())
s = input()

an = s.count('R') *s.count('G') *s.count('B')

for i in range(n-2):
    for j in range(i+1,n-1):
        k = 2*j-i
        if (k<n) and (s[i]!=s[j]) and (s[j]!=s[k])and(s[i]!=s[k]):
                an -= 1

print(an)
### BUGGY CODE ###

L, R = list(map(int, input().split()))

_min = 2019
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        buf = i*j % 2019
        if buf < _min:
            _min = buf
print(_min)

### FIXED CODE ###

L, R = list(map(int, input().split()))

if (R - L) >= 2019:
    print(0)
else:
    _min = 2019
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            buf = i*j % 2019
            if buf < _min:
                _min = buf
    print(_min)
### BUGGY CODE ###

N,K = map(int,input().split())
S = input()

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = []
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        memo.append(cnt)
        cnt = 1
        now = S[i+1]

m = 0
l = []
if S[0] == '1':
    for i in range(len(memo)):
        if i%2 == 0:
            s = sum(memo[i:i+2*K+1])
            l.append(s)
        else:
            s = sum(memo[i:i+2*K])
            l.append(s)



        # if s > m:
        #     m = s
else:
    for i in range(len(memo)):
        if i%2 == 1:
            s = sum(memo[i:i+2*K+1])
            l.append(s)
        else:
            s = sum(memo[i:i+2*K])
            l.append(s)


        # if s > m:
        #     m = s

print(max(l))



### FIXED CODE ###

N,K = map(int,input().split())
S = input()

if S[N-1] == '1':
    S += '0'
else:
    S += '1'

memo = [1]
now = S[0]
cnt = 1
for i in range(N):
    if S[i+1] == now:
        cnt += 1
    else:
        cnt += 1
        memo.append(cnt)
        now = S[i+1]

n = len(memo)
for i in range(2*K+1):
    memo.append(N+1)

m = 0
l = []
if S[0] == '1':
    for i in range(n):
        if i%2 == 0:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])



        # if s > m:
        #     m = s
else:
    for i in range(n):
        if i%2 == 1:
            l.append(memo[i+2*K+1]-memo[i])
        else:
            l.append(memo[i+2*K]-memo[i])


        # if s > m:
        #     m = s

print(max(l))
### BUGGY CODE ###

#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
for tmp_num in range(1000):
    tmp = str(tmp_num).zfill(3)
    digit = 0
    for i in range(N):
        if S[i] == tmp[digit]: digit += 1
        if digit == 3: break
    if digit == 3: ans += 1
print(ans)

### FIXED CODE ###

#!/usr/bin/env/ python3
N = int(input())
S = input()
#A, B, C = input().split()
#A, B, C, X, Y = map(int, input().split())

#N = int(input())
#H, W = map(int, input().split())
#S = [input() for _ in range(H)]
#print(A[0][0])

ans = 0
for tmp_num in range(1000):
    tmp = str(tmp_num).zfill(3)
    digit = 0
    for i in range(N):
        if S[i] == tmp[digit]:
            digit += 1
            if digit == 3:
                ans += 1
                break
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
s=str(input())
import numpy as np

grid = np.ones([q,2])
for i in range(q):
    l,r = map(int,input().split())
    grid[i,:] = [l,r] 

line = np.ones([n,])
for i in range(n-1):
    if (s[i:i+2]=="AC"): 
        line[i]=1
    else:
        line[i]=0
    
for i in range(0,q):
    target = line[int(grid[i,0])-1:int(grid[i,1]-1)]
    print(int(sum(target)))

### FIXED CODE ###

import numpy as np

n,q=map(int,input().split())
s=str(input())

line = np.zeros([n,])
count = 0
for i in range(1,n):
    if (s[i-1:i+1]=="AC"): 
        count += 1
    line[i]=count 
        
for i in range(q):
    l,r = map(int,input().split())
    target = line[r-1] - line[l-1]
    print(int(target))
### BUGGY CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

heapq.heapify(A)

for m in range(M):
    B, C = map(int, input().split())
    for b in range(B):
        x = heapq.heappop(A)
        if x >= C:
            heapq.heappush(A, x)
            break
        else:
            x = max(x, C)
            heapq.heappush(A, x)

print(sum(A))


### FIXED CODE ###

import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))

change = []
for m in range(M):
    B, C = map(int, input().split())
    change.append((B, C))
change.sort(key=lambda x: -x[1])

change2 = []
for c in change:
    change2.extend([c[1]] * c[0])
    if len(change2) >= N:
        change2 = change2[:N]
        break


heapq.heapify(A)

for c in change2:
    x = heapq.heappop(A)
    if x >= c:
        # 先頭すでに十分大きい場合は抜ける
        heapq.heappush(A, x)
        break
    else:
        x = max(x, c)
        heapq.heappush(A, x)

print(sum(A))
### BUGGY CODE ###

import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


N, K = [int(x) for x in input().split()]

G = [set() for _ in range(N)]

for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)


def len12(g, st):
    s = set()
    for n1 in g[st]:
        s.add(n1)
        for n2 in g[n1]:
            s.add(n2)
    if st in s:
        s.remove(st)
    return len(s)


G2 = [set() for _ in range(N)]
opened = set()
opened.add(0)
closed = set()

ans = K
while len(opened) != 0:
    target = opened.pop()
    closed.add(target)
    for n in G[target]:
        if n in closed:
            continue
        opened.add(n)
        G2[target].add(n)
        G2[n].add(target)
        cnt = len12(G2, n)
        ans = ans * (K - cnt)
        ans %= MOD

print(ans)


### FIXED CODE ###

import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


N, K = [int(x) for x in input().split()]

# G = [set() for _ in range(N)]
G = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)


def len12(g, st):
    cnt = len(g[st])
    for n1 in g[st]:
        cnt += (len(g[n1]) - 1)
    return cnt


G2 = [[] for _ in range(N)]
opened = set()
opened.add(0)
closed = set()

ans = K
while len(opened) != 0:
    target = opened.pop()
    closed.add(target)
    for n in G[target]:
        if n in closed:
            continue
        opened.add(n)
        G2[target].append(n)
        G2[n].append(target)
        cnt = len12(G2, n)
        ans = ans * (K - cnt)
        ans %= MOD

print(ans)
### BUGGY CODE ###

s = input()
S = []
for i in range(len(s)):
  S.append(s[i])
Q = int(input())
flag = 0
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag % 2 == 0:         
            if q[1] == "1":
                S.insert(0,q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == "1":
                S.append(q[2])
            else:
                S.insert(0,q[2])
if flag%2 == 0:
    S = "".join(S)
    print(S)
else:
    S = S[::-1]
    S = "".join(S)
    print(S)

### FIXED CODE ###

S = input()
Q = int(input())
flag = 0
H = ""
for _ in range(Q):
    q = list(input().split())
    if q[0] == "1":
        flag += 1
    else:
        if flag%2 == 0:
            if q[1] == "1":
                H = H+q[2]
            else:
                S = S+q[2]
        else:
            if q[1] == "1":
                S = S+q[2]
            else:
                H = H+q[2]
H = H[::-1]
H = H+S
if flag%2 == 0:
    print(H)
else:
    H = H[::-1]
    print(H)
### BUGGY CODE ###

from operator import itemgetter
import sys

def main():
    n = int(input())  
    keys = map(lambda i:(map(int,sys.stdin.readline().split())+[i]),xrange(n))
    keys.sort()
    id_m = len(keys)/2
    root = Node(keys[id_m][:2],keys[id_m][2])
    if id_m != 0:
        recursive_add_Node(root,keys[:id_m],1)
    if id_m+1 != len(keys):
        recursive_add_Node(root,keys[id_m+1:],1)

    q = int(input())
    for i in xrange(q):
        sx, tx, sy, ty = map(int,sys.stdin.readline().split())
        nums = []
        find(root,[sx,sy],[tx,ty],0,nums)
        nums.sort()
        map(lambda i:sys.stdout.write("{}\n".format(i)), nums)
        print ("")

def find(z,s,t,d,nums):
    if(s[0]<=z.key[0]<=t[0])and(s[1]<=z.key[1]<=t[1]):
        nums.append(z.num)
    d += 1
    xy = d%2
    if (z.left != None)and(z.key[xy]>=s[xy]):
        find(z.left,s,t,d,nums)
    if (z.right != None)and(z.key[xy]<=t[xy]):
        find(z.right,s,t,d,nums)

def add_Node(root,k,n):
    y = None
    x = root
    d = 0
    xy = 0
    while(x != None):
        d += 1
        xy = d%2
        y = x
        if x.key[xy] > k[xy]:
            x = x.left
        else:
            x = x.right
    
    z = Node(k,n)

    if y.key[xy] > k[xy]:
        y.left = z
    else:
        y.right = z
        
def recursive_add_Node(root,k,d):
    k.sort(key=itemgetter(d%2))
    len_k = len(k)
    id_m = len_k/2
    add_Node(root,k[id_m][:2],k[id_m][2])
   
    if id_m != 0:
        recursive_add_Node(root,k[:id_m],d+1)
    if id_m+1 != len_k:
        recursive_add_Node(root,k[id_m+1:],d+1)

class Node():
    def __init__(self,k,n):
        self.key   = k
        self.num   = n
        self.left  = None
        self.right = None


if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin,stdout
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline
 
def main():
    n = int(input())
    keys = map(lambda i: map(int,readline().split())+[i], xrange(n))
    keys.sort()

    root = int(math.sqrt(len(keys)))
 
    low = [x for x, y, i in keys[::root]]
    high = [x for x, y, i in keys[root - 1::root]] + [float('inf')]
 
    keys = [sorted(keys[i:i+root], key=itemgetter(1)) for i in range(0,len(keys),root)]
    keys_y = map(lambda k:[y for x,y,i in k], keys)

    q = int(input())
    for i in xrange(q):
        sx,tx,sy,ty = map(int,readline().split())
        
        nums = []
        for i in range(bisect_left(high, sx), bisect_right(low, tx)):
            y = keys_y[i]
            for j in range(bisect_left(y, sy), bisect_right(y, ty)):
                if sx <= keys[i][j][0] <= tx:
                    nums.append(keys[i][j][2])
        if nums:
            nums.sort()
            map(lambda n:stdout.write("{}\n".format(n)), nums)
        print("")

if __name__ == "__main__":
    main()
### BUGGY CODE ###

from itertools import permutations
N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

exist = [0, 1]
box = set([ i for i in range( 1, N+1 ) ])
minCost = 10**9
for key in range( 1, (1<<M)+1 ):
    openBox = set([])
    price = 0
    for i in range(M):
        if ((key>>i) & 1)==1:
            openBox |= set(c[i])
            price += a[i]
    if openBox == box and price <= minCost:
        minCost = price

res = minCost if minCost < 10**9 else -1
print(res)

### FIXED CODE ###

N, M = map(int, input().split())
a, b, c = [], [], []
for _ in range(M):
    a_, b_ = map(int, input().split())
    c_ = list( map(int, input().split()) )
    a.append(a_)
    b.append(b_)
    c.append(c_)

INF = 10**9
bit_dp = [INF for _ in range(2**N)]
bit_dp[0] = 0
for i in range(M):
    bit_n = 0
    for j in c[i]:
        bit_n |=  1 << j - 1
    for j in range(2**N):
        if bit_dp[j|bit_n] > bit_dp[j] + a[i]:
            bit_dp[j|bit_n] = bit_dp[j] + a[i]

res = -1 if bit_dp[-1] >= INF else bit_dp[-1]
print(res)
### BUGGY CODE ###

n, q = map(int, input().split())
s = input()
for i in range(q):
    l, r = map(int, input().split())
    print(s[l-1:r].count('AC'))


### FIXED CODE ###

n, q = map(int, input().split())
s = input()

cnt = 0
ans = [0]
for i in range(n-1):
    if s[i:i+2] == 'AC':
        cnt += 1
    ans.append(cnt)

for i in range(q):
    l, r = map(int, input().split())
    print(ans[r-1]-ans[l-1])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import Counter
from collections import defaultdict
def main():
    S = list(map(int, input().rstrip("\r\n")))
    N = len(S)
    P = 2019
    S.reverse()
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            if S[i] % P == 0:ans += N-i
    else:
        D = [0] * (N+1)
        tenpow = 1
        d = defaultdict(int)
        d[0] += 1
        for i in range(N):
            S[i] = S[i] * tenpow % P
            tenpow *= 10 % P
            D[i+1] = (S[i] + D[i]) % P
            d[D[i+1]] += 1
        for v in d.values():
            ans += v*(v-1)//2
    print(ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import Counter
def main():
    S = list(map(int, input().rstrip("\r\n")))
    N = len(S)
    P = 2019
    S.reverse()
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            if S[i] % P == 0:ans += N-i
    else:
        D = [0] * (N+1)
        tenpow = 1
        for i in range(N):
            S[i] = S[i] * tenpow % P
            tenpow *= 10
            tenpow %= P
            D[i+1] = (S[i] + D[i]) % P
        c = Counter(D)
        for v in c.values():
            ans += v*(v-1)//2
    print(ans)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    A = [ deque( map( int, input().split())) for _ in range(N)]
    cnt = N*(N-1)
    days = 0
    W = [False]*N
    while cnt > 0:
        days += 1
        now = cnt
        V = [0]*N
        for i in range(N):
            if V[i] == 1 or W[i]:
                continue
            a = A[i][0]
            a -= 1
            if V[a] == 1 or W[a]:
                continue
            if i+1 == A[a][0]:
                V[a] = 1
                V[i] = 1
                A[a].popleft()
                A[i].popleft()
                if not A[a]:
                    W[a] = True
                if not A[i]:
                    W[i] = True
                cnt -= 2
        if now == cnt:
            print(-1)
            return
    print( days)

                        
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque
def main():
    N = int( input())
    A = [deque()] + [deque( map( int, input().split())) for _ in range(N)]
    Days = [0]*(N+1)
    NOW = [0]*(N+1)
    # for i in range(1, N+1):
    #     a = A[i].popleft()
    #     if NOW[a] == i:
    #         Days[a] = Days[i] = max(Days[a], Days[i])
    q = deque( [ i+1 for i in range(N)])
    while q:
        i = q.popleft()
        if not A[i]:
            continue
        a = A[i].popleft()
        if NOW[a] == i:
            Days[a] = Days[i] = max(Days[a], Days[i])+1
            q.append(i)
            q.append(a)
            NOW[a] = NOW[i] = 0
        else:
            NOW[i] = a
    for i in range(1,N+1):
        if A[i]:
            print(-1)
            return
    print( max(Days))
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = [list(map(int, readline().split())) for _ in range(n)]
    for i in range(n):
        for j in range(n - 1):
            a[i][j] -= 1
    ls = [0] * n
    ql = collections.deque()
    for i in range(n):
        ql.append([0, i])

    for i in range(10 ** 10):
        fq = [True] * n
        while ql:
            d, ps = ql.popleft()
            if d == i:
                if ls[ps] < n - 1 and fq[ps]:
                    fq[ps] = False
                    nw = a[ps][ls[ps]]
                    rw = a[nw][ls[nw]]
                    if ps == rw and fq[nw]:
                        ls[ps] += 1
                        ql.append([d+1, ps])
                        ls[nw] += 1
                        ql.append([d+1, nw])
                        fq[nw] = False
            else:
                if d > i:
                    ql.appendleft([d, ps])
                break
        if len(ql) == 0 or sum(ls) == n * (n - 1):
            print(i + 1 if sum(ls) == n * (n - 1) else -1)
            exit()


if __name__ == '__main__':
    solve()


### FIXED CODE ###

def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ad = [0] * n
    dq = collections.deque([[0, i + 1] for i in range(n)])
    for i in range(10 ** 15):
        fd = {}
        while True:
            if len(dq) != 0:
                d, q = dq.popleft()
                q -= 1
                if d <= i:
                    if ad[q] < n - 1:
                        qq = a[q][ad[q]] - 1
                        tq = a[qq][ad[qq]] - 1
                        if q == tq and qq not in fd and tq not in fd:
                            ad[qq] += 1
                            ad[tq] += 1
                            if ad[qq] < n - 1:
                                dq.append([d + 1, qq + 1])
                            if ad[tq] < n - 1:
                                dq.append([d + 1, tq + 1])
                            fd[qq] = 0
                            fd[tq] = 0
                else:
                    dq.append([d, q + 1])
                    break
            else:
                break
        if len(dq) == 0:
            b = True
            for v in ad:
                if v != n - 1:
                    b = False
                    break
            if b:
                print(i + 1)
                exit()
            else:
                print(-1)
                exit()


if __name__ == '__main__':
    slove()
### BUGGY CODE ###


n = int(input())
ans = 0
i = 1
x = n
while i<n:
    if (n-i)%i==0:
        x = (n-i)//i
        if x<=i:break
        ans += x
    i += 1
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
i = 1
x = n
while i<n**0.5:
    if (n-i)%i==0:
        x = (n-i)//i
        if x<=i:break
        ans += x
    i += 1
print(ans)
### BUGGY CODE ###

N=int(input())
li=[input() for i in range(N)]

li.sort()
B=[int(li.count(li[i])) for i in range(N)]

M=max(B)
C=[]
for i in range(N):
    if li.count(li[i])==M and not li[i] in C:
        C.append(li[i])
    else:
        pass

C.sort()

L=len(C)

for k in range(L):
    print(C[k])


### FIXED CODE ###

N=int(input())
li=[]
import collections

for i in range(N):
    S=input()
    li.append(S)

li.sort()

c=collections.Counter(li)
cl=c.values()
m=max(cl)
keys=[k for k,v in c.items() if v==m]
keys.sort()

for j in range(len(keys)):
    print(keys[j])