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

def d():
    S = str(input())
    Q = int(input())
    rvs = False

    for i in range(Q):
        q = list(input().split())

        if q[0] == '1':
            rvs = not rvs
        elif q[0] == '2':
            if q[1] == '1':
                if rvs:
                    S = S + q[2]
                else:
                    S = q[2] + S
            elif q[1] == '2':
                if rvs:
                    S = q[2] + S
                else:
                    S = S + q[2]
            else:
                raise ValueError(
                    'F({}) is {}, which is invalid!'.format(i, q[1]))
        else:
            raise ValueError('T({}) is {}, which is invalid!'.format(i, q[0]))

    if rvs == True:
        S = S[::-1]
    print(''.join(S))


##########
d()


### FIXED CODE ###

def d():
    from collections import deque
    S = deque(str(input()))
    Q = int(input())
    rvs = False

    for i in range(Q):
        q = list(input().split())

        if q[0] == '1':
            rvs = not rvs
        elif q[0] == '2':
            if q[1] == '1':
                if rvs:
                    S.append(q[2])
                else:
                    S.appendleft(q[2])
            elif q[1] == '2':
                if rvs:
                    S.appendleft(q[2])
                else:
                    S.append(q[2])
            else:
                raise ValueError(
                    'F({}) is {}, which is invalid!'.format(i, q[1]))
        else:
            raise ValueError('T({}) is {}, which is invalid!'.format(i, q[0]))

    if rvs:
        ans = list(S)[::-1]
    else:
        ans = list(S)
    print(''.join(ans))


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

x=int(input())
a=0
b=0
for i in range(-x,x):
  for j in range(-x,x):
    if i**5-j**5==x:
      a=i
      b=j
      break
print(a,b)

### FIXED CODE ###

x=int(input())
a=0
b=0
for i in range(-500,500):
  for j in range(-500,500):
    if i**5-j**5==x:
      a=i
      b=j
      break
  else:
    continue
  break
print(a,b)
### BUGGY CODE ###

N, *S = open(0).read().split()
dict = {i : 0 for i in S}
for i in S:
  dict[i] += 1
ans_list = [i for i, j in dict.items() if j == max(dict.values())]
ans_list.sort()
print("\n".join(ans_list))

### FIXED CODE ###

from collections import Counter

N, *S = open(0).read().split()
count = Counter(S)
max_value = max(count.values())
ans_list = [i for i, j in count.items() if j == max_value]
ans_list.sort()
print("\n".join(ans_list))
### BUGGY CODE ###

n = int(input())
a = []
for i in range(n):
  a.append(int(input()))

for i in range(n):
  if i == 0:
    print(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)

### FIXED CODE ###

n = int(input())
a = [int(input()) for _ in range(n)]
tmpa = a[:] 
tmpa.sort()

for x in a:
  if x == tmpa[n-1]:
    print(tmpa[n-2])
  else:
    print(tmpa[n-1])
"""
if a[0] > a[1]:
  m,m2 = a[0],a[1]
else:
  m,m2 = a[1],a[0]

for x in a[2:]:
  if x > m2:
    if x>m:
      m2,m = 

"""
"""
for i in range(n):
  if i == 0:
    p
    rint(max(a[i+1:]))
    continue
  if i == n-1:
    print(max(a[0:n-1]))
    break
  ans = max(max(a[0:i]),max(a[i+1:n]))
  print(ans)
  """
### BUGGY CODE ###

# -*- coding: utf-8 -*-
#D - Good Grid
import sys 
from itertools import permutations
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,C = map(int,readline().split())
D = []
for _ in range(C):
    row = list(map(int,readline().split()))
    D.append(row)
data = []
for _ in range(N):
    row = list(map(int,readline().split()))
    data.append(row)

INF = 10**31
ans = INF
A = [i for i in range(C)]

for a,b,c in permutations(A,3):
    total = 0
    for i in range(N):
        for j in range(N):
            pre_c = data[i][j]-1
            if (i+j) % 3 == 0:
                total += D[pre_c][a]   
            elif (i+j) % 3 == 1:
                total += D[pre_c][b]
            else:
                total += D[pre_c][c]
    ans = min(ans,total)

print(ans)
                 

### FIXED CODE ###

# -*- coding: utf-8 -*-
#D - Good Grid
import sys 
from itertools import permutations
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,C = map(int,readline().split())
D = []
for _ in range(C):
    row = list(map(int,readline().split()))
    D.append(row)
data = []
for _ in range(N):
    row = list(map(int,readline().split()))
    data.append(row)

INF = 10**31
ans = INF
X = defaultdict(int)
Y = defaultdict(int)
Z = defaultdict(int)

for i in range(N):
    for j in range(N):
        pre_c = data[i][j]-1
        if (i+j) % 3 == 0:
            X[pre_c] += 1   
        elif (i+j) % 3 == 1:
            Y[pre_c] += 1
        else:
            Z[pre_c] += 1

M = [i for i in range(C)]
for a,b,c in permutations(M,3):
    total = 0
    for k,v in X.items():
        total += D[k][a]*v
    for k,v in Y.items():
        total += D[k][b]*v
    for k,v in Z.items():
        total += D[k][c]*v
    
    ans = min(ans,total)
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split()) # 横に2個
L = [list(map(int, input().split())) for _ in range(N-1)]

mod = 10**9+7

neardic = {}
checked = {}
for p in range(1, N+1):
    near = []
    for l in L:
        if p in l:
            other = set(l) - {p}
            near.append(list(other)[0])
    neardic[p] = set(near)
    checked[p] = False


def color(p=1, state=[1], prob=K, checked=checked):
    checked[p] = True
    nears = neardic[p]
    leaf = True
    for near in nears:
        if not checked[near]:
            leaf = False
            break
    if leaf:
        state.pop()
        return prob
    
    nextprobmax = K-1 if len(state) == 1 else K-2
    c = 0
    for i, near in enumerate(nears):
        if checked[near]:
            c += 1
            continue
        prob = prob * (nextprobmax - i + c) % mod
        state.append(near)
        prob = color(near, state, prob, checked)
    return prob

print(color())

### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, K = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

checked = [False]*N
C = [None]*N
checked[0] = True

def dfs(p, c1, c2, depth):
    C[p] = c1 + c2
    d = 0
    for np in graph[p]:
        if not checked[np]:
            checked[np] = True
            d += 1
            g = 1 if depth > 0 else 0
            dfs(np, d, g, depth+1)
        

dfs(0, 0, 0, 0)
#print(C)

mod = 10**9+7
ans = 1
for n in range(N):
    ans = ans * (K-C[n]) % mod

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

a,b = map(int,input().split())
cnt=0
for x in range(a+1):
    for y in range(a+1):
        z = b-x-y
        if 0<=z<=a and x+y+z==b:
            cnt+=1
print(cnt)

### FIXED CODE ###

a,b = map(int,input().split())
cnt=0
for x in range(a+1):
    for y in range(a+1):
        z = b-x-y
        if 0<=z<=a and x+y+z==b:
            cnt+=1
print(cnt)
### BUGGY CODE ###

def LIS(L):
  """数列L→最大増加部分列の長さ
  計算量はN^2"""
  res=0
  dp=[1]*N#最後がa[i] となるような最長の増加部分列の長さ
  for i in range(N):
    for j in range(i):
      if L[j]<L[i]:
        dp[i]=max(dp[i],dp[j]+1)
    res=max(res,dp[i])
  return res
 
import math 
x1,y1,x2,y2=map(int,input().split())
N=int(input())
W=abs(x2-x1)
H=abs(y2-y1)
xsgn=2*(x2>x1)-1
ysgn=2*(y2>y1)-1
XY=[]
for i in range(N):
  x,y=map(int,input().split())
  if (x-x1)*(x-x2)<=0 and (y-y1)*(y-y2)<=0:
    XY+=[[xsgn*(x-x1),ysgn*(y-y1)]]
N=len(XY)
short=20-5*math.pi
long=10*math.pi-20
straight=100*(W+H)
 
XY.sort()
Y = [y for x,y in XY]
 
