Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- // basic counting way
- long long int cnt[10005];
- int main(){
- int x;
- int N;
- long long int total = 0;
- scanf("%d", &N);
- for(int i = 0; i < N; i++){
- // basically we just add the amount of pair we had b4, because position doesn't matter
- // only amount of numbers matters
- // 'streaming' algorithm
- // replace x, we do not need to use another array
- scanf("%d", &x);
- total += cnt[x]++;
- }
- printf("%lld\n", total);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement