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

import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]


NN = 10 ** 6 + 100
primes = []
isprime = [True for _ in range(NN + 1)]
min_factor = [-1 for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    min_factor[i] = i
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False
        if min_factor[j] == -1:
            min_factor[j] = i
def prime_factrize(n):
    res = []
    while n != 1:
        prime = min_factor[n]
        exp = 0
        while min_factor[n] == prime:
            exp += 1
            n //= prime
        res.append([prime, exp])
    return res


n = INT()
a = LIST()
ll = []
for i in range(n):
    aa = prime_factrize(a[i])
    for j in range(len(aa)):
        if len(ll) == 0:
            ll.append(aa[j])
        else:
            left = 0
            rght = len(ll) - 1
            while left < rght:
                cntr = (rght + left) // 2
                if ll[cntr][0] == aa[j][0]:
                    left = cntr
                    rght = cntr
                elif ll[cntr][0] > aa[j][0]:
                    rght = cntr - 1
                elif ll[cntr][0] < aa[j][0]:
                    left = cntr + 1
            if ll[left][0] == aa[j][0]:
                ll[left][1] = max(ll[left][1], aa[j][1])
            else:
                ll.append(aa[j])
            ll.sort(key=lambda x: x[0])
l = 1
for i in range(len(ll)):
    l *= pow(ll[i][0], ll[i][1], mod)
ans = 0
for i in range(n):
    ans += l // a[i]
    ans %= mod
print(ans)


### FIXED CODE ###

import sys
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return list(map(int, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n = INT()
a = LIST()
l = 1
for i in a:
    l = lcm(l, i)
l %= mod
ans = 0
for i in a:
    ans += l * pow(i, mod - 2, mod)
print(ans % mod)
### BUGGY CODE ###

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

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

### FIXED CODE ###

k, s = map(int, input().split())
 
ans = 0
for x in range(k+1):
    for y in range(k+1):
        ans += max(0, 0<=s-x-y<=k)
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
lst=[[] for i in range(n)]
visited=[False for i in range(n)]
ans=[0]*n

for i in range(m):
      a,b=map(int,input().split())
      lst[a-1].append(b-1)
      lst[b-1].append(a-1)

Q=[0]
visited[0]=True

while Q:
  v=Q.pop(0)
  for i in lst[v]:
        if visited[i]==False:
              visited[i]=True
              ans[i]=v
              Q.append(i)

print('Yes')

for i in range(1,n):
      print(ans[i]+1)

### FIXED CODE ###

n,m=map(int,input().split())
lst=[[] for i in range(n)]
visited=[False for i in range(n)]
ans=[0]*n

for i in range(m):
      a,b=map(int,input().split())
      lst[a-1].append(b-1)
      lst[b-1].append(a-1)

Q=[0]
visited[0]=True

while Q:
  v=Q.pop(0)
  for i in lst[v]:
        if visited[i]==False:
              visited[i]=True
              ans[i]=v
              Q.append(i)

print('Yes')

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

N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  a = h[i:i+K]
  ans.append(max(a)-min(a))

print(min(ans))

### FIXED CODE ###

N, K = map(int, input().split())
h = [int(input()) for _ in [0]*N]

h = sorted(h)
ans = []

for i in range(len(h)-K+1):
  ans.append(h[i+K-1]-h[i])
  if ans[-1] == 0:
    print(0)
    exit()

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

from sys import stdin
import math
import fractions
from collections import deque

INF = 10 ** 10

# 再帰的に更新
def update_dp(dp, n):
    for i in nextl[n]:
        dp[i] = max(dp[i], dp[n]+1)
        update_dp(dp, i)


if __name__ == "__main__":

    N, M = [int(x) for x in stdin.readline().rstrip().split()]
    xv = [list(map(int, stdin.readline().rstrip().split())) for _ in range(M)]

    # iにいくまでの最長のパス
    dp = [0] * (N+1)

    # iのnextを保持するリスト
    nextl = [[] for _ in range(N+1)]

    for x, v in xv:
        dp[v] = max(dp[v], dp[x]+1)
        update_dp(dp, v)
        nextl[x].append(v)

    # for DEBUG
    #print(dp)
    print(max(dp))

### FIXED CODE ###

from sys import stdin
import math
import fractions
from collections import deque
import sys

# 再起の上限を変更
sys.setrecursionlimit(100000)

INF = 10 ** 10

# 深さ優先探索
def dfs(i):
    global is_visited
    global tsort_res

    if is_visited[i]:
        return 

    is_visited[i] = True
    for j in nextl[i]:
        dfs(j)
    
    # 帰りがけ順で追加
    # 追加は先頭に行う
    tsort_res.appendleft(i)


# トポロジカルソート
def tsort():
    for i in range(1, N+1):
        dfs(i)

if __name__ == "__main__":

    N, M = [int(x) for x in stdin.readline().rstrip().split()]

    # トポロジカルソートで頂点iより後ろのパスの最大長
    dp = [0] * (N+1)

    # 頂点xから頂点vへの有向辺
    nextl = [[] for _ in range(N+1)]
    for _ in range(M):
        x, v = list(map(int, stdin.readline().rstrip().split()))
        nextl[x].append(v)
    
    # トポロジカルソートされた結果の入るリスト
    tsort_res = deque([])

    is_visited = [False] * (N+1)

    tsort()

    # 今回は逆順に使うのでリバースする
    # 汎用性のため、dfsでは先頭に追加するようにしている
    tsort_res = list(tsort_res)[::-1]

    for x in tsort_res:
        for v in nextl[x]:
            dp[x] = max(dp[x], dp[v] + 1)


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

import sys
sys.setrecursionlimit(400000000)
n,k=map(int,input().split())
h=list(map(int,input().split()))
flog=[-1]*n
#初期値は0
def Num(dest):
    if flog[dest-1]!=-1:
        return flog[dest-1]
    if dest<k+2:
        res=abs(h[dest-1]-h[0])
        flog[dest-1]=res
        return res
    else:
        min=10**4*n
        for i in range(1,k+1):
            tmp=Num(dest-i)+abs(h[dest-1]-h[dest-i-1])
            if min>tmp:
                min=tmp
        flog[dest-1]=min
        return min
          

    
print(Num(n))

### FIXED CODE ###

import sys
sys.setrecursionlimit(400000000)
def main():
    n,k=map(int,input().split())
    h=tuple(map(int,input().split()))
    flog=[-1]*n
    for i in range(n):#dest=i 0が１
        if i<k+1:#0~k
            flog[i]=abs(h[i]-h[0])
        else:
            min=10**9
            for j in range(1,k+1):#1~k
                tmp=flog[i-j]+abs(h[i]-h[i-j])
                if tmp<min:
                    min=tmp
            flog[i]=min
    print(flog[n-1])
   # print(flog)
if __name__=="__main__":
    main()
### BUGGY CODE ###

N, A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for k in range(50 * N + 1)] for j in range(N + 1)] for i in range(N + 1)]
dp[0][0][0] = 1
for i in range(1,N+1):
    for j in range(i+1):
        for k in range(50 * N + 1):
            dp[i][j][k] += dp[i-1][j][k]
            if j != 0 and k - X[i-1] >= 0:
                dp[i][j][k] += dp[i-1][j-1][k - X[i-1]]
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A * i]
print(ans)

