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

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

n = 1
visit = [1]
for i in range(K):
    n = A[n-1]
    if n in visit:
        loop = [n]
        m = n
        while True:
            m = A[m-1]
            if m == n:
                print(loop[(K-len(visit)+1)%len(loop)-1])
                break
            loop += [m]
        break
    visit += [n]
else:
    print(visit[K])
    

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(lambda s: int(s)-1, input().split()))

n = 0
visit = {0}
ls = [0]
for _ in range(K):
    n = A[n]
    if n not in visit:
        visit.add(n)
        ls += [n]
    else:
        loop_start = 0
        loop_length = 0
        flag = False
        m = 0
        for _ in range(N):
            if n == m:
                if flag:
                    break
                else:
                    flag = True
            if flag:
                loop_length += 1
            else:
                loop_start += 1
            m = A[m]

        print(ls[loop_start + ((K-loop_start) % loop_length)]+1)
        break
else:
    print(n+1)
### BUGGY CODE ###

n = int(input())
gift = []
for i in  range(n):
    get = input()
    if get not in gift:
        gift.append(get)

print(len(gift))

### FIXED CODE ###

n = int(input())
dic = {}
cnt =0
for i in  range(n):
    get = input()

    if get not in dic:
        dic[get] = 1

print(len(dic))
### BUGGY CODE ###

def prime(n):
    num=[i for i in range(n,1,-1) if n%i ==0]
    prime=[]
    p = 2
    while p <=n**0.5 and len(num) != 0:
        p=num.pop()
        prime.append(p)
        num = [i for i in num if i%p != 0]
    return prime
