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

import sys
input = sys.stdin.readline
Max = 2000
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())

h,w = m()

aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa.pop()
        if not c == 0:
            if aa[c-1][v] > aa[c][v]+1:
                aa[c-1][v] = aa[c][v]+1
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] > aa[c][v]+1:
                aa[c+1][v] = aa[c][v]+1
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] > aa[c][v]+1:
                aa[c][v-1] = aa[c][v]+1
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] > aa[c][v]+1:
                aa[c][v+1] = aa[c][v]+1
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)
        


### FIXED CODE ###

import sys
input = sys.stdin.readline
Max = 2000
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())

h,w = m()

aa = [[] for i in range(h)]
aaa = []
ma = 0
for i in range(h):
    k = list(input())
    for j in range(w):
        if k[j] == "#":
            aa[i].append(0)
            aaa.append([i,j])
        else:
            aa[i].append(Max)
kk = []
while True:
    if len(aaa) == 0:
        break
    for i in range(len(aaa)):
        c,v = aaa[i]
        if not c == 0:
            if aa[c-1][v] > aa[c][v]+1:
                aa[c-1][v] = aa[c][v]+1
                kk.append([c-1,v])
                ma = max(ma,aa[c-1][v])
        if not c == h-1:
            if aa[c+1][v] > aa[c][v]+1:
                aa[c+1][v] = aa[c][v]+1
                kk.append([c+1,v])
                ma = max(ma,aa[c+1][v])
        if not v == 0:
            if aa[c][v-1] > aa[c][v]+1:
                aa[c][v-1] = aa[c][v]+1
                kk.append([c,v-1])
                ma = max(ma,aa[c][v-1])
        if not v == w-1:
            if aa[c][v+1] > aa[c][v]+1:
                aa[c][v+1] = aa[c][v]+1
                kk.append([c,v+1])
                ma = max(ma,aa[c][v+1])
    aaa = kk
    kk = []
print(ma)
### BUGGY CODE ###

N, M = map(int, input().split())
X = [-1] * N
E = [[] for i in range(N)]
I = [0] * N
for i in range(M):
  L, R, D = map(int, input().split())
  E[L - 1].append([R - 1, D])
  X[R - 1] = -2
  I[R - 1] += 1
ans = True
for i in range(N):
  if X[i] == -1:
    _X = [x for x in X]
    _X[i] = 0
    Q = [i]
    while Q:
      s = Q[0]
      Q = Q[1:]
      X[s] = -3
      for e, d in E[s]:
        if _X[e] <= -2 and _X[s] + d <= 10 ** 9:
          _X[e] = _X[s] + d
          Q.append(e)
        elif _X[e] != _X[s] + d:
          ans = False
          break
    if not ans:
      break
for i in range(N):
  if X[i] == -2 and I[i]:
    ans = False
    break
print('Yes' if ans else 'No')

### FIXED CODE ###

import heapq
N, M = map(int, input().split())
E = [[] for _ in range(N)]
RE = [[] for _ in range(N)]
S = [0] * N
for _ in range(M):
  l, r, d = map(int, input().split())
  S[l - 1] = 1
  E[l - 1].append([d, r - 1])
  RE[r - 1].append([d, l - 1])
D = [None] * N
def dijkstra(i):
  D[i] = 0
  Q = [[0, i]]
  while Q:
    d, s = heapq.heappop(Q)
    for dist, adj in E[s]:
      if D[adj] == None:
        D[adj] = D[s] + dist
        heapq.heappush(Q, [D[adj], adj])
      elif D[adj] == 'Error' or D[adj] != D[s] + dist:
        D[s] = 'Error'
        break
    else:
      for dist, adj in RE[s]:
        if D[adj] == None:
          D[adj] = D[s] - dist
          heapq.heappush(Q, [D[adj], adj])
        elif D[adj] == 'Error' or D[adj] != D[s] - dist:
          D[s] = 'Error'
          break
      else:
        continue
    break