### FIXED CODE ###

N, A = map(int,input().split())
X = list(map(int,input().split()))
dp = [[[0 for k in range(50 * N + 1)] for j in range(N + 1)] for i in range(N + 1)]
dp[0][0][0] = 1
for i in range(1,N+1):
    for j in range(i+1):
        for k in range(50 * N + 1):
            dp[i][j][k] += dp[i-1][j][k]
            if j != 0 and k - X[i-1] >= 0:
                dp[i][j][k] += dp[i-1][j-1][k - X[i-1]]
ans = 0
for i in range(1, N+1):
    ans += dp[N][i][A * i]
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(input().split())
for i in range(n):
  for k in range(i+1,n):
    if a[i] == a[k]:
      print("NO")
      exit()
print("YES")

### FIXED CODE ###

n = int(input())
a = list(input().split())
if n == len(list(set(a))):
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

import array

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

A.sort()
cnt = 0
for i in range(N):
    for j in range(N):
        if A[i] % A[j] == 0 and i != j:
            cnt += 1
            break
        if A[j] > A[i]: break

print (N-cnt)


### FIXED CODE ###

import numpy as np
import random

rand = False
if rand:
    N = 10 ** 5
    A = random.choices(range(1, 10**6), k=N)
else:
    N = int(input())
    A = list(map(int, input().split()))

