Harryxun/stf_run huggingface dataset:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

for y in range(h):
  for x in range(w):
    if s[y][x]=='.':
      cnt=0
      for dy,dx in [[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]:
        ny=y+dy
        nx=x+dx
        if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
          cnt+=1
      s[y][x]=str(cnt)

print(''.join(s))

### FIXED CODE ###

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

for y in range(h):
  for x in range(w):
    if s[y][x]=='.':
      cnt=0
      for dy,dx in [[0,1],[0,-1],[1,0],[-1,0],[1,1],[-1,1],[1,-1],[-1,-1]]:
        ny=y+dy
        nx=x+dx
        if 0<=ny<h and 0<=nx<w and s[ny][nx]=='#':
          cnt+=1
      s[y][x]=str(cnt)

for i in s:
  print(''.join(i))
s=list(input())
if s[3]==s[2] and s[5]==s[4]:
print('Yes')
else:
print('No')

### FIXED CODE ###

s=list(input())
if s[3]==s[2] and s[5]==s[4]:
	print('Yes')
else:
	print('No')
A, B = map(int, input().split())


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


a = make_divisors(A)
b = make_divisors(B)
L = []
for x in a:
    if x in b:
        L.append(x)
L.sort()
L = L[1:]#1を消す

ans = 1
for l in L:
    for i in range(2, l):
        if l % i == 0:
            flag = True
            break
    if flag:
        continue
    ans += 1

print(ans)

### FIXED CODE ###

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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


def is_prime(p):
    if p == 1:
        return False
    for i in range(2, int(p ** 0.5) + 1):
        if p % i == 0:
            return False
    return True


A, B = map(int, input().split())

g = gcd(A, B)
d = make_divisors(g)

ans = 1
for i in d:
    if is_prime(i):
        ans += 1

print(ans)
import math

H = int(input())

print(int(math.pow(2, int(math.log2(H)+1))-1))

### FIXED CODE ###

import math

H = int(input())

print(int(math.pow(2, int(math.log2(H)) +1) - 1))
(N,A,B,C)=map(int,input().split())
2
L=[]
3
for i in range(N):
4
  L.append(int(input()))
5
  
6
L_sums=[]
7
costs=[]
8
#bin_is=[]
9
for i in range(2**N+1,2**N+2**N):
10
  bin_i=str(bin(i))[2:]
11
  L_sum=0
12
  cost=-1
13
  for j in range(N):
14
    L_sum+=L[j]*int(bin_i[j+1])
15
    cost+=int(bin_i[j+1])
16
  L_sums.append(L_sum)
17
  costs.append(10*cost)
18
  #bin_is.append(bin_i)
19
​
20
cost_A=[]
21
for i in range(2**N-1):
22
  cost_A.append(costs[i]+abs(L_sums[i]-A))
23
min_cost_A=min(cost_A)
24
min_cost_A_index=cost_A.index(min(cost_A))+1
25
min_cost_A_index_bin=str(bin(min_cost_A_index+2**N))[2:]
26
for i in range(N):
27
  if min_cost_A_index_bin[i+1]=='1':
28
    del(L[i])
29
N=len(L)
30
#-------------------
31
L_sums=[]
32
costs=[]
33
#bin_is=[]
34
for i in range(2**N+1,2**N+2**N):
35
  bin_i=str(bin(i))[2:]
36
  L_sum=0
37
  cost=-1
38
  for j in range(N):
39
    L_sum+=L[j]*int(bin_i[j+1])
40
    cost+=int(bin_i[j+1])
41
  L_sums.append(L_sum)
42
  costs.append(10*cost)
43
  #bin_is.append(bin_i)
44
​
45
cost_B=[]
46
for i in range(2**N-1):
47
  cost_B.append(costs[i]+abs(L_sums[i]-B))
48
min_cost_B=min(cost_B)
49
min_cost_B_index=cost_B.index(min(cost_B))+1
50
min_cost_B_index_bin=str(bin(min_cost_B_index+2**N))[2:]
51
for i in range(N):
52
  if min_cost_B_index_bin[i]=='1':
53
    del(L[i])
54
N=len(L)
55
#-----------------
56
L_sums=[]
57
costs=[]
58
#bin_is=[]
59
for i in range(2**N+1,2**N+2**N):
60
  bin_i=str(bin(i))[2:]
61
  L_sum=0
62
  cost=-1
63
  for j in range(N):
64
    L_sum+=L[j]*int(bin_i[j+1])
65
    cost+=int(bin_i[j+1])
66
  L_sums.append(L_sum)
67
  costs.append(10*cost)
68
  #bin_is.append(bin_i)
69
​
70
cost_C=[]
71
for i in range(2**N-1):
72
  cost_C.append(costs[i]+abs(L_sums[i]-C))
73
min_cost_C=min(cost_C)
74
#min_cost_C_index=cost_C.index(min(cost_C))+1
75
#min_cost_C_index_bin=str(bin(min_cost_C_index))[2:]
76
#for i in range(N):
77
#  if min_cost_C_index_bin[i]=='1':
78
#    del(L[i])
79
#N=len(L)
80
#----------------
81
print(min_cost_A+min_cost_B+min_cost_C)

### FIXED CODE ###

mod = 1000000007
eps = 10**-9


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

    N, A, B, C = map(int, input().split())
    L = []
    for _ in range(N):
        L.append(int(input()))

    ans = 10**9
    for i in range(4 ** N):
        AA = []
        BB = []
        CC = []
        ii = i
        for j in range(N):
            k = ii % 4
            if k == 0:
                AA.append(L[j])
            elif k == 1:
                BB.append(L[j])
            elif k == 2:
                CC.append(L[j])
            ii >>= 2
        if len(AA) * len(BB) * len(CC) == 0:
            continue
        ans_new = abs(sum(AA) - A) + 10*(len(AA)-1) + abs(sum(BB) - B) + 10*(len(BB)-1) + abs(sum(CC) - C) + 10*(len(CC)-1)
        ans = min(ans, ans_new)
    print(ans)


if __name__ == '__main__':
    main()
def search(prev, start, stop):
    global nodes, edges
    for neigh in nodes[start]:
        if neigh==prev:
            continue
        if neigh==stop:
            return [stop,start]
        res=search(start,neigh,stop)
        if res!=False:
            res.append(start)
            return res
    return False

def size(prev, curr):
    su=1
    global nodes, edges
    for neigh in nodes[curr]:
        if neigh==prev:
            continue
        su+=size(curr,neigh)
    return su

n=int(input())
nodes=[[] for i in range (n)]
edges=[]
for i in range(n-1):
    line=input().split()
    a=int(line[0])-1
    b=int(line[1])-1
    edges.append([a,b])
    nodes[b].append(a)
    nodes[a].append(b)

res=search(-1,n-1,0)

fennec=(len(res)-1)//2
snuke=fennec+1
snuke=res[snuke]
fennec=res[fennec]
fennecsize=size(snuke,fennec)
snukesize=size(fennec,snuke)

if fennecsize>snukesize:
    print ("Fennec")
else:
    print("Snuke")


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
def search(prev, start, stop):
    global nodes, edges
    for neigh in nodes[start]:
        if neigh==prev:
            continue
        if neigh==stop:
            return [stop,start]
        res=search(start,neigh,stop)
        if res!=False:
            res.append(start)
            return res
    return False

def size(prev, curr):
    su=1
    global nodes, edges
    for neigh in nodes[curr]:
        if neigh==prev:
            continue
        su+=size(curr,neigh)
    return su

n=int(input())
nodes=[[] for i in range (n)]
edges=[]
for i in range(n-1):
    line=input().split()
    a=int(line[0])-1
    b=int(line[1])-1
    edges.append([a,b])
    nodes[b].append(a)
    nodes[a].append(b)

res=search(-1,n-1,0)

fennec=(len(res)-1)//2
snuke=fennec+1
snuke=res[snuke]
fennec=res[fennec]
fennecsize=size(snuke,fennec)
snukesize=size(fennec,snuke)

if fennecsize>snukesize:
    print ("Fennec")
else:
    print("Snuke")
N = int(input())
d = list(map(int, input().split()))


def combinations(d, out, i, j):
    if (j >= N):
        i += 1
        j = i + 1
        if (i >= N):
            return out
        else:
            if (j >= N):
                return out
    out += d[i] * d[j]

    return combinations(d, out, i, j + 1)


out = combinations(d, 0, 0, 1)

print(out)

### FIXED CODE ###

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

out = 0
for i in range(N):
    for j in range(i + 1, N):
        out += d[i] * d[j]

print(out)
from __future__ import division
import math

def cross(p1,p2):
    a,b,c,d=p1[0],p1[1],p2[0],p2[1]
    t=pow(a,2)+pow(c,2)+pow(d,2)-pow(b,2)-2*a*c
    alpha=4*(pow(b-d,2)+pow(c-a,2))
    beta=4*(t*(b-d)-2*b*pow(c-a,2))
    gamma=pow(t,2)+4*pow(b,2)*pow(c-a,2)-4*pow(c-a,2)
    judge=pow(beta,2)-4*alpha*gamma
    EPS=1e-5
    if judge>EPS:
        y1=(-beta+math.sqrt(judge))/(2*alpha)
        y2=(-beta-math.sqrt(judge))/(2*alpha)
        x1=(2*(b-d)*y1+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        x2=(2*(b-d)*y2+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x1,y1),(x2,y2))
    elif -EPS<=judge<=EPS:
        y=-beta/(2*alpha)
        x=(2*(b-d)*y+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x,y),)
    else:
        return None