def chk_prime(n):
    for i in range(2,-1*int(-n**0.5//1)):
        if n%i == 0:
            return False
    return True

def main():
    a,b=map(int,input().split(' '))

    ans = 1
    if chk_prime(min(a,b)):
        if max(a,b)%min(a,b) == 0 and min(a,b) != 1:
            ans = 2
    else:
        prime_list=prime(int(min(a,b)/2))
        for i in prime_list:
            if a%i == 0 and b%i==0:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

from math import *
def gcd(n,m):
    while m != 0:
        n,m=m,n%m
    return n
def main():
    a,b=map(int,input().split(' '))
    g=gcd(a,b)
    cnt = 1
    g2 = int(sqrt(g))
    for i in range(2,g2+1):
        if g%i ==0:
            while g%i ==0:
                g //= i
            cnt += 1
    if g > 1:
        cnt += 1
    print(cnt)

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

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

ans = 0
sumA = [sum(A[i+1:]) for i in range(N)]

for i in range(N-1):
    ans += A[i] * sumA[i]

ans = ans % (10 ** 9 + 7)
print(ans)


### FIXED CODE ###

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

X = 0
Ans = 0

for i in range(N - 1):
    X += A[i]
    Ans += X * A[i + 1]
    Ans = Ans % (10 ** 9 + 7)

print(Ans)
### BUGGY CODE ###

n = int(input()); s= 1
lis = list(map(int,input().split()))
if 0 in lis: print(0)
else:
    for i in range(n):
        s = s*lis[i]
    if s>1000000000000000000: print(-1)
    else: print(s)

### FIXED CODE ###

input()
lis = list(map(int,input().split()))
s = 1
if 0 in lis: print(0)
else:
    for i in range(len(lis)):
        s = s * lis[i]
        if s>1000000000000000000: print(-1); exit()
    print(s)
### BUGGY CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def popcnt(n):
    return bin(n).count("1")


def mod(n, cnt):
    if n == 0:
        return cnt
    n = n % popcnt(n)
    cnt += 1
    return mod(n, cnt)


n = int(readline())
x = list(readline().decode().rstrip())

for i in range(n):
    b = x
    # print(b)
    if b[i] == "0":
        b[i] = "1"
    elif b[i] == "1":
        b[i] = "0"
    # print(''.join(b))
    # print(popcnt(''.join(b)))
    num = int(''.join(b), 2)
    # print(''.join(b), num)
    t = mod(num, 0)
    print(t)
    if b[i] == "0":
        b[i] = "1"
    elif b[i] == "1":
        b[i] = "0"


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def popcnt(n):
    return bin(n).count("1")


def mod(n, cnt):
    if n == 0:
        return cnt
    n = n % popcnt(n)
    cnt += 1
    return mod(n, cnt)


n = int(readline())
x2 = list(readline().decode().rstrip())
x10 = int(''.join(x2), 2)

c = x2.count('1')
mod1 = x10 % (c + 1)
mod2 = x10 % (c - 1) if c - 1 != 0 else 0

for i in range(n):
    if x2[i] == '0':
        t = (mod1 + pow(2, n - i - 1, c + 1)) % (c + 1)
    else:
        if c - 1 != 0:
            t = (mod2 - pow(2, n - i - 1, c - 1)) % (c - 1)
        else:
            print(0)
            continue
    print(mod(t, 1))
### BUGGY CODE ###

def calc(a_list, b_list, x):
    inf = 10**11
    aa = [a - x for a in a_list]
    bb = [b - x for b in b_list]
    if len([b for b in bb if b>=0])*len([a for a in aa if a>=0]) >0:
        p_1 = max([b for b in bb if b>=0][0], [a for a in aa if a>=0][0])
    else:
        p_1 = inf
    if len([b for b in bb if b<=0])*len([a for a in aa if a<=0]) >0:
        p_2 = max(abs(max([b for b in bb if b<=0])), abs(max([a for a in aa if a<=0])))
    else:
        p_2 = inf
    if len([b for b in bb if b<=0])*len([a for a in aa if a>=0]) >0:
        b_tmp = max([b for b in bb if b<=0])
        a_tmp = min([a for a in aa if a>=0])
        p_3 = a_tmp - b_tmp + min(abs(a_tmp), abs(b_tmp))
    else:
        p_3 = inf
    if len([b for b in bb if b>=0])*len([a for a in aa if a<=0]) >0:
        b_tmp = min([b for b in bb if b>=0])
        a_tmp = max([a for a in aa if a<=0])
        p_4 = b_tmp - a_tmp + min(abs(a_tmp), abs(b_tmp))
    else:
        p_4 = inf
    return min(p_1, p_2, p_3, p_4)
a,b,q = map(int, input().split())
a_list = []
b_list = []
q_list = []
for i in range(a):
    a_list.append(int(input()))
for j in range(b):
    b_list.append(int(input()))
for k in range(q):
    q = int(input())
    ans = calc(a_list, b_list, q)
    print(ans)

### FIXED CODE ###

import bisect
a, b, q = map(int, input().split())
s = []
for i in range(a):
    s.append(int(input()))
t = []
for j in range(b):
    t.append(int(input()))
inf = 10 ** 18
s = [-inf] + s + [inf]
t = [-inf] + t + [inf]
for k in range(q):
    x = int(input())
    s_r, t_r = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = inf
    for s_ in [s[s_r], s[s_r - 1]]:
        for t_ in [t[t_r], t[t_r - 1]]:
            d = min(abs(x-s_), abs(x-t_)) + abs(s_ - t_)
            res = min(d, res)
    print(res)
### BUGGY CODE ###

# A(300)
import math
import numpy as np
N, K = map(int, input().split())
A_np = np.array(list(map(int, input().split())))

if K > A_np.max():
    print("IMPOSSIBLE")
    
else:    
    L = 10**9+1
    l = math.ceil(math.sqrt(L)) + 1

    isprime = np.ones(l)
    isprime[0] = 0
    isprime[1] = 0
    for i in range(2, l):
        if isprime[i]:
            isprime[2*i:l:i] = 0


    # find LCM
    LCM = 1
    for p in range(l):
        if isprime[p]:
            while True:
                if (A_np % p).sum() == 0:
                    A_np = A_np // p
                    LCM *= p
                else:
                    A_np[A_np % p == 0] = A_np[A_np % p == 0] // p
                    break


    # rare case 
    # large p in common
    if A_np.max() == A_np.min():
        LCM *= A_np.max()
    else:
        LCM = 1
        
    if K % LCM == 0:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")






### FIXED CODE ###

# A(300)
N, K = map(int, input().split())
A_list = list(map(int, input().split()))


def gcd(x, y):
    if x < y:
        x, y = y, x
    while y > 0:
        r = x % y
        x = y
        y = r

    return x

# find LCM
LCM = A_list[0]
for i in range(1, N):
    LCM = gcd(LCM, A_list[i])
    
if K % LCM == 0 and K <= max(A_list):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
### BUGGY CODE ###

n, k = map(int,input().split())

pedras = list(map(int,input().split()))

dp = [1000000000] * n

dp[0] = 0
dp[1] = abs(pedras[1] - pedras[0])

for i in range(2,n):
    pulo = 0
    for j in range(i-1,-1,-1):
        pulo += 1
        if pulo > k:
            break
        else:
            dp[i] = min(dp[i], dp[j] + abs(pedras[i] - pedras[j]))


print(dp[n-1])


### FIXED CODE ###

n,k = map(int,input().split())

INF = 1e12

dp = [INF] * n

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

dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2,n):#Ele vai começar a contar cada pedra a partir da terceira
    pulo = 0
    for j in range(i-1,-1,-1):#O pulo começar pequeno, tendo tamanho 1 e indo até o máximo k
        pulo += 1
        if pulo > k:
            break
        else:
            dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]))