A.sort()
MX = max(A)
ret = np.zeros(MX+1, dtype=np.bool)
A = np.array(A, dtype=np.int32)
ret[ A ] = True

for i in range(N-1):
    m = A[i] * 2
    if A[i] == A[i+1]: m = A[i]
    ret[ np.arange(m, MX+1, A[i]) ] = False

print(np.sum(ret))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(500000)

n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((r, d))
    edges[r].append((l, -d))


coord = [None for i in range(n)]
def dfs(v):
    possible = True
    for u, d in edges[v]:
        if not possible:
            break
        if coord[u]:
            if coord[u] != coord[v] + d:
                return False
        else:
            # not visited yet
            coord[u] = coord[v] + d
            possible = possible and dfs(u)

    return possible

ans = True
for i in range(n):
    if coord[i]:
        continue
    coord[i] = 0
    ans = ans and dfs(i)

if ans:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

from collections import deque

def topological_sort(graph: list, n_v: int) -> list:
    # graph[node] = [(cost, to)]
    indegree = [0] * n_v # 各頂点の入次数
    for i in range(n_v):
        for c, v in graph[i]:
            indegree[v] += 1

    cand = deque([i for i in range(n_v) if indegree[i] == 0])
    res = []
    while cand:
        v1 = cand.popleft()
        res.append(v1)
        for c, v2 in graph[v1]:
            indegree[v2] -= 1
            if indegree[v2] == 0:
                cand.append(v2)

    return res




n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for i in range(m):
    l, r, d = map(int, input().split())
    l -= 1
    r -= 1
    edges[l].append((d, r))

ts = topological_sort(edges, n)

if len(ts) != n:
    ans = "No"
    # print("Not DAG")
else:
    # DAG
    dist = [-1] * n
    ans = "Yes"
    for i in range(n):
        v = ts[i]
        if dist[v] == -1:
            dist[v] = 0

        for c, u in edges[v]:
            if dist[u] == -1:
                dist[u] = dist[v] + c
            elif dist[u] != dist[v] + c:
                ans = "No"
                break

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

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

while N>abs(N-K):
  N=abs(N-K)

print(N)

### FIXED CODE ###

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

if N//K>=2:
  N=N-(N//K)*K
  
while N>abs(N-K):
  N=abs(N-K)

print(N)
### BUGGY CODE ###

n, l = map(int, input().split())
ss = [input() for _ in range(n)]
prefix = set()
for s in ss:
	u = ""
	for i in range(len(s)):
		u += s[i]
		prefix.add(u)
grundy = 0
for p in list(prefix):
	le = len(p)
	if p[le-1] == "0":
		t = p[:le-1] + "1"
	else:
		t = p[:le-1] + "0"
	if t not in prefix:
		grundy ^= (l-le+1) & (-l+le-1)

if grundy == 0:
	print("Bob")
else:
	print("Alice")

### FIXED CODE ###

import sys
#from collections import defaultdict
sys.setrecursionlimit(10**6)

def input():
	return sys.stdin.readline()[:-1]
n, l = map(int, input().split())
ss = [list(input())[::-1] for _ in range(n)]

def addTree(tree, sentence):
	if not sentence:
		return None   

	if sentence[-1] not in tree:
		tree[sentence[-1]] = {}

	p = sentence.pop()
	tree[p] = addTree(tree[p], sentence)

	return tree

def createTree(sentences):    
	tree = {}
	for sentence in sentences:
		tree = addTree(tree, sentence)

	return tree

tree = createTree(ss)
#print(tree)

grundy = 0
def dfs(cur, level):
	global grundy
	if cur is None:
		return
	elif len(cur) == 1:
		grundy ^= (l-level) & (-l+level)
	for k in cur.keys():
		dfs(cur[k], level+1)
	return
	
dfs(tree, 0)

if grundy == 0:
	print("Bob")
else:
	print("Alice")
### BUGGY CODE ###

n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = min(w+d*(k-1) for w,d in l)
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)

