Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created March 23, 2026 09:05
Show Gist options
  • Select an option

  • Save maehrm/d46edef7c749fb00d448df3e4b63922c to your computer and use it in GitHub Desktop.

Select an option

Save maehrm/d46edef7c749fb00d448df3e4b63922c to your computer and use it in GitHub Desktop.
E - This Message Will Self-Destruct in 5s https://atcoder.jp/contests/abc166/tasks/abc166_e
N = int(input())
A = list(map(int, input().split()))
# j - i = Ai + Aj
# j - Aj = i + Ai
cnt = {}
for j in range(N):
val = j - A[j]
if val not in cnt:
cnt[val] = 0
cnt[val] += 1
ans = 0
for i in range(N):
val = i + A[i]
if val in cnt:
ans += cnt[val]
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment