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

a=int(input())
b=input()
b=b.split(" ")
b=[int(i) for i in b]
c=1
for i in b:
    c=c*i
if(c>10**18):
    print(-1)
else:
    print(c)
    

### FIXED CODE ###

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

if 0 in b:
  print(0)
  exit()
c=1
for i in b:
    c*=i
    if(c>10**18):
        print(-1)
        exit()
     
print(c)
### BUGGY CODE ###

def main():
  _map = map
  _range = range
  _len = len
  _max = max
  _input = input
  _int = int
  n, m = _map(_int, _input().split())
  d1 = [None] * (10 ** 5 + 1)
  for _ in _range(n):
    a, b = _map(_int, _input().split())
    if d1[a] is None:
      d1[a] = [b]
    else:
      d1[a].append(b)
  result = 0
  d2 = {}
  maxb = -1
  for i in _range(1, m + 1):
    if d1[i] is None:
      if _len(d2) == 0:
        continue
    else:
      for j in d1[i]:
        if j not in d2:
          d2[j] = 1
        else:
          d2[j] += 1
        if j > maxb:
          maxb = j
    result += maxb
    d2[maxb] -= 1
    if d2[maxb] == 0:
      del d2[maxb]
      if _len(d2) == 0:
        maxb = -1
      else:
        maxb = _max(d2.keys())
  print(result)
main()

### FIXED CODE ###

n, m = map(int, input().split())
d1 = {}
for _ in range(n):
  a, b = map(int, input().split())
  if a in d1:
    d1[a].append(b)
  else:
    d1[a] = [b]
result = 0
d2 = {}
maxb = -1
for i in range(1, m + 1):
  if i in d1:
    for j in d1[i]:
      if j not in d2:
        d2[j] = 0
      d2[j] += 1
      if j > maxb:
        maxb = j
  else:
    if len(d2) == 0:
      continue
  result += maxb
  if d2[maxb] == 1:
    del d2[maxb]
    if len(d2) == 0:
      maxb = 0
    else:
      maxb = max(d2.keys())
  else:
    d2[maxb] -= 1
print(result)
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


h,w,k = map(int, input().split())
x1,y1,x2,y2 = map(lambda x: int(x)-1, input().split())
s = [None]*h
for i in range(h):
    s[i] = input()
    
from heapq import heappop as hpp, heappush as hp
q = []
hp(q, (0,x1,y1,(0,0),0))

dx = [0,1,0,-1]
dy = [1,0,-1,0]
# dist = [[None]*w for _ in range(h)]
dist = [None]*(w*h)
dist[x1*w+y1] = 0
# done = [[0]*w for _ in range(h)]
done = [0]*(w*h)
done[x1*w+y1] = 15

while q:
    d, x, y, t, td = hpp(q)
    for i,(xx, yy) in enumerate(zip(dx,dy)):
        if (-xx,-yy)==t:
            continue
        nx, ny = xx+x, yy+y
        if nx<0 or nx>=h or ny<0 or ny>=w or s[nx][ny]=="@":
            continue
        if (xx,yy)==t and td<k:
            nd = d
            ntd = td+1
        else:
            nd = d+1
            ntd = 1
        if dist[nx*w+ny] is None or nd<dist[nx*w+ny]:
            hp(q, (nd,nx,ny,(xx,yy),ntd))
            dist[nx*w+ny] = nd
            done[nx*w+ny] = 1<<(i)
        elif nd==dist[nx*w+ny]and ((done[nx*w+ny]&1<<(i))==0):
            hp(q, (nd,nx,ny,(xx,yy),ntd))
            done[nx*w+ny] |= 1<<(i)
            
if dist[x2*w+y2] is None:
    print(-1)
else:
    print(dist[x2*w+y2])

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

h,w,k = map(int, input().split())
x1,y1,x2,y2 = map(lambda x: int(x)-1, input().split())
s = [None]*h
for i in range(h):
    s[i] = input()
    
from queue import deque
q0 = deque([(0,x1,y1,(0,0),0)])
q1 = deque()