### FIXED CODE ###

n,k = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(n)]
ok = min(w+d*(k-1) for w,d in l)
ng = 0
while ok-ng > 1:
  mid = (ok+ng)//2
  tot = 0
  for w,d in l:
    if w > mid:
      continue
    tot += 1 + (mid-w)//d
  if tot >= k:
    ok = mid
  else:
    ng = mid
print(ok)
### BUGGY CODE ###

def sgm(i):
    sum=0
    for j in range(i+1):
        sum+=j
    return sum

n, k=map(int, input().split())
p=list(map(int, input().split()))
idx=0
max=0
sum=0
for i in range(n-k+1):
    for j in range(k):
        sum+=p[i+j]
    if sum>=max:
        max=sum
        idx=i
    sum=0

e=0
for i in range(idx,idx+k):
    e+=(sgm(p[i])/p[i])
print(e)

### FIXED CODE ###

n, k=map(int, input().split())
p=list(map(int, input().split()))
idx=0
sum=0
for i in range(k):
    sum+=p[i]
max=sum
for i in range(k,n):
    sum+=p[i]
    sum-=p[i-k]
    if sum>=max:
        max=sum
        idx=i-k+1

e=0
for i in range(idx,idx+k):
    e+=((p[i]+1)/2)
print(e)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
for i in range(q):
  a,b=map(int,input().split())
  if b==n:b=-1
  print(s[a-1:b].count("AC"))

### FIXED CODE ###

from bisect import bisect_left
n,q=map(int,input().split())
s=input().replace("AC","XY")
ref=[i for i,j in enumerate(s) if j=="X"]
for _ in range(q):
	a,b=map(int,input().split())
	a-=1;b-=1
	print(bisect_left(ref,b)-bisect_left(ref,a))
### BUGGY CODE ###

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

ansL = []
for i in range(5020):
    if L + i > R:
        break

    ansL.append((L + i) % 2019)

ans = []
for i in range(len(ansL)):
    for j in range(len(ansL)):
        if i == j:
            continue
        
        ans.append((ansL[i] * ansL[j]) % 2019)
        

ans = sorted(ans)
print(ans[0])

### FIXED CODE ###

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

ansL = []
for i in range(2019):
    if L + i > R:
        break

    ansL.append((L + i) % 2019)

ans = 999999
for i in range(len(ansL)):
    for j in range(i, len(ansL)):
        if i == j:
            continue
        
        ans = min([ans, ((ansL[i] * ansL[j] ) % 2019)])

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

#!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
b = set()
for i in a:
    b = b ^ {i}
print(len(b))


### FIXED CODE ###

#!/usr/bin/env python3
from collections import defaultdict
n, *a = map(int, open(0).read().split())
b = defaultdict(int)
for i in a:
    b[i] += 1
print(sum(i % 2 > 0 for i in b.values()))
### BUGGY CODE ###

from operator import itemgetter
import sys

# スペース区切りの整数入力
n,d,a = map(int, input().split())

#指定数分の2つの整数を順番に受けてリストに入力
e = []
for i in range(n):
    e.append([int(x) for x in input().split()])
e.sort(key=itemgetter(0))

atk_times_sum = 0

for i in range(n):
    if e[i][1] <= 0:
        continue
    atk_l = e[i][0]
    atk_u = e[i][0] + d*2
    if e[i][1] % a == 0:
        atk_times = e[i][1] // a
    else:
        atk_times = e[i][1] // a + 1
    atk_times_sum += atk_times
    for j in range(i,n):
        if atk_l <= e[j][0] and e[j][0] <= atk_u:
            e[j][1] -=  a * atk_times
        else:
            break

print(atk_times_sum)

### FIXED CODE ###

from operator import itemgetter
from collections import deque
import sys

# スペース区切りの整数入力
n,d,a = map(int, input().split())

#指定数分の2つの整数を順番に受けてリストに入力
e = []
for i in range(n):
    e.append([int(x) for x in input().split()])
