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

# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]

    INF = float('inf')
    dp = [[INF] * (2*H+2) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(2*H+2):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
# from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
sys.setrecursionlimit(10 ** 7)
from heapq import heappop, heappush
#from collections import defaultdict
# import math
# from itertools import product, accumulate, combinations, product
# import bisect# lower_bound etc
#import numpy as np
# from copy import deepcopy
#from collections import deque
#import numba

def run():
    H, N = map(int, sysread().split())
    AB = list(map(int, read().split()))
    A = AB[::2]
    B = AB[1::2]
    Amax = max(A)

    INF = float('inf')
    dp = [[INF] * (H+Amax+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+Amax+1):
            tmp = j - A[i]
            if tmp >= 0:
                dp[i+1][j] = min([dp[i][j], dp[i+1][tmp] + B[i]])
            elif j == H and tmp < 0:
                dp[i + 1][H] = min(dp[i][H], dp[i + 1][0] + B[i])
            else:
                dp[i+1][j] = dp[i][j]
    ret = min(dp[N][H:])
    print(ret)



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

S = input()
N = len(S)
l = list()
n = 0
out = 0
for i in range(N-1, -1, -1):
    n += int(S[i]) * (10**(N-1 - i))
    r = n % 2019
    l.append(r)
for i in range(2019):
    m = l.count(i)
    out += (m*(m-1))//2 
    if i == 0:
        out += m
print(out)

### FIXED CODE ###

S = input()[::-1]
N = len(S)
l = [0]*2019
l[0] = 1
n = 0
d = 1

for i in range(N):
    n += int(S[i]) * d
    r = n % 2019
    l[r] += 1
    d = 10*d % 2019
    
out = 0    
for m in l:
    out += (m*(m-1))//2 
print(out)
### BUGGY CODE ###

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

points = [0 for _ in range(N)]
for i in range(Q):
  p, x = map(int, input().split())
  points[p-1] += x
  
def dfs(v, pv):
  for nv in G[v]:
    if nv != pv:
      points[nv] += points[v]
      dfs(nv, v)

dfs(0, 0)
print(*points)

### FIXED CODE ###

#138_D
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
    
def dfs(frm, cur):
    for to in edges[cur]:
        if to != frm:
            cnt[to] += cnt[cur]
            dfs(cur, to)
dfs(-1, 0)          
print(*cnt)
### BUGGY CODE ###

n = int(input())
s = input()
cnt = 0
r = s.count('R')
g = s.count('G')
b = s.count('B')

for i in range(n):
    for j in range(i,n):
        if i == j:
            continue
        k = 2 * j - i
        if k > len(s) - 1:
            continue
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            cnt +=1

all = r * g * b
print(all - cnt)

### FIXED CODE ###


def main():
    n = int(input())
    s = str(input())
    cnt = 0
    r = s.count('R')
    g = s.count('G')
    b = s.count('B')

    for i in range(n):
        for j in range(i,n):
            if i == j:
                continue
            k = 2 * j - i
            if k > len(s) - 1:
                continue
            if s[i] == s[j] or s[j] == s[k] or s[k] == s[i]:
                continue

            cnt +=1

    all = r * g * b
    print(all - cnt) 
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    total = 0
    x = a.copy()
    del x[i]
    x = collections.Counter(x)
    for v in x.values():
        total += v*(v-1)//2
    print (total)


### FIXED CODE ###

import collections
n = int(input())
a = list(map(int, input().split()))
l = [0]*n
ans = 0

for k,v in collections.Counter(a).items():
    l[k-1] = v
    ans += v*(v-1)//2

for i in range(n):
    print (ans-l[a[i]-1]+1)
### BUGGY CODE ###

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


from collections import defaultdict
display_num = defaultdict(int)
move_num = defaultdict(int)
connection = defaultdict(lambda: defaultdict(int))
def_room = defaultdict(int)

for i in range(M):
  A, B = map(int, input().split())
  connection[A-1][B-1] = 1
  connection[B-1][A-1] = 1

c = defaultdict(int)
d = defaultdict(lambda: 10**10)
p = defaultdict(lambda: -1)
d[0] = 0
p[0] = -1

while True:
  mincost = 10**10
  for i in range(N):
    if c[i] != 2 and d[i] < mincost:
      mincost = d[i]
      u = i
  if mincost == 10**10:
    break
  c[u] = 2
  for v in range(N):
    if c[v] != 2 and connection[u][v] == 1:
      if d[u] + 1 < d[v]:
        d[v] = d[u] + 1
        p[v] = u
        c[v] = 1
print("Yes")
for i in range(1,N):
  print(p[i] + 1)


### FIXED CODE ###

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


from collections import defaultdict
import queue
connection = defaultdict(lambda: defaultdict(int))

for i in range(M):
  A, B = map(int, input().split())
  connection[A-1][B-1] = 1
  connection[B-1][A-1] = 1

c = defaultdict(int)
q = queue.Queue()
d = defaultdict(int)
p = defaultdict(int)

c[0] = 1
d[0] = 0
q.put(0)

while not(q.empty()):
  u = q.get()
  for v in connection[u]:
    if c[v] == 0:
      c[v] = 1
      d[v] = d[u] + 1
      p[v] = u
      q.put(v)
  c[u] = 2
print("Yes")
for i in range(1,N):
  print(p[i] + 1)
### BUGGY CODE ###

A,B=map(int,input().split())
mod = 2018
for i in range(A,B):
  for j in range(i+1,B+1):
    mod = min(mod,(i*j)%2019)
print(mod)

### FIXED CODE ###

A,B=map(int,input().split())
mod = 2018
flag =0
for i in range(A,B):
  x = i % 2019
  for j in range(i+1,B+1):
    j = j % 2019
    mod = min(mod, (x*j)%2019)
    if mod == 0:
      flag = 1
      break
  if flag:
    break

print(mod)
### BUGGY CODE ###

import sys
import bisect
input = sys.stdin.readline

def find(x):
    if par[x]==x:
        return x
    else:
        return find(par[x])

def unite(x,y):
    x=find(x)
    y=find(y)
    if x==y:return
    if rank[x]<rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x]+=1

def same(x,y):
    return find(x)==find(y)

 
def main():
    n,k,l = map(int,input().split()) 
 
    global par,rank
    par  = [i for i in range(2*n)]
    rank = [0 for _ in range(2*n)] 
    for _ in range(k):
        p,q = map(int,input().split())
        p-=1
        q-=1
        unite(p,q)
    for _ in range(l):
        p,q = map(int,input().split())
        p-=1
        q-=1
        unite(p+n,q+n)

    ans=[0 for _ in range(n)]
    for i in range(n):
        for j in range(n):
            if same(i,j) and same(i+n,j+n):
                ans[i]+=1
    for i in range(n):
        print(ans[i])

main()

### FIXED CODE ###

from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue,copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inpln(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])

