#include <bits/stdc++.h>
using namespace std;
int countPairs(int arr[], int n, int target) {
int cnt=0;
unordered_map<int,int> mp;
for(int i=0;i<n;i++){
int complement = target - arr[i];
if(mp.find(complement)!=mp.end()){
cnt+=mp[complement];
}
mp[arr[i]]++;
}
return cnt;
}
int main() {
// your code goes here
int arr[5] = {1, 5, 7, -1, 5};
int target=6;
cout<<countPairs(arr,5,target);
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgY291bnRQYWlycyhpbnQgYXJyW10sIGludCBuLCBpbnQgdGFyZ2V0KSB7CiAgICAgaW50IGNudD0wOwogICAgdW5vcmRlcmVkX21hcDxpbnQsaW50PiBtcDsKICAgIGZvcihpbnQgaT0wO2k8bjtpKyspewogICAgICAgIGludCBjb21wbGVtZW50ID0gdGFyZ2V0IC0gYXJyW2ldOwogICAgICAgIGlmKG1wLmZpbmQoY29tcGxlbWVudCkhPW1wLmVuZCgpKXsKICAgICAgICAgICAgY250Kz1tcFtjb21wbGVtZW50XTsKICAgICAgICB9CiAgICAgICAgbXBbYXJyW2ldXSsrOwogICAgfQogICAgcmV0dXJuIGNudDsKfQppbnQgbWFpbigpIHsKCS8vIHlvdXIgY29kZSBnb2VzIGhlcmUKCWludCBhcnJbNV0gPSB7MSwgNSwgNywgLTEsIDV9OwoJaW50IHRhcmdldD02OwoJY291dDw8Y291bnRQYWlycyhhcnIsNSx0YXJnZXQpOwoJcmV0dXJuIDA7Cn0=