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

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n = int(input())
s = input().rstrip()

dp = [[0] * n for _ in range(n)]
dp[0] = [1] * n

used = 0
for i, ch in enumerate(s):
    if ch == "<":
        for j in range(n - used - 1, -1, -1):
            if j-1 >= 0:
                dp[i+1][j-1] = dp[i][j]
        for j in range(n - 1, 0, -1):
            dp[i+1][j-1] += dp[i+1][j]
            dp[i+1][j-1] %= MOD
    else:
        for j in range(n - used - 2, -1, -1):
            dp[i+1][j] = dp[i][j]
        for j in range(1, n - used - 1):
            dp[i+1][j] += dp[i+1][j-1]
            dp[i+1][j] %= MOD
    used += 1

# for line in dp:
#     print(line)
print(sum(dp[-1]) % MOD)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

n = int(input())
s = input().rstrip()

dp = [[0] * n for _ in range(n)]
dp[0] = [1] * n

used = 0
for i, ch in enumerate(s):
    if ch == "<":
        for j in range(n - used - 1, -1, -1):
            if j-1 >= 0:
                dp[i+1][j-1] = dp[i][j]
        for j in range(n - 1, 0, -1):
            dp[i+1][j-1] += dp[i+1][j]
            dp[i+1][j-1] %= MOD
    else:
        for j in range(n - used - 2, -1, -1):
            dp[i+1][j] = dp[i][j]
        for j in range(1, n - used - 1):
            dp[i+1][j] += dp[i+1][j-1]
            dp[i+1][j] %= MOD
    used += 1

# for line in dp:
#     print(line)
print(sum(dp[-1]) % MOD)
### BUGGY CODE ###

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from heapq import heappop,heappush

h,w = map(int,readline().split())
ch,cw = map(int,readline().split())
dh,dw = map(int,readline().split())
s = read().split()

ch -= 1
cw -= 1
dh -= 1
dw -= 1

wall = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if(s[i][j] == '#'):
            wall[i][j] = 1

cost = [[-1] * w for _ in range(h)]
hq = [(0,ch,cw)]


while(hq):
    ci,xi,yi = heappop(hq)
    if(cost[xi][yi] != -1):
        continue
    cost[xi][yi] = ci

    for dx in range(-2,3):
        for dy in range(-2,3):
            xj,yj = xi+dx,yi+dy
            # print(xi,yi,xj,yj)
            if(xj<0)|(xj>=h)|(yj<0)|(yj>=w):
                continue
            if(cost[xj][yj]!=-1):
                continue
            if(xi==xj)&(yi==yj):
                continue
            if(wall[xj][yj]==1):
                continue
            if(abs(xi-xj)+abs(yi-yj)==1):
                heappush(hq,(ci,xj,yj))
            else:
                heappush(hq,(ci+1,xj,yj))

print(cost[dh][dw])

### FIXED CODE ###

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import deque

h,w = map(int,readline().split())
ch,cw = map(int,readline().split())
dh,dw = map(int,readline().split())
s = read().split()

ch -= 1
cw -= 1
dh -= 1
dw -= 1

wall = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if(s[i][j] == '#'):
            wall[i][j] = 1

inf = 10**10
cost = [[inf] * w for _ in range(h)]
cost[ch][cw]=0
d = deque()
d.append((0,ch,cw))

while(d):
    ci,xi,yi = d.popleft()
    if(cost[xi][yi] > ci):
        continue

    for dx in range(-2,3):
        xj = xi+dx
        if(xj<0)|(xj>=h):
            continue
        for dy in range(-2,3):
            yj = yi+dy
            # print(xi,yi,xj,yj)
            if(yj<0)|(yj>=w):
                continue
            if(xi==xj)&(yi==yj):
                continue
            if(wall[xj][yj]==1):
                continue
            if(abs(xi-xj)+abs(yi-yj)==1):
                if(cost[xj][yj] > ci):
                    cost[xj][yj] = ci
                    d.appendleft((ci,xj,yj))
            else:
                if(cost[xj][yj] > ci+1):
                    cost[xj][yj] = ci+1
                    d.append((ci+1,xj,yj))

if(cost[dh][dw] == inf):
    print(-1)
else:
    print(cost[dh][dw])
### BUGGY CODE ###

N, Q = map(int, input().split())

