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

l = [0,2,5,5,4,5,6,3,7,6]
n,m = list(map(int,input().split()))
a = list(map(int,input().split()))
dp = [['',0] for i in range(n+1)]
for i in range(n):
  for j in range(m):
    if dp[i][1] + l[a[j]] != i + l[a[j]] or i + l[a[j]] > n:
      pass
    elif len(dp[i][0]) + 1 > len(dp[i + l[a[j]]][0]):
      dp[i + l[a[j]]][0] = str(a[j]) + dp[i][0]
      dp[i + l[a[j]]][1] = dp[i][1] + l[a[j]]
    elif len(dp[i][0]) + 1 == len(dp[i + l[a[j]]][0]):
      if int(str(a[j]) + dp[i][0]) > int(dp[i + l[a[j]]][0]):
        dp[i + l[a[j]]][0] = str(a[j]) + dp[i][0]
        dp[i + l[a[j]]][1] = dp[i][1] + l[a[j]]
      else:
        pass
    else:
      pass
print(dp[n][0])

### FIXED CODE ###

if __name__ == "__main__":
  l = [0,2,5,5,4,5,6,3,7,6]
  n,m = list(map(int,input().split()))
  a = list(map(int,input().split()))
  res = ''
  INF = 10**4
  
  dp = [[0,0] for i in range(n+1)]
  for i in range(n):
    for j in range(m):
      if dp[i][1] + l[a[j]] != i + l[a[j]] or i + l[a[j]] > n:
        pass
      else:
        dp[i + l[a[j]]][0] = max(dp[i][0] + 1, dp[i + l[a[j]]][0])
        dp[i + l[a[j]]][1] = dp[i][1] + l[a[j]]
  for i in range(1,n): dp[i][0] = -INF if dp[i][0] == 0 else dp[i][0]
  
  a.sort(reverse = True)
  i = n
  while i > 0:
    for j in range(m):
      if i >= l[a[j]] and dp[i - l[a[j]]][0] + 1 == dp[i][0]:
        res += str(a[j])
        i -= l[a[j]]
        break
      else:
        pass
  print(res)
### BUGGY CODE ###


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

if sum(A) <= K:
  print(0)
  exit()

A.sort()
F.sort(reverse=True)

def check(x):
  k = 0
  for a,f in zip(A, F):
    if a*f > x:
      while a > 0:
        a -= 1
        k += 1
        if a*f <= x: break

  return k <= K

# AをX以下にできるか？?
ng,ok = 0, 10**18+1
while ok-ng > 1:
  x = (ok+ng)//2
  if check(x):
    ok = x
  else:
    ng = x

print(ok)

### FIXED CODE ###

import math

N,K = map(int,input().split())
A = list(map(int,input().split()))
F = list(map(int,input().split()))
if sum(A) <= K:
  print(0)
  exit()
A.sort()
F.sort(reverse=True)

l,r = -1,10**12+1

while r-l > 1:
  m = (l+r)//2

  k = 0
  for i in range(N):
    a,f = A[i], F[i]
    k += max(0,a-(m//f))

  if k <= K:
    r = m
  else:
    l = m

print(r)
### BUGGY CODE ###

import sys
input=sys.stdin.readline
N=int(input())
S=input()[:-1]
c=N
for i in range(N+1):
  c = min(c,S[:i].count('#')+S[i:].count("."))
print(c)


### FIXED CODE ###

import sys
input=sys.stdin.readline
N=int(input())
S=input()
w=S.count('.')
c=w
for i in range(N):
  if S[i]=='.':
    w-=1
  else:
    w+=1
  c=min(c,w)
print(c)
### BUGGY CODE ###

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

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

  ans = 0
  while(len(A)>1):
    a = A.pop()
    b = (1<<(int(math.log(a,2))+1))-a
    #print(a,b)
    r = bisect.bisect_left(A, b)
    if r < len(A) and A[r] == b:
      ans += 1
      del A[r]
  print(ans)

if __name__ == '__main__':
  main()

### FIXED CODE ###

import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] * (W+1) for _ in range(N+1)]

for i in range(N):
    w, v = wv[i]
    for j in range(W+1):
        if j < w:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j], dp[i][j-w]+v)
print(max(dp[N]))

### FIXED CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)]
for i in range(1, N+1):
    for sum_w in range(W+1):
        weight = sum_w - wv[i-1][0]
        if weight < 0:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w]])
        else:
            dp[i][sum_w] = max([dp[i][sum_w], dp[i-1][sum_w], dp[i-1][weight]+wv[i-1][1]])
print(max(dp[N]))
### BUGGY CODE ###

