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

import sys
input = sys.stdin.readline

N = int(input())
edge = [[None]*N for _ in range(N)]
sum_w = 0
for i in range(N-1):
    u, v, w = map(int, input().split())
    edge[u-1][v-1] = w
    sum_w += w
dist = [sum_w]*N
comp = [None]*N

is_finish = False
dist[0] = 0
while not is_finish:
    min_dist = sum_w+1
    min_ptr = -1
    for i in range(N):
        if comp[i] == None and dist[i] < min_dist:
            min_dist = dist[i]
            min_ptr = i
    if min_ptr < 0:
        is_finish = True
    else:
        comp[min_ptr] = 1
        for i in range(N):
            if comp[i] == None:
                if i < min_ptr and edge[i][min_ptr] != None:
                    dist[i] = dist[min_ptr] + edge[i][min_ptr]
                elif min_ptr < i and edge[min_ptr][i] != None:
                    dist[i] = dist[min_ptr] + edge[min_ptr][i]

for item in dist:
    print(item%2)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N = int(input())
tree = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    tree[u-1].append([v-1,w])
    tree[v-1].append([u-1,w])

dist = [None]*N
dist[0] = 0
comp = [0]*N
next_ptr = [0]
for ptr in next_ptr:
    comp[ptr] = 1
    edges = tree[ptr]
    for edge in edges:
        if comp[edge[0]] == 0:
            dist[edge[0]] = dist[ptr] + edge[1]
            next_ptr.append(edge[0])

for item in dist:
    print(item%2)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

L = []
sums = []
ans = []

def main():
    global L,ans,sums
    N,Q= map(int, input().split())
    ans = [0]*(N+1)
    sums = [0]*(N+1)
    L=[]
    [L.append([])for _ in range(N+1)]
    for _ in range(N-1):
        A,B = map(int, input().split())
        L[A].append(B)
        L[B].append(A)
    for _ in range(Q):
        p,x = map(int, input().split())
        sums[p]+=x
    dfs(1,0)

    print(*ans[1:N+1])


def dfs(p,pre):
    global L,ans,sums
    ans[p] = ans[pre] + sums[p]
    for i in range(len(L[p])):
        if pre==L[p][i]:
            continue    
        dfs(L[p][i],p)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline

L = []
sums = []
ans = []

def main():
    global L,ans,sums
    N,Q= map(int, input().split())
    ans = [0]*(N+1)
    sums = [0]*(N+1)
    L=[]
    [L.append([])for _ in range(N+1)]
    for _ in range(N-1):
        A,B = map(int, input().split())
        L[A].append(B)
        L[B].append(A)
    for _ in range(Q):
        p,x = map(int, input().split())
        sums[p]+=x
    dfs(1,0)

    print(*ans[1:N+1])


def dfs(p,pre):
    global ans
    ans[p] = ans[pre] + sums[p]
    for ki in L[p]:
        if pre==ki:
            continue    
        dfs(ki,p)


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

from operator import itemgetter
import heapq
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
heap_a = [-i for i in a]
heapq.heapify(heap_a)
b = []
c = []
for i in range(m):
    bi, ci = list(map(int, input().split()))
    b.append(bi)
    c.append(ci)
    for j in range(bi):
        heapq.heappush(heap_a, -ci)

s = 0

for i in range(n):
    s += -1 * heapq.heappop(heap_a)

print(s)


### FIXED CODE ###

from operator import itemgetter
import heapq
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
heap_a = [i for i in a]
heapq.heapify(heap_a)
b = []
c = []
for i in range(m):
    bi, ci = list(map(int, input().split()))
    b.append(bi)
    c.append(ci)

bc = zip(b, c)
bc = sorted(bc, key=itemgetter(1), reverse=True)
b, c = zip(*bc)

flag = False

for i in range(m):
    if flag:
        break
    for j in range(b[i]):
        min_a = heapq.heappop(heap_a)
        if min_a < c[i]:
            heapq.heappush(heap_a, c[i])
        else:
            heapq.heappush(heap_a, min_a)
            flag = True
            break
print(sum(heap_a))
### BUGGY CODE ###

import numpy as np

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

ans = np.zeros(N-1, np.int64)

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]


### FIXED CODE ###

import numpy as np

