Harryxun/stf_run huggingface dataset:
from intertools import chain
from collections import deque
H, W = map(int,input().split())
S = [list(map(str,input().split())) for _ in range(H)]
dhw = [[0,1],[0,-1],[1,0],[-1,0]]

ans = 0
for h in range(H):
  for w in range(W):
    d = deque([h,w])
    maze = [[-1] * W for _ in range(H)]
    if S[h][w] == '#':
      continue
    maze[h][w] = 0
    while d:
      ht , hw = d.popleft()
      for dh, dw in dhw:
        nh = ht + dh
        nw = wt + dw
        if 0 <= nh < H and 0 <= nw < W:
          if maze[nh][nw] == -1 and S[nh][nw] == '.':
            d.append([nh,nw])
            maze[nh][nw] = maze[ht][wt] + 1
    ans = max(ans,max(chain(*maze))
print(ans)


### FIXED CODE ###

C = input()
k = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in range(len(k)):
  if C == k[i]:
    print(k[i+1])
def_input(a,b):
  print a*b 2*(a+b)

### FIXED CODE ###

a,b = map(int, raw_input().split())
s = a*b
l = 2*a + 2*b
print s, l
def main():
    import sys
    input = sys.stdin.readline
    
    R,C,N = map(int,input().split())
    P = []
    X = {0,R}
    Y = {0,C}
    M = 0
    for i in range(N):
        x1,y1,x2,y2 = map(int,input().split())
        if (x1 in X or y1 in Y) and  (x2 in X or y2 in Y):
            M += 1
            if y1==0:
                L1 = x1
            elif x1==R:
                L1 = R+y1
            elif y1==C:
                L1 = 2*R + C - x1
            else:
                L1 = 2*(R+C) - y1
            
            if y2==0:
                L2 = x2
            elif x2==R:
                L2 = R+y2
            elif y2==C:
                L2 = 2*R + C - x2
            else:
                L2 = 2*(R+C) - y2
                
            P.append([min(L1,L2), max(L1,L2)])
    P = sorted(P, key = lambda a:a[0])
    from collections import deque
    
    flag = 0
    Q = []
    for i in range(M):
        x1,x2 = P[i]
        if Q == []:
            Q.append([x1,x2])
        else:
            while Q[-1][1] < x1 and Q!=[]:
                Q.pop()
            if Q==[]:
                Q.append([x1,x2])
            else:
                y1,y2 = Q[-1]
                if y2 < x2:
                    flag = 1
                    break
                else:
                    Q.append([x1,x2])
    if flag == 1:
        print("NO")
    else:
        print("YES")
    
main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    
    R,C,N = map(int,input().split())
    P = []
    X = {0,R}
    Y = {0,C}
    M = 0
    for i in range(N):
        x1,y1,x2,y2 = map(int,input().split())
        if (x1 in X or y1 in Y) and  (x2 in X or y2 in Y):
            if y1==0:
                L1 = x1
            elif x1==R:
                L1 = R+y1
            elif y1==C:
                L1 = 2*R + C - x1
            else:
                L1 = 2*(R+C) - y1
            
            if y2==0:
                L2 = x2
            elif x2==R:
                L2 = R+y2
            elif y2==C:
                L2 = 2*R + C - x2
            else:
                L2 = 2*(R+C) - y2
                
            P.append([min(L1,L2), max(L1,L2)])
    P = sorted(P, key = lambda a:a[0])
    M = len(P)
    
    flag = 0
    Q = []
    for i in range(M):
        x1,x2 = P[i]
        if Q == []:
            Q.append([x1,x2])
        else:
            while Q!=[] and Q[-1][1] < x1:
                Q.pop()
            if Q==[]:
                Q.append([x1,x2])
            else:
                y1,y2 = Q[-1]
                if y2 < x2:
                    flag = 1
                    break
                else:
                    Q.append([x1,x2])
    if flag == 1:
        print("NO")
    else:
        print("YES")
    
main()
n = int(input())

def bfs(s):
  if int(s) >= n:
    return 0
  return ('3' in s and '5' in s and '7' in s) + bfs(s+'3') + bfs(s+'5') + bfs(s+'7')

print(bfs(''))

### FIXED CODE ###

n = int(input())
 
def bfs(s):
  if int(s) > n:
    return 0
  return ('3' in s and '5' in s and '7' in s) + bfs(s+'3') + bfs(s+'5') + bfs(s+'7')
 
print(bfs('0'))
from collections import deque

x, y, a, b, c = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:x]

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
T = deque(sorted(P, reverse=True))
R = deque(sorted(R, reverse=True))

