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

# Q_C
N = int(input())
A = list(map(int, input().split()))
import numpy as np

A = np.array(A)
I = np.array(list(range(1, N + 1)))
G = A - I
#print(G)
b = np.min(G)
#print(b)

re = -1
if b == 0:
    G = np.absolute(G)
    re = np.sum(G)
else:
    uG = np.unique(G)
    for i in uG:
        temp = np.sum(np.absolute(G - np.full(N , i)))
#        print(temp)
        if re > temp or re == -1:
            re = temp
print(int(re))

### FIXED CODE ###

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

import numpy as np
import collections

A = np.array(A)
I = np.array(list(range(1, N + 1)))

G = A - I

b = np.median(G)
G = np.absolute(G - np.full(N, b))
re = np.sum(G)

print(int(re))
### BUGGY CODE ###

n=int(input())
a=input().split()
ans=''
for i in range(1,n+1):
    ans+=str(a.index(str(i))+1)+' '

print(ans)


### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
    b[a[i]-1]=str(i+1)

print(' '.join(b))
### BUGGY CODE ###

k = int(input())
n = 7
ans = 1
for _ in range(1000000):
  if n % k == 0:
    print(ans)
    exit()
  else:
    n = 10*n + 7
    ans += 1
print('-1')

### FIXED CODE ###

k = int(input())
mod = 7
ans = 1
for i in range(k):
  if mod % k == 0:
    print(ans)
    exit()
  else:
    mod = (mod*10 + 7) % k
    ans += 1
print('-1')
### BUGGY CODE ###

def main():
    import sys
    from collections import deque
    from sys import stdin
    readline = stdin.readline
    n,m = map(int, readline().split())
    abl =[[]for i in range(n)]
    for i in range(m):
        a,b = map(int,readline().split())
        abl[a-1].append(b)
        abl[b-1].append(a)

    an=[0]*(n-1)
    i=1
    wk=deque([i])
    wwk=deque([])
    il=deque(abl[0])

    while any(wk):
        i=wk.pop()
        il=deque(abl[i-1])
        for k in range(len(il)):
            iwk=il.pop()
            if an[iwk-2]==0 and iwk>1:
                wwk.append(iwk)
                an[iwk-2]=i
                if all(an):
                    print('Yes')
                    for i in an:
                        print(i)
                    sys.exit()
        if not(any(wk)):
            wk=deque(wwk)
            j=len(wk)
            wwk=deque([])
    print('No')

main()

### FIXED CODE ###

def main():
    from collections import deque
 
    n,m =map(int,input().split())
    abl=[[] for i in range(n+1)]
    for i in range(m):
        a,b = map(int,input().split())
        abl[a].append(b)
        abl[b].append(a)
 
    an=[0]*(n+1)
    an[0]=1
    tg = deque([1])
    while len(tg):
        itg = tg.popleft()
        for j in abl[itg]:
            if an[j]==0:
                an[j]=itg
                tg.append(j)

    if all(an):
        print('Yes')
        for j in an[2:]:
            print(j)
    else:
        print('No')
 
main()
### BUGGY CODE ###

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

L=sorted(L, reverse=True)
count=0
for i in range(0, N-2):
    stop_count = 0
    for j in range(i+1, N-1):
        for k in range(N-1, j, -1):
            if L[i] < L[j] + L[k]:
                count+=k-j
                break


print(count)

### FIXED CODE ###

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

L.sort()
#print(L)

ans=0
for i in range(0, N-2):
    for j in range(i+1, N-1):


        left, right = j, N

        while right-left > 1:
            mid=(left+right) // 2
            if L[i]+L[j] <= L[mid]:
                right=mid
            else:
                left=mid
        ans += left - j
        #print(i,j,left)
print(ans)
### BUGGY CODE ###

import math
import sys
import collections
N=int(input())
Tr=list(input())
R=[]
G=[]
B=[]
for i in range(N):
   if Tr[i]=="R":
       R.append(i)
   if Tr[i]=="G":
       G.append(i)
   if Tr[i]=="B":
       B.append(i)
cnt=0
for i in R:
    for j in G:
        for k in B:
            if max(i,j,k)-(i+j+k-max(i,j,k)-min(i,j,k))!=(i+j+k-max(i,j,k)-min(i,j,k))-min(i,j,k):
                cnt+=1
