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

import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
INF=np.inf
#print(S)
def bfs(sx,sy,gx,gy):
  #dx, dy 四方向に対応したベクトルのリスト
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  #P: (x, y)のキュー
  P=[]
  #d: スタートから各点までの最小距離の配列
  d=np.ones((H, W))*INF
  #スタート地点をキューに入れ、その点の距離を0にする
  P.append([sx, sy])
  d[sx,sy]=0
    
  #キューがからになるまでループ
  while len(P)>0:
    #キューの先頭を取り出す
    p=P.pop(0)
    #取り出してきた状態がゴールなら探索をやめる
    if (p[0]==gx and p[1]==gy):
      break
        
    #移動四方向をループ
    for i in range(4):
      #移動した後の点をnx, nyとする
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
            
      #移動が可能かどうかの判定とすでに訪れたことがあるかどうかの判定（d[nx, ny]!=INFならおtpずれたことがある）
      if 0<=nx and nx<H and 0<=ny and ny<W and S[nx, ny]!="#" and d[nx, ny]==INF:
        #移動できるならキューに入れ、その点の距離をpからの距離＋１で確定する
        P.append([nx, ny])
        d[nx, ny]=d[p[0], p[1]]+1
  #print(d)
  if d[gx,gy]!=INF:
    result=d[gx, gy]
  else:
    result=0
  return result
ans=0
for sx in range(H):
  for sy in range(W):
    for gx in range(H):
      for gy in range(W):
        if S[sx,sy]=="#" or S[gx,gy]=="#":
          continue
        res=bfs(sx,sy,gx,gy)
        ans=max(ans, res)
print(int(ans))

### FIXED CODE ###

import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
INF=-1
#print(S)
def bfs(sx,sy):
  #dx, dy 四方向に対応したベクトルのリスト
  dx=[1,0,-1,0]
  dy=[0,1,0,-1]
  #P: (x, y)のキュー
  P=[]
  #d: スタートから各点までの最小距離の配列
  d=np.ones((H, W))*INF
  #スタート地点をキューに入れ、その点の距離を0にする
  P.append([sx, sy])
  d[sx,sy]=0
    
  #キューがからになるまでループ
  while len(P)>0:
    #キューの先頭を取り出す
    p=P.pop(0)
    #取り出してきた状態がゴールなら探索をやめる
    """
    if (p[0]==gx and p[1]==gy):
      break
    """
        
    #移動四方向をループ
    for i in range(4):
      #移動した後の点をnx, nyとする
      nx=p[0]+dx[i]
      ny=p[1]+dy[i]
            
      #移動が可能かどうかの判定とすでに訪れたことがあるかどうかの判定（d[nx, ny]!=INFならおtpずれたことがある）
      if 0<=nx and nx<H and 0<=ny and ny<W and S[nx, ny]!="#" and d[nx, ny]==INF:
        #移動できるならキューに入れ、その点の距離をpからの距離＋１で確定する
        P.append([nx, ny])
        d[nx, ny]=d[p[0], p[1]]+1
  """
  #print(d)
  if d[gx,gy]!=INF:
    result=d[gx, gy]
  else:
    result=0
  """
  result=d.max()
  return result
ans=0
Tlen=H*W
for sx in range(H):
  for sy in range(W):
    if S[sx,sy]=="#":
      continue
    res=bfs(sx,sy)
    ans=max(ans, res)
