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

N,M = map(int,input().split())
L = []
for _ in range(M):
    a,b = map(int,input().split())
    L.append([a,b])
L = sorted(L,key = lambda x:x[1])
cnt = 0
while len(L):
    now = L.pop(0)
    cnt += 1
    while len(L):
        if L[0][0] <= now[1] - 0.5 and now[1] - 0.5  <= L[0][1]:
            L.pop(0)
        else:
            break
print(cnt)





### FIXED CODE ###

N,M = map(int,input().split())
L = []
for _ in range(M):
    a,b = map(int,input().split())
    L.append([a,b])
L = sorted(L,key = lambda x:x[1])
cnt = 0
while len(L):
    now = L.pop(0)
    cnt += 1
    while len(L):
        if L[0][0] <= now[1] - 0.5 and now[1] - 0.5  <= L[0][1]:
            L.pop(0)
        else:
            break
print(cnt)
### BUGGY CODE ###

from numpy import array, sum, argmax

N,M = list(map(int,input().split()))
A = array([int(i) for i in input().split()])

for i in range(M):
  #print(A)
  idx = argmax(A)
  A[idx] >>= 1

print(sum(A))


### FIXED CODE ###

import heapq

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

#print(A_tmp)
A = [-i for i in A_tmp]

heapq.heapify(A)
#print(A)

