Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    for y in c.items():
        if x[0] == y[0]:
            count += x[1] * y[1]
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    for y in c.items():
        if x[0] == y[0]:
            count += x[1] * y[1]
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
dtype = [('number',int),('height',int)]
A = np.array(list(enumerate(list(map(int, input().split())))),dtype=dtype)
count = 0
B = np.sort(A,order='height')
mem = [i+1 for i in range(N-1)]
Min = B[0][1] + B[1][1]
Max = B[-1][1] + B[-2][1]
for i in range(max(2,Min),min(N,Max+1)):
    for j in range(N-1):
        c = B[j][1]
        d = i - c
        for k in range(mem[j],N):
            e = B[k][1]
            if e == d:
                if abs(B[j][0]-B[k][0]) == i:
                    count += 1
            elif e > d:
                mem[j] = k
                break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
Min = h[0] + h[1]
Max = h[-1] + h[-2]
for i in range(max(2,Min),min(N,Max+1)):
    for j in range(N-1):
        c = h[j]
        if c >= i:
            break
        else:
            d = i - c
            for k in range(mem[j],N):
                if h[k] == d:
                    if abs(B[j][0]-B[k][0]) == i:
                        count += 1
                elif h[k] > d:
                    mem[j] = k
                    break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
Min = h[0] + h[1]
Max = h[-1] + h[-2]
for i in range(2,N):
    if Min > i:
        continue
    elif Max < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                for k in range(mem[j],N):
                    if h[k] == d:
                        if abs(B[j][0]-B[k][0]) == i:
                            count += 1
                    elif h[k] > d:
                        mem[j] = k
                        break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
for i in range(2,N):
    if h[0] + h[1] > i:
        continue
    elif h[-1] + h[-2] < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                for k in range(mem[j],N):
                    if h[k] == d:
                        if abs(B[j][0]-B[k][0]) == i:
                            count += 1
                    elif h[k] > d:
                        mem[j] = k
                        break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
mem = [i+1 for i in range(N-1)]
for i in range(2,N):
    if h[0] + h[1] > i:
        continue
    elif h[-1] + h[-2] < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                for k in range(mem[j],N):
                    if h[k] == d:
                        if abs(B[j][0]-B[k][0]) == i:
                            count += 1
                    elif h[k] > d:
                        mem[j] = k
                        break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
for i in range(2,N):
    if h[0] + h[1] > i:
        continue
    elif h[-1] + h[-2] < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                bs = bisect.bisect_left(h,d)
                if bs < N:
                    if bs <= j:
                        bs = j + 1
                    for k in range(bs,N):
                        if h[k] == d:
                            if abs(B[j][0]-B[k][0]) == i:
                                count += 1
                        else:
                            break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
h = [x[1] for x in B]
for i in range(2,N):
    if h[0] + h[1] > i:
        continue
    elif h[-1] + h[-2] < i:
        break
    else:
        for j in range(N-1):
            c = h[j]
            if c >= i:
                break
            else:
                d = i - c
                bs = bisect.bisect_left(h,d)
                if bs < N:
                    if bs <= j:
                        bs = j + 1
                    for k in range(bs,N):
                        if h[k] == d:
                            if abs(B[j][0]-B[k][0]) == i:
                                count += 1
                        else:
                            break
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
for i in range(2,N):
    if B[0][1] + B[1][1] > i:
        continue
    elif B[-1][1] + B[-2][1] < i:
        break
    else:
        for j in range(N-1):
            broke = False
            c = B[j][1]
            if c >= i:
                break
            else:
                for k in range(1,N-j):
                    d = B[j+k][1]
                    e = c + d
                    if e > i:
                        break
                    elif e == i:
                        if abs(B[j][0]-B[j+k][0]) == e:
                            count += 1
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
count = 0
B = sorted(A,key=lambda x:x[1])
for i in range(2,N):
    if B[0][1] + B[1][1] > i:
        continue
    elif B[-1][1] + B[-2][1] < i:
        break
    else:
        for j in range(N-1):
            broke = False
            c = B[j][1]
            if c >= i:
                break
            else:
                for k in range(1,N-j):
                    d = B[j+k][1]
                    e = c + d
                    if e > i:
                        break
                    elif e == i:
                        if abs(B[j][0]-B[j+k][0]) == e:
                            count += 1
print(count)

Fixed submission:
from collections import Counter
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
b = Counter([x[0]+x[1]+1 for x in A])
c = Counter([x[0]-x[1]+1 for x in A])
count = 0
for x in b.items():
    count += x[1] * c[x[0]]
print(count)