def find(x): # 木の根を求める
    if par[x]==x:
        return x
    else:
        return find(par[x])

def unite(x,y): # xとyの属する集合を併合
    x=find(x)
    y=find(y)
    if x==y:return
    if rank[x]<rank[y]:
        par[x]=y
    else:
        par[y]=x
        if rank[x]==rank[y]:
            rank[x]+=1

def same(x,y): # xとyが同じ集合に属するか判定
    return find(x)==find(y)
 
def main():
    n,k,l = inpm()
 
    global par,rank
    par  = [i for i in range(2*n)]
    rank = [-1 for _ in range(2*n)] 
    for _ in range(k):
        p,q = inpm()
        p-=1
        q-=1
        unite(p,q)
    for _ in range(l):
        r,s = inpm()
        r-=1
        s-=1
        unite(r+n,s+n)

    root_s=defaultdict(int)
    root=[]
    for i in range(n):
        root.append(str(find(i))+' '+str(find(i+n)))
        root_s[root[i]]+=1
    
    ans=[0 for _ in range(n)]
    for i in range(n):
        ans[i] = root_s[root[i]]
    print(*ans) 


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

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

r = [t for t in range(a, b + 1)]
r = r[:k] + r[-k:]
r = list(set(r))
r = sorted(r)

for _r in r:
    print(_r)

### FIXED CODE ###

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

r = range(a, b + 1)
r = list(set(r[:k]) | set(r[-k:]))
r.sort()

for _r in r:
    print(_r)
### BUGGY CODE ###

import pprint
N, W = map(int, input().split())
weight = []
value = []
for _ in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)
value_sum = sum(value)
dp = []
for _ in range(N + 1):
    dp_val = [float('inf') for _ in range(value_sum + 1)]
    dp.append(dp_val)
# print(dp)
dp[0][0] = 0
# for v in range(value_sum):
#     dp[0][v] = 0
for idx in range(N):
    for v in range(value_sum + 1):
        if value[idx] <= v:
            dp[idx + 1][v] = min(dp[idx][v], dp[idx][v - value[idx]] + weight[idx])
        else:
            dp[idx + 1][v] = dp[idx][v]
