Đếm cặp có tổng bằng 0

lqdoj
 avatar
tocdovodoi
plain_text
2 months ago
228 B
4
Indexable
Never
n = int(input())
a = list(map(int, input().split()))
dem = 0
cacso = {}
for so in a:
    if -so in cacso:
        dem += cacso[-so]
    if so in cacso:
        cacso[so] += 1
    else:
        cacso[so] = 1
print(dem)
Leave a Comment