"""
for i in range(Tlen):
  for j in range(i,Tlen):
    sx,sy=i%H, int(i//H)
    gx,gy=j%H, int(j//H)
    
    if S[sx,sy]=="#" or S[gx,gy]=="#":
      continue
    res=bfs(sx,sy,gx,gy)
    ans=max(ans, res)
"""
"""
for sx in range(H):
  for sy in range(W):
    for gx in range(H):
      for gy in range(W):
        if S[sx,sy]=="#" or S[gx,gy]=="#":
          continue
        res=bfs(sx,sy,gx,gy)
        ans=max(ans, res)
"""
print(int(ans))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    from itertools import groupby, product
    wv_list = [list(g) for k, g in groupby(sorted(zip(w, v), key=lambda x:(x[0],-x[1])), key=lambda x:x[0])]
    base_w = wv_list[0][0][0]
    acc_wv = [[0] * (N+1) for _ in range(4)]
    for wv in wv_list:
        i = wv[0][0] - base_w
        for j, (_, v) in enumerate(wv):
            acc_wv[i][j+1] = acc_wv[i][j] + v
    ans = 0
    for i, j, k, l in product(range(N+1), repeat=4):
        if i * base_w + j * (base_w + 1) + k * (base_w + 2)+ l * (base_w + 3) > W:
            continue
        ans = max(ans, acc_wv[0][i] + acc_wv[1][j] + acc_wv[2][k] + acc_wv[3][l])
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    print(solve(N, W, w, v))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    from itertools import groupby, product
    base_w = w[0]
    v_list = [[] for _ in range(4)]
    for ww, vv in zip(w, v):
        v_list[ww-base_w].append(vv)
    v_list = [sorted(vv, reverse=True) for vv in v_list]
    acc_v = [[0] for _ in range(4)]
    for i, vv in enumerate(v_list):
        for vvv in vv:
            acc_v[i].append(acc_v[i][-1] + vvv)
    ans = 0
    for i, j, k, l in product(*[range(len(a)) for a in acc_v]):
        if i * base_w + j * (base_w + 1) + k * (base_w + 2)+ l * (base_w + 3) > W:
            continue
        ans = max(ans, acc_v[0][i] + acc_v[1][j] + acc_v[2][k] + acc_v[3][l])
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
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
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    print(solve(N, W, w, v))

def test():
    import doctest
    doctest.testmod()

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

def main():
    t = input()
    if t == "1":
        print(1)
        exit(0)
    li = [int(v) for v in input().split(' ')]
    s_li = sorted(li)
    count = 0
    c1 = 0
    for v in range(s_li[0] - 1, s_li[-1] + 1, 2):
        t_c = 0
        c1 = s_li.count(v - 1)
        c2 = s_li.count(v)
        c3 = s_li.count(v + 1)
        c4 = s_li.count(v + 2)

        t_c = c1 + c2 + c3
        t_c2 = c2 + c3 + c4
        if t_c > count:
            count = t_c
        if t_c2 > count:
            count = t_c2
        if c1 != 0:
            s_li = s_li[s_li.index(v - 1):]
        if count > len(s_li):
            break
    print(count)



if __name__ == '__main__':
    main()

### FIXED CODE ###

n = int(input())
cnt = [0] * 100002
a = list(map(int, input().split()))
for v in a:
    cnt[v] += 1
    cnt[v+1] += 1
    cnt[v+2] += 1
    
print(max(cnt))
### BUGGY CODE ###

import collections


N = int(input())

S = [input() for i in range(N)]

count = collections.Counter(S)
result = []

max_k, mx = max(count.items(), key=lambda x : x[1])

result.append(max_k)
del count[max_k]
for i in range(len(count)):
    max_k, max_v = max(count.items(), key=lambda x : x[1])
    if max_v == mx:
        result.append(max_k)
        del count[max_k]
    else:
        break

for r in sorted(result):
    print(r)

### FIXED CODE ###

import collections


N = int(input())

S = [input() for i in range(N)]

count = collections.Counter(S)


mx = max(count.values())

result = [key for key, val in count.items() if val == mx]
print("\n".join(sorted(result)))
### BUGGY CODE ###

N, M = list(map(int, input().split()))
gate = [True for i in range(N+1)]

for i in range(M):
    r, m = list(map(int, input().split()))
    gate[:r] = [False] * r
    gate[m+1:] = [False] * (N-m+1)

print(sum(gate))

### FIXED CODE ###

N, M = list(map(int, input().split()))
l = 1
r = N

for i in range(M):
    L, R = list(map(int, input().split()))
    l = max(l, L)
    r = min(r, R)

print(max(0, r-l+1))
### BUGGY CODE ###

import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
import numpy as np
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()

def update(a):
    b = [0]*(n+1)
    for i in range(n):
        b[max(i-a[i], 0)] +=1
        if i+a[i] <n:
            b[i+a[i]+1] -=1
    for i in range(1,n):
        b[i] += b[i-1]
    return b[:n]
end = [n]*n

for i in range(k):
    if a == end:
        break
    a = update(a)
for i in range(n):
    print(str(int(a[i]))+" ",end = "" )

### FIXED CODE ###

import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
a = LIST()


end = [n]*n

for i in range(min(k, 41)):
    b = [0]*(n+1)
    for j in range(n):
        b[max(j-a[j], 0)] +=1
        if j+a[j] <n:
            b[j+a[j]+1] -=1
    for j in range(1,n):
        b[j] += b[j-1]
    a = b[:n]

for i in range(n):
    print(str(int(a[i]))+" ",end = "" )
### BUGGY CODE ###

