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

N, M = map(int,input().split())
A_list = []
Dp_list = [0] * (N+1)
Dp_list[0] = 1
for i in range(M):
    A_list.append(int(input()))
if A_list:
    if A_list[0] == 1:
        Dp_list[1] = 0
    else:
        Dp_list[1] = 1
else:
    Dp_list[1] = 1
if N != 1:
    for i in range(2, N + 1):
        if i not in A_list:
            Dp_list[i] = Dp_list[i-2] + Dp_list[i-1]
        elif i in A_list and i-1 in A_list:
            Dp_list = [0] * (N + 1)
            break
        else:
            Dp_list[i] = 0
        if Dp_list[i] > 1000000007:
            Dp_list[i] -= 1000000007
    print(Dp_list[N])
else:
    print(1)

### FIXED CODE ###

N, M = map(int,input().split())
A_list = set([int(input()) for _ in range(M)])
Dp_list = [0] * (N+1)
Dp_list[0] = 1

if 1 in A_list:
    Dp_list[1] = 0
else:
    Dp_list[1] = 1

if N != 1:
    for i in range(2, N + 1):
        if i in A_list:
            continue

        Dp_list[i] = Dp_list[i-2] + Dp_list[i-1]
        Dp_list[i] %= 1000000007
    print(Dp_list[N])
else:
    print(1)
### BUGGY CODE ###

def yaku(k):
    count  = 0
    an = []
    for i in range(1,k+1):
        if len(an) > 0 and i == an[-1]:
            count += len(an)
            break
        if k % i == 0:
            count += 1
            if k/i != i:
                an.append(k/i)
    return count

n = int(input())
ans = 0
for i in range(n-1):
    count = yaku(n-i-1)
    ans += count
print(ans)

### FIXED CODE ###

n = int(input())
ans = 0
for i in range(1,n):
    for j in range(i,n):
        if i*j <= n-1:
            if i == j:
                ans += 1
            else:
                ans += 2
        else:
            break
print(ans)
### BUGGY CODE ###

import bisect

N = int(input())
Ls = list(map(int, input().split()))
Ls.sort()
# index: 0,...,N-1

ans = 0
for i in range(N-2): # i: 0,...,N-3
    for j in range(i+1, N-1): # j: i+1,...,N-2
        # k: j+1,...,N-1
        ans += bisect.bisect_left(Ls[j+1:], Ls[j] + Ls[i])

print(ans)


### FIXED CODE ###

import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort() # index: 0,...,N-1

ans = 0
for i in range(N-2): # i: 0,...,N-3
    for j in range(i+1, N-1): # j: i+1,...,N-2
        # k の満たすべき条件:
        # 1. L[k] > L[j] - L[i]
        #     L[k] > L[j] なので自動的に満たす
        # 2. L[k] < L[i] + L[j]
        x = bisect.bisect_left(L, L[i]+L[j])
        # (<L[i]+L[j]), (<L[i]+L[j]), ..., (<L[i]+L[j]) | (L[i]+L[j]<=), (L[i]+L[j]<=), ...
        # | (x) より左側はOK
        # j+1 より右側はOK
        # L[j]<L[i]+L[j] と L[i]+L[j]<=L[x] より L[j]<L[x] つまり j<x
        ans += x - (j + 1)

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

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

if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    
    zentori=[]
    for i in range(1,2**(N+1)):
        baai=[]
        for j in range(N+1):
            if (i>>j) & 1:
                baai.append(j)
        if len(baai)>=K:
            zentori.append((sum(baai),len(baai)))
    
    setzentori=set(zentori)
    print(int(len(setzentori)%(10**9+7)))

### FIXED CODE ###

N, K = map(int, input().split())
 
if K==N+1:
    print(1)
elif K==N:
    print(N+2)
else:
    def tousawa(shokou, makkou, kosu):
        return int((shokou+makkou)*kosu/2)
    
    ans=0
    for i in range(K,N+2):
        ans+=tousawa(N-i+1,N,i)-tousawa(0,i-1,i)+1
    print(int(ans%(10**9+7)))
### BUGGY CODE ###

class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [0] * (n + 1)
 
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s

  def add(self, i, x):
    while i <= self.size:
      self.tree[i] += x
      i += i & -i

from itertools import accumulate
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = [int(input())-k for i in range(n)]
acc = [0]+list(accumulate(a))
acc_i = []
for i,x in enumerate(acc):
  acc_i.append((x,i+1))
acc_i.sort()
bit = Bit(n+2)
ans = 0
for i in range(n+1):
  x = acc_i[i][1]
  ans += n+1-x+bit.sum(x)
  bit.add(1,-1)
  bit.add(x+1,1)
