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

A = tuple(range(12700))

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


### FIXED CODE ###

from collections import defaultdict
from bisect import bisect_right

def sol():
    S = input()
    T = input()

    setS = set(S)
    setT = set(T)
    for t in setT:
        if not t in setS:
            print('-1')
            return

    posS = defaultdict(list)

    for i, s in enumerate(S):
        posS[s].append(i)

    for s in enumerate(S):
        posS[s].sort()

    prev = -1
    ans = 0
    N = len(S)

    for t in T:
        next = bisect_right(posS[t], prev)
        if next >= len(posS[t]):
            ans += N - prev
            ans += posS[t][0]
            prev = posS[t][0]
        else:
            ans += posS[t][next] - prev
            prev = posS[t][next]

    print(ans)

sol()
### BUGGY CODE ###

K, S = map(int, input().split())
cnt = 0
for x in range(K + 1):
    for y in range(K + 1):
        for z in range(K + 1):
            if x + y + z == S:
                cnt += 1
print(cnt)

### FIXED CODE ###

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

import sys
sys.setrecursionlimit(1000000)
N=int(input())
ab=[[] for _ in range(N)]
for _ in range(N-1):
  a,b=map(int,input().split())
  ab[a-1].append(b)
  ab[b-1].append(a)


def dfs(pre,p,pa):
  global path
  if p==N:
    path=pa
  else:
    for i in ab[p-1]:
      if i!=pre:
        dfs(p,i,pa+[i])

dfs(-1,1,[1])
spath=set(path)

def dfs2(pre,p):
  a=0
  for i in ab[p-1]:
    if i in spath:
      pass
    elif i==pre:
      pass
    else:
      a+=dfs2(p,i)
  return 1+a

ff=0
sf=0
L=len(path)
for i in range(L):
  if i<=(L-1)//2:
    ff+=dfs2(-1,path[i])
  else:
    sf+=dfs2(-1,path[i])
    
if ff>sf:
  print("Fennec")
else:
  print("Snuke")


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
N=int(input())
ab=[[] for _ in range(N)]
for _ in range(N-1):
  a,b=map(int,input().split())
  ab[a-1].append(b)
  ab[b-1].append(a)
"""
N=10**5
ab=[[]]*N
ab[0]=[2]
ab[N-1]=[N-1]
for i in range(1,N-1):
  ab[i]=[i,i+2]
"""
par=[0]*N
  
def dfs(pre,p):
  global path
  par[p-1]=pre
  if p==N:
    pass
  else:
    for i in ab[p-1]:
      if i!=pre:
        dfs(p,i)

dfs(-1,1)
path=[N]
p=N
while p!=1:
  p=par[p-1]
  path.append(p)
path.reverse()

spath=set(path)

def dfs2(pre,p):
  a=0
  for i in ab[p-1]:
    if i in spath:
      pass
    elif i==pre:
      pass
    else:
      a+=dfs2(p,i)
  return 1+a

ff=0
sf=0
L=len(path)
for i in range(L):
  if i<=(L-1)//2:
    ff+=dfs2(-1,path[i])
  else:
    sf+=dfs2(-1,path[i])
    
if ff>sf:
  print("Fennec")
else:
  print("Snuke")
### BUGGY CODE ###

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

if N ==1:
    print(P)
    exit()
 
i=1
a = i**N
 
while a<=P:
    if P%a == 0:
        ans = i
    i = i+1
    a = i**N
    
print(ans)

### FIXED CODE ###


N,P=map(int,input().split())
if N==1:
    print(P)
    exit()
elif P==1:
    print(1)
    exit()

PO=P
K=[0]*(int(P**0.5)+1)

for i in range(2,int(P**0.5)):
    while P%i==0:
        K[i]+=1
        P=P//i
    K[i]=K[i]//N
    if P==1:
        break

ans=1
for i in range(2,int(PO**0.5)):
    if K[i]!=0:
        ans*=i**K[i]

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

N=int(input())
A=list(map(int,input().split()))
L=[i+A[i] for i in range(N)]
R=[i-A[i] for i in range(N)]
sum=0
for i in L:
  sum=sum+R.count(i)
print(sum)

### FIXED CODE ###

n=int(input())
A=list(map(int,input().split()))
L=[]
R=[]
for i in range(n):
  L.append(i+A[i])
  R.append(i-A[i])
from collections import Counter
zisyo=Counter(R)
ans=0
for i in L:
  ans=ans+zisyo.get(i,0)