print(cnt)


### FIXED CODE ###

import math
import sys
import collections

def main():
    N=int(input())
    Tr=list(input())
    R=[]
    G=[]
    B=[]
    for i in range(N):
       if Tr[i]=="R":
           R.append(i)
           continue
       if Tr[i]=="G":
           G.append(i)
           continue
       if Tr[i]=="B":
           B.append(i)
           continue
    cnt=len(R)*len(G)*len(B)
    for j in range(N):
        for i in range(j):
            if 2*j-i<=N-1:
                if Tr[2*j-i]!=Tr[i] and Tr[2*j-i]!=Tr[j] and Tr[j]!=Tr[i]:
                    cnt-=1
    print(cnt)
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import copy
n=int(input())
x=list(input())
b=[]
for i in range(2**19):
  b.append(format(i,'0'+str(19)+'b'))
ct=[0]*(n+1)
for i in range(1,n):
  ct1=0
  for j in range(len(b[i])):
    if b[i][j]=='1':
      ct1+=1
  ct[i]=i%ct1

CT=0
for i in range(n):
  if x[i]=='1':
    CT+=1

moda=[]
modb=[]
modc=[]
for i in range(n):
  if CT>=2:
    moda.append(pow(2,i,CT-1))
  if CT>=1:
    modb.append(pow(2,i,CT))
  modc.append(pow(2,i,CT+1))


x.reverse()
za=0
zb=0
zc=0
for i in range(n):
  if x[i]=='1':
    if CT>=2:
      za+=moda[i]
      za%=(CT-1)
    if CT>=1:
      zb+=modb[i]
      zb%=CT
    zc+=modc[i]
    zc%=(CT+1)
x.reverse()
moda.reverse()
modc.reverse()

for i in range(n):
  y=copy.copy(x)
  y2=y[i]
  y[i]=str(1-int(y[i]))
  ct1=0
  for j in range(n):
    if y[j]=='1':
      ct1+=1
  if ct1==0:
    print(0)
  else:
    if y2=='1':
      z=copy.copy(za)
      z-=moda[i]
      z%=ct1
    else:
      z=copy.copy(zc)
      z+=modc[i]
      z%=ct1
    
    
    
    ans=1
    while z!=0:
      z=ct[z]
      ans+=1
    print(ans)

### FIXED CODE ###

import copy
n=int(input())
x=list(input())
b=[]
for i in range(2**18):
  b.append(format(i,'0'+str(18)+'b'))
  if i>n+1:
    break
ct=[0]*(n+1)
for i in range(1,n):
  ct1=0
  for j in range(len(b[i])):
    if b[i][j]=='1':
      ct1+=1
  ct[i]=i%ct1

CT=0
for i in range(n):
  if x[i]=='1':
    CT+=1

moda=[1]
modb=[1]
modc=[1]
for i in range(n-1):
  if CT>=2:
    moda.append(moda[-1]*2%(CT-1))
  if CT>=1:
    modb.append(modb[-1]*2%CT)
  modc.append(modc[-1]*2%(CT+1))


x.reverse()
za=0
zb=0
zc=0
for i in range(n):
  if x[i]=='1':
    if CT>=2:
      za+=moda[i]
      za%=(CT-1)
    if CT>=1:
      zb+=modb[i]
      zb%=CT
    zc+=modc[i]
    zc%=(CT+1)
x.reverse()
moda.reverse()
modc.reverse()

for i in range(n):
  y2=x[i]
  if y2=='1':
    ct1=CT-1
  else:
    ct1=CT+1
  if ct1==0:
    print(0)
  else:
    if y2=='1':
      z=za
      z-=moda[i]
      z%=ct1
    else:
      z=zc
      z+=modc[i]
      z%=ct1
    
    ans=1
    while z!=0:
      z=ct[z]
      ans+=1
    print(ans)
### BUGGY CODE ###

N = int(input())
p = list(map(int,input().split()))
cou1 = 0
cou2 = 0
num1 = min(p)
num2 = p.count(num1) 


for i in range(N):
    num3 = min(p[0:i+1])
    if p[i] == num3:
        cou1 += 1
    if p[i] == num1:
        cou2 += 1
    if cou2 == num2:
        break
    
