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

# coding: utf-8
# hello worldと表示する
import sys
import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
pairs=[LI() for i in range(n)]
def pair_revise(x,y,a,b):
    global p
    global q
    #print(x,y,a,b)
    for i in range(max(1,min(floor(x/a),floor(y/b))),max(ceil(x/a),ceil(y/b))+1):
        p,q=a*i,b*i
        if p>=x and q>=y:
            break
    return [p,q]
    #return [x*max(ceil(x/a),ceil(y/b)),y*max(ceil(x/a),ceil(y/b))]
    #for i in range(max(ceil(x/a),ceil(y/b)),):
u,v=pairs[0]
for i in range(n-1):
    u,v=pair_revise(u,v,pairs[i+1][0],pairs[i+1][1])
print(u+v)
    
    
        





### FIXED CODE ###

# coding: utf-8
# hello worldと表示する
import sys
#import numpy
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor,pi,factorial
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def ceil(x,y):
    return (-1)*((-x)//y)
    
n=I()
pairs=[LI() for i in range(n)]
x,y=1,1
for i in range(n):
    a=pairs[i][0]
    b=pairs[i][1]
    k=max(ceil(x,a),ceil(y,b))
    x,y=a*k,b*k
print(x+y)





'''def pair_revise(x,y,a,b):
    global p
    global q
    i=max(ceil(x/a),ceil(y/b))
    p,q=a*i,b*i
    return p,q
u,v=1,1
for i in range(n):
    u,v=pair_revise(u,v,pairs[i][0],pairs[i][1])
    print(u,v)
print(u+v)'''
### BUGGY CODE ###

K,S = map(int,input().split())
ans = 0
for i in range(K+1):
    for j in range(K+1):
        for k in range(K+1):
            s = i + j + k
            if s == S:
                ans += 1
print(ans)

### FIXED CODE ###

K,S = map(int,input().split())
ans = 0
for i in range(K+1):
    if i > S:
        break
    for j in range(K+1):
        if i + j > S:
            break
        elif 0 <= S - (i + j) <= K:
            ans += 1
print(ans)
### BUGGY CODE ###

import collections

h,w,k=map(int,input().split())
sy,sx,gy,gx=map(int,input().split())
sy,sx,gy,gx=sy-1,sx-1,gy-1,gx-1
board=[input() for _ in range(h)]
q=collections.deque()
q.append((sx,sy))
checked=[[0]*w for _ in range(h)]
checked[sy][sx]=1
cost=[[10**18]*w for _ in range(h)]
cost[sy][sx]=0
while len(q)!=0:
  x,y=q.popleft()
  c=cost[y][x]
  for i in range(1,k+1):
    if x+i<w and board[y][x+i]=='.' and c<cost[y][x+i]:
      cost[y][x+i]=c+1
      q.append((x+i,y))
    else:
      break
  for i in range(1,k+1):
    if x-i>=0 and board[y][x-i]=='.' and c<cost[y][x-i]:
      cost[y][x-i]=c+1
      q.append((x-i,y))
    else:
      break
  for i in range(1,k+1):
    if y+i<h and board[y+i][x]=='.' and c<cost[y+i][x]:
      cost[y+i][x]=c+1
      q.append((x,y+i))
    else:
      break
  for i in range(1,k+1):
    if y-i>=0 and board[y-i][x]=='.' and c<cost[y-i][x]:
      cost[y-i][x]=c+1
      q.append((x,y-i))
    else:
      break
if cost[gy][gx]==10**18:
  print(-1)
else:
  print(cost[gy][gx])

### FIXED CODE ###

import collections

h,w,k=map(int,input().split())
sy,sx,gy,gx=map(int,input().split())
sy,sx,gy,gx=sy-1,sx-1,gy-1,gx-1
board=[input() for _ in range(h)]
q=collections.deque()
q.append((sx,sy))
checked=[[0]*w for _ in range(h)]
checked[sy][sx]=1
cost=[[10**18]*w for _ in range(h)]
cost[sy][sx]=0
dx=[1,0,-1,0]
dy=[0,1,0,-1]
while len(q)!=0:
  x,y=q.popleft()
  c=cost[y][x]
  for i in range(4):
    for j in range(1,k+1):
      if x+j*dx[i]<0 or w<=x+j*dx[i] or y+j*dy[i]<0 or h<=y+j*dy[i]:
        break
      if board[y+j*dy[i]][x+j*dx[i]]=='@':
        break
      if cost[y+j*dy[i]][x+j*dx[i]]<=c:
        break
      if cost[y+j*dy[i]][x+j*dx[i]]>c+1:
        q.append((x+j*dx[i],y+j*dy[i]))
        cost[y+j*dy[i]][x+j*dx[i]]=c+1
if cost[gy][gx]==10**18:
  print(-1)
else:
  print(cost[gy][gx])
### BUGGY CODE ###

import sys
input = sys.stdin.readline

def main():
	n=int(input())
	A=list(map(int,input().split()))
	res=0

	for i in range(n):
		for j in range(i+A[i]+1,n):
			if abs(i-j)==A[i]+A[j]:
				res+=1
	print(res)
	
if __name__ == '__main__':
	main()

### FIXED CODE ###

from collections import defaultdict

n=int(input())
A=list(map(int,input().split()))
B=defaultdict(int)
res=0

for i in range(n):
	B[A[i]+i]+=1
	if i-A[i] in B:
		res+=B[i-A[i]]

print(res)
### BUGGY CODE ###

def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        l.append((a,b))
    l.sort(key=lambda x: x[0])
    t = {}
    i = 0
    r = 0
    for d in range(1, M+1):
        while i < len(l):
            a, b = l[i]
            if a <= d:
                if b in t:
                    t[b] += 1
                else:
                    t[b] = 1
            else:
                break
            i += 1
        if not t:
            continue
        m = max(t)
        if t[m] == 1:
            t.pop(m)
        else:
            t[m] -= 1
        r += m
    return r
print(main())


### FIXED CODE ###

import heapq
def main():
    N, M = map(int, input().split())
    l = []
    for _ in range(N):
        a, b = map(int, input().split())
        if a > M:
            continue
        l.append((a,b))
    l.sort(key=lambda x: x[0])
    t = []
    i = 0
    r = 0
    for d in range(1, M+1):
        while i < len(l):
            a, b = l[i]
            if a <= d:
                heapq.heappush(t, -b)
            else:
                break
            i += 1
        if not t:
            continue
        r -= heapq.heappop(t)
    return r
print(main())
### BUGGY CODE ###

n=int(input())
s=input()
Rs,Gs,Bs=[],[],[]

for i in range(n):
    if s[i]=='R':
        Rs.append(i)
    elif s[i]=='G':
        Gs.append(i)
    else:
        Bs.append(i)

ans=len(Rs)*len(Gs)*len(Bs)
for i in Rs:
    for j in Gs:
        for k in Bs:
            l=[i,j,k]
            l.sort()
            a,b,c=l[0],l[1],l[2]
            if b-a==c-b:
                ans-=1

print(ans)


### FIXED CODE ###

n=int(input())
s=input()
Rs,Gs,Bs=[],[],[]

for i in range(n):
    if s[i]=='R':
        Rs.append(i)
    elif s[i]=='G':
        Gs.append(i)
    else:
        Bs.append(i)

ans=len(Rs)*len(Gs)*len(Bs)
for i in Rs:
    for j in Gs:
        dis=abs(i-j)
        a=min(i,j)-dis
        b=max(i,j)+dis
        c=min(i,j)+dis//2
        if a>=0:
            if s[a]=='B':
                ans-=1
        if b<n:
            if s[b]=='B':
                ans-=1
        if dis%2==0:
            if s[c]=='B':
                ans-=1

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

from fractions import gcd
import math

def prime(x):
  if x==2:
    return True
  else:
      for j in range(2,math.ceil(math.sqrt(x))+1):
        if x%j==0:
          return False
          break
        else:
          pass
      else:
        return True
  
a,b = map(int,input().split())
ab = gcd(a,b)
cnt = 0
for i in range(1,ab+1):
  if ab%i==0:
    if prime(i):
      cnt += 1
print(cnt)
    

### FIXED CODE ###

from fractions import gcd
import math

def prime(x):
  if x==2:
    return True
  else:
      for j in range(2,math.ceil(math.sqrt(x))+1):
        if x%j==0:
          return False
          break
        else:
          pass
      else:
        return True
  
a,b = map(int,input().split())
ab = gcd(a,b)
lis = []
for i in range(1,math.ceil(math.sqrt(ab))+1):
  if ab%i==0:
    if prime(i) and i not in lis:
      lis.append(i)
    if prime(ab//i) and ab//i not in lis:
      lis.append(ab//i)
print(len(lis))
### BUGGY CODE ###

n=int(raw_input())
s=raw_input()
ret=n
for i in range(n+1):
    head=s[:i]
    tail=s[i:]
    temp=head.count("#")+tail.count(".")
    if temp<ret:
        ret=temp
    if temp==0:
        ret=0
        break
print(ret)


### FIXED CODE ###

n=int(raw_input())
s=raw_input()

temp=s.count("#")
if temp==0 or temp==n:
    print(0)
else:
    head=0
    tail=n-temp
    ret=tail+head
    for c in s:
        if c=="#":
            head+=1
        else:
            tail-=1
        temp2=head+tail
        if temp2<ret:
            ret=temp2
    print(ret)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

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

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = bin(int_list[i])[2:].zfill(max_len)

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == '1':
        or_list.append(K_bin[:i] + '0' + '1' * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for i in range(N):
        A = int_list[i]
        if int(k, 2) - int(A, 2) == int(k, 2) ^ int(A, 2):
            ans_k += val_list[i]
    ans = max(ans, ans_k)

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

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

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_list[i][1])

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == '1':
        or_list.append(K_bin[:i] + '0' + '1' * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for A, B in int_list:
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == '1' and k[j] == '0':
                ok = 0
                break
        if ok:
            ans_k += B
    ans = max(ans, ans_k)

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

from collections import deque

n,k = map(int,input().split())
li = deque([int(x) for x in input().split()])
li.appendleft(0)

dp = [10**8] * (n+1)
dp[0] = 0

for i in range(1,n+1):
    if i == 1:
        dp[1] = 0
    elif i < k:
        temp = []
        for j in range(1,i+1):
            s = abs(li[i] - li[i-j]) + dp[i-j]
            temp.append(s)
        else:
            dp[i] = min(temp)
    elif i >= k:
        temp = []
        for j in range(1,k+1):
            s = abs(li[i] - li[i-j]) + dp[i-j]
            temp.append(s)
        else:
            dp[i] = min(temp)
            
print(dp[-1])

### FIXED CODE ###

n,k = map(int,input().split())
li = [int(x) for x in input().split()]

dp = [10**8] * n

for i in range(n):
    if i == 0:
        dp[0] = 0
    elif i < k-1:
        temp = []
        for j in range(i):
            s = abs(li[i] - li[i-j-1]) + dp[i-j-1]
            temp.append(s)
        else:
            dp[i] = min(temp)
    elif i >= k-1:
        temp = []
        for j in range(k):
            s = abs(li[i] - li[i-j-1]) + dp[i-j-1]
            temp.append(s)
        else:
            dp[i] = min(temp)
            
print(dp[-1])
### BUGGY CODE ###

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

X=sorted(A)

maxim=X[n-1]

if maxim%2==0:
    half=maxim//2
    target=half
    i=0
    while True:
        if (target+i in X)==1 and target+i != maxim:
            print(maxim,end=" ")
            print(target+i)
            break
        elif (target-i in X)==1 and target-i != maxim:
            print(maxim,end=" ")
            print(target-i)
            break
        else:
            i=i+1
#            print(i)

elif maxim%2==1:
    half=maxim//2
    target=half
    i=0
    while True:
        if (target+i+1 in X)==1 and target+i+1 != maxim:
            print(maxim,end=" ")
            print(target+i+1)
            break
        elif (target-i in X)==1 and target-i != maxim:
            print(maxim,end=" ")
            print(target-i)
            break
        else:
            i=i+1
#            print(i)

### FIXED CODE ###

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

maximal=max(A)
print(maximal,end=" ")
B=list(map(lambda x:abs(x - maximal/2),A))
minimam=B.index(min(B))
if A[minimam]==maximal:
    print("0")
else:
    print(A[minimam])
### BUGGY CODE ###

def f_c():
    n = int(input())
    s = input()

    stack, c = 1, 1
    if s[0]=="W":
        print(0)
        return 0
    for i in range(1, n*2):
        if s[i]=="B":
            if stack%2==0:
                stack += 1
            else:
                c *= stack
                stack -= 1
        else:
            if stack%2==0:
                c *= stack
                stack -= 1
            else:
                stack += 1
        if stack<0:
            break
    if stack!=0:
        print(0)
    else:
        for i in range(1, n+1):
            c*=i
        print(c%(10**9+7))

if __name__ == "__main__":
    f_c()


### FIXED CODE ###

# import sys
# input = sys.stdin.readline
Q = 10**9+7
def main():
    N = int( input())
    S = input()
    left = 0
    ans = 1
    # for i in range(N*2):
    #     s = S[i]
    for s in S:
        if s == "B":
            if left%2 == 0:
                left += 1
            else:
                ans *= left
                left -= 1
        else:
            if left%2 == 1:
                left += 1
            else:
                ans *= left
                left -= 1
        ans %= Q
    if left > 0 or ans == 0:
        print(0)
        return
    for i in range(1,N+1):
        ans *= i
        ans %= Q
    print(ans)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N,K = map(int,input().split())
if N%K==0:
    print(0)
elif K%N==0:
    print(N)
else:
    while abs(N-K) < N:
        N = abs(N-K)
    print(N)

### FIXED CODE ###

N,K = map(int,input().split())
if N>=K:
    N = N%K
    while abs(N-K) < N:
        N = abs(N-K)
    print(N)
else:
    if K >= 2*N:
        print(N)
    else:
        N = K%N
        print(N)
### BUGGY CODE ###

a,b = input().split()
ab = int(a+b)
ans = "No"
i=3
while i*i<=ab:
  if i*i == ab:
    ans="Yes"
print(ans)

### FIXED CODE ###

a,b = input().split()
ab = int(a+b)
ans = "No"
i=3
while i*i<=ab:
  if i*i == ab:
    ans="Yes"
  i+=1
print(ans)
### BUGGY CODE ###

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

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

#print(dp)

for i in range(N):
    w, v = map(int,input().split())
    for j in range(W+1):
        if j - w >= 0:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
        else:
            dp[i+1][j] = dp[i][j]


print(dp[-1][-1])







### FIXED CODE ###

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

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

#print(dp)

for i in range(N):
    w, v = map(int,input().split())
    for j in range(W+1):
        if j - w >= 0:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w]+v)
        else:
            dp[i+1][j] = dp[i][j]


print(dp[-1][-1])
### BUGGY CODE ###

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

MOD = 998_244_353

D = [[0 for _ in range(S+1)] for _ in range(N+1)]
D[0][0] = 1
for i in range(1, N+1):
  for j in range(0, S+1):
    D[i][j] = 2 * D[i-1][j] % MOD
    if j >= A[i-1]:
      D[i][j] += D[i-1][j-A[i-1]]
      D[i][j] %= MOD
  #print(D[i])
    
print(D[N][S])

### FIXED CODE ###

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

MOD = 998_244_353

D = [[0 for _ in range(S+1)] for _ in range(N+1)]
D[0][0] = 1
for i in range(1, N+1):
  for j in range(0, S+1):
    D[i][j] = 2 * D[i-1][j] % MOD
    if j >= A[i-1]:
      D[i][j] += D[i-1][j-A[i-1]]
      D[i][j] %= MOD
  #print(D[i])
    
print(D[N][S])
### BUGGY CODE ###

# https://atcoder.jp/contests/abc164/tasks/abc164_d

from operator import mul
from functools import reduce
from collections import defaultdict

def combination(n, r):
    if not 0 <= r <= n: return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

S = input()
L = len(S)
res = 0

T = [0]
x = ""
for s in reversed(S):
    """ 累積和 """
    x = s + x
    T.append(int(x))

reminder = [0]*2019
for i in range(L+1):
    reminder[T[i]%2019] += 1

for c in reminder:
    res += combination(c,2)

print(res)

### FIXED CODE ###

# https://atcoder.jp/contests/abc164/tasks/abc164_d

from operator import mul
from functools import reduce
from collections import defaultdict

def combination(n, r):
    if not 0 <= r <= n: return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

S = input()

res = 0

T = [0]
x = 0
L = len(S)
for i, s in zip(range(L),reversed(S)):
    """ 累積和 """
    x = (int(s)*pow(10,i,2019) + x)%2019
    T.append(x)

reminder = [0]*2019
for i in range(L+1):
    reminder[T[i]%2019] += 1

for c in reminder:
    res += combination(c,2)

print(res)
### BUGGY CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation = 0
for i in range(N-1):
    summation += ((B[i] * (sum(B[j] for j in range(i+1,N)) % x)) % x)
print(summation % x)


### FIXED CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2
summation2 = sum(b ** 2 for b in B)
summation = ((summation1 - summation2) // 2) % x
print(summation)
### BUGGY CODE ###

from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(stdin.readline().rstrip()) for _ in range(M)]

def solve(n):
    dp = []
    for i in range(n+1):
        if i in A:
            dp.append(0)
        else:
            dp.append(1)
    for i in range(2, n+1):
        if dp[i] == 0:
            continue
        dp[i] = dp[i-1]+dp[i-2]
    return dp[n] % 1000000007

print(solve(N))

### FIXED CODE ###

from sys import stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
dp = [1 for i in range(N+1)]
MOD = 1000000007
for _ in range(M):
  a = int(stdin.readline().rstrip())
  dp[a] = 0
for i in range(2, N+1):
    if dp[i] == 0:
        continue
    dp[i] = dp[i-1]+dp[i-2]
print(dp[N] % MOD)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

for X in range(K + 1):
    for Y in range(K + 1):
        for Z in range(K + 1):
            if X + Y + Z == S:
                cnt += 1
print(cnt)


### FIXED CODE ###

# -*- coding: utf-8 -*-
K, S = map(int, input().split())
cnt = 0

for X in range(K + 1):
    for Y in range(K + 1):
        Z = S - X - Y
        if 0 <= Z <= K:
            cnt += 1

print(cnt)
### BUGGY CODE ###

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  for i in range(h):
    for j in range(w):
      if field[i][j]=='#':
        q=collections.deque()
        visited=[[False]*w for _ in range(h)]
        q.append((i,j))
        while q:
          y,x=q.popleft()
          if visited[y][x]:
            continue
          visited[y][x]=True
          for dy,dx in dd:
            ny=y+dy
            nx=x+dx
            if 0<=ny<h and 0<=nx<w:
              if field[y][x]==field[ny][nx]:
                continue
              if visited[ny][nx]:
                continue
              if field[ny][nx]=='.':
                ans+=1
              q.append((ny,nx))
    # print(ans)
  return ans

# main()
print(main())


### FIXED CODE ###

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[S() for _ in range(h)]

  ans=0
  visited=[[False]*w for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if visited[i][j]:
        continue
      if field[i][j]!='#':
        continue
      q=collections.deque()
      q.append((i,j))
      b=0
      wh=0
      while q:
        y,x=q.popleft()
        if visited[y][x]:
          continue
        if field[y][x]=='#':
          b+=1
        else:
          wh+=1
        visited[y][x]=True
        for dy,dx in dd:
          ny=y+dy
          nx=x+dx
          if not (0<=ny<h and 0<=nx<w):
            continue
          if field[y][x]==field[ny][nx]:
            continue
          if visited[ny][nx]:
            continue
          q.append((ny,nx))
      ans+=b*wh
      # print(i,j,b,wh,ans)
  return ans

# main()
print(main())
### BUGGY CODE ###

N = int(input())

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

ls = [sorted(list(s)) for s in ls]

hoge = 0
for i in range(N):
    hoge += sum([1 if x==ls[i] else 0 for x in ls[i:len(ls)]]) - 1

print(hoge)

### FIXED CODE ###

N = int(input())
s = [''.join(sorted(input().rstrip())) for _ in range(N)]

memo = {}
for x in s:
    if x not in memo:
        memo[x] = 1
    else:
        memo[x] += 1

print(sum(x*(x-1)//2 for x in memo.values()))
### BUGGY CODE ###

import sys

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

for i in range(N+1):
    if Y < i * 10000:
        continue
    for j in range(N+1):
        if N < i + j or Y < i * 10000 + 5000 * j:
            break
        for k in range(N+1):
            if N < i + j + k or Y < i * 10000 + j * 5000 + k * 1000:
                break
            if N == i + j + k and Y == i * 10000 + j * 5000 + k * 1000:
                print(i,j,k)
                sys.exit()
print("-1 -1 -1")


### FIXED CODE ###

import sys

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

for i in range(N+1):
    for j in range(N+1):
        k = N - i - j

        if k >= 0 and Y == i * 10000 + j * 5000 + k * 1000:
            print(i,j,k)
            sys.exit()
print("-1 -1 -1")
### BUGGY CODE ###

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

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

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

### FIXED CODE ###

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

ans=1
for a in A:
    ans *= a
    if ans > 10**18:
        if 0 in A:
            ans = 0
        else:
            ans = -1
        break

print(ans)