print(ans)
### BUGGY CODE ###

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

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,input().split())
    val[a-1] += b 
visited = [True for i in range(N)]

def dps(i): 
    visited[i] = False
    if sum(visited) == 0 :
        return 1
    else :
        for j in graph[i]:
            if visited[j]:
                val[j] += val[i]
                dps(j)
                
dps(0)
for i in val:
    print(i,end=" ")

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
readline = sys.stdin.readline
N,Q =  map(int,input().split())
graph = [[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,readline().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

val = [0 for i in range(N)]
for i in range(Q):
    a,b = map(int,readline().split())
    val[a-1] += b 

def dps(i,parent): 
    for j in graph[i]:
        if j == parent:
            continue
        val[j] += val[i]
        dps(j,i)
                
dps(0,-1)
print(*val)
### BUGGY CODE ###

def next_locations(maze, H, W, i, j):
    if maze[i][j] == '#':
        return list()
    locations = list()
    if i - 1 >= 0 and maze[i - 1][j] == '.':
        locations.append((i - 1, j))
    if i + 1 < H and maze[i + 1][j] == '.':
        locations.append((i + 1, j))
    if j - 1 >= 0 and maze[i][j - 1] == '.':
        locations.append((i, j - 1))
    if j + 1 < W and maze[i][j + 1] == '.':
        locations.append((i, j + 1))
    return locations


def location_to_index(W, i, j):
    return W * i + j


def warshall_floyd(V, d):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                d[i][j] = min([d[i][j], d[i][k] + d[k][j]])
    return d


def main():
    H, W = list(map(int, input().split(' ')))
    INF = H * W
    maze = list()
    for _ in range(H):
        maze.append(input())
    d = [[INF for _ in range(H * W)] for _ in range(H * W)]
    for i in range(H):
        for j in range(W):
            from_index = location_to_index(W, i, j)
            locs = next_locations(maze, H, W, i, j)
            for loc in locs:
                to_index = location_to_index(W, loc[0], loc[1])
                d[from_index][to_index] = 1 if from_index != to_index else 0
    d = warshall_floyd(H * W, d)
    answer = 0
    for from_index in range(H * W):
        for to_index in range(H * W):
            dist = d[from_index][to_index]
            if dist == INF:
                continue
            if dist > answer:
                answer = dist
    print(answer)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall


def next_locations(maze, H, W, i, j):
    if maze[i][j] == '#':
        return list()
    locations = list()
    if i - 1 >= 0 and maze[i - 1][j] == '.':
        locations.append((i - 1, j))
    if i + 1 < H and maze[i + 1][j] == '.':
        locations.append((i + 1, j))
    if j - 1 >= 0 and maze[i][j - 1] == '.':
        locations.append((i, j - 1))
    if j + 1 < W and maze[i][j + 1] == '.':
        locations.append((i, j + 1))
    return locations


def location_to_index(W, i, j):
    return W * i + j


def main():
    H, W = list(map(int, input().split(' ')))
    INF = H * W
    maze = list()
    for _ in range(H):
        maze.append(input())
    d = [[INF for _ in range(H * W)] for _ in range(H * W)]
    for i in range(H):
        for j in range(W):
            from_index = location_to_index(W, i, j)
            locs = next_locations(maze, H, W, i, j)
            for loc in locs:
                to_index = location_to_index(W, loc[0], loc[1])
                d[from_index][to_index] = 1 if from_index != to_index else 0
    d = csgraph_from_dense(d, null_value=INF)
    d = floyd_warshall(d)
    answer = 0
    for from_index in range(H * W):
        for to_index in range(H * W):
            dist = d[from_index][to_index]
            if dist == float('inf'):
                continue
            if dist > answer:
                answer = dist
    print(int(answer))


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

n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  if ind==0:
    d=B[1]+B[-1]
  elif ind==n-1:
    d=B[-2]+B[0]
  else:
    d=B[ind-1]+B[ind+1]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(B[ind],ind)
  
print(ans)


### FIXED CODE ###

n=int(input())
A=[int(i) for i in input().split()]
B=[int(i) for i in input().split()]

from heapq import heappop, heappush
push = lambda x,i: heappush(BB,(-x,i))
BB=[]

for i,b in enumerate(B):
  push(b,i)

ans=0
while BB:
  b,ind=heappop(BB)
  b,ai=-b,A[ind]
  if b<ai:
    ans=-1
    break
  d=B[(ind-1)%n]+B[(ind+1)%n]
  dd=(b-ai)//d
  if dd==0:
    if b==ai:
      continue
    ans=-1
    break
  ans+=dd
  B[ind]-=d*dd
  push(b-d*dd,ind)
  
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    big = pow(10, 18)
    ret = 1
    for a in A:
        ret *= a
    if ret > big:
        print(-1)
    else:
        print(ret)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    big = pow(10, 18)
    ret = 1
    if 0 in A:
        print(0)
        return
    for a in A:
        ret *= a
        if ret > big:
            print(-1)
            return
    print(ret)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

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

import numpy as np
s = input()
t = input()
dp = np.zeros((len(s)+1, len(t)+1))

for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1]+1
        else :
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

l = int(dp[len(s)-1][len(t)-1])
i = len(s)-1
j = len(t)-1
ans = []

while dp[i][j]:
    if s[i] == t[j]:
        ans.append(s[i])
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else :
        j -= 1
print(''.join(ans[::-1]))


### FIXED CODE ###

import numpy as np
s = np.array(list(input()))
t = np.array(list(input()))
dp = np.zeros((len(s)+1, len(t)+1), dtype=int)

equal = s[:, None] == t[None, :]

for i in range(len(s)):
    dp[i+1, 1:] = np.maximum(dp[i, :-1]+equal[i], dp[i, 1:])
    dp[i+1] = np.maximum.accumulate(dp[i+1])

i = len(s)
j = len(t)
ans = []

while i>0 and j>0:
    if s[i-1] == t[j-1]:
        ans.append(s[i-1])
        i -= 1
        j -= 1
    elif dp[i][j] == dp[i-1][j]:
        i -= 1
    else :
        j -= 1

print(''.join(ans[::-1]))
### BUGGY CODE ###

N,*A =map(int,open(0).read().split())

for i in range(1,N+1):
  print(max(A[:i-1]+A[i:]))

### FIXED CODE ###

N,*A =map(int,open(0).read().split())
B =sorted(A)
biggest = B[-1]
for i in A:
  if i==biggest:
    print(B[-2])
  else:
    print(biggest)
### BUGGY CODE ###

n, x, y = map(int, input().split())
edge = [[] for _ in range(n+1)]
dist = [[-1 for i in range(n+1)] for j in range(n+1)]
counter = [0 for i in range(n)]
for i in range(1, n):
    edge[i].append(i+1)
    edge[i+1].append(i)
edge[x].append(y)
edge[y].append(x)
# print(edge)

def search(now_edge, i, depth):
    next_list = []
    for next_edge in edge[now_edge]:
        if dist[i][next_edge]==-1:
            dist[i][next_edge] = depth
            dist[next_edge][i] = depth
            next_list.append(next_edge)
    for next_edge in next_list:
        search(next_edge, i, depth+1)

for i in range(1, n+1):
    now_edge = i
    depth = 0
    dist[i][now_edge] = depth
    search_set = set(edge[now_edge])
    while -1 in dist[i][1:]:
        now_search = search_set
        search_set = set()
        depth += 1
        for next_edge in now_search:
            if dist[i][next_edge]==-1:
                dist[i][next_edge] = depth
                dist[next_edge][i] = depth
                search_set = search_set.union(edge[next_edge])
            elif dist[i][next_edge]==depth:
                search_set = search_set.union(edge[next_edge])
    for num in dist[i][1:]:
        counter[num] += 1
# print(dist)

for num in counter[1:]:
    print(num//2)

### FIXED CODE ###

n, x, y = map(int, input().split())
edge = [[] for _ in range(n+1)]
dist = [[abs(i-j) for i in range(n+1)] for j in range(n+1)]
counter = [0 for i in range(n)]
for i in range(1, n):
    edge[i].append(i+1)
    edge[i+1].append(i)
edge[x].append(y)
edge[y].append(x)
for i in range(y+1):
    for j in range(x, n+1):
        if j > i:
            new_dist = abs(x-i)+abs(y-j)+1
            if new_dist < dist[i][j]:
                dist[i][j] = new_dist

for i in range(1, n+1):
    for num in dist[i][i+1:]:
        counter[num] += 1
# print(dist)

for num in counter[1:]:
    print(num)
### BUGGY CODE ###

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

a = sorted(a)
w = 0
while True:
    h = 1
    cn = 0
    while True:
        if w + h == len(a):
            '''
            print(a)
            '''
            if cn == 1:
                del a[w]
                w -= 1
            break
        if a[w] == a[w+h]:
            cn =1
        if a[w+h] % a[w] == 0:
            '''
            print(h)
            '''
            del a[w+h]
        else:
            '''
            print(a[w+h], h, w, a)
            '''
            h += 1
    w += 1
    if w == len(a):
        print(len(a))
        exit()


### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
prime = [True] * (10 ** 6 + 10)

b = sorted(set(a))

for i in b:
    num = i * 2
    while True:
        if num >= 10 ** 6 + 1:
            break
        prime[num] = False
        num += i

ans = 0
for s in a:
    if prime[s] == True and c[s] == 1:
        ans += 1

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

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

E = []
for p in P:
    e = ((p * p + p) / 2) * (1 / p)
    E.append(e)

ans = 0
for i in range(0, N - K + 1):
    ans = max(ans, sum(E[i:i + K]))

print(ans)


### FIXED CODE ###

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

E = []
for p in P:
    e = ((p * p + p) / 2) * (1 / p)
    E.append(e)

memo = sum(E[:K])
ans = memo
for i in range(0, N - K):
    memo = memo - E[i] + E[i + K]
    ans = max(ans, memo)

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

n = int(input())
a = [int(input()) for i in range(n)]
# n = 6
# a = [5,6,7,2,6,4]

b = [a[0]]
minb = a[0]
count = 1
for i in range(1,n):
    if minb < a[i]:
        for j in range(len(b)):
            if b[j] < a[i]:
                b[j] = a[i]
                minb = min(b)
                break
    else:
        b += [a[i]]
        count += 1
        minb = a[i]

print(count)


### FIXED CODE ###

import bisect

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

b = []
for i in range(n):
    k = bisect.bisect(b,-a[i])
    if k == len(b):
        b.append(-a[i])
    else:
        b[k] = -a[i]

print(len(b))
### BUGGY CODE ###

A, B, K = list(map(int, input().split()))

time = 0

while time < K:
    if A == 0 and B > 0:
        B = B - 1
    if A > 0:
        A = A - 1
    time = time + 1
A = str(A)
B = str(B)
print(A+" "+B)

### FIXED CODE ###

A, B, K = list(map(int, input().split()))

if A >= K:
    A = A - K
    A = str(A)
    B = str(B)
    print(A+" "+B)
else:
    K = K - A
    if B <= K:
        print("0 0")
    if B > K:
        B = B - K
        A = "0"
        B = str(B)
        print(A+" "+B)
### BUGGY CODE ###

import sys
import numpy as np

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))

for _ in range(M):
    a = np.max(A)
    n = A.argmax()
    A[n] = int(a / 2)
    
ans = sum(A)

print(ans)

### FIXED CODE ###

import sys
import numpy as np
import bisect

N, M = map(int, sys.stdin.readline().split())
A = np.array(list(map(int, sys.stdin.readline().split())))
A.sort()

max = A[N - 1]

count = 0

while count < M:
    max = A[N - 1]
    c = bisect.bisect_left(A, int(max / 2))
    add = N - c
    if count + add > M:
        d = M - count
        A[-d:] = A[-d:] // 2
        break
    else:
        A[c:] = A[c:] // 2
        count += add
        if count == M:
            break
    A.sort()
    
ans = int(sum(A))

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

n = int(input())

sum = 0
for i in range(1, n):
    sum += i

print(sum)


### FIXED CODE ###

n = int(input())
print(sum(range(1, n)))
### BUGGY CODE ###

import sys
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
# discounts = list(list(map(int, input().split())) for _ in )

discounts = dict()
for discount in sys.stdin:
    x, y, c = discount.split()
    c = int(c)
    if x in discounts:
        if y in discounts[x]:
            if discounts[x][y] < c:
                discounts[x][y] = c
        else:
            discounts[x][y] = c
    else:
        discounts[x] = {y: c}

