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

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from math import factorial

def func(x, arr):
    if len(arr) == 0:
        return x
    if x < arr[0]:
        return x * factorial(len(arr)) % MOD
    ret = 0
    for i in range(len(arr)):
        ret = (ret + func(x % arr[i], arr[:i] + arr[i + 1:])) % MOD
    return ret

def main():
    N, X = LI()
    S = LI()
    S.sort()
    ans = func(X, S)

    return ans

print(main())

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from math import factorial
from collections import Counter

def main():
    N, X = LI()
    S = LI()
    S.sort(reverse=True)
    dp = Counter()
    dp[X] = factorial(N)
    for i, s in enumerate(S):
        pre = dp
        dp = Counter()
        for n, cnt in pre.items():
            if s <= n:
                dp[n] += cnt * (N - 1 - i) // (N - i)
                dp[n % s] += cnt // (N - i)
            else:
                dp[n] += cnt
    ans = 0
    for n, cnt in dp.items():
        ans = (ans + (n * cnt) % MOD) % MOD

    return ans

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

from collections import Counter

def main():
    N = int(input())
    *A, = map(int, input().split())
    A.sort()
    C = Counter(A)

    MAX = 2000005
    T = [0]*MAX

    ans = 0
    for a in A:
        if T[a]:
            continue
        else:
            if C[a] == 1:
                ans += 1
            for i in range(2*a, MAX, a):
                T[i] += 1
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import Counter

def main():
    N = int(input())
    *A, = map(int, input().split())
    C = Counter(A)

    MAX = 1000005
    T = [0]*MAX

    ans = 0
    for a in C.keys():
        if T[a]:
            continue
        else:
            for i in range(2*a, MAX, a):
                T[i] = 1

    ans = 0
    for a, n in C.items():
        if n == 1 and T[a] == 0:
            ans += 1

    print(ans)


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

import sys
finput = sys.stdin.readline
n,m = map(int, finput().split())

tasks = [0]*n
rewards = [0]*n
total = [0]*(m+1)

for i in range(n):
    tasks[i],rewards[i] = [int(j) for j in finput().split()]

que = [idx for idx, item in enumerate(rewards) if item == max(rewards)]

day = 0
minflag = [idx for idx, item in enumerate(tasks) if item == min(tasks)]

while que:
    subtasks = [tasks[i] for i in que]
    while subtasks:
        t = max(subtasks)
        idx = subtasks.index(t)
        if t+day <= m:
            total[t+day:m+1] = [total[i]+rewards[que[idx]] for i in range(t+day,m+1)]
            day += 1
        del subtasks[idx]
        del tasks[que[idx]]
        del rewards[que[idx]]
        if que[idx] in minflag:
            del minflag[minflag.index(que[idx])]
            if minflag==[]:
                minflag = [idx for idx, item in enumerate(tasks) if item == min(tasks)]
        del que[idx]
        
    if rewards==[]:
        break
    if day+min(tasks)>m:
        break
    que += [idx for idx, item in enumerate(rewards) if item == max(rewards)]

print(max(total))


### FIXED CODE ###

import heapq
import sys

finput = sys.stdin.readline

n,m = map(int, finput().split())

q = [[] for i in range(m)]

for i in range(n):
    a,b = [int(j) for j in finput().split()]
    if a>m:
        continue
    q[a-1].append(-b)

hq = []
heapq.heapify(hq)
ans = 0
for i in range(m):
    if len(hq)==0 and len(q[i])==0:
        continue
    for j in range(len(q[i])):
        heapq.heappush(hq, q[i][j])
    ans += heapq.heappop(hq)

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

from fractions import gcd

a, b = map(int, input().split())

ans = []
g = gcd(a,b)
while g > 1:
    for i in range(2,g+1):
        if g%i == 0:
            ans.append(i)
            while g%i == 0:
                g //= i
            break
print(len(ans)+1)

### FIXED CODE ###

from fractions import gcd
from math import sqrt, ceil

a, b = map(int, input().split())