e.sort(key=itemgetter(0))

atk_times_sum = 0
atk_que = deque()
atk_acm_p = 0

for i in range(n):
    while len(atk_que) > 0:
        if atk_que[0][0] < e[i][0]:
            atk_u,atk_p = atk_que.popleft()
            atk_acm_p -= atk_p
        else:
            break
    e[i][1] -= atk_acm_p
    if e[i][1] <= 0:
        continue
    atk_u = e[i][0] + d*2
    if e[i][1] % a == 0:
        atk_times = e[i][1] // a
    else:
        atk_times = e[i][1] // a + 1
    e[i][1] = 0 
    atk_times_sum += atk_times
    atk_p = a * atk_times
    atk_acm_p += atk_p
    atk_que.append([atk_u,atk_p])

print(atk_times_sum)
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
m = 1
for a in A:
  m *= a
if m>10**18:
  print(-1)
else:
  print(m)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
m = 1
if 0 in A:
  print(0)
else:
  for a in A:
    m *= a
    if m>10**18:
      print(-1)
      break
  else:
    print(m)
### BUGGY CODE ###

N, Q = [int(nq) for nq in input().split()]
S = input()
ANS = []
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    ans = 0
    for n in range(l-1, r-1):
        if S[n:n+2] == "AC":
            ans += 1
    ANS.append(ans)
for q in range(Q):
    print(ANS[q])

### FIXED CODE ###

N, Q = [int(nq) for nq in input().split()]
S = input()
AC = []
for s in range(len(S)-1):
    if S[s:s+2] == "AC":
        AC.append(1)
    else:
        AC.append(0)
CS = [0]*len(AC)
CS[0] = AC[0]
for i in range(len(AC)-1):
    CS[i+1] = CS[i] + AC[i+1]
for q in range(Q):
    l, r = [int(lr) for lr in input().split()]
    if l == 1:
        print(CS[r-2])
    else:
        print(CS[r-2] - CS[l-2])
### BUGGY CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())


def main():
    for i in range(1, N + 1):
        ans = 0
        xn = int(i ** 0.5) + 1
        for x in range(1, xn):
            s = i - x * x
            if s < 0:
                break
            yn = int(s ** 0.5) + 1
            for y in range(x, yn):
                t = s - (y * y + x * y)
                if t < 0:
                    break
                zn = int(t ** 0.5) + 1
                for z in range(y, zn):
                    v = z * (x + y + z)
                    if v == t:
                        n = len({x, y, z})                            
                        if n == 3:
                            ans += 6
                        elif n == 2:
                            ans += 3
                        else:
                            ans += 1
        print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!python3

LI = lambda: list(map(int, input().split()))

# input
N = int(input())

MAX = 10 ** 2


def main():
    l = [0] * (N + 1)
    for x in range(1, MAX + 1):
        for y in range(1, MAX + 1):
            for z in range(1, MAX + 1):
                v = (x + y + z) ** 2 - (x * y + y * z + z * x)
                if v <= N:
                    l[v] += 1
    for ans in l[1:]:
        print(ans)
        

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

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

num_list = []

for i in range(n-k+1):
    num = 1
    for j in range(i,i+k):
        num *= a[j]
    num_list.append(num)
    
for i in range(len(num_list)-1):
    if num_list[i] < num_list[i+1]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

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

for i in range(n-k):
    if a[i]<a[i+k]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N = int(input())
L = sorted(list(map(int, input().split())))
n = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L[j]-L[i]<L[k]<L[i]+L[j]:
                n +=1
            else:
                break
print(n)

### FIXED CODE ###

import bisect
 
n = int(input())
l = sorted(list(map(int, input().split())))
count = 0
 
for i in range(n):
    a = l[i]
    for j in range(i+1, n):
        b = l[j]
        ab = a + b
        index_c = bisect.bisect_left(l, ab)#二分探索,abをlの中のどこに挿入するか
        count += index_c - j -1

print(count)
### BUGGY CODE ###

n, m = map(int, input().split())
start_list = []
end_list = []

for _ in range(m):
    s, e = map(int, input().split())

    if s == 1:
        start_list.append(e)
    if e == n:
        end_list.append(s)

