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

a,b,c,k=map(int,input().split())
if a==b==c:
    print(0)
    exit()
for i in range(k):
    A=c+b;B=a+c;C=a+b
    a=A;b=B;c=C
if abs(a-b)>10**18:
    print("Unfair")
else:
    print(a-b)

### FIXED CODE ###

a,b,c,k=map(int,input().split())
if a==b==c:
    print(0)
    exit()
elif abs(a-b)>10**18:
    print("Unfair")
elif k%2==1:
    print(b-a)
else:
    print(a-b)
### BUGGY CODE ###

#!/usr/bin/env python3
import math
n = int(input())
def eratosthenes(n):
    prime = [2]
    i = 2
    while prime[-1] < n:
        i += 1
        prime_bit = 0
        for div in prime:
            if i % div == 0: 
                break
            if div == prime[-1]: prime_bit = 1
        if prime_bit: prime.append(i)
        """for j in range(2,math.ceil(i**1/2)+1): #２だけ特別扱いしないといけない
            if i % j == 0: break
            if j == math.ceil(i**1/2): 
                prime.append(i)"""
    return prime
prime = eratosthenes(n)
print(prime[-1])

### FIXED CODE ###

#!/usr/bin/env python3
import math
n = int(input())
def is_prime(n):
    for i in range(2,math.ceil(n**1/2)+1):
        if n % i == 0:
            return False
    return True    
i = n
while True:
    if is_prime(i): break
    i += 1
print(i)
### BUGGY CODE ###

# 2020-05-22
from collections import deque


def main():
    n, m, k = [int(x) for x in input().split()]
    friends = [set() for _ in range(n)]
    blocks = [set() for _ in range(n)]
    for _ in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        friends[a].add(b)
        friends[b].add(a)
    for _ in range(k):
        a, b = [int(x) - 1 for x in input().split()]
        blocks[a].add(b)
        blocks[b].add(a)

    ansers = []
    ansers_append = ansers.append
    nets = set()
    visited = set()
    visited_add = visited.add
    for person in range(n):
        if person in visited:
            # Already marked in one of the nets.
            for candidate_net in nets:
                if person in candidate_net:
                    net = candidate_net
                    break
        else:
            stack = deque()
            stack_append = stack.append
            stack_pop = stack.pop
            stack_append(person)
            net = {person}
            net_add = net.add
            while stack:
                new = stack_pop()
                for adj in friends[new]:
                    if adj in net:
                        continue
                    stack_append(adj)
                    net_add(adj)
            nets.add(tuple(net))

        # 友達をたどるとブロック対象に着くことがある。積集合 &。
        ans = len(net) - len(friends[person]) - len(net & blocks[person]) - 1
        ansers_append(ans)
        visited_add(person)
    print(*ansers)
    return


if __name__ == '__main__':
    main()


### FIXED CODE ###

# 2020-05-22
def main():
    n, m, k = [int(x) for x in input().split()]
    friends = [set() for _ in range(n)]
    blocks = [set() for _ in range(n)]
    for _ in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        friends[a].add(b)
        friends[b].add(a)
    for _ in range(k):
        a, b = [int(x) - 1 for x in input().split()]
        blocks[a].add(b)
        blocks[b].add(a)

    networks = {}  # The dict of networks as sets. Keys are leaders.
    net_leaders = [-1] * n  # The leaders of the networks that the ones joined.
    visited = [False] * n
    for person in range(n):
        if visited[person]:
            continue
        network = set()
        network_add = network.add
        stack = [person]
        stack_append = stack.append
        stack_pop = stack.pop
        while stack:
            new = stack_pop()
            visited[new] = True
            net_leaders[new] = person
            network_add(new)
            for adj in friends[new]:
                if visited[adj]:
                    continue
                stack_append(adj)
        networks[person] = network

    answers = []
    answers_append = answers.append
    for person in range(n):
        net = networks[net_leaders[person]]
        ans = len(net) - len(friends[person]) - 1
        for block in blocks[person]:
            if block in net:
                ans -= 1
        answers_append(ans)

    print(*answers)
    return


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