dx = [0,1,0,-1]
dy = [1,0,-1,0]
# dist = [[None]*w for _ in range(h)]
dist = [None]*(w*h)
dist[x1*w+y1] = 0
# done = [[0]*w for _ in range(h)]
done = [0]*(w*h)
done[x1*w+y1] = 15

while q0 or q1:
    if not q0:
        q0 = q1
        q1 = deque()
    d, x, y, t, td = q0.popleft()
    for i,(xx, yy) in enumerate(zip(dx,dy)):
        if (-xx,-yy)==t:
            continue
        nx, ny = xx+x, yy+y
        if nx<0 or nx>=h or ny<0 or ny>=w or s[nx][ny]=="@":
            continue
        if (xx,yy)==t and td<k:
            nd = d
            ntd = td+1
            q = q0
        else:
            nd = d+1
            ntd = 1
            q = q1
        if dist[nx*w+ny] is None or nd<dist[nx*w+ny]:
            q.append((nd,nx,ny,(xx,yy),ntd))
            dist[nx*w+ny] = nd
            done[nx*w+ny] = 1<<(i)
        elif nd==dist[nx*w+ny]and ((done[nx*w+ny]&1<<(i))==0):
            q.append((nd,nx,ny,(xx,yy),ntd))
            done[nx*w+ny] |= 1<<(i)
            
if dist[x2*w+y2] is None:
    print(-1)
else:
    print(dist[x2*w+y2])
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import numpy as np
S = input()
n = len(S)
l = np.zeros(n, dtype=int)
DNA = ['A', 'G', 'C', 'T']

i = 0
while(i < n):
  if(S[i] in DNA):
    if(i == n-1):
      l[i] = 1
      i+=1
    else:
      for j in range(i+1, n):
        if(S[j] not in DNA):
          l[i] = j-i
          i = j+1
          break;
  else:
    i += 1
print(max(l))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import numpy as np
S = input()
n = len(S)
l = np.zeros(n, dtype=int)
DNA = ['A', 'G', 'C', 'T']

if S[0] in DNA:
  ll = [1]
else:
  ll = [0]

for i in range(1, n):
  if S[i] in DNA:
    ll.append(ll[i-1]+1)
  else:
    ll.append(0)

print(max(ll))
### BUGGY CODE ###

import sys

input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    dp = [0] * (W + 1)

    WV = (map(int, input().split()) for _ in range(N))

    for w, v in WV:
        for j in range(W, w - 1, -1):
            dp[j] = max(dp[j], dp[j - w] + v)

    print(dp[-1])


main()


### FIXED CODE ###

import sys


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

    N, W = map(int, input().split())
    dp = [0] * (W + 1)

    WV = (map(int, input().split()) for _ in range(N))

    for w, v in WV:
        for j in range(W, w - 1, -1):
            tmp = dp[j - w] + v
            if tmp > dp[j]:
                dp[j] = tmp

    print(dp[-1])


main()
### BUGGY CODE ###

N = int(input())
array=[int(n) for n in input().split()]
lst=[]
left_array=array[:N] 
right_array=array[-N:]
left_lst=[sum(left_array)]
right_lst=[sum(right_array)]
for k in range(N,2*N):
    new_a=array[k]
    new_b=array[-k-1]
    left_array.append(new_a)
    left_array.remove(min(left_array))
    left_lst.append(sum(left_array))
    right_array.append(new_b)
    right_array.remove(max(right_array))
    right_lst.append(sum(right_array))
lst = [a-b for a,b in zip(left_lst,list(reversed(right_lst)))]
print(max(lst))

### FIXED CODE ###

N = int(input())
array = [int(n) for n in input().split()]
import copy
import heapq
lst = [None for i in range(N + 1)]
left_lst = copy.deepcopy(lst)
right_lst = copy.deepcopy(lst)
left_array = array[:N]
right_array= [-n for n in array[-N:]]
l_sum = sum(left_array)
r_sum = sum(right_array)
heapq.heapify(left_array)
heapq.heapify(right_array)
left_lst[0] = l_sum
right_lst[0] = r_sum

for k in range(N, 2 * N):
    new_a, new_b = array[k], array[-k - 1]*-1
    heapq.heappush(left_array,new_a)
    heapq.heappush(right_array,new_b)
    old_a = heapq.heappop(left_array)
    l_sum += (new_a - old_a)
    left_lst[k - N + 1] = l_sum
    old_b = heapq.heappop(right_array)
    r_sum += (new_b - old_b)
    right_lst[k - N + 1] = r_sum