min = -1
for i in range(len(a_list)):
    b_line_prices = []
    for j in range(len(b_list)):
        price = a_list[i] + b_list[j]
        x = str(i + 1)
        y = str(j + 1)
        if x in discounts:
            if y in discounts[x]:
                price -= discounts[x][y]
        if min == -1 or price < min:
            min = price
print(min)

### FIXED CODE ###

import sys
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

ans = min(a_list) + min(b_list)
for discount in sys.stdin:
    x, y, c = map(int, discount.split())
    ans = min(ans, a_list[x - 1] + b_list[y - 1] - c)
print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(1000000)




def main():
    n = int(input())
    x_dic = {}
    y_dic = {}
    i = 0
    for a in map(int, input().split()):
        x_dic[i] = a + i
        y_dic[i] = i - a
        i += 1

    count = 0
    for i in range(n):
        ai = x_dic[i]
        for j in range(i+1, n):
            # combi = (i,j)
            if ai == y_dic[j]:
                count += 1
    print(count)



main()


### FIXED CODE ###

def is_ok(mid: int, target: int, ls: []):
    return target <= ls[mid]


def bi_search(target: int, ls: []):
    ng = -1
    ok = len(ls)

    cnt = 0
    while ok - ng > 1:
        mid = ng + int((ok - ng) / 2)
        cnt += 1
        if is_ok(mid, target, ls):
            ok = mid
        else:
            ng = mid
    return ok