ans = 0
# print(dp)
for i in range(value_sum + 1):
    if dp[-1][i] <= W:
        ans = i
print(ans)

### FIXED CODE ###

N, W = map(int, input().split())
weight = []
value = []
for _ in range(N):
    w, v = map(int, input().split())
    weight.append(w)
    value.append(v)
value_sum = sum(value)
dp = []
for _ in range(N + 1):
    dp_val = [float('inf') for _ in range(value_sum + 1)]
    dp.append(dp_val)
dp[0][0] = 0

for idx in range(N):
    for v in range(value_sum + 1):
        if value[idx] <= v:
            dp[idx + 1][v] = min(dp[idx][v], dp[idx][v - value[idx]] + weight[idx])
        else:
            dp[idx + 1][v] = dp[idx][v]
ans = 0
# print(dp)
for i in range(value_sum + 1):
    if dp[-1][i] <= W:
        ans = i
print(ans)
### BUGGY CODE ###

def main():
  N,M = map(int,input().split())
  a = [int(input()) for i in range(M)]
  m = 10**9+7

  dp = [0]*(N+1)
  dp[0] = 1
  if 1 not in a:
    dp[1] = 1
  for i in range(2,N+1):
    if i not in a:
      dp[i] = dp[i-1] + dp[i-2]
      dp[i] %= m
  print(dp[-1])

if __name__ == '__main__':
  main()

### FIXED CODE ###

def main():
  N,M = map(int,input().split())
  a = [int(input()) for i in range(M)]
  m = 10**9+7
  
  stair = [0]*(N+1)
  for i in a:
    stair[i] = -1
  
  dp = [0]*(N+1)
  dp[0] = 1
  if 1 not in a:
    dp[1] = 1
  for i in range(2,N+1):
    if stair[i] == 0:
      dp[i] = dp[i-1] + dp[i-2]
      dp[i] %= m
  print(dp[N])

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

import sys
input = sys.stdin.readline
from collections import deque

N, M , K = [int(x) for x in input().split()]
AB = []
G_F = [deque([]) for _ in range(N)]
G_B = [deque([]) for _ in range(N)]
G_F_s = [set() for _ in range(N)]
G_B_s = [set() for _ in range(N)]
for _ in range(M):
    AB = [int(x) for x in input().split()]
    G_F[AB[0] - 1].append(AB[1] - 1)
    G_F[AB[1] - 1].append(AB[0] - 1)
    G_F_s[AB[0] - 1].add(AB[1] - 1)
    G_F_s[AB[1] - 1].add(AB[0] - 1)

CD = []
for _ in range(K):
    CD = [int(x) for x in input().split()]

    G_B[CD[0] - 1].append(CD[1] - 1)
    G_B[CD[1] - 1].append(CD[0] - 1)
    G_B_s[CD[0] - 1].add(CD[1] - 1)
    G_B_s[CD[1] - 1].add(CD[0] - 1)

ans = 0
from collections import deque
G_F = deque(G_F)
G_B = deque(G_B)

# グラフの作成(無向グラフでは#を消す)

time = 0
arrive_time = [-1] * (N) # 到着時刻

# 深さ優先探索
def dfs(v, graph):
    global time
    time += 1
    stack = [v]
    arrive_time[v] = time
    while stack:
        v = stack[-1]
        if graph[v]:
            w = graph[v].popleft()
            if arrive_time[w] < 0:
                time += 1
                arrive_time[w] = time
                stack.append(w) 
        else:
            stack.pop()          
    return arrive_time
import copy
ans = [0] * N
for i in range(N - 1):
    for j in range(i + 1, N):
        arrive_time = [-1] * N
        if j in G_B_s[i] or j in G_F_s[i]:
            continue
        graph = copy.deepcopy(G_F)
        arrive_time = dfs(i, graph)
        if arrive_time[j] > 0:
            ans[i] += 1
            ans[j] += 1

print(*ans)




### FIXED CODE ###

import sys
input = sys.stdin.readline
 
n,m,k = map(int,input().split())
ab = [set() for _ in range(n)]
cd = [[] * n for _ in range(n)]

 
#Union Find
 
#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True
 
#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]
 
#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

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

for i in range(k):
    c, d = [int(x) for x in input().split()]
    if same(c - 1, d - 1):
        cd[c - 1].append(d - 1)
        cd[d - 1].append(c - 1)

ans = [0] * n

for i in range(n):
    ans[i] = size(i) - 1 - len(cd[i]) - len(ab[i])

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

N,M=map(int,input().split())
mod=998244353

MAX=3*M//2+N