N = int(input())
A = sorted(list(map(int, input().rstrip().rsplit())))

ans = 1
for val in A:
    ans *= val

    if ans == 0:
        break

    if ans > 10**18:
        ans = -1

print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().rstrip().rsplit()))
A_dict = {}

for val in A:
    A_dict[val] = A_dict.get(val, 0) + 1

limit = 10**18
ans = 1

if A_dict.get(0, 0) > 0:
    ans = 0
else:
    for val in A_dict:
        ans *= val ** A_dict[val]

        if ans > limit:
            ans = -1
            break

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

N = int(input())
ans = 1

for i in range(1,N+1):
  ans = ans * (i)
print(ans%(10**9+7))

### FIXED CODE ###

N = int(input())
ans = 1

for i in range(1,N+1):
  ans = (ans * (i))%(10**9+7)
print(ans)
### BUGGY CODE ###

import numpy as np
N = int(input())
A = input().split()

for i in range(1,N+1):
    num = A.index(str(i))
    num = int(num)
    print(num+1)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
L = [[] for i in range(N)]
for i in range(N):
    L[i] = [A[i], i+1]
L = sorted(L)
for i in range(N):
    print(L[i][1])
### BUGGY CODE ###

from collections import defaultdict

n = int(input())
s = input()
S = []
for i in range(n):
    S.append(s[i])
q = int(input())
for i in range(q):
    qw = input()
    if qw[0] == "1":
        qw = qw[2:]
        i, ch = map(str, qw.split())
        S[int(i) - 1] = ch
    else:
        qw = qw[2:]
        l, r = map(int, qw.split())
        new = defaultdict(str)
        c = 0
        for i in range(l - 1, r):
            if new[S[i]] != True:
                new[S[i]] = True
                c += 1
                
        print(c)
        

### FIXED CODE ###

from collections import defaultdict
import bisect

n = int(input())
s = input()
S = []
cnt_ch = defaultdict(list)
for i in range(n):
    S.append(s[i])
    cnt_ch[s[i]].append(i)
    
    
    
    
q = int(input())
for i in range(q):
    qw = input()
    if qw[0] == "1":
        qw = qw[2:]
        i, ch = map(str, qw.split())
        if S[int(i) - 1] == ch:
            continue
        remove = bisect.bisect_left(cnt_ch[S[int(i) - 1]], int(i) - 1)
        del cnt_ch[S[int(i) - 1]][remove]
        S[int(i) - 1] = ch
        if not cnt_ch[ch]:
            cnt_ch[ch].append(int(i) - 1)
            continue
        bisect.insort_left(cnt_ch[ch], int(i) - 1)
        
        
    else:
        #print(cnt_ch)
        qw = qw[2:]
        l, r = map(int, qw.split())
        cnt = 0
        for i in range(ord("a"),ord("a") + 26):
            if not cnt_ch[chr(i)]:
                continue
            edge = bisect.bisect_left(cnt_ch[chr(i)], l - 1)
            #print(cnt_ch[chr(i)][edge - 1:])
            #if bisect.bisect_left(cnt_ch[chr(i)][edge:], i) < r:
            #print(cnt_ch[chr(i)])
            #print(l, r)
            #print(edge)
            if edge < len(cnt_ch[chr(i)]):
                if cnt_ch[chr(i)][edge] < r:
                    cnt += 1
            #print(cnt, "cnt", chr(i))
        print(cnt)
### BUGGY CODE ###

n, k = list(map(int, input().split()))
# 先頭に0番要素を追加すれば、配列の要素番号と入力pが一致する
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

ans = -1e9*1e9
# 開始ノードをsi
for si in range(1, n+1):

    # 閉ループのスコアを取り出す
    x = si
    s = list()  # ノードの各スコアを保存
    tot = 0     # ループ1周期のスコア
    while 1:
        x = p[x]
        s.append(c[x])
        tot += c[x]
        if (x == si): break # 始点に戻ったら終了
    
    # siを開始とする閉ループのスコア(s)を全探
    s_len = len(s)
    t = 0
    for i in range(s_len):
        t += s[i]   # i回移動したときのスコア
        if (i+1 > k): break # 移動回数の上限を超えたら終了
        # 1周期のスコアが正ならば、可能な限り周回する
        if tot > 0:
            e = (k-(i+1))//s_len # 周回数
            now = t + tot*e      # i回移動と周回スコアの合計
        else:
            now = t
        ans = max(ans, now)

print(ans)


### FIXED CODE ###

n, k = list(map(int, input().split()))
# 先頭に0番要素を追加すれば、配列の要素番号と入力pが一致する
p = [0] + list(map(int, input().split()))
c = [0] + list(map(int, input().split()))

