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

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
hmin = INF
xyh = []
for i in range(N):
    x,y,h = inpl()
    hmin = min(h,hmin)
    xyh.append([x,y,h])

for H in range(hmin,hmin+210):
    for cx in range(101):
        for cy in range(101):
            flag= True
            for x,y,h in xyh:
                if max(H-abs(cx-x)-abs(cy-y),0) != h:
                    flag = False
                    break

            if flag:
                print(cx,cy,H)
                sys.exit()


### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
hmin = INF
xyh = []
for i in range(N):
    x,y,h = inpl()
    hmin = min(h,hmin)
    xyh.append([x,y,h])

for H in range(hmin,hmin+210):
    for cx in range(101):
        for cy in range(101):
            flag= True
            for x,y,h in xyh:
                if max(H-abs(cx-x)-abs(cy-y),0) != h:
                    flag = False
                    break

            if flag:
                print(cx,cy,H)
                sys.exit()
### BUGGY CODE ###

import collections

S = input()
Q = int(input())

d = collections.deque(S)

for _ in range(Q):
    Qi = input()
    if Qi == "1":
        d.reverse()
    else:
        T, F, C = Qi.split()
        if F == "1":
            d.appendleft(C)
        else:
            d.append(C)

print("".join(d))


### FIXED CODE ###

import collections


class Formatter:
    def __init__(self, s):
        self._d = collections.deque(s)
        self._d_reverse = collections.deque(reversed(s))

    def reverse(self):
        self._d, self._d_reverse = self._d_reverse, self._d

    def append(self, s):
        self._d.append(s)
        self._d_reverse.appendleft(s)

    def appendleft(self, s):
        self._d.appendleft(s)
        self._d_reverse.append(s)

    def __iter__(self):
        return iter(self._d)


S = input()
Q = int(input())

d = Formatter(S)

for _ in range(Q):
    Qi = input()
    if Qi == "1":
        d.reverse()
    else:
        T, F, C = Qi.split()
        if F == "1":
            d.appendleft(C)
        else:
            d.append(C)

print("".join(d))
### BUGGY CODE ###

k = int(input())



if k % 2 != 0 and k % 5 != 0:
    if k % 7 == 0:
        l = 9 * k // 7
    else:
        l = 9 * k
    for i in range(1,k + 3):
        if (10 ** i) % l == 1:
            print(i)
            break

else:
    print(-1)

### FIXED CODE ###

k = int(input())

if k == 1 or k == 7:
    print(1)

elif k % 2 != 0 and k % 5 != 0:
    if k % 7 == 0:
        l = 9 * k // 7
    else:
        l = 9 * k

    m = 10 % l
    for i in range(1,k + 3):
        if m * 10 % l == 1:
            print(i + 1)
            break
        else:
            m = m * 10 % l

else:
    print(-1)
### BUGGY CODE ###

n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

for x in range(n):
    ans = a[:x] + a[x+1:]
    print(max(ans))


### FIXED CODE ###

n = int(input())
a = list()
for x in range(n):
    a.append(int(input()))

copy_a = sorted(a, reverse=True)

A_Max = copy_a[0]
A_Second = copy_a[1]

for x in range(n):
    if a[x] == A_Max:
        print(A_Second)
    else:
        print(A_Max)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = [int(x) for x in input().split()]
g = [[] for _ in range(n)]

for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)
tmp = []
ans = [0]*n
ans2 = [0]
t = 0
while t < n:
  for s in ans2:
    for i in range(1,n):
      if s in g[i] and ans[i] == 0:
        tmp.append(i)
        ans[i] = s+1
  ans2 = tmp
  t += 1
if ans.count(0) == 1:
  print('Yes')
  for i in range(1,n):
    print(ans[i])
else:
  print('No')

### FIXED CODE ###

N,M=list(map(int,input().split()))
 
g=[[] for i in range(N+1)]
 
for i in range(M):
	a,b=list(map(int,input().split()))
	g[a].append(b)
	g[b].append(a)
 
from collections import deque
 
queue = deque([1])
d = [None] * (N+1)
while queue:
	v = queue.popleft()
	for i in g[v]:
		if d[i] is None:
			d[i] = v
			queue.append(i)
 
print("Yes")
print(*d[2:],sep='\n')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def small_dp(N,k,X):
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        return max(X[0][1]*i + X[1][1]*((N-i*X[0][0])//X[1][0]) + (N-i*X[0][0])%X[1][0] for i in range(N//X[0][0]+1))
    if k == 3:
        return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    
    for C in ((A,B), (B,A)):
        *X, = filter(lambda c: int.__sub__(*c)<0, zip(*C))
        N = small_dp(N, len(X), X)
    res = N

    return str(res)

if __name__ == '__main__':
    print(solve())


### FIXED CODE ###

# -*- coding: utf-8 -*-
from itertools import product
from heapq import heappop, heappush

def small_dp(N,A,B):
    *X, = filter(lambda c: int.__sub__(*c)<0, zip(A,B))
    k = len(X)
    if k == 0:
        return N
    if k == 1:
        return X[0][1]*(N//X[0][0]) + N%X[0][0]
    if k == 2:
        c = 0
        for i in range(N//X[0][0]+1):
            j = (N-i*X[0][0])//X[1][0]
            c = max(X[0][1]*i + X[1][1]*j + (N-i*X[0][0])%X[1][0], c)
        return c
    if k == 3:
        if (N//X[1][0]+1)*(N//X[0][0]+1) <= 10**6 :
            return max(X[0][1]*i + max(X[1][1]*j + X[2][1]*((N-i*X[0][0]-j*X[1][0])//X[2][0]) + ((N-i*X[0][0]-j*X[1][0])%X[2][0]) for j in range((N-i*X[0][0])//X[1][0]+1)) for i in range(N//X[0][0]+1))
        else:
            import numpy as np
            dp = np.zeros(N+1, dtype=int)
            for w in range(1,N+1):
                dp[w] = max(dp[w-X[i][0]]+X[i][1] if w>=X[i][0] else w for i in range(k))
            N = dp[-1]
            return N

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    res = small_dp(small_dp(N, A, B), B, A)

    return str(res)

if __name__ == '__main__':
    print(solve())
### BUGGY CODE ###

N, M = list(map(int, input().split()))
can = []
for i in range(1, M // 2 + 1):
	if M % i == 0:
		if N <= M // i:
			can.append(i)
		else:
			break

if N == 1:
	print(M)
else:
	print(max(can))



### FIXED CODE ###

import numpy as np
N, M = list(map(int, input().split()))
can = []
for i in range(1, int(np.sqrt(M)) + 1):
	if M % i == 0:
		if N <= M // i:
			can.append(i)
		if N <= i:
			can.append(M // i)

if N == 1:
	print(M)
else:
	print(max(can))
### BUGGY CODE ###

L, R = map(int, input().split())

minimam = 2019
for i in range(L, R):
    for j in range(i+1, R+1):
        if (i*j) % 2019 < minimam:
            minimam = (i*j) % 2019

print(minimam)

### FIXED CODE ###

L, R = map(int, input().split())

minimam = 2019
for i in range(L, min(R, L+2019)):
    for j in range(i+1, min(R+1, L+2019)):
        if (i*j) % 2019 < minimam:
            minimam = (i*j) % 2019

print(minimam)
### BUGGY CODE ###

k = int(input())
i = 0
s = 0

if k % 2 == 0:
    print('-1')
    exit()

while True:
    i += 1
    s = (7 + 10*s) % k
    if s == 0:
        print(i)
        exit()

### FIXED CODE ###

K = int(input())
 
num = 0
cnt = 0
ans = -1
 
for i in range(K):
    num = num*10 +7
    cnt += 1
    if num%K != 0:
        num = num%K
    else:
        ans = cnt
        break
    
print(ans)
### BUGGY CODE ###


import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])
print(ans)

### FIXED CODE ###

import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(len(l)):
    for j in range(i + 1, len(l)):
        ans += max(bisect.bisect_left(l, l[i] + l[j])-j-1, 0)
print(ans)
### BUGGY CODE ###

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price_list = []

for s in a:
  for t in b:
    price_list.append(s + t)


for i in range(M):
  x, y, c = map(int, input().split())
  price = a[x-1] + b[y-1] - c
  price_list.append(price)


min_price = price_list[0]

for n in price_list:
  if min_price >= n:
    min_price = n
  elif min_price < n:
    pass


print(min_price)

### FIXED CODE ###

A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
price_list = []

for i in range(M):
  x, y, c = map(int, input().split())
  price = a[x-1] + b[y-1] - c
  price_list.append(price)


a.sort()
b.sort()
price_list.append(a[0]+b[0])
min_price = price_list[0]

for n in price_list:
  if min_price >= n:
    min_price = n
  elif min_price < n:
    pass


print(min_price)
### BUGGY CODE ###

#073_C
n=int(input())
s=set()
for _ in range(n):
    a=int(input())
    a={a}
    s=s^a
print(len(s))

### FIXED CODE ###

N=int(input())
s=set()
for i in range(N):s^={input()}
print(len(s))
### BUGGY CODE ###

from itertools import combinations
from collections import defaultdict


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

dA = defaultdict(int)
for i in A:
    dA[i] += 1

dB = defaultdict(int)

for i in A:
    temp = 0
    for j in dA.keys():
        if i == j:
            a = list(range(dA[j] - 1))
            if not dB[len(a)]:
                temp += len(list(combinations(a, 2)))
                dB[len(a)] = len(list(combinations(a, 2)))
            else:
                temp += dB[len(a)]
        else:
            b = list(range(dA[j]))
            if not dB[len(b)]:
                temp += len(list(combinations(b, 2)))
                dB[len(b)] = len(list(combinations(b, 2)))
            else:
                temp += dB[len(b)]
    print(temp)

### FIXED CODE ###

from math import factorial
from collections import defaultdict


def cmb(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


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

dA = defaultdict(int)
for i in A:
    dA[i] += 1

sm = 0

for i in dA.values():
    if i >= 2:
        sm += cmb(i, 2)
    else:
        sm += 0

for j in A:
    print(sm - (dA[j] - 1))
### BUGGY CODE ###

N=int(input())
AS = list(map(int,input().split()))
zero=False
sum = 1
for i in range(len(AS)):
  if AS[i]==0:
    zero=True
    break
  sum = sum * AS[i]
if zero==True:
  print(0)
else:
  if sum > 10**18:
    print(-1)
  else:
    print(sum)

### FIXED CODE ###

N=int(input())
AS = list(map(int,input().split()))
if 0 in AS:
  print(0)
  exit()
s = 0
sum = 1
l=len(AS)
for i in range(l):
  A=AS[i]
  sum = sum * A
  if sum > 10**18:
    s=2
    break
if sum > 10**18:
  print(-1)
else:
  print(sum)
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
while M > 0:
    M -= 1
    A[A.index(max(A))] //= 2
print(sum(A))


### FIXED CODE ###

import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)  # aを優先度付きキューに

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))  # 計算誤差の関係で-1を2回かけてます
print(-sum(a))
### BUGGY CODE ###


import heapq
n = int(input())
stw = []
x_list = []
y_list = []
for i in range(n):
  x, y = map(int, input().split())
  x_list += [[x, i]]
  y_list += [[y, i]]
x_list.sort()
y_list.sort()
for i in range(n-1):
  xs = x_list[i][1]
  xt = x_list[i+1][1]
  ys = y_list[i][1]
  yt = y_list[i+1][1]
  dis_x = abs(x_list[i][0]-x_list[i+1][0])
  dis_y = abs(y_list[i][0]-y_list[i+1][0])
  stw += [[dis_x, xs, xt]]
  #stw += [[dis_x, xt, xs]]
  stw += [[dis_y, ys, yt]]
  #stw += [[dis_y, yt, ys]]
  
#print(stw)
heapq.heapify(stw)
#stw = sorted(stw, key=lambda x:x[2])

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.root = [-1]*(n+1)
    self.rnk = [0]*(n+1)
  def Find_Root(self, x):
    if(self.root[x] < 0):
      return x
    else:
      self.root[x] = self.Find_Root(self.root[x])
      return self.root[x]
  def Unite(self, x, y):
    x = self.Find_Root(x)
    y = self.Find_Root(y)
    if(x == y):
      return 
    if self.root[x] > self.root[y]:
      x, y = y, x
    self.root[x] += self.root[y]
    self.root[y] = x 
  def isSameGroup(self, x, y):
    return self.Find_Root(x) == self.Find_Root(y)
  def Count(self, x): # xが属するグループのサイズを返す
    return -self.root[self.Find_Root(x)]
  def Members(self, x): # xが属するグループに属する要素をリストで返す
    return [i for i in range(self.n) if self.Find_Root(i)==self.Find_Root(x)]
  def Roots(self): # 全ての根の要素をリストで返す
    return [i for i, x in enumerate(self.root) if x < 0]
  def Group_Count(self): # グループの数を返す
    return len(self.Roots())


def kruskal():
  # stw = [[s0, t0, w0], [s1, t1, w1], ..., [sn, tn, wn]]
  # stw: s: 始点, t: 終点, w: st間の重み
  # stwはwを小さい順にソートされたものとする
  res = 0
  uf = UnionFind(n)
  while stw:
    w, s, t = heapq.heappop(stw)
    if not uf.isSameGroup(s, t):
      uf.Unite(s, t)
      res += w
  return res

print(kruskal())

### FIXED CODE ###

import itertools
import heapq
from heapq import heappush, heappop
global G, inp_x, inp_y

def input_graph(N):
  global G, inp_x, inp_y
  inp_x = []
  inp_y = []
  for i in range(N):
    x, y = map(int, input().split())
    inp_x.append((x, i))
    inp_y.append((y, i))
  inp_x.sort()
  inp_y.sort()
  for i in range(N-1):
    xa = inp_x[i][1]
    xb = inp_x[i+1][1]
    ya = inp_y[i][1]
    yb = inp_y[i+1][1]
    cost_x = abs(inp_x[i][0]-inp_x[i+1][0])
    cost_y = abs(inp_y[i][0]-inp_y[i+1][0])
    G[xa] += [(cost_x, xb)]
    G[xb] += [(cost_x, xa)]
    G[ya] += [(cost_y, yb)]
    G[yb] += [(cost_y, ya)]

  
def prim(V):
  global G, used
  edgelist = []
  for e in G[0]:
    heappush(edgelist, e)
  used[0] = True
  res = 0
  while edgelist:
    minedge = heappop(edgelist)
    if used[minedge[1]]:
      continue 
    v = minedge[1]
    used[v] = True 
    for e in G[v]:
      if not used[e[1]]:
        heappush(edgelist, e)
    res += minedge[0]
  return res

def main():
  global G, used
  N = int(input())
  G = [[] for _ in range(N)]
  used = [False for _ in range(N)]
  input_graph(N)
  print(prim(N))

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

n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*64
for i in range(n):
    for j in range(a[i].bit_length()):
        if a[i]>>j & 1: b[j]+=1
c=0
for i in range(64):
    c+=(b[i]*(n-b[i])*2**i) % 1000000007
print(c%1000000007)
### BUGGY CODE ###

import math 
a,b,n=map(int,input().split())
def calc(x):
    global a,b
    return math.floor(a*x/b)-a*math.floor(x/b)
kind=set()
bef=-100
for i in range(1,n+1):
    num=calc(i)
    if bef!=num:
        if num in kind:
            break
    kind.add(num)
    bef=num
print(max(kind))

### FIXED CODE ###

import math
a,b,n=map(int,input().split())
def calc(x):
    global a,b
    return math.floor(a*x/b)-a*math.floor(x/b)
print(calc(min(n,b-1)))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100001)
def input():
    return sys.stdin.readline()[:-1]

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
for i in range(1, N+1):
    t = 0
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t
K = N
ans = ""
while dp[K] > 0:
    for a in A:
        xa = x[a]
        if K >= xa and dp[K] == dp[K-xa] + 1:
            if dp[K] == 1 and K != xa:
                continue
            ans += str(a)
            K -= xa
            break
print(ans)

### FIXED CODE ###

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)
x = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0 for i in range(N+1)]
INF = float('inf')
for i in range(1, N+1):
    t = -INF
    for a in A:
        if i >= x[a]:
            t = max(dp[i-x[a]] + 1, t)
    dp[i] = t

K = N
k = dp[N]
ans = ""
while k > 0:
    for a in A:
        xa = x[a]
        if K >= xa and k == dp[K-xa] + 1:
            ans += str(a)
            K -= xa
            k -= 1
            break
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10000)

def findset(x,element,weight,resultPos=0,sumW=0):
    if(x != element[x]):
        resultPos,sumW = findset(element[x],element,weight,resultPos,sumW)
        sumW += weight[x]
    else:
        resultPos = x
    return resultPos,sumW

def union(x,y,element,weight,w):
    x,wx = findset(x,element,weight)
    y,wy = findset(y,element,weight)
    link(x,wx,y,wy,w,element)
def link(x,wx,y,wy,z,element):
    z = z+wy-wx

    element[x] = y
    weight[x] = z

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

element = [i for i in range(n)]
weight = [0 for i in range(n)]

for i in range(q):
    inp = map(int, input().split());
    inp = list(inp)    
    if(inp[0] == 0):
        x,y,w = inp[1],inp[2],inp[3]
        union(x,y,element,weight,w)
    else:
        x,y = inp[1],inp[2]
        x,wx = findset(x,element,weight)
        y,wy = findset(y,element,weight)
        if(x == y):
            print(wx-wy)
        else:
            print('?')



### FIXED CODE ###

import sys
sys.setrecursionlimit(50000)

def findset(x,element,weight):
    if(x != element[x]):
        element[x],s = findset(element[x],element,weight)
        weight[x] += s
    return element[x],weight[x]

def union(x,y,element,weight,w):
    x,wx = findset(x,element,weight)
    y,wy = findset(y,element,weight)
    link(x,y,w+wy-wx,element,weight)

def link(x,y,z,element,weight):

    element[x] = y
    weight[x] = z

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

element = [i for i in range(n)]
weight = [0 for i in range(n)]

for i in range(q):
    inp = map(int, input().split());
    inp = list(inp)    
    if(inp[0] == 0):
        x,y,w = inp[1],inp[2],inp[3]
        union(x,y,element,weight,w)
    else:
        x,y = inp[1],inp[2]
        x,wx = findset(x,element,weight)
        y,wy = findset(y,element,weight)
        if(x == y):
            print(wx-wy)
        else:
            print('?')
### BUGGY CODE ###

n = int(input())
lst = []
for i in range(n):
    x,y = map(int,input().split())
    lst.append([x,y])
lst.sort()
pmn = lst[0][0]
pmx = lst[-1][0]

lst.sort(key=lambda x:x[1])
qmn = lst[0][1]
qmx = lst[-1][1]

res = 0
for p in range(pmx+1 - pmn):
    for q in range(qmx+1 - qmn):
        cnt = 0
        for i in range(n):
            tmp_x, tmp_y = lst[i][0], lst[i][1]
            if ([p,q]!=[0,0]) and ([tmp_x+p, tmp_y+q] in lst):
                cnt += 1
        res = max(res, cnt)
print(n - res)

### FIXED CODE ###

import itertools
from collections import Counter
n = int(input())
xy = [[int(x) for x in input().split()] for _ in range(n)]
vectors = []
for xy1, xy2 in itertools.combinations(xy,2):
    p = xy2[0] - xy1[0]
    q = xy2[1] - xy1[1]
    vectors.append((p, q))
    vectors.append((-p, -q))
c = Counter(vectors)
if n>=2:
    x = max(c.values())
    res = n - x
else:
    res = 1
print(res)
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[0]
for i in range(1,n):
  b=a[i]
  l.append(min(l[j]+abs(b-a[j])for j in range(i-min(k,i),i)))
print(l[-1])

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
l=[0]
for i in range(1,n):
  b=a[i]
  l.append(min(l[j]+abs(b-a[j])for j in range(i-min(k,i),i)))
print(l[-1])
### BUGGY CODE ###

from heapq import heappop,heappush
from math import ceil
n,k=map(int,input().split())
a=list(map(int,input().split()))
hq=[]
for x in a:
	heappush(hq,[-x,1])
for i in range(k):
	r=heappop(hq)
	heappush(hq,[r[0]*r[1]/(r[1]+1),r[1]+1])
ans=-heappop(hq)[0]
print(ceil(ans))

### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
l=0
r=max(a)+1
while r-l>1:
	cnt=0
	mid=(l+r+1)//2
	if mid==0:
		print(1)
		exit()
	for x in a:
		if x>1:
			cnt+=(x-1)//mid
	if cnt<=k:
		r=mid
	else:
		l=mid
print(r)
### BUGGY CODE ###

n=int(input())
a=[int(j) for j in input().split()]
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

#最小公倍数
def lcm(x,y):
    return x*y//gcd(x,y)

mod=10**9+7
t=a[0]
for i in a:
    t=lcm(t,i)

ans=0
for i in a:
    ans+=t//i
    ans%=mod
print(ans)


### FIXED CODE ###

n=int(input())
a=[int(j) for j in input().split()]
t=1
mod=10**9+7
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
for i in a:
    t*=i//gcd(t,i)
print(sum(t//i for i in a)%mod)
### BUGGY CODE ###

n,k=map(int,input().split())
ans=0
a=[]
if k==1:
  print(0)
elif abs(n-k) > n:
  print(n)
else:
  while len(a)==len(set(a)):
    n=abs(n-k)
    a.append(n)
    if n == 1:
      break
  print(min(a))

### FIXED CODE ###

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

a=n%k
ans=min(a,k-a)
print(ans)
### BUGGY CODE ###

N = int(input())

total = 0
A = []
for i in range(N):
    a = int(input())
    total += a
    A.append(a)

mod = 998244353

dp = [[0]*91000 for i in range(N+1)]
dp[0][0] = 1
for i in range(1, N+1):
    for j in range(300*i, -1, -1):
        dp[i][j+A[i-1]] += dp[i-1][j]
        dp[i][j+A[i-1]] %= mod
        dp[i][j] += 2*dp[i-1][j]
        dp[i][j] %= mod

exc = 0
for j in range((total+1)//2, total+1):
    exc += dp[N][j]
    exc %= mod

res = (3**N % mod) - exc * 3

if total % 2 == 0:
    dp = [[0]*91000 for i in range(N+1)]
    dp[0][0] = 1
    for i in range(1, N+1):
        for j in range(300*i, -1, -1):
            dp[i][j+A[i-1]] += dp[i-1][j]
            dp[i][j+A[i-1]] %= mod
            dp[i][j] += dp[i-1][j]
            dp[i][j] %= mod
    res += dp[N][total//2] * 3

print(res % mod)

### FIXED CODE ###

import numpy as np

mod = 998244353
N = int(input())
a = np.array([int(input()) for i in range(N)])
sum_a = np.sum(a)
dp = np.zeros((N+1, sum_a+1))
dp[0,0] = 1

for i in range(1, N+1):
    a_i = a[i-1]
    dp[i,a_i:] += dp[i-1,:-a_i]
    dp[i,:] += dp[i-1,:] * 2
    dp[i,:] %= mod

exc = np.sum(dp[N, (sum_a+1)//2:]) % mod
res = 3**N % mod - exc * 3

if sum_a % 2 == 0:
    dp = np.zeros((N+1, sum_a+1))
    dp[0,0] = 1
    for i in range(1, N+1):
        a_i = a[i-1]
        dp[i,a_i:] += dp[i-1,:-a_i]
        dp[i,:] += dp[i-1,:]
        dp[i,:] %= mod
    res += dp[N, sum_a//2] * 3

print(int(res % mod))
### BUGGY CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

a = sorted(A)

for b, c in BC:
	for i in range(b):
		if a[i] < c:
			a[i] = c
		else:
			break
	a = sorted(a)

print(sum(a))


### FIXED CODE ###

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

am = {}
for a in A:
	if not a in am:
		am[a] = 1
	else:
		am[a] += 1

for b, c in BC:
	if not c in am:
		am[c] = b
	else:
		am[c] += b

al = sorted(am)[::-1]

c, v = N, 0
for k in al:
	if am[k] < c:
		c -= am[k]
		v += am[k] * k
	else:
		v += c * k
		break

print(v)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
S[0] = 0
diff = float("INF")
idx = -1
for i in range(N):
  S[i+1] = S[i] + A[i]
  if abs(sum(A)/2 - S[i+1]) < diff:
    diff = abs(sum(A)/2 - S[i+1])
    idx = i+1
lsum = S[idx]
rsum = S[-1]-S[idx]
print(abs(lsum-rsum))

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
c = sum(A)/2

S = [0] * (N+1)
S[0] = 0
for i in range(N):
  S[i+1] = A[i] + S[i]

m = float("INF")
j = -1
for i in range(1, N+1):
  if abs(c - S[i]) < m:
    m = abs(c - S[i])
    j = i

print(abs((S[N] - S[j]) - S[j]))