N, X, Y = map(int, input().split())
X -= 1
Y -= 1

ans = [0] * (N-1)

for i in range(N - 1):
    for j in range(i + 1, N):
        d1 = abs(j - i)
        d2 = abs(X - i) + 1 + abs(j - Y)
        ans[min(d1, d2) - 1] += 1

[print(ans[i]) for i in range(N - 1)]
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())
E = [set() for _ in range(N)]
C = {}
for i in range(N-1):
  a,b,c = map(int,input().split())
  E[a-1].add(b-1)
  E[b-1].add(a-1)
  C[min(a-1,b-1)*N+max(a-1,b-1)] = c
  
Q,K = map(int,input().split())
K -= 1
Query = []
for i in range(Q):
  x,y = map(int,input().split())
  Query.append([x-1,y-1])
#print(E)
#print(C)
#print(K)
#print(Query)

Kcost = [0 for _ in range(N)]
def dfs(u,v):
  if v != -1:
    Kcost[u] = Kcost[v] + C[min(u,v)*N+max(u,v)]
  for t in E[u]:
    if t != K and Kcost[t] == 0:
      dfs(t,u)
dfs(K,-1)

for x,y in Query:
  print(Kcost[x]+Kcost[y])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())
E = [set() for _ in range(N)]
C = {}
for i in range(N-1):
  a,b,c = map(int,input().split())
  E[a-1].add(b-1)
  E[b-1].add(a-1)
  C[min(a-1,b-1)*N+max(a-1,b-1)] = c
  
Q,K = map(int,input().split())
K -= 1
#print(E)
#print(C)
#print(K)

Kcost = [0 for _ in range(N)]
def dfs(u,v):
  if v != -1:
    Kcost[u] = Kcost[v] + C[min(u,v)*N+max(u,v)]
  for t in E[u]:
    if t != K and Kcost[t] == 0:
      dfs(t,u)
dfs(K,-1)

for i in range(Q):
  x,y = map(int,input().split())
  print(Kcost[x-1]+Kcost[y-1])
### BUGGY CODE ###

n = int(input())
s = [list(str(input())) for k in range(n)]
s_sorted = list(map(lambda x: sorted(x), s))
ans = 0
for i in range(n):
    for j in range(n):
        if i < j:
            if s_sorted[i] == s_sorted[j]:
                ans += 1
            else:
                pass
        else:
            pass
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
s_sorted = []
for _ in range(n):
    s_sorted.append(''.join(sorted(input())))
s_count = Counter(s_sorted)
ans = 0
for i in s_count:
    ans += (s_count[i] * (s_count[i] - 1)) // 2
print(ans)
### BUGGY CODE ###

def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    #print(Q)

    for i in range(q):
        if int(Q[i][0])==1:
            d.reverse()
            #print(s)
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                d.appendleft(Q[i][2])
                #print(s)
            else:
                d.append(Q[i][2])
                #print(s)
    print(''.join(list(d)))






resolve()

### FIXED CODE ###

def resolve():
    from collections import deque
    d=deque()
    s=list(input())
    d.extend(s)
    #print(d)
    q=int(input())
    Q=[list(map(str,input().split())) for i in range(q)]

    reverse= False
    for i in range(q):
        if int(Q[i][0])==1:
            reverse=not reverse
        elif int(Q[i][0])==2:
            if int(Q[i][1])==1:
                if reverse:
                    d.append(Q[i][2])
                else:
                    d.appendleft(Q[i][2])
                #print(s)
            else:
                if reverse:
                    d.appendleft(Q[i][2])
                else:
                    d.append(Q[i][2])
                #print(s)

    if reverse:
        print(''.join(list(reversed(d))))
    else:
        print(''.join(list(d)))






resolve()
### BUGGY CODE ###

n = int(input())
a = [int(s) for s in input().split()]
max_index = a.index(max(a))
count = 0
last_index = len(a)
while(last_index > 0):
    for i in range(max_index,last_index):
        count += a[max_index] - a[i]
    last_index = max_index
    if last_index == 0:
        break
    max_index = a.index(max(a[:last_index]))

print(count)

### FIXED CODE ###

