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

first_step_string = input()
query_num = int(input())
query_li = list()
for _ in range(query_num):
    query_li.append(input().split())

ans = first_step_string
for query in query_li:
    if query[0] == '1':
        ans = ans[::-1]
    elif query[1] == '1':
        ans = query[2] + ans
    else:
        ans += query[2]

print(ans)


### FIXED CODE ###

from collections import deque

s = deque(input())
query_num = int(input())
query_li = list()
for _ in range(query_num):
    query_li.append(input().split())

rev_flag = False
for query in query_li:
    if query[0] == '1':
        rev_flag = not rev_flag
    elif (query[1] == '1' and rev_flag) or (query[1] == '2' and not rev_flag):
        s.append(query[2])
    else:
        s.appendleft(query[2])

if rev_flag:
    print(''.join(deque(reversed(s))))
else:
    print(''.join(s))
### BUGGY CODE ###

n = int(input())
factor = []
tmp = n
for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
    while tmp % i == 0:
        factor.append(i)
        tmp //= i
if tmp != 1:
    factor.append(tmp)
if len(factor) == 0:
    factor.append(n)
if len(factor) == 1:
    print(factor[0] - 1)
else:
    ans = float("inf")
    for i in range(1, 2 ** len(factor)):
        a, b = 1, 1
        for j in range(len(factor)):
            if i & (2 ** j) == 0:
                a *= factor[j]
            else:
                b *= factor[j]
        if a + b - 2 < ans:
            ans = a + b - 2
    print(ans)


### FIXED CODE ###

n = int(input())
ans = 1000000000000
for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        a = i
        b = n // i
        ans = min(ans, a + b - 2)
print(ans)
### BUGGY CODE ###

num = [int(i) for i in input().split()]
ans = 0
for i in range(num[0], num[1]+1):
  if i%num[2] != 0 and i%num[3] != 0:
    ans += 1
print(ans)

### FIXED CODE ###

import fractions
num = [int(i) for i in input().split()]
lower_limit = num[0]
upper_limit = num[1]
c = num[2]
d = num[3]

def count_multi(x):
  count = upper_limit//x- (lower_limit-1)//x                          
  return count

cd_gcd = fractions.gcd(c, d)

