codeforces.com/contest/421/problem/D
const int MAXN = 310000;struct Node{ int n, num; int operator< (const Node& a) const { return num < a.num; }} ipt[MAXN];int cnt[MAXN];int cmp(Node& a, int b){ return a.num < b;}int main(){// freopen("in.txt", "r", stdin); int n, k, a, b; while (~RII(n, k)) { CLR(cnt, 0); map<pair<int, int>, int> mp; FE(i, 1, n) ipt[i].n = i; FE(i, 1, n) ipt[i].num = 0; REP(i, n) { RI(a); ipt[a].num++; cnt[a]++; RI(b); ipt[b].num++; cnt[b]++; if (a > b) swap(a, b); mp[MP(a, b)]++; } sort(ipt + 1, ipt + n + 1); LL ans = 0; FE(i, 1, n) { int ind = lower_bound(ipt + i + 1, ipt + n + 1, k - ipt[i].num, cmp) - ipt; ans += n - ind + 1; } FC(it, mp) { a = (it->first).first; b = (it->first).second; if (cnt[a] + cnt[b] >= k && cnt[a] + cnt[b] - it->second < k) ans--; } cout << ans << endl; } return 0;}