fountain=LIS(Y)
 
if fountain<min(W,H)+1:
  print(straight-short*fountain)
else:
  print(straight-short*(fountain-1)+long)

### FIXED CODE ###

#最大増加部分列（Longest Increasing Subsequence）
def LIS(N,a):
  """数列の長さN, 数列a→最大増加部分列の長さ
  計算量はN^2"""
  res=0
  dp=[1]*N#最後がa[i] となるような最長の増加部分列の長さ
  for i in range(N):
    for j in range(i):
      if XY[j][0]<XY[i][0] and XY[j][1]<XY[i][1]:
        dp[i]=max(dp[i],dp[j]+1)
    res=max(res,dp[i])
  return res

import math 
x1,y1,x2,y2=map(int,input().split())
N=int(input())
W=abs(x2-x1)
H=abs(y2-y1)
xsgn=2*(x2>x1)-1
ysgn=2*(y2>y1)-1
XY=[]
for i in range(N):
  x,y=map(int,input().split())
  if (x-x1)*(x-x2)<=0 and (y-y1)*(y-y2)<=0:
    XY+=[[xsgn*(x-x1),ysgn*(y-y1)]]
N=len(XY)
short=20-5*math.pi
long=10*math.pi-20
straight=100*(W+H)
from bisect import bisect
 
# find LIS
XY.sort()
XY = [y for x,y in XY]

dp = [H+1]*len(XY)
 
for i,f in enumerate(XY):
  dp[bisect(dp,f)] = f
fountain = bisect(dp,H)
if fountain<min(W,H)+1:
  print(straight-short*fountain)
else:
  print(straight-short*(fountain-1)+long)
### BUGGY CODE ###

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)
# print(A)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

print(ans)


### FIXED CODE ###

import sys
# def input(): return sys.stdin.readline().rstrip()
# input = sys.stdin.readline
input = sys.stdin.buffer.readline

N = int(input())
A = sorted(zip(map(int, (input().split())) ,range(N)), reverse=True)

dp = [[0]*(N+1) for _ in range(N+1)]
ans = 0
for i in range(N):
    for j in range(i+1):
        dp[i+1][j]   = max(dp[i+1][j], dp[i][j] + A[i][0] * abs(A[i][1] - (N-1-(i-j))))
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + A[i][0] * abs(A[i][1] - j))

for i in range(N):
    ans = max(ans, dp[N][i])

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

N = int(input())

count = 0
for A in range(1, N+1):
    for B in range(A, N+1):
        if str(A)[-1]==str(B)[0] and str(B)[-1]==str(A)[0]:
            count +=1
            if A != B:
                count += 1
print(count)

### FIXED CODE ###

N = int(input())

cnt = [[0]*10 for i in range(10)]
# 先頭がi, 末尾がjであるような数の個数を計算
for n in range(1, N+1):
    n = str(n)
    i = int(n[0])
    j = int(n[-1])
    cnt[i][j] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j]*cnt[j][i]

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

n, m = map(int, input().split())
jobs = []

for i in range(n):
    a, b = map(int, input().split())
    jobs.append([a,b])

jobs_sorted = sorted(jobs, key=lambda x:(x[0],-x[1]))

days = [0 for i in range(m)]
for i in range(n):
    # print(jobs_sorted[i])
    after = jobs_sorted[i][0]
    money = jobs_sorted[i][1]
    if after <= m:
        for j in range(m - after, -1, -1):
            if days[j] < money:
                days.insert(j + 1, money)
                del days[0]
                break
    # print(days)

print(sum(days))

### FIXED CODE ###

import heapq

n, m = map(int, input().split())
jobs = dict()

for i in range(n):
    a, b = map(int, input().split())
    if not a in jobs.keys():
        jobs[a] = [-b]
    else:
        jobs[a].append(-b)
# print(jobs)
sum_money = 0
money_list = [0]
heapq.heapify(money_list)
for i in range(1, m+1):
    if i in jobs.keys():
        for money in jobs[i]:
            heapq.heappush(money_list, money)
    # print(money_list)
    max_money = -heapq.heappop(money_list)
    sum_money += max_money
    if max_money == 0:
        heapq.heappush(money_list, 0)