ans = 0
for i in range(x+y):
    if T[0] >= R[0] and len(T) > 0:
        ans += T.popleft()
    elif len(R) > 0:
        ans += R.popleft()
    else:
        ans += T.popleft()

print(ans)


### FIXED CODE ###

from collections import deque

x, y, a, b, c = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P = sorted(P, reverse=True)[:x]

Q = sorted(Q, reverse=True)[:y]

P.extend(Q)
R.extend(P)

T = sorted(R, reverse=True)[:x+y]
print(sum(T))
n=int(input())
n=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
p=make_divisors(n)

l=len(p)
if l%2==1:
  ans=p[l-1]*2-2
  
else:
  ans=p[l-1]+p[l-2]-2
  
print(ans)

### FIXED CODE ###

n=int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
p=make_divisors(n)

l=len(p)
if l%2==1:
  ans=p[l-1]*2-2
  
else:
  ans=p[l-1]+p[l-2]-2
  
print(ans)
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
s=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]=0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  for i in range(1,n):
    if a>=abs(l[i]):
      a=abs(l[i])
      m=i
  s=0
  for i in range(m):
    s+=abs(l[i])
  s+=-abs(l[m])
  for i in range(m+1,n):
    s+=abs(l[i])
  print(s)
    


### FIXED CODE ###

n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
s=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]==0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  for i in range(1,n):
    if a>=abs(l[i]):
      a=abs(l[i])
      m=i
  s=0
  for i in range(m):
    s+=abs(l[i])
  s+=-abs(l[m])
  for i in range(m+1,n):
    s+=abs(l[i])
  print(s)
n,l,t=map(int,input().split())
inf=[]
s=0
for _ in range(n):
x,y=map(int,input().split())
   if y==1:
       x+=t
   else:
       x-=t
    inf.append(x%l)
    s+=x//l
inf.sort()
s%n
for i in range(n):
    print(inf[(i+s)%n])

### FIXED CODE ###

n,l,t=map(int,input().split())
inf=[]
s=0
for _ in range(n):
   x,y=map(int,input().split())
   if y==1:
       x+=t
   else:
       x-=t
   inf.append(x%l)
   s+=x//l
inf.sort()
for i in range(n):
    print(inf[(i+s)%n])
w,h,x,y,z = map(int,raw_input().split())

if w-r > x and h-r > y and x > 0 and y > 0:
    print "Yes"
else:
    print "No"

### FIXED CODE ###

w,h,x,y,r = map(int,raw_input().split())
if w-r >= x and h-r >= y and x-r >= 0 and y-r >= 0:
    print "Yes"
else:
    print "No"
from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) > 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
           R.remove(s)
           pair += 1
           
print(pair)

### FIXED CODE ###

from operator import itemgetter

n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = sorted([list(map(int, input().split())) for _ in range(n)], key = itemgetter(0))
pair = 0

for b in B:
   L = [r for r in R if r[0] < b[0] and r[1]<b[1]]
   if len(L) != 0:
       s = L[0]
       for l in L:
           if s[1] < l[1]:
               s = l
       R.remove(s)
       pair += 1
           