ab_list = []
tree_dict = {}
for i in range(N-1):
    a, b = map(int, input().split())
    ab_list.append(a)
    ab_list.append(b)

    if a not in tree_dict:
        tree_dict[a] = [b]
    else:
        tree_dict[a].append(b)

value_dict = {k:0 for k in list(set(ab_list))}

p_list = []
x_list = []
for i in range(Q):
    p, x = map(int, input().split())
    p_list.append(p)
    x_list.append(x)

for p, x in zip(p_list, x_list):
    f = 0
    for k, v in value_dict.items():
        if k == p:
            kk_list = [k]
            while(1):
                if len(kk_list) == 0:
                    f = 1
                    break
                k = kk_list[0]
                value_dict[k] += x
                if k in tree_dict:
                    kk_list += tree_dict[k]
                kk_list.pop(0)
        if f == 1:
            break

print(' '.join([str(v) for k, v in value_dict.items()]))

### FIXED CODE ###

N, Q = map(int, input().split())

ab_list = []
tree_dict = {}
for i in range(N-1):
    a, b = map(int, input().split())
    ab_list.append(a)
    ab_list.append(b)

    if a not in tree_dict:
        tree_dict[a] = [b]
    else:
        tree_dict[a].append(b)

value_list = list(set(ab_list))

px_dict = {}
for i in range(Q):
    p, x = map(int, input().split())
    if p in px_dict:
        px_dict[p] += x
    else:
        px_dict[p] = x

out = ""
for v in value_list:
    if v in px_dict:
        x = px_dict[v]
        if v in tree_dict:
            tree_list = tree_dict[v]
            for t in tree_list:
                if t in px_dict:
                    px_dict[t] += x
                else:
                    px_dict[t] = x
        o = str(px_dict[v])
    else:
        o = str(0)
    out += o + " "

print(out[:-1])
### BUGGY CODE ###

N, M = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]

nl = []
for i in range(N):
    for j in range(l[i][1]):
        nl.append(l[i][0])
    
sorted_nl = sorted(nl)

ans = 0
for i in range(M):
    ans += sorted_nl[i]
    
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(N)]

sl = sorted(l)
buy = 0
ans = 0
for i in range(N):
    for j in range(sl[i][1]):
        if buy < M:
            ans += sl[i][0]
            buy += 1
        else:
            break

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

N = int(input())
s = []
ans = []
for _ in range(N):
    inp = int(input())
    s.append(inp)

for bit in range(1<<N):
    sums = 0
    for i in range(N):
        mask = 1<<i
        if mask&bit:
            sums += s[i]
        ans.append(sums)
ans = sorted(ans,reverse=True)
answer=0
for i in range(N):
    if ans[i]%10!=0:
        answer = ans[i]
        break
print(answer)

### FIXED CODE ###

N = int(input())
s = []
for _ in range(N):
    inp = int(input())
    s.append(inp)
s = sorted(s)
sm = sum(s)
if sm%10!=0:
    ans = sm
else:
    for i in s:
        if i%10!=0:
            sm-=i
            break
    ans = sm
    if sm==sum(s):
        ans = 0
print(ans)
### BUGGY CODE ###

n,m = map(int, input().split())
lst = list(map(int, input().split()))
# lst.sort(reverse=True)

for i in range(m):
    lst.sort(reverse=True)
    lst[0]=int(lst[0]/2)

    # if lst[0]<lst[1]:
    #     lst[0],lst[1]=lst[1],lst[0]
print(sum(lst))


### FIXED CODE ###

import heapq

n,m = map(int, input().split())
lst = [-int(i) for i in input().split()]
heapq.heapify(lst)

