Skip to content

Instantly share code, notes, and snippets.

@maehrm
Created December 6, 2025 01:16
Show Gist options
  • Select an option

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

Select an option

Save maehrm/dd86a33f6d29d685bea85dcdd8eba46e to your computer and use it in GitHub Desktop.
from collections import defaultdict
N, M = map(int, input().split())
d = defaultdict(int)
for _ in range(M):
A, B = map(int, input().split())
d[(A + B) % N] += 1
ans = M * (M - 1) // 2
for _, v in d.items():
ans -= v * (v - 1) // 2
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment