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

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

b_list = []

for a in a_list:
    b_list.append(a)
    b_list.reverse()

print(" ".join(map(str, b_list)))


### FIXED CODE ###

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

b_list_even = []
b_list_odd = []
for i, a in enumerate(a_list , start=1):
    if i % 2 == 0:
        b_list_even.append(a)
    else:
        b_list_odd.append(a)


if n % 2 != 0:
    b_list_odd.reverse()
    b_list = b_list_odd + b_list_even
else:
    b_list_even.reverse()
    b_list = b_list_even + b_list_odd

print(" ".join(map(str, b_list)))
### BUGGY CODE ###

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
l=[[] for _ in range(n)]
for i in range(m):#各部屋の通じてる部屋番のリストを作る
    a=ab[i][0]
    b=ab[i][1]
    l[a-1].append(b)
    l[b-1].append(a)

l_depth=[]
l_depth.append(1)
l_depth_sub=[0]*n
l_depth_sub[0]+=1

for i in range(n):#深さのリストを作る
    for j in range(len(l[i])):
        if l_depth_sub[l[i][j]-1]==0:
            l_depth_sub[l[i][j]-1]+=1
            l_depth.append(l[i][j])
                
    if l_depth_sub.count(0)==0:break

print('Yes')
for i in range(1,n):
    k=10**9
    for j in range(len(l[i])):
        if l_depth.index(l[i][j])<k:
            k=l_depth.index(l[i][j])
    print(l_depth[k])


### FIXED CODE ###

import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
 
g=nx.Graph() #無向グラフ
g.add_edges_from(s) #リストsを参照して頂点（部屋）の追加
di=nx.predecessor(g,source=1)#1から全点までの最短路におけるその点の前の点を表示
 
print("Yes")
for x in range(2,n+1):
      print(di[x][0])
### BUGGY CODE ###

N = int(input())
inp = list(map(lambda x: int(x), input().split(" ")))

counts = {}
for i in range(N):
    counts[inp[i]] = 0
for i in range(N):
    counts[inp[i]] += 1

ret = {}

for i in range(N):
    ret[inp[i]] = -1

for i in range(N):
    if (ret[inp[i]] != -1):
        print(ret[inp[i]])
    else:
        sum1 = 0
        for k in counts.keys():
            if (k==inp[i]):
                sum1 += (counts[k]-1)*(counts[k]-2)//2
            else:
                sum1 += (counts[k])*(counts[k]-1)//2
        ret[inp[i]] = sum1
        print(sum1)


### FIXED CODE ###

N = int(input())
inp = list(map(lambda x: int(x), input().split(" ")))

counts = {}
for i in range(N):
    counts[inp[i]] = 0
for i in range(N):
    counts[inp[i]] += 1

ret = {}

allsum = 0
for k in counts.keys():
    allsum += counts[k]*(counts[k]-1)//2

for i in range(N):
    print(allsum - counts[inp[i]]+1)
### BUGGY CODE ###

# D - Integer Cards
# https://atcoder.jp/contests/abc127/tasks/abc127_d

import sys

n, m = list(map(int, sys.stdin.readline().split()))
cards = list(map(int, sys.stdin.readline().split()))
cards.sort()

combinations = []
for i in range(m):
    combinations.append(list(map(int, sys.stdin.readline().split())))

combinations = sorted(combinations, key=lambda x: x[1])

# c[i]より小さい数があればb[i]枚まで入れ替えていい
for index in reversed(range(len(combinations))):
    cnt = 0
    for i in range(len(cards)):
        if cards[i] < combinations[index][1] and cnt < combinations[index][0]:
            cards[i] = combinations[index][1]
            cnt += 1

print(sum(cards))

### FIXED CODE ###

# D - Integer Cards
# https://atcoder.jp/contests/abc127/tasks/abc127_d

import sys

n, m = list(map(int, sys.stdin.readline().split()))
cards = list(map(int, sys.stdin.readline().split()))

combinations = [list(map(int, sys.stdin.readline().split())) for _ in range(m)]

cards.sort()
combinations.sort(key=lambda x: x[1], reverse=True)

i = 0
for b, c in combinations:
    for k in range(i, min(n, i + b)):
        if cards[k] < c:
            cards[k] = c
            i += 1
        else:
            break

print(sum(cards))
### BUGGY CODE ###

import math

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

ans = 1
for num in range(N):
    if 0 in A:
        ans = 0
        break
    ans *= A[num]
    if ans > math.pow(10, 18):
        ans = -1
        break

print(ans)

### FIXED CODE ###

import math

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

ans = 1
for num in range(N):
    ans *= A[num]
    if ans > math.pow(10, 18):
        ans = -1
        break

if 0 in A:
    ans = 0

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

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

BC = []
for _ in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
    
def reverse_insort(a, x, lo=0, hi=None):
    """Insert item x in list a, and keep it reverse-sorted assuming a
    is reverse-sorted.

    If x is already in a, insert it to the right of the rightmost x.

    Optional args lo (default 0) and hi (default len(a)) bound the
    slice of a to be searched.
    """
    if lo < 0:
        raise ValueError('lo must be non-negative')
    if hi is None:
        hi = len(a)
    while lo < hi:
        mid = (lo+hi)//2
        if x > a[mid]: hi = mid
        else: lo = mid+1
    a.insert(lo, x)

cards = A[:]
cards  =sorted(cards, reverse=True)

opes = BC[:]

for b, c in opes:
    for _ in range(b):
        if cards[-1] > c:
            break
        else:
            cards.pop()
            reverse_insort(cards, c)
            
ans = sum(cards)
#print(cards)
print(ans)
            


### FIXED CODE ###

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

BC = []
for _ in range(M):
    b, c = map(int, input().split())
    BC.append((b, c))
    
cards = A[:]
opes = BC[:]

cards_dict = {}

for c in cards:
    if c in cards_dict:
        cards_dict[c] += 1
    else:
        cards_dict[c] = 1

for b, c in opes:
    if c in cards_dict:
        cards_dict[c] += b
    else:
        cards_dict[c] = b
        
cards_dict = sorted(cards_dict.items(), reverse=True)
#print(cards_dict)

num = 0
ans = 0
for k, v in cards_dict:
    if num + v > N:
        ans += k * (N-num)
        num = N
    else:
        ans +=  k * v
        num += v
    if num == N:
        break
        
print(ans)
### BUGGY CODE ###

n, m = map(int, input().split())
n += 1
s = input()
dst = [float("inf")]*n
dst[-1] = 0

for i in reversed(range(n-1)):
    if s[i] == "1":
        continue
    for j in range(min(n-1-i, m)):
        # print(i, j)
        if s[i+j+1] == "0":
            dst[i] = min(dst[i], dst[i+j+1]+1)

# print(dst)
if dst[0] == float("inf"):
    print(-1)
else:
    last_idx = 0
    last_num = dst[0]
    ans = []
    for i in range(1, n):
        if dst[i] != float("inf") and dst[i] != last_num:
            ans.append(i - last_idx)
            last_num = dst[i]
            last_idx = i

    print(*ans)



### FIXED CODE ###

n, m = map(int, input().split())
n += 1
s = input()
dst = [float("inf")]*n
dst[-1] = 0
m_last = n-1

for i in reversed(range(n-1)):
    if s[i] == "1":
        continue
    for j in reversed(range(min(m_last+1, i+m+1))):
        # print(i, j)
        if s[j] == "0":
            dst[i] = dst[j]+1
            m_last = j
            break

    if dst[i] == float("inf"):
        print(-1)
        exit()

# print(dst)
last_idx = 0
last_num = dst[0]
ans = []
for i in range(1, n):
    if dst[i] != float("inf") and dst[i] != last_num:
        ans.append(i - last_idx)
        last_num = dst[i]
        last_idx = i

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

s=input()
n=int(input())
for i in range(n):
  a=list(input())
  if a[0]=="1":
    s=s[::-1]
  else:
    if a[2]=="1":
      s=a[4]+s
    else:
      s=s+a[4]
print(s)

### FIXED CODE ###

from collections import deque
S=list(input())
Q=int(input())
query=[]
reverseflg=False
S=deque(S)

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