print(ans)

### FIXED CODE ###

class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [0] * (n + 1)
 
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s

  def add(self, i, x):
    while i <= self.size:
      self.tree[i] += x
      i += i & -i

from itertools import accumulate
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = [int(input())-k for i in range(n)]
acc = [0]+list(accumulate(a))
acc_i = []
for i,x in enumerate(acc):
  acc_i.append((x,i+1))
acc_i.sort()
bit = Bit(n+2)
ans = 0
for i in range(n+1):
  x = acc_i[i][1]
  ans += n+1-x+bit.sum(x)
  bit.add(1,-1)
  bit.add(x+1,1)
print(ans)
### BUGGY CODE ###

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,Q= map(int, sys.stdin.readline().split())
    S = sys.stdin.readline().rstrip()
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(Q)]
    # print(l[1][0])

    for i in range(Q):
        n0=l[i][0]
        n1=l[i][1]
        s_l=S[n0-1:n1]
        print(s_l.count("AC"))



### FIXED CODE ###

"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd
from itertools import accumulate

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    N,Q= map(int, sys.stdin.readline().split())
    S = sys.stdin.readline().rstrip()
    l= [list(map(int,list(sys.stdin.readline().split()))) for i in range(Q)]
    # 累積和
    flg = []
    for i in range(N-1):
        tmp_S = S[i:i+2] #２文字ずつ
        if tmp_S == "AC":
            flg.append(1)
        else:
            flg.append(0)

    flg2 = [0] + flg
    flg2 = list(accumulate(flg2)) #accumurateで累積和[0, 1, 1, 2, 2, 2, 3, 3]

    for e in l:
        print(flg2[e[1]-1] - flg2[e[0]-1]) #累積和から順番で引っ張ってくる
### BUGGY CODE ###

from itertools import permutations
N,M,R = map(int,input().split())
r = list(map(int,input().split()))
Ans = 10**10
A = [[10**10 for _ in range(N)] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    A[a-1][b-1] = c
    A[b-1][a-1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            A[i][j] = min(A[i][j], A[i][k]+A[k][j])
P = list(permutations(r))
for p in P:
    d = 0
    for i in range(R-1):
        d += A[p[i]-1][p[i+1]-1]
    Ans = min(Ans,d)
print(Ans)

### FIXED CODE ###

from itertools import permutations
N,M,R = map(int,input().split())
r = list(map(int,input().split()))
Ans = 10**10
A = [[10**10 for _ in range(N)] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    A[a-1][b-1] = c
    A[b-1][a-1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            A[i][j] = min(A[i][j], A[i][k]+A[k][j])
P = list(permutations(r))
for p in P:
    d = 0
    for i in range(R-1):
        d += A[p[i]-1][p[i+1]-1]
    Ans = min(Ans,d)
print(Ans)
### BUGGY CODE ###

h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
def check(s,t):
    if (0 <= s <= w - 1) and (0 <= t <= h - 1):
        return True
    else:
        return False
def bfs(x, y, cost):
    if check(x,y):
        if grid[y][x] != "#":
            if cost < graph[y][x]:
                graph[y][x] = cost
                bfs(x+1,y,cost+1)
                bfs(x,y+1,cost+1)
                bfs(x-1,y,cost+1)
                bfs(x,y-1,cost+1)
ans = 0
inf = 4000
for i in range(h):
    for j in range(w):
        graph = [[inf for _ in range(w)] for _ in range(h)]
        bfs(j,i,0)
        for p in range(h):
            for q in range(w):
                if graph[p][q] < inf:
                    ans = max(ans, graph[p][q])
print(ans)


    



### FIXED CODE ###

from collections import deque
h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
def check(s,t):
    if (0 <= s <= w - 1) and (0 <= t <= h - 1):
        return True
    else:
        return False
def bfs(que):
    finished = set()
    while que:
        x , y, cost = que.popleft()
        if (not check(x,y) ) or grid[y][x] == '#':
            continue
        if (x,y) not in finished:
            finished.add((x,y))
            graph[y][x] = cost
            que.append([x+1,y,cost+1])
            que.append([x, y+1, cost+1])
            que.append([x-1,y,cost+1])
            que.append([x,y-1,cost+1])
ans = 0
inf = 400

for i in range(h):
    for j in range(w):
        que = deque()
        que.append([j,i,0])
        graph = [[inf for _ in range(w)] for _ in range(h)]
        bfs(que)
        for p in range(h):
            for q in range(w):
                if graph[p][q] < inf:
                    ans = max(ans, graph[p][q])
print(ans)
### BUGGY CODE ###

s = input()
q = int(input())

rev_s = False
for i in range(q):
   tmp = list(input().split())
   if len(tmp) == 1:
      if rev_s == True:
         rev_s = False
      else:
         rev_s = True
   else:
      f, c = int(tmp[1]), tmp[2]
      if rev_s == False:
         if f == 1:
            s = c + s
         else:
            s = s + c
      else:
         if f == 1:
            s = s + c
         else:
            s = c + s

if rev_s == True:
   print(s[::-1])
else:
   print(s)


### FIXED CODE ###

from collections import deque

s = input()
q = int(input())

t = deque(s)

reverse = False
for _ in range(q):
   query = input()
   if query[0] == '1':
      reverse = not reverse
   elif query[0] == '2':
      _, f, c = query.split()
      if f == '1':
         if reverse:
            t.append(c)
         else:
            t.appendleft(c)
      elif f == '2':
         if reverse:
            t.appendleft(c)
         else:
            t.append(c)

result = ''.join(t)
if reverse:
   result = result[::-1]
print(result)
### BUGGY CODE ###

import math
 
N=int(input())
 
a=math.ceil(math.sqrt(N))
 
for i in range(a,((N+1)//10+1)):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))

### FIXED CODE ###

import math
 
N=int(input())
 
a=math.floor(math.sqrt(N))
 
for i in range(a,0,-1):
  if N%i==0:
    r=N//i
    print(max(len(str(i)),len(str(r))))
    exit()

print(len(str(N)))
### BUGGY CODE ###

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

### FIXED CODE ###

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

total = 1
li.sort()
for a in li:
    if a == 0:
        total = 0
        break
    total *= a
    if 10 ** 18 < total:
        total = -1
        break
print(total)
### BUGGY CODE ###

# coding:utf-8

import sys
from collections import deque, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def topological_sort(graph: dict) -> list:
    stack = deque([])
    visited = set()
    not_leaf = set(graph.keys())
    sort_list = []

    for i in graph.keys():
        if i in visited:
            continue
        stack.append(i)

        while stack:
            v = stack[-1]
            if v not in not_leaf:
                sort_list.append(stack.pop())
                visited.add(v)
                continue

            for next in graph[v]:
                if next not in visited:
                    stack.append(next)
                    break
            else:
                sort_list.append(stack.pop())
                visited.add(v)

    return sort_list[::-1]


n, m = LI()
T = defaultdict(list)

for _ in range(n + m - 1):
    a, b = LI()
    T[a].append(b)

ts_list = topological_sort(T)


tree = defaultdict(int)
tree[ts_list[0]] = 0
queue = deque([ts_list[0]])
while queue:
    v = queue.popleft()
    for next in T[v]:
        tree[next] = v
        queue.append(next)

print(*tree.values(), sep='\n')


### FIXED CODE ###

# coding:utf-8

import sys
from collections import deque
from operator import itemgetter

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


n, m = LI()

G = [[] for _ in range(n)]
RG = [[] for _ in range(n)]
indegree = [0] * n

for _ in range(n + m - 1):
    a, b = LI_()
    G[a].append(b)
    RG[b].append(a)
    indegree[b] += 1

# Topological sort
que = deque()
for i in range(n):
    if indegree[i] == 0:
        que.append(i)

res = []
while que:
    v = que.popleft()
    res.append(v)
    for v2 in G[v]:
        indegree[v2] -= 1
        if indegree[v2] == 0:
            que.append(v2)

# 親の候補が複数ある場合
# 木の高さが最大になるような候補を選ぶ
# -> トポロジカル順序で最も後ろにある候補を選ぶ
order = [i for i, n in sorted(enumerate(res), key=itemgetter(1))]
for i in range(n):
    if len(RG) == 0:
        print(0)
        continue

    parent = -1
    d = -1
    for j in RG[i]:
        if order[j] > d:
            parent = j
            d = order[j]

    print(parent + 1)
### BUGGY CODE ###

s = input()
t = input()
q = int(input())
abcd = [tuple(map(int,input().split())) for i in range(q)]

def to_one(word):


    word = word.replace('AAA', '')
    word = word.replace('BBB', '')

    word = word.replace('AB', '')
    word = word.replace('BA', '')

    word = word.replace('AA', 'B')
    word = word.replace('BB', 'A')

    word = word.replace('AAA', '')
    word = word.replace('BBB', '')

    word = word.replace('AB', '')
    word = word.replace('BA', '')

    if len(word)==0:
            return 'C'

    if len(word)==1:
        return word


for a,b,c,d in abcd:

    s_i = s[a-1:b]
    t_i = t[c-1:d]

    if to_one(s_i) == to_one(t_i):
        print('YES')
    else:
        print('NO')



### FIXED CODE ###

from itertools import accumulate

s = input()
t = input()
q = int(input())
abcd = [tuple(map(int,input().split())) for i in range(q)]

s_number = [2 if ab == 'B' else 1 for ab in s]
t_number = [2 if ab == 'B' else 1 for ab in t]

s_sum = [0] + s_number
s_sum = list(accumulate(s_sum))

t_sum = [0] + t_number
t_sum = list(accumulate(t_sum))

for a,b,c,d in abcd:

    s_i = s_sum[b]-s_sum[a-1]
    t_i = t_sum[d]-t_sum[c-1]

    if s_i%3 == t_i%3:
        print('YES')
    else:
        print('NO')
### BUGGY CODE ###

import numpy as np
import copy
def main():
    n = int(input())
    
    ans_list = []
    for i in range(n):
        a = int(input())
        ans_list.append(a)

    for j in range(n):
        tmp_list = copy.deepcopy(ans_list)
        tmp_list[j] = 0
    
        print(np.max(tmp_list))



    
    
if __name__ == '__main__':
    main()



### FIXED CODE ###

import numpy as np
import copy
def main():
    n = int(input())
    
    max_num = 0
    max_second = 0
    for i in range(n):
        a = int(input())
        if a > max_num:
            max_num = a
            max_index = i
        elif a > max_second:
            max_second = a

    for j in range(n):
        if j == max_index:
            print(max_second)
        else:
            print(max_num)



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

n,m = map(int,input().split(" "))
question_list = []
res_list = []
ac_list = []
for i in range(m):
    a,b = input().split(" ")
    a = int(a)
    question_list.append(a)
    res_list.append(b)
correct = 0
mistake = 0




for i,j in enumerate(res_list):
    if i == 0:
        if j == "WA":
            mistake += 1
        else:
            correct += 1
            ac_list.append(question_list[i])
            
    else:
        #今やっている問題がまだ正解していない
        if question_list[i] not in ac_list:
            if j == "WA":
                mistake += 1
            else:
                correct += 1
                ac_list.append(question_list[i])
                
            
    if len(ac_list) == n:
        break
            
for i,j in enumerate(res_list):
    if question_list[i] not in ac_list:
        mistake -= 1
        
      
print(correct,mistake)
            

    



### FIXED CODE ###

# coding: utf-8

n,m = map(int,input().split(" "))
ac_list = [0] * n
wa_list = [0] * n


wa = 0

for i in range(m):
    a,b = input().split(" ")
    if ac_list[int(a) - 1]:
        continue
    if b == "AC":
        ac_list[int(a) - 1] = 1
        wa += wa_list[int(a)-1]
    else:
        wa_list[int(a)-1] += 1
        
print(sum(ac_list),wa)
### BUGGY CODE ###

from collections import deque

def resolve():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))

    q = deque()

    for i in range(n):
        bef_i = i-1 if i > 0 else n-1
        aft_i = i+1 if i < n-1 else 0
        if bb[i] > aa[i] and bb[i] > bb[bef_i] + bb[aft_i]:
            q.append(i)

    count = 0

    while len(q) > 0:
        i = q.popleft()

        bef_i = i-1 if i > 0 else n-1
        bef2_i = bef_i-1 if bef_i > 0 else n-1
        aft_i = i+1 if i < n-1 else 0
        aft2_i = aft_i+1 if aft_i < n-1 else 0

        bb[i] = bb[i] - bb[bef_i] - bb[aft_i]
        count += 1

        if bb[i] > aa[i] and bb[i] > bb[bef_i] + bb[aft_i]:
            q.append(i)

        if bb[bef_i] > aa[bef_i] and bb[bef_i] > bb[bef2_i] + bb[i]:
            q.append(bef_i)

        if bb[aft_i] > aa[aft_i] and bb[aft_i] > bb[aft2_i] + bb[i]:
            q.append(aft_i)

    for i in range(n):
        if aa[i] != bb[i]:
            print(-1)
            return

    print(count)
resolve()

### FIXED CODE ###

from collections import deque

def resolve():
    n = int(input())
    aa = list(map(int, input().split()))
    bb = list(map(int, input().split()))

    q = deque()
    diffs = set()

    for i in range(n):
        if bb[i] != aa[i]:
            diffs.add(i)

        bef_i = i-1 if i > 0 else n-1
        aft_i = i+1 if i < n-1 else 0
        if bb[i] > aa[i] and bb[i] > bb[bef_i] + bb[aft_i]:
            q.append(i)

    count = 0

    while len(q) > 0:
        i = q.popleft()

        bef_i = i-1 if i > 0 else n-1
        bef2_i = bef_i-1 if bef_i > 0 else n-1
        aft_i = i+1 if i < n-1 else 0
        aft2_i = aft_i+1 if aft_i < n-1 else 0

        count += (bb[i] - aa[i]) // (bb[bef_i] + bb[aft_i])
        bb[i] = (bb[i] - aa[i]) % (bb[bef_i] + bb[aft_i]) + aa[i]

        if bb[i] == aa[i]:
            diffs.remove(i)

        if bb[bef_i] > aa[bef_i] and bb[bef_i] > bb[bef2_i] + bb[i]:
            q.append(bef_i)

        if bb[aft_i] > aa[aft_i] and bb[aft_i] > bb[aft2_i] + bb[i]:
            q.append(aft_i)

    if len(diffs) > 0:
        print(-1)
        return

    print(count)
resolve()
### BUGGY CODE ###

# D - Lamp

from numpy import zeros, max

H, W = map(int, input().split())
M = [[str(m) for m in input()] for _ in range(H)]
U = zeros((H, W), dtype=int)
L = zeros((H, W), dtype=int)
D = zeros((H, W), dtype=int)
R = zeros((H, W), dtype=int)

for i in range(H):
    for j in range(W):
        if M[i][j] != '#':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i - 1][j] + 1
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j - 1] + 1

        k, l = H - i - 1, W - j - 1
        if M[k][l] != '#':
            if i == 0:
                D[k][l] = 1
            else:
                D[k][l] = D[k + 1][l] + 1
            if j == 0:
                R[k][l] = 1
            else:
                R[k][l] = R[k][l + 1] + 1

print(max(U + L + D + R - 3))


### FIXED CODE ###

# # D - Lamp

import numpy as np

H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]
M = (np.array(M) == '.') * 1

L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, i] = M[:, i]
        R[:, W - i - 1] = M[:, W - i - 1]
    else:
        L[:, i] = (L[:, i - 1] + 1) * M[:, i]
        R[:, W - i - 1] = (R[:, W - i] + 1) * M[:, W - i - 1]

