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

L,R = (int(i) for i in input().split())
ans=0
amari=2018
if L-R>=2018:
    print(ans)
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            if amari>=(i*j)%2019:
                amari=(i*j)%2019
    print(amari)

### FIXED CODE ###

L,R = (int(i) for i in input().split())
ans=0
amari=2018
if R-L>=2018:
    print(ans)
else:
    for i in range(L,R+1):
        for j in range(i+1,R+1):
            if amari>=(i*j)%2019:
                amari=(i*j)%2019
    print(amari)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Sep 30 09:02:42 2018
ABC111D
@author: maezawa
"""
import sys
input = sys.stdin.readline

n = int(input())
xy = []
for _ in range(n):
    xy.append(list(map(int, input().split())))
    
#print(xy)
m = 1
parity = sum(xy[0])%2
far = 0
for point in xy:
    length = sum(list(map(abs, point)))
    if length > far:
        far = length
    if length%2 != parity:
        m = -1

if m == -1:
    print(m)
else:
    if parity == 0:
        ds = [1,1]
    else:
        ds = [1,1,1]
    i = 1
    while i**2 < far:
        ds.append(2**i)
        i += 1
    ds.append(2**i)
    ds.reverse()
    print(len(ds))
    print(*ds, sep=' ')
    for point in xy:
        direction = ''
        point0 = [0,0]
        for arm in ds:
            x = point[0] - point0[0]
            y = point[1] - point0[1]
            if abs(x) > abs (y):
                if x > 0:
                    direction += 'R'
                    point0[0] += arm
                else:
                    direction += 'L'
                    point0[0] -= arm
            else:
                if y > 0:
                    direction += 'U'
                    point0[1] += arm
                else:
                    direction += 'D'
                    point0[1] -= arm
            #print(point0)
        print(direction)
                    
       

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Sep 30 09:02:42 2018
ABC111D
@author: maezawa
"""
import sys
input = sys.stdin.readline

n = int(input())
xy = []
for _ in range(n):
    xy.append(list(map(int, input().split())))
    
#print(xy)
m = 1
parity = sum(xy[0])%2
far = 0
for point in xy:
    length = sum(list(map(abs, point)))
    if length > far:
        far = length
    if length%2 != parity:
        m = -1

if m == -1:
    print(m)
else:
    if parity == 0:
        ds = [1,1]
    else:
        ds = [1,1,1]
    i = 1
    while 2**i < far:
        ds.append(2**i)
        i += 1
    ds.append(2**i)
    ds.reverse()
    print(len(ds))
    print(*ds, sep=' ')
    for point in xy:
        direction = ''
        point0 = [0,0]
        for arm in ds:
            x = point[0] - point0[0]
            y = point[1] - point0[1]
            if abs(x) > abs (y):
                if x > 0:
                    direction += 'R'
                    point0[0] += arm
                else:
                    direction += 'L'
                    point0[0] -= arm
            else:
                if y > 0:
                    direction += 'U'
                    point0[1] += arm
                else:
                    direction += 'D'
                    point0[1] -= arm
            #print(point0)
        print(direction)
### BUGGY CODE ###

import bisect

N,M = map(int, input().split())
A_list = list(map(int, input().split()))

A_list = sorted(A_list)
#print(A_list)

for i in range(M):
    val = A_list.pop()//2
    bisect.insort_left(A_list, val, lo=min(N-1, max(0,(N-M) + i)) )

print(sum(A_list))

### FIXED CODE ###

import heapq

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

heapq.heapify(A_list)

for i in range(M):
    heapq.heappush(A_list, ((heapq.heappop(A_list) * -1 )// 2) * -1)

print(sum(A_list) * -1)
### BUGGY CODE ###

i=input()
while True:
  if int(i[0])+int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
  elif int(i[0])+int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])+int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
  elif int(i[0])+int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
  elif int(i[0])-int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit

### FIXED CODE ###

i=input()
b=True
while b==True:
  if int(i[0])+int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])+int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])-int(i[2])-int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"-"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])+int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"+"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])+int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"+"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
  elif int(i[0])-int(i[1])-int(i[2])+int(i[3])==7:
    print(i[0]+"-"+i[1]+"-"+i[2]+"+"+i[3]+"="+"7")
    exit
    b=False