print(pair)
import queue
N,M = map(int,input().split())
tree = [[] for _ in range(M+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append([b,a])
    tree[b].append([a,b])

que = queue.Queue()
que.put(1)
result = [-1]*(N+1)
for i in range(len(tree[1])):
    tree[1][i][1] = 1
while(True):
    if que.empty():
        break
    nex = que.get()
    
    for i in tree[nex]:
        if result[i[0]] == -1 or result[i[1]] != -1:
            result[i[0]] = nex
            que.put(i[0])


result = result[2:]
if result.count(-1) != 0:
    print("No")
else :
    print("Yes")
    for i in result:
        print(i)

        

### FIXED CODE ###

import queue
N,M = map(int,input().split())
tree = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    tree[a].append(b)
    tree[b].append(a)

que = queue.Queue()
que.put(1)
result = [-1]*(N+1)
result[1] = 0
while(True):
    if que.empty():
        break
    start = que.get()
    for i in tree[start]:
        if result[i] == -1:
            result[i] = start
            que.put(i)

if -1 in result[2:]:
    print("No")
else:
    print("Yes")
    for i in result[2:]:
        print(i)
a,b,c=map(int,input().split())
if a + b >= c:
  print(b+c)
else:
  print(a+2b)
  
  

### FIXED CODE ###

a,b,c=map(int,input().split())
if a + b >= c :
  print(b+c)
elif a==b==c==0:
  print(0)
else:
  print(a+2*b+1)
S = input()
toppings = S.count(o)
print(700 + toppings*100)


### FIXED CODE ###

S = input()
toppings = S.count("o")
print(700 + toppings*100)
#!/usr/bin/env python3
import sys
INF = float("inf")
import math


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        # 単位元
        self.idelem = 0
        # 比較関数
        self.func = max

        self.N0 = 2**(math.ceil(math.log2(N)))
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s

    def __str__(self):
        return str(self.tree[self.N0-1:-1])


def solve(N: int, h: "List[int]", a: "List[int]"):

    seg = SegmentTree(N+1)

    for i in range(N):
        temp = a[i] + seg.query(0, h[i])
        seg.update(h[i], temp)
    print(seg.query(0, N+1))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h, a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
INF = float("inf")
import math


class SegmentTree(object):
    # セグメント木

    def __init__(self, N):
        # 単位元
        self.idelem = 0
        # 比較関数
        self.func = max

        self.N0 = 1
        while self.N0 < N:
            self.N0 *= 2
        self.tree = [self.idelem]*(2*self.N0)

    def update(self, k, x):
        k += self.N0-1
        self.tree[k] = x
        while k > 1:
            k = (k-1)//2
            self.tree[k] = self.func(self.tree[2*k+1], self.tree[2*k+2])

    def query(self, l, r):
        l += self.N0-1
        r += self.N0-1
        s = self.idelem
        while l < r:
            if r % 2 == 0:
                r -= 1
                s = self.func(s, self.tree[r])

            if l % 2 == 0:
                s = self.func(s, self.tree[l])
                l += 1
            l //= 2
            r //= 2
        return s

    def __str__(self):
        return str(self.tree[self.N0-1:-1])


def solve(N: int, h: "List[int]", a: "List[int]"):

    seg = SegmentTree(N+1)

    for i in range(N):
        temp = a[i] + seg.query(0, h[i])
        seg.update(h[i], temp)
    print(seg.query(0, N+1))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h, a)


if __name__ == '__main__':
    main()
https://shirahonoyu.com/#character

### FIXED CODE ###

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

found = False
for a in range(n+1):
    for b in range(n-a+1):
        c = n - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if total == y:
            found = True
            print(a, b, c)
            break
    if found:
        break

if not found:
    print('-1 -1 -1')
n = int(input())
a = list(map(int, input().split()))
submap = {}
for each in a:
  try:
    submap[i] += 1
  except:
    submap[i] = 1
for i in range(1, n+1):
  try:
    print(submap[i])
  except:
    print(0)

### FIXED CODE ###


n = int(input())
a = list(map(int, input().split()))
submap = {}
for each in a:
  try:
    submap[each] += 1
  except:
    submap[each] = 1
for i in range(1, n+1):
  try:
    print(submap[i])
  except:
    print(0)
def miller_rabin(n, k=100):
    import random
    if n == 2:
        return True
    if n == 1 or n & 1 == 0:
        return False
    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1
    for _ in range(k):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)
        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1
        if y != n - 1 and t & 1 == 0:
            return False
    return True
def main():
  x=int(input())
  for i in range(x,1000000):
    if miller_rabin(i):
      print(i)
      return
main()

### FIXED CODE ###

print("".join(input().split()[::-1]))
import math
from functools import reduce
def gcdlist(numbers):
    return reduce(math.gcd,numbers)
n=int(input())
a=list(map(int,input().split()))
print(gcdlist(a))

### FIXED CODE ###

import fractions
from functools import reduce
def gcdlist(numbers):
    return reduce(fractions.gcd,numbers)
n=int(input())
a=list(map(int,input().split()))
print(gcdlist(a))
import sys
import math
input = sys.stdin.readline

s = it(input())
x_1 = 2
y_2 = math.ceil(s/2)
if s%2 == 0:
    x_2 = 0
    y_1 = 0
else:
    x_2 = 1
    y_1 = 1
x_3 = 0
y_3 = 0
print(x_1, y_1, x_2, y_2, x_3, y_3)

### FIXED CODE ###

import sys
import math
input = sys.stdin.readline

s = int(input())
if s == 10**18:
    print(0, 0, 0, 10**9, 10**9, 0)
    sys.exit()
t = math.floor(math.sqrt(s))
if t*(t+1) < s:
    x1 = t+1
    y2 = t+1