n = int(input())
a = [int(s) for s in input().split()]
count = 0
max = a[0]
for i in range(1, len(a)):
    if max >  a[i]:
        if a[i - 1] > max:
            max = a[i - 1]
        count += max - a[i]
    else:
        max = a[i]
print(count)
### BUGGY CODE ###

from functools import reduce


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b

def llcm(l):
    return reduce(lcm, l)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    l = A[0]
    r = 0
    MOD = 10**9 + 7
    for i, a in enumerate(A):
        nl = lcm(l, a)
        r = (r * (nl // l) + nl // a) % MOD
        l = nl
    print(r)

main()


### FIXED CODE ###

from functools import reduce


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b

def llcm(l):
    return reduce(lcm, l)

def modinv(a, m):
    b, u, v = m, 1, 0
    while b:
        t = a // b
        a, b = b, a - t * b
        u, v = v, u - t * v
    u %= m
    if u < 0:
        u += m
    return u

def main():
    MOD = 10**9 + 7
    N = int(input())
    A = list(map(int, input().split()))
    l = llcm(A) % MOD
    r = 0
    for i, a in enumerate(A):
        r = (r + l * modinv(a, MOD)) % MOD
    return r

print(main())
### BUGGY CODE ###

s = input()
q = int(input())
is_r = False

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            s = q_i[2] + s
        else:
            s = s + q_i[2]

s = s if not is_r else s[::-1]
print(s)

### FIXED CODE ###

s = input()
q = int(input())
is_r = False
f_list = []
b_list = []

for i in range(q):
    q_i = input().split(' ')
    t_i = q_i[0]
    if t_i == '1':
        is_r = not is_r
    else:
        f_i = q_i[1]
        if (f_i == '1' and not is_r) or (f_i == '2' and is_r):
            f_list.append(q_i[2])
        else:
            b_list.append(q_i[2])

f_list = f_list[::-1]
f_list.append(s)
f_list.extend(b_list)
s = ''.join(f_list) if not is_r else ''.join(f_list)[::-1]
print(s)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(1000000)


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

ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]


class Tree():
    def __init__(self, v):
        self.parent = None
        self.v = v
        self.x = 0
        self.memo = None

    def add(self, x):
        self.x += x

    def calc(self):
        if self.v == 1:
            return self.x
        if self.memo is not None:
            return self.memo

        tmp = self.parent.calc()
        self.memo = tmp + self.x
        return self.memo



trees = {i: Tree(i) for i in range(1, N + 1)}

for a,b in ab:
    trees[b].parent = trees[a]

for p,x in px:
    trees[p].add(x)

ans = []
for i in range(1,N+1):
    ans.append(trees[i].calc())

print(" ".join(map(str,ans)))

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)


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

ab = [list(map(int, input().split())) for _ in range(N - 1)]
px = [list(map(int, input().split())) for _ in range(Q)]


class Tree():
    def __init__(self, v):
        self.parent = None
        self.v = v
        self.x = 0
        self.memo = None

    def add(self, x):
        self.x += x

    def calc(self):
        if self.v == 1:
            return self.x
        if self.memo is not None:
            return self.memo

        tmp = self.parent.calc()
        self.memo = tmp + self.x
        return self.memo



trees = {i: Tree(i) for i in range(1, N + 1)}

for a,b in ab:
    trees[b].parent = trees[a]

for p,x in px:
    trees[p].add(x)


print(" ".join(map(str,[trees[i].calc() for i in range(1,N+1)])))
### BUGGY CODE ###

n=(int)(input())
a = list(input() for i in range(n))
lis = sorted(list(set(a)))
big = [0 for i in range(len(lis))]
maxi = 0
for i in range(len(lis)):
  big[i] = a.count(lis[i])
maxi = max(big)
for i in range(len(lis)):
  if big[i] == maxi:
    print(lis[i])

### FIXED CODE ###

n=(int)(input())
a = sorted(list(input() for i in range(n)))
lis = sorted(list(set(a)))
big = [0 for i in range(len(lis))]
maxi = 0
counter = 1
check = 0
#print(a)
for i in range(len(a) - 1):
  #print(a[i])
  if a[i] == a[i + 1]:
    counter += 1
  else:
    big[check] = counter
    counter = 1
    check += 1
else:
  big[-1] = counter
maxi = max(big)
#print(lis, big)
for i in range(len(lis)):
  if big[i] == maxi:
    print(lis[i])