### BUGGY CODE ###

from operator import mul
from functools import reduce
n = int(input())
a = list(map(int,input().split()))
tmp = sorted(a)
M = 10**18

if 0 in a:
	print(0)
else:
	tmp = reduce(mul, a)
	if tmp > M:
		print(-1)
	else:
		print(tmp)
   

### FIXED CODE ###

n = int(input())
s = sorted(map(int,input().split()))
M = 10 ** 18
ans = 1
for ss in s:
	ans *= ss
	if ans > M:
		ans = -1
		break
	elif ans == 0:
		break
print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(1,n):
    for j in range(i,n+1):
        if j-i==a[i-1]+a[j-1]:
            ans+=1
print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
num1=[0]*(2*(10**5)+10)
num2=[0]*(2*(10**5)+10)
for i in range(n):
    if a[i]+i+1<2*(10**5)+5:
        num1[a[i]+i+1]+=1
    if a[i]+1<i+1:
        num2[-a[i]+i+1]+=1
ans=0
for i in range(len(num1)):
    ans+=num1[i]*num2[i]
print(ans)
### BUGGY CODE ###

N = int(input())

w = -1
flg = False
for h in range(1, 3500 + 1):
    for n in range(h, 3500 + 1):
        p = N * n * h
        q = 4 * n * h - N * (n + h)
        #print(h, n, p, q)
        if q != 0:#q == 0のとき、1/wなしで4/Nに一致するので不適（wは無限大になる）
            if p % q == 0:
                w = p // q
                if w > 0:
                    flg = True
                    break
    if flg:
        break
print(h, n, w)

### FIXED CODE ###

N = int(input())

w = -1
flg = False
for h in range(1, 3500 + 1):
    for n in range(h, 3500 + 1):
        q = 4 * n * h - N * (n + h)
        #print(h, n, p, q)
        if q > 0:
            #q == 0: 1/wなしで4/Nに等しくなり不適（w無限大）
            #q < 0: p > 0より、w < 0となり不適
            p = N * n * h
            if p % q == 0:
                w = p // q
                flg = True
                break
    if flg:
        break
print(h, n, w)
### BUGGY CODE ###

import sys

N, Q = map(int, input().split())
s = sys.stdin.readline().rstrip()
ac_list = []
start = 0
while True:
  index = s.find('AC', start)
  if index == -1:
    break
  ac_list.append([index + 1, index + 2])
  start = index + 1


for _ in range(Q):
  l, r = map(int, input().split())
  res = 0
  for a, c in ac_list:
    if l <= a and c <= r:
      res += 1
  print(res)

### FIXED CODE ###

import sys
import bisect

N, Q = map(int, input().split())
s = sys.stdin.readline().rstrip()
ac_list = []
start = 0
while True:
  index = s.find('AC', start)
  if index == -1:
    break
  ac_list.append(index + 1)
  start = index + 1


for _ in range(Q):
  l, r = map(int, input().split())
  res = 0
  start = bisect.bisect_left(ac_list, l)
  end = bisect.bisect_right(ac_list, r-1) - 1
  print(end-start+1)
### BUGGY CODE ###