def maxNum(P,L):
    ans=1
    for x,y in P:
        cnt=0
        for px,py in L:
            d=math.sqrt(pow(px-x,2)+pow(py-y,2))
            if d<=1:
                cnt+=1
        ans=max(ans,cnt)
    return ans

while True:
    n=input()
    if n==0:break
    L=[map(float,raw_input().split(",")) for i in range(n)]
    P=[]
    for i in range(n-1):
        for j in range(i+1,n):
            points=cross(L[i],L[j])
            if points:
                P.extend(points)
    print maxNum(P,L)

### FIXED CODE ###

from __future__ import division
import math

def cross(p1,p2):
    a,b,c,d=p1[0],p1[1],p2[0],p2[1]
    t=pow(a,2)+pow(c,2)+pow(d,2)-pow(b,2)-2*a*c
    alpha=4*(pow(b-d,2)+pow(c-a,2))
    beta=4*(t*(b-d)-2*b*pow(c-a,2))
    gamma=pow(t,2)+4*pow(b,2)*pow(c-a,2)-4*pow(c-a,2)
    judge=pow(beta,2)-4*alpha*gamma
    EPS=1e-5
    if c==a:
        y=(pow(a,2)+pow(b,2)-pow(c,2)-pow(d,2))/(2*(b-d))
        bd=pow(b-d,2)
        a1=4*bd
        b1=-8*a*bd
        c1=4*a*a*bd+pow(a*a-b*b-c*c-d*d+2*b*d,2)-4*bd
        inroot=pow(b1,2)-4*a1*c1
        if inroot<0:
            return None
        x1=(-b1+math.sqrt(inroot))/(2*a1)
        x2=(-b1-math.sqrt(inroot))/(2*a1)
        return ((x1,y),(x2,y))

    if judge>EPS:
        y1=(-beta+math.sqrt(judge))/(2*alpha)
        y2=(-beta-math.sqrt(judge))/(2*alpha)
        x1=(2*(b-d)*y1+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        x2=(2*(b-d)*y2+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x1,y1),(x2,y2))
    elif -EPS<=judge<=EPS:
        y=-beta/(2*alpha)
        x=(2*(b-d)*y+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x,y),)
    else:
        return None