### BUGGY CODE ###

s = input()
a, b = -1, -1
N = len(s)
for i in range(N):
    for j in range(N):
        d = [0] * 26
        for k in range(i, j + 1):
            d[ord(s[k]) - ord("a")] += 1
        if max(d) > (j - i + 1) // 2 and j - i >= 1:
            a, b = i + 1, j + 1
            break
print(a, b)

### FIXED CODE ###

S = input()
N = len(S)
for i in range(N - 1):
    if S[i] == S[i + 1]:
        print(i + 1, i + 2)
        exit(0)

for i in range(N - 2):
    if S[i] == S[i + 2]:
        print(i + 1, i + 3)
        exit(0)

print(-1, -1)
### BUGGY CODE ###

n,a,b = map(int,input().split())
ans = 2**n-1

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

ans -= cmb(n,a)+cmb(n,b)

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

### FIXED CODE ###

mod =10**9+7
n,a,b = map(int,input().split())
ans = pow(2,n,mod)-1
def cmb(n,k):
    x,y = 1,1
    for i in range(k):
        x = x * (n-i) % mod
        y = y * (k-i) % mod
    return x * pow(y, mod-2, mod) % mod
ans -= cmb(n,a) + cmb(n,b)
print(ans%mod)
### BUGGY CODE ###

N, K =map(int, input().split())
min = N
 
while abs(N-K) < min:
	if abs(N-K) < min:
		min = abs(N-K)
		N -= K
 
print(min)

### FIXED CODE ###

N, K=map(int, input().split())
min=min(N%K, abs((N%K)-K))
print(min)
### BUGGY CODE ###

num = n = int(input())
price = []
max_profit = -999999999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
for i in range(1,num):
    for n in range(0,i):
        pro = price[i] - price[n]
        if pro > max_profit:
            max_profit = pro

print("{0}".format(max_profit))

### FIXED CODE ###

num= n = int(input())

price = []
max_pro = -999999999

while(n>0):
    x = int(input())
    price.append(x)
    n -= 1
min = price[0]
for i in range(1,num):
    pro = price[i]-min

    if(max_pro < pro):
        max_pro = pro
    if(min > price[i]):
        min = price[i]