for i in range(N):
  if D[i] == 'Error':
    print('No')
    break
  elif D[i] == None:
    dijkstra(i)
else:
  for d in D:
    if d == 'Error':
      print('No')
      break
  else:
    print('Yes')
### BUGGY CODE ###

import numpy as np

h, w, d = map(int, input().split())
arr = np.zeros([h, w], dtype=np.int64)

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

q = int(input())
lr = np.zeros([q, 2], dtype=np.int64)

for i in range(q):
    lr[i] = list(map(int, input().split()))

ans = []
for l, r in lr:
    score = 0
    while l != r:
        tmp = l + d
        u = np.where(arr == l)
        v = np.where(arr == tmp)
        score += (abs(v[0][0] - u[0][0]) + abs(v[1][0] - u[1][0]))
        l += d
    ans.append(score)

print(*ans, sep="\n")

### FIXED CODE ###

h, w, d = map(int, input().split())
arr = [0] * (h * w + 1)

a = [list(map(int, input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        s = a[i][j]
        arr[s] = (i, j)

q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

cnt = h * w
result = [[0] for _ in range(d)]
for i in range(d):
    l = i
    score = 0
    while l + d <= cnt:
        if l == 0:
            result[i].append(score)
            l += d
            continue
        (ux, uy) = arr[l]
        (vx, vy) = arr[l + d]
        score += (abs(vx - ux) + abs(vy - uy))
        result[i].append(score)
        l += d


for l, r in lr:
    ans = result[l % d]
    print(ans[r // d] - ans[l // d])
### BUGGY CODE ###

mod = 1000000007
eps = 10**-9


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

    N = int(input())
    A = list(map(int, input().split()))
    M = 10**6

    A.sort()
    C = Counter(A)
    ans = 0
    seen = [0] * (M+1)
    for a in A:
        if C[a] == 1 and seen[a] == 0:
            ans += 1
        for j in range(1, M+1):
            if a * j > M:
                break
            seen[a*j] = 1
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

mod = 1000000007
eps = 10**-9


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

    N = int(input())
    A = list(map(int, input().split()))
    M = 10**6

    A.sort()
    C = Counter(A)
    ans = 0
    seen = [0] * (M+1)
    A = set(A)
    for a in A:
        if C[a] == 1 and seen[a] == 0:
            ans += 1
        for j in range(1, M+1):
            if a * j > M:
                break
            seen[a*j] = 1
    print(ans)


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

import numpy as np

n = int(input())
li = []
for i in range(n):
    a = int(input())
    p = np.full(n, -1, dtype=np.int)
    for j in range(a):
        x, y = map(int, input().split())
        p[x-1] = y
    li.append(p)

ans = 0
for i in range(2**n):
    s = 0
    t = [0]*n
    for j in range(n):
        if i>>j & 1:
            t[j]=1
    is_contradict = 0
    for j in range(n):
        if t[j]:
            for k in range(n):
                if li[j][k]==-1:
                    continue
                if li[j][k] != t[k]:
                    is_contradict = 1
    if not is_contradict:
        ans = max(ans, sum(t))

print(ans)

### FIXED CODE ###

n = int(input())
li = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        li[i][x-1] = y

ans = 0
for i in range(2**n):
    s = 0
    t = [0]*n
    for j in range(n):
        if i>>j & 1:
            t[j]=1
    is_contradict = 0
    for j in range(n):
        if t[j]:
            for k in range(n):
                if li[j][k]==-1:
                    continue
                if li[j][k] != t[k]:
                    is_contradict = 1
    if not is_contradict:
        ans = max(ans, sum(t))

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

import sys
N=int(input())
A=list(map(int, input().split()))
for i in range(N):
  sys.stdout.write(str(A.index(i+1)+1)+" ")

### FIXED CODE ###

N=int(input())
As=list(map(int, input().split()))
man = [""] * N
for i in range(N):
  man[As[i]-1] = str(i+1)
result = ' '.join(man)
print(result)
### BUGGY CODE ###

import numpy as np

n, k = [int(i) for i in input().split()]

dp = [0] * n

steps = np.array([int(i) for i in input().split()])

for i in range(1, n):
    start = max(0, i-k)
    dp[i] = (dp[start:i] + abs(steps[i] - steps[start:i])).min()

print(dp[-1])

### FIXED CODE ###

import numpy as np
 
 
N, K = map(int, input().split())
inputs = np.array([int(i) for i in input().split()])
 
dp = np.zeros(N, dtype=int)
for i in range(1, N):
    start = max(0, i-K)
    dp[i] = (dp[start:i] + abs(inputs[i] - inputs[start:i])).min()
 
print(dp[-1])
### BUGGY CODE ###

N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]]

List.sort(key=lambda x: x[0])
List_S = []
 
result = 0
p = 0
 
for i in range(1,M+1):
    for j in range(p,N):
        A = List[j][0]
        B = List[j][1]
        if A <= i:
            List_S.append(B)
            p += 1
        else:
            break
    if len(List_S) != 0:
        max_index = List_S.index(max(List_S))
        result += List_S[max_index]
        del List_S[max_index]
 
print(result)

### FIXED CODE ###

from operator import itemgetter
import sys
input = sys.stdin.readline

N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(int,input().split())) for i in range(N)] # [[1,2],[3,4],[5,6]]

List.sort(key=itemgetter(0))
List_S = [0]
 
result = 0
p = 0

for i in range(1, M+1):
    add = 0
    add_list = []
    while p < N and List[p][0] == i:
        if List_S[len(List_S)-1] < List[p][1]:            
            List_S.append(List[p][1])
        else:
            add_list.append(List[p][1])
            add += 1
        p += 1
            
    if len(List_S) != 1:
        result += List_S.pop()
        if add > 0:
            List_S.extend(add_list)
            List_S.sort()
 
print(result)
### BUGGY CODE ###

s = input()
n = len(s)

digits = [ord(c) - ord('0') for c in s]

total = 0
for i in range(n):
    if digits[i] == 0:
        continue

    num = 0
    for j in range(i, n):
        num = num * 10 + digits[j]
        if j + 4 < i:
            continue

        if num % 2019 == 0:
            total += 1

print(total)

### FIXED CODE ###

S = input()
digits = list(map(int, S))
divisor = 2019

rem_count = [0] * divisor
rem_count[0] = 1
num = 0
pow10 = 1
total = 0

for digit in reversed(digits):
    num = digit * pow10 + num
    num %= divisor
    total += rem_count[num % divisor]
    pow10 *= 10
    pow10 %= divisor
    rem_count[num % divisor] += 1

print(total)
### BUGGY CODE ###

def main():
    s = list(input())
    n = len(s)
    dp = [[0 for _ in range(13)] for _ in range(n+1)]
    dp[0][0] = 1
    mod = 10**9+7
    for i in range(n):
        if s[i] != '?':
            for j in range(13):
                index = (j*10+int(s[i]))%13
                dp[i+1][index] += dp[i][j]
        else:
            for j in range(10):
                for k in range(13):
                    index = (k*10+j)%13
                    dp[i+1][index] += dp[i][k]
        for j in range(13):
            dp[i+1][j] %= mod
    print(dp[n][5])

if __name__ == "__main__":
    main()

### FIXED CODE ###

mod = 10**9+7
def main():
    s = list(input())
    n = len(s)
    dp = [[0 for _ in range(13)] for _ in range(n+1)]
    dp[0][0] = 1
    for i in range(n):
        if s[i] != '?':
            s[i] = int(s[i])
            for k in range(13):
                index = (k*10+s[i])%13
                dp[i+1][index] += dp[i][k]
        else:
            for j in range(10):
                for k in range(13):
                    index = (k*10+j)%13
                    dp[i+1][index] += dp[i][k]
        for j in range(13):
            dp[i+1][j] %= mod
    print(dp[n][5])

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

import sys

s = sys.stdin.readline().rstrip()
q = int(sys.stdin.readline().rstrip())
query = [sys.stdin.readline().rstrip().split() for i in range(q)]
for i in range(q):
    que = query[i]
    if que[0] == '1':
        s = s[::-1]
    else:
        if que[1] == '1':
            s = que[2] + s
        else:
            s = s + que[2]
print(s)

### FIXED CODE ###

import sys

s = sys.stdin.readline().rstrip()
q = int(sys.stdin.readline().rstrip())
query = [sys.stdin.readline().rstrip().split() for i in range(q)]
top = 1
s = list(s)
s_front = []
s_back = []
for i in range(q):
    que = query[i]
    if que[0] == '1':
        top *= -1
    else:
        if que[1] == '1':
            if top > 0:
                s_front.append(que[2])
                # s = ''.join([que[2], s])
                # s = que[2] + s
            else:
                s_back.append(que[2])
                # s = ''.join([s, que[2]])
                # s = s + que[2]
        else:
            if top > 0:
                s_back.append(que[2])
                # s = ''.join([s, que[2]])
                # s = s + que[2]
            else:
                s_front.append(que[2])
                # s = ''.join([que[2], s])
                # s = que[2] + s
s_front.reverse()
s_front.extend(s)
s_front.extend(s_back)
s = s_front
s = ''.join(s)
if top < 0:
    s = s[::-1]
print(s)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
import copy

[N, M] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
BC = []
for m in range(M):
    BC.append((int(i) for i in input().split()))

# Aをソートする
A.sort()

for m in range(M):
    (B, C) = BC[m]
    # 小さいほうからB枚のカードをCに変える
    # ただし変えるのは元の数字より大きい時だけ
    for i in range(B):
        if A[i] < C:
            A[i] = C
    A.sort()

print (sum(A))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import copy
from operator import itemgetter

[N, M] = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
BC = []
for m in range(M):
    BC.append([int(i) for i in input().split()])

# Aをソートする
A.sort()

# BCをCが大きい順にソートする
sorted_BC = sorted(BC, key=itemgetter(1, 0), reverse=True)

new_A = []
for [B, C] in sorted_BC:
    # もしAの最小値がCを超えていたらもうやる意味ないので終了
    if A[0] > C:
        break

    # 小さいほうからB枚のカードをCに変える
    # ただし変えるのは元の数字より大きい時だけ
    I = 0
    for i in range(B):
        I = i
        if len(A) <= i:
            I -=1
            break
        if A[i] > C:
            I -=1
            break
        new_A.append(C)
        #print(new_A)

    # 変えた分はリストから除外する
    #print(A)
    #print(I)
    del A[:I+1]
    if len(A) == 0:
        break

    #print(A)

if len(A) != 0:
    new_A.extend(A)

print (sum(new_A))
### BUGGY CODE ###

n = int(input())
dic = []
for i in range(n):
    f, st = input().split()
    if f == "insert":
        dic.append(st)
    else:
        if st in dic:
            print("yes")
        else:
            print("no")
            

### FIXED CODE ###

n = int(input())
dic = {}
for i in range(n):
    a = input()
    if a[0] == "i":
        dic[a[7:]] = 0
    else:
        print("yes" if a[5:] in dic else "no")
### BUGGY CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    l, r = 0, N-1
    MOD = 10**9+7
    if K == N:
        ans = 1
        for num in A:
            ans *= num
        print((ans+MOD)%MOD)
        exit()
    elif A[-1] < 0 and K%2 == 1:
        ans = 1
        for i in range(K):
            ans *= A[-i-1]
        ans = (ans+MOD)%MOD
        print(ans)
        exit()
    ans = 1
    if K%2 == 1:
        ans *= A[-1]
        r -= 1
    for _ in range(K//2):
        nl = A[l]*A[l+1]
        nr = A[r]*A[r-1]
        if nl > nr:
            ans *= nl
            l += 2
        else:
            ans *= nr
            r -= 2
    print((ans+MOD)%MOD)
    
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline

def main():
    N, K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()
    l, r = 0, N-1
    MOD = 10**9+7
    if K == N:
        ans = 1
        for num in A:
            ans *= num
            ans = (ans+MOD)%MOD
        print((ans+MOD)%MOD)
        exit()
    elif A[-1] < 0 and K%2 == 1:
        ans = 1
        for i in range(K):
            ans *= A[-i-1]
            ans = (ans+MOD)%MOD
        print(ans)
        exit()
    ans = 1
    if K%2 == 1:
        ans *= A[-1]
        r -= 1
    for _ in range(K//2):
        nl = A[l]*A[l+1]
        nr = A[r]*A[r-1]
        if nl > nr:
            ans *= nl
            l += 2
        else:
            ans *= nr
            r -= 2
        ans = (ans+MOD)%MOD
    print(ans)
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

ret = 0
cnt_0 = [0] * 60
cnt_1 = [0] * 60

for item in a_ls:
    for i in range(60):
        if len(bin(item)) <= i:
            cnt_0[i] += 1
        elif bin(item)[-1-i] == '1':
            cnt_1[i] += 1
        else:
            cnt_0[i] += 1

for i in range(60):
    ret += (cnt_0[i] * cnt_1[i]) * (2 ** i)
    ret %= 10 ** 9 + 7

print(ret)


### FIXED CODE ###

def str2bitstr(chs):
    val = int(chs)
    tmp = bin(val)[2:]
    tmp2 = '0' * (60 - len(tmp))
    return tmp2 + tmp


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

cnts = [0] * 60

for item in a:
    for i, ch in enumerate(item):
        if ch == '1':
            cnts[i] += 1

ret = 0
now = 1

for i in range(1, 61):
    kumi = cnts[-i] * (n - cnts[-i]) % (10 ** 9 + 7)
    ret += kumi * now % (10 ** 9 + 7)
    now *= 2 % (10 ** 9 + 7)
    ret = ret % (10 ** 9 + 7)

print(ret % (10 ** 9 + 7))
### BUGGY CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    A = LI()
    B = LI()
    mb = B[-1]
    for i in range(N):
        if A[i] == B[i]:
            if B[i] < mb:
                p = bisect.bisect_left(B[i+1:],B[i]+1) + i+1
                if p > N-1:
                    print('No')
                    return
            else:
                p = N-1 - i
            B[i],B[p] = B[p],B[i]
            if A[i] == B[i]:
                print('No')
                return
    print('Yes')
    print(*B,sep=' ')

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    A = LI()
    B = LI()

    c = collections.Counter()
    for x in A:
        c[x] += 1
    for x in B:
        c[x] += 1
        if c[x] > N:
            print('No')
            return

    s = 0
    for i in range(N):
        if A[i] == B[i]:

            p = bisect.bisect_left(B,B[i]+1,i+1)
            if p > N-1:
                p = s
                s += 1
                while B[i] == B[s]:
                    s+=1

            B[i],B[p] = B[p],B[i]
    print('Yes')
    print(*B,sep=' ')

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

s ="0"+ input()

nagasa=len(s)
ans=0

for i in range(1,nagasa):
    if nagasa-i<4:
        break
    for k in range(nagasa,1,-1):
        if k-i<4:
            break
        if int(s[i:k])%2019==0:
            ans+=1

print(ans)

### FIXED CODE ###

s = input()

ans=0
s=s[::-1]
t=1
ketame=0
amari10=1
kosuu=[1]+[0]*2020
for i in s:
    ketame=(ketame+(int(i)*amari10)%2019)%2019
    amari10*=10
    amari10%=2019
    kosuu[ketame]+=1

for i in range(len(kosuu)):
    if kosuu[i]>0:
        ans+=kosuu[i]*(kosuu[i]-1)/2
    
print(int(ans))
### BUGGY CODE ###

N,M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
list_N = list(range(1,N+1))
for j in range(M):
    A,B = [int(i) for i in input().split()]
    if H[A-1]<H[B-1]:
        if A in list_N:
            list_N.remove(A)
    elif H[A-1]>H[B-1]:
        if B in list_N:
            list_N.remove(B)
    else:
        if A in list_N:
            list_N.remove(A)
        if B in list_N:
            list_N.remove(B)
print(len(list_N))

### FIXED CODE ###

def set1():
    N,M = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    set_N = set([i for i in range(1, N+1)])
    for i in range(M):
        A,B = [int(i) for i in input().split()]
        if H[A-1] < H[B-1]:
            if A in set_N:
                set_N.remove(A)
        elif H[B-1] < H[A-1]:
            if B in set_N:
                set_N.remove(B)
        else:
            if A in set_N:
                set_N.remove(A)
            if B in set_N:
                set_N.remove(B)
    print(len(set_N))

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

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

ans = 1
flag = 0
a.sort()

for i in range(n):
    ans = ans * a[i] // 1



if ans > 10**18:
    print(-1)
else:
    print(ans)

### FIXED CODE ###

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

ans = 1
flag = 0
a.sort()

for i in range(n):
    ans = ans * a[i] // 1
    if ans > 10**18:
        flag = 1
        break



if flag == 1:
    print(-1)
else:
    print(ans)
### BUGGY CODE ###

import numpy as np
from collections import Counter

N,X,Y=map(int, input().split())
INF=100000
d = [[INF if i!=j else 0 for i in range(N) ] for j in range(N)]
d=np.array(d)
d[X-1,Y-1]=d[Y-1,X-1]=1
for k in range(N):
  for i in range(N):
    for j in range(N):
      if abs(i-j)==1:d[i][j] =d[j][i]=1
      d[i][j] = min(d[i][j], d[i][k]+d[k][j])

unique, counts = np.unique(d, return_counts=True)
count = dict(zip(unique, counts))
for i in range(1,N):
  if count.get(i):print(count[i]//2)
  else: print(0)

### FIXED CODE ###

N,X,Y=map(int, input().split())
d = [0]+list(range(N-1, 0, -1))
X,Y=min(X,Y),max(X,Y)

for i in range(1,N):
  for j in range(i+1,N+1):
    if i<= X:
      if j>= Y:
        d[j-i] -=1
        d[j-Y+X-i+1] += 1
      else:
        if j > (X+Y)/2:
          d[j-i] -=1
          d[X-i+1+Y-j] += 1
    else:
      if i-X+abs(j-Y)+1 < j-i:
        d[j-i] -= 1
        d[i-X+abs(j-Y)+1] += 1

for i in range(1,N):
  print(d[i])
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()

ACindex = []
index = 0
while (True):
    index = S.find("AC", index)
    if index == -1:
        break
    ACindex.append(index)
    index += 2
# print(ACindex)


for i in range(Q):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    count = 0
    for index in ACindex:
        if L <= index and index + 1 <= R:
            count += 1
    print(count)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()

ACindex = []
index = 0
while (True):
    index = S.find("AC", index)
    if index == -1:
        break
    ACindex.append(index)
    index += 2
# print(ACindex)

ACs = []
num_of_AC = 0
pre = -1
for i in ACindex:
    ACs += [num_of_AC]*(i-pre)
    num_of_AC += 1
    pre = i

ACs += [num_of_AC]*(N-1-pre)

for i in range(Q):
    L, R = map(int, input().split())
    L -= 1
    R -= 1
    count = ACs[R]-ACs[L]
    print(count)
# print(ACs)
### BUGGY CODE ###

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

sum=1
for _ in A:
    sum*=_

if sum>10**18:
    print("-1")
else:
    print(sum)


### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
sum=1
for _ in A:
    sum*=_
    if sum>10**18:
        break
if 0 in A:
    print("0")
elif sum>10**18:
    print("-1")
else:
    print(sum)