lst = [ a + b for a, b in zip(left_lst, list(reversed(right_lst)))]
print(max(lst))
### BUGGY CODE ###

n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
for i in range(n):
	if x[i][1]>max(x[i][0] for i in range(n))-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(n):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//max(x[i][0] for i in range(n))+1
	print(q+len(c))


### FIXED CODE ###

n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
M = max(x[i][0] for i in range(n))

for i in range(n):
	if x[i][1]>M-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//M+1
	print(q+len(c))
### BUGGY CODE ###

MOD = 10**9+7

def mat_dot(one, two, mod):
	return [[sum([(one[i][k]*two[k][j])%mod for k in range(max(len(two), len(one[0])))])%mod for j in range(len(two[0]))] for i in range(len(one))]

def mat_pow(mat, exp, mod):
	size = len(mat)
	res = [[0 for _ in range(size)] for _ in range(size)]
	for i in range(size):
		res[i][i] = 1
	cnt = 0
	while (1<<cnt) <= exp:
		if (exp>>cnt)&1:
			res = mat_dot(res, mat, mod)
		mat = mat_dot(mat, mat, mod)
		cnt += 1
	return res

n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = mat_pow(a, k, MOD)
print(sum([sum(x) for x in b]) % MOD)

### FIXED CODE ###

MOD = 10**9+7

def mat_dot(one, two, mod):
	return [[sum([(one[i][k]*two[k][j])%mod for k in range(max(len(two), len(one[0])))])%mod for j in range(len(two[0]))] for i in range(len(one))]

def mat_pow(mat, exp, mod):
	size = len(mat)
	res = [[0 for _ in range(size)] for _ in range(size)]
	for i in range(size):
		res[i][i] = 1
	cnt = 0
	while (1<<cnt) <= exp:
		if (exp>>cnt)&1:
			res = mat_dot(res, mat, mod)
		mat = mat_dot(mat, mat, mod)
		cnt += 1
	return res

n, k = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = mat_pow(a, k, MOD)
print(sum([sum(x) for x in b]) % MOD)
### BUGGY CODE ###

n,w=map(int,input().split())
l=[[0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))
dp=[[-10**10]*(w+1) for _ in range(n+1)]
for k in range(w+1):
    dp[0][k]=0
for i in range(1,n+1):
    for j in range(0,w+1):
        if j-l[i][0]>=0:
            dp[i][j]=max(dp[i-1][j-l[i][0]]+l[i][1],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][w])

### FIXED CODE ###

n,w=map(int,input().split())
l=[[0,0]]
for _ in range(n):
    l.append(list(map(int,input().split())))
dp=[[-10**10]*(w+1) for _ in range(n+1)]
for k in range(w+1):
    dp[0][k]=0
for i in range(1,n+1):
    for j in range(0,w+1):
        if j-l[i][0]>=0:
            dp[i][j]=max(dp[i-1][j-l[i][0]]+l[i][1],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]
print(dp[n][w])
### BUGGY CODE ###

if __name__ == "__main__":
    N,x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    A = 0

    a.sort()
    while x >= 0:
        try:
            if a[-1] < x:
                x -= a.pop(-1)
                A += 1
        except:
            break

    if x != 0:
        A -= 1
    print(A)

### FIXED CODE ###

if __name__ == "__main__":
    n, x = map(int, input().split())
    aaa = list(map(int, input().split()))
    ans = 0
    
    for a in sorted(aaa):
        if x < a:
            break
        ans += 1
        x -= a
    else:
        if x > 0:
            ans -= 1
    print(ans)
### BUGGY CODE ###

from collections import deque
from copy import copy

row, column = map(int, input().split())
map1 = [list(map(int, input().split())) for _ in range(row)]
map2 = [list(map(int, input().split())) for _ in range(row)]
map_ = [[n1 - n2 for n1, n2 in zip(row1, row2)] for row1, row2 in zip(map1, map2)]