possible = False
for i in end_list:
    if i in start_list:
        possible = True
        break        

print('POSSIBLE' if possible else 'IMPOSSIBLE')

### FIXED CODE ###


n, m = map(int, input().split())
memo = [False] * n

possible = False
for _ in range(m):
    s, e = map(int, input().split())

    if s == 1:
        if memo[e]:
            possible = True
            break

        memo[e] = True

    elif e == n:
        if memo[s]:
            possible = True
            break

        memo[s] = True

print('POSSIBLE' if possible else 'IMPOSSIBLE')
### BUGGY CODE ###

# -*- coding: utf-8 -*-

import copy

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

B = []
C = []
for _ in range(Q):
    B_i, C_i = map(int, input().split())
    
    B.append(B_i)
    C.append(C_i)

for i in range(Q):
    A_ = []
    for j in range(N):
        A_.append(A[j] if A[j] != B[i] else C[i])
    print(sum(A_), flush=True)
    
    A = copy.deepcopy(A_)


### FIXED CODE ###

# -*- coding: utf-8 -*-

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

B = []
C = []
for _ in range(Q):
    B_i, C_i = map(int, input().split())
    
    B.append(B_i)
    C.append(C_i)

max_i = max(max(A), max(C))

A_N = [0 for _ in range(max_i + 1)]
sum_i = 0

for a in A:
    A_N[a] += a
    sum_i += a

for i in range(Q):
    diff_replace = int(A_N[B[i]] / B[i]) * C[i]
    sum_i += diff_replace - A_N[B[i]]
    
    A_N[C[i]] += diff_replace
    A_N[B[i]] = 0
    
    print(sum_i)
### BUGGY CODE ###

def sumPair(A):
    L = len(A)
    M = 1000000007
    total_sum = 0
    
    for i in range(0, L):
        for j in range(i+1, L):
            pair_m = A[i] * A[j]
            total_sum = (total_sum + pair_m) % M
    return total_sum
        

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

### FIXED CODE ###

def fastSumPair(A):
    L = len(A)
    M = 1000000007
    
    # (a + b + c)**2 = a**2 + b**2 + c**2 + 2*(a*b + b*c + c*a)
    # derive from this equation
    
    # first array
    A_1_sum = 0
    for i in range(0, L):
        A_1_sum = (A_1_sum + A[i]) 
    
    A_1_sum = (A_1_sum ** 2) 
        
    # second array
    A_2_sum = 0
    for i in range(0, L):
        A_2_sum = (A_2_sum + A[i] ** 2) 
                  
    return int((A_1_sum - A_2_sum) // 2) % M        

N = int(input())
A = list(map(int, input().rstrip().split()))
print(fastSumPair(A))
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for _ in range(k):
    imos = [0] * (n + 1)
    for i in range(n):
        imos[max(0, i - a[i])] += 1
        imos[min(n, i + a[i] + 1)] -= 1
    for i in range(1, n):
        imos[i] += imos[i-1]
    imos.pop()
    a = imos
    if min(a) == n:
        break 
print(*a)


### FIXED CODE ###

def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    for _ in range(k):
        imos = [0] * (n + 1)
        for i in range(n):
            imos[max(0, i - a[i])] += 1
            imos[min(n, i + a[i] + 1)] -= 1
        for i in range(1, n):
            imos[i] += imos[i-1]
        imos.pop()
        a = imos
        if min(a) == n:
            break 
    print(*a)
main()
### BUGGY CODE ###

N = int(input())
A_list = list(map(int ,input().split()))
sorted(A_list)

s = 1
if A_list[0] == 0:
    print("0")
else :
    for i in range(len(A_list)):
        s = s*A_list[i]
    if s>pow(10,18):
        print("-1")
    else:
        print(s)

### FIXED CODE ###

import sys
N = int(input())
A_list = list(map(int ,input().split()))

s = 1

A_list.sort()
if A_list[0]==0:
    print("0")
    sys.exit()
for i in range(len(A_list)):
        s = s*A_list[i]
        if s>pow(10,18):
            print("-1")
            sys.exit()

print(s)