Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main(){
long n; scanf("%ld\n", &n);
const int scale = 10;
long long count[2 * scale + 1] = {0};
int temp;
while(n--){scanf("%d",&temp);count[scale + temp]++;}
long long total(0);
for(int k = 0; k < scale; k++){total += count[k] * count[2 * scale - k];}
total += count[scale] * (count[scale] - 1) / 2;
printf("%lld\n", total);
return 0;
}
Copy The Code &
Try With Live Editor
Input
5
-3 3 0 0 3
-3 3 0 0 3
Output
3
Demonstration
Codeforces Solution-B. Opposites Attract-Solution in C, C++, Java, Python