ans = 0
tmp = 1
g = gcd(a,b)
while g > 1:
    for i in range(tmp+1,ceil(sqrt(g))):
        if g%i == 0:
            ans += 1
            tmp = i
            while g%i == 0:
                g //= i
            break
    else:
        # もうgでしか割れないはず
        ans += 1
        break
print(ans+1)
### BUGGY CODE ###

x = input()
y = x.split()
y = [int (i) for i in y]

length = y[0]
num    = y[1]

count  = 0
string = input()
for i in range(num):
    z = input()
    c = z.split()
    c = [int (i) for i in c]
    l = c[0] - 1
    r = c[1] - 1
    for j in range(l,r+1):
        if j+1 < r+1:
             if string[j] == "A" and string[j+1] == "C":
                 count +=1
    print(count)
    count = 0


### FIXED CODE ###

x = input()
y = x.split()
y = [int (i) for i in y]
string = input()

length = y[0]
num    = y[1]
arr    = [0] * (length + 1)
arr[0] = 0

count = 0
for i in range(length-1):
    if string[i] == "A" and string[i+1] == "C":
        count +=1
        arr[i+1] = count
    else:
        arr[i+1] = arr[i]

result   = 0
for i in range(num):
    z = input()
    c = z.split()
    c = [int (i) for i in c]
    l = c[0]
    r = c[1]
    result = arr[r-1] - arr[l-1]

    print(result)
    result = 0
### BUGGY CODE ###

N, M, Q = map(int, input().split())
trains = [list(map(int, input().split())) for _ in range(M)]
questions = [list(map(int, input().split())) for _ in range(Q)]
for q in questions:
    count = 0
    for train in trains:
        if q[0] <= train[0] and q[1] >= train[1]:
            count += 1
    print(count)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N, M, Q = map(int, input().split())

sum_table = [[0]*(N+1) for _ in range(N+1)]
for _ in range(M):
    l, r = map(int, input().split())
    sum_table[l][r] += 1

for i in range(1, N+1):
    for j in range(1, N+1):
        sum_table[i][j] += sum_table[i-1][j] + sum_table[i][j-1] - sum_table[i-1][j-1]

for _ in range(Q):
    p, q = map(int, input().split())
    print(sum_table[q][q] - sum_table[q][p-1] - sum_table[p-1][q] + sum_table[p-1][p-1])
### BUGGY CODE ###

def f(h, w):
    dt = [[-1, 0], [0, -1], [0, 1], [1, 0]]
    t = [[9] * (w + 2)]
    for _ in range(h):
        t += [[9] + [(c == "#") * 1 for c in input()] + [9]]
    t += [[9] * (w + 2)]
    kuro = set()
    for i, ti in enumerate(t):
        for j, tij in enumerate(ti):
            if tij == 1:
                kuro.add((i, j))
    cnt = -1
    while kuro:
        cnt += 1
        nxt = set()
        for i, j in kuro:
            t[i][j] = 1
            for di, dj in dt:
                ni, nj = i + di, j + dj
                if t[ni][nj] == 0:
                    nxt.add((ni, nj))
        kuro = nxt - kuro
    print(cnt)


h, w = map(int, input().split())
f(h, w)


### FIXED CODE ###

def f(h, w):
    dt = [[-1, 0], [0, -1], [0, 1], [1, 0]]
    t = [[True] * (w + 2)]
    for _ in range(h):
        t += [[True] + [(c == "#") for c in input()] + [True]]
    t += [[True] * (w + 2)]
    kuro = []
    for i, ti in enumerate(t[1:-1]):
        for j, tij in enumerate(ti[1:-1]):
            if tij:
                kuro+=[(i + 1, j + 1)]
    cnt = -1
    while kuro:
        cnt += 1
        nxt = []
        for i, j in kuro:
            ti=t[i]
            if not ti[j+1]:
                ti[j + 1]=True
                nxt += [(i, j+1)]
            if not ti[j-1]:
                ti[j - 1]=True
                nxt += [(i, j-1)]
            if not t[i - 1][j]:
                t[i - 1][j]=True
                nxt += [(i - 1, j)]
            if not t[i + 1][j]:
                t[i + 1][j]=True
                nxt += [(i + 1, j)]
        kuro = nxt
    print(cnt)