def maxNum(P,L):
    ans=1
    for x,y in P:
        cnt=0
        for px,py in L:
            d=math.sqrt(pow(px-x,2)+pow(py-y,2))
            if d<=1:
                cnt+=1
        ans=max(ans,cnt)
    return ans

while True:
    n=input()
    if n==0:break
    L=[map(float,raw_input().split(",")) for i in range(n)]
    P=[]
    for i in range(n-1):
        for j in range(i+1,n):
            points=cross(L[i],L[j])
            if points:
                P.extend(points)
    print maxNum(P,L)
s = input()
K = int(input())
# substrings = {}
substrings = []
for i in range(1,6:
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            # substrings[s[j:j+1]] = True
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])

### FIXED CODE ###

s = input()
K = int(input())
# substrings = {}
substrings = []
for i in range(1,6):
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            # substrings[s[j:j+1]] = True
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])
from collections import deque

h, w = map(int, input().split())
Black = deque([])
White = deque([])
Black_grid = [[-1 for _ in range(w)] for _ in range(h)]

for i in range(h):
    a = str(input())
    for j in range(w):
        if a[j] == '#':
            Black.append([i,j])
            Black_grid[j][i] = 0
        else:
            White.append([i,j])

Move = [[-1,0],[1,0],[0,-1],[0,1]]


