#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = (int)1e9 + 7;   const int N = (int)3e5 + 7;   char read_char() {     char c;     for (;;) {       c = getchar();       if (c >=  A  && c <=  Z ) return c;     }   }   long long powmod(long long a, long long b) {     long long res = 1;     a %= MOD;     for (; b; b >>= 1) {       if (b & 1) res = res * a % MOD;       a = a * a % MOD;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long add(long long a, long long b) {     a = ((a + b) % MOD + MOD) % MOD;     return a;   }   long long mul(long long a, long long b) { return a * b % MOD; }   int n, p, cnt[N], tmp[N];   pair<int, int> a[N];   void Init() {     memset(cnt, 0, sizeof(cnt));     for (int i = (0); i < (n); ++i) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       a[i].first = u, a[i].second = v;       cnt[u]++;       cnt[v]++;     }     for (int i = (1); i < (n + 1); ++i) tmp[i] = cnt[i];     sort(tmp + 1, tmp + n + 1);     sort(a, a + n);   }   int Solve() {     long long ans = 0;     for (int i = n, j = 1; j < i; i--) {       while (tmp[j] + tmp[i] < p && j < i) j++;       ans += i - j;     }     for (int i = 0, j; i < n; i = j) {       j = i + 1;       while (j < n && a[i] == a[j]) j++;       int u = a[i].first, v = a[i].second;       if (cnt[u] + cnt[v] >= p && cnt[u] + cnt[v] - (j - i) < p) {         ans--;       }     }     return !printf( %lld n , ans);   }   int main() {     while (~scanf( %d%d , &n, &p)) {       Init();       Solve();     }     return 0;   }   