for i in range(m):
    a=-(-heapq.heappop(lst)//2)
    heapq.heappush(lst, a)
print(-sum(lst))
### BUGGY CODE ###

n = int(input())
s = [list(input()) for i in range(n)]
count = [0]*26
for i in s:
    for j in i:
        count[ord(j)-ord("a")] += 1
if max(count) == n**2:
    print(n**2)
    exit()
ans = 0
for a in range(n):
    for b in range(n):
        check = True
        for x in range(n):
            for y in range(x):
                if s[(x+a)%n][(y+b)%n] != s[(y+a)%n][(x+b)%n]:
                    check = False
                    break
            if check == False:
                break
        if check:
            ans += 1
print(ans)

### FIXED CODE ###

n = int(input())
s = [list(input()) for i in range(n)]
ans = 0
for a in range(n):
    check = True
    for x in range(n):
        for y in range(x):
            if s[(x+a)%n][y] != s[(y+a)%n][x]:
                check = False
                break
        if check == False:
            break
    if check:
        ans += n-a
    if a == 0:
        continue
    check = True
    for x in range(n):
        for y in range(x):
            if s[x][(y+a)%n] != s[y][(x+a)%n]:
                check = False
                break
        if check == False:
            break
    if check:
        ans += n-a
print(ans)
### BUGGY CODE ###

import numpy as np


def solve(s):
    MOD = 10 ** 9 + 7
    dp = np.zeros(13, dtype=np.int64)
    dp[0] = 1
    idx = np.zeros(13, dtype=np.int8)
    for i in range(13):
        idx[i * 10 % 13] = i
    window = np.ones(10, dtype=np.int8)
    for c in s:
        if c == '?':
            dp = np.convolve(dp[idx], window)
            dp[:9] += dp[13:]
            dp = dp[:13] % MOD
        else:
            dp = np.roll(dp[idx], int(c))
    return dp[5]


s = input()
print(solve(s))


### FIXED CODE ###

import numpy as np


def solve(s):
    MOD = 10 ** 9 + 7
    dp = np.zeros(13, dtype=np.int64)
    dp[0] = 1
    idx = np.zeros(13, dtype=np.int8)
    for i in range(13):
        idx[i * 10 % 13] = i
    window = np.ones(10, dtype=np.int8)
    for c in s:
        if c == '?':
            tdp = dp[idx]
            ndp = np.concatenate([tdp[4:], tdp])
            dp = np.convolve(ndp, window, mode='valid') % MOD
        else:
            dp = np.roll(dp[idx], int(c))
    return dp[5]


s = input()
print(solve(s))
### BUGGY CODE ###



k = int(input())

def calcGcd(p, q):
    if p % q == 0:
        return q
    return calcGcd(q, p%q)

ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += calcGcd(calcGcd(a, b), c)

print(ans)

### FIXED CODE ###

from math import gcd

k = int(input())


ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        for c in range(1, k+1):
            ans += gcd(gcd(a, b), c)

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

import sys
from collections import deque
finput=lambda: sys.stdin.readline().strip()

n=int(finput())
a=finput().split()
b=[]

for i in range(n):
  if (n-i)%2==0:
    b.append(a[i])
  else:
    b.insert(0,a[i])
print(' '.join(b))


### FIXED CODE ###

import sys
from collections import deque
finput=lambda: sys.stdin.readline().strip()

n=int(finput())
a=finput().split()
b=deque()

for i in range(n):
  if (n-i)%2==0:
    b.append(a[i])
  else:
    b.appendleft(a[i])
print(' '.join(b))
### BUGGY CODE ###

n,m = map(int,input().split())
prise = []
conte = []
suma = 0
sum_p = 0
for i in range(n):
    a,b = map(int,input().split())
    prise.append(a)
    conte.append(b)
    suma += a*b
    sum_p += b

while sum_p >= m:
    ind = prise.index(max(prise))
    if conte[ind] >= (sum_p - m):
        suma = suma - (sum_p-m)*prise[ind]
        break
    else:
        suma = suma - conte[ind]*prise[ind]
        sum_p -= conte[ind]
        if sum_p == m:
            break
    prise.pop(ind)
    conte.pop(ind)
print(suma)

### FIXED CODE ###

n,m = map(int,input().split())
plist = []
for _ in range(n):
    plist.append([int(x) for x in input().split()])

plist.sort()

cost=0
i = 0

while i < len(plist):
    tmp = plist[i]
    if tmp[1] < m:
        m -= tmp[1]
        cost += tmp[0] * tmp[1]
        i += 1
        continue
    else:
        cost += tmp[0] * m
        break
print(cost)
### BUGGY CODE ###

n = int(input())

a_list=[]
for i in range(n):
  a = int(input())
  a_list.append(a)

for i in range(n):
  print(max(a_list[:i]+a_list[i+1:]))



### FIXED CODE ###

n = int(input())

a_list=[]
for i in range(n):
  a = int(input())
  a_list.append(a)

saidai1=max(a_list)
saidai1_index=a_list.index(saidai1)
saidai2=max(a_list[:saidai1_index]+a_list[saidai1_index+1:])

for i in range(n):
  if a_list[i]==saidai1:
    print(saidai2)
  else:
    print(saidai1)
### BUGGY CODE ###

def q2():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]

    # dp配列の初期化 (最小化問題なので初期値をINFとする)
    dp = [float('inf')]*N
    dp[0] = 0
    dp[1] = abs(H[1] - H[0])

    for i in range(1, N):
        max_K = i if K > i else K
        for k in range(0, max_K + 1):
            step = dp[i-k] + abs(H[i] - H[i-k])
            dp[i] = min(dp[i], step)

    print(dp[N-1])