#No final ele vai armazenar o pulo de menor custo, afinal não importa o tamanho do pulo e sim seu custo, sendo assim,
#Temos que calcular os custos de todos os possiveis pulos até a pedra atual.

print(dp[n-1])
### BUGGY CODE ###

# フェルマーの小定理
def main():
    from builtins import pow

    K = int(input())
    S = input()

    m = 1000000007

    result = 0
    a = 1
    b = 1
    t = pow(26, K, m)
    u = pow(26, m - 2, m) * 25 % m
    l = len(S)
    for i in range(K + 1):
        # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
        result += t * (a * pow(b, m - 2, m))
        result %= m
        t *= u
        t %= m
        a *= l + i
        a %= m
        b *= i + 1
        b %= m
    print(result)


main()


### FIXED CODE ###

# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007


def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


fac = make_factorial_table(len(S) + K)

result = 0
for i in range(K + 1):
    result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, m)
    result %= m
print(result)
### BUGGY CODE ###

import heapq
N, M = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)

done = [[False] * N for i in range(N)]

hq = [(-A[0]*2, 0, 0)]
done[0][0] = True
heapq.heapify(hq)  # リストhqのheap化

ans = 0
c = 0
while c < M:
    v, i, j = heapq.heappop(hq)  # heap化されたリストhqから最小値を削除＆その最小値を出力
    ans -= v
    c += 1

    if i+1 < N and done[i+1][j] is False:
        heapq.heappush(hq, (-A[i+1]-A[j], i+1, j))  # heap化されたリストhqに要素xを追加
        done[i+1][j] = True

    if j+1 < N and done[i][j+1] is False:
        heapq.heappush(hq, (-A[i]-A[j+1], i, j+1))  # heap化されたリストhqに要素xを追加
        done[i][j+1] = True

print(ans)


### FIXED CODE ###

from itertools import accumulate
import bisect
N, M = map(int, input().split())
A = [int(i) for i in input().split()]
A.sort()

OK = 0
NG = max(A)*2+1
c = 0
# 幸福度がmid点以上上がる握手をM回できるか
while NG-OK > 1:
    mid = (OK+NG)//2
    cnt = 0

    for a in A:
        cnt += N-bisect.bisect_left(A, mid-a)

    if cnt >= M:
        OK = mid
    else:
        NG = mid

S = list(accumulate(A))

ans = 0
c = 0
for a in A:
    idx = bisect.bisect_right(A, OK-a)
    if idx >= 1:
        ans += a*(N-idx)+S[-1]-S[idx-1]
    else:
        ans += a*(N-idx)+S[-1]

    c += N-idx
ans += OK*(M-c)
print(ans)
### BUGGY CODE ###

import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = [0] + list(map(int, input().split()))

    M = 0
    ans = ''
    B = [0] * (N+1)
    for i in range(N, 0, -1):
        cnt = 0
        for j in range(2*i, N+1, i):
            cnt += B[j]

        if A[i] != cnt % 2:
            B[i] += 1
            M += 1
            ans = str(i) + ' ' + ans

    if M == 0:
        print(0)
    else:
        print(M)
        print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
 