for i in range(M):
  tmp = heapq.heappop(A)
  heapq.heappush(A, -(-tmp // 2))
  #print(A)

print(-sum(A))
### BUGGY CODE ###

a,b = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
if b >= a:
    print(0)
else:
    for i in range(b):
        del lis[0]
    s = sum(lis)
    print(s)

### FIXED CODE ###

a,b = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort(reverse=True)
print(sum(lis[b:]))
### BUGGY CODE ###

import math

N,M = map(int,input().split(' '))
An = [ int(input()) for _ in range(M)]

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

def one_two_comb(N):
    two_n = N//2
    comb_list = []
    for i in range(1,two_n+1):
        comb_list.append([N-i,i])
    return comb_list

def sum_comb(comb_list):
    comb_sum = 0
    for val in comb_list:
        comb_sum += combinations_count(val[0],val[1])
    return comb_sum
    

diff_list = []
current_num = 0
for a in An:
    diff = a - current_num
    if diff == 0:
        print(0)
        exit(0)
    diff_list.append(diff)
    current_num = a +1
diff = N+1 - current_num
diff_list.append(diff)
#print(diff_list)

all_sum = 1
for idx,diff in enumerate(diff_list):
    if idx == 0 or len(diff_list):
        diff -= 1
    '''
    else:
        diff -= 2
    '''

    if diff == 0:
        all_sum *= 1
    else:
        internal_comb_list = one_two_comb(diff)
        comb_count = sum_comb(internal_comb_list) + 1
        all_sum *= comb_count
print(all_sum%(10**9+7))






### FIXED CODE ###

import math

N,M = map(int,input().split(' '))
An = [ int(input()) for _ in range(M)]

'''
factorial_list = [1] * (N+1)
for i in range(1,N+1):
    factorial_list[i] = factorial_list[i-1] * i

def combinations_count(n, r):
    return factorial_list[n] // (factorial_list[n - r] * factorial_list[r])
'''

feruma_list = [1] * (N+1)
for i in range(2,N+1):
    feruma_list[i] = feruma_list[i-2] + feruma_list[i-1]


def nCk(n, k):
    ret = 1
    mo = 10**9 + 7
    for i in range(k):
        ret = ret * (n - i) * pow(i + 1, mo - 2, mo) % mo
    return ret

def one_two_comb(N):
    two_n = N//2
    comb_list = []
    for i in range(1,two_n+1):
        comb_list.append([N-i,i])
    return comb_list

def sum_comb(comb_list):
    comb_sum = 0
    for val in comb_list:
        comb_sum += nCk(val[0],val[1])
    return comb_sum
    

diff_list = []
current_num = 0
max_diff = -1
for a in An:
    diff = a - current_num
    if diff == 0:
        print(0)
        exit(0)
    diff_list.append(diff)
    current_num = a +1
diff = N+1 - current_num
diff_list.append(diff)
#print(diff_list)


all_sum = 1
for idx,diff in enumerate(diff_list):
    
    if idx == 0 or len(diff_list):
        diff -= 1
    '''
    if diff == 0:
        all_sum *= 1
    else:
        internal_comb_list = one_two_comb(diff)
        comb_count = sum_comb(internal_comb_list) + 1
        if all_sum > 10**9+7:
            all_sum = all_sum%(10**9+7)
        all_sum *= comb_count
    '''

    comb_count = feruma_list[diff]
    if all_sum > 10**9+7:
        all_sum = all_sum%(10**9+7)
    all_sum *= comb_count

print(all_sum%(10**9+7))
### BUGGY CODE ###

#!/usr/bin/env python3

import math
x = int(input())

#aもbも0以上のとき
border = 1;
while border ** 5 - (border - 1) ** 5 < x:
    border += 1

for i in range(border + 1):
    aa = ((x + i ** 5) ** (1.0 / 5.0)) #仮
    if aa % 1 == 0:
        a = int(aa)
        b = i
        print(a, b)
        break
else:
    while True:
        b = -1
        aa = ((x + b ** 5) ** (1.0 / 5.0))  # 仮
        if aa % 1 == 0:
            a = int(aa)
            print(a, b)
            break
        if x < b:
            break
        b -= 1




### FIXED CODE ###

#!/usr/bin/env python3

import math
x = int(input())

#aもbも0以上のとき
border = 1;
while border ** 5 - (border - 1) ** 5 < x:
    border += 1

for i in range(border + 1):
    aa = ((x + i ** 5) ** (1.0 / 5.0)) #仮
    a = round(aa)
    if a ** 5 - i ** 5 == x:
        b = i
        print(a, b)
        break
else:
    b = -1

    while x + b ** 5 >= 0:

        aa = ((x + b ** 5) ** (1.0 / 5.0))  # 仮
        a = round(aa)
        if a ** 5 - b ** 5 == x:
            print(a, b)
            break
        b -= 1
### BUGGY CODE ###

import hashlib

n = int(input())
s = input()


objects = []
l = [[] for i in range(n//2+1)]


for i in range(n):
    objects.append(hashlib.md5())


for size in range(1, n//2+1):
    for i in range(n - size + 1):
        h = objects[i]
        h.update(s[i].encode())
        l[size].append(h.hexdigest())


def output():
    for size, li in zip(reversed(range(n//2+1)), reversed(l)):
        hashes = set()
        for h in li:
            if h in hashes:
                return size
            hashes.add(h)

    return 0

print(output())

### FIXED CODE ###

import hashlib

n = int(input())
s = input()


def output():
    left, right = 0, n//2+1
    while left < right-1:
        mid = (left+right)//2
        if check(mid):
            left = mid
        else:
            right = mid
    return left


def check(x):
    hashes = set()
    for i in range(n - 2*x + 1):
        hashes.add(s[i: i+x])
        if s[i+x: i+2*x] in hashes:
            return True
    return False


print(output())
### BUGGY CODE ###

N = int(input())
X = list(map(int,input().split()))
Y = []

for i in range(N):
    Y = sorted(X[:i]+X[i+1:])
    #print(Y)
    print(Y[len(Y)//2])

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
Y = sorted(X)

m1=Y[N//2-1]
m2=Y[N//2]

medians = [m2 if x < m2 else m1 for x in X]
print('\n'.join(map(str,medians)))
### BUGGY CODE ###

# row = [int(x) for x in input().rstrip().split(" ")]
# n = int(input().rstrip())
# s = input().rstrip()

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

    n = input().rstrip()
    a_list = [int(x) for x in input().rstrip().split(" ")]

    import itertools

    c = itertools.combinations(a_list, 2)

    x = 1000000007

    ans = 0
    for v in c:
        ans += v[0] * v[1]
        ans = ans % x

    print(ans)

if __name__ == "__main__":
    resolve()


### FIXED CODE ###

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

    n = input().rstrip()
    past_a = 0

    ans = 0
    for a in input().rstrip().split(" "):
        a = int(a)
        ans += a * past_a
        past_a += a

    x = 1000000007

    ans = ans % x

    print(ans)

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

N=int(input())
num = 7
plus = 70
i=1
a=[]

while num%N!=0:
    if num%N in a:
        i=-1
        break
    a.append(num%N)
    num+=plus
    plus*=10
    i+=1
    if i>N:
        i=-1
        break
print(i)

### FIXED CODE ###

N=int(input())
num = 7
i=1
a=[]
prir1=1
while i<=N:
    xx=num%N
    if xx==0:
        print(i)
        prir1=0
        break
    num=10*xx+7
    i+=1
if prir1:
    print(-1)
### BUGGY CODE ###

# 無限回試行できる時、Kの最小値を最大化する問題
s = input()
now = s[0]
cnt = 1
use = []
for i in range(1,len(s)):
    if now == s[i]:
        cnt += 1
    else:
        use.append(cnt)
        cnt = 1
        now = s[i]
use.append(cnt)

min_prob = len(s)
sum_s = sum(use)
def ketsugou(l):
    global min_prob
    global sum_s
    #一番小さいやつをくっつけていく
    m = l.index(min(l))
    if m == 0 or m == len(l) - 1:
        s1 = l[m]
        s2 = sum_s - l[m]
        min_prob = min(min_prob, max(s1, s2))
        if m == 0:
            l.pop(0)
            l[0] += s1
        else:
            l.pop()
            l[-1] += s1
    else:
        s1 = sum(l[:m])
        s2 = s1 + l[m]
        s3 = sum_s - s1
        s4 = sum_s - s2
        min_prob = min(min_prob, max(s1, s2,s3,s4))
        if l[m - 1] < l[m + 1]:
            l[m - 1] += l[m]
        else:
            l[m + 1] += l[m]
        l.pop(m)
while(len(use) > 1):
    ketsugou(use)
print(min_prob)


### FIXED CODE ###

# 無限回試行できる時、Kの最小値を最大化する問題
s = input()
now = s[0]
cnt = 1
use = []
for i in range(1,len(s)):
    if now == s[i]:
        cnt += 1
    else:
        use.append(cnt)
        cnt = 1
        now = s[i]
use.append(cnt)

min_prob = len(s)
sum_s = sum(use)
def ketsugou(l):
    global min_prob
    global sum_s
    #一番小さいやつをくっつけていく
    m = l.index(min(l))
    if m == 0 or m == len(l) - 1:
        s1 = l[m]
        s2 = sum_s - l[m]
        min_prob = min(min_prob, max(s1, s2))
        if m == 0:
            l = l[1:]
            l[0] += s1
        else:
            l.pop()
            l[-1] += s1
    else:
        s1 = sum(l[:m])
        s2 = s1 + l[m]
        s3 = sum_s - s1
        s4 = sum_s - s2
        min_prob = min(min_prob, max(s1, s2,s3,s4))
        if l[m - 1] < l[m + 1]:
            l[m - 1] += l[m]
        else:
            l[m + 1] += l[m]
        l.pop(m)
#while(len(use) > 1):
#    ketsugou(use)
sum_ss = 0
for i in range(len(use)):
    sum_ss += use[i]
    min_prob = min(min_prob, max(sum_s - sum_ss, sum_ss))

print(min_prob)
### BUGGY CODE ###

n, k = map(int,input().split())

if k == 1:
    print(0)
    exit()
while n >= abs(n-k):
    n = abs(n-k)
    
print(n)

### FIXED CODE ###

n, k = map(int,input().split())
print(min(n%k, k - n%k))
### BUGGY CODE ###

from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

n, k = map(int, input().split())
intensity = list(map(int, stdin.readline().split()))

count = 0
while count < k:
    totsum = 0
    prefs = [0]*n
    for i in range(n):
        if intensity[i]!=0:
            l = i - intensity[i]
            r = i + intensity[i] + 1

            prefs[max(l, 0)] += 1
            if r <= n-1: 
                prefs[r] += -1

    for i in range(1, n):
        prefs[i] += prefs[i-1]
        totsum += prefs[i]
    
    for i in range(n):
        if intensity[i] == 0:
            prefs[i] += 1
            totsum += 1
    
    if totsum == n*k:
        print(*prefs)
        exit()
    
    intensity = prefs
    count += 1

print(*prefs)

### FIXED CODE ###

from sys import stdin
# from collections import defaultdict as dd
# from collections import deque as dq
# import itertools as it
# from math import sqrt, log, log2
# from fractions import Fraction

n, k = map(int, input().split())
intensity = list(map(int, stdin.readline().split()))

count = 0
while count < k:
    totsum = 0
    prefs = [0]*n
    zeros = []
    for i in range(n):
        l = i - intensity[i]
        r = i + intensity[i] + 1

        prefs[max(l, 0)] += 1
        if r <= n-1: 
            prefs[r] += -1
            
    for i in range(1, n):
        prefs[i] += prefs[i-1]
        totsum += prefs[i]
    
    if sum(prefs) == n*n:
        print(*prefs)
        exit()
    
    intensity = prefs
    count += 1

print(*prefs)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(100000)
I=lambda:map(int,input().split())
n,m=I()
g=[[]for _ in range(n+1)]
v=[1 for _ in range(n+1)]
v[1]=0

for _ in range(m):
  a,b=I()
  g[a].append(b)
  g[b].append(a)

def dfs(x):
  for j in g[x]:
    if v[j]:
      v[j]=0
      return dfs(j)+[j]
      break
  else:
    return []
z=dfs(1)+[1]+dfs(1)[::-1]
print(len(z))
print(*z)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
I=lambda:map(int,input().split())
n,m=I()
g=[set() for _ in range(n+1)]
v=[1 for _ in range(n+1)]
v[1]=0

for _ in range(m):
  a,b=I()
  g[a].add(b)
  g[b].add(a)

def dfs(x):
  for j in g[x]:
    if v[j]:
      v[j]=0
      l=dfs(j)
      l.append(j)
      return l
      break
  else:
    return []
z=dfs(1)+[1]+dfs(1)[::-1]
print(len(z))
print(*z)
### BUGGY CODE ###

#Pythonだと少し間に合わない
N = int(input())

x = (3500 * N + (4 * 2500 - 2 * N) - 1) //(4 * 2500 - 2 * N)
for h in range(1, x + 2):
    for n in range(1, 3501):
        if (N * h * n) >= (4 * h * n - N * (h + n)) > 0:
            if (N * h * n) % (4 * h * n - N * (h + n)) == 0:
                w = (N * h * n) // (4 * h * n - N * (h + n))
                print (h, n, w)
                exit()


### FIXED CODE ###

N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        if (N * h * n) >= (4 * h * n - N * (h + n)) > 0:
            if (N * h * n) % (4 * h * n - N * (h + n)) == 0:
                w = (N * h * n) // (4 * h * n - N * (h + n))
                print (h, n, w)
                exit()
### BUGGY CODE ###

N,M=map(int, input().split())
a_list=[]
for i in range(M):
    a_list.append(list(map(int,input().split())))
V_list=[]
for i in range(1,N+1) :
    i_list=[]
    for item in a_list :
        if item[0]==i :
            i_list.append(item[1])
        elif item[1]==i :
            i_list.append(item[0])
    V_list.append(i_list)

from collections import deque
s_list=[0]*N
current_V=deque()
current_V.append(1)

while (current_V!=deque([])) :
    a=current_V.popleft()
    current_list=V_list[a-1]
    for item in current_list :
        if s_list[item-1]==0 :
            current_V.append(item)
            s_list[item-1] =a
print('Yes')
for item in s_list[1:] :
    print(item)

### FIXED CODE ###

N,M=map(int, input().split())
a_list=[]
for i in range(M):
    a_list.append(list(map(int,input().split())))
V_list=[[] for i in range(N)]

for item in a_list :
    V_list[item[0]-1].append(item[1])
    V_list[item[1] - 1].append(item[0])

from collections import deque
s_list=[0]*N
current_V=deque()
current_V.append(1)

while (current_V!=deque([])) :
    a=current_V.popleft()
    current_list=V_list[a-1]
    for item in current_list :
        if s_list[item-1]==0 :
            current_V.append(item)
            s_list[item-1] =a
print('Yes')
for item in s_list[1:] :
    print(item)
### BUGGY CODE ###

import numpy as np
n = int(input())
a = np.array(sorted([int(i) for i in input().split()]))
b = np.array(sorted([int(i) for i in input().split()]))
c = np.array(sorted([int(i) for i in input().split()]))
cnt = 0
for ai in a:
  for bi in b:
    if bi <= ai:
      continue
    cnt += len(c[c > bi])
    # print(ai, bi, c[c > bi])
print(cnt)

### FIXED CODE ###

from bisect import bisect_left, bisect_right

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))
ba = [bisect_left(a, bi) for bi in b]
bc = [bisect_right(c, bi) for bi in b]
cnt = 0
for i in range(n):
    cnt += ba[i] * (n - bc[i])
print(cnt)
### BUGGY CODE ###

def main():
    import sys
    from collections import Counter
    S=sys.stdin.readline().strip()
    L=[0]*len(S)

    now=0
    for i in range(len(S)):
        now+=int(S[-i-1])*10**i
        L[-i-1]=now%2019

    dic=Counter(L)
    
    output=0
    for val in dic.values():
        if val!=1:
            output+=val*(val-1)//2
    
    output+=dic[0]
    print(output)

main()


### FIXED CODE ###

def pow_with_mod(x, n, m):
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
            K %= m
        x *= x
        x %= m
        n //= 2

    return (K * x) % m

def main():
    import sys
    S=sys.stdin.readline().strip()
    N=len(S)
    L=[0]*2019
    now=0
    for i in range(N):
        now+=int(S[-i-1])*pow_with_mod(10, i, 2019)
        now%=2019
        L[now]+=1  
    print(L[0]+sum([x*(x-1)//2 for x in L]))
main()
### BUGGY CODE ###

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

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in range(n):
  if ans in a[i:n]:
    ans += 1
    continue
  cnt += 1
  
print(cnt)

### FIXED CODE ###

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

ans = 1
cnt = 0

if ans not in a:
  print(-1)
  exit()
for i in a:
  if i == ans:
    ans += 1
    continue
  cnt += 1
  
print(cnt)
### BUGGY CODE ###

S = input()

ans = [0] * len(S)

for i in range(len(S)):
    if S[i] == 'R':
        for j in range(i+1, len(S)):
            if S[j] == 'L':
                if (j - i) % 2 == 0:
                    ans[j] += 1
                else:
                    ans[j-1] += 1
                break

    else:
        for j in range(i-1, -1, -1):
            if S[j] == 'R':
                if (i-j) % 2 == 0:
                    ans[j] += 1
                else:
                    ans[j+1] += 1
                break

print(*ans)


### FIXED CODE ###

S = input() + 'R'

ans = [0] * len(S)

cur = 'R'
cur_i = 0
points = []


for i in range(len(S)):
    if cur != S[i]:
        if S[i] == 'L':
            diff = i - cur_i
            if diff % 2 == 0:
                ans[i-1] += int(diff/2)
                ans[i] += int(diff/2)
            else:
                ans[i-1] += int((diff+1)/2)
                ans[i] += int((diff-1)/2)

            cur_i = i
            cur = 'L'

        if S[i] == 'R':
            diff = i - cur_i
            if diff % 2 == 0:
                ans[cur_i-1] += int(diff/2)
                ans[cur_i] += int(diff/2)
            else:
                ans[cur_i-1] += int((diff-1)/2)
                ans[cur_i] += int((diff+1)/2)

            cur_i = i
            cur = 'R'


print(*ans[:-1])
### BUGGY CODE ###

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

for i in range(n):
    a[i] = a[i] % (10**9 +7)

s = 0

for i in range(n-1):
    for j in range(i+1,n):
        s += a[i]*a[j]

print(s % (10**9 + 7))


### FIXED CODE ###

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

for i in range(n):
    sum += a[i]

for i in range(n-1):
    sum -= a[i]
    ans += a[i] * sum

print(ans % (10**9 + 7))
### BUGGY CODE ###

import sys
import numpy as np

# N K 操作回数、K番目の値
n, k = map(int, input().split())

# ai, bi  追加する整数 ai, 追加する数 bi
s = []
for i in range(n):
    s.append(list(map(int, input().split())))

num = []
for pr in s:
    for i in range(pr[1]):
        num.append(pr[0])

num.sort()

print(num[k-1])

### FIXED CODE ###

import sys
import numpy as np

# N K 操作回数、K番目の値
n, k = map(int, input().split())

# ai, bi  追加する整数 ai, 追加する数 bi
s = []
for i in range(n):
    s.append(list(map(int, input().split())))

# ai, bi の順にソート
s.sort()

number = 0
for s_item in s:
    # kの位置以上に来たか
    number += s_item[1]
    if number >= k:
        number_k = s_item[0]
        break

print(number_k)
### BUGGY CODE ###

import itertools

def main():
    N = int(input())
    S = input()
    id_l = [i for i in range(N)]

    ans = 0
    for v in itertools.permutations(id_l, 3):
        if v[0] < v[1] < v[2]:
            if (v[2] - v[1]) != (v[1] - v[0]):
                if (S[v[0]] != S[v[1]]) and (S[v[1]] != S[v[2]]) and (S[v[0]] != S[v[2]]):
                    ans += 1
    print(ans)

    return 0


if __name__ == '__main__':
    main()

### FIXED CODE ###

import math
import collections

def main():
    N = int(input())
    S = input()

    c = collections.Counter(S)
    c = c['R'] * c['G'] * c['B']

    count = 0
    for i in range(N):
        for j in range(i+1, N):
            k = 2*j-i
            if k < N:
                if (S[i] != S[j]) and (S[j] != S[k]) and (S[i] != S[k]):
                    count += 1

    print(c - count)

    return 0

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

MOD = 2019

L, R = [int(i) for i in input().strip().split()]

res = R*R
for i in range(L, R):
  for j in range(i+1, R+1):
    _, r = divmod(i*j, MOD)
    if r < res:
      res = r
print(res)


### FIXED CODE ###

MOD = 2019

L, R = [int(i) for i in input().strip().split()]

if (L // MOD) != (R // MOD):
  print(0)
else:
  res = R*R
  for i in range(L, R):
    for j in range(i+1, R+1):
      _, r = divmod(i*j, MOD)
      if r < res:
        res = r
  print(res)
### BUGGY CODE ###

N,M = map(int,input().split())
for i in range(M // N,0,-1):
    if M % i == 0:
        ans = i
        break
print(ans)

### FIXED CODE ###

import math as m
N,M = map(int,input().split())
# N == 1 の処理
if N == 1:
    print(M)
    exit()
# Mの素数判定
judge = "prime"
for i in range(m.floor(pow(M,1/2)),1,-1):
    if M % i == 0:
        judge = "conposite"
        break
if judge == "prime":
    print(1)
    exit()
for i in range(M // N,0,-1):
    if M % i == 0:
        print(i)
        exit()
### BUGGY CODE ###

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

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]


for b[0] in range(0,mi*2+1,2) :
    # print(x)
    # b[0] = x

    for i in range(1,n) :
        b[i] = 2 * a[i-1] - b[i-1]
        # print(b)
        if (b[i] < 0) : 
            break

    else :
        if (b[-1] + b[0] == 2 * a[-1]) :
            break


# s = str(b)
# for i in b :
#     s = s + str(i) + " " 

# print(s)
print(str(b).strip("[]").replace(",",""))

### FIXED CODE ###

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

b = [0] * n
if(a[0] > a[-1]) : mi = a[-1]
else : mi = a[0]

aa = 0
for i in range(1, n, 2) :
    aa += a[i]
b[0] = sum(a) - 2 * aa

for i in range(1,n) :
    b[i] = 2 * a[i-1] - b[i-1]
print(str(b).strip("[]").replace(",",""))
### BUGGY CODE ###

l=[0]*2019
l[0]=1
s,k=0,1
for c in reversed(input()):k*=10;s+=int(c)*k;l[s%2019]+=1
print(sum(v*(v-1)//2for v in l))

### FIXED CODE ###

m=2019
l=[0]*m
l[0]=1
s,k=0,1
for c in reversed(input()):k=k*10%m;s=(s+int(c)*k)%m;l[s]+=1
print(sum(v*(v-1)//2for v in l))
### BUGGY CODE ###

import sys

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

ans = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    ans *= A[i]
    if ans > 10 ** 18:
        ans = -1

print(ans)


### FIXED CODE ###

import sys

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

ans = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    ans *= A[i]
    if ans > 10 ** 18:
        ans = -1
        break

print(ans)