def main():
    n = int(input())
    l_dic = {}
    r_dic = {}
    i = 0
    for a in map(int, input().split()):
        ld = l_dic.setdefault(i + a, [])
        ld.append(i)
        rd = r_dic.setdefault(i - a, [])
        rd.append(i)
        i += 1

    count = 0
    for rk, rv_list in r_dic.items():
        if rk not in l_dic:
            continue
        lv_list = l_dic[rk]
        for rv in rv_list:
            ind = bi_search(rv, lv_list)
            if ind == len(lv_list):
                count += ind
            else:
                count += ind + 1
            # for lv in lv_list:
            #     if lv < rv:
            #         count += 1
            #     else:
            #         break

    print(count)


main()
### BUGGY CODE ###

X = int(input())
diff = 1
for i in range(2,X):
    if X % i == 0:
        diff = i
        break

s = (10 **9)//2
while True:
    ss = s//2
    A = ss 
    B = ss - diff
    xx = A ** 5 - B ** 5
    if xx == X:
        break
    elif xx > X:
        s = ss //2
    else:
        s =  (3*ss) //4
print(int(A),int(B))

### FIXED CODE ###

def main():
    X = int(input())
    for B in range(-120,121):
        for A in range(B,121):
            xx = A**5 -B ** 5
            if X ==  xx:
                print(A,B)
                return
            elif X <xx:
                break

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

n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in set(a):
    temp = a.count(i)
    if temp > i:
        ans += temp - i
    elif temp < i:
        ans += temp

print(ans)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
dic = {}
for i in a:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1
ans = 0
for k, v in dic.items():
    if k > v:
        ans += v
    elif k < v:
        ans += v-k

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

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

ans = 0
for i in range(n-2):
    h = a[i]
    for j in range(i+h, min(n, i+max+h+1)):
        if abs(i-j) == h+a[j]:
            ans += 1

print(ans)


### FIXED CODE ###

from collections import Counter

n = int(input())
a = list(map(int, input().split()))
ans = 0
l=[]
for i in range(n):
    l.append(i-a[i])
cnt = Counter(l)
for i in range(n):
    ans += cnt[i+a[i]]

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

H,W = map(int, input().split())
A = []
for _ in range(H):
    A += [ [ 1 if x == "#" else 0 for x in input()] ]

import numpy as np


A = np.array(A)
WK = np.zeros(A.shape)
i = 0
S = H * W
while True:
    if np.sum(A) == S:
        break
    WK = 0+A
    A[:-1] |= WK[1:]
    A[1:] |= WK[:-1]
    A[:,:-1] |= WK[:,1:]
    A[:,1:] |= WK[:,:-1]
    i += 1

print(i)


### FIXED CODE ###

from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = [None] * (H*W)
matS = matE = 0
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat[matE] = (h, w, 0)
            matE+=1
    dp[h] = s

def search(dp, mat, nH, nW, cnt):
    global matE
    if dp[nH][nW] == ".":
        mat[matE] = (nH, nW, cnt+1)
        matE+=1
        dp[nH][nW] = "#"

while matS < matE:
    h, w, cnt = mat[matS]
    matS += 1

    if h > 0:
        search(dp, mat, h - 1, w, cnt)
    if h < H-1:
        search(dp, mat, h + 1, w, cnt)
    if w > 0:
        search(dp, mat, h , w - 1, cnt)
    if w < W-1:
        search(dp, mat, h , w + 1, cnt)

print(cnt)