else:
    x1 = t
    y2 = t+1
x2 = 1
y1 = x1*y2 - s

print(0, 0, x1, y1, x2, y2)
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 19:52:57 2019

@author: Yamazaki Kenichi
"""

N,M = map(int,input().split())
bb = [list(map(int,(input().split()))) for i in range(M)]

def comb2(N):
    return N*(N-1)//2
ans = [int(comb2(N))]
A = [-1 for i in range(N+1)]
B = [[] for i in range(N+1)]
T=[[-1,-1,-1] for i in range(N+1)]
def p(u):
    return T[u][0]
def ch(u):
    return T[u][1]
def root(u):
    if p(u) == -1:
        return u
    else:
        return root(p(u))
def leef(u):
    if ch(u) == -1:
        return u
    else:
        return leef(ch(u))
def pn(u):
    if p(u) == -1:
        return 0
    else:
        return pn(p(u))+1
def cn(u):
    if ch(u) == -1:
        return 0
    else:
        return cn(ch(u)) +1
def al(u):
    return T[u][2]
k = 0
bb.reverse()
for c in bb:
    if ans[-1] == 0:
        ans.append(0)
        continue
    if al(c[0]) == -1 and al(c[1]) ==-1:
        T[c[0]][2],T[c[1]][2] = 1,1
        T[c[0]][1] = c[1]
        T[c[1]][0] = c[0]
        ans.append(ans[-1]-1)
    elif al(c[0]) != -1 and al(c[1]) ==-1:
        T[c[1]][2] = 1
        res = pn(c[0])+1+cn(c[0])
        tmp = leef(c[0])
        T[tmp][1] = c[1]
        T[c[1]][0] = tmp
        ans.append(ans[-1]-res)
    elif al(c[0]) == -1 and al(c[1]) !=-1:
        T[c[0]][2] = 1
        res = pn(c[1])+1+cn(c[1])
        tmp = leef(c[1])
        T[tmp][1] = c[0]
        T[c[0]][0] = tmp
        ans.append(ans[-1]-res)
    elif root(c[0]) != root(c[1]):
        res = (pn(c[0])+1+cn(c[0])) * (pn(c[1])+1+cn(c[1]))
        tmp = leef(c[0])
        tmp2 = root(c[1])
        T[tmp][1] = tmp2
        T[tmp2][0] = tmp
        ans.append(ans[-1]-res)
    else:
        ans.append(ans[-1])
        continue
#    print(pn(c[0]),cn(c[0]),pn(c[1]),cn(c[1]))
#    print(T)
for i in range(M):
    print(ans[-i-2])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 14:59:59 2019

@author: Yamazaki Kenichi
"""

N,M = map(int,input().split())
bb = [list(map(int,(input().split()))) for i in range(M)]

def comb2(N):
    return N*(N-1)//2
ans = [int(comb2(N))]
bb.reverse()

T = [[-1,1] for i in range(N+1)]
def p(u):
    return T[u][0]
def findset(u):
    if p(u) == -1:
        return u
    else:
        T[u][0] = findset(p(u))
        return T[u][0]
def unite(u,v):
    if findset(u) == findset(v):
        return    
    if T[findset(u)][1] >= T[findset(v)][1]:
        T[findset(u)][1] += T[findset(v)][1]
        T[findset(v)][0] = findset(u)
    else:
        T[findset(v)][1] += T[findset(u)][1]
        T[findset(u)][0] = findset(v)
        
for c in bb:
    if findset(c[0]) != findset(c[1]):
        res1 = T[findset(c[0])][1]
        res2 = T[findset(c[1])][1]
        unite(c[0],c[1])
        ans.append(ans[-1]-res1*res2)
    else:
        ans.append(ans[-1])
for i in range(M):
    print(ans[-i-2])
s = input()
for i in s:
  if s.counter(i) != 2:
    print('No')
    exit()
print('Yes')

### FIXED CODE ###

s = input()
for i in s:
  if s.count(i) != 2:
    print('No')
    exit()
print('Yes')
import math
a=int(input())
b=int(input())

c=a*b
d=math.sqrt(a*a+b*b)
print(str(c)+" "+str(d))


### FIXED CODE ###

l = input().split()

a=int(l[0])*int(l[1])
b=2*int(l[0])+2*int(l[1])