ans = -float('inf')
# 開始ノードをsi
for si in range(1, n+1):

    # 閉ループのスコアを取り出す
    x = si
    s = list()  # ノードの各スコアを保存
    #s_len = 0
    tot = 0     # ループ1周期のスコア
    while 1:
        x = p[x]
        s.append(c[x])
        #s[s_len] = c[x]
        #s_len += 1
        tot += c[x]
        if (x == si): break # 始点に戻ったら終了
    
    # siを開始とする閉ループのスコア(s)を全探
    s_len = len(s)
    t = 0
    for i in range(s_len):
        t += s[i]   # i回移動したときのスコア
        if (i+1 > k): break # 移動回数の上限を超えたら終了
        # 1周期のスコアが正ならば、可能な限り周回する
        if tot > 0:
            e = (k-(i+1))//s_len # 周回数
            now = t + tot*e      # i回移動と周回スコアの合計
        else:
            now = t
        ans = max(ans, now)

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

#C
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
k=int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        for k in range(1, k + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

### FIXED CODE ###

#C
import math
k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(1, k + 1):
        ij = math.gcd(i, j)
        for l in range(1, k + 1):
            ans += math.gcd(l, ij)
print(ans)
### BUGGY CODE ###

# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
import itertools
from math import factorial

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

div_num  = 1000000007

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

dmg = [int(input()) for _ in range(M)]

for i in range(M - 1):
    # 連番なら終了
    if dmg[i] + 1 == (dmg[i + 1]):
        print(0)
        exit()

comb_list = []
start = 0
for i in range(len(dmg) + 1):
    if i == len(dmg):
        interval = N - start
    else:
        interval = (dmg[i] - 1) - start
    j = 0
    comb_sum = 0
    while True:
        if (2 * j) > interval:
            break
        num_ptn_1_2 = j + (interval - (2 * j))
        r = j
        #comb_sum += int(factorial(num_ptn_1_2) / factorial(r) / factorial(num_ptn_1_2 - r))
        comb_sum += cmb(num_ptn_1_2,r)
        j += 1
    if i < len(dmg):
        # 壊れた階段の次を始点にする
        start = dmg[i] + 1
    comb_list.append(comb_sum)

result = 1

for elem in comb_list:
    result *= elem

print(result % div_num)

### FIXED CODE ###

# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
import itertools

mod  = 1000000007

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

broken = [0 for _ in range(N + 2)]

for i in range(M):
    n = int(input())
    broken[n] = True

dp = [0 for _ in range(N + 2)]
dp[N] = 1
for i in range(0, N)[::-1]:
    if broken[i]:
        dp[i] = 0
        continue
    dp[i] = (dp[i + 1] + dp[i + 2]) % mod

print(dp[0])
### BUGGY CODE ###

N,Q= map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
for i in range(Q):
  l[i],r[i] = map(int,input().split())
  cnt=0
  for j in range(l[i]-1,r[i]-1):
    #print(S[j]+S[j+1])
    if S[j]+S[j+1]=="AC":
      cnt +=1
  print(cnt)

### FIXED CODE ###

N,Q=map(int,input().split())
S=input()
l=[0]*Q
r=[0]*Q
T=[0]

for j in range(0,N-1):
  if S[j]+S[j+1]=="AC":
    T.append(T[-1]+1)
  else:
    T.append(T[-1])
T.append(T[-1])
#print(T)

for i in range(Q):
  l[i],r[i] = map(int,input().split())
  print( T[r[i]-1] - T[l[i]-1] )
### BUGGY CODE ###

import numpy as np
import sys
input = sys.stdin.readline


def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + [int(i) for i in input().split()])
    B = np.array([0] + [int(i) for i in input().split()])

    A.cumsum(out=A)
    B.cumsum(out=B)
    ans = 0

    for i in range(N + 1):
        if A[i] > K:
            break

    A_max_i = i
    B_min_i = 0
    for A_i in range(A_max_i, -1, -1):
        for B_i in range(B_min_i, M + 1):
            if A[A_i] + B[B_i] > K:
                break
        else:
            B_i += 1
        ans = max(ans, A_i + B_i - 1)

    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np


def main():
    N, M, K = map(int, input().split())
    A = np.array([0] + [int(i) for i in input().split()])
    B = np.array([0] + [int(i) for i in input().split()])

    A.cumsum(out=A)
    B.cumsum(out=B)

    ans = 0
    j = M
    for i in range(N + 1):
        if A[i] > K:
            break
        while B[j] + A[i] > K:
            j -= 1
        ans = max(ans, i + j)

    print(ans)


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