inv=[0]*(MAX+1)
inv[1]=1
for i in range(2,MAX+1):
    inv[i]=-(mod//i)*inv[mod%i]%mod

g1=[1,1]
g2=[1,1]
for i in range(2,MAX+1):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(g2[-1]*inv[i]%mod)
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

ans=0
for i in range(min(N+1,M+1)):
    if M%2!=i%2:
        continue
    m=(3*M-i)//2
    num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod
    if m>=M+1:
        num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod
    ans=(ans+cmb(N,i)*num)%mod

print(ans)  

### FIXED CODE ###

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

inv=[0]*(3*M//2+N+2)
inv[1]=1
for i in range(2,3*M//2+N+2):
    inv[i]=-(mod//i)*inv[mod%i]%mod

#階乗テーブル
g1=[1,1]
g2=[1,1]
for i in range(2,3*M//2+N+2):
    num_1=g1[-1]*i%mod
    g1.append(num_1)
    g2.append(g2[-1]*inv[i]%mod)
    
def cmb(n,r):
    return g1[n]*g2[r]*g2[n-r]%mod

#奇数の和で場合分け
#iは奇数の数

ans=0
for i in range(min(N+1,M+1)):
    if M%2!=i%2:
        continue
    m=(3*M-i)//2
    num=(cmb(m+N-1,N-1)-i*cmb(m-M+N-1,N-1))%mod
    if m>=M+1:
        num=(num-(N-i)*cmb(m-M+N-2,N-1))%mod
    ans=(ans+cmb(N,i)*num)%mod

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

from collections import defaultdict


def main():
    number = int(input())
    numcount = defaultdict(int)
    for x in input().split():
        numcount[int(x)] += 1
    queries = int(input())
    for _ in range(queries):
        before, after = [int(x) for x in input().split()]
        tmp = numcount[before]
        numcount[before] -= tmp
        numcount[after] += tmp

        print(sum(num * count for num, count in numcount.items()))


if __name__ == '__main__':
    main()


### FIXED CODE ###

from collections import defaultdict


def main():
    number = int(input())
    numcount = defaultdict(int)
    for x in input().split():
        numcount[int(x)] += 1
    queries = int(input())
    ans = sum(num * count for num, count in numcount.items())
    for _ in range(queries):
        before, after = [int(x) for x in input().split()]
        tmp = numcount[before]
        numcount[before] -= tmp
        numcount[after] += tmp
        ans += (after - before) * tmp
        print(ans)


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

input()
a = map(int, input().split())
ans = 1
from functools import reduce
from operator import mul
ans = reduce(mul, a)
if(ans > 10 ** 18):
    ans = -1
print(ans)

### FIXED CODE ###

input()
a = map(int, input().split())
a = list(a)
ans = 1
c = 10 ** 18
if 0 in a:
    print(0)
    exit(0)
for b in a:
    ans *= b
    if(ans > c ):
        print(-1)
        exit(0)
print(ans)
### BUGGY CODE ###

from collections import deque, defaultdict

N = int(input())
A = [deque(map(lambda a: int(a) - 1, input().split())) for _ in range(N)]

canBattle = defaultdict(lambda: False)
D = [0] * N

for day in range(N**2):
    for i, a in enumerate(A):
        if not a:
            continue
        j = a[0]
        canBattle[(i, j)] = True

        if canBattle[(j, i)]:
            A[i].popleft()
            A[j].popleft()
            d = max(D[i], D[j])
            D[i], D[j] = d + 1, d + 1
    if all(len(a) == 0 for a in A):
        print(max(D))
        exit()

print(-1)


### FIXED CODE ###

import sys
from heapq import heappop, heappush
from operator import itemgetter
from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7
INF = float('inf')


def sol():
    N = int(input())
    A = [deque()] + [deque(map(int, input().split())) for _ in range(N)]

    days = [0] * (N + 1)
    now = [0] * (N + 1)

    que = deque([i + 1 for i in range(N)])

    while que:
        i = que.popleft()
        if not A[i]:
            continue

        a = A[i].popleft()
        if now[a] == i:
            days[a] = days[i] = max(days[a], days[i]) + 1
            que.append(i)
            que.append(a)
            now[a] = now[i] = 0
        else:
            now[i] = a

    for i in range(1, N + 1):
        if A[i]:
            print(-1)
            return
    print(max(days))


sol()
### BUGGY CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit, maxsize


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [(1, -maxsize)] * (n//1000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())
        a -= 1
        base[a] += v

        b = a - a % 1000
        index = value = -maxsize
        for i, v in enumerate(base[b:b+1000], b+1):
            if value < v:
                value = v
                index = i
        midway[b//1000] = (index, value)

        index = value = -maxsize
        for i, v in midway:
            if value < v:
                value = v
                index = i
        print(index, value)
    exit()


if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit


def main(readline=stdin.readline):
    n, q = (int(s) for s in readline().split())

    base = [0] * n
    midway = [0] * (n//100 + 1)
    last = [0] * (n//10000 + 1)

    for _ in range(q):
        a, v = (int(s) for s in readline().split())

        a -= 1
        base[a] += v

        b = a - a % 100

        index = b
        value = base[b]
        end = b + 100 if b + 100 < n else n
        for i in range(b, end):
            if value < base[i]:
                value = base[i]
                index = i
        midway[b//100] = index

        c = a - a % 10000
        cc = c // 100

        index = c
        value = base[c]
        for i in midway[cc:cc+100]:
            if value < base[i]:
                value = base[i]
                index = i
        last[c//10000] = index

        index = last[0]
        value = base[index]
        for i in last:
            if value < base[i]:
                value = base[i]
                index = i

        print(index+1, value)
    exit()


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

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
OFS = ord('a')
_ = input()
S = list(input()[:-1])

D = [[] for _ in [0]*26]
for i, s in enumerate(S):
    D[ord(s)-OFS].append(i)

for _ in [0]*int(input()):
    Q = input()[:-1].split()
    if Q[0] == '1':
        i, c = int(Q[1])-1, Q[2]

        s = ord(S[i])-OFS
        D[s].pop(bisect_left(D[s], i))
        insort_left(D[ord(c)-OFS], i)
        S[i] = c

    else:
        l, r = int(Q[1])-1, int(Q[2])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i < len(L) and L[i] <= r:
                cnt += 1

        print(cnt)


### FIXED CODE ###

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
OFS = ord('a')
_ = input()
S = list(input()[:-1])

D = [[] for _ in [0]*26]
for i, s in enumerate(S):
    D[ord(s)-OFS].append(i)

for _ in [0]*int(input()):
    Q = input()[:-1].split()
    if Q[0] == '1':
        i, c = int(Q[1])-1, Q[2]

        if S[i] != c:
            s = ord(S[i])-OFS
            D[s].pop(bisect_left(D[s], i))
            insort_left(D[ord(c)-OFS], i)
            S[i] = c

    else:
        l, r = int(Q[1])-1, int(Q[2])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i < len(L) and L[i] <= r:
                cnt += 1

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

def main(): 
  import sys
  input = sys.stdin.readline
  n = int(input())
  num = list(map(int, input().split()))
  mod = 10**9+7

  from collections import Counter
  # 高速素因数分解(√n)
  def factorization(a):
          yy, j = [], 2
          y = yy.append
          while(a > 1):
              for i in range(j, int(a**0.5)+1):
                  if a % i == 0:
                      y(i)
                      a, j = a//i, i
                      break
              else:
                  y(a)
                  break
          return Counter(yy)

  lcd = dict()
  for i in num:
    j = dict(factorization(i))
    for x,y in j.items():
      if not x in lcd.keys():
        lcd[x] = y
      else:
        lcd[x] = max(lcd[x],y)

  lc = 1
  for i,j in lcd.items():
    lc *= pow(i,j,mod)

  def modinv(a, mod=10**9+7):
      return pow(a, mod-2, mod)

  ans =0
  for i in range(n):
    ans += lc*modinv(num[i],mod)
    ans %= mod
  print(ans)
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
num = list(map(int, input().split()))
mod = 10**9+7

import fractions
lc = num[0]
for i in range(1, n):
    lc = lc * num[i] // fractions.gcd(lc, num[i])

lc %= mod    
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

ans =0
for i in range(n):
  ans += lc*modinv(num[i],mod)
  ans %= mod
print(ans)
### BUGGY CODE ###

n, *str_n = open(0).read().split()
n = int(n)
dic = list(set(str_n))
dic.sort()
str_n.sort()

cnt = [0] *len(dic)
j = 0
for i in range(n-1):
    if str_n[i] == str_n[i+1]:
        cnt[j] += 1
    else:
        j += 1
        
max_vote = [i for i, v in enumerate(cnt) if v == max(cnt)]
        
for i in max_vote:
    print(dic[i])

### FIXED CODE ###

import collections

n, *s_n = open(0).read().split()
n = int(n)

dic = collections.Counter(s_n)

dic_values_max = max(list(dic.values()))

max_key = [i for i, j in dic.items() if j == dic_values_max]

max_key.sort()

for k in max_key:
    print(k)