print(str(a)+" "+str(b))
input = []
array = []
input = [int(input()) for i in range(6)]
array = input[:5]
k = input[5] 
size = len(array)
for i in range(size):
  if (i < 4):
    if (array[size - i - 1] - array[0] > k):
      print(':(')
      break
  if (i < 3):
    if (array[size - i - 1] - array[1] > k):
      print(':(')
      break
  if (i < 2):
    if (array[size - i - 1] - array[2] > k):
      print(':(')
      break
  if (i < 1):
    if (array[size - i - 1] - array[3] > k):
      print(':(')
      break
  if (i == 4):
    print('Yay')

### FIXED CODE ###

array1 = [int(input()) for i in range(6)]
array2 = array1[:5]
k = array1[5] 
 
for i in range(5):
  if (i < 4 and array2[4 - i] - array2[0] > k):
    print(':(')
    break
  if (i < 3 and array2[4 - i] - array2[1] > k):
    print(':(')
    break
  if (i < 2 and array2[4 - i] - array2[2] > k):
    print(':(')
    break
  if (i < 1 and array2[4 - i] - array2[3] > k):
    print(':(')
    break
  if (i == 4):
    print('Yay!')
S=str(input())
T=str(input())

count=0
for i in range(3):
    if S[i]==S[j]:
        count+=1

print(count)

### FIXED CODE ###

S=str(input())
T=str(input())

count=0
for i in range(3):
    if S[i]==T[i]:
        count+=1

print(count)
array = input().split()
if (int(array[0] > int(array[1] > int(array[2]):
    print("Yes")
else:
    print("No")


### FIXED CODE ###

#
# 2b
#

def main():
    a, b, c = map(int, input().split())
    if a < b < c:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()
S = list(input())
K = int(input())
S = [int(i) for i in S]
if K == 1:
    print(S[0])
else:
    print(S[1])

### FIXED CODE ###

import sys
S = list(input())
K = int(input())
S = [int(i) for i in S]
count = 0
for i in range(K):
    if S[i] is not 1:
        print(S[i])
        sys.exit()
    else:
        count+= 1
if count == K:
    print(1)
def main():
    a = input()
    l = list(map(int,input().split()))
    ans = check(int(a),l)
    print(ans)

def check(a,l):
    num = 0
    for i in range(a):
        for j in range(i):
            if l[i] > l[j]:
                break
        else:
            num = num + 1
    return num

main()

### FIXED CODE ###

def main():
  a,b = map(int,input().split())
  ans = check(a,b)
  print(ans)
  
def check(n,m):
  if n == m:
    return "Yes"
  else:
    return "No"
main()
n = int(input())
t = map(int, input())
bottle_neck = min(t)
ti = int(n/bottle_neck)
if bottle_neck * ti > n:
    ti=1
else:
    ti+=1
print(ti+4)



### FIXED CODE ###

import math
n = int(input())
t=[]
for i in range(5):
    t.append(int(input()))
bottle_neck = min(t)
ti = math.ceil(n/bottle_neck)
print(ti + 4)
a=list.input()

if a[2]==a[3] and a[4]==a[5]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

s=input()

a=s[2]
b=s[3]
c=s[4]
d=s[5]

if a==b and c==d:
  print("Yes")
else :
  print("No")
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;

int main()
{
    int n;
    cin>>n;
    ll ans = 1ll;

    bool flag = true;
    REP(i,n) {
        ll nans = ans;
        ll a;
        cin>>a;
        nans *= a;

        if (nans > (ll)1e18 || nans < ans) {
            flag = false;
        }
        ans = nans;
    }
    cout<<(flag || ans == 0 ? ans : -1)<<endl;

    return 0;
}


### FIXED CODE ###

from sys import stdin
input = stdin.readline

n = int(input())
a = list(map(int, input().split()))
ans = 1
flag = True

for ta in a:
    ans *= ta
    if (ans > 10 ** 18):
        flag = False
        ans = 1

if (flag or ans == 0):
    print(ans)
else:
    print(-1)
import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
unique, counts = np.unique(a, return_counts=True) 
counts = np.array(counts).astype("int64")
counts = counts * (counts - 1) // 2
print(count + np.sum(counts))

### FIXED CODE ###

import numpy as np
(n, m) = list(map(int, input().split()))
a = np.array(list(map(int, input().split()))).astype("int64") 
a = np.cumsum(a)
a %= m
count = np.sum(a == 0)
a.sort()
tc = 1
for i in range(1, n):
    if a[i - 1] == a[i]:
        tc += 1
    else:
        count += tc * (tc - 1) // 2
        tc = 1
else:
    count += tc * (tc - 1) // 2
print(count)