print(cou1)
    

### FIXED CODE ###

#41
import math
N = int(input())
p = list(map(int,input().split()))

cou = 0
x = math.inf

for j in range(N):
    if min(x,p[j]) == p[j]:
        x = p[j]
        cou += 1

print(cou)
### BUGGY CODE ###

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


def lcm(x, y):
        return (x*y) // gcd(x, y)


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

lcm_value = A[0]
for i in range(1, N):
    lcm_value = lcm(lcm_value, A[i])

# print(lcm_value)
mod = 10**9+7
ans = 0
for i in range(N):
    ans += (lcm_value // A[i]) % mod

print(ans % mod)


### FIXED CODE ###

def gcd(m, n):
    while n:
        m, n = n, m % n
    return m


def lcm(x, y):
        return (x*y) // gcd(x, y)


N = int(input())
A = list(map(int, input().split()))
A.sort()
lcm_value = A[0]
for i in range(1, N):
    lcm_value = lcm(lcm_value, A[i])

# print(lcm_value)
mod = 10**9+7
ans = 0
for i in range(N):
    ans += (lcm_value // A[i])

print(ans % mod)
### BUGGY CODE ###

N = int(input())

b = 1

a = list(map(int, input().split()))
for i, a in enumerate(a):
    try:
        b *= a
    except:
        print("-1")
if b > pow(10, 18):
    print("-1")
else:
    print(b)
        


### FIXED CODE ###

import sys
N = int(input())

b = 1

a = sorted(list(map(int, input().split())), reverse=True)
if a[-1] == 0:
    print("0")
    sys.exit()
for i in a:
    b *= i
    if b > pow(10, 18):
        print("-1")
        sys.exit()
print(b)
### BUGGY CODE ###

inf =  1000005
def main():
  N = int(input())
  a = list(map(int, input().split()))
  a.sort()
  flag = [True]*inf
  num = [0]*inf 
  for i in range(N):
    num[a[i]] += 1
    if flag[a[i]]:
      j = 2
      while (j*a[i] < inf):
        flag[j*a[i]] =  False
        j += 1
  ans = 0
  for i in range(N):
    if flag[a[i]] and num[a[i]] == 1:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()

### FIXED CODE ###

inf =  1100000
def main():
  N =  int(input())
  a = list(map(int, input().split()))
  a.sort()
  detect = [0] *inf
  for x in a:
    if detect[x] != 0:
      detect[x] = 2
      continue
    for i in range(x, inf, x):
      detect[i] += 1
  ans = 0
  for i in range(N):
    if detect[a[i]] == 1:
      ans += 1
  print(ans)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

N = int(input())

box = []
for i in range(1, N + 1): 
    if N % i == 0:
        box.append(int(N / i)) 

a = box[int(len(box)/2)]
b = int(N / a)

kkk = (a-1) + (b-1)

print(kkk)

### FIXED CODE ###

import math

N = int(input())

box = []
for i in range(1, int(math.sqrt(N) + 1)):
    if N % i == 0:
        box.append(int(N / i)) 

a = box[-1]
b = int(N / a)

kkk = (a-1) + (b-1)

print(kkk)
### BUGGY CODE ###

n = int(input())
note = dict()
for i in range(n):
    s = "".join(sorted(input()))
    if s in note.keys():
        note[s] += 1
    else:
        note[s] = 1
        
ans = 0
for i in note.values():
    ans += i*(i-1)//2

print(ans)

### FIXED CODE ###

import sys
#input = sys.stdin.readline

n = int(input())
note = dict()
ans = 0
for i in range(n):
    s = "".join(sorted(sys.stdin.readline()))
    if s in note.keys():
        ans += note[s]
        note[s] += 1
    else:
        note[s] = 1

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

N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
mat=[[0]*(N+1) for i in range(N+1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  mat[uvw[i][0]][uvw[i][1]]=uvw[i][2]
  mat[uvw[i][1]][uvw[i][0]]=uvw[i][2]
  nodelink[uvw[i][0]].append(uvw[i][1])
  nodelink[uvw[i][1]].append(uvw[i][0])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=g(nuru)
  for nuruyo in tonari:
    if color[nuruyo]<0:
      if h(nuru, nuruyo)==0:
        f(nuruyo, iro)
      else:
        f(nuruyo, 1-iro)
      
def g(x):
  return nodelink[x]

def h(a, b):
  return mat[a][b]%2

f(1, 0)

for i in range(1, N+1):
  print(color[i])

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**5+1)

N=int(input())
uvw=[list(map(int, input().split())) for i in range(N-1)]
nodelink=[[] for i in range(N+1)]
for i in range(N-1):
  nodelink[uvw[i][0]].append([uvw[i][1], uvw[i][2]])
  nodelink[uvw[i][1]].append([uvw[i][0], uvw[i][2]])
  
color=[-1]*(N+1)

def f(nuru, iro):
  color[nuru]=iro
  tonari=nodelink[nuru]
  for nuruyo in tonari:
    if color[nuruyo[0]]<0:
      if (nuruyo[1]%2)==0:
        f(nuruyo[0], iro)
      else:
        f(nuruyo[0], 1-iro)
      
f(1, 0)

for i in range(1, N+1):
  print(color[i])
### BUGGY CODE ###

n=int(input())
d={}
for i in range(n):
  a=str(sorted(input()))
  if a in list(d.keys()):
    d[a]+=1
  else:
    d[a]=1
l=list(d.values())
c=0
for i in l:
  c+=(i*(i-1))//2
print(c)


### FIXED CODE ###

from collections import Counter as co
n=int(input())
a=[str(sorted(input())) for _ in range(n)]
d=co(a)
l=d.values()
c=0
for i in l:
  c+=(i*(i-1))//2
print(c)
### BUGGY CODE ###

a,b,c = map(int,input().split(" "))
for i in range(a,b+1):
  if i < a+c or i > b-c:
    print(i)


### FIXED CODE ###

a,b,c = map(int,input().split())
ar = []
if a + c > b:
    d = b+1
else:
    d = a+c
for i in range(a,d):
    ar.append(i)
if b - c < a:
    e = a
else:
    e = b-c+1
for i in range(e,b+1):
    ar.append(i)
br = set(ar)
cr = sorted(br)
for i in cr:
    print(i)
### BUGGY CODE ###

n = int(input())
stations = []
for _ in range(n-1):
    stations.append(tuple(map(int, input().split())))

for i in range(n-1):
    stats = stations[i:]
    t = 0
    for c, s, f in stats:
        if t <= s:
            t = s
        else:
            temp = s
            while temp < t:
                temp += f
            t = temp
        t += c
    print(t)
print(0)


### FIXED CODE ###

n = int(input())
stations = []
for _ in range(n-1):
    stations.append(tuple(map(int, input().split())))

outputs = [0] * n
for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        c, s, f = stations[j]
        if t <= s:
            t = s
        else:
            if t%f != 0:
                t = t+f - t%f
        t += c
    print(t)
print(0)
### BUGGY CODE ###

# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()[::-1]
def nC2(n):
    if n<2:
        return 0
    return n*(n-1)//2

MOD = 2019
tmp = [0]*MOD
tmp[0] += 1
tens = 1
num = 0
for s in S:
    num += int(s) * tens
    key = num % MOD
    tmp[key] += 1
    tens *= 10

ans = 0
for i in tmp:
    ans += nC2(i)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


### FIXED CODE ###

# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
S = input()[::-1]

MOD = 2019
tmp = [0]*MOD
tmp[0] += 1
tens = 1
num = 0
for s in S:
    num += int(s) * tens
    num = num % MOD
    tmp[num] += 1
    tens *= 10
    tens %= MOD

ans = 0
for i in tmp:
    ans += i*(i-1)//2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))
### BUGGY CODE ###

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

L = [0] * (1000000)

for i in range(len(A)):
    for j in range(len(B)):
        tmp = A[i] + B[j] 
        L[i*1000+j] = tmp

L.sort(reverse=True)

ans_list = [0] * (3000000)

for i in range(min(K,len(L))):
    for j in range(len(C)):
        tmp = L[i] + C[j]
        ans_list[i*1000+j] = tmp

ans_list.sort(reverse=True)


for i in range(K):
    print(ans_list[i])

### FIXED CODE ###

#%%
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()

bc = [0] * (y * z)
q = 0
for i in range(y):
    for j in range(z):
        bc[q] = b[i] + c[j]
        q += 1

bc.sort(reverse=True)
r = len(bc)
bc = bc[:min(k, r)]

abc = [0] * (x * min(k, r))
q = 0
for i in range(min(k, r)):
    for j in range(x):
        abc[q] = bc[i] + a[j]
        q += 1

abc.sort(reverse=True)
for i in range(min(k, x*y*z)):
    print(abc[i])
### BUGGY CODE ###

n = int(input())
a = input().split()
b = []

for num in a:
    b = b + [num]
    b = b[::-1]

print(" ".join(b))

### FIXED CODE ###

from collections import deque

n = int(input())
a = input().split()
b = deque([])
for i, num in enumerate(a):
  if n%2 == i%2:
    b.append(num)
  else:
    b.appendleft(num)
    

print(" ".join(b))
### BUGGY CODE ###

k,s=map(int,input().split())
t=0

for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i+j+k==s:
                t+=1
print(t)


### FIXED CODE ###

k,s=map(int,input().split())
t=0

for i in range(k+1):
    for j in range(k+1):
        l=s-i-j
        if 0<=l<=k:
            t+=1
print(t)
### BUGGY CODE ###

n,*s=open(0)
n=int(n)
s=[tuple(t.rstrip())for t in s]
c=0
for _ in range(n):
  c+=all([x==y for x,y in zip(s,zip(*s))])*n
  s=s[1:]+s[:1]
print(c)

### FIXED CODE ###

n,*s=[t[:-1]for t in open(0)]
n=int(n)
c=0
for _ in range(n):
  c+=all(x==''.join(y)for x,y in zip(s,zip(*s)))*n
  s=s[1:]+s[:1]
print(c)
### BUGGY CODE ###

while True:
  n, x = map(int, raw_input().split())
  if n + x == 0: break
  ans = 0
  for i in range(n):
    tmp_ans = []
    tmp_ans.append(i+1)
    for j in range(n):
      if j not in tmp_ans and i <= j: 
        tmp_ans.append(j+1)
      for h in range(n):
        if h not in tmp_ans and j <= h: 
          tmp_ans.append(h+1)
        if sum(tmp_ans) == x: ans+= 1
  
  print ans

### FIXED CODE ###

while True:
  n, x = map(int, raw_input().split())
  if n + x == 0: break
  ans = 0
  for i in range(1, n+1):
    tmp_ans = []
    tmp_ans.append(i)
    for j in range(1, n+1):
      if j not in tmp_ans and i < j: 
        tmp_ans.append(j)
        for h in range(1, n+1):
          if h not in tmp_ans and j < h: 
            tmp_ans.append(h)
            if sum(tmp_ans) == x: ans+= 1
            tmp_ans.remove(h)
        tmp_ans.remove(j)
    tmp_ans.remove(i)
  
  print ans
### BUGGY CODE ###

N=int(input())
P=list(map(int,input().split()))
cnt=0

for i in range(N):
  if P[i]<=min(P[:i+1]):
    cnt+=1

print(cnt)


### FIXED CODE ###

N=int(input())
P=list(map(int,input().split()))
cnt=0
bar=P[0]
for i in range(N):
  if P[i]<=bar:
    bar=P[i]
    cnt+=1
print(cnt)
### BUGGY CODE ###

import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7


N, K, Q = rl()
A = []
for i in range(Q):
	a = ri()
	A.append(a)

scores = [K] * N
for a in A:
	idx = a-1
	for i in range(N):
		if i != idx:
			scores[i] -= 1
for s in scores:
	if s > 0:
		print('Yes')
	else:
		print('No')

### FIXED CODE ###

import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7


N, K, Q = rl()
A = []
for i in range(Q):
	a = ri()
	A.append(a)

scores = [0] * N
for a in A:
	idx = a-1
	scores[idx] += 1

for s in scores:
	if K > Q-s:
		print('Yes')
	else:
		print('No')
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0
for i in range(1, N//2+1):
    for j in range(N-2*i+1):
        #j~j+i, k~k+i(k>=j+i)
        one = S[j:j+i]
        if one in S[j+i:]:
            ans = i
            break
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
 
def z_algo(s):
    s_length = len(s)
    l, r = 0, 1
    Z = [0]*s_length
    Z[0] = s_length
    for i in range(1, s_length):
        if r<i:
            l, r = i, i
            while r<s_length and s[r]==s[r-l]:
                r += 1
            Z[i] = r-i
            r -= 1
        else:
            k = i-l
            if i+Z[k]-1<r:
                Z[i] = Z[k]
            else:
                l = i
                while r<s_length and s[r]==s[r-l]:
                    r += 1
                Z[i] = r-i
                r -= 1
    return Z

ans = 0
for i in range(N):
    z = z_algo(S[i:])
    for j in range(i, N):
        ans = max(ans, min(j-i, z[j-i]))
print(ans)
### BUGGY CODE ###

import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in c.items():
  for j in L:
    if v in b:
      for i in b[v]:
        if i < j:
          ans += 1
        else:
          break
print(ans)

### FIXED CODE ###

import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
n = int(readline())
a = list(map(int, readline().split()))
b = defaultdict(list)
c = defaultdict(list)

for i, v in enumerate(a, 1):
  b[i + v].append(i)
  if 2 <= i - v <= 100000001:
    c[i - v].append(i)
c = dict(c)

ans = 0
for v, L in b.items():
  for j in L:
    if v in c:
      ans += len(c[v])
print(ans)
### BUGGY CODE ###

print(sum(range(int(input()))))

### FIXED CODE ###

N=int(input())
print(N * (N-1) // 2)
### BUGGY CODE ###

A,B,C,D = list(map(int,input().split()))
integer = (i for i in range(A, B+1))
cnt = 0
for x in integer:
    if x % C != 0 and x % D != 0:
        cnt += 1
print(cnt)

### FIXED CODE ###

import fractions
def lcm(C,D):
    return C*D//fractions.gcd(C,D)
A,B,C,D = map(int, input().split())
b = (B - B//C - B//D + B//lcm(C,D))
a = ((A-1) - (A-1)//C- (A-1)//D + (A-1)//lcm(C,D))
print(b-a)
### BUGGY CODE ###

x=int(input())
for i in range(-10**9,10**9):
    for j in range(-10**9,10**9):
        if i**5-j**5==x:
            print(i,j)
            break

### FIXED CODE ###

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

N = int(input())
A = [int(i) for i in input().split()]
ans = 0
if N % 2 != 0:
    num_list = [int(i) for i in range(2, N, 2)]
    for num in num_list:
        if A.count(num) != 2:
            break
    else:
        if A.count(0) == 1:
            ans = 2 ** (N // 2)

else:
    num_list = [int(i) for i in range(1, N, 2)]
    for num in num_list:
        if A.count(num) != 2:
            break
    else:
        ans = 2 ** (N // 2)

print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 1
if N % 2 == 0:
    if len(A) != 2*len(set(A)):
        ans = 0
else:
    if A.count(0) == 1:
        A.remove(0)
        if len(A) != 2*len(set(A)):
            ans = 0
    else:
        ans = 0
if ans == 0:
    print(0)
else:
    print((2**(N//2))%(10**9+7))
### BUGGY CODE ###

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

A.sort()
for i in range(M):
    A[-1] = A[-1]//2
    A.sort()

print(sum(A))


### FIXED CODE ###

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

A.sort()
while M != 0:
    x = bisect.bisect_left(A,A[-1]/2)
    if N-x <= M:
        M -= N-x
        for i in range(x,N):
            A[i] = A[i]/2
        A.sort()
    else:
        for i in range(N-M,N):
            A[i] = A[i]/2
        M = 0
        A.sort()

print(sum(map(int,A)))
### BUGGY CODE ###

#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[]

for i in range(N-1):
  if S[i:i+2]=="AC":
    AC.append(1)
  else:
    AC.append(0)

for i in range(Q):
  print(sum(AC[lr[i][0]-1:lr[i][1]-1]))

### FIXED CODE ###

#conding utf-8
N,Q=map(int,input().split())
S=input()
lr=[[int(i) for i in input().split()] for i in range(Q)]

AC=[0]
tmp=0
for i in range(N-1):
  if S[i:i+2]=="AC":
    tmp=tmp+1
  AC.append(tmp)

for i in range(Q):
  print(AC[lr[i][1]-1]-AC[lr[i][0]-1])