Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

i_dic = {}
for i,a in enumerate(a_ls):
	val = -a+(i+1)
	if val not in i_dic: i_dic[val] = []
	i_dic[val].append(i+1)

cnt = 0
for i in range(len(a_ls)):
	val = a_ls[i] + (i+1)
	cand_ls = i_dic.get(val, [])
	ok_ls = [j for j in cand_ls if j>(i+1)]
	cnt += len(ok_ls)

print(cnt)

Fixed submission:
def count_j(arg_ls, th, b_idx, e_idx):
	if b_idx-1 == e_idx: return 0
	if b_idx == e_idx: return int(arg_ls[b_idx] > th)
	cent_idx = (e_idx+1 - b_idx) // 2 + b_idx
	cent_j = arg_ls[cent_idx]
	if cent_j > th:
		return count_j(arg_ls, th, b_idx, cent_idx-1) + (e_idx+1 - cent_idx)
	else:
		return count_j(arg_ls, th, cent_idx, e_idx)

n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

i_dic = {}
for i,a in enumerate(a_ls):
	val = -a+(i+1)
	if val not in i_dic: i_dic[val] = []
	i_dic[val].append(i+1)

cnt = 0
for i in range(len(a_ls)):
	val = a_ls[i] + (i+1)
	cand_ls = i_dic.get(val, [])
	result = count_j(cand_ls, (i+1), 0, len(cand_ls)-1)
	cnt += result

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
# input
n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

cnt = 0
for i in range(n-1):
	abs_val = i+1
	for j in range(n-abs_val):
		if abs_val <= a_ls[j]: continue
		if a_ls[j] + a_ls[j+abs_val] == abs_val: cnt += 1

# result
print(cnt)

Fixed submission:
def count_j(arg_ls, th, b_idx, e_idx):
	if b_idx-1 == e_idx: return 0
	if b_idx == e_idx: return int(arg_ls[b_idx] > th)
	cent_idx = (e_idx+1 - b_idx) // 2 + b_idx
	cent_j = arg_ls[cent_idx]
	if cent_j > th:
		return count_j(arg_ls, th, b_idx, cent_idx-1) + (e_idx+1 - cent_idx)
	else:
		return count_j(arg_ls, th, cent_idx, e_idx)

n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

i_dic = {}
for i,a in enumerate(a_ls):
	val = -a+(i+1)
	if val not in i_dic: i_dic[val] = []
	i_dic[val].append(i+1)

cnt = 0
for i in range(len(a_ls)):
	val = a_ls[i] + (i+1)
	cand_ls = i_dic.get(val, [])
	result = count_j(cand_ls, (i+1), 0, len(cand_ls)-1)
	cnt += result

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

cnt = 0
for i in range(n-1):
	abs_val = i+1
	for j in range(n-abs_val):
		if a_ls[j] + a_ls[j+abs_val] == abs_val: cnt += 1

print(cnt)

Fixed submission:
def count_j(arg_ls, th, b_idx, e_idx):
	if b_idx-1 == e_idx: return 0
	if b_idx == e_idx: return int(arg_ls[b_idx] > th)
	cent_idx = (e_idx+1 - b_idx) // 2 + b_idx
	cent_j = arg_ls[cent_idx]
	if cent_j > th:
		return count_j(arg_ls, th, b_idx, cent_idx-1) + (e_idx+1 - cent_idx)
	else:
		return count_j(arg_ls, th, cent_idx, e_idx)

n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

i_dic = {}
for i,a in enumerate(a_ls):
	val = -a+(i+1)
	if val not in i_dic: i_dic[val] = []
	i_dic[val].append(i+1)

cnt = 0
for i in range(len(a_ls)):
	val = a_ls[i] + (i+1)
	cand_ls = i_dic.get(val, [])
	result = count_j(cand_ls, (i+1), 0, len(cand_ls)-1)
	cnt += result

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

# input
n = int(input())
inp_ls = input().split(" ")
a_ls = np.array([int(e) for e in inp_ls[:n]])

cnt = 0
for i in range(n-1):
	abs_val = i+1
	l0 = a_ls[:-abs_val]
	l1 = a_ls[abs_val:]
	h_sum_ls = l0+l1
	cnt += np.count_nonzero(h_sum_ls == abs_val)

# result
print(cnt)


Fixed submission:
def count_j(arg_ls, th, b_idx, e_idx):
	if b_idx-1 == e_idx: return 0
	if b_idx == e_idx: return int(arg_ls[b_idx] > th)
	cent_idx = (e_idx+1 - b_idx) // 2 + b_idx
	cent_j = arg_ls[cent_idx]
	if cent_j > th:
		return count_j(arg_ls, th, b_idx, cent_idx-1) + (e_idx+1 - cent_idx)
	else:
		return count_j(arg_ls, th, cent_idx, e_idx)

n = int(input())
inp_ls = input().split(" ")
a_ls = [int(e) for e in inp_ls[:n]]

i_dic = {}
for i,a in enumerate(a_ls):
	val = -a+(i+1)
	if val not in i_dic: i_dic[val] = []
	i_dic[val].append(i+1)

cnt = 0
for i in range(len(a_ls)):
	val = a_ls[i] + (i+1)
	cand_ls = i_dic.get(val, [])
	result = count_j(cand_ls, (i+1), 0, len(cand_ls)-1)
	cnt += result

print(cnt)