def main():
    N = int(input())
    S = input()
    nums = []
    for b in range(N+1):
        nums.append(num_change(S, b, N))
    print(min(nums))


def num_change(S, border, N):
    count = 0
    for i in range(N):
        if i < border:
            if S[i] == '#':
                count += 1
        else:
            if S[i] == '.':
                count += 1
    return count


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    S = input()
    left_black = 0
    right_white = S.count('.')
    min_change = left_black + right_white
    for s in S:
        if s == '#':
            left_black += 1
        else:
            right_white -= 1
        min_change = min(min_change, left_black + right_white)
    print(min_change)


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

N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(L):
    while True:
        NL = []
        #print(L)
        minb = min(L)
        for l in L:
            r = l % minb
            if r != 0:
                NL.append(r)
        if(len(NL) == 0):
            return minb
        NL.append(minb)
        L = NL

lgcd = [0] * N
rgcd = [0] * N

for i in range(N):
    lgcd[i] = gcd(A[0:i+1])
    rgcd[i] = gcd(A[i:])
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd([lgcd[i-1],rgcd[i+1]])
    if maxg < g:
        maxg = g

print(maxg)


### FIXED CODE ###

N = int(input())
A = sorted(list(map(int,input().split())))
def gcdaaaaaaaaa(L):
    nextminb = L[0]
    nextn = len(L)
    while True:
        n = nextn
        minb = nextminb
        for l in L[:n]:
            nextn = 0
            r= l % minb
            
            if r != 0:
                L[nextn] = r
                nextn += 1
                if r < nextminb :
                    nextminb = r
        if minb == nextminb:
            return minb
        
def gcd(a,b):
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b,r)
def gcdL(L):
    g = L[0]
    for l in L:
        g = gcd(g,l)
    return g



lgcd = [0] * N
rgcd = [0] * N

lg = A[0]
rg = A[-1]
for i in range(N):
    
    lg = gcd(lg,A[i])
    lgcd[i] = lg
    rg = gcd(rg,A[N-i-1])
    rgcd[N-i-1] = rg
    
maxg = max(lgcd[N-2],rgcd[1])
for i in range(1,N-1):
    g = gcd(lgcd[i-1],rgcd[i+1])
    if maxg < g:
        maxg = g

print(maxg)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**5)

def solve(ab, hp, memo):
  if hp <= 0:
    return 0
  else:
    ans = 10**10
    if not hp in memo:
      for attack, cost in ab:
        ans = min(ans, solve(ab, hp-attack, memo)+cost)
      memo[hp] = ans
    return memo[hp]

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
memo = {}
for i in range(H+1):
  solve(AB, i, memo)
print(memo[H])

### FIXED CODE ###

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
memo = [10**10]*(H+1)
memo[0] = 0
i = 0
while i <= H:
  for a, b in AB:
    memo[i] = min(memo[i], b+memo[max(0, i-a)])
  i += 1
print(memo[H])
### BUGGY CODE ###

n = int(input())
s = input()

d = {}
for i in range(n-2):
    for j in range(i+1, n-1):
        for l in range(j+1, n):
            r = s[i] + s[j] + s[l]
            if r not in d:
                d[r] = 0
            d[r] += 1

print(len(d))

### FIXED CODE ###

n = int(input())
s = input()

ans = 0
for i in range(1000):
    i = str(i)
    i = (3-len(i)) * '0' + i
    r = 0
    for j in range(n):
        if s[j] == i[r]:
            r += 1
        if r == 3:
            break
    if r == 3:
        ans +=1

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

def main():
  import sys
  input = sys.stdin.readline
  n,k=map(int,input().split())
  h=tuple(map(int,input().split()))
  dp=[0]*(n+1)
  for i in range(2,n+1):
    a=min(i-1,k)+1
    dp[i]+=min([dp[i-j]+abs(h[i-1]-h[i-j-1]) for j in range(1,a)])
  print(dp[-1])
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  import sys
  input = sys.stdin.readline
  n,k=map(int,input().split())
  h=tuple(map(int,input().split()))
  dp=[0]*(n+1)
  for i in range(2,n+1):
    a=min(i-1,k)+1
    m=float('inf')
    for j in range(1,a):
      x=dp[i-j]+abs(h[i-1]-h[i-j-1])
      m=x if m>=x else m
    dp[i]+=m
  print(dp[-1])
if __name__=='__main__':
  main()
### BUGGY CODE ###

n = int(input())
edges = [tuple(map(int, input().split())) for _ in range(n-1)]