N=int(input())
a=4/N
h_st=int(N*(1/4))
h_st=1
for h in range(h_st,3501):
    H=1/h
    for n in range(h,3501):
        flag=0
        if a-H-1/n-1/n<=0 and a-H-1/n-1/3500>=0:

            st,end=h,3500
            for w in [st,end]:
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    break
            while st!=end:
                #print(h,n,st,end)
                w=int((st+end)/2)
                if end-st==1:
                    end=w
                    st=w
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
                elif B>0:
                    end=w
                else:
                    st=w

        if flag:
            break
    if flag:
        break

print(h,n,w)


### FIXED CODE ###

N=int(input())
a=4/N
h_st=max(int(N*(1/4))-1,1)
#h_st=1
for h in range(h_st,3501):
    H=1/h
    for n in range(h,3501):
        flag=0
        if 4*h*n*n-(n*n+h*n+h*n)*N<=0 and 4*h*n*3500-(n*3500+h*3500+h*n)*N>=0:

            st,end=n,3500
            for w in [st,end]:
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
            while st!=end:
                #print(h,n,st,end)
                w=int((st+end)/2)
                if end-st==1:
                    end=w
                    st=w
                B=4*h*n*w-(n*w+h*w+h*n)*N
                if B==0:
                    flag=1
                    break
                elif B>0:
                    end=w
                else:
                    st=w

        if flag:
            break
    if flag:
        break

print(h,n,w)
### BUGGY CODE ###

import sys
import heapq


def can_eat_with_score(key):
    now_K = K
    for i, now_score in enumerate(score):
        if key < now_score:
            now_K -= (now_score-key+F[i]-1) // F[i]
            if now_K < 0:
                return False
    return True


input = sys.stdin.readline

priority_que = []
N, K = map(int, input().split())
A = sorted(map(int, input().strip().split()))
F = sorted(map(int, input().strip().split()))[::-1]
score = [A[i]*F[i] for i in range(N)]
if sum(A) <= K:
    print("0")
    exit()


left = -1
right = max(score)
while right - left > 1:
    mid = (left+right) // 2
    can_eat = can_eat_with_score(mid)
    # print(mid, can_eat)
    if can_eat:
        right = mid
    else:
        left = mid
print(left+1)


### FIXED CODE ###

import sys
import heapq


def can_eat_with_score(key):
    now_K = K
    for i, now_score in enumerate(score):
        if key < now_score:
            now_K -= (now_score-key+F[i]-1) // F[i]
            if now_K < 0:
                return False
    return True


input = sys.stdin.readline

priority_que = []
N, K = map(int, input().split())
A = sorted(map(int, input().strip().split()))
F = sorted(map(int, input().strip().split()))[::-1]
score = [A[i]*F[i] for i in range(N)]
if sum(A) <= K:
    print("0")
    exit()


left = -1
right = max(score)
while right - left > 1:
    mid = (left+right) // 2
    can_eat = can_eat_with_score(mid)
    # print(mid, can_eat)
    if can_eat:
        right = mid
    else:
        left = mid
print(left+1)
### BUGGY CODE ###

import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return  sys.stdin.readline
    else:
        return fileobject.readline

def calc(field, H, W):
    ret =  [[0] * (W + 1) for i in range(H + 1)]
    for i in range(H):
        cnt = 0
        cnt_list = []
        for j in range(W + 1):
            if field[i][j] == "#":
                cnt_list.append(cnt)
                cnt = 0
            else:
                cnt += 1
        k = 0
        for j in range(W + 1):
            if field[i][j] == ".":
                ret[i][j] = cnt_list[k]
            else:
                ret[i][j] = 0
                k+=1
    return ret





def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = [["#"] * (W + 1) for i in range(H + 1)]
    field_T = [["#"] * (H + 1) for i in range(W + 1)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            field[i][j] = input_raw[0][j]
            field_T[j][i] = field[i][j]
    ret1 = calc(field, H, W)
    ret2 = calc(field_T, W, H)
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, ret1[i][j] + ret2[j][i] - 1)
    print ans

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return  sys.stdin.readline
    else:
        return fileobject.readline

def calc(field, H, W):
    ret =  [[0] * (W + 1) for i in range(H + 1)]
    for i in range(H):
        cnt = 0
        cnt_list = []
        for j in range(W + 1):
            if field[i][j] == "#":
                cnt_list.append(cnt)
                cnt = 0
            else:
                cnt += 1
        k = 0
        for j in range(W + 1):
            if field[i][j] == ".":
                ret[i][j] = cnt_list[k]
            else:
                ret[i][j] = 0
                k+=1
    return ret