for q in range(Q):
  if query[q][0]=="1":
    reverseflg= not reverseflg
  
  if query[q][0]=="2":
    if query[q][1]=="1":
      if reverseflg== False:
        S.appendleft(query[q][2])
      else:
        S.append(query[q][2])
    
    else:
      if reverseflg== False:
        S.append(query[q][2])
      else:
        S.appendleft(query[q][2])

if reverseflg==True:
  S.reverse()
  
print(''.join(S))
### BUGGY CODE ###

n, k = map(int, input().split())

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


li_cost = [float("inf")] * n

li_cost[0] = 0

# i = 現在の足場
for i in range(n):
    for a in range(1, k + 1):
        if i + a < n:
            li_cost[i + a] = min(abs(li_h[i] - li_h[i + a]) + li_cost[i], li_cost[i + a])

print(li_cost[-1])



### FIXED CODE ###

n, k = map(int, input().split())

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


dp = [float("inf")] * n

dp[0] = 0

for i in range(1, n):
    w = i - k if i - k > 0 else 0
    dp[i] = min([cost + abs(height - li_h[i]) for cost, height in zip(dp[w:i], li_h[w:i])])

print(dp[-1])
### BUGGY CODE ###

from sys import stdin
import sys
sys.setrecursionlimit(10**7)


class DFS():
    def __init__(self,N,S):
        self.N = N
        self.S = S
        self.seen = [False] * (self.N + S[-1])
        self.cnt = [0] * self.N

    def dfs(self, i):
        if self.seen[i]:
            return self.cnt[i]
        if i == self.N-1:
            return 1
        elif i > self.N-1:
            return 0
        else:
            cnt = 0
            for s in self.S:
                cnt += self.dfs(i+s)
            else:
                self.cnt[i] = cnt % 998244353
                self.seen[i] = True
            return self.cnt[i]


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int, _in[0].split(' ')))  # type:list(int)
    L_R_arr = []
    for i in range(K):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        L_R_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 0
    S = []
    for L, R in L_R_arr:
        S.extend([i for i in range(L, R+1)])
    S = sorted(set(S))

    dfs = DFS(N, S)
    dfs.dfs(0)
    ans = dfs.cnt[0] % 998244353
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from sys import stdin
import sys
sys.setrecursionlimit(10**7)


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, K = list(map(int, _in[0].split(' ')))  # type:list(int)
    L_R_arr = []
    for i in range(K):
        _ = list(map(int, _in[i+1].split(' ')))  # type:list(int)
        L_R_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    dp = [0] * N
    sdp = [0] * (N+1)
    dp[0] = 1
    for i in range(N):
        for L, R in L_R_arr:
            right = max(0, i-L+1)
            left  = max(0, i-R)
            dp[i] += sdp[right] - sdp[left]
        else:
            sdp[i+1] = (sdp[i] + dp[i]) % 998244353
    ans = dp[-1] % 998244353
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


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

from collections import deque


def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    q = deque()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                q.append((i, j, 0))
    visited = [[0] * W for _ in range(H)]
    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while len(q):
        i, j, cost = q.popleft()
        if visited[i][j]:
            continue
        visited[i][j] = cost
        for d in directions:
            ni = i + d[0]
            nj = j + d[1]
            if 0 <= ni < H and 0 <= nj < W and visited[ni][nj] == 0:
                q.append((ni, nj, cost+1))
    print(max([max(x) for x in visited]))


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque


def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    q = deque()
    visited = [[False] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                q.append((i, j, 0))
                visited[i][j] = True
    ans = 0
    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while len(q):
        i, j, cost = q.popleft()
        ans = max(ans, cost)
        for d in directions:
            ni = i + d[0]
            nj = j + d[1]
            if 0 <= ni < H and 0 <= nj < W and not visited[ni][nj]:
                q.append((ni, nj, cost+1))
                visited[ni][nj] = True
    print(ans)


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

N = int(input())
S = input()
list = [0]*N

for i in range(N-1):
    list[i+1] = 1 if S[i:i+2] == '#.' else 0

for i in range(N-1):
    if list[i] == 1 and (S[:i-1].count('.') == len(S[:i-1])):
        list[i-1] = 1
        list[i] = 0
    elif list[i] == 1 and S[i+1] == '.':
        list[i+1] = 1

print(sum(list))

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N = int(input())
S = input()

result = S.count('.')
r = result
def dfs(i):
    global result
    global r
    if i == N:
        return float('inf')
    if S[i] == '#':
        r += 1
    else:
        r -= 1
    result = min(result,r)
    return min(result,dfs(i+1))

print(dfs(0))
### BUGGY CODE ###

N, M = map(int, input().split())
afs = []
for i in range(M):
  a, b = map(int, input().split())
  cs = map(int, input().split())
  f = 0
  for c in cs:
    f = f|(1<<(c-1))
  afs.append((a, f))
dp = [{} for i in range(M+1)]
dp[0][0] = 0
for i in range(M):
  d = dp[i]
  a0, f0 = afs[i]
  d2 = {}
  for f in d:
    d2[f] = d[f]
  for f in d:
    f2 = f|f0
    a2 = d[f]+a0
    d2[f2] = a2 if f2 not in d2 else min(d2[f2], a2)
  dp[i+1] = d2
#print(dp)
if (1<<N)-1 in dp[M]:
  r = dp[M][(1<<N)-1]
else:
  r = -1
print(r)


### FIXED CODE ###

N, M = map(int, input().split())
afs = []
for i in range(M):
  a, b = map(int, input().split())
  cs = map(int, input().split())
  f = 0
  for c in cs:
    f = f|(1<<(c-1))
  afs.append((a, f))
dp = [{} for i in range(M+1)]
dp[0][0] = 0
for i in range(M):
  d = dp[i]
  a0, f0 = afs[i]
  d2 = {}
  for f in d:
    d2[f] = d[f]
  for f in d:
    f2 = f|f0
    a2 = d[f]+a0
    d2[f2] = a2 if f2 not in d2 else min(d2[f2], a2)
  dp[i+1] = d2
#print(dp)
if (1<<N)-1 in dp[M]:
  r = dp[M][(1<<N)-1]
else:
  r = -1
print(r)
### BUGGY CODE ###

#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np


def main():
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[0 for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    dp = [[np.inf for j in range(N)] for i in range(N)]
    for i in range(H):
        for j in range(W):
            n = W*i + j
            if j < W-1 and S[i][j] == '.' and S[i][j+1] == '.':
                dp[n][n+1] = dp[n+1][n] = 1
            if i < H-1 and S[i][j] == '.' and S[i+1][j] == '.':
                dp[n][n+W] = dp[n+W][n] = 1

    for i in range(N):
        dp[i][i] = 0


    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])
    
    answer = 0
    for i in range(N):
        for j in range(N):
            if answer < dp[i][j] and dp[i][j] != np.inf:
                answer = dp[i][j]
    print(answer)