h, w = map(int, input().split())
f(h, w)
### BUGGY CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    if ia < ib:
        union_list[ib] = ia
    elif ia > ib:
        union_list[ia] = ib
    elif ia==ib:
        union_list[ia] -= 1
        union_list[ib] = ia
    


def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

print(ans)




### FIXED CODE ###

#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    if ia == ib:
        return 
        
    if ia < ib:
        union_list[ib] = ia
    elif ia > ib:
        union_list[ia] = ib
    


def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

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

H = int(input())
i = 0

while True:
    H //= 2
    i += 1
    if H == 1:
        break

suretu = [None] * (i + 1)

for i in range(i+1):
    suretu[i] = 2**i

result = sum(suretu)
print(result)

### FIXED CODE ###

H = int(input())
i = 0
result = 0
 
while True:
    result += 2**i
    H //= 2
    i += 1
    if H == 0:
        break
 
print(result)
### BUGGY CODE ###

n,m=map(int,input().split())
L=[]
x=m/n
for i in range(1,int(x+1)):
  if m%i==0:
    if i<=x:
      L.append(i)
    if m//i<=x:
      L.append(m//i)
print(max(L))

### FIXED CODE ###

n,m=map(int,input().split())
L=[]
x=m/n
for i in range(1,min(int(x)+1,int(m**0.5)+1)):
  if m%i==0:
    if i<=x:
      L.append(i)
    if m//i<=x:
      L.append(m//i)
print(max(L))
### BUGGY CODE ###

s = input()
ans = 0
while True:
    pos_0 = s.find('01')
    pos_1 = s.find('10')
    if pos_0==-1 and pos_1==-1:
        break
    pos = max(pos_0,pos_1)
    s = s[:pos]+s[pos+2:]
    ans+=2
print(ans)


### FIXED CODE ###

s = input()
print(min(s.count('0')*2,s.count('1')*2))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import math
Q = int(input())

def isPrime(n):
    if n == 1:
        return False
    if n == 2:
        return True
    if n%2 == 0:
        return False
    for i in range(3, math.ceil(math.sqrt(n))+1, 1):
        if n % i == 0:
            return False
    return True



ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0
    for i in range(l, r+1, 2):
        #print(i, isPrime(i), isPrime((i+1)/2), isPrime((i+1)/2))
        if ((i+1)/2)%2 == 0 and (i+1)/2 != 2:
            continue
        else:
            if isPrime(i) and isPrime((i+1)/2):
                num += 1
    print(num)



### FIXED CODE ###

# -*- coding: utf-8 -*-
import math
Q = int(input())

ls = []
rs = []
for n in range(Q):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
    num = 0

max_r = max(rs)

def eratos(n):
    if n == 1:
        return set()
    primes = [1 for i in range(n+1)]
    primes[0] = 0
    primes[1] = 0
    for i in range(2,math.floor(math.sqrt(n))+1):
        if primes[i] == 1:
            j = i + i
            while j <= n:
                primes[j] = 0
                j = j + i
    return primes


def count_similar(era, n):
    count_similar = [0 for i in range(n+1)]
    for i in range(1,n+1):
        count_similar[i] = count_similar[i-1]
        if era[i] == 1 and era[int((i+1)/2)] == 1:
            count_similar[i] += 1
    return count_similar




era = eratos(max_r)
cnt = count_similar(era, max_r)

for l, r in zip(ls, rs):
    print(cnt[r] - cnt[l-1])
### BUGGY CODE ###

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

count = 0
for x in range(k+1):
	for y in range(k+1):
		for z in range(k+1):
			if x+y + z == s:
				count+=1
				
print(count)

### FIXED CODE ###

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

count = 0
for x in range(k+1):
	for y in range(k+1):
		if 0 <= s - (x + y) <= k:
			count+=1
				
print(count)
### BUGGY CODE ###

n, m, k = map(int, input().split())
MOD = 998244353

def modpow(a, n, p):
  if n == 0:
    return 1
  if n == 1:
    return a % p 
  elif n % 2 == 1:
    return a * modpow(a, n-1, p) % p
  else:
    return modpow(a, n//2, p) **2 % p
dp = [0]*(k+1)
dp[0] = m* modpow(m-1, n-1, MOD) % MOD
for j in range(1, k+1):
  bunsi = 1
  for i in range(n-1-j+1, n):
    bunsi = bunsi * i % MOD

  bunbo = 1
  for i in range(1, j+1):
    bunbo = bunbo * i % MOD

  comb = bunsi * modpow(bunbo, MOD-2, MOD) % MOD
  dp[j] = (m * modpow(m-1, n-1-j, MOD)*comb % MOD + dp[j-1]) % MOD
print(dp[k])

### FIXED CODE ###

n, m, k = map(int, input().split())
MOD = 998244353

def modpow(a, n, p):
  if n == 0:
    return 1
  if n == 1:
    return a % p 
  elif n % 2 == 1:
    return a * modpow(a, n-1, p) % p
  else:
    return modpow(a, n//2, p) **2 % p
dp = [0]*(k+1)
dp[0] = m* modpow(m-1, n-1, MOD) % MOD
bunsi = 1
bunbo = 1
for j in range(1, k+1):
  bunsi = bunsi * (n-j) % MOD
  bunbo = bunbo * j % MOD

  comb = bunsi * modpow(bunbo, MOD-2, MOD) % MOD
  dp[j] = (m * modpow(m-1, n-1-j, MOD)*comb % MOD + dp[j-1]) % MOD
print(dp[k])
### BUGGY CODE ###

n = int(input())
l = [[] for _ in range(n+1)]
s = [0 for _ in range(n+1)]
ll = []
for _ in range(n-1):
  ai,bi = map(int,input().split())
  l[ai].append(bi)
  l[bi].append(ai)
  ll.append([ai,bi])
  s[ai] += 1
  s[bi] += 1
mx = 0
for i in range(1,n+1):
  if s[i] > mx:
    mx = s[i]
    mxi = i
print(mx)
ans = [[0 for _ in range(n+1)] for _ in range(n+1)]
def dfs(a,b,c):
  i = 1
  for h in l[a]:
    if h != b:
      if i == c:
        i += 1
      ans[a][h] = i
      ans[h][a] = i
      dfs(h,a,i)
      i += 1
  return
dfs(mxi,0,0)
for xx in ll:
  print(ans[xx[0]][xx[1]])

### FIXED CODE ###

import sys
import resource
sys.setrecursionlimit(10**5)
n = int(input())
l = [[] for _ in range(n+1)]
s = [0 for _ in range(n+1)]
ll = []
for i in range(n-1):
  ai,bi = map(int,input().split())
  l[ai].append([bi,i])
  l[bi].append([ai,i])
  s[ai] += 1
  s[bi] += 1
mx = 0
for i in range(1,n+1):
  if s[i] > mx:
    mx = s[i]
    mxi = i
print(mx)
ans = [0 for _ in range(n-1)]
def dfs(a,b,c):
  i = 1
  for h,j in l[a]:
    if h != b:
      if i == c:
        i += 1
      ans[j] = i
      dfs(h,a,i)
      i += 1
  return
dfs(mxi,0,0)
for x in ans:
  print(x)
### BUGGY CODE ###

N=int(input())
for i in range(1,N+1):
  cnt=0
  for x in range(1,N-2):
    for y in range(1,N-x+1):
      for z in range(1,N-x-y+1):
        if i==x**2+y**2+z**2+x*y+y*z+z*x:
          cnt+=1
  print(cnt)
      

### FIXED CODE ###

import sys
input = sys.stdin.readline
import math

N=int(input())
ans=[0]*(N+1)
sn=int(math.sqrt(N)+1)
for x in range(1,sn+1):
  for y in range(1,sn+1):
    for z in range(1,sn+1):
      i=x**2+y**2+z**2+x*y+y*z+z*x
      if 1<=i<=N:
        ans[i]+=1
for h in range(1,N+1):          
  print(ans[h])
### BUGGY CODE ###

def func(z,c):
    if c == 0:
        z = 0
    else:
        z = z%c
    a = bin(z)
    b = 0
    for i in range(len(a)):
        if a[i] == "1":
            b += 1
    return z,b

n = int(input())
x = input()
c = 0
for i in range(n):
    if x[i] == "1":
        c += 1
X = int(x,2)

for i in range(n):
    
    if x[i] == "0":
        d = c + 1
        z = X + pow(2,n-i-1)
    else:
        d = c - 1
        z = X - pow(2,n-i-1)
    ans = 0
    #print(z,d)
    while z:
        z,d = func(z,d)
        ans += 1
    print(ans)
    

### FIXED CODE ###

def func(z,c):
    if c == 0:
        z = 0
    else:
        z = z%c
    a = bin(z)
    b = 0
    for i in range(len(a)):
        if a[i] == "1":
            b += 1
    return z,b

n = int(input())
x = input()
c = 0
for i in range(n):
    if x[i] == "1":
        c += 1
s0 = int(x,2)%(c+1)
if c <= 1:
    s1 = 0
else:
    s1 = int(x,2)%(c-1)
for i in range(n):
    sw = 0
    if x[i] == "0":
        d = c + 1
        z = (s0 + pow(2,n-i-1,d))%d
    else:
        d = c - 1
        if d == 0:
            z = 0
            sw = 1
        else:
            z = (s1 - pow(2,n-i-1,d))%d
    ans = 1
    p = bin(z)
    e = 0
    for A in str(p):
        if A == "1":
            e += 1
    d = e
    if sw == 1:
        ans = 0
    else:
        while z:
            z,d = func(z,d)
            ans += 1
    print(ans)
### BUGGY CODE ###

def count_divisors(n):
    counter = 0
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            if i != n // i: 
                counter += 2
            else:
                counter += 1
    return counter

# A * B  = N - C
N = int(input())
count = 0
for i in range(1, N):
    count += count_divisors(i)

print(count)

### FIXED CODE ###

N = int(input())

N_m1 = N - 1
counter = 0
for i in range(1, N_m1 + 1):
    counter += N_m1 // i

print(counter)
### BUGGY CODE ###

n = int(input())

sntlist = []
for i in range( n ):
    sntlist.append( input() )

def is_anagram( a, b ):
    for chr in a:
        if a.count( chr ) != b.count( chr ):
            return False
    return True

count = 0
for i in range( len( sntlist )-1 ):
    for j in range( i+1, len(sntlist) ):
        if is_anagram( sntlist[i], sntlist[j] ):
            count += 1
print(count)


### FIXED CODE ###

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

dict = {} 
for i in range(n):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  
 
count = 0;
for v in dict.values():
  count += (v * (v-1) // 2)
print(count)
### BUGGY CODE ###

s=raw_input();i=a=0;exec"a+=s[i]!=s[-~i];i+=1;"*~-len(s);print a

### FIXED CODE ###

s=raw_input()
print sum([s[i]!=s[i+1] for i in range(len(s)-1)])
### BUGGY CODE ###

N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()

for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)  
  print(S.count("AC", l, r))
 

### FIXED CODE ###

N, Q = input().strip().split()
N = int(N)
Q = int(Q)
S = input()

counts = [0 for _ in range(len(S))]
for i in range(1, len(S)):
  if S[i] == 'C' and S[i-1] == 'A':
    counts[i] = counts[i-1] + 1
  else:
    counts[i] = counts[i-1]
    
for q_i in range(Q):
  l, r = input().strip().split()
  l = int(l)-1
  r = int(r)-1  
  print(counts[r] - counts[l])
### BUGGY CODE ###

import math

n, m = map(int, input().split())
s = input()
t = input()


def lcm(x, y):
    return (x * y) // math.gcd(x, y)

l = (lcm(n, m))
# print(l)

slst = []
for i in range(n):
    num = i * l // n + 1
    slst.append(num - 1)
tlst = []
for i in range(m):
    num = i * l // m + 1
    tlst.append(num - 1)

# print(slst)
# print(tlst)

x = [0 for _ in range(l)]
idx = 0
for i in slst:
    x[i] = s[idx]
    idx += 1
# print(x)

idxt = 0
for i in tlst:
    if x[i] != 0:
        if x[i] != t[idxt]:
            print(-1)
            exit()
    idxt += 1
print(l)


### FIXED CODE ###

import math

n, m = map(int, input().split())
s = input()
t = input()


def lcm(x, y):
    return (x * y) // math.gcd(x, y)
l = (lcm(n, m))

sdict = {}
s_num = []
for i, moji in enumerate(list(s)):
    num = i * l // n + 1
    sdict[num - 1] = moji
    s_num.append(num - 1)

tdct = {}
t_num = []
for i, moji in enumerate(list(t)):
    num = i * l // m + 1
    tdct[num - 1] = moji
    t_num.append(num - 1)

stlst = list(set(s_num) & set(t_num))

for i in stlst:
    if sdict[i] != tdct[i]:
        print(-1)
        exit()
print(l)
### BUGGY CODE ###

n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
dp = [float('inf')]*n
dp[0] = 0

for i in range(1,n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(min(i,k)+1))

print(dp[n-1])

### FIXED CODE ###

n,k = [int(i) for i in input().split()]
h = [int(i) for i in input().split()]
inf = 10**10
dp = [inf]*n
dp[0] = 0
 
for i in range(1,n):
    dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]) for j in range(min(i,k)+1))
 
print(dp[n-1])
### BUGGY CODE ###

n = int(input())
s = [str(input()) for _ in range(n)]
d = dict((l,s.count(l)) for l in set(s))
max = max(d.values())
k = [x for x, y in d.items() if y ==max]
k.sort()
for i in k:
    print(i)


### FIXED CODE ###

n = int(input())
d = {}
for i in range(n):
    s = str(input())
    if s in d.keys():
        d[s] += 1
    else:
        d[s] = 1
max = max(d.values())
k = [x for x, y in d.items() if y ==max]
k.sort()
for i in k:
    print(i)
### BUGGY CODE ###

def main():
    n, k = map(int, input().split())
    ds = set()
    for _ in range(k):
        l, r = map(int, input().split())
        ds = ds | {i for i in range(l, r + 1)}
    dp = [0] * (n + 1)
    dp[1] = 1

    for i in range(1, n + 1):
        for d in ds:
            if i + d <= n:
                dp[i + d] = (dp[i + d] + dp[i]) % 998244353

    print(dp[-1] % 998244353)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    lr = [list(map(int, input().split())) for _ in range(k)]
    dp = [0] * (n + 1)
    dp[1] = 1
    dpsum = [0] * (n + 1)
    dpsum[1] = 1
    mod = 998244353

    for i in range(2, n + 1):
        for j in range(k):
            li = i - lr[j][1]
            ri = i - lr[j][0]
            if ri < 0:
                continue
            dp[i] = (dp[i] + dpsum[ri] - dpsum[li - 1]) % mod
        dpsum[i] = dpsum[i - 1] + dp[i]

    print(dp[-1] % mod)


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

from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque()
for s in S:
  ans.append(s)
for i,q in enumerate(query):
  if len(q)==1:
    tmp=''
    for a in ans:
      tmp+=a
    ans=deque(tmp[::-1])
  else:
    _,f,c=q
    if f=='1':
      ans.appendleft(c)
    else:
      ans.append(c)
print(*ans,sep='')

### FIXED CODE ###

from collections import deque
S=input()
Q=int(input())
query=[list(map(str,input().split())) for _ in range(Q)]

ans=deque(S)
reverse=False
for i,q in enumerate(query):
  if len(q)==1:
    reverse=not reverse
  else:
    _,f,c=q
    if (f=='2') ^ reverse:
      ans.append(c)
    else:
      ans.appendleft(c)
if reverse:
  print(*reversed(ans),sep='')
else:
  print(*ans,sep='')
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,input().split())
    val[a-1] += b 

def dps(i,parent): 
    for j in graph[i]:
        if j == parent:
            continue
        val[j] += val[i]
        dps(j,i)
                
dps(0,0)
print(*val[0:])
    
    


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,readline().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,readline().split())
    val[a-1] += b 

def dps(i,parent): 
    for j in graph[i]:
        if j == parent:
            continue
        val[j] += val[i]
        dps(j,i)
                
dps(0,-1)
print(*val)