print ("{0}".format(max_pro))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(10 ** 9 // n):
    f = 0
    for j in range(n):
        f += i % a[j]
    print(f)
    ans.append(f)
print(max(ans))


### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int, input().split()))
f = 0
ans = np.cumsum(a) - n
print(ans[-1])
### BUGGY CODE ###

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

pair = n*(n - 1)/2
not_4 = 0
ans = 'Yes'
num = len(a)
for i in range(num):
  for j in range(num):
    
    if i != j and a[i]*a[j]%4 != 0:
      not_4 += 1
      
      
    if not_4 >= pair:
      ans = 'No'
      break
    
print(ans)

### FIXED CODE ###

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

four = 0
two = 0
one = 0
for i in a:
  if i%4 == 0:
    four += 1
  elif i%2 == 0 and i%4 != 0:
    two += 1
  elif i%2 != 0:
    one += 1

if four >= one or four + 1 >= two//2 + two%2 + one or n == two:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

N = int(input())

for h in range(1, 3500+1):
  for n in range(1, 3500+1):
    if 4*h*n - N*n - N*h == 0:
      continue
    w = (N*h*n) // (4*h*n - N*n - N*h)
    if w < 1 or w > 3500:
      continue
    if 4*h*n*w == N*(n*w + h*w + n*h):
      print(h, n, w)
      exit()

### FIXED CODE ###

N = int(input())

for h in range(1, 3500+1):
  for n in range(1, 3500+1):
    if 4*h*n - N*n - N*h == 0:
      continue
    w = (N*h*n) // (4*h*n - N*n - N*h)
    if w < 1 or w > 3500:
      continue
    if 4*h*n*w == N*(n*w + h*w + n*h):
      print(h, n, w)
      exit()
### BUGGY CODE ###

import sys
import copy
import math
import itertools
#import numpy as np
import re

N = int(input())
A = [int(input()) for c in range(N)]
A_s = list(set(A))
cnt=0

for i in A_s:
    if A.count(i)%2 == 1:
        cnt+=1

print(cnt)

### FIXED CODE ###

N = int(input())
A = [int(input()) for c in range(N)]
A = sorted(A)

tmp = 1
cnt = 0
for i in range(N):    
    if i+1<N:
        if A[i] == A[i+1]:
            tmp += 1
        else:
            cnt += tmp%2
            tmp = 1
    else:
        cnt += tmp%2

print(cnt)
### BUGGY CODE ###

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

pre = A
for i in range(0,K,1):
    now = [0]*N
    for j in range(0,N,1):
        for k in range(max(0,j-pre[j]),min(N,j+pre[j]+1),1):
            now[k]+=1
    owari = True
    for j in range(0,N,1):
        if now[j]!=N:
            owari = False
        pre[j]=now[j]
    if owari:
        break
print(" ".join(list(map(str,now))))

### FIXED CODE ###

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

pre = A
for i in range(0,K,1):
    now = [0]*N

    kuiL = [0]*N
    kuiR = [0]*N
    for j in range(0,N,1):
        #for k in range(max(0,j-pre[j]),min(N,j+pre[j]+1),1):
        #    now[k]+=1
        kuiL[max(0,j-pre[j])]+=1
        kuiR[min(N-1,j+pre[j])]+=1
    tmp = 0
    for j in range(0,N,1):
        if j!=0:
            tmp = tmp + kuiL[j]-kuiR[j-1]
        else:
            tmp = tmp + kuiL[j]
        now[j]+=tmp

    owari = True
    for j in range(0,N,1):
        if now[j]!=N:
            owari = False
        pre[j]=now[j]
    if owari:
        break
print(" ".join(list(map(str,now))))
### BUGGY CODE ###


n,m = map(int,input().split())
s = list(input())
abli = [tuple(map(int,input().split())) for i in range(m)]

def addEdge(graph,u,v):
    graph[u].append(v)


def adjAB(graph,node):
    Aflag =False
    Bflag =False
    for i in graph[node]:
        if s[i-1]=='A':
            Aflag = True
        if s[i-1]=='B':
            Bflag = True
        if Aflag and Bflag:
            break
    if Aflag and Bflag:
        return(True)
    else:
        return(False)


def deleteNode(graph,node):
    graph.pop(node,None)
    for i in graphAB:
        while node in graph[i]:
            graph[i].remove(node)
        


from collections import defaultdict
graphAB = defaultdict(list)

for i,j in abli:
    addEdge(graphAB,i,j)
    if i != j:
        addEdge(graphAB,j,i)


visitset = set(graphAB.keys())

while bool(visitset):
    i = visitset.pop()
    #print(i,visitset)
    if not adjAB(graphAB,i):
        #print(i)
        tmp = set(graphAB[i])
        if i in tmp:
            tmp.remove(i)
        visitset = visitset | tmp
        deleteNode(graphAB,i)




if graphAB == {}:
    print('No')
else:
    print('Yes')





### FIXED CODE ###

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
GC027 C
"""

n,m = map(int,input().split())
s = list(input())
edges = [tuple(map(int,input().split())) for i in range(m)]
ali = [0 for i in range(n)]
bli = [0 for i in range(n)]


def addEdge(graph,u,v):
    graph[u].add(v)


from collections import defaultdict
graphAB = defaultdict(set)

def incrementAB(node,adj):
    if s[adj-1] == 'A':
        ali[node-1]+=1
    if s[adj-1] == 'B':
        bli[node-1]+=1

def decrementAB(node,adj):
    if s[adj-1] == 'A':
        ali[node-1]-=1
    if s[adj-1] == 'B':
        bli[node-1]-=1

for i,j in edges:
    addEdge(graphAB,i,j)
    addEdge(graphAB,j,i)

def adjAB(node):
    if ali[node-1]!=0 and bli[node-1]!=0:
        return(True)
    else:
        return(False)

graphvers = set(graphAB.keys())
visitset = set()
for i in range(1,n+1):
    if not i in graphvers:
        s[i-1] = 'C'
    else:
        for j in graphAB[i]:
            incrementAB(i,j)
        if not adjAB(i):
            visitset.add(i)


while bool(visitset):
    #print(graphAB)
    #print(graphABopp)
    #print(abli)
    i = visitset.pop()
    for j in graphAB[i]:
        if s[j-1] != 'C':
            decrementAB(j,i)
            if not adjAB(j):
                visitset.add(j)
    s[i-1] = 'C'

#print(graphAB)
#print(graphABopp)

sset= set(s)
sset.add('C')
sset.remove('C')
if bool(sset):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

import collections as col
N=int(input())
S=[]
answer=[]

for _ in range(N):
    S.append(input())
T=sorted(S)
s=col.Counter(T)
values, counts = zip(*s.most_common())
#print(values,counts)



for i in range(len(counts)):
    if counts[i]==max(counts):
        answer.append(values[i])
answer.sort()
for j in answer:
    print(j)
 

### FIXED CODE ###

N=int(input())
S=[input() for _ in range(N)]

S_d={}
A=[]

for i in range(N):
    if S[i] not in S_d.keys():
        S_d[S[i]]=1
    else:
        S_d[S[i]]+=1

max_co=max(S_d.values())

for j in S_d.keys():
    if S_d[j]==max_co:
        A.append(j)

B=sorted(A)

for k in B:
    print(k)
### BUGGY CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
# dp[n][i][s] := i 番目まで見て n 個使って合計が s になる場合の数 これは無理
# dp[i][s] := i 番目まで見て合計 s 
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
    for s in range(S+1):
        if s-a >= 0:
            dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
        else:
            dp[i][s] = dp[i-1][s] * 2 % mod
print(dp[N][S])


### FIXED CODE ###

N, S = map(int, input().split())
A = list(map(int, input().split()))
# dp[n][i][s] := i 番目まで見て n 個使って合計が s になる場合の数 これは無理
# dp[i][s] := i 番目まで見て合計 s 
dp = [[0]*(S+1) for _ in range(N+1)]
dp[0][0] = 1
mod = 998244353
for i, a in enumerate(A, 1):
    for s in range(S+1):
        if s-a >= 0:
            dp[i][s] = (dp[i-1][s] * 2 + dp[i-1][s-a]) % mod
        else:
            dp[i][s] = dp[i-1][s] * 2 % mod
print(dp[N][S])
### BUGGY CODE ###

H, W, M = map(int,input().split())

X = [0] * H
Y = [0] * W

B = []
h = H
while h:
    h -= 1
    B.append([])
    
A = []
m = M
while m:
    m -= 1
    x, y = map(int,input().split())
    x, y = x -1, y -1
    A.append((x, y))
    B[x].append(y)
    X[x] += 1
    Y[y] += 1

def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

xm = max(X)
ym = max(Y)
xms = my_index_multi(X, xm)
yms = my_index_multi(Y, ym)

ans = False
for i in xms:
    for j in yms:
        if not j in B[i]:
            ans = True
            break
  
cnt = xm + ym         
print(cnt if ans else cnt - 1)

### FIXED CODE ###

import sys

input = sys.stdin.readline
H, W, M = map(int,input().split())
q=set(tuple(map(lambda x :int(x)-1,input().split())) for _ in range(M))

X = [0] * H
Y = [0] * W

for i, j in q:
    X[i] += 1
    Y[j] += 1
    
def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

xm = max(X)
ym = max(Y)
xms = my_index_multi(X, xm)
yms = my_index_multi(Y, ym)

ans = xm + ym - 1

bl = False
for i in xms:
    for j in yms:
        if not (i, j) in q:
            print(ans + 1)
            sys.exit()
            bl = True
            
print(ans)
### BUGGY CODE ###

s=input()
k=int(input())
ans=[]
for i in range(1,len(s)+1):
    ans=ans+[s[x:x+i] for x in range(len(s)-i+1)]
    ans=list(set(ans))
print(sorted(ans)[k-1])

### FIXED CODE ###

s=input()
k=int(input())
moji=sorted(list(set(s)))
ans=[moji[0]]
mojinum=0
if k==1:
    print(ans[0])
    import sys
    sys.exit()
while(True):
    for r in range(len(moji)):
        if ans[-1]+moji[r] in s:
            ans.append(ans[-1]+moji[r])
            break
        elif r==len(moji)-1:
            mojinum+=1
            ans.append(moji[mojinum])
    if len(ans)>=k:
        break
print(ans[k-1])