def main():
    input = sys.stdin.readline
    N = int(input())
    A = [0] + list(map(int, input().split()))
 
    M = 0
    ans = []
    B = [0] * (N+1)
    for i in range(N, 0, -1):
        cnt = 0
        for j in range(2*i, N+1, i):
            cnt += B[j]
 
        if A[i] != cnt % 2:
            B[i] += 1
            M += 1
            ans.append(i)
 
    if M == 0:
        print(0)
    else:
        ans = ans[::-1]
        print(M)
        print(' '.join(map(str, ans)))
 
 
if __name__ == '__main__':
    main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
s = input()
mods = [0]*2019
mods[0] += 1
for i in range(len(s)):
    value = int(s[i:])
    # print(value)
    # print(value % 2019)
    # print('==========-')
    mods[value % 2019] += 1
ans = 0
for mod in mods:
    ans += (mod)*(mod-1)//2

print(ans)


### FIXED CODE ###

# -*- coding: utf-8 -*-
s = input()
mods = [0]*2019
mods[0] += 1
# for i in range(len(s)):
#     value = int(s[i:])
#     mods[value % 2019] += 1
base = 1
value = 0
for c in map(int, reversed(s)):
    value += (c*base) % 2019
    base = (base * 10) % 2019
    # value = int(s[i:])
    mods[value % 2019] += 1