while Black:
    now = Black.popleft()
    x = now[0]
    y = now[1]
    for move in Move:
        x_next = x + move[0]
        y_next = y + move[1]
        if x_next < 0 or x_next >= w or y_next < 0 or y_next >= h:
            continue
        elif Black_grid[y_next][x_next] >= 0:
            continue
        else:
            Black.append([x_next, y_next])
            Black_grid[y_next][x_next] = Black_grid[y][x] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, Black_grid[i][j])
    
print(ans)

### FIXED CODE ###

from collections import deque

h, w = map(int, input().split())
Black = deque([])
Black_grid = [[-1 for _ in range(w)] for _ in range(h)]

for i in range(h):
    a = str(input())
    for j in range(w):
        if a[j] == '#':
            Black.append([j,i])
            Black_grid[i][j] = 0

Move = [[-1,0],[1,0],[0,-1],[0,1]]

while Black:
    now = Black.popleft()
    x = now[0]
    y = now[1]
    for move in Move:
        x_next = x + move[0]
        y_next = y + move[1]
        if x_next < 0 or x_next >= w or y_next < 0 or y_next >= h:
            continue
        elif Black_grid[y_next][x_next] >= 0:
            continue
        else:
            Black.append([x_next, y_next])
            Black_grid[y_next][x_next] = Black_grid[y][x] + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, Black_grid[i][j])
    
