/******************************************************* * Copyright (C) 2015 Haotian Wu * * This file is the solution to the question: * https://www.hackerrank.com/challenges/pairs * * Redistribution and use in source and binary forms are permitted. *******************************************************/ #include #include #include #include #include #include #include #include #include using namespace std; // HASH int main() { int n,k,tmp; map mp; scanf("%d %d",&n,&k); for (int i=0;i :: iterator j = mp.begin(); j != mp.end() ; j++) { if (mp.find((j->first) + (long long)k) == mp.end()) continue; else ans += (j->second) * (long long)(mp[(j->first) + (long long)k]); } printf("%lld\n",ans); }