for i in range(H):
    if i == 0:
        U[i, :] = M[i, :]
        D[H - i - 1, :] = M[H - i - 1, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * M[i, :]
        D[H - i - 1, :] = (D[H - i, :] + 1) * M[H - i - 1, :]

print(max(np.max(L + R + D + U - 3), 0))
### BUGGY CODE ###

import collections
S = list(map(int, input()))[::-1]
mod_list = [0 for _ in range(len(S)+1)]
x = 0
d = 0
for i, s in enumerate(S):
    x += s * pow(10, d)
    d += 1
    mod_list[i] = x%2019
c = collections.Counter(mod_list)
ans = 0
for i in range(2020):
    ans += c[i] * (c[i]-1)//2
print(ans)

### FIXED CODE ###

import collections
S = list(map(int, input()))[::-1]
mod_list = [0 for _ in range(len(S)+1)]
x = 0
d = 0
for i, s in enumerate(S):
    x += s * pow(10, d, 2019)
    d += 1
    mod_list[i] = x%2019
c = collections.Counter(mod_list)
ans = 0
for i in range(2020):
    ans += c[i] * (c[i]-1)//2
print(ans)
### BUGGY CODE ###

def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, n):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x, 2):
            mod_i = i % n
            res[x] = res[x] - a[mod_i]
        for i in range(x + 2, n + x, 2):
            mod_i = i % n
            res[x] = res[x] + a[mod_i]
        res[x] = str(int(res[x] / 2))
    print(' '.join(res))


### FIXED CODE ###

def mul(inp):
    return int(inp * 2)


if __name__ == '__main__':
    n = int(input())
    a = list(map(mul, map(int, input().split())))
    res = [0] * n
    for x in range(0, 1):
        res[x] = a[x]
        count = 1
        for i in range(x + 1, n + x, 2):
            mod_i = i % n
            res[x] = res[x] - a[mod_i]
        for i in range(x + 2, n + x, 2):
            mod_i = i % n
            res[x] = res[x] + a[mod_i]
        res[x] = int(res[x] / 2)
    for x in range(1, n):
        res[x] = a[x - 1] - res[x - 1]
    print(' '.join(map(str, res)))