print(ans)
n,q = map(int,input().split())
l = [ [] for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[a-1].append(b-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
def f(p,x):
    ans[p] +=x
    for i in l[p]:
        f(i,x)
for p1 in p:
    f(p1[0]-1,p1[1])
print(" ".join(map(str,ans)))

### FIXED CODE ###

#D解説実装
n,q = map(int,input().split())
l = [0 for i in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    l[b-1] = (a-1)
ans = [0 for _ in range(n)]
p = [list(map(int,input().split())) for i in range(q)]
for p1 in p:
    ans[p1[0]-1] += p1[1]
for i in range(1,n):
    ans[i] += ans[l[i]]
print(" ".join(map(str,ans)))
x=input()
a=[0]
d={}
d[0]=0
for i in range(1,1000):
	a+=[i**5]
	a+=[-i**5]
	d[i**5]=i
	d[-i**5]=-i

a.sort()
for i in range(len(a)):
    if x+a[i] in a:
        print d[a[i]+x],d[a[i]]
        break

### FIXED CODE ###

x=input()
a=[0]
d={}
d[0]=0
for i in range(1,1000):
	a+=[i**5]
	a+=[-i**5]
	d[i**5]=i
	d[-i**5]=-i

a.sort()
for i in range(len(a)):
    if x+a[i] in a:
        print d[a[i]+x],d[a[i]]
        break
import math

num = int(input())

cards = [int(x) for x in input().split()]

res = sum(cards)
res2 = 0

judge = math.inf
if num == 2:
    judge = abs(cards[0]-cards[1])
else:
    for i in cards:
        res -= i
        res2 += i
        div = abs(res - res2)
        judge = div if div < judge else judge

print(judge)

### FIXED CODE ###

num = [int(x) for x in input().split()]
if num[0] %3 == 0 or num[1] % 3 == 0 or (num[0]+num[1]) %3 == 0:
    print("Possible")
else:
    print("Impossible")
N = int(input())
D = [int(i)-1 for i in input().split()]
Dlist = [0]*(max(D)+1)
for d in D:
    Dlist[d] += 1


M = int(input())
T = [int(i)-1 for i in input().split()]
Tlist = [0]*(max(T)+1)
for t in T:
    Tlist[t] += 1
 
flag = True
 
for i in T:
    if Tlist[i] > Dlist[i]:
        flag = False
        break
 
if flag:
    print('YES')
else:
    print('NO')


### FIXED CODE ###

from collections import Counter
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

cD = Counter(D)

for t in T:
    if cD.get(t,0) == 0:
        print('NO')
        exit()
    else:
        cD[t] -= 1

print("YES")
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
for i in range(1, N): A[i] += A[i - 1]
for i in range(1, M): B[i] += B[i - 1]
ans, j = 0, M - 1
for i in range(N):
    if A[i] > K: break
    while B[j] > K - A[i]: j -= 1
    ans = max(ans, i + j + 2)
print(ans)

### FIXED CODE ###

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]
for i in range(N):
	a.append(a[i] + A[i])
for i in range(M):
	b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
	if a[i] > K: break
	while b[j] > K - a[i]: j -= 1
	ans = max(ans, i + j)
print(ans)
a, b = map(input())
print(a+b)

### FIXED CODE ###

a,b = map(str,input().split())
print(b+a)
N = int(input())
L = [int(input().split())]
 
ans = 1
for i in range(N):
    if  L[:i]>L[i]:
        continue
    else:
        ans = ans+1

### FIXED CODE ###

N = int(input())
H = list(map(int,input().split()))
NowHeight = 0
ans = 0
for i in range(N):
  if NowHeight <= H[i]:
    NowHeight = H[i]
    ans += 1
print(ans)
def calc_lcs(X, Y):
    m = len(X)
    n = len(Y)
    c = [[0 for _ in range(n)] for i in range(m)]
    for i in range(m):
        for j in range(n):
            if X[i] == Y[j]:
                c[i][j] = c[i-1][j-1] + 1
            elif c[i-j][j] >= c[j][j-1]:
                c[i][j] = c[i - 1][j]
            else:
                c[i][j] = c[i][j -1]
    max_lcs = 0
    for row in c:
        temp = max(row)
        if temp > max_lcs:
            max_lcs = temp
    return max_lcs


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    # X = 'abcbdab'
    # Y = 'bdcaba'

    for _ in range(num):
        X = input()
        Y = input()

        # ???????????????
        result = calc_lcs(X, Y)

        # ???????????¨???
        print(result)

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_C

最長共通部分列
"""


c = []
def prep_array(X, Y):
    global c
    """ 値が0の2次元配列を用意する。サイズは入力データの最大値を想定して縦横(1000+1)以上必要。 """
    # from array import array
    # c = [array('I', [0] * (len(X)+1)) for _ in range(len(Y)+1)]  #  arrayで用意
    c = [[0]*(len(Y)+2) for _ in range(len(X)+2)] #  リストで用意
    return c


def check_max(array):
    """ 2次元配列の中の最大の値を返す """
    max_lcs = 0
    for row in array:
        temp_max = max(row)
        if temp_max > max_lcs:
            max_lcs = temp_max
    return max_lcs


def calc_lcs4(X, Y, c):
    """
    Y[j]のアクセス方法を変更
    リストの値を一旦変数に保存するように変更
    最長共通部分長を関数内で計算するように変更
    4/5 のテストデータを使用してプロファイリングすると実効時間は 5.6秒
    """
    X = ' ' + X
    Y = ' ' + Y
    m = len(X)
    n = len(Y)
    max_lcs = 0

    pre_row = c[0]
    for i in range(1, m):
        row = c[i]
        XX = X[i]
        for j, YY in enumerate(Y):
            if XX == YY:
                pr_j1 = pre_row[j - 1]
                row[j] = pr_j1 + 1
                if pr_j1+1 > max_lcs:
                   max_lcs = pr_j1 + 1
            else:
                pr_j = pre_row[j]
                r_j1 = row[j-1]
                if pr_j >= r_j1:
                    row[j] = pr_j
                else:
                    row[j] = r_j1
        pre_row = row
    return max_lcs


if __name__ == '__main__':
    # データの入力
    num = int(input())
    #f = open('input.txt')
    #num = int(f.readline())

    for _ in range(num):
        X = input().strip()
        Y = input().strip()

        # 処理の実行
        result = calc_lcs4(X, Y, prep_array(X, Y))

        # 結果の表示
        print(result)
N, K, X, Y = (int(input().split()) for _ in range(4))
t = 0
if N >= K:
    print(X*K + Y*(N-K))
else:
    print(X*N)

### FIXED CODE ###

n,k,x,y=(int(input()) for i in range(4))
if n - k > 0:
  ans = k * x + (n - k) * y
else:
  ans = n * x
print(ans)
X, A = map(int, input().split())

if X < A: print(0)
else: print()10


### FIXED CODE ###

X, A = map(int, input().split())

if X < A: print(0)
else: print(10)
lis=0
S=0
L=0
lis=int(input().split())
S=lis[0]*lis[1]
L=lis[0]*2+lis[1]*2
print(S L)

### FIXED CODE ###

lis=0
S=0
L=0
lis=input().split()
S=int(lis[0])*int(lis[1])
L=int(lis[0])*2+int(lis[1])*2
print(S,L)
import sys
input = sys.stdin.readline
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque

def main(): 
    n,m = map(int,input().split())
    L = [[] for _ in range(n)]
    R = [[] for _ in range(n)]
    for _ in range(m):
        l,r,d = map(int,input().split())
        l -= 1
        r -= 1
        L[l].append((r,d))
        R[r].append((l,d))
    
    visited = [True] * n
    X = [0] * n

    def dfs(i):
        ans = True
        for r in L[i]:
            j, d = r
            if visited[j]:
                X[j] = X[i] + d
                visited[j] = False
                ans = (ans&dfs(j)) 
            else:
                if X[j] - X[i] != d:
                    ans = False
                    break
        for l in R[i]:
            j,d = l
            if visited[j]:
                X[j] = X[i] - d
                visited[j] = False
                ans = (ans&dfs(j))
            else:
                if X[i] - X[j] != d:
                    ans = False
                    break
        return ans
    
    ans = True
    for i in range(n):
        if visited[i]:
            visited[i] = False
            ans = (ans&dfs(i))
    
    if ans:
        print('Yes')
    else:
        print('No')        
  
if __name__=='__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
INF = 10 ** 9
MOD = 10 ** 9 + 7
from collections import deque
sys.setrecursionlimit(100000000)

def main(): 
    n,m = map(int,input().split())
    L = [[] for _ in range(n)]
    R = [[] for _ in range(n)]
    for _ in range(m):
        l,r,d = map(int,input().split())
        l -= 1
        r -= 1
        L[l].append((r,d))
        R[r].append((l,d))
    
    visited = [True] * n
    X = [0] * n

    def dfs(i):
        ans = True
        for r in L[i]:
            j, d = r
            if visited[j]:
                X[j] = X[i] + d
                visited[j] = False
                ans = (ans&dfs(j)) 
            else:
                if X[j] - X[i] != d:
                    ans = False
                    break
        for l in R[i]:
            j,d = l
            if visited[j]:
                X[j] = X[i] - d
                visited[j] = False
                ans = (ans&dfs(j))
            else:
                if X[i] - X[j] != d:
                    ans = False
                    break
        return ans
    
    ans = True
    for i in range(n):
        if visited[i]:
            visited[i] = False
            ans = (ans&dfs(i))
    
    if ans:
        print('Yes')
    else:
        print('No')        
  
if __name__=='__main__':
    main()
N, K = input().split()

if N >= K:
	N %= K

if ( K / 2 ) >= N:
	print ( N )

else:
    print ( K - N )

### FIXED CODE ###

N, K = map(int,input().split())
 
if N >= K:
	N %= K
 
if ( K // 2 ) >= N:
	print ( N )
 
else:
    print ( K - N )
N = int(input().strip())

keta = len(str(N))

count = 0
  
for i in range(1, keta, 2):
  count += (10 ** i)
  
if (keta  % 2) != 0:
  count += (N - 10 ** (keta - 1) + 1)
  
if N >= 10:
  count -= 1
  
print(count)

### FIXED CODE ###

A, B, C = list(map(int, input().strip().split(' ')))
 
print(max(C - (A - B), 0))
N = input()
N = (int)N
i=0
V = []
C = []
num = 0
while i<N:
  num = input()
  V.append((int)num)
 
num = 0
i=0
while i<N:
  num = input()
  C.append((int)num)
max = 0
while i<N:
  max += V[i] - C[i]
  
print(max)

### FIXED CODE ###

N = 0
V = []
C = []
 
i = 0
ans = 0

str = input()
N = int(str)
 
str = input().split()
while i < N:
  V.append(int(str[i]))
  i = i+1
  
i=0
str = 0
str = input().split()
while i < N:
  C.append(int(str[i]))
  i = i+1

i=0
while i<N:
  if V[i] > C[i]:
    ans = ans + V[i] - C[i]
  i = i+1
    
    
print(ans)
a, b, c, d = [int(x) for x input().split(" ")]
print(max(a*c a*d, b*c, b*d))


### FIXED CODE ###

a, b, c, d = [int(x) for x in input().split(" ")]
print(max([a*c, a*d, b*c, b*d]))
N = input()

A = []

for i in range(1,int(N)+1):
    a = input()
    A.append(a)

SUM = 1
for i in range(len(A)):
    SUM = SUM * int(A[i])
    
if (int(SUM) < 10 ** 18):
    print(SUM)
else:
    print(-1)

### FIXED CODE ###

def main ():
    N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
        print (0)
        return
    prod = 1 
    for a in A:
        prod *= a
        if prod > 1000000000000000000:
            print(-1) 
            return
    print(prod)

    
main ()