n,m=map(int,input().split())
for i in range(n,m+1):
  if m%i==0:
    print(m//i)
    exit()
print(1)

### FIXED CODE ###

n,m=map(int,input().split())
yakusuu=[]
for i in range(1,int(m**0.5)+1):
  if m%i==0:
    yakusuu.append(m//i)
    if m//i==i:continue
    yakusuu.append(i)
ans=0
for y in yakusuu:
  if y<n:continue
  if m%y==0:
    ans=max(ans,m//y)
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

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

def ans(a):
    if 0 in a:
        return 0
    n = 1
    for i in a:
        n *= i
        if n > 10**18:
            return -1
    return n

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

A, B = map(int, input().split())
while A % B != 0:
	A, B = B, A % B
G = B
ans = 1
list = [2]
for i in range(3, G + 1):
	chk = True
	for j in list:
		if i % j == 0:
			chk = False
	if chk == True:
		list.append(i)
for k in list:
	if G % k == 0:
		G /= k
		ans += 1
print(ans)

### FIXED CODE ###

import collections
def prime_factorize(n):
	list = []
	while n % 2 == 0:
		list.append(2)
		n //= 2
	f = 3
	while f * f <= n:
		if n % f == 0:
			list.append(f)
			n //= f
		else:
			f += 2
	if n != 1:
		list.append(n)
	return list

A, B = map(int, input().split())
while A % B != 0:
	A, B = B, A % B
G = B
c = collections.Counter(prime_factorize(G))
print(len(list(c.keys())) + 1)
### BUGGY CODE ###

n,p = list(map(int,input().split()))
S = input()

if p == 2 or p == 5:
  ans = 0
  for i,c in enumerate(S):
    if int(c)%p == 0:
      ans += i+1
  print(ans)
  exit()

def MS(si):
  res = 0
  for i,s in enumerate(si):
    res += int(s)*(10**i)
  return res%p
  
  
s = [x for x in S]
M = [0]*p
for i,s in enumerate(S[::-1]):
  M[MS(S[::-1][:i+1])] += 1

M[0] += 1
ans = 0
for m in M:
  ans += (m*(m-1))//2
print(ans)



### FIXED CODE ###

n,p = list(map(int,input().split()))
S = input()

if p == 2 or p == 5:
  ans = 0
  for i,s in enumerate(S):
    if int(s)%p == 0:
      ans += i+1
  print(ans)
  exit()

def MS(i,s,pre):
  return (s*i +pre)%p
 
M = [0]*p
M[0] = 1
t = 1
now = 0
for i in S[::-1]:
    i = int(i)
    now += i*t
    now %= p
    M[now] += 1
    t = t*10%p

ans = sum(map(lambda m:(m*(m-1))//2, M))
print(ans)
### BUGGY CODE ###

def main():
    q = int(input())
    p_s = primes()
    is_like_2017 = is_like_2017_function(p_s)
    for _ in range(q):
        l, r = map(int, input().split(' '))
        count = 0
        for i in range(l, r+1, 2):
            if is_like_2017(i):
                count += 1
        print(count)


def is_like_2017_function(primes):
    def _f(num):
        if num in primes and ((num+1)//2) in primes:
            return True
        else:
            False
    return _f


def primes():
    MAX = 10**5
    result = [True] * MAX
    result[0] = False
    loop_max = int(MAX**0.5) + 1
    for i in range(loop_max):
        if result[i]:
            for j in range((i+1)*2 - 1, MAX, (i+1)):
                if (j+1) % (i+1) == 0:
                    result[j] = False
    return [i+1 for i, b in enumerate(result) if b]


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    q = int(input())
    p_s = primes()
    is_like_2017 = is_like_2017_function(p_s)

    counter = 0

    memo = [0] * (10**5+1)

    for i in range(0, 10**5+1):
        if is_like_2017(i):
            counter += 1
        memo[i] = counter

    for _ in range(q):
        l, r = map(int, input().split(' '))
        print(memo[r] - memo[l-1])


def is_like_2017_function(primes):
    def _f(num):
        if primes[num] and primes[(num+1)//2]:
            return True
        else:
            False
    return _f


def primes():
    MAX = 10**5+1
    result = [True] * MAX
    result[0] = False
    loop_max = int(MAX**0.5) + 1
    for i in range(loop_max):
        if result[i]:
            for j in range((i+1)*2 - 1, MAX, (i+1)):
                if (j+1) % (i+1) == 0:
                    result[j] = False
    return [False] + result


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

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n

t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    t = t * 10 % MOD

cnt = 0
for cr in range(n):
    cm = 0
    for cl in range(cr, n):
        cm = (cm + m[cl]) % MOD
        if cm == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

import copy

s = list(input())

s.reverse()
n = len(s)
MOD = 2019
m = [0] * n
msum = [0] * (n+1)
cnt = [0] * (MOD)
cnt[0] = 1
t = 1
for i in range(n):
    m[i] = int(s[i]) * t % MOD
    msum[i+1] = (msum[i] + m[i]) % MOD
    cnt[msum[i+1]] += 1
    t = t * 10 % MOD

ans = 0
for i in range(MOD):
    ans += cnt[i] * (cnt[i] - 1) // 2
print(ans)
### BUGGY CODE ###

from collections import* #defaultdict Counter deque appendleft
import sys
input=sys.stdin.readline  #危険！基本オフにしろ！

d=defaultdict(list)
n,m,p=map(int,input().split())

for s in range(m):
    a,b,c=map(int,input().split())
    d[a].append([b,c])

def BELLMANFORD(point,d,p):
    cost       = {node:-float("inf") for node in range(1,n+1)}
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.copy().items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p

    negative=[0]*n                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定 negativeの1は閉路に入っている部分を表す
        for now,lis in d.copy().items():
            for nex,c in lis:
                if negative[now-1]==1:
                    negative[nex-1]=1
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p
                    negative[now-1]=1
 
    return cost,negative

def main():
    x,y=(BELLMANFORD(1,d,p))
    if y[n-1]==1:
        print(-1)
    else:
        print(max(x[n],0))

    
if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline  #危険！基本オフにしろ！


n,m,p=map(int,input().split())

d={}
for s in range(m):
    a,b,c=map(int,input().split())
    if a in d:
        d[a].append((b,c))
    else:
        d[a]=[(b,c)]

#print(d)


def BELLMANFORD(point,d,p):
    cost       = [-float("inf") for node in range(n+1)]  #infじゃないと閉路検出がうまくいかない
    cost[point]= 0
    for i in range(n-1):                                  #経路の長さは最大n-1であるため
        for now,lis in d.items():
            for nex,c in lis:
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p

    negative=[0]*n                                        #負閉路の長さは最大nであるため
    
    for i in range(n):                  #閉路判定 negativeの1は閉路に入っている部分を表す
        for now,lis in d.items():
            for nex,c in lis:
                if negative[now-1]==1:
                    negative[nex-1]=1
                if cost[nex]<cost[now]+c-p:
                    cost[nex]=cost[now]+c-p
                    negative[now-1]=1
 
    return cost,negative

def main():
    x,y=(BELLMANFORD(1,d,p))
    
    if y[n-1]==1:
        print(-1)
    else:
        print(max(x[n],0))

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

k, s=map(int, input().split())
count=0
for x in range(k+1):
  if x>s:
    continue
  for y in range(k+1):
    if y>s:
      continue
    for z in range(k+1):
      if z>s:
        continue
      if x+y+z==s:
        count+=1
print(count)

### FIXED CODE ###

k, s=map(int, input().split())
count=0
for x in range(k+1):
  for y in range(k+1):
    z=s-x-y
    if 0<=z<=k:
      count+=1
      
print(count)
### BUGGY CODE ###

h,w,n=map(int,input().split())
H=[0]*h
W=[0]*w
L=[[0 for i in range(w)] for i in range(h)]
for i in range(n):
    a,b=map(int,input().split())
    L[a-1][b-1]=1
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
H_max=[i+1 for i, x in enumerate(H) if x == h_max]
W_max=[i+1 for i, x in enumerate(W) if x == w_max]
ans=h_max+w_max-1
for hh in H_max:
    for ww in W_max:
        if L[hh-1][ww-1]==0:
            ans+=1
            break
    else:
        continue
    break
print(ans)

### FIXED CODE ###

h,w,n=map(int,input().split())
H=[0]*h
W=[0]*w
L=[(0,0)]*n
for i in range(n):
    a,b=map(int,input().split())
    L[i]=(a,b)
    H[a-1]+=1
    W[b-1]+=1
h_max=max(H)
w_max=max(W)
ans=h_max+w_max
cnt=0
for l in L:
    if H[l[0]-1]==h_max and W[l[1]-1]==w_max:
        cnt+=1
if H.count(h_max)*W.count(w_max)==cnt:
    ans-=1
print(ans)
### BUGGY CODE ###

N,M = map(int,input().split(' '))
#A = []
#B = []
Drinks = []
for i in [0]*N:
	a,b = map(int,input().split(' '))
	#A.append(a)
	#B.append(b)
	Drinks+=[a]*b
Drinks.sort()
 
print(sum(Drinks[:M]))


### FIXED CODE ###

N,M = map(int,input().split(' '))
D = []
for i in [0]*N:
	a,b = map(int,input().split(' '))
	D.append([a,b])

D.sort(key = lambda x : x[0])

ans = 0
for c, s in D:
	if s < M:
		M -= s
		ans += c * s
	else:
		ans += M * c
		break
print(ans)
### BUGGY CODE ###

n = int(input())
l = list(map(int, input().split()))
ls = []
a = 0
for i in l:
    if i not in ls :
        ls.append(i)
        a += 1
    else :
        print('NO')
        break
if a == len(l):
    print('YES')

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(n-1):
  if a[i]==a[i+1]:
    print("NO")
    exit()
print("YES")
### BUGGY CODE ###

[n,q]=[int(x) for x in input().split()]
ab=[[int(x) for x in input().split()] for _ in range(n-1)]
px=[[int(x) for x in input().split()] for _ in range(q)]

bubungi=[[x] for x in range(1,n+1)]

for node in sorted(ab)[::-1]:
    bubungi[node[0]-1]=bubungi[node[0]-1]+bubungi[node[1]-1]

scores=[0,]*n
for q in px:
    for i in bubungi[q[0]-1]:
        scores[i-1]+=q[1]

print(" ".join([str(s) for s in scores]))

### FIXED CODE ###


n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
neigh = {}
 
scores = [0] * n
 
for i in range(q) :
    scores[px[i][0] - 1] += px[i][1]
#print(*scores) 
for i in range(n - 1) :
    neigh.setdefault(ab[i][0], []).append(ab[i][1])
#print(neigh)

sortKey = sorted(neigh.keys())
 
for k in sortKey :
    for e in neigh[k]:
        scores[e-1]+=scores[k-1]
 
print(*scores)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
broken_steps = [int(input()) for _ in range(m)]
#print(broken_steps)

def ptn_num(x): # 'x'stepまでのパターン数
    if x == 1:
        print(1)
    else:
        dp = [0] * (x+1) # DP枠_including step'0'
        cnt = 0
        if 1 in broken_steps: # in case, step'1' broken 
            dp[:2] = 1, 0
        else:
            dp[:2] = 1, 1 # Usually

        for i in range(2, x+1):
            if i in broken_steps: # 階段が壊れている場合...
                cnt += 1
                if cnt == 2:
                    print(0)
                    exit()
            else: # 階段が壊れてない場合...
                dp[i] = (dp[i-1] + dp[i-2]) % (10**9+7)
                cnt = 0
        
        print(dp[-1])

ptn_num(n)


### FIXED CODE ###

n, m = map(int, input().split())
a = set(map(int, [input() for _ in range(m)]))

dp = [0] * (n+1)
# 0段目と1段目は1通り（但し、１段目が壊れていない場合）（0 段目は「なにもしない」という から1 通り）
dp[:2] = 1, 1 if 1 not in a else 0 

for i in range(2, n+1):
    if i in a:
        continue
    else:
        dp[i] = (dp[i-1] + dp[i-2])

print(dp[-1] % (10**9+7))
### BUGGY CODE ###

N = int(input())
num_dict = {}

num_list = [int(input()) for i in range(N)]
max_num = max(num_list)

for cnt in range(N):
  if num_list[cnt] == max_num:
    print(max(num_list[0:cnt] + num_list[cnt+1:]))
  else:
    print(max_num)

### FIXED CODE ###

N = int(input())
num_list = [int(input()) for i in range(N)]
max_num = max(num_list)
max_num_num = num_list.count(max_num)

for cnt in range(N):
  if num_list[cnt] == max_num and max_num_num == 1:
    print(max(num_list[0:cnt] + num_list[cnt+1:]))
  else:
    print(max_num)
### BUGGY CODE ###

n=int(input())
a=[int(i) for i in input().split()]
ans=chk=0
for i in range(a[-1]*2,-1,-2):
    ans=[0]*n
    ans[0]=i
    f=1
    for j in range(1,n):
        t=(a[j-1]-ans[j-1]//2)*2
        if t>=0 and (t+ans[j-1])//2==a[j-1]:
            ans[j]=t
        else:
            f=0
            break
    if f and ans[-1]//2+ans[-2]//2==a[-2] and ans[-1]//2+ans[0]//2==a[-1]:
        print(*ans)

### FIXED CODE ###

# from https://atcoder.jp/contests/abc133/submissions/6272850
n=int(input())
a=[int(i) for i in input().split()]
c=[0]
s=sum(a)

for i in range(2*n):
    c.append(c[-1]+a[(i*2+1)%n])
ans=[0]*n
for i in range(n):
    ans[i*2%n]=s-2*(c[i+n//2]-c[i])
print(*ans)
### BUGGY CODE ###

N = int(input())
a = []
count = 0
for i in range(N):
    a += [''.join(sorted(input()))]
sorted_a = sorted(a)
for i in range(N-1):
    for j in range(1, N):
        if i+j >= N:
            break
        if sorted_a[i] == sorted_a[i+j]:
            count += 1
        else:
            break
print(count)

### FIXED CODE ###

from collections import defaultdict

n = int(input())
s = [input() for _ in range(n)]

d = defaultdict(int)
for i in range(n):
    d["".join(sorted(s[i]))] += 1

ans = 0
for k in d.keys():
    ans += d[k] * (d[k]-1) // 2
print(ans)
### BUGGY CODE ###

from dataclasses import dataclass

class BIT:
    '''
    All methods use 0-based index while the implementation use 1-based index
    '''
    def __init__(self, N, val=0):
        self.data = [val] * (N + 1)
        self.N = N

    def add_at(self, idx, val):
        i = idx + 1
        while i <= self.N:
            self.data[i] += val
            i += i & (-i)

    def sum_to(self, idx):
        res = 0
        i = idx + 1
        while i > 0:
            res += self.data[i]
            i -= i & (-i)
        return res

    def sum_in(self, l, r): # [l, r]
        return self.sum_to(r) - self.sum_to(l - 1)


@dataclass
class Query:
    i: int
    l: int
    r: int


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

queries = [[] for _ in range(N)]
for i in range(Q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    queries[r].append(Query(i, l, r))

V = max(C)
bit = BIT(N)
last = [-1] * (max(C) + 1)

query_idx = 0
ans = [-1] * Q
for i, c in enumerate(C):
    if last[c] != -1:
        bit.add_at(last[c], -1)    
    bit.add_at(i, +1)
    last[c] = i

    for q in queries[i]:
        ans[q.i] = bit.sum_in(q.l, q.r)

print('\n'.join(map(str, ans)))

### FIXED CODE ###


class BIT:
    '''
    All methods use 0-based index while the implementation use 1-based index
    '''
    def __init__(self, N, val=0):
        self.data = [val] * (N + 1)
        self.N = N
    
    def add_at(self, idx, val):
        i = idx + 1
        while i <= self.N:
            self.data[i] += val
            i += i & (-i)
    
    def sum_to(self, idx):
        res = 0
        i = idx + 1
        while i > 0:
            res += self.data[i]
            i -= i & (-i)
        return res
    
    def sum_in(self, l, r): # [l, r]
        return self.sum_to(r) - self.sum_to(l - 1)
    
    
class Query:
    def __init__(self, i, l, r):
        self.i = i
        self.l = l
        self.r = r
    
    
N, Q = map(int, input().split())
C = list(map(int, input().split()))
    
queries = [[] for _ in range(N)]
for i in range(Q):
    l, r = map(int, input().split())
    l, r = l - 1, r - 1
    queries[r].append(Query(i, l, r))
    
bit = BIT(N)
last = [-1] * (max(C) + 1)
    
query_idx = 0
ans = [-1] * Q
for i, c in enumerate(C):
    if last[c] != -1:
        bit.add_at(last[c], -1)    
    bit.add_at(i, +1)
    last[c] = i
    
    for q in queries[i]:
        ans[q.i] = bit.sum_in(q.l, q.r)
    
print('\n'.join(map(str, ans)))