color = {}
C = 0
forbidden = [set() for _ in range(n+1)]
for a, b in sorted(edges):
    for c in range(n):
        if c not in forbidden[a] and c not in forbidden[b]:
            forbidden[a].add(c)
            forbidden[b].add(c)
            color[(a, b)] = c
            C = max(C, c)
            break

print(C + 1)
for a, b in edges:
    print(color[(a, b)] + 1)

### FIXED CODE ###

n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

ans = {(-1, 0): -1}
que = {(-1, 0)}
while que:
    queque = set()
    for p, v in que:
        c = 1
        for w in connect[v]:
            if w != p:
                if c == ans[(p, v)]:
                    c += 1
                ans[(v, w)] = c
                queque.add((v, w))
                c += 1
    que = queque
pri = [0] * (n-1)
for i, (a, b) in enumerate(edge):
    a -= 1
    b -= 1
    if (a, b) in ans:
        pri[i] = ans[(a, b)]
    else:
        pri[i] = ans[(b, a)]
print(max(pri))
for x in pri:
    print(x)
### BUGGY CODE ###

n = int(input())
s = list(input())
r_pos = []
g_pos = []
b_pos = []
for i in range(n):
    st = s[i]
    if st == "R":
        r_pos.append(i)

    if st == "G":
        g_pos.append(i)

    if st == "B":
        b_pos.append(i)

#print(r_pos, g_pos, b_pos)
ans = 0
for r in r_pos:
    for g in g_pos:
        for b in b_pos:
            color = [r, g, b]
            color.sort()
            x = color[0]
            y = color[1]
            z = color[2]
            if z - y != y - x:
                ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
s = list(input())
r_pos = []
g_pos = []
b_pos = []

for i in range(n):
    st = s[i]
    if st == "R":
        r_pos.append(i)

    if st == "G":
        g_pos.append(i)

    if st == "B":
        b_pos.append(i)

colors = [r_pos, g_pos, b_pos]
if len(colors[0]) > len(colors[1]):
    colors[0], colors[1] = colors[1], colors[0]
if len(colors[0]) > len(colors[2]):
    colors[0], colors[2] = colors[2], colors[0]
if len(colors[1]) > len(colors[2]):
    colors[1], colors[2] = colors[2], colors[1]

x_num, y_num, z_num = len(colors[0]), len(colors[1]), len(colors[2])

ans = x_num * y_num * z_num
c = set(colors[2])
for a in colors[0]:
    for b in colors[1]:
        x, y = min(a, b), max(a, b)

        dif = y - x
        left_pos = x - dif
        right_pos = y + dif
        mid_pos = 4000
        if dif % 2 == 0:
            mid_pos = x + dif // 2

        left = 0
        right = 0
        mid = 0
        if left_pos in c:
            left = 1
        if right_pos in c:
            right = 1
        if mid_pos in c:
            mid = 1

        ans -= left + right + mid

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

s = input()
mod = 10 ** 9 + 7
dp = []
for _ in range(len(s) + 1):
    l = []
    for __ in range(13):
        l.append(0)
    dp.append(l)
# [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
    if si == '?':
        for n in range(10):
            a = n * (10 ** i) % 13
            for j in range(13):
                dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
    else:
        a = int(si) * (10 ** i) % 13
        for j in range(13):
            dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
print(dp[len(s)][5])


### FIXED CODE ###

s = input()
mod = 10 ** 9 + 7
memo = [0] * (len(s) + 1)
memo[0] = 1
dp = [[0 for _ in range(13)] for __ in range(len(s) + 1)]
dp[0][0] = 1
for i, si in enumerate(s[::-1]):
    memo[i+1] = memo[i] * 10 % 13
    if si == '?':
        for n in range(10):
            a = n * memo[i]
            for j in range(13):
                dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
    else:
        a = int(si) * memo[i]
        for j in range(13):
            dp[i+1][(j + a) % 13] = (dp[i+1][(j + a) % 13] + dp[i][j]) % mod
print(dp[len(s)][5])
### BUGGY CODE ###

def main():
	k = int(input())
	h = tuple(map(int,input().split()))
	ans = 1
	for i in range(k):
		ans *= h[i]
	if ans <= 10 **18:
		print(ans)
	else:
		print(-1)
	


if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	k = int(input())
	h = tuple(map(int,input().split()))
	ans = 1
	avoid = 0
	if (0 in h):
		print(0)
	else:
		for i in range(k):
			ans = h[i] * ans
			if ans > 10 **18:
				print(-1)
				avoid = 1
				break
		if avoid == 0:
			print(ans)
	


if __name__ == '__main__':
	main()