def main_dijkstra(): # ダイクストラ法を全域に対して探索させた実装
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[line for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    data = np.zeros([N, N])
    for i in range(H):
        for j in range(W):
            n = W * i + j
            if j<W-1 and S[i][j]=='.' and S[i][j+1]=='.':
                data[n][n+1] = data[n+1][n] = 1
            if i<H-1 and S[i][j]=='.' and S[i+1][j]=='.':
                data[n][n+W] = data[n+W][n] = 1

    G = csgraph_from_dense(data)
    answer = 0
    for n in range(N):
        result = dijkstra(G, indices=n)
        result = [x for x in result if x!=np.inf]
        answer = max(answer, max(result))
    print(int(answer))
    pass

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
import numpy as np

def main():
    H, W = list(map(int, input().split()))
    N = H * W
    S = [[line for line in range(W)] for row in range(H)]
    for i in range(H):
        row = input()
        for j, line in enumerate(row):
            S[i][j] = line

    data = np.zeros([N, N])
    for i in range(H):
        for j in range(W):
            n = W * i + j
            if j<W-1 and S[i][j]=='.' and S[i][j+1]=='.':
                data[n][n+1] = data[n+1][n] = 1
            if i<H-1 and S[i][j]=='.' and S[i+1][j]=='.':
                data[n][n+W] = data[n+W][n] = 1

    G = csgraph_from_dense(data)
    answer = 0
    for n in range(N):
        result = dijkstra(G, indices=n)
        result = [x for x in result if x!=np.inf]
        answer = max(answer, max(result))
    print(int(answer))
    pass

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

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

def primeList(N):
    R = int(N**0.5) + 10
    isPrime = [True] * (R + 1)
    for p in range(2, R):
        if not isPrime[p]:
            continue
        for q in range(p * 2, R, p):
            isPrime[q] = False
    return {p for p in range(2, R) if isPrime[p]}

primes = primeList(max(A))

def primeCount(N):
    ret = defaultdict(int)  # 素数のリスト
    n = N
    for num in primes:
        ret[num] = 0
        while n % num == 0:
            n //= num
            ret[num] += 1
    if n > 1 :
        ret[n] = 1
    return ret

PC = [primeCount(a) for a in A]
L = defaultdict(int)
for pc in PC:
    for p, c in pc.items():
        L[p] = max(L[p], c)

ans = 0
for pc in PC:
    b = 1
    for p, c in L.items():
        b *= pow(p, c - pc[p], MOD)
        b %= MOD
    ans += b
    ans %= MOD

print(ans)


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

def lcm(n, m):
    return n * m // gcd(n, m)

L = A[0]
for a in A:
    L = lcm(L, a)

ans = 0
for a in A:
    ans += L // a

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

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,k = list(map(int, input().split()))
v = [[0]*(4*k) for _ in range(4*k)]

for i in range(n):
    x,y,c = input().split()
    x = int(x)
    y = int(y)
    if c=="B":
        x += k
    x %= 2*k
    y %= 2*k
    v[x][y] += 1
    v[x][y+2*k] += 1
    v[x+2*k][y] += 1
    v[x+2*k][y+2*k] += 1
def cumsum2(v):
    # v: h*wの2次元リスト
    h,w = len(v), len(v[0])
    v.insert(0, [0]*w)
    for l in v:
        l.insert(0, 0)
    for i in range(1,h+1):
        for j in range(1,w+1):
            v[i][j] = v[i-1][j] + v[i][j-1] - v[i-1][j-1] + v[i][j]
    return v
c = cumsum2(v)
ans = -1
for i in range(2*k):
    for j in range(2*k):
        val0 = c[i+k][j+k]-c[i+k][j]-c[i][j+k]+c[i][j] + c[i+2*k][j+2*k]-c[i+2*k][j+k]-c[i+k][j+2*k]+c[i+k][j+k]
#         val1 = c[i+2*k][j+k]-c[i+2*k][j]-c[i+k][j+k]+c[i+k][j] + c[i+k][j+2*k]-c[i+k][j+k]-c[i][j+2*k]+c[i][j+k]
        ans = max(ans, val0)
print(ans)

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n,k = list(map(int, input().split()))
v = [[0]*(2*k) for _ in range(2*k)]

for i in range(n):
    x,y,c = input().split()
    x = int(x)
    y = int(y)
    if c=="B":
        x += k
    x %= 2*k
    y %= 2*k
    v[x][y] += 1
#     v[x][y+2*k] += 1
#     v[x+2*k][y] += 1
#     v[x+2*k][y+2*k] += 1
def cumsum2(v):
    # v: h*wの2次元リスト
    h,w = len(v), len(v[0])
    v.insert(0, [0]*w)
    for l in v:
        l.insert(0, 0)
    for i in range(1,h+1):
        for j in range(1,w+1):
            v[i][j] = v[i-1][j] + v[i][j-1] - v[i-1][j-1] + v[i][j]
    return v
cumsum2(v)

def sub(c, i, j):
    i %= 2*k
    j %= 2*k
    l = []
    if i<=k and j<=k:
        l = [[i,i+k,j,j+k]]
    elif i>k and j<=k:
        l = [[i,2*k,j,j+k], [0,i-k,j,j+k]]
    elif i<=k and j>k:
        l = [[i,i+k,j,2*k], [i,i+k,0,j-k]]
    else:
        l = [[i,2*k,j,2*k], [0,i-k,j,2*k], [i,2*k,0,j-k], [0,i-k,0,j-k]]
    return sum((c[z][w] - c[z][y] - c[x][w] + c[x][y]) for x,z,y,w in l)
ans = -1
for i in range(2*k):
    for j in range(2*k-i):
        val0 = sub(v, i,j) + sub(v, i+k, j+k)
#         val0 = v[i+k][j+k]-v[i+k][j]-v[i][j+k]+v[i][j] + v[i+2*k][j+2*k]-v[i+2*k][j+k]-v[i+k][j+2*k]+v[i+k][j+k]
#         val1 = v[i+2*k][j+k]-v[i+2*k][j]-v[i+k][j+k]+v[i+k][j] + v[i+k][j+2*k]-v[i+k][j+k]-v[i][j+2*k]+v[i][j+k]
        ans = max(ans, val0)
print(ans)
### BUGGY CODE ###

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

### FIXED CODE ###

from collections import Counter
n=int(input())
a=list(list(map(int,input().split())))
ma=[i-a[i] for i in range(n)]
r=Counter(ma)
ans=0
for i in range(n):
    ans+=r[i+a[i]]
print(ans)
### BUGGY CODE ###

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

for i in range(q):
    a,b = map(int,input().split())
    count = 0
    for i in range(a-1,b):
        for j in range(a-1,b):
            count += l[i][j]
    print(count)

### FIXED CODE ###

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


for i in range(n):
    for j in range(n):
        if i != 0:
            l[i][j] += l[i-1][j]
        if j != 0:
            l[i][j] += l[i][j-1]
        if i!= 0 and j != 0:
            l[i][j] -= l[i-1][j-1]
    

for i in range(q):
    a,b = map(int,input().split())
    ans = l[b-1][b-1]
    if a >= 2:
        ans -= l[a-2][b-1]
    print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
ps = list(map(lambda n: (int(n)+1)/2, input().split()))

mx = 0
for i in range(n - (k-1)):
  sm = sum(ps[i:i+k])
  if sm > mx:
    mx = sm
print(mx)

### FIXED CODE ###

n, k = map(int, input().split())
ps = list(map(lambda n: (int(n)+1)/2, input().split()))

mx = sum(ps[:k])
sm = sum(ps[:k])
for i in range(k, n):
  sm += ps[i] - ps[i-k]
  if sm > mx:
    mx = sm
print(mx)
### BUGGY CODE ###

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

### FIXED CODE ###

import collections

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

n = int(input())
sl = [input() for _ in [0]*n]
for i in range(len(sl)):
  sl[i] = sorted(sl[i])
  sl[i] = ''.join(sl[i])
count = 0
sl.sort()
for i in range(n-1):
  for j in range(i+1,n):
    if sl[i] == sl[j]:
      count += 1
    else:
      break
print(count)

### FIXED CODE ###

n = int(input())
sl = sorted([''.join(sorted(input())) for _ in [0]*n])
count = 0
while len(sl)>1:
  i = 1
  flag = True
  while flag:
    if sl[-1] == sl[-(i+1)]:
      i += 1
      if i == len(sl):
        flag=False
    else:
      flag = False
  if i>1:
    count += i*(i-1)//2
  del sl[-i:]
  flag=True
print(count)
### BUGGY CODE ###

N=int(input())
height=list(map(int,input().split()))
humidai_list=[0]
total_height=[height[0]]
del height[0]
#リストの要素を消す
for i in height:
    if max(total_height) > i :
        humidai=max(total_height)-i
        humidai_list.append(humidai)
        total_height.append(i+humidai)
    else:
        humidai=0
        humidai_list.append(humidai)
        total_height.append(i)
print(sum(humidai_list))


### FIXED CODE ###

N=int(input())
height=list(map(int,input().split()))
humidai_list=[0]
total_height=[height[0]]
del height[0]
#リストの要素を消す
for i in height:
    if total_height[-1] > i :
        humidai=total_height[-1]-i
        humidai_list.append(humidai)
        total_height.append(i+humidai)
    else:
        total_height.append(i)
print(sum(humidai_list))