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

lqdoj
tocdovodoi avatar
tocdovodoi
plain_text
04/23/2024 7:15 PM
304 B
22
Indexable
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)
Editor is loading...
Leave a Comment