n = map_[0][0]
queue = deque([(0, 0, n), (0, 0, -n)])
ansque = deque()

def bfs(queue):
    while True:
        nextqueue = deque()
        while queue:
            posr, posc, n = queue.popleft()
            if (posr, posc) == (row - 1, column - 1):
                ansque.append(abs(n))
            for dr, dc in zip([1, 0], [0, 1]):
                nextr = posr + dr
                nextc = posc + dc
                if 0 <= nextr < row and 0 <= nextc < column:
                    nextn = map_[nextr][nextc]
                    nextqueue.append((nextr, nextc, n + nextn))
                    nextqueue.append((nextr, nextc, n - nextn))
        if nextqueue:
            queue = copy(nextqueue)
        else:
            return ansque

print(min(bfs(queue)))


### FIXED CODE ###

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

A = [list(map(int, input().split())) for _ in range(R)]
B = [list(map(int, input().split())) for _ in range(R)]

dp = [0] * C
dp[0] = s = 1 << 6400

for row_a, row_b in zip(A, B):
    for i, (a, b) in enumerate(zip(row_a, row_b)):
        d = abs(a - b)
        if i > 0:
            dp[i] |= dp[i - 1]
        dp[i] = (dp[i] << d) | (dp[i] >> d)

g = dp[-1]
for i in range(6401):
    if g & (s << i) or g & (s >> i):
        print(i)
        quit()
### BUGGY CODE ###

n, k = map(int, input().split(" "))
dices = list(map(int, input().split(" ")))
dices_e = [float(e*(e+1)/(2*e)) for e in dices]
max_e = 0.0
for i in range(n-k+1):
  e = sum(dices_e[i:i+k])
  if e>max_e:
    max_e = e

print(max_e)

### FIXED CODE ###

n, k = map(int, input().split(" "))
dices_e = [float((e+1)/2) for e in list(map(int, input().split(" ")))]
e = max_e = sum(dices_e[:k])
for i in range(1, n-k+1):
  e = e - dices_e[i-1] + dices_e[i+k-1]
  if e>max_e:
    max_e = e

print(max_e)
### BUGGY CODE ###

import collections
N = int(input())
countr = []
liss = []
ccr = []
for i in range(N):
  s = input()
  a = collections.Counter(s)
  if a in liss:
    ind = liss.index(a)
    ccr[ind] += countr[ind]
    countr[ind] += 1
  else:
    liss.append(a)
    countr.append(1)
    ccr.append(0)


print(int(sum(ccr)))


### FIXED CODE ###

N = int(input())
liss = {}
for i in range(N):
  s = input()
  a = "".join(sorted(s))
  if a in liss:
    liss[a] += 1
  else:
    liss[a] = 1

ans = 0
for cc in liss:
  ans = ans + (liss[cc] * (liss[cc] - 1) / 2)
print(int(ans))
### BUGGY CODE ###

N = int(input())

memo1 = []
memo2 = []
for i in range(N):
  S = input()
  sum_n = min_n = 0
  for s in S:
    if s == ')':
      sum_n -= 1
      min_n = min(min_n, sum_n)
    else:
      sum_n += 1
  if sum_n >= 0:
    memo1.append([min_n, sum_n])
  else:
    memo2.append([min_n-sum_n, -sum_n])

memo1.sort(reverse=True)
left = 0
for min_n, sum_n in memo1:
  if left + min_n < 0:
    print('No')
    quit()
  else:
    left += sum_n

memo2.sort(reverse=True)
right = 0
for min_n, sum_n in memo2:
  if right + min_n < 0:
    print('No')
    quit()
  else:
    right += sum_n

if left == right:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = int(input())

memo1 = []
memo2 = []
for i in range(N):
  S = input()
  sum_n = min_n = 0
  for s in S:
    if s == ')':
      sum_n -= 1
      min_n = min(min_n, sum_n)
    else:
      sum_n += 1
  if sum_n >= 0:
    memo1.append([min_n, sum_n])
  else:
    memo2.append([min_n-sum_n, -sum_n])

memo1.sort(reverse=True)
left = 0
for min_n, sum_n in memo1:
  if left + min_n < 0:
    print('No')
    quit()
  else:
    left += sum_n