def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = [["#"] * (W + 1) for i in range(H + 1)]
    field_T = [["#"] * (H + 1) for i in range(W + 1)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            field[i][j] = input_raw[0][j]
            field_T[j][i] = field[i][j]
    ret1 = calc(field, H, W)
    ret2 = calc(field_T, W, H)
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, ret1[i][j] + ret2[j][i] - 1)
    print ans

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

import sys

n,k = map(int,input().split())
x = n
min = sys.maxsize

while True:
    if x%k == 0:
        min = 0
        break

    x = abs(x-k)
    if x == min :break
    elif x < min : min = x

print(min)


### FIXED CODE ###

import sys

n,k = map(int,input().split())
x = k+(n%k)
min = sys.maxsize

while True:
    if x%k == 0:
        min = 0
        break

    x = abs(x-k)
    if x == min :break
    elif x < min : min = x

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

import heapq
import sys
input=sys.stdin.readline
from copy import deepcopy
from collections import defaultdict
h, w, d = map(int, input().split())
p = dict()
D = defaultdict(list)
for i in range(h):
    for j, x in enumerate(map(int, input().split())):
        p[x] = (x, i, j)
        D[x%d].append(p[x])

for key in D.keys():
    D[key].sort()

q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    ans = 0
    v = D[a%d]
    for x, i, j in v:
        if x == a:
            s, t = i, j
        if a < x <= b:
            ans += abs(s-i)+abs(t-j)
            s, t = i, j
            if x == b:
                break
    print(ans)


### FIXED CODE ###

import sys
input=sys.stdin.readline
h, w, d = map(int, input().split())
p = dict()

for i in range(h):
    for j, x in enumerate(map(int, input().split())):
        p[x] = (i, j)

dp = [0]*(h*w+1)
for i in range(h*w+1):
    if d < i:
        dp[i] = dp[i-d] + abs(p[i][0]-p[i-d][0])+abs(p[i][1]-p[i-d][1])

q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    ans = dp[b]-dp[a]
    print(ans)
### BUGGY CODE ###

n, m = list(map(int, input().split()))
alist = list(map(int, input().split()))
for i in range(m) :
    b, c = list(map(int, input().split()))
    alist.sort()
    for j in range(b) :
        if alist[j] < c :
            alist[j] = c
print(sum(alist))

### FIXED CODE ###

from operator import itemgetter

n, m = map(int, input().split())
aa = list(map(int, input().split()))
bcbc = [list(map(int, input().split())) for _ in range(m)]
bcbc.extend([[1, a] for a in aa])
bcbc.sort(key=itemgetter(1), reverse=True)

count = 0
s = 0
for b, c in bcbc :
    if count + b >= n :
        b = n - count
    count += b
    s += b*c
    if count == n :
        break
print(s)
### BUGGY CODE ###

n, m = map(int,input().split())
cards = [1 for _ in range(n)]
for _ in range(m):
    l,r= map(lambda x: int(x) - 1,input().split())
    if 0 < l:    
        cards[:l] = [0 for _ in range(l)]
    if r < n-1:
        cards[r+1:] = [0 for _ in range(n-1 -r)]
print(sum(cards))

### FIXED CODE ###

n, m = map(int,input().split())
cards = [1 for _ in range(n)]
L = 0
R = n-1
for _ in range(m):
    l,r= map(lambda x: int(x) - 1,input().split())
    L = max(L,l)
    R = min(R,r)
    
print(max(0,R-L+1))
### BUGGY CODE ###

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

l=[]
ans=0

for i in a:
    if not i in l:
        l.append(i)

for i in l:
    if a.count(i)<i:
        ans+=a.count(i)
    elif a.count(i)>i:
        ans+=a.count(i)-i
        
print(ans)

### FIXED CODE ###

import collections
n=int(input())
a=[int(i) for i in input().split()]


ans=0

l=collections.Counter(a)

for i,j in l.most_common():
    if int(i)<j:
        ans+=j-int(i)
    elif int(i)>j:
        ans+=j
        
print(ans)
### BUGGY CODE ###

n=int(input())
box=[]
count=0
for i in range(n):
    tmp=str(input())
    if tmp not in box:
        count+=1
        box.append(tmp)
        
print(count)

### FIXED CODE ###

import collections
n=int(input())
box=[]
for i in range(n):
    tmp=str(input())
    box.append(tmp)
l=len(collections.Counter(box))
print(l)
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect


def isincluded(array, value):
    i = bisect.bisect_left(array, value)
    if i != len(array) and array[i] == value:
        return True
    else:
        return False


def process(commands):
    d = []
    for c in commands:
        cpair = c.split()
        if cpair[0] == "insert":
            bisect.insort_left(d, cpair[1])
        elif cpair[0] == "find":
            r = "yes" if isincluded(d, cpair[1]) else "no"
            print(r)


def main():
    n = int(input())
    commands = [input() for i in range(n)]
    process(commands)


if __name__ == "__main__":
    main()

### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def process(commands):
    d = set()
    for c in commands:
        cpair = c.split()
        if cpair[0] == "insert":
            d.add(cpair[1])
        elif cpair[0] == "find":
            r = "yes" if cpair[1] in d else "no"
            print(r)


def main():
    n = int(input())
    commands = [input() for i in range(n)]
    process(commands)


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

import collections
import itertools

X = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = prime_factorize(X)
L = len(a)

for i in range(L+1):
    d = itertools.combinations(a,i)
    Y = 1
    if i != 0:
        for j in d:
            Y *= j[0]
    A = -X
    while A < X+1:
        if A ** 5 - (A-Y)**5 == X:
            print(A,A-Y)
            exit()
        else:
            A += 1

### FIXED CODE ###

X = int(input())

for i in range(-200,200):
    for j in range(-200,200):
        if i ** 5 - j ** 5 == X:
            print(i,j)
            exit()
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
R = [N]*N
def update(A):
    b = [0]*N
 
    for i,a in enumerate(A):
        l = max(0,i-a)
        r = min(N-1,i+a)
 
        b[l] += 1
        if r+1 < N:
            b[r+1] -= 1
    
    res = []
    s = 0
    for i in b:
        s += i
        res.append(s)
    return res
 
for _ in range(K):
    A = update(A)
    if A == R:
      break
print(*A)

### FIXED CODE ###

"""
https://atcoder.jp/contests/tokiomarine2020/submissions/14229099
"""
N,K = map(int,input().split())
A = list(map(int,input().split()))

def update(A):
    b = [0]*N

    for i,a in enumerate(A):
        l = max(0,i-a)
        r = min(N-1,i+a)

        b[l] += 1
        if r+1 < N:
            b[r+1] -= 1
    
    res = []
    s = 0
    for i in b:
        s += i
        res.append(s)
    return res

for _ in range(min(K,75)):
    A = update(A)

print(*A)
### BUGGY CODE ###

import numpy as np
n = int(input())
MIN = n
x = 1
while np.sqrt(n) >= x:
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
    x += 1
print(int(MIN))

### FIXED CODE ###

import numpy as np
n = int(input())
MIN = n
for x in range(1,int(np.sqrt(n)+1)):
    if n % x == 0:
        MIN = min([MIN,x + n/x - 2])
print(int(MIN))
### BUGGY CODE ###

N = int(input())
li = list(map(int, input().split()))
ans = "Yes"
for i in range(1, N):
    if li[i] - li[i-1] < -1:
        ans = "No"
        break
    elif li[i] - li[i-1] == -1:
        if i != 1:
            tmp = i -2
            while tmp >= 0:
                if li[i] - li[tmp] <= -2:
                    ans = "No"
                    break
                tmp -= 1
print(ans)

### FIXED CODE ###

N = int(input())
li = list(map(int, input().split()))
ans = "Yes"
count = N - 1
while count >= 1:
    if li[count] - li[count-1] >= 0:
        pass
    elif li[count] - li[count-1] == -1:
        li[count-1] -= 1
    else:
        ans = "No"
        break
    count -= 1
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
s=str(input())
s=list(s)
for i in range(0,q):
  l,r=map(int,input().split())
  temp=s[l-1:r]
  temp="".join(temp)
  print(temp.count("AC"))

### FIXED CODE ###

n,q=map(int,input().split())
s=str(input())
a=[0]*n
s=list(s)
for i in range(1,n):
  temp=0
  if s[i]=="C" and s[i-1]=="A":
    temp=1
  a[i]=a[i-1]+temp
for i in range(0,q):
  l,r=map(int,input().split())
  print(a[r-1]-a[l-1])
### BUGGY CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = map(int, args[1].split())

    ret = 1
    for a in A:
        if 10**18 < ret*a:
            ret = -1
        else:
            ret *= a

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    A = list(map(int, args[1].split()))
    A.sort()

    ret = 1
    for a in A:
        if 10**18 < ret*a:
            ret = -1
            break
        else:
            ret *= a

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))