multi_c_d = count_multi(c) + count_multi(d) - count_multi(c*d//cd_gcd)
print(upper_limit - lower_limit + 1 - multi_c_d)
### BUGGY CODE ###

def main():

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

    ans = 0

    for i in range(n - 1):
        for j in range(i + 1, n):
            ans += (a[i] * a[j]) % (10**9 + 7)

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

main()

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
v = sum(a)

for i in range(n - 1):
    v -= a[i]
    ans += a[i]*v

print(ans % mod)
### BUGGY CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

dp=[0]*(w+1)

for i in range(n):
 for j in range(w,-1,-1):
  if j+l[i][0]<=w:
   dp[j+l[i][0]] =max(dp[j+l[i][0]],dp[j]+l[i][1])

print(max(dp))

### FIXED CODE ###

n,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

dp=[0]*(w+1)

for i in range(n):
 for j in range(w,-1,-1):
  if j+l[i][0]<=w:
   dp[j+l[i][0]] =max(dp[j+l[i][0]],dp[j]+l[i][1])

print(max(dp))
### BUGGY CODE ###

n, k, q = list(map(int, input().split()))
a = [int(input()) for i in range(q)]
p = []
for i in range(n):
    p.append(k)
for i in range(q):
    for j in range(n):
        if(j + 1 == a[i]):
            pass
        else:
            p[j] = p[j] - 1
#print(p)
for i in range(n):
    if(p[i] > 0):
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

n, k, q = list(map(int, input().split()))
a = [int(input()) for i in range(q)]
p = [k - q] * n
for i in range(q):
    p[a[i] - 1] += 1
for i in range(n):
    if(p[i] > 0):
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

import copy
 
n = int(input())
x = list(map(int,input().split()))
 
 
for i in range(n):
  xx = copy.deepcopy(x)
  xx.pop(i)
  xx.sort()
  print(xx[(len(xx) + 1) // 2 - 1])

### FIXED CODE ###

import copy

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

xx= sorted(x)
L_x = xx[n//2 - 1]
R_x = xx[n//2]

for arr in x:
  print(L_x if R_x <= arr else R_x)
### BUGGY CODE ###

import numpy as np
N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if P[i]  <=  np.min(P[:i+1]):
        cnt += 1
print(cnt)    

### FIXED CODE ###

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

smallest_so_far = float("inf")
cnt = 0

for the_num in P:
    if the_num < smallest_so_far :
        smallest_so_far = the_num
        cnt += 1
print(cnt)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    k,q=MI()
    dd=LI()
    for _ in range(q):
        n,x,m=MI()
        cc=[d%m for d in dd]
        zall=cc.count(0)
        zlast=cc[:(n-1)%k].count(0)
        s=sum(cc)*((n-1)//k)
        r=sum(cc[:(n-1)%k])
        last=x%m+s+r
        no=last//m
        print(n-1-no-zall*((n-1)//k)-zlast)

main()

### FIXED CODE ###

import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    k,q=MI()
    dd=LI()
    for _ in range(q):
        n,x,m=MI()
        sall=spart=0
        zall=zpart=0
        for i,d in enumerate(dd):
            d%=m
            if i<(n-1)%k:
                spart+=d
                if d==0:zpart+=1
            sall+=d
            if d==0:zall+=1
        last=x%m+sall*((n-1)//k)+spart
        no=last//m
        print(n-1-no-zall*((n-1)//k)-zpart)

main()
### BUGGY CODE ###

A, B, N = map(int,input().split())
score = 0
for i in range(N):
    x = i+1
    val = int(A*x/B) - A * int(x/B)
    #print( int(A*x/B) , A * int(x/B))
    if(val >= score):
        score = val
    else:
        break
print(score)


### FIXED CODE ###

A, B, N = map(int,input().split())
x = min(N,B-1)
val = int(A*x/B) - A * int(x/B)
print(val)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(5 * 10**5)
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))


### FIXED CODE ###

import sys
sys.setrecursionlimit(5 * 10**5)
input=sys.stdin.readline
 
N, Q = list(map(int, input().split()))
 
M = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = list(map(int, input().split()))
    M[a-1].append(b-1)
    M[b-1].append(a-1)
 
ans = [0] * N
for _ in range(Q):
    p, x = list(map(int, input().split()))
    ans[p-1] += x
 
def setAnswer(parent, number):
    ans[number] += ans[parent]
 
    for i in M[number]:
        if i != parent:
            setAnswer(number, i)

ans.append(0)
setAnswer(N, 0)
ans.pop(N)
 
print(' '.join(map(str, ans)))
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)

absa=[abs(i) for i in a]
minans=sum(absa)

for x in range(1,n):
  valx=0
  for i in range(x):
    valx+=a[i]
  
  valy=0
  for j in range(x,n):
    valy+=a[j]

  ans=abs(valx-valy)

  if ans < minans:
    minans=ans
    
print(minans)

### FIXED CODE ###

n=int(input())
a=[int(i) for i in input().split()]
#print(n,a)
suma=sum(a)
minans=abs(2*a[0]-suma)
#print(minans)

mydata=0
for i in range(0,n-1):
  mydata+=a[i]
  ans=abs(2*mydata-suma)
  if ans < minans:
    minans = ans
    
print(minans)
### BUGGY CODE ###

from collections import defaultdict as dd
from copy import deepcopy as dc
import time
st = time.time()
N = int(input())
e = dd(list)

matche = dd(list)

for i in range(1, N + 1):
  e[i] = list(map(int, input().split()))

for i in range(1, N + 1):
  for j in range(N - 2):
    if matche[(min(e[i][j], i), max(e[i][j], i))] != []:
      matche[(min(e[i][j], i), max(e[i][j], i))].append((min(i, e[i][j + 1]), max(i, e[i][j + 1])))
    else:
      matche[(min(e[i][j], i), max(e[i][j], i))].append((min(i, e[i][j + 1]), max(i, e[i][j + 1])))
    #print(i, j, matche)
#print(matche)
matchkey = dc(matche)
S = matchkey.keys()
visited = dd(int)
depth = 0
#print(S)
def dfs(s):
  if time.time() - st > 1.7:
    print(N * (N - 1) // 2)
  global visited
  global depth
  temp = 0
  #print(s)
  if matche[s] != []:
    for c in matche[s]:
      if visited[c] == 1:
        print(-1)
        #print(visited, c)
        exit(0)
      else:
        depth += 1
        visited[c] = 1
        #print(depth)
        temp = max(dfs(c), temp)
        depth -= 1
        visited[c] = 0
  else:
    return depth
  return temp
temp = 0
for s in S:
  temp = max(dfs(s), temp)
print(temp + 1)

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
#試合にコードを割り当てる
#of[l] = 前の番号の競技者の「既に数え上げた試合の数」
#r = 相手
#l = じぶん
def code(l, r, of):
  if l > r:
      l, r = r, l
  return of[l] + r - l - 1
#オフセットを作る。重複の試合を取り除くため、
#1ならN - 1試合、2ならN - 2試合...という風にする
of = [0] * (N + 1)
for i in range(N):
  of[i + 1] = of[i] + N - i - 1
#print(of)
#試合の前後関係を持つグラフ
#たぶんDAGになっている。なってないなら試合組めないと思う
g = [[] for _ in range(N * (N - 1) // 2)]
for i in range(N):
  for j in range(N - 2):
      fcode = code(i, A[i][j] - 1, of)
      tcode = code(i, A[i][j + 1] - 1, of)
      g[fcode].append(tcode)
#print(g)
def sort_topologically(g):
  n = len(g)
  #ecはコードによる試合頂点の入次数を記録
  ec = [0] * n
  for i in range(n):
    for e in g[i]:
      ec[e] += 1
  #print(ec)
  #retは入次数0の頂点を順にとってきている
  ret = [0] * n
  q = 0
  for i in range(n):
    if ec[i] == 0:
      ret[q] = i
      q += 1
  #p = 参照中の入次数0の試合
  #q = 入次数0の頂点数
  #while文はp == qの時点で終わる
  #for文では、入次数0の頂点pから出る有向辺を除去する
  #その上で入次数0の頂点が増えればretへ追加
  #このretは確かにトポロジカル順序になる
  p = 0
  #print(ret)
  while p < q:
    for to in g[ret[p]]:
      ec[to] -= 1
      if ec[to] == 0:
        ret[q] = to
        q += 1
    p += 1
  #ソートが終わったなら全ての辺は除去済みのはずである
  #このグラフは一応連結しているはずなので閉路検知ができる
  for i in range(n):
    if ec[i] > 0:
      return None
  return ret

od = sort_topologically(g)
#print(od)
#Noneなら閉路を持つので試合構築不可能
if not od:
  print(-1)
else:
  #dp = トポロジカル順序を持つ順序集合の先頭からi番目までを見た際の最大パス長
  dp = [1] * (N * (N - 1) // 2)
  for i in range(N * (N - 1) // 2):
    for e in g[od[i]]:
      dp[e] = max(dp[e], dp[od[i]] + 1)
  #print(dp)
  print(max(dp))
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
import itertools 
combi = itertools.combinations(L, 3)
wa = 0
for c in combi:
    if(c[0] < c[1] + c[2] and c[0] > abs(c[1] - c[2])):
        wa +=1
print(wa)

### FIXED CODE ###

N = int(input())
L = list(map(int, input().split()))
L.sort()
wa = 0
import bisect
for i in range(N-1,1,-1):
    for j in range(i-1,0,-1):
        diff = L[i]-L[j]
        k = bisect.bisect_right(L, diff)
        wa += j-k if j-k > 0 else 0           
            
print(wa)
### BUGGY CODE ###

def get_answer(ki):
    n = ki[0][0]
    q = ki[0][1]
    #n_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[1:-q]]]
    #q_data = [[int(k[0]), int(k[1])] for k in [k.split(" ") for k in ki[-q:]]]
    n_data = ki[1:-q]
    q_data = ki[-q:]
    score = [0] * n

    """
        assert get_answer(["4 3",
                       "1 3", "1 4", "2 3",
                       "2 10", "1 100", "3 1"]) == "100 111 101 100"
    """
    t_index = {}
    for i in range(1, n + 1):
        t_index[i] = []
    for nn in n_data:
        t_index[nn[0]].append(nn[1])
        t_index[nn[1]].append(nn[0])

    q_index = {}
    for qq in q_data:
        i = qq[0]
        if i in q_index.keys():
            q_index[i] += qq[1]
        else:
            q_index[i] = qq[1]

    t_stack = [1]
    s_stack = [0]
    r_flag = [0] * n
    while len(t_stack) > 0:
        i = t_stack.pop()
        s = s_stack.pop()
        if r_flag[i - 1]:
            continue
        r_flag[i - 1] = 1
        if i in q_index.keys():
            s += q_index[i]
        score[i - 1] += s
        t_stack += t_index[i]
        for si in range(len(t_index[i])):
            s_stack.append(s)

    s_value = str(score[0])
    for i in range(1, n):
        s_value += " " + str(score[i])
    return s_value


if __name__ == "__main__":
    input_ki = []
    while True:
        try:
            input1 = input()
            if not input1:
                break;
            if len(input1) == 0:
                break;
            s = input1.split(" ")
            input_ki.append([int(s[0]), int(s[1])])
        except EOFError:
            break
    print(get_answer(input_ki))


### FIXED CODE ###

import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる
### BUGGY CODE ###

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

cnt=0
for i in range(n):
    for j in range(i+1,n):
        if A[i]==A[j]:
            cnt+=1
            break

if cnt==1:
    print("NO")
else:
    print("YES")

### FIXED CODE ###

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

A = list(set(A))

if len(A) == n:
    print('YES')
else :
    print('NO')
### BUGGY CODE ###

n,k,q=map(int,input().split())
point=[k for i in range(n)]
for i in range(q):
    for i in range(n):
        point[i]-=1
    point[int(input())-1]+=1        
for i in point:
    if(i>0):
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[0 for i in range(n)]
for i in range(q):
    a[int(input())-1]+=1
for i in a:
    if k-q+i>0:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

# pypy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import defaultdict

R, C, K = map(int, readline().split())
rcv = list(map(int, read().split()))
rc2v = defaultdict(int)
for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]):
    rc2v[(rr-1, cc-1)] = vv

dp = [[[0]*4 for c in range(C)] for r in range(2)]
dp[0][0][1] = rc2v[(0, 0)]

for c in range(1, C):
  for k in range(1, 4):
    dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+rc2v[(0, c)])

for r in range(1, R):
  rr = r % 2
  dp[rr][0][0] = max(dp[rr-1][0])
  dp[rr][0][1] = dp[rr][0][0] + rc2v[(r, 0)]
  for c in range(1, C):
    temp_max = max(dp[rr-1][c])
    dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+rc2v[(r, c)])
    for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+rc2v[(r, c)])
    
if R % 2:
  print(max(dp[0][-1]))
else:
  print(max(dp[-1][-1]))

### FIXED CODE ###

# pypy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

R, C, K = map(int, readline().split())
rcv = list(map(int, read().split()))
rc2v = {}
for rr, cc, vv in zip(rcv[::3], rcv[1::3], rcv[2::3]):
    rc2v[(rr-1, cc-1)] = vv

dp = [[[0]*4 for c in range(C)] for r in range(2)]
dp[0][0][1] = rc2v[(0, 0)] if (0, 0) in rc2v else 0

for c in range(1, C):
  for k in range(1, 4):
    v = rc2v[(0, c)] if (0, c) in rc2v else 0
    dp[0][c][k] = max(dp[0][c-1][k], dp[0][c-1][k-1]+v)

for r in range(1, R):
  rr = r % 2
  dp[rr][0][0] = max(dp[rr-1][0])
  v = rc2v[(r, 0)] if (r, 0) in rc2v else 0
  dp[rr][0][1] = dp[rr][0][0] + v
  for c in range(1, C):
    v = rc2v[(r, c)] if (r, c) in rc2v else 0
    temp_max = max(dp[rr-1][c])
    dp[rr][c][1] = max(dp[rr][c-1][1], max(dp[rr][c-1][0], temp_max)+v)
    for k in range(2, 4):
      dp[rr][c][k] = max(dp[rr][c-1][k], dp[rr][c-1][k-1]+v)
    
if R % 2:
  print(max(dp[0][-1]))
else:
  print(max(dp[-1][-1]))
### BUGGY CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

S = input()
n = len(S)

ans = 0
for i in range(n-3):
    for j in range(i+4, n+1):
        if int(S[i:j]) % 2019 == 0:
            # print(S[i:j])
            ans += 1

print(ans)

### FIXED CODE ###

S = input()

res = [0] * 2019
res[0] = 1

d = 1
a = 0

for c in reversed(S):
    a += int(c) * d
    a %= 2019
    res[a] += 1
    d *= 10
    d %= 2019

ans = 0
for r in res:
    ans += r*(r-1) // 2
print(ans)
### BUGGY CODE ###

s = list(input())
n = len(s)

ans = 0
count = 0
for i in range(n):
    if s[i] == "W":
        ans += s[: i].count("B")

print(ans)


### FIXED CODE ###

s = input()
n = len(s)

ans = 0
count = 0
for i in range(n):
    if s[i] == "W":
        ans += i - count
        count += 1

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

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

ans=0
t=min(b,n)
for i in range(t,min(t-3,-1),-1):
    ans=max(ans,((a*i)//b-(a*(i//b))))
print(ans)


### FIXED CODE ###

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

ans=0
t=min(b,n)
for i in range(t,max(t-3,-1),-1):
    ans=max(ans,((a*i)//b-(a*(i//b))))
print(ans)
### BUGGY CODE ###


def main():
  import sys
  input = sys.stdin.readline

  N = int(input())
  A = list(map(int, input().split()))
  mod = 10 ** 9 + 7

  from fractions import gcd
  from functools import reduce

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

  L = reduce(lcm, A)

  ans = 0

  for i in range(N):
    ans += (L // A[i]) % mod

  print(ans % mod)

if __name__ == '__main__':
    main()

### FIXED CODE ###


N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

from fractions import gcd

L = A[0]
for i in range(1,N):
  L=(L*A[i])//gcd(L,A[i])

ans = 0

for i in range(N):
  ans += (L // A[i])

print(ans % mod)
### BUGGY CODE ###

BUFSIZE = 50
D = int(input())
C = list(map(int, input().split()))

c0 = sum(C)
Q = [(0, [], 0, [0]*26)]

for d in range(D):
    S = list(map(int, input().split()))
    Q2 = []
    
    for q in Q:
        sc, ts, c1, lasts = q
        c2 = c1 + c0

        for t in range(26):
            c3 = c2 - (d + 1 - lasts[t])*C[t]
            lasts2 = lasts[:]
            lasts2[t] = d+1
            Q2.append((sc + S[t] - c3, [ts, t], c3, lasts2))

    sizeOfQ2 = len(Q2)
    Q = sorted(Q2, reverse=True)[:min(sizeOfQ2, BUFSIZE)]

# print(Q[0][0])
T = []
ts = Q[0][1]

for d in range(D):
    T.append(ts[1] + 1)
    ts = ts[0]

for t in reversed(T):
    print(t)



### FIXED CODE ###

BUFSIZE = 30
D = int(input())
C = list(map(int, input().split()))

c0 = sum(C)
Q = [(0, [], 0, [0]*26)]

for d in range(D):
    S = list(map(int, input().split()))
    Q2 = []
    
    for q in Q:
        sc, ts, c1, lasts = q
        c2 = c1 + c0

        for t in range(26):
            c3 = c2 - (d + 1 - lasts[t])*C[t]
            lasts2 = lasts[:]
            lasts2[t] = d+1
            Q2.append((sc + S[t] - c3, [ts, t], c3, lasts2))

    sizeOfQ2 = len(Q2)
    Q = sorted(Q2, reverse=True)[:min(sizeOfQ2, BUFSIZE)]

# print(Q[0][0])
T = []
ts = Q[0][1]

for d in range(D):
    T.append(ts[1] + 1)
    ts = ts[0]

for t in reversed(T):
    print(t)
### BUGGY CODE ###

from math import sqrt, ceil

N = 10100000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))

quadruplet = [True, False, True, False, False, False, True, False,True]
ans = [0]*N
for i in range(8,N):
    if temp[i] and temp[i-8:i+1] == quadruplet: ans[i] = i
while True:
    n = int(input())
    if not n: break
    print(max(ans[:n+1]))


### FIXED CODE ###

from math import sqrt, ceil

N = 10100000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))

quadruplet = [True, False, True, False, False, False, True, False,True]
ans = [0]*N
for i in range(8,N):
    if temp[i] and temp[i-8:i+1] == quadruplet: ans[i] = i
    else: ans[i] = ans[i-1]
while True:
    n = int(input())
    if not n: break
    print(ans[n])
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split())) 
B = [0 for _ in range(N)]
for i in range(N):
  B[i] =A.index(i+1) + 1
L=[str(a) for a in B]
L=" ".join(L)
print(L)

### FIXED CODE ###

import numpy as np
N = int(input())
A = list(map(int, input().split())) 
B = np.argsort(A) + 1
L=[str(a) for a in B]
L=" ".join(L)
print(L)
### BUGGY CODE ###

a = list(map(lambda x: ord(x)-ord("a"), list(input())))
n = len(a)
m = 26

b = [None]*(n+m)
prev = [0]*m
for i in range(m):
    b[n+i] = (1, (i,))
    prev[i] = n+i

for i in reversed(range(n)):
    ai = a[i]
    tmp = min(b[j] for j in prev)
    b[i] = (tmp[0]+1, (ai,)+tmp[1])
    prev[ai] = i
tmp = min(b[j] for j in prev)
ans = "".join(chr(ord("a")+i) for i in tmp[1])
print(ans)

### FIXED CODE ###

a = list(map(lambda x: ord(x)-ord("a"), list(input())))
n = len(a)
m = 26

b = [1]*(n+1)
prev = [n]*m
G = [[] for i in range(n+1)]
for i in reversed(range(n)):
    ai = a[i]
    tmp = min(b[j] for j in prev)
    for j in prev:
        G[i].append(j)
    b[i] = tmp+1
    prev[ai] = i

cnt = min(b[j] for j in prev)
edge = prev
ans = []
for _ in range(cnt):
    for i, to in enumerate(edge):
        if b[to] == cnt-_:
            ans.append(chr(ord("a")+i))
            edge = G[to]
            break
print("".join(ans))
### BUGGY CODE ###

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

lst = [0] * N
skips = [int(input()) for _ in range(M)]
for x in range(N):
    if x in skips:
        lst[x] = 0
    elif x in [0, 1]:
        lst[x] = 1
    else:
        lst[x] = (lst[x - 1] + lst[x - 2]) % 1000000007

if N == 1:
    print(lst[-1])
else:
    print((lst[-1] + lst[-2]) % 1000000007)

### FIXED CODE ###

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

lst = [0] * N
pre1 = 0
pre2 = 0
skips = set([int(input()) for _ in range(M)])
for x in range(N):
    if x in skips:
        lst[x] = 0
    elif x in [0, 1]:
        lst[x] = 1
    else:
        lst[x] = (lst[x - 1] + lst[x - 2]) % 1000000007

if N == 1:
    print(lst[-1])
else:
    print((lst[-1] + lst[-2]) % 1000000007)
### BUGGY CODE ###

import fractions 
import math
from functools import reduce
#最大公約数
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

#インプット
n = int(input())
a = list(map(int,input().split()))

#最大公約数算出
z=lcm_list(a)

print(sum([z//x for x in a])%((10**9)+7))


### FIXED CODE ###

import fractions
 
import math
from functools import reduce
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
  
n = int(input())
a = list(map(int,input().split()))

c=0

z=lcm_list(a)

for i in range(0,n):
  c+=(z//a[i])
#print(z)
print(c%((10**9)+7))