N = int(input())
A = list(map(int, input().split()))
C = [i for i in range(N)]
d = dict(zip(C, A))
B = sorted(A)
B.append(0)
p = B[0]
nm = []
nn = []
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        nm.append(p)
        nn.append(u)
        u=0
    u += 1
    p = q
y = dict(zip(nm, nn))
P = len(nm)
for j in range(N):
    g = 0
    x = d[j]
    y[x] -= 1
    va = list(y.values())
    for l in range(P):
        v = va[l]
        g += v*(v-1)//2
    print(g)
    y[x] += 1

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = sorted(A)
B.append(0)
p = B[0]
y = dict()
u = 0
for k in range(N+1):
    q = B[k]
    if p != q:
        y[p] = u
        u = 0
    u += 1
    p = q
All = 0
for l in y.values():
    All +=l*(l-1)//2
for j in range(N):
    x = A[j]
    print(All+(y[x]-1)*(y[x]-2)//2-y[x]*(y[x]-1)//2)
### BUGGY CODE ###

#5888164
N = int(input())
edge = [[] for _ in range(N)]
ans = [-1] * N
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    w %= 2
    edge[u].append((v,w))
    edge[v].append((u,w))

stack = [(e,0) for e in edge[0]]
ans[0] = 0

while len(stack) > 0:
    e,c = stack.pop(0)
    n,w = e[0],e[1]
    if ans[n] >= 0:
        continue
    ans[n] = (c + w) % 2
    stack += [(e,ans[n]) for e in edge[n]]

for a in ans:
    print(a)

### FIXED CODE ###

#5888164
N = int(input())
edge = [[] for _ in range(N)]
ans = [-1 for _ in range(N)]
for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    w %= 2
    edge[u].append((v,w))
    edge[v].append((u,w))

stack = [(e,0) for e in edge[0]]
ans[0] = 0

while len(stack) > 0:
    e,c = stack.pop()
    n,w = e[0],e[1]
    if ans[n] >= 0:
        continue
    ans[n] = (c + w) % 2
    stack += [(e,ans[n]) for e in edge[n]]

for a in ans:
    print(a)
### BUGGY CODE ###

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

for i in range(n):
    print(a.count(i+1))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
l = [0] * n

for i in range(1,n):
    l[a[i-1] - 1] += 1
for i in range(n):
    print(l[i])
### BUGGY CODE ###

from scipy.sparse.csgraph import dijkstra

N,M = map(int,input().split())
L = list(map(int,input().split()))
for i in range(N) :
    L[i] -= 1

A = [[float("inf") for i in range(N)] for i in range(N)]
for i in range(M) :
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    A[a][b] = 1
    A[b][a] = 1

dist = dijkstra(A)
ans = N
for i in range(N) :
    if i == L[i] :
        continue
    if dist[i][L[i]] < float("inf") :
        continue    
    else :
        ans -= 1
print(ans)


### FIXED CODE ###

from collections import deque

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

G = [[] for i in range(N)]

for i in range(len(L)) :
    u,v = L[i]
    u -= 1
    v -= 1
    
    G[u].append(v)
    G[v].append(u)

explored = [0 for i in range(N)]

ans = 0

for i in range(N) :
    
    if explored[i] :
        continue
    
    explored[i] = 1
    q = deque([i])
    
    A = []
    B = []
    while q :
        now = q.popleft()
        
        A.append(now)
        B.append(P[now]-1)
        
        for to in G[now] :
            if explored[to] :
                continue
            
            q.append(to)
            explored[to] = 1
    
    C = set(A) & set(B)
    ans += len(C)
    

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

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

for a in A:
    try:
        memo[a] += 1
    except:
        memo[a] = 1

import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# print(memo)
for i in range(N):
    ans = 0
    for key in memo.keys():
        if memo[key] < 2:
            continue
        if A[i] == key:
            if memo[key] - 1 < 2:
                continue
            else:
                ans += combinations_count(memo[key]-1, 2)
                # print(ans)
        else:
            ans += combinations_count(memo[key], 2)
    print(ans)


### FIXED CODE ###

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

for a in A:
    try:
        memo[a] += 1
    except:
        memo[a] = 1

import math
def combinations_count(n, r):
    if n < r:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

sum_memo = 0

for key in memo.keys():
    sum_memo += combinations_count(memo[key], 2)

for a in A:
    print(sum_memo-(memo[a]-1))
### BUGGY CODE ###

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
x,y = map(int,input().split())
kai = []
for i in range(x+1):
    if x-i == (y-2*i)*2:
        kai.append(i)
        kai.append(y-2*i)
        break
m = 10**9 + 7
if len(kai) == 0:
    print(0)
else:
    ans = 1
    b = kai[0]+kai[1]
    for i in range(kai[0]):
        #print(ans)
        ans = ans*(b-i)%m
        ans = ans*mod_inv(i+1,m)%m
    print(ans)

### FIXED CODE ###

def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m
x,y = map(int,input().split())
kai = []
for i in range(x+1):
    if x-i == (y-2*i)*2:
        kai.append(i)
        kai.append(y-2*i)
        break
m = 10**9 + 7
if len(kai) == 0:
    print(0)
else:
    ans = 1
    b = kai[0]+kai[1]
    for i in range(kai[0]):
        #print(ans)
        ans = ans*(b-i)%m
        ans = ans*mod_inv(i+1,m)%m
    print(ans)
### BUGGY CODE ###

H, W, A, B = list(map(int, input().split()))

def combinations_count(n, r):
    if n - r < r:
        r = n - r
    if r == 0:
        return 1
    if r == 1:
        return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def solve():
    # print(H, W, A, B)

    goal = W - 1, H - 1

    # 境界点
    nx = B - 1
    ny = H - A

    # 境界点から斜め右上の点から, y=0 へ伸びる線が choke point
    c_bottom = nx + 1, ny - 1
    # print(c_bottom)
    choke_points = []
    combs = []

    for i in range(c_bottom[1], -1, -1):
        choke_points.append((c_bottom[0], i))

    for i in range(len(choke_points)):
        x, y = choke_points[i]
        if i == len(choke_points) - 1:
            combs.append(combinations_count(x + y, x))
        else:
            combs.append(combinations_count((x + y) - 1, x - 1))

    for i in range(len(choke_points)):
        x, y = choke_points[i]
        dx, dy = goal[0] - x, goal[1] - y
        combs[i] *= combinations_count(dx + dy, dx)

    # print(sum(combs))
    res = sum(combs) % (10 ** 9 + 7)
    return res
  

res = solve()
print(res)


### FIXED CODE ###

H, W, A, B = list(map(int, input().split()))
 
# 事前計算 + 演算ごとに mod する
def solve():
    # 組合せの計算用に階乗を事前計算しておく
    MOD = 10 ** 9 + 7
    FACT = [0] * (H + W + 1)
    INV_FACT = [0] * (H + W + 1)  # 逆元. 組合せの計算ごとにMODを取るため
 
    FACT[0], INV_FACT[0] = 1, 1
    for i in range(1, (H + W + 1)):
        FACT[i] = (FACT[i - 1] * i) % MOD
        INV_FACT[i] = pow(FACT[i], MOD - 2, MOD)  # フェルマーの小定理を使う
 
    def mod_nCr(n, r):
        if n < r or n == 0 or r == 0:
            return 1
 
        return FACT[n] * (INV_FACT[r] * INV_FACT[n - r]) % MOD
 
    # print(H, W, A, B)
 
    # 座標は(x, y). startは(0, 0)
    goal = W - 1, H - 1
 
    # 境界点: 移動できないエリアの右上の点
    nx = B - 1
    ny = H - A
 
    # 境界点から右斜め上に1つ移動した点(choke_left)から, 右端へ伸びる線がchoke points
    choke_left = nx + 1, ny - 1
 
    choke_points = []
    for i in range(B, W):
        choke_points.append((i, choke_left[1]))
 
    # 組合せを計算する: startからcp1, cp2からgoalまで組合せを掛ける
    ans = 0
    for cp1 in choke_points:
        x, y = cp1
        from_start_to_cp1 = mod_nCr(x + y, x)
 
        # cp1から1つ下の点がcp2
        y += 1
        dx, dy = goal[0] - x, goal[1] - y
        from_cp2_to_goal = mod_nCr(dx + dy, dx)
 
        ans = ans % MOD + (from_start_to_cp1 * from_cp2_to_goal % MOD) % MOD
 
    return ans % MOD
 
res = solve()
print(res)
### BUGGY CODE ###

#!/usr/bin/env python3
 
import sys
# 以下を記述しないとTLEになる, 何故？
from heapq import heappushpop
from collections import defaultdict
# ---- ここまで -----------------------
 
S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()
 
ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1
 
print(ans)

### FIXED CODE ###

import bisect
s = input().rstrip()
t = input().rstrip()

a_ord = ord("a")
ch_place = [[] for _ in range(26)]
for i, ch in enumerate(s):
    ch_place[ord(ch) - a_ord].append(i)

# print(ch_place)

count = 0
idx = -1 
for ch in t:
    ch_num = ord(ch) - a_ord
    if len(ch_place[ch_num]) == 0:
        print(-1)
        exit()
    place = bisect.bisect_right(ch_place[ch_num], idx)
    # print(ch_place[ch_num], idx, place)
    if place == len(ch_place[ch_num]):
        idx = ch_place[ch_num][0]
        count += 1
    else:
        idx = ch_place[ch_num][place]

# print(count, idx)
print(count * len(s) + idx + 1)
### BUGGY CODE ###

r,g,b,n=map(int,input().split())
balls=sorted([r,g,b])
ans=0
for i in range(n//balls[2]+1):
  for j in range((n-(i*balls[2]))//balls[1]+1):
    for k in range((n-i*balls[2]-j*balls[1])//balls[0]+1):
      if i*balls[2]+j*balls[1]+k*balls[0]==n:
        ans+=1
print(ans)

### FIXED CODE ###

b,r,g,n=map(int,input().split())
ans=0
for i in range(3000//r+1):
    for j in range(3000//g+1):
        if n-j*g-i*r>=0 and (n-j*g-i*r)%b==0:
            ans+=1
print(ans)
### BUGGY CODE ###

p = int(input())
A = list(map(int,input().split()))
co = 0
cont = 0
for i in A:
  cont += 1
  if A.count(cont) != 0 and i == A.index(cont)+1:
    A.pop(A.index(cont))
    co += 1
print(co)

### FIXED CODE ###

p = int(input())
ans = 0
*A,= map(int,input().split())
for j,i in enumerate(A):
  if A[A[j]-1]==j+1:
    ans+=1
print(ans//2)
### BUGGY CODE ###


from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import statistics
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm(a, b):
  return a*b//gcd(a, b)

def main():
  S = input()
  Q = int(input())
  TFC = list(list(input().split()) for _ in range(Q))
  rev = 0
  for i in range(Q):
    if TFC[i][0] == '1':
      rev ^= 1
    else:
      if TFC[i][1] == '1':
        if rev == 0:
          S = TFC[i][2] + S
        else:
          S = S + TFC[i][2]
      else:
        if rev == 0:
          S = S + TFC[i][2]
        else:
          S = TFC[i][2] + S
  print(S if rev == 0 else S[::-1])
  
if __name__ == '__main__':
  main()

### FIXED CODE ###


from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from functools import reduce

from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import statistics
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm(a, b):
  return a*b//gcd(a, b)

def main():
  S = input()
  Q = int(input())
  TFC = list(list(input().split()) for _ in range(Q))
  rev = 0
  q = deque(S)
  for i in range(Q):
    if TFC[i][0] == '1':
      rev ^= 1
    else:
      if TFC[i][1] == '1':
        if rev == 0:
          q.appendleft(TFC[i][2])
        else:
          q.append(TFC[i][2])
      else:
        if rev == 0:
          q.append(TFC[i][2])
        else:
          q.appendleft(TFC[i][2])
  ans = ''.join(q)
  print(ans if rev==0 else ans[::-1])
  
if __name__ == '__main__':
  main()
### BUGGY CODE ###

n = int(input())
stack = []
for _ in range(n):
    stack.append(int(input()))

candidate = [-float('inf')]
for i in range(1, len(stack) // 2 + 1):
    for r1, r2 in zip(stack[::1], stack[i::1]):
        candidate.append(r2 - r1)
    for r1, r2 in zip(stack[::1], stack[len(stack) - i::1]):
        candidate.append(r2 - r1)
    candidate = [max(candidate)]

print(candidate[0])

### FIXED CODE ###

n = int(input())
stack = []
for _ in range(n):
    stack.append(int(input()))

maxv = -10**9
minv = stack[0]
for i in range(1, len(stack)):
    maxv = max(maxv, stack[i] - minv)
    minv = min(minv, stack[i])

print(maxv)
### BUGGY CODE ###

import math
n=int(input())
nn=str(n)
# c=int(math.log10(n)//1)+1

a=list(range(1,n+1))

b=[[[] for _ in range(10)] for __ in range(10)]
for i in range(1,10):
    for j in range(1,10):
        box=[]
        for h in a:
            if str(h)[0]==str(i) and str(h)[-1]==str(j):
                box.append(h)
        b[i][j]=box

# b=[[[] for _ in range(10)] for __ in range(9)]

ans=0
for i in range(1,10):
    for j in range(1,10):
        ans+=len(b[i][j])*len(b[j][i])
print(ans)

### FIXED CODE ###

import math
n=int(input())
nn=str(n)
# c=int(math.log10(n)//1)+1

a=list(range(1,n+1))


# b=[[[] for _ in range(10)] for __ in range(10)]
b=[[[0] for _ in range(10)] for __ in range(10)]


# for i in range(1,10):
#     for j in range(1,10):
#         box=0
#         for h in a:
#             if str(h)[0]==str(i) and str(h)[-1]==str(j):
# #                 box.append(h)
#                 box+=1
#         b[i][j]=box
        
        
        
for h in a:
    x=int(str(h)[0])
#     print(x)
    y=int(str(h)[-1])
    b[x][y][0]+=1



# b=[[[] for _ in range(10)] for __ in range(9)]

ans=0
for i in range(1,10):
    for j in range(1,10):
        ans+=(b[i][j][0])*(b[j][i][0])
print(ans)
### BUGGY CODE ###

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

if B > N:
    print(A*N//B)
else:
    L = []
    for x in range(N):
        L.append(A*x//B-A*(x//B))
    print(max(L))

### FIXED CODE ###

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

if B > N:
    print(A*N//B)
else:
    print(A*(B-1)//B)
### BUGGY CODE ###

n,k=map(int,input().split())
s=input()
a=[]
tmp=1
for i in range(len(s)-1):
	if s[i] == s[i+1]:
		tmp+=1
	else:
		a.append(tmp)
		tmp=1
a.append(tmp)

b=[]
b.append(a[0])
if s[0]=='0':
	m=2*k
else:
	m=2*k+1
t=4*k+1
for i in range(len(a)):
	b.append(sum(a[i:i+m]))
	m=t-m
print(max(b))


### FIXED CODE ###

n,k=map(int,input().split())
s=input()
a=[]
a.append(0)
for i in range(len(s)-1):
	if s[i] != s[i+1]:
		a.append(i+1)
a.append(n)
if s[-1]=='0':
	m=2*k
else:
	m=2*k+1
t=4*k+1
_max=0
i=len(a)-1
if i- m<0:
	print(n)
else:
	while i-m>=0:
		tmp=a[i]-a[i-m]
		#print('i:{} tmp:{}'.format(i,tmp))
		if tmp>_max:
			_max=tmp
		m=t-m
		i-=1
	if a[i]>_max:
		_max=a[i]
	print(_max)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
clashes=[-1]*20
ans=0
lastclash=-1
for i in range(n):
  binstr='{0:b}'.format(a[i])
  binlist=[]
  t=len(binstr)
  for j in range(t):
    binlist.append(binstr[j])
  binlist.reverse()
  for j in range(20-t):
    binlist.append('0')
  maxclash=-1
  for j in range(20):
    if clashes[j]>maxclash and binlist[j]=='1':
      maxclash=clashes[j]
  for j in range(20):
    if binlist[j]=='1':
      clashes[j]=i
  lastclash=max(maxclash,lastclash)
  ans+=i-lastclash
print(ans)

  

### FIXED CODE ###

def split(word): 
    return [char for char in word]  
n=int(input())
a=list(map(int,input().split()))
blist=[]
for i in range(20):
  blist.append(0)
ans=0
finalbad=0
for i in range(n):
  s='{0:08b}'.format(a[i])
  maxclash=0
  for j in range(20-len(s),20):
    if s[j-(20-len(s))]=='1':
      if blist[j]>maxclash:
        maxclash=blist[j]
      blist[j]=i+1
  if maxclash>finalbad:
    finalbad=maxclash
  ans+=i+1-finalbad
print(ans)
### BUGGY CODE ###

N=int(input())
sisterN=[]
SISTERn=[]
for n in range(N):
    _=int(input())
    if _<50000:
        _s= _
        if sisterN.count(_s)==1:
            sisterN.remove(_s)
        else:
            sisterN.append(_s)

    else:
        _b= _
        if SISTERn.count(_b)==1:
            SISTERn.remove(_b)
        else:
            SISTERn.append(_b)
print(len(sisterN)+len(SISTERn))

### FIXED CODE ###

N=int(input())
S=set()

for n in range(N):
    _=int(input())
    if _ in S:
        S.remove(_)
    else:
        S.add(_)

print(len(S))
### BUGGY CODE ###

import bisect
n = int(input())
s = list(input())
alp = 'abcdefghijklmnopqrstuvwxyz'
cnt = {c: [] for c in alp}

for i, c in enumerate(s):
    cnt[c].append(i)

q = int(input())
for _ in range(q):
    t, x, y = input().split()
    ans = 0
    if t == '1':
        i, c = int(x) - 1, y
        a = bisect.bisect_left(cnt[s[i]], i)
        cnt[s[i]].pop(a)
        s[i] = c
        b = bisect.bisect_left(cnt[c], i)
        cnt[c].insert(b, i)
    else:
        l, r = int(x) - 1, int(y) - 1
        for c in alp:
            a = bisect.bisect_left(cnt[c], l)
            if a < len(cnt[c]) and cnt[c][a] <= r:
                ans += 1
               
        print(ans)

### FIXED CODE ###

import bisect
n = int(input())
s = list(input())
alp = 'abcdefghijklmnopqrstuvwxyz'
cnt = {c: [] for c in alp}

for i, c in enumerate(s):
    cnt[c].append(i)

q = int(input())
for _ in range(q):
    t, x, y = input().split()
    ans = 0
    if t == '1':
        i, c = int(x) - 1, y
        if s[i] == c:
            continue
        a = bisect.bisect_left(cnt[s[i]], i)
        cnt[s[i]].pop(a)
        s[i] = c
        b = bisect.bisect_left(cnt[c], i)
        cnt[c].insert(b, i)
    else:
        l, r = int(x) - 1, int(y) - 1
        for c in alp:
            a = bisect.bisect_left(cnt[c], l)
            if a < len(cnt[c]) and cnt[c][a] <= r:
                ans += 1

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

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
  if a.count(a[i])>=2:
    ans=1
    break
if ans==1:
  print('NO')
else:
  print('YES')

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
b=sorted(a)
for i in range(n-1):
  if b[i]==b[i+1]:
    ans=1
    break
if ans==1:
  print('NO')
else:
  print('YES')
### BUGGY CODE ###

def main():
	flag = True
	N = int(input())
	arr = list(map(int, input().split()))
	ans = arr[0]
	for i in range(1, N):
		ans *= arr[i]
	if ans > 1000000000000000000:
		print(-1)
	else:
		print(ans)


if __name__ == '__main__':
	main()

### FIXED CODE ###

def main():
	N = int(input())
	arr = list(map(int, input().split()))
	ans = arr[0]
	if arr.count(0) > 0:
		print(0)
		return
	for i in range(1, N):
		ans *= arr[i]
		if ans > 1000000000000000000:
			print(-1)
			return
	print(ans)


if __name__ == '__main__':
	main()