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

from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = float('inf')
for n in range(2**N):
    n = bin(n)[2:]
    n = '0'*(N-len(n))+n
    l = []
    for i in range(N):
        if n[i]=='0':
            l.append([A[i],i,0])
        else:
            l.append([B[i],i,1])
    inversion = 0
    for i in range(N):
        for j in range(i+1,N):
            if l[i][0]>l[j][0]:
                inversion += 1
    l.sort()
    d = defaultdict(list)
    for i in range(N):
        v,j,k = l[i]
        if (i-j+k)%2==1:
            d[v].append(i)
    possible = True
    for v in d:
        if len(d[v])%2==1:
            possible = False
        else:
            for i in range(len(d[v])//2):
                if (d[v][2*i+1]-d[v][2*i])%2==1:
                    inversion += d[v][2*i+1]-d[v][2*i]
                else:
                    possible = False
        if not possible:
            break
    if possible:
        ans = min(ans,inversion)

if ans == float('inf'):
    ans = -1
print(ans)

### FIXED CODE ###

from collections import defaultdict
from operator import itemgetter
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ans = 1000
for n in range(2**N):
    n = bin(n)[2:]
    if n.count('1')%2!=0:
        continue
    n = '0'*(N-len(n))+n
    l = []
    for i in range(N):
        if n[i]=='0':
            l.append([A[i],i])
        else:
            l.append([B[i],i+1])
    inversion = 0
    for i in range(N):
        if inversion>=ans:
            break
        for j in range(i+1,N):
            if l[i][0]>l[j][0]:
                inversion += 1
    if inversion>=ans:
        continue
    l.sort(key=itemgetter(0))
    d = defaultdict(list)
    for i in range(N):
        v,j = l[i]
        if (i-j)%2==1:
            d[v].append(i)
    possible = True
    for v in d:
        if len(d[v])%2==1:
            possible = False
        else:
            for i in range(len(d[v])//2):
                if (d[v][2*i+1]-d[v][2*i])%2==1:
                    inversion += d[v][2*i+1]-d[v][2*i]
                else:
                    possible = False
                    break
        if not possible:
            break
    if possible:
        ans = min(ans,inversion)

if ans == 1000:
    ans = -1
print(ans)
### BUGGY CODE ###

import sys
import math
from  collections import defaultdict

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

sys.setrecursionlimit(1000000)

def solve(test):
	s = list(input())
	t = list(input())
	memo = {}
	ans = lcs(s, t, 0, 0, memo)
	print(''.join(ans))

def lcs(s, t, i, j, memo):
	if (i, j) in memo:
		return memo[(i, j)]
	elif i == len(s) or j == len(t):
		return ['']
	else:
		ans = ''
		if s[i] == t[j]:
			ans = [s[i]] + lcs(s, t, i + 1, j + 1, memo)
		else:
			s1 = lcs(s, t, i + 1, j, memo)
			s2 = lcs(s, t, i, j + 1, memo)
			if len(s1) >= len(s2):
				ans = s1
			else:
				ans = s2
		memo[(i, j)] = ans
		return ans


if __name__ == "__main__":
	test_cases = 1
	for t in range(1, test_cases + 1):
		solve(t)


### FIXED CODE ###

import sys
import math
from  collections import defaultdict

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')


def solve(test):
	s = [''] + list(input())
	t = [''] + list(input())
	rec = [[0 for j in range(len(t))] for i in range(len(s))]
	for i in range(1, len(s)):
		for j in range(1, len(t)):
			if s[i] == t[j]:
				rec[i][j] = 1 + rec[i - 1][j - 1]
			else:
				rec[i][j] = max(rec[i - 1][j], rec[i][j - 1])

	ans = []
	i, j = len(s) - 1, len(t) - 1
	while i >= 0 and j >= 0:
		if s[i] == t[j]:
			ans.append(s[i])
			i -= 1
			j -= 1
		elif rec[i - 1][j] > rec[i][j - 1]:
			i -= 1
		else:
			j -= 1

	print(''.join(ans[::-1]))


if __name__ == "__main__":
	test_cases = 1
	for t in range(1, test_cases + 1):
		solve(t)
### BUGGY CODE ###

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

sum = 1
for i in range(n):
	sum = sum * a[i]
if sum > 10**18:
	print(-1)
else:
	print(sum)

### FIXED CODE ###

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

total = 1
a.sort()
if a[0] == 0:
	print(0)
	sys.exit()
for i in range(n):
	total *= a[i]
	if total > 10**18:
		print('-1')
		sys.exit()
print(total)
### BUGGY CODE ###

def drop(lst,h,w):
    for i in range(w-1,-1,-1):
        work=[lst[j][i] for j in range(h)]
        work=[x for x in work if x]
        for j in range(h-1,-1,-1):
            if work: lst[j][i]=work.pop()
            else : lst[j][i]=None

def chain(lst,h,w,k):
    sm=0
    for j in range(h):
        train=1
        for i in range(w-1):
            if not lst[j][i] :
                train=1
                continue
            if lst[j][i]==lst[j][i+1]:
                train+=1
            else :
                if train>=k:
                    sm+=lst[j][i]*train
                    lst[j][i-train+1:i+1]=[None]*train
                train=1
        if train>=k:
            sm+=lst[j][-1]*train
            lst[j][-train:]=[None]*train
    return sm


def procedure(lst,h,w,k,x):
    lst[x[0]][x[1]]=None
    drop(lst,h,w)
    sm=0
    i=0
    point=chain(lst,h,w,k)
    while point:
        sm+=(2**i)*point
        drop(lst,h,w)
        point=chain(lst,h,w,k)
        i+=1
        #print(lst)
    return sm


def main():
    h,w,k=map(int,input().split())
    lst=[[int(x) for x in input()] for _ in range(h)]
    mx=0

    for i in range(1,h):
        for j in range(w):
            work=[[lst[i][j] for j in range(w)] for i in range(h)]
            sm=procedure(work,h,w,k,(i,j))
            if mx<sm : mx=sm
    print(mx)


main()

### FIXED CODE ###

def drop(lst,h,w):
    for i in range(w-1,-1,-1):
        work=[lst[j][i] for j in range(h)]
        work=[x for x in work if x]
        for j in range(h-1,-1,-1):
            if work: lst[j][i]=work.pop()
            else : lst[j][i]=None

def chain(lst,h,w,k):
    sm=0
    for j in range(h):
        train=1
        for i in range(w-1):
            if not lst[j][i] :
                train=1
                continue
            if lst[j][i]==lst[j][i+1]:
                train+=1
            else :
                if train>=k:
                    sm+=lst[j][i]*train
                    lst[j][i-train+1:i+1]=[None]*train
                train=1
        if train>=k:
            sm+=lst[j][-1]*train
            lst[j][-train:]=[None]*train
    return sm


def procedure(lst,h,w,k,x):
    lst[x[0]][x[1]]=None
    drop(lst,h,w)
    sm=0
    i=0
    point=chain(lst,h,w,k)
    while point:
        sm+=(2**i)*point
        drop(lst,h,w)
        point=chain(lst,h,w,k)
        i+=1
        #print(lst)
    return sm


def main():
    h,w,k=map(int,input().split())
    lst=[[int(x) for x in input()] for _ in range(h)]
    mx=0

    for i in range(1,h):
        for j in range(w):
            work=[[lst[i][j] for j in range(w)] for i in range(h)]
            sm=procedure(work,h,w,k,(i,j))
            if mx<sm : mx=sm
    print(mx)


main()
### BUGGY CODE ###

n, m, k = input().split()
a = input().split()
b = input().split()

n = int(n)
m = int(m)
k = int(k)
a = list(map(int, a))
b = list(map(int, b))

ans = 0

for i_a in range(n+1):
  if sum(a[0:i_a])>k:
    break
  for i_b in range(m+1):
    if sum(a[0:i_a]) + sum(b[0:i_b]) <= k:
      ans = max(ans, len(a[0:i_a]) + len(b[0:i_b]))
    else:
      continue

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 a[i] + b[j] > k:
    j -= 1
  ans = max(ans, i+j)

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

from sys import exit

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

S = input()

AC = []
for i in range(len(S) - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        AC.append(i)

l = []
r = []

for i in range(Q):
    li, ri = map(int, input().split())
    l.append(li)
    r.append(ri)

for i in range(Q):
    count = 0
    for ac in AC:
        if ac < l[i] - 1 or r[i] - 1 < ac + 1:
            count += 1
    print(len(AC) - count)


### FIXED CODE ###

from sys import exit

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

S = input()

AC = [0] * N

c = 0

for i in range(N - 1):
    if S[i] == 'A' and S[i + 1] == 'C':
        c += 1
    AC[i + 1] = c

for _ in range(Q):
    li, ri = map(int, input().split())
    print(AC[ri - 1] - AC[li - 1])
### BUGGY CODE ###

from collections import deque
N,M = map(int,input().split())
E = [[] for _ in range(N+1)]
for i in range(M):
    x,y,z = map(int,input().split())
    E[x].append(y)
    E[y].append(x)

d = [-1]*(N+1)

def dfs(start,num):
    q = deque([start])
    while(q):
        v = q.pop()
        if(d[v] == -1):
            d[v] = num
        for s in E[v]:
            if(d[s] == -1):
                q.append(s)

group_num = 0
for i in range(1,N+1):
    if(d[i] == -1):
        group_num += 1
        dfs(i,group_num)

print(group_num) 

### FIXED CODE ###

from collections import deque
N,M = map(int,input().split())
E = [[] for _ in range(N+1)]
for i in range(M):
    x,y,z = map(int,input().split())
    E[x].append(y)
    E[y].append(x)

d = [-1]*(N+1)

def dfs(start,num):
    q = deque([start])
    d[start] = num
    while(q):
        v = q.pop()
        for s in E[v]:
            if(d[s] == -1):
                d[s] = num
                q.append(s)

group_num = 0
for i in range(1,N+1):
    if(d[i] == -1):
        group_num += 1
        dfs(i,group_num)

print(group_num)
### BUGGY CODE ###

#import
#import math
import numpy as np
#= int(input())
#= input()
N, W = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

x = [list(map(int, input().split())) for _ in range(N)]

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

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dpi = dp[i]
        dpim = dp[i-1]
        if x[i - 1][0] <= j:
            dpi[j] = max(dpim[j], dpim[j - x[i - 1][0]] + x[i - 1][1])
        else:
            dpi[j] = dpim[j]

print(dp[-1][W])


### FIXED CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, W = map(int, input().split())
#= list(map(int, input().split()))
#= [input(), input()]

x = [list(map(int, input().split())) for _ in range(N)]

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

for i in range(1, N + 1):
    for j in range(1, W + 1):
        dp[i][j] = dp[i - 1][j]
        if i != 0 and x[i - 1][0] <= j:
            dp[i][j] = max(dp[i][j], dp[i-1][j-x[i-1][0]] + x[i-1][1])

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

from collections import Counter

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

c = Counter(a)
nu = {k for k, v in c.items() if v > 1}

s = set()
for aa in a:
    m = 2
    while aa*m <= 10**6:
        s.add(aa*m)
        m += 1

o = 0
for aa in a:
    if aa in s or aa in nu:
        continue
    o += 1

print(o)


### FIXED CODE ###

from collections import Counter

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

c = Counter(a)
nu = {k for k, v in c.items() if v > 1}

s = set()
u = set()
for aa in a:
    m = 2
    if aa in s or aa in u:
        continue
    u.add(aa)
    while aa*m <= mx:
        s.add(aa*m)
        m += 1

o = 0
for aa in a:
    if aa in s or aa in nu:
        continue
    o += 1

print(o)
### BUGGY CODE ###

N = int(input())
ans = 0
for i in range(1, N):
    ans += i
print(ans)

### FIXED CODE ###

N = int(input())
n = N - 1

ans = n * (n + 1) // 2
print(ans)
### BUGGY CODE ###

# C
n = int(input())
l = list(map(int, input().split()))

m = 0
for i in range(1, 10**5):
    if m < l.count(i-1)+l.count(i)+l.count(i+1):
        m = l.count(i-1)+l.count(i)+l.count(i+1)
        
print(m)

### FIXED CODE ###

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

l = [0]*(10**5+10)
for i in range(n):
    l[a[i]] += 1
    
s = 0
for j in range(1, len(l)-1):
    if  s < l[j-1] + l[j] + l[j+1]:
        s = l[j-1] + l[j] + l[j+1]
        
print(s)
### BUGGY CODE ###

def match(c1, c2):
    return c1 == '?' or c1 == c2 or '?' == c2

a = input()
b = input()
c = input()
A, B, C = len(a), len(b), len(c)
ab, bc, ac = [1] * 120000, [1] * 120000, [1] * 120000

for i in range(A):
    for j in range(B):
        if not match(a[i], b[j]):
            ab[i-j+6000]= 0
for i in range(B):
    for j in range(C):
        if not match(b[i], c[j]):
            bc[i-j+6000]= 0
for i in range(A):
    for j in range(C):
        if not match(a[i], c[j]):
            ac[i-j+6000]= 0
ans = 6000

for i in range(-4000, 4000):
    for j in range(-4000, 4000):
        if ab[i+6000] and bc[j-i+6000] and ac[j+6000]:
            L = min(0, min(i, j))
            R = max(A, max(B+i, C+j))
            ans = min(ans, R-L)
print(ans)
    

### FIXED CODE ###

a = input()
b = input()
c = input()
A, B, C = len(a), len(b), len(c)
ab, bc, ac = [1] * 16000, [1] * 16000, [1] * 16000

for i in range(A):
    if a[i] == '?':
        continue
    for j in range(B):
        if b[j] != '?' and a[i] != b[j]:
            ab[i-j+8000]= 0
for i in range(B):
    if b[i] == '?':
        continue
    for j in range(C):
        if c[j] != '?' and b[i] != c[j]:
            bc[i-j+8000]= 0
for i in range(A):
    if a[i] == '?':
        continue
    for j in range(C):
        if c[j] != '?' and a[i] != c[j]:
            ac[i-j+8000]= 0
ans = 6000

for i in range(-4000, 4000):
    for j in range(-4000, 4000):
        if ab[i+8000] and bc[j-i+8000] and ac[j+8000]:
            L = min(0, min(i, j))
            R = max(A, max(B+i, C+j))
            ans = min(ans, R-L)
print(ans)
### BUGGY CODE ###

a = int(input())
b = list(map(int, input().strip().split()))
prod = 1
for i in range(a):
  prod *= b[i]
if prod > 10**18:
  print(-1)
else:
  print(prod)

### FIXED CODE ###

n = int(input())
ar = list(map(int,input().split()))
ans = 1
z = 0
p = 0
for i in ar:
    if ans != -1:
        ans *= i
    if i == 0:
        z+=1
    if ans > 1e18:
        ans = -1
if z:
    ans = 0
print(ans)
### BUGGY CODE ###

n = int(input())
strings = []
answer = 0
for i in range(n):
  string = input()
  string = sorted(string)
  strchar=[string['char'] for string in strings]
  if string not in strchar:
    strings.append(dict(char=string, num=0))
  else:
    strchar=[strn for strn in strings if string == strn['char']]
    strchar[0]['num'] = strchar[0]['num'] + 1
    answer = answer + strchar[0]['num']
print(answer)

### FIXED CODE ###

n = int(input())
strings = {}
answer = 0
for i in range(n):
  string = input()
  string = ''.join(sorted(string))
  if string not in strings:
    strings[string]=1
  else:
    answer += strings[string]
    strings[string] += 1
print(answer)
### BUGGY CODE ###

n=int(input());a=map(int,input().split());b,c,f=[],[],0
for i,q in enumerate(a):b+=i+q,;c+=i-q,
from collections import*
for d,e in Counter(b).items():f+=e*Counter(c)[d]
print(f)

### FIXED CODE ###

n,*a=map(int,open(0).read().split())

# mx=n*(n-1)//2
# n <=2*10**5
from collections import Counter
b=[]
c=[]
for i,q in enumerate(a):
    b.append(i+q)
    c.append(i-q)
# print(b,c)
bb=Counter(b).items()
cc=Counter(c)

# print(bb,cc)
ans=0
for (bi,bj) in bb:
    ans+=bj*cc[bi]
print(ans)
### BUGGY CODE ###

n,m=map(int,input().split())
u,v=[],[]
path=[[] for i in range(n)]
for i in range(m):
    ui,vi=[int(x)-1 for x in input().split()]
    path[ui].append(vi)
    # path[vi].append(ui)
s,t=[int(x)-1 for x in input().split()]
from collections import deque
q=deque()
q.append((s,0))
# print(path)
check=[False]*n
while q:
    # print(q)
    p,num=q.popleft()
    if num%3!=0:
        for i in path[p]:
            q.append((i,num+1))
        continue
    elif p==t:
        print(num//3)
        import sys
        sys.exit()
    elif check[p]==True:
        continue
    else:
        for i in path[p]:
            q.append((i,num+1))
        check[p]=True
print(-1)

### FIXED CODE ###

n,m=map(int,input().split())
u,v=[],[]
path=[[] for i in range(n)]
for i in range(m):
    ui,vi=[int(x)-1 for x in input().split()]
    path[ui].append(vi)
    # path[vi].append(ui)
s,t=[int(x)-1 for x in input().split()]
from collections import deque
q=deque()
q.append((s,0))
# print(path)
check=[[False]*n for x in [0,1,2]]
while q:
    # print(q)
    p,num=q.popleft()
    if check[num%3][p]==True:
        continue
    if num%3!=0:
        for i in path[p]:
            q.append((i,num+1))
        check[num%3][p]=True
        continue
    elif p==t:
        print(num//3)
        import sys
        sys.exit()
    else:
        for i in path[p]:
            q.append((i,num+1))
        check[0][p]=True
print(-1)
### BUGGY CODE ###

#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
n,a,b = LI()
ans = [min(a,b),max(0,a+b-n)]
print(ans[0],ans[1])
"""

#B
"""
n = II()
a = S()
b = S()
c = S()
ans = 0
for i in range(n):
    if a[i] == b[i]:
        if b[i] == c[i]:
            continue
        else:
            ans += 1
    else:
        if b[i] == c[i] or c[i] == a[i]:
            ans += 1
        else:
            ans += 2
print(ans)
"""

#C
n = II()
c = LIR(n)
a = []
lis = [True for i in range(n)]
for i in range(n):
    a.append(c[i]+[i])
a.sort(key = lambda x:-x[0]-x[1])
count = 0
ans = 0
i = 0
while count < n:
    x,y,z = a.pop(0)
    if lis[z]:
        count += 1
        i ^= 1
        lis[z] = False
        if i == 1:
            ans += x
        else:
            ans -= y
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


### FIXED CODE ###

#!usr/bin/env python3
from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A
"""
n,a,b = LI()
ans = [min(a,b),max(0,a+b-n)]
print(ans[0],ans[1])
"""

#B
"""
n = II()
a = S()
b = S()
c = S()
ans = 0
for i in range(n):
    if a[i] == b[i]:
        if b[i] == c[i]:
            continue
        else:
            ans += 1
    else:
        if b[i] == c[i] or c[i] == a[i]:
            ans += 1
        else:
            ans += 2
print(ans)
"""

#C
n = II()
c = LIR(n)
c.sort(key = lambda x:-x[0]-x[1])
ans = 0
i = 0
for i in range(n):
    x,y = c.pop(0)
    if i%2 == 0:
        ans += x
    else:
        ans -= y
print(ans)

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T
### BUGGY CODE ###

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

ans = [0 for i in range(n)]
c = 0
for i in range(n) :
  c += 1
  for j in range(n) :
    if a[j] == c :
      ans[c-1] = j + 1
      break

print(*ans)

### FIXED CODE ###

import numpy as np

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

ans = np.argsort(a)
ans += 1

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

import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
l=[]
for i in range(m):
    b,c=map(int,input().split())
    l+=[c]*b
l.sort()
l=l[::-1]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

print(ans)

### FIXED CODE ###

import sys
imput=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
y=[list(map(int,input().split()))[::-1] for i in range(m)]
y.sort()
y=y[::-1]
#print(y)

l=[]
w=0
for i in range(m):
    w+=y[i][1]
    l+=[y[i][0]]*y[i][1]
    if w>=n:
        break

#print(l)
l=l[:n]
ans=0
#print(a,l)
for i in range(n):
    if i<=len(l)-1:
        ans+=max(a[i],l[i])
    else:
        ans+=a[i]

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

K,N=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A.append(A[0]+K)
i=0
c=[]
for i in range(N):
    b=A[i+1]-A[i]
    c=c+[b]
print(K-max(c))


### FIXED CODE ###

K,N=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
A.append(A[0]+K)
i=0
b=0
for i in range(N):
    if b<A[i+1]-A[i]:
        b=A[i+1]-A[i]
print(K-b)
### BUGGY CODE ###

N = int(input())
B = input()
B_1 = B.count("1")
mod_p1 = int(B,2) % (B_1+1)
if B_1 != 1:
    mod_m1 = int(B,2) % (B_1-1)

def calc_small(n, iter):
    iter += 1
    mod = n % bin(n).count("1")

    if mod == 0:
        return iter
    else:
        return calc_small(mod, iter)


for i in range(N):
    if B_1 == 1 and int(B[i]) == 1:
        print(0)
        continue
    mod = (mod_m1 - (2**(N-i-1))) % (B_1-1) if int(B[i]) == 1 else (mod_p1 + (2**(N-i-1))) % (B_1+1)
    iter = 1
    if mod == 0:
        print(iter)
    else:
        print(calc_small(mod, iter))

### FIXED CODE ###

N = int(input())
B = input()

B_1 = B.count("1")
mod_p1 = int(B,2) % (B_1+1)
if B_1 != 1:
    mod_m1 = int(B,2) % (B_1-1)

def calc_small(n, iter):
    iter += 1
    mod = n % bin(n).count("1")

    if mod == 0:
        return iter
    else:
        return calc_small(mod, iter)

for i in range(N):
    if B_1 == 1 and int(B[i]) == 1:
        print(0)
        continue
    mod = (mod_m1 - pow(2,N-i-1,B_1-1)) % (B_1-1) if int(B[i]) == 1 else (mod_p1 + pow(2,N-i-1,B_1+1)) % (B_1+1)
    iter = 1
    if mod == 0:
        print(iter)
    else:
        print(calc_small(mod, iter))
### BUGGY CODE ###

n = int(input())

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    ans = 0
    for j in range(i, n-1):
        for k in range(10**8):
            tmp = s[j] + f[j] * k
            if ans <= tmp:
                ans = tmp + c[j]
                break
    else:
        print(ans)

print(0)

### FIXED CODE ###

n = int(input())

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

anss =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        k = 0
        while 1:
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
            else:
                k += 1
    else:
        anss.append(tmp)
else:
    anss += [0]

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

n = int(input())
x = [input() for i in range(n)]
i = 0
count, yo, list_yo = [], [], []

while not(x == []):
  a = x.count(x[i])
  count.append(a)
  yo.append(x[i])
  x.remove(x[i])
  if len(x) < max(count):
    break
  
for k, c in enumerate(count):
  if c == max(count):
    list_yo.append(yo[k])

list_yo.sort()
for i in range(len(list_yo)):
   print(list_yo[i])



### FIXED CODE ###

import collections
n = int(input())
s = [input() for i in range(n)]
s = collections.Counter(s)
m = 0
ans = []

for i in s.values():
  m = max(m,i)

for k, j in s.items():
  if j == m:
    ans.append(k)
ans.sort()

for i in range(len(ans)):
  print(ans[i])
#print(*ans, sep = "\n")
### BUGGY CODE ###

n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
f=[]
for x in l:
	f.append(x[0]==x[1])
l=f.copy()
i=0
while i<n:
	j=0
	while i+j<n and l[i+j]==l[i] and l[i]:
		j+=1 
	if j>2:
		print('Yes')
		break	
	i+=j
else:
	print('No')
	

### FIXED CODE ###

n=int(input())
l=[list(map(int,input().split())) for _ in range(n)]
f=[]
for x in l:
	f.append(x[0]==x[1])
l=f.copy()
i=0
while i<n:
	j=1
	while i+j<n and l[i+j]==l[i] and l[i]:
		j+=1 
	if j>2:
		print('Yes')
		break	
	i+=j
else:
	print('No')
### BUGGY CODE ###

n = int(input())


import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
x = prod(map(int, input().split()))

if x > 1000000000000000000:
    print(-1)
else:
    print(x)


### FIXED CODE ###

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

x = 1
flag = False
INF = 10**18
if 0 in a:
    print(0)
else:
    for i in range(n):
        if flag == False:
            x *= a[i]
        if x > INF:
            flag = True
    
    if flag:
        print(-1)
    else:
        print(x)