memo2.sort(reverse=True)
right = 0
for min_n, sum_n in memo2:
  if right + min_n < 0:
    print('No')
    quit()
  else:
    right += sum_n

if left == right:
  print('Yes')
else:
  print('No')
### BUGGY CODE ###

#from operator import itemgetter
#from collections import Counter
#import heapq
N = int(input())
S = input()
#N, M = map(int, input().split())
#A = list(map(lambda x: int(x)*(-1), input().split()))
#A = [int(input()) for i in range(N)]
#C = [list(map(int, input().split())) for i in range()]
R  =[]
G  =[]
B  =[]
answer = 0
for i, s in enumerate(S):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)
l_B = len(B) 
for r in R:
    for g in G:
        sa = abs(r-g)
        hiku = 0
        for b in B:
            if sa == abs(b-r) or sa == abs(b-g) or abs(b-r) == abs(g-b):
                hiku += 1

        answer += l_B - hiku

print(answer)


### FIXED CODE ###

N = int(input())
S = input()
#N, M = map(int, input().split())
#A = list(map(lambda x: int(x)*(-1), input().split()))
#A = [int(input()) for i in range(N)]
#C = [list(map(int, input().split())) for i in range()]
R  =[]
G  =[]
B  =[]
for i, s in enumerate(S):
    if s == 'R':
        R.append(i)
    elif s == 'G':
        G.append(i)
    else:
        B.append(i)
answer = len(R)*len(G)*len(B)
hiku = 0

for i in range((N-1)//2):
    for j in range(N-i-i-2):
        if S[j] != S[j+i+1] and S[j+i+1] != S[j+i+i+2] and S[j] != S[j+i+i+2]:
            hiku += 1


answer -= hiku
print(answer)
### BUGGY CODE ###

import math
import copy
s=0
n, m=map(int, input().split())
mm = copy.copy(m)
t = {}
a = int(math.sqrt(mm))

while s==0:
    for i in range(2,a+2):
        if m%i==0:
            m=m//i
            if m==1:
                s=1
            if i in t.keys():
                t[i]+=1
            else:
                t[i]=1
            break
out=1

def combi(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) 

for tk in t.keys():
    out *= combi(t[tk]+n-1, n-1)
print(out%(1000000007))

### FIXED CODE ###

import math

n, m=map(int, input().split())
t = {}
a = int(math.sqrt(m))

s=0

line = [2, 3] + [i%2*2 + i//2 * 6 + 5 for i in range(a)]
# line = [2] + list(range(3, m+2, 2))

for i in line:
# for i in range(2, m+2, 2):
#     print(i)
    cnt = 0
    while m%i==0:
        m=m//i
        cnt += 1

    if cnt>0:
        t[i]=cnt

    if m==1:
        break

if m!=1:
    t[m]=1

def combi(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) 

out=1
for tk in t.keys():
    out *= combi(t[tk]+n-1, n-1)
#     out = out%(1000000007)
print(out%(1000000007))
### BUGGY CODE ###

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

ans = 0
a_as = [0 for _ in range(max(a))]

for x in a:
    a_as[x-1] += 1

for i,cnt in enumerate(a_as):
    if cnt == 0 or cnt == i+1:
        continue
    elif cnt > i+1:
        ans += cnt - (i+1)
    else:
        ans += cnt
    
print(ans)

### FIXED CODE ###


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

ans = 0
a_as = {}

for x in a:
    if x in a_as:
        a_as[x] += 1
    else:
        a_as[x] = 1

for x in a_as:
    if x > a_as[x]:
        ans += a_as[x]
    else:
        ans += abs(a_as[x]-x)
    
print(ans)
### BUGGY CODE ###


def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split()))

def f(m, a):
	r = []
	for n in a[::-1]:
		if n not in r:
			r.append(n)
	for i in range(m):
		if (i+1) not in r:
			r.append(i+1)
	return r


n, m = reads()
q = read()
a = reads()

r = f(m, a)
count = [0] * (m+1)
count[0] = n

for aa in a[::-1]:
	index = r.index(aa)
	if 0 < count[index]:
		count[index] -= 1
		count[index+1] += 1