if __name__ == '__main__':
    q2()

### FIXED CODE ###

def q2():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]

    # dp配列の初期化 (最小化問題なので初期値をINFとする)
    dp = [float('inf')]*N
    dp[0] = 0
    dp[1] = abs(H[1] - H[0])

    for i in range(1, N):
        max_K = i if K > i else K
        for k in range(0, max_K + 1):
            step = dp[i-k] + abs(H[i] - H[i-k])
            dp[i] = min(dp[i], step)

    print(dp[N-1])


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

from sys import stdin
from bisect import insort
n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a.sort()
for i in range(m):
    harf = a[n-1] // 2
    a[n-1:n] = []
    insort(a, harf)
print(sum(a))


### FIXED CODE ###

from sys import stdin
import heapq
n, m = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = [-1 * x for x in a]
heapq.heapify(a)
for i in range(m):
    harf = heapq.heappop(a)
    harf = ((harf*(-1))//2)*(-1)
    heapq.heappush(a,harf)
print(sum(a)*(-1))
### BUGGY CODE ###

a = int(input())
total = 0
for i in range(a):
    total += i
print(total)

### FIXED CODE ###

a = int(input())
print(int(a*(a-1)//2))
### BUGGY CODE ###

x = int(input())
lim = int(x**(1/5))+1
for i in range(-100000*lim, 100000*lim):
    if x + i**5 < 0:
        continue
    if (x+i**5)**(1/5) == int((x+i**5)**(1/5)):
        print(int((x+i**5)**(1/5)), i)
        exit()

### FIXED CODE ###

x = int(input())
lim = int(x**(1/5))+1

for a in range(10**6):
    mul = 1
    if a**5 < x:
        mul = -1
    
    b = ((a**5 - x)*mul)**(1/5)
    b*=mul
    b = int(b)
    if a**5 - b**5 == x:
        print(a, b)
        exit()
### BUGGY CODE ###

#!/usr/bin/env python3
#ABC122 C

n,q = map(int,input().split())
s = list(input())
def check(x):
    sum = 0
    i = 0
    while i < len(x):
        if i < len(x)-1:
            if x[i] == 'A':
                if x[i+1] == 'C':
                    sum += 1
                    i += 1
        i += 1
    return sum
ans = []
for _ in range(q):
    l,r = map(int,input().split())
    ans.append(check(s[l-1:r]))
for i in range(q):
    print(ans[i])


### FIXED CODE ###

#!/usr/bin/env python3
#ABC122 C

n,q = map(int,input().split())
s = input()
t = [0 for _ in range(n+1)]

for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] =='AC' else 0)

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

import queue

N, Q = map(int,input().split())
counter = [0]*N
tree = [[] for _ in range(N)]
parent = [-1]*N
for _ in range(N-1):
  a, b = map(int,input().split())
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)

  
for _ in range(Q):
  p, x = map(int,input().split())
  counter[p-1] += x

q = queue.Queue()
q.put(0)

while not q.empty():
  index = q.get()
  pindex = parent[index]
  for i in tree[index]:
    if i == pindex: continue
    counter[i] += counter[index]
    parent[i] = index
    q.put(i)
    
print(*counter)


### FIXED CODE ###

from collections import deque

N, Q = map(int,input().split())
counter = [0]*N
tree = [[] for _ in range(N)]
parent = [-1]*N
for _ in range(N-1):
  a, b = map(int,input().split())
  tree[a-1].append(b-1)
  tree[b-1].append(a-1)

  
for _ in range(Q):
  p, x = map(int,input().split())
  counter[p-1] += x

q  = deque()
q.append(0)

while q:
  index = q.pop()
  pindex = parent[index]
  for i in tree[index]:
    if i == pindex: continue
    counter[i] += counter[index]
    parent[i] = index
    q.append(i)
    
print(*counter)
### BUGGY CODE ###

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0
while dp[5] < N:
    for i in range(4, -1, -1):
        dp[i+1] += min(dp[i],T[i])
        dp[i] -= min(dp[i],T[i])
    ans += 1
print(ans)


### FIXED CODE ###

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

dp = [0] * 6
dp[0] = N
T = [A,B,C,D,E]
ans = 0

ans = -(-N//min(T)) + 4
# while dp[5] < N:
#     for i in range(4, -1, -1):
#         if dp[i] == 0:
#             continue
#         dp[i+1] += min(dp[i],T[i])
#         dp[i] -= min(dp[i],T[i])
#     ans += 1
print(ans)
### BUGGY CODE ###

N, K, L = map(int, input().split())
G = [[[], []] for i in range(N)]
R = [[i, i] for i in range(N)]
def root(i, j):
  if R[i][j] != i:
    R[i][j] = root(R[i][j], j)
  return R[i][j]
for i in range(K):
  p, q = map(int, input().split())
  rp = root(p - 1, 0)
  rq = root(q - 1, 0)
  if rp != rq:
    R[rp][0] = min(rp, rq)
    R[rq][0] = min(rp, rq)
for i in range(L):
  r, s = map(int, input().split())
  rr = root(r - 1, 1)
  rs = root(s - 1, 1)
  if rr != rs:
    R[rr][1] = min(rr, rs)
    R[rs][1] = min(rr, rs)
U = [[[], []] for i in range(N)]
for i in range(N):
  R[i][0] = root(i, 0)
  R[i][1] = root(i, 1)
  U[R[i][0]][0].append(i)
  U[R[i][1]][1].append(i)
A = [1 for i in range(N)]
for i in range(N):
  if A[i] == 1:
    S = set(U[R[i][0]][0]) & set(U[R[i][1]][1])
    for s in S:
      A[s] = len(S)
ans = ''
for a in A:
  ans += ' ' + str(a)
print(ans)

### FIXED CODE ###

from collections import defaultdict
N, K, L = map(int, input().split())
G = [[[], []] for i in range(N)]
R = [[i, i] for i in range(N)]
def root(i, j):
  if R[i][j] != i:
    R[i][j] = root(R[i][j], j)
  return R[i][j]
for i in range(K):
  p, q = map(int, input().split())
  rp = root(p - 1, 0)
  rq = root(q - 1, 0)
  if rp != rq:
    R[rp][0] = min(rp, rq)
    R[rq][0] = min(rp, rq)
for i in range(L):
  r, s = map(int, input().split())
  rr = root(r - 1, 1)
  rs = root(s - 1, 1)
  if rr != rs:
    R[rr][1] = min(rr, rs)
    R[rs][1] = min(rr, rs)
A = defaultdict(int)
for i in range(N):
  R[i][0] = root(i, 0)
  R[i][1] = root(i, 1)
  A[(R[i][0], R[i][1])] += 1
for i in range(N):
  print(A[(R[i][0], R[i][1])])
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
while(any([ai % 2 == 0 for ai in a])):
    ans += 1
    for i in range(n):
        ai = a[i]
        if ai % 2 == 0:
            a[i] = ai // 2
            break
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    x = 0
    ai = a[i]
    while(ai%2==0):
        ai = ai//2
        x+=1
    ans+=x
print(ans)
### BUGGY CODE ###

n=int(input())

def col(n):
    ans=chk=0
    for i in range(1,n):
        if i**2>=n: break
        for j in range(1,n):
            if j**2>=n: break
            for k in range(1,n):
                if k**2>=n: break
                if i**2+j**2+k**2+i*j+j*k+k*i==n: ans+=1
    return ans
for i in range(1,n+1):
    print(col(i))


### FIXED CODE ###

n=int(input())
d={}
for i in range(1,100):
    if i**2>n: break
    for j in range(i,100):
        if j**2>n: break
        for k in range(j,100):
            tmp=i**2+j**2+k**2+i*j+j*k+k*i
            if tmp>n: break
            if i==k: x=1
            elif i==j or j==k: x=3
            else: x=6
            if tmp in d:
                d[tmp]+=x
            else:
                d[tmp]=x
for i in range(1,n+1):
    if i in d: print(d[i])
    else: print(0)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
n = int(input())
h = list(map(int, input().split()))

memo = [-1] * n
def cost(i):
    if i == 0:
        return 0
    elif i == 1:
        return abs(h[i]-h[i-1])
    else:
        if memo[i-1] == -1:
            return min(cost(i-1)+abs(h[i-1]-h[i]), cost(i-2)+abs(h[i-2]-h[i]))
print(cost(n-1))

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))