print(sum([mod*(mod-1)//2 for mod in mods]))
### BUGGY CODE ###

N=int(input())
A=[int(i) for i in input().split()]
mini=min(A)
while mini>0:
    for i in range(len(A)):
        if A[i]!=mini:
            A[i]=A[i]%mini
    z=A.count(0)
    A=sorted(A)[z:]
    m=A[0]
    if m==1:
        break
    else:
        if [i%m for i in A]==[0]*len(A):
            break
print(A[0])


### FIXED CODE ###

N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)
### BUGGY CODE ###

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


for i in range(M):
    b, c = map(int, input().split())
    A += [c] * b

A = sorted(A)
print(sum(A[-N:]))

### FIXED CODE ###

from collections import defaultdict

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

d = defaultdict(int)
for i in range(N):
    d[A[i]] += 1
for i in range(M):
    b, c = map(int, input().split())
    d[c] += b
    

key = sorted(list(d.keys()))

num = N
i = 0
S = 0
while num > 0:
    i -= 1
    n = d[key[i]]
    num -= n
    S += key[i] * n
    
S += key[i] * num

print(S)
### BUGGY CODE ###

x, k, d = map(int, input().split())
x_pre = x
while k > 0:
    if x >= 0:
        x -= d
    else:
        x += d

    if abs(x) >= abs(x_pre):
        if k % 2 == 0:
            print(abs(x_pre))
            exit()
        else:
            print(abs(abs(x_pre) - d))
            exit()
    else:
        x_pre = x
        k -= 1

print(abs(x_pre))

### FIXED CODE ###

x, k, d = map(int, input().split())
x_pre = x
y = abs(x) - k*d

if y >= 0:
    print(y)
    exit()

while k > 0:
    if x >= 0:
        x -= d
    else:
        x += d

    if abs(x) >= abs(x_pre):
        if k % 2 == 0:
            print(abs(x_pre))
            exit()
        else:
            print(abs(abs(x_pre) - d))
            exit()
    else:
        x_pre = x
        k -= 1

print(abs(x_pre))
### BUGGY CODE ###

from itertools import combinations
n=int(input())
num = list(map(int,input().split()))
ans = 0
for i in combinations(num,2):
  s = (i[0]*i[1])%(10**9+7)
  ans += s

new = ans%(10**9+7)
print(new)

### FIXED CODE ###

n=int(input())
A = list(map(int,input().split()))
s=sum(A)
all=0
for i in A:
  s -= i
  all += (i*s)
ans=all%(10**9+7)
print(ans)
### BUGGY CODE ###

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

import copy
hats = A[:]

import queue
q = queue.Queue()

for i, h1 in enumerate(hats):
    hats2 = hats[i+1:]
    for j, h2 in enumerate(hats2):
        hats3 = hats2[j+1:]
        for h3 in hats3:
            set_hats = set(hats)
            set_hats.discard(h1)
            set_hats.discard(h2)
            set_hats.discard(h3)
            q.put({'top': h1, 'three': [h1, h2, h3], 'set_hats': set_hats})
            q.put({'top': h1, 'three': [h1, h3, h2], 'set_hats': set_hats})
            
ans = 'No'
while not q.empty():
    data = q.get()
    #print(data)
    three = data['three']
    
    if three[0] ^ three[2] != three[1]:
        continue
       
    top = data['top']
    if top == None:
        ans = 'Yes'
        break
    
    set_hats = data['set_hats']
    if len(set_hats) == 0:
        three = three[1:] + [top]
        top = None
        q.put({'top': top, 'three': three, 'set_hats': set_hats})
    else:
        for s in set_hats:
            tmp = copy.copy(set_hats)
            tmp.discard(s)
            three = three[1:] + [s]
            q.put({'top': top, 'three': three, 'set_hats': tmp})
        
print(ans)

### FIXED CODE ###

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

hats = A[:]
import copy
from collections import defaultdict
d = defaultdict(lambda: 0)

for h in hats:
    d[h] += 1

def f():
    if len(d) == 3:
        xor = 0
        for key in d:
            xor ^= key
        if xor == 0:
            lsit_d = list(d.keys())
            if d[lsit_d [0]] == d[lsit_d [1]] and d[lsit_d [0]] == d[lsit_d [2]]:
                return 'Yes'
            else:
                return 'No'
        else:
            return 'No'

    if len(d) == 1:
        lsit_d = list(d.keys())
        if lsit_d [0] == 0:
            return 'Yes'
        
    if len(d) == 2:
        if d[0] * 2 == N - d[0]:
            return 'Yes'
    
    return 'No'
    
print(f())
### BUGGY CODE ###

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

ans = 0

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

print(ans)
            

### FIXED CODE ###

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

a = [0]*n

for i in range(n):
    if s[i] == 'R':
        a[i] = 0
    if s[i] == 'G':
        a[i] = 1
    if s[i] == 'B':
        a[i] = 2

cnt = [0]*3

for i in range(n):
    cnt[a[i]] += 1

ans = 1

for i in range(3):
    ans *= cnt[i]

for j in range(n):
    for i in range(j):
        k = j + (j-i)
        if k < n:
            
            if a[i] == a[j]:
                continue
            if a[j] == a[k]:
                continue
            if a[k] == a[i]:
                continue
            ans -= 1
print(ans)
### BUGGY CODE ###

N = int(input())
C = 10 ** 9 + 7
B = 0
A = list(map(int, input().split()))
for i in range(N-1):
    for j in range(i+1, N):
        B += A[i] * A[j]        
print(B % C)        



### FIXED CODE ###

N = int(input())
C = 10 ** 9 + 7
B = 0
a = 0
ans = 0
A = list(map(int, input().split()))
for i in range(N):
    a += A[i]
for i in range(N-1):
    a -= A[i]
    B = A[i] * a
    ans += B
    B = 0    
print(ans % C)
### BUGGY CODE ###

N = int(input())
M = [x+1 for x in range(N)]
print(sum(M)-N)

### FIXED CODE ###

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

n = int(input())
L = sum([list(map(int, input().split())) for i in range(n)], [])
next = 1
count = 0
for i in range(n):
  if next == 2:
    print(i)
    quit()
  next = L[next-1]
print(-1)

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
cur = 1
cnt = 0
while True:
    if cur == 2:
        print(cnt)
        exit()
    elif cnt > n:
        print(-1)
        exit()
    else:
        cur = a[cur - 1]
        cnt += 1
### BUGGY CODE ###

from collections import defaultdict, deque
class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
    self.P = [1]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      self.P[x] = 0
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
      self.P[y] = 0
    else:
      self.par[y] = x
      self.P[y] = 0
      self.rank[x] += 1
      

N, M = map(int, input().split())
dic = defaultdict(list)
union = UnionFind(N)

for i in range(M):
  l, r, d = map(int, input().split())
  dic[l-1] += [(r-1,d)]
  dic[r-1] += [(l-1,-d)]
  union.unit(l-1, r-1)

dist = [-1]*N
pair = []
for x in range(N):
  if union.P[x]==1:
    pair += [(x,0)]
    dist[x] = 0

stuck = deque(pair)
while stuck:
  e, a = stuck.popleft()
  flag = False
  for c in dic[e]:
    p, d = c
    x = d + dist[e]
    if dist[p]==-1:
      dist[p] = x
      stuck += [(p, x)]
    elif dist[p]!=x:
      print('No')
      flag = True
      break
  if flag:
    break
else:
  print('Yes')

### FIXED CODE ###

from collections import defaultdict, deque
N, M = map(int, input().split())
used = [True]*N
dic = defaultdict(list)
for i in range(M):
  l, r, d = map(int,input().split())
  l -= 1
  r -= 1
  used[r] = False
  dic[l] += [(r,d)]

dist = [-1]*N
q = deque([])
for i in range(N):
  if used[i]:
    q += [i]
    dist[i] = 0

ans = True
while q:
  e = q.popleft()
  flag = False
  for p, d in dic[e]:
    if dist[p]==-1:
      dist[p] = d+dist[e]
      q += [p]
    elif dist[p]!=dist[e]+d:
      ans = False
      flag = True
      break
  if flag:
    break
if ans:
  if -1 not in dist:
    print('Yes')
  else:
    print('No')
else:
  print('No')
### BUGGY CODE ###

n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
for i in range(m) :
    b, c = list(map(int, input().split()))
    alist.sort()
    for j in range(b) :
        if alist[j] < c :
            alist[j] = c
        else :
            break
print(sum(alist))

### FIXED CODE ###

from operator import itemgetter

n, m = map(int, input().split())
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
bcbc.extend([[1, a] for a in aa])
bcbc.sort(key=itemgetter(1), reverse=True)

count = 0
s = 0
for b, c in bcbc :
    if count + b >= n :
        b = n - count
    count += b
    s += b*c
    if count == n :
        break
print(s)
### BUGGY CODE ###

N, A, B, K = map(int, input().split())

mod = 998244353
g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range(2, N+1):
  g1.append((g1[-1] * i) % mod)
  inv.append((-inv[mod % i] * (mod//i)) % mod)
  g2.append((g2[-1] * inv[-1]) % mod)

def cmb(n, r):
  if r < 0 or r > n:
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r]

ans = 0
for x in range(N+1):
  rest = K - A*x
  if rest % B == 0:
    y = rest // B
    for g in range(max(0, x+y-N), min(x,y)+1):
      r = x - g
      b = y - g
      ans += cmb(N, r) * cmb(N-r, g) * cmb(N-r-g, b)

print(ans % mod)

### FIXED CODE ###

N, A, B, K = map(int, input().split())

MOD = 998244353
factorials = [1]
inv_facts = [1]
for i in range(1, N+1):
    factorials.append(factorials[-1] * i % MOD)
    inv_facts.append(inv_facts[-1] * pow(i, MOD-2, MOD) % MOD)

def combi(n, k):
    ret = factorials[n]
    ret *= inv_facts[k]
    ret %= MOD
    ret *= inv_facts[n-k]
    ret %= MOD
    return ret

ans = 0
for a in range(N+1):
    rest = K - (A * a)
    if rest < 0:
        break
    if rest % B == 0:
        b = rest // B
        if b <= N:
            tmp = combi(N, a) * combi(N, b) % MOD
            ans += tmp
            ans %= MOD
print(ans)
### BUGGY CODE ###

import heapq

n= int(input())
s=[input() for i in range(n)]

ss = list(set(s))

if(len(s)==len(ss)):
    s.sort()
    for i in s:
        print(i)

else:
    li = []
    heapq.heapify(li)
    for i in ss:
        ans = s.count(i)
        heapq.heappush(li,(-ans,i))
    
    for i in range(len(ss)):
        amount,st = heapq.heappop(li)
        if(i==0):
            print(st)
            ri=amount
            continue
        
        if(ri==amount):
            print(st)
        else:
            break

### FIXED CODE ###

import collections

n= int(input())
s=[input() for i in range(n)]

li = collections.Counter(s)
ma= max(li.values())

ans= [i for i,j in li.items() if(j==ma)]
print("\n".join(sorted(ans)))