to = 0
for i in range(m):
	if 0 < count[i]:
		to = i
		break

left, right = r[:to], r[to:]

flag = True
index = 0
for i in range(1, len(r)+1):
	if i in left:
		continue
	if right[index] != i:
		flag = False
		break
	if right[index] == i:
		index += 1

if flag:
	print('Yes')
else:
	print('No')



### FIXED CODE ###


def read():
    return int(input())

def reads(sep=None):
    return list(map(int, input().split()))

def f(m, a):
	sa = set(a)
	seen = set()
	r = []
	for n in a[::-1]:
		if n not in seen:
			r.append(n)
			seen.add(n)
	for i in range(m):
		if (i+1) not in sa:
			r.append(i+1)
	return r

def isSorted(a):
	for i in range(1, len(a)):
		if a[i-1] > a[i]:
			return False
	return True

n, m = reads()
q = read()
a = reads()

r = f(m, a)
count = [0] * (m+1)
count[0] = n

table = [-1] * (m+1)
for i in range(len(r)):
	table[r[i]] = i

for aa in a[::-1]:
	index = table[aa]
	if 0 < count[index]:
		count[index] -= 1
		count[index+1] += 1

to = m
for i in range(m):
	if 0 < count[i]:
		to = i
		break

if isSorted(r[to:]):
	print('Yes')
else:
	print('No')
### BUGGY CODE ###

#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = -10 ** 9
    for start in range(N):
        # ループを探す
        now = start
        loop = []
        total = 0
        while now != start or not loop:
            loop.append(C[now])
            now = P[now]
            total += C[now]
        # ループごとの最大スコアを探す
        length = len(loop)
        # sum_loop = sum(loop)
        # # ループ長よりも操作回数が多いか？，ループを周回すると得か？で場合分け
        # res = 0 if sum_loop <= 0 else sum_loop * (K // length)
        # limit = K if K <= length else K % length
        # for k in range(limit):
        #     res += loop[k]
        #     ans = max(ans, res)
        t = 0
        for i in range(length):
            t += loop[i]
            if i + 1 > K:
                break
            now = t
            if total > 0:
                e = (K - (i + 1)) // length
                now += total * e
            ans = max(ans, now)
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    P = [int(x) - 1 for x in input().split()]
    C = [int(x) for x in input().split()]

    ans = -10 ** 9
    for start in range(N):
        # ループを探す
        now = start
        loop = []
        total = 0
        while now != start or not loop:
            loop.append(C[now])
            now = P[now]
            total += C[now]
        # ループごとの最大スコアを探す
        length = len(loop)
        # sum_loop = sum(loop)
        # # ループ長よりも操作回数が多いか？，ループを周回すると得か？で場合分け
        # res = 0 if sum_loop <= 0 else sum_loop * (K // length)
        # limit = K if K <= length else K % length
        # for k in range(limit):
        #     res += loop[k]
        #     ans = max(ans, res)
        t = 0
        for i in range(length):
            t += loop[i]
            if i + 1 > K:
                break
            now = t
            if total > 0:
                e = (K - (i + 1)) // length
                now += total * e
            ans = max(ans, now)
    print(ans)


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

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

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

    return ans

print(main())

### FIXED CODE ###

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

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

    return ans

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

N = list(map(int, input().split()))[-1]
A = sorted(list(map(int, input().split())))[::-1]
B = sorted(list(map(int, input().split())))[::-1]
C = sorted(list(map(int, input().split())))[::-1]

result = []
for i in range(len(A)):
  for j in range(len(B)):
    for k in range(len(C)):
      if i+j+k <= N:
        result.append(A[i]+B[j]+C[k])
  
result = sorted(result)[::-1]
for i in range(N):
  print(result[i])
  

### FIXED CODE ###

N = list(map(int, input().split()))[-1]
A = sorted(list(map(int, input().split())), reverse=True)[:N]
B = sorted(list(map(int, input().split())), reverse=True)[:N]
C = sorted(list(map(int, input().split())), reverse=True)[:N]

first = [i+j for i in A for j in B]
first = sorted(first, reverse=True)[:N]
second = [i+j for i in first for j in C]
result = sorted(second, reverse=True)[:N]

[print(i) for i in result]