cost = [0] * (n + 1)
cost[0] = 0
cost[1] = abs(h[1] - h[0])

for i in range(2, n):
  cost1 = cost[i-2] + abs(h[i] - h[i-2])
  cost2 = cost[i-1] + abs(h[i] - h[i-1])
  cost[i] = min(cost1, cost2)
print(cost[n-1])
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n = int(input())
d = {}
for i in range(n):
    s = input()
    if s not in d.keys():
        d[s] = 0
    d[s] += 1
# print(d)
# print(max(d.values()))
ans = [k for k,v in d.items() if v==max(d.values())]
print('\n'.join(sorted(ans)))

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

from collections import Counter
n = int(input())
s = Counter([input() for i in range(n)])
high = max(s.values())
ans = [k for k,v in s.items() if v==high]
print('\n'.join(sorted(ans)))
### BUGGY CODE ###

import sys

# sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    inf = 10 ** 20
    n = read_int()
    weight = {}
    adj = {u: [] for u in range(1, n + 1)}
    for i in range(n - 1):
        a, b, c = read_int_list()
        adj[a].append(b)
        adj[b].append(a)
        weight[(a, b)] = c
        weight[(b, a)] = c

    q, k = read_int_list()
    state = {u: 0 for u in range(1, n + 1)}
    d = {u: inf for u in range(1, n + 1)}

    state[k] = 1
    d[k] = 0
    Q = [k]
    while Q:
        u = Q.pop(0)
        for v in adj[u]:
            if state[v] == 0:
                state[v] = 1
                d[v] = d[u] + weight[(u, v)]
                Q.append(v)
        state[u] = 2

    for i in range(q):
        x, y = read_int_list()
        res = d[x] + d[y]
        print(res)


main()


### FIXED CODE ###

import sys
from collections import deque


# sys.stdin = open('d1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    adj = [[] for u in range(n+1)]
    for i in range(n - 1):
        a, b, c = map(int, input().split())
        adj[a].append((b, c))
        adj[b].append((a, c))

    d = [0] * (n+1)
    q, k = read_int_list()

    # Q = [(k, 0, 0)]
    Q = deque([(k, 0, 0)])
    while Q:
        u, parent, dist = Q.popleft()
        for v, w in adj[u]:
            if v != parent:
                Q.append((v, u, dist+w))
        d[u] = dist

    res = [0] * q
    for i in range(q):
        x, y = map(int, input().split())
        res[i] = d[x] + d[y]
    print(*res, sep='\n')


main()
### BUGGY CODE ###

def main():
	n = int(input())
	l = list(map(int, input().split()))
	_sum = 0
	for i in range(n):
		for j in range(i + 1, n):
			_sum += l[i] * l[j]
	mod = 10**9 + 7
	print(_sum % mod)

main()

### FIXED CODE ###

def main():
	n = int(input())
	l = list(map(int, input().split()))
	a = sum(l)
	a *= a
	b = sum([i * i for i in l])
	a = (a - b) // 2
	mod = 10**9 + 7
	print(a % mod)

main()
### BUGGY CODE ###

N=int(input())
S=input()

pin={}

l=len(S)
for i in range(10):
  for j in range(10):
    for k in range(10):
     pin['{}{}{}'.format(i,j,k)]='{}{}{}'.format(i,j,k)

ans=0
for key in pin:
  s=pin[key]
  flag=0
  for i in range(N) :
    if S[i]==s[0]:
      for j in range(i+1,N):
        if S[j]==s[1]:
           for k in range(j+1,N):
             if S[k]==s[2]:
               flag=1
  if flag==1:
    ans+=1
    
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
S=list(map(int,S))
ans=0
for s in range(1000):
      A=s//100
      B=(s-A*100)//10
      C=s-A*100-B*10
      isOne=0
      isTen=0
      isHundred=0
      for i in range(N) :
        if isOne==0:
          if S[i]==A: 
            isOne=1
        elif isTen==0:
          if S[i]==B: 
            isTen=1
        elif isHundred==0:
          if S[i]==C:
            isHundred=1
            ans+=1
        else:
          break

print(ans)