print(sum_money)
### BUGGY CODE ###

n, m = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
for _ in range(m):
    idx = a.index(max(a))
    a[idx] //= 2
print(sum(a))

### FIXED CODE ###

import heapq as hp
n, m = (int(x) for x in input().split())
a = [int(x)*(-1) for x in input().split()]
hp.heapify(a)
for _ in range(m):
    min = hp.heappop(a)
    hp.heappush(a, (-1)*(-min//2))
print(-sum(a))
### BUGGY CODE ###

import math
from functools import reduce


K = int(input())
ans = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd(a,b,c)
print(ans)

### FIXED CODE ###

import math
from functools import reduce


K = int(input())
ans = 0

def gcd(*numbers):
    return reduce(math.gcd, numbers)

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            ans += gcd(a,b,c)
print(ans)
### BUGGY CODE ###

s = input()
t = s[::-1]
isS = True
n = int(input())
query = []

for i in range(n):
    query.append(list(input().split()))

# print(query)

for i in range(n):
    # Reverse
    if query[i][0] == '1':
        # s = s[::-1]
        isS = not isS
    # Add
    else:
        # To Head
        if query[i][1] == '1':
            if isS:
                s = query[i][2] + s
                t += query[i][2]
            else:
                s += query[i][2]
                t = query[i][2] + t
        # To Tail
        else:
            if isS:
                s += query[i][2]
                t = query[i][2] + t
            else:
                s = query[i][2] + s
                t += query[i][2]

if isS:
    print(s)
else:
    print(t)

### FIXED CODE ###

from collections import deque

s = input()
t = s[::-1]
ss = deque(s)
tt = deque(t)
isS = True
n = int(input())
query = []

# print(q1, q2)

for i in range(n):
    query.append(list(input().split()))

# print(query)

for i in range(n):
    # Reverse
    if query[i][0] == '1':
        # s = s[::-1]
        isS = not isS
    # Add
    else:
        # To Head
        if query[i][1] == '1':
            if isS:
                ss.appendleft(query[i][2])
                tt.append(query[i][2])
            else:
                ss.append(query[i][2])
                tt.appendleft(query[i][2])
        # To Tail
        else:
            if isS:
                ss.append(query[i][2])
                tt.appendleft(query[i][2])
            else:
                ss.appendleft(query[i][2])
                tt.append(query[i][2])

if isS:
    temp = list(ss)
    ans = ''.join(temp)
    print(ans)
else:
    temp = list(tt)
    ans = ''.join(temp)
    print(ans)
### BUGGY CODE ###

n = int(input())
re = 1

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

for i in range(n):
    re = re * li[i]
if re > 1000000000000000000:
    print(-1)
else:
    print(re)


### FIXED CODE ###

n = int(input())
re = 1

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

for i in range(n):
    if re > 1000000000000000000:
        break
    re = re * li[i]
if 0 in li:
    print(0)
elif re > 1000000000000000000:
    print(-1)
else:
    print(re)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
q = int(input())
for i in range(q):
         b,c = map(int,input().split())
         a = [c if i == b else i for i in a]
         print(sum(a))



### FIXED CODE ###

import collections
import copy
n = int(input())
a = list(map(int,input().split()))
suma = sum(a)
numcount = [0] * ((10 ** 5) + 1)
for i in range(n):
         numcount[a[i]] += 1
q = int(input())
for i in range(q):
         b,c = map(int,input().split())
         if numcount[b] != 0:
                  tmpb = numcount[b]
                  numcount[c] += numcount[b]
                  numcount[b] = 0
                  suma += tmpb*(c - b)
         print(suma)
### BUGGY CODE ###

import math
import numpy as np

S = [v for v in input()]
N = len(S)
M = np.array([[0] * N for i in range(N)])
for i in range(N):
    if S[i] == 'L':
        M[i - 1][i] = 1
    else:
        M[i + 1][i] = 1

binary = format(10 ** 100, 'b')
Bin = []
for v in binary:
    a = int(v)
    Bin.append(a)

ans = [1] * N
for i in range(len(Bin)):
    a = Bin.pop()
    if a == 0:
        M = np.linalg.matrix_power(M, 2)
    else:
        ans = np.dot(M, [1 for i in range(N)])
        M = np.linalg.matrix_power(M, 2)

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

### FIXED CODE ###

S = [v for v in input()]
N = len(S)
M = [0] * N
for i in range(N):
    if S[i] == 'L':
        M[i] = i - 1
    else:
        M[i] = i + 1

binary = format(10 ** 100, 'b')
Bin = []
for v in binary:
    a = int(v)
    Bin.append(a)

ans = [1] * N
while Bin:
    a = Bin.pop()
    if a == 0:
        L = [0] * N
        for j in range(N):
            L[j] = M[M[j]]
        M = L
    else:
        new_ans = [0] * N
        for j in range(N):
            new_ans[M[j]] += ans[j]
        ans = new_ans

        L = [0] * N
        for j in range(N):
            L[j] = M[M[j]]
        M = L

print(' '.join(map(str, ans)))
### BUGGY CODE ###

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

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

for i in range(Q):
  L, R = map(int,input().split())
  c =0
  for p in positions:
    if L <= p+1 and p+2 <= R:
        c +=1
  print(c)


### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
t = [0] * (N + 1)
for i in range(N):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
 
count=1
for i in A:
    print(A.count(count))
    count+=1
 
print(0)

### FIXED CODE ###

import collections
 
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
for i in range(1, N+1):
    print(cnt[i])
### BUGGY CODE ###

N=int(input())
ls=[int(s) for s in input().split()]
money=1000
stock=0
for i in range(N-1):
  if ls[i]<ls[i+1]:
    while money>=ls[i]:
      money-=ls[i]
      stock+=1
  elif ls[i]>ls[i+1]:
    while stock>0:
      money+=ls[i]
      stock-=1
while stock>0:
  money+=ls[N-1]
  stock-=1
print(money)

### FIXED CODE ###

N=int(input())
ls=[int(s) for s in input().split()]
money=1000
stock=0
for i in range(N-1):
  if ls[i]<ls[i+1]:
    s=money//ls[i]
    money-=s*ls[i]
    stock+=s
  elif ls[i]>ls[i+1]:
    money+=ls[i]*stock
    stock=0
money+=ls[N-1]*stock

print(money)
### BUGGY CODE ###

import operator
from functools import reduce

n = int(input())

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


sum = reduce(operator.mul, a, 1)


if sum > 10 ** 18:
    print(-1)
else:
    print(sum)



### FIXED CODE ###

n = int(input())

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

if 0 in a:
        sum = 0
else:
    for i in range(1,len(a)):
        sum = sum * a[i]
        if sum > 10**18:
            break
        


if sum > 10**18:
    print(-1)
else:
    print(sum)
### BUGGY CODE ###

n, k = map(int, input().split())
s = input()
s2 = [["1", 0, 0]]
zero = 0
one_count = 1
for i, c in enumerate(s):
    if s2[-1][0] == c:
        s2[-1][2] += 1
    else:
        s2.append([c, i, 1])
        zero += (1 - int(c))
        if c == "1":
            one_count += 1
if zero <= k:
    print(n)
    exit()
if s2[-1][0] == "0":
    s2.append(["1", len(s)-1, 0])
    one_count += 1
ans = -1
sum_ = -1
for i in range(one_count - k):
    a = 0
    if sum_ < 0:
        for e in s2[i*2:(i+k)*2+1]:
            a += e[2]
    else:
        sum_ = sum_ - s2[i-2][2] + s2[(i+k)*2+1][2]
    if ans < a:
        ans = a
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
s = input()
cur = "1"
sum_ = [0]
ans = -1
for i, c in enumerate(s):
    if cur != c:
        sum_.append(i)
        if c == "0":
            if len(sum_) >= 2 + k + k:
                ans = max(ans, sum_[-1] - sum_[-2-k-k])
        cur = c
sum_.append(len(s))
if s[-1] == "0":
    sum_.append(len(s))
if len(sum_) > 2 + k + k:
    ans = max(ans, sum_[-1] - sum_[-2-k-k])
else:
    ans = n
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
l = []
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            l.append(S[i]+S[j]+S[k])
l = list(set(l))
print(len(l))

### FIXED CODE ###

# coding: utf-8
N = int(input())
S = input()
ans = []
for v in range(1000):
    used = [False for _ in range(len(S))]
    v = str(v).zfill(3)
    idx = 0
    for i in range(len(S)):
        if v[0] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[1] == S[i] and not used[i]:
            used[i] = True
            idx = i + 1
            break
    for i in range(idx, len(S)):
        if v[2] == S[i] and not used[i]:
            used[i] = True
            break
    if sum(used) == 3 and v not in ans:
        ans.append(v[:])
print(len(ans))
### BUGGY CODE ###

import sys

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

# 座標数よりコマ数が多ければ初期位置で条件を満たす
if N >= M:
    print(0)
    sys.exit()

# ソートする
X.sort()

# 隣り合う数の差を計算する
diff = list()
for m in range(M-1):
    diff.append(X[m+1] - X[m])

for n in range(N-1):
    max_index = diff.index(max(diff))
    diff.pop(max_index)

print(sum(diff))

### FIXED CODE ###

import sys

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

# 座標数よりコマ数が多ければ初期位置で条件を満たす
if N >= M:
    print(0)
    sys.exit()

# ソートする
X.sort()

# 隣り合う数の差を計算する
diff = list()
for m in range(M-1):
    diff.append(X[m+1] - X[m])

diff.sort(reverse=True)
print(sum(diff[N-1:]))
### BUGGY CODE ###

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

#累積和
ans=0
for i in range(n):
    acum=0
    for j in range(i,n):
        acum+=a[j]
        if(acum==0):
            ans+=1
print(ans)


### FIXED CODE ###

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

#累積和
ans=0
acum={}
acumi=0
for i in range(n):
    acumi+=a[i]
    acum[acumi]=acum.get(acumi, 0)+1

for k,v in acum.items():
    if(k==0):
        ans+=v*(1+v)//2
    else:
        ans+=(v-1)*v//2
print(ans)
### BUGGY CODE ###

n = int(input())
ls = list(map(int, input().split()))
rg = range(1, n + 1)
for i in rg:
    print(ls.count(i))


### FIXED CODE ###

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

ls2 =[0 for x in range(n)]
#0がn個のリストを用意する

for x in ls:
    ls2[x - 1] += 1

for x in range(n):
    print(ls2[x])
### BUGGY CODE ###

from collections import Counter
import queue

N, X, Y = map(int, input().split())
d = [[] for _ in range(N+1)]
d[X].append(Y)
d[Y].append(X)
for i in range(1,N):
    d[i].append(i+1)
    d[i+1].append(i)

ans=[0]*(N+1)

for i in range(N):
    dist = [None]*N
    s=i+1
    q=queue.Queue()
    q.put(s)
    dist[i]=0

    while not q.empty():
        From = q.get()
        for To in d[From]:
            if dist[To-1] == None:
                q.put(To)
                dist[To-1] = dist[From-1]+1
    c=Counter(dist)
    for i,m in c.items():
        ans[i]+=m

for i in range(1,N):
    print(ans[i]//2)

### FIXED CODE ###

from collections import Counter, deque


def bfs(d, s, N):
    dist = [-1]*N
    q = deque()
    q.append(s)
    dist[i] = 0
    while len(q) != 0:
        From = q.popleft()
        for To in d[From]:
            if dist[To-1] == -1:
                q.append(To)
                dist[To-1] = dist[From-1]+1
    return dist


N, X, Y = map(int, input().split())
d = [[] for _ in range(N+1)]
d[X].append(Y)
d[Y].append(X)
for i in range(1, N):
    d[i].append(i+1)
    d[i+1].append(i)

ans = [0]*(N+1)

for i in range(N):
    s = i+1
    c = Counter(bfs(d, i+1, N))
    for i, m in c.items():
        ans[i] += m

for i in range(1, N):
    print(ans[i]//2)