#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout<<x<<" "<<y<<endl
#define MAXN 300002

using namespace std;

int tree[MAXN];

int query(int x){

    int ans = 0;
    for(int i = x; i > 0; i -= i&-i)ans += tree[i];
    return ans;
}

void update(int x, int val){

    for(int i = x; i < MAXN; i += i&-i)tree[i] += val;

}

vector<int>L[MAXN];
int S[MAXN];

int main(){

    int n, p, x, y;
    while(cin>>n>>p){

        for(int i = 0; i < n; i++){
            scanf("%d%d", &x, &y);
            if(x > y)swap(x, y);

            L[x].pb(y);
            S[x]++, S[y]++;

        }

        if(p == 0){

            cout<< n * (n + 1)/2 << endl;
            continue;

        }

        for(int i = 1; i <= n; i++)if(S[i] > 0)update(S[i], 1);
        long long ans = 0;

        for(int i = 1; i <= n; i++)sort(all(L[i]));

        for(int i = 1; i <= n; i++){

            if(S[i] > 0)update(S[i], -1);
            ans += n - i - query(max(0, p - S[i] - 1));

            if(L[i].size() == 0)continue;
            int ct = 1;

            for(int j = 1; j < L[i].size(); j++){

                    if(L[i][j - 1] == L[i][j])ct++;
                    else{

                        if(S[i] + S[L[i][j - 1]] >= p && S[i] + S[L[i][j - 1]] - ct < p)ans--;
                        ct = 1;

                    }
            }

            int pos = L[i].back();
            if(ct > 0 && S[i] + S[pos] >= p && S[i] + S[pos] - ct < p)ans--;

        }

        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define cout2(x, y) cout<<x<<" "<<y<<endl
#define MAXN 300002

using namespace std;

int tree[MAXN];

int query(int x){

    int ans = 0;
    for(int i = x; i > 0; i -= i&-i)ans += tree[i];
    return ans;
}

void update(int x, int val){

    for(int i = x; i < MAXN; i += i&-i)tree[i] += val;

}

vector<int>L[MAXN];
int S[MAXN];

int main(){

    int n, p, x, y;
    while(cin>>n>>p){

        for(int i = 0; i < n; i++){
            scanf("%d%d", &x, &y);
            if(x > y)swap(x, y);

            L[x].pb(y);
            S[x]++, S[y]++;

        }

        for(int i = 1; i <= n; i++)update(S[i] + 1, 1);
        long long ans = 0;

        for(int i = 1; i <= n; i++)sort(all(L[i]));

        for(int i = 1; i <= n; i++){

            update(S[i] + 1, -1);
            ans += n - i - query(max(1, p - S[i]));

            if(L[i].size() == 0)continue;
            int ct = 1;

            for(int j = 1; j < L[i].size(); j++){

                    if(L[i][j - 1] == L[i][j])ct++;
                    else{

                        if(S[i] + S[L[i][j - 1]] >= p && S[i] + S[L[i][j - 1]] - ct < p)ans--;
                        ct = 1;

                    }
            }

            int pos = L[i].back();
            if(ct > 0 && S[i] + S[pos] >= p && S[i] + S[pos] - ct < p)ans--;

        }

        cout<<ans<<endl;
    }

}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int p=-1;
    while(s<=t){
        int mid=(s+t)>>1;
        if(root[mid].val==v) p=mid;
        if(root[mid].val<=v) s=mid+1;
        else t=mid-1;
    }
    return p==-1?s:p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val>root[y].val) cnt[y]+=(*it).second-2;
            else cnt[x]+=(*it).second-2;
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
        ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int p=-1;
    while(s<=t){
        int mid=(s+t)>>1;
        if(root[mid].val==v) p=mid;
        if(root[mid].val<=v) s=mid+1;
        else t=mid-1;
    }
    return p==-1?s:p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p){
                if(root[x].val>root[y].val) cnt[y]+=(*it).second-2;
                else cnt[x]+=(*it).second-2;
            }
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
        ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int mid;
    int p=t+1;
    while(s<=t){
        mid=(s+t)>>1;
        if(root[mid].val>=v) p=min(p,mid);
        if(root[mid].val<=v) s=mid+1;
        else t=mid-1;
    }
    return p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        {
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p && root[x].val+root[y].val-(*it).second <p ) ans--;
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            //  output(s);
            ans+=(n-s+1)*1LL;
        }
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    while(s<=t){
        int mid=(s+t)>>1;
        if(root[mid].val<v) s=mid+1;
        else t=mid-1;
    }
    return s;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val>root[y].val) cnt[y]+=(*it).second-2;
            else cnt[x]+=(*it).second-2;
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
        ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int p=-1;
    while(s<=t){
        int mid=(s+t)>>1;
        //  if(root[mid].val==v) p=mid;
        if(root[mid].val<v) s=mid+1;
        else t=mid-1;
    }
    return p==-1?s:p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p){
                if(root[x].val>root[y].val) root[x].val-=(*it).second;
                else root[y].val-=(*it).second;
            }
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
        // ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int p=-1;
    while(s<=t){
        int mid=(s+t)>>1;
        //  if(root[mid].val==v) p=mid;
        if(root[mid].val<v) s=mid+1;
        else t=mid-1;
    }
    return p==-1?s:p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p){
                if(root[x].val>root[y].val) cnt[x]+=(*it).second;
                else cnt[y]+=(*it).second;
            }
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
         ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int p=-1;
    while(s<=t){
        int mid=(s+t)>>1;
         if(root[mid].val==v) p=mid;
        if(root[mid].val<=v) s=mid+1;
        else t=mid-1;
    }
    return p==-1?s:p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p){
                if(root[x].val>root[y].val) cnt[x]+=(*it).second;
                else cnt[y]+=(*it).second;
            }
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
         ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int mid;
    int p=t+1;
    while(s<=t){
        mid=(s+t)>>1;
        if(root[mid].val>=v) p=min(p,mid);
        if(root[mid].val<v) s=mid+1;
        else t=mid-1;
    }
    return p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        {
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p && root[x].val+root[y].val-(*it).second <p ) ans--;
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
// output(s);
            ans+=(n-s+1)*1LL;
        }
    }
    printf("%I64d\n",ans);
    return 0;
}


/*
 * File Name: cf.cpp
 * Create Time: 19:54:02,星期二, 22 四月 2014.
 * Author: qqspeed
 */

#include<algorithm>
#include<bitset>
#include<deque>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<limits>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<vector>
#include<complex>
using namespace std;

#define FOR(i,b,e) for(__typeof(b)i=(b);i!=(e);i++)
#define FOR_EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define rep(i,s,t) for(int i=s;i<t;i++)
#define INF ~0U>>2
#define L t<<1
#define R t<<1|1
#define PI acos(-1.0)
#define clr(a) memset(a,0,sizeof(a))
typedef complex<double>Com;
typedef pair<int,int> ii;
typedef long long ll;
typedef unsigned long long ull;

inline void DATA(char *s,char *d){
    freopen(s,"r",stdin);
    freopen(d,"w",stdout);
}

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[10];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

#define N 300005
vector<int>v[N];
map<ii,int>mp;
int n,p;
int a[N],b[N];
struct node{
    int id,val;
}root[N];
bool cmp(node i,node j){
    return i.val<j.val||(i.val==j.val&&i.id<j.id);
}
ll ans;
inline int BS(int s,int t,int v){
    int p=-1;
    while(s<=t){
        int mid=(s+t)>>1;
        //  if(root[mid].val==v) p=mid;
        if(root[mid].val<v) s=mid+1;
        else t=mid-1;
    }
    return p==-1?s:p;
}
int cnt[N];
int main(){
    ans=0;
    clr(cnt);
    mp.clear();
    n=input(),p=input();
    rep(i,1,n+1) v[i].clear();
    rep(i,1,n+1) root[i].id=i,root[i].val=0;
    rep(i,1,n+1){
        a[i]=input(),b[i]=input();
        if(a[i]>b[i]) swap(a[i],b[i]);
        v[a[i]].push_back(b[i]);
        mp[ii(a[i],b[i])]++;
        root[a[i]].val++;
        root[b[i]].val++;
    }
    for(map<ii,int>::iterator it=mp.begin();it!=mp.end();it++){
        if((*it).second>=2){
            int x=(*it).first.first;
            int y=(*it).first.second;
            if(root[x].val+root[y].val>=p){
                if(root[x].val>root[y].val) cnt[y]+=(*it).second-2;
                else cnt[x]+=(*it).second-2;
            }
        }
    }
    sort(root+1,root+n+1,cmp);
    rep(i,1,n){
        {
            int r=p-root[i].val;
            int s=BS(i+1,n,r);
            ans+=(n-s+1)*1LL;
        }
        ans-=(cnt[root[i].id])*1LL;
    }
    printf("%I64d\n",ans);
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=3e5+5;
vint v;
int a[maxn],n,p;
ll go(){
    ll ans=0;
    for(int i=1 ; i<=n ; i++){
        int tmp=max(0,p-a[i]);
        int pos=0;
        if(tmp<=a[n] && tmp>=a[1]){
            pos=lower_bound(a+i+1,a+1+n,tmp)-a;
            ans+=ll(n-pos+1);
        }
        else if(tmp<a[1]){
            ans+=ll(n-i);
        }
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        a[u1]++;a[u2]++;
    }
    /*for(int i=1 ; i<=n ; i++)
        v.pb(a[i]);
    sort(v.begin(),v.end());*/
    sort(a+1,a+1+n);
    cout<<go()<<endl;
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=3e5+10;
map<pii,int> mp;
vint v;
int a[maxn],n,p,k;
pair<pii,int> inmap[maxn];
ll go(){
    ll ans=0;
    for(int i=1 ; i<n ; i++){
        int tmp=max(0,p-a[i]);
        int pos=0;
        if(tmp<=a[n]){
            pos=lower_bound(a+i+1,a+1+n,tmp)-a;
            ans+=ll(n-pos+1);
        }
    }
    for(int i=1 ; i<=k ; i++){
        int tmp1=a[inmap[i].xx.xx];
        int tmp2=a[inmap[i].xx.yy];
        if(tmp1+tmp2>=p && (tmp1+tmp2-inmap[i].yy)<p)
            ans--;
    }
//    cout<<inmap[mp[pii(2,3)]].xx.xx<<' '<<inmap[mp[pii(2,3)]].xx.yy<<' '<<inmap[mp[pii(2,3)]].yy<<endl;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        a[u1]++;a[u2]++;
        if(u1>u2)swap(u1,u2);
        if(mp.find(pii(u1,u2))==mp.end()){
            mp[pii(u1,u2)]=++k;
            inmap[k].xx=pii(u1,u2);
        }
        inmap[mp[pii(u1,u2)]].yy++;
    }
    sort(a+1,a+1+n);
    cout<<go()<<endl;
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=3e5+5;
map<pii,int> mp;
vint v;
int a[maxn],n,p,k;
pair<pii,int> inmap[maxn];
ll go(){
    ll ans=0;
    for(int i=1 ; i<=n ; i++){
        int tmp=max(0,p-a[i]);
        int pos=0;
        if(tmp<=a[n] && tmp>=a[1]){
            pos=lower_bound(a+i+1,a+1+n,tmp)-a;
            ans+=ll(n-pos+1);
        }
        else if(tmp<a[1]){
            ans+=ll(n-i);
        }
    }
    for(int i=1 ; i<=k ; i++){
        int tmp1=a[inmap[i].xx.xx];
        int tmp2=a[inmap[i].xx.yy];
        if(tmp1+tmp2>=p && (tmp1+tmp2-inmap[i].yy)<p){
            ans--;
        }
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        a[u1]++;a[u2]++;
        if(u1>u2)swap(u1,u2);
        if(mp.find(pii(u1,u2))==mp.end()){
            mp[pii(u1,u2)]=++k;
            inmap[k].xx=pii(u1,u2);
        }
        inmap[mp[pii(u1,u2)]].yy++;
    }
    sort(a+1,a+1+n);
    cout<<go()<<endl;
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=3e5+5;
vint v;
int a[maxn],n,p;
ll go(){
    ll ans=0;
    for(int i=0 ; i<(int)v.size()-1 ; i++){
        int tmp=p-v[i];
        int pos=0;
        if(tmp<=v.back()){
            pos=lower_bound(v.begin(),v.end(),tmp)-v.begin();
            ans+=(v.size()-max(pos,i+1));
        }
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        a[u1]++;a[u2]++;
    }
    for(int i=1 ; i<=n ; i++)
        v.pb(a[i]);
    sort(v.begin(),v.end());
    cout<<go()<<endl;
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <map>
# define xx first
# define yy second
# define mk make_pair
using namespace std;
typedef pair<int,int> pii;
const int maxn=3e5+10;
map<pii,int> mp;
int a[maxn],n,p,k=0,naf[maxn];
pair<pii,int> inmap[maxn];
long long go(){
    long long ans=0;
    for(int i=1 ; i<n ; i++){
        int tmp=max(0,p-a[i]);
        if(tmp<=a[n])
            ans+=(n-(lower_bound(a+i+1,a+1+n,tmp)-a)+1);
    }
    for(int i=1 ; i<=k ; i++){
        int tmp1=naf[inmap[i].xx.xx],tmp2=naf[inmap[i].xx.yy];
        if(tmp1+tmp2>=p && (tmp1+tmp2-inmap[i].yy)<p)
            ans--;
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        if(u1>u2)swap(u1,u2);
        a[u1]++;a[u2]++;naf[u1]++;naf[u2]++;
        if(mp.find(pii(u1,u2))!=mp.end())
            inmap[mp[pii(u1,u2)]].yy++;
        else{
            k++;
            mp[pii(u1,u2)]=k;
            inmap[k]=mk(mk(u1,u2),1);
        }
    }
    sort(a+1,a+1+n);
    cout<<go()<<endl;
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=3e5+10;
map<pii,int> mp;
vint v;
int a[maxn],n,p,k=0;
int naf[maxn];
pair<pii,int> inmap[maxn];
ll go(){
    ll ans=0;
    for(int i=1 ; i<n ; i++){
        int tmp=max(0,p-a[i]);
        int pos=0;
        if(tmp<=a[n]){
            pos=lower_bound(a+i+1,a+1+n,tmp)-a;
            ans+=ll(n-pos+1);
        }
    }
    for(int i=1 ; i<=k ; i++){
        int tmp1=inmap[i].xx.xx;
        int tmp2=inmap[i].xx.yy;
        if(naf[tmp1]+naf[tmp2]>=p && (naf[tmp1]+naf[tmp2]-inmap[i].yy)<p){
            ans--;
        }
    }
//    cout<<inmap[mp[pii(2,3)]].xx.xx<<' '<<inmap[mp[pii(2,3)]].xx.yy<<' '<<inmap[mp[pii(2,3)]].yy<<endl;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        if(u1>u2)swap(u1,u2);
        a[u1]++;a[u2]++;
        naf[u1]++;naf[u2]++;
        if(mp.find(pii(u1,u2))!=mp.end()){
            inmap[mp[pii(u1,u2)]].yy++;
        }
        else{
            k++;
            mp[pii(u1,u2)]=k;
            inmap[k].xx.xx=u1;
            inmap[k].xx.yy=u2;
            inmap[k].yy=1;
        }
    }
    sort(a+1,a+1+n);
    cout<<go()<<endl;
    return 0;
}


//                                                  به نام خداوند بخشنده ی مهربان
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <fstream>
#include <complex>
#include <vector>
#include <string>
#include <cstdio>
#include <queue>
#include <deque>
#include <cmath>
#include <map>
#include <set>

# define xx first
# define yy second
# define pb push_back
# define pp pop_back
# define eps 1e-9
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
const int maxn=3e5+5;
vint v;
int a[maxn],n,p;
ll go(){
    ll ans=0;
    for(int i=1 ; i<=n ; i++){
        int tmp=p-a[i];
        int pos=0;
        if(tmp<=a[n]){
            pos=lower_bound(a+i+1,a+1+n,tmp)-a;
            ans+=(n-pos+1);
        }
    }
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin>>n>>p;
    for(int i=1 ; i<=n ; i++){
        int u1,u2;cin>>u1>>u2;
        a[u1]++;a[u2]++;
    }
    /*for(int i=1 ; i<=n ; i++)
        v.pb(a[i]);
    sort(v.begin(),v.end());*/
    sort(a+1,a+1+n);
    cout<<go()<<endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

const int nmax=3e5+5;
pair<int,int> cnt[nmax];//first:被票次数 second:coder编号

int lwr_bnd(int l,int r,int x)
{
    int mid;
    while(l<r)
    {
        mid=l+(r-l)/2;
        if(cnt[mid].first>=x)
            r=mid;
        else
            l=mid+1;
    }
    return l;
}

int main()
{
    ios::sync_with_stdio(false);
//    freopen("/Users/fromfire/Desktop/acm/ACM/in.txt", "r", stdin);

    map<int,int> mtch[nmax];
    int num[nmax];//被票次数

    int n,p,t1,t2;
    cin >> n >> p;
    for(int i=0;i<=n;i++)
        cnt[i].second=i;
    for(int i=0;i<n;i++)
    {
        cin >> t1 >> t2;
        cnt[t1].first++; num[t1]++;
        cnt[t2].first++; num[t2]++;

        if(mtch[t2].count(t1))
        {
            (*(mtch[t2].find(t1))).second++;
            (*(mtch[t1].find(t2))).second++;
        }
        else
        {
            mtch[t2][t1]=1;
            mtch[t1][t2]=1;
        }
    }

    sort(cnt+1,cnt+n+1);
    int ans=0;
    for(int i=n;i>=2;i--)
    {
        int x=lwr_bnd(1,i-1,p-cnt[i].first);
        if(cnt[i].first+cnt[x].first<p) break;
        int id=cnt[i].second;
        ans += (i-x);
        for(map<int,int>::iterator it=mtch[id].begin(); it!=mtch[id].end(); it++)
            if(num[id] + num[(*it).first] >= p &&
               num[cnt[i].second] + num[(*it).first] - (*it).second < p)
                ans--;
    }
    cout << ans << endl;

    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;

const int nmax=3e5+5;
pair<int,int> cnt[nmax];//first:被票次数 second:coder编号
map<int,int> mtch[nmax];
int num[nmax];//被票次数

int lwr_bnd(int l,int r,int x)
{
    int mid;
    while(l<r)
    {
        mid=l+(r-l)/2;
        if(cnt[mid].first>=x)
            r=mid;
        else
            l=mid+1;
    }
    return l;
}

int main()
{
//    freopen("/Users/fromfire/Desktop/acm/ACM/in.txt", "r", stdin);
    ios::sync_with_stdio(false);

    int n,p,t1,t2;
    cin >> n >> p;
    for(int i=0;i<=n;i++)
        cnt[i].second=i;
    for(int i=0;i<n;i++)
    {
        cin >> t1 >> t2;
        cnt[t1].first++; num[t1]++;
        cnt[t2].first++; num[t2]++;

        if(mtch[t2].count(t1))
        {
            (*(mtch[t2].find(t1))).second++;
            (*(mtch[t1].find(t2))).second++;
        }
        else
        {
            mtch[t2][t1]=1;
            mtch[t1][t2]=1;
        }
    }

    sort(cnt+1,cnt+n+1);
    long long ans=0;
    bool mark[nmax]={0};
    for(int i=n;i>=2;i--)
    {
        int x=lwr_bnd(1,i-1,p-cnt[i].first);
        if(cnt[i].first+cnt[x].first<p) break;
        int id=cnt[i].second;
        mark[id]=1;
        ans += (i-x);
        for(map<int,int>::iterator it=mtch[id].begin(); it!=mtch[id].end(); it++)
            if(num[id] + num[(*it).first] >= p && !mark[(*it).first] &&
               num[cnt[i].second] + num[(*it).first] - (*it).second < p)
                ans--;
    }
    cout << ans << endl;

    return 0;
}


//Solution by Miras Myrzakerey
//Look at my code
//My code is amazing

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <iomanip>

using namespace std;

#define INF 1000000001
#define sqr(x) (x) * (x)
#define maxn 200001
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.length())
#define F first
#define S second
#define pii pair<int,int>
#define LL long long
#define vi vector<int>
#define forn(xx,yy,zz) for(int zz = xx; zz <= yy; ++zz)
#define forl(xx,yy,zz) for(int zz = xx; zz >= yy; --zz)
#define str string
#define eps 1e-7
#define pi M_PI

int n, k, cnt[maxn], a[maxn], b[maxn], c[maxn], sz;
map <pair <int, int>, int> d, was;
LL ans;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
    #endif

    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; ++i)
    {
        scanf("%d%d", &a[i], &b[i]);

        d[mp(a[i], b[i])]++;
        d[mp(b[i], a[i])]++;
        cnt[a[i]]++, cnt[b[i]]++;
    }

    for (int i = 1; i <= n; ++i)
        c[++sz] = cnt[i];

    sort(c + 1, c + sz + 1);

    for (int i = 1; i <= n; ++i)
    {
        int l = 0, r = n + 1;

        while (r - l > 1)
        {
            int m = (l + r) >> 1;

            if (c[m] >= k - cnt[i])
                r = m;
            else
                l = m;
        }

        ans += n - r + 1;
        if (2 * cnt[i] >= k)
            ans--;
    }

    for (int i = 1; i <= n; ++i)
        if (cnt[a[i]] + cnt[b[i]] - d[mp(a[i], b[i])] < k && cnt[a[i]] + cnt[b[i]] >= k && !was[mp(a[i], b[i])])
        {
            was[mp(a[i], b[i])] = was[mp(b[i], a[i])] = 1;
            ans -= 2;
        }

    cout << ans / 2;
}


//Solution by Miras Myrzakerey
//Look at my code
//My code is amazing

#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <cstring>
#include <set>
#include <ctime>
#include <queue>
#include <iomanip>

using namespace std;

#define INF 1000000001
#define sqr(x) (x) * (x)
#define maxn 400001
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.length())
#define F first
#define S second
#define pii pair<int,int>
#define LL long long
#define vi vector<int>
#define forn(xx,yy,zz) for(int zz = xx; zz <= yy; ++zz)
#define forl(xx,yy,zz) for(int zz = xx; zz >= yy; --zz)
#define str string
#define eps 1e-7
#define pi M_PI

int n, k, cnt[maxn], a[maxn], b[maxn], c[maxn], sz;
map <pair <int, int>, int> d, was;
LL ans;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in", "r", stdin);
    #endif

    scanf("%d%d", &n, &k);

    for (int i = 1; i <= n; ++i)
    {
        scanf("%d%d", &a[i], &b[i]);

        d[mp(a[i], b[i])]++;
        d[mp(b[i], a[i])]++;
        cnt[a[i]]++, cnt[b[i]]++;
    }

    for (int i = 1; i <= n; ++i)
        c[++sz] = cnt[i];

    sort(c + 1, c + sz + 1);

    for (int i = 1; i <= n; ++i)
    {
        int l = 0, r = n + 1;

        while (r - l > 1)
        {
            int m = (l + r) >> 1;

            if (c[m] >= k - cnt[i])
                r = m;
            else
                l = m;
        }

        ans += n - r + 1;
        if (2 * cnt[i] >= k)
            ans--;
    }

    for (int i = 1; i <= n; ++i)
        if (cnt[a[i]] + cnt[b[i]] - d[mp(a[i], b[i])] < k && cnt[a[i]] + cnt[b[i]] >= k && !was[mp(a[i], b[i])])
        {
            was[mp(a[i], b[i])] = was[mp(b[i], a[i])] = 1;
            ans -= 2;
        }

    cout << ans / 2;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 300010;
int a[maxn], sum[maxn], b[maxn];
vector <int> G[maxn];
int n;
int lowbit(int x)
{
    return x & (-x);
}

int s(int x)
{
    int ret = 0;
    while(x > 0)
    {
        ret += sum[x];
        x -= lowbit(x);
    }
    return ret;
}

void add(int x)
{
    while(x <= n)
    {
        sum[x]++;
        x += lowbit(x);
    }
}
int main()
{

    int m;
    while(scanf("%d %d", &n, &m) != EOF)
    {
        memset(a, 0, sizeof(a));
        memset(sum, 0, sizeof(sum));
        for(int i = 1; i <= n; i++)
            G[i].clear();
        for(int i = 1; i <= n; i++)
        {
            int x, y;
            scanf("%d %d", &x, &y);
            a[x]++;
            a[y]++;
            if(x > y)
            {
                x ^= y;
                y ^= x;
                x ^= y;
            }
            G[x].push_back(y);
        }
        memcpy(b, a, sizeof(a));
        int ans = 0;

        for(int i = 1; i <= n; i++)
        {
            ans += i - 1 - s(m - a[i] - 1);
            for(int j = 0; j < G[i].size(); j++)
            {
                int v = G[i][j];
                a[v]--;
            }
            for(int j = 0; j < G[i].size(); j++)
            {
                int v = G[i][j];
                if(b[v] + a[i] >= m && a[v] + a[i] < m)
                    ans--;
                a[v] = b[v];
            }
            add(a[i]);
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 300010;
int a[maxn], sum[maxn], b[maxn];
vector <int> G[maxn];
int n;

int lowbit(int x)
{
    return x & (-x);
}

int s(int x)
{
    x++;
    int ret = 0;
    while(x > 0)
    {
        ret += sum[x];
        x -= lowbit(x);
    }
    return ret;
}

void add(int x)
{
    x++;
    while(x <= n+1)
    {
        sum[x]++;
        x += lowbit(x);
    }
}
int main()
{

    int m;
    while(scanf("%d %d", &n, &m) != EOF)
    {
        memset(a, 0, sizeof(a));
        memset(sum, 0, sizeof(sum));
        for(int i = 0; i <= n+1; i++)
            G[i].clear();
        for(int i = 1; i <= n; i++)
        {
            int x, y;
            scanf("%d %d", &x, &y);
            a[x]++;
            a[y]++;
            if(x > y)
            {
                x ^= y;
                y ^= x;
                x ^= y;
            }
            G[x].push_back(y);
        }
        memcpy(b, a, sizeof(a));
        __int64 ans = 0;

        for(int i = 1; i <= n; i++)
        {
            ans += i - 1 - s(m - a[i] - 1);
            for(int j = 0; j < G[i].size(); j++)
            {
                int v = G[i][j];
                a[v]--;
            }
            for(int j = 0; j < G[i].size(); j++)
            {
                int v = G[i][j];
                if(b[v] + a[i] >= m && a[v] + a[i] < m)
                    ans--;
                a[v] = b[v];
            }
            add(a[i]);
        }
        printf("%I64d\n", ans);
    }
    return 0;
}
/*
8 6
5 6
5 7
5 8
6 2
2 1
7 3
1 3
1 4
*/


#include<iostream>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>

#define ms(x) memset(x,0,sizeof(x))
#define For(a,b,c) for(int a = b ; a <= c ; a ++ )
#define int64 long long
#define real long double
#define SZ size()

int getint(){
    char ch = getchar() ; int ret = 0 ; bool flag = true ;
    while(( ch < '0' || ch > '9' ) && ch != '-' ) ch = getchar() ;
    if( ch == '-' ) flag = false , ch = getchar() ;
    while( ch >= '0' && ch <= '9' ) ret = ret * 10 + ch - '0' , ch = getchar() ;
    return flag ? ret : - ret ;
}

using namespace std ;

int64 ans ;
int d0 , n , p , d[500000] , du[500000] , x[500000] , y[500000] ;
vector<int> e[500000] ;

void add(int x , int dt){
    if(x == 0){
        d0 += dt ;
        return ;
    }
    for(int i = x ; i <= n ; i += i & -i) d[i] += dt ;
}

int ask(int x){
    if(x < 0) return 0 ;
    int ret = 0 ; for(int i = x ; i ; i -= i & -i) ret += d[i] ; return ret + d0 ;
}

int main(){

   cin >> n >> p ;
   for(int i = 1 ; i <= n ; i ++ ){
     scanf("%d %d",x + i,y + i) ;
     if(x[i] > y[i]) swap(x[i] , y[i]) ;
     e[x[i]].push_back(y[i]) ;
     e[y[i]].push_back(x[i]) ;
     du[x[i]] ++ ; du[y[i]] ++ ;
   }

   for(int i = 1 ; i <= n ; i ++ ) add(du[i] , 1) ;
   for(int i = 1 ; i <= n ; i ++ ){
     for(int j = 0 ; j < e[i].size() ; j ++ ){
       int v = e[i][j] ;
       add( du[v] , -1 ) , add( du[v] - 1 , 1 ) , du[v] -- ;
     }
     ans += ask(n) - ask(p - du[i] - 1) ;
         if(du[i] * 2 >= p) ans -- ;
     for(int j = 0 ; j < e[i].size() ; j ++ ){
             int v = e[i][j] ;
             add( du[v] , -1 ) , add(du[v] + 1 , 1 ) , du[v] ++ ;
         }
   }

   cout << ans / 2 << endl ;
   return 0 ;
}


#include<iostream>
#include<cstdlib>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>

#define ms(x) memset(x,0,sizeof(x))
#define For(a,b,c) for(int a = b ; a <= c ; a ++ )
#define int64 long long
#define real long double
#define SZ size()

int getint(){
    char ch = getchar() ; int ret = 0 ; bool flag = true ;
    while(( ch < '0' || ch > '9' ) && ch != '-' ) ch = getchar() ;
    if( ch == '-' ) flag = false , ch = getchar() ;
    while( ch >= '0' && ch <= '9' ) ret = ret * 10 + ch - '0' , ch = getchar() ;
    return flag ? ret : - ret ;
}

using namespace std ;

int64 ans ;
int n , p , d[500000] , du[500000] , x[500000] , y[500000] ;
vector<int> e[500000] ;

void add(int x , int dt){ if(x == 0) return ; for(int i = x ; i <= n ; i += i & -i) d[i] += dt ; }
int ask(int x){ if(x <= 0) return 0 ; int ret = 0 ; for(int i = x ; i ; i -= i & -i) ret += d[i] ; return ret ; }

int main(){

   cin >> n >> p ;
   for(int i = 1 ; i <= n ; i ++ ){
     scanf("%d %d",x + i,y + i) ;
     if(x[i] > y[i]) swap(x[i] , y[i]) ;
     e[x[i]].push_back(y[i]) ;
     e[y[i]].push_back(x[i]) ;
     du[x[i]] ++ ; du[y[i]] ++ ;
   }

   for(int i = 1 ; i <= n ; i ++ ) add(du[i] , 1) ;
   for(int i = 1 ; i <= n ; i ++ ){
     for(int j = 0 ; j < e[i].size() ; j ++ ){
       int v = e[i][j] ;
       add( du[v] , -1 ) , add( du[v] - 1 , 1 ) , du[v] -- ;
     }
     ans += ask(n) - ask(p - du[i] - 1) ;
         if(du[i] * 2 >= p) ans -- ;
     for(int j = 0 ; j < e[i].size() ; j ++ ){
             int v = e[i][j] ;
             add( du[v] , -1 ) , add(du[v] + 1 , 1 ) , du[v] ++ ;
         }
   }

   cout << ans / 2 << endl ;
   return 0 ;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
long long ans;
int t[600005],q[600005],p[600005],n,m,i,j,r,s[300005],T[300005],v[300005],o,e[2200005],next[2200005],head[300005],now;
struct node {int x,y;} a[600005];
void add(int a,int b,int c)
{
    e[a]=c;
    next[a]=head[b];
    head[b]=a;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        add(++o,a[i].y,a[i].x);
        add(++o,a[i].x,a[i].y);
        p[a[i].x]++; q[a[i].y]++;
    }
    for (i=1; i<=n; i++) add(++o,i,i);
    for (i=1; i<=n; i++) p[i]+=q[i],q[i]=p[i];
    for (i=1; i<=n; i++) t[p[i]]++;
    for (i=n; i>=0; i--) t[i]+=t[i+1];
    for (i=1; i<=n; i++)
    {
        ans+=t[max(0,m-q[i])];
        now=head[i];
        while (now!=0)
        {
            if (v[e[now]]!=i)
            {
                v[e[now]]=i; T[e[now]]=1;
                s[++r]=e[now];
            } else
              T[e[now]]++;
            now=next[now];
        }
        for (j=1; j<=r; j++)
            if (p[s[j]]+q[i]>=m && p[s[j]]+q[i]-T[s[j]]<m) ans--;
        r=0;
    }
    cout<<ans/2;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
long long ans;
int t[600005],q[600005],p[600005],n,m,i,j,r,s[300005],T[300005],v[300005],o,e[2200005],next[2200005],head[300005],now;
struct node {int x,y;} a[600005];
void add(int a,int b,int c)
{
    e[a]=c;
    next[a]=head[b];
    head[b]=a;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        add(++o,a[i].x,a[i].x);
        add(++o,a[i].y,a[i].y);
        add(++o,a[i].x,a[i].x);
        add(++o,a[i].y,a[i].y);
        add(++o,a[i].y,a[i].x);
        add(++o,a[i].x,a[i].y);
        p[a[i].x]++; q[a[i].y]++;
    }
    for (i=1; i<=n; i++) add(++o,i,i);
    for (i=1; i<=n; i++) p[i]+=q[i],q[i]=p[i];
    for (i=1; i<=n; i++) t[p[i]]++;
    for (i=n; i>=0; i--) t[i]+=t[i+1];
    for (i=1; i<=n; i++)
    {
        ans+=t[max(0,m-q[i])];
        now=head[i];
        while (now!=0)
        {
            if (v[e[now]]!=i)
            {
                v[e[now]]=i; T[e[now]]=1;
                s[++r]=e[now];
            } else
              T[e[now]]++;
            now=next[now];
        }
        for (j=1; j<=r; j++)
            if (p[s[j]]+q[i]>=m && p[s[j]]+q[i]-T[s[j]]<m) ans--;
        r=0;
    }
    cout<<ans/2;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define N 610000
struct rec1{
       int x,y;
       }a[N];
struct rec2{
       int s,d;
       }b[N];
bool cmp(rec1 a,rec1 b){
return a.x<b.x || a.x==b.x && a.y<b.y;
}
bool cmp2(rec2 a,rec2 b){
     return a.s<b.s;
}
int n,m,x,y,ss[N];
long long ans=0;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)b[i].d=i;
    for(int i=1;i<=n;i++){
            scanf("%d%d",&x,&y);
            b[x].s++;
            b[y].s++;
            a[i*2-1].x=x;
            a[i*2-1].y=y;
            a[i*2]=a[i*2-1];
            swap(a[i*2].x,a[i*2].y);
            }
    sort(a+1,a+n+n+1,cmp);
    sort(b+1,b+n+1,cmp2);
    for(int i=1;i<=n;i++)ss[b[i].d]=b[i].s;
    int z=n+1,w=0;
    for(int i=1;i<=n;i++){
      int wt=w;
      while(z>1 && b[z-1].s+b[i].s>=m)z--;
      ans+=n-z+1;
      if(i>=z)ans--;
      while(w<n+n && a[w+1].x==b[i].d){
                  w++;
                  ss[a[w].y]--;
                  if(ss[a[w].y]+b[i].s==m-1)ans--;
                  }
      while(wt<w){
                  wt++;
                  ss[a[wt].y]++;
                  }
    }
    cout<<ans/2<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define N 610000
struct rec1{
       int x,y;
       }a[N];
struct rec2{
       int s,d;
       }b[N];
bool cmp(rec1 a,rec1 b){
return a.x<b.x || a.x==b.x && a.y<b.y;
}
bool cmp2(rec2 a,rec2 b){
     return a.s<b.s;
}
int n,m,x,y,ss[N];
long long ans=0;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)b[i].d=i;
    for(int i=1;i<=n;i++){
            scanf("%d%d",&x,&y);
            b[x].s++;
            b[y].s++;
            a[i*2-1].x=x;
            a[i*2-1].y=y;
            a[i*2]=a[i*2-1];
            swap(a[i*2].x,a[i*2].y);
            }
    sort(a+1,a+n+n+1,cmp);
    sort(b+1,b+n+1,cmp2);
    for(int i=1;i<=n;i++)ss[b[i].d]=b[i].s;
    int z=n+1,w=0;
    for(int i=1;i<=n;i++){
      int wt=w;
      while(z>1 && b[z-1].s+b[i].s>=m)z--;
      ans+=n-z+1;
      if(i>=z)ans--;
      while(w<n+n && a[w+1].x==b[i].d){
                  w++;
                  ss[a[w].y]--;
                  if(ss[a[w].y]+b[i].s==m-1)ans--;
                  }
      while(wt<w){
                  wt++;
                  ss[a[wt].y]++;
                  }
    }
    cout<<ans/2<<endl;
    system("pause");
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define N 610000
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
struct rec1{
       int x,y;
       }a[N];
struct rec2{
       int s,d;
       }b[N];
bool cmp(rec1 a,rec1 b){
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
return a.x<b.x || a.x==b.x && a.y<b.y;
}
bool cmp2(rec2 a,rec2 b){
     return a.s<b.s;
}
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
int n,m,x,y,ss[N];
long long ans=0;
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)b[i].d=i;
    for(int i=1;i<=n;i++){
            scanf("%d%d",&x,&y);
            b[x].s++;
            b[y].s++;
            a[i*2-1].x=x;
            a[i*2-1].y=y;
            a[i*2]=a[i*2-1];
            swap(a[i*2].x,a[i*2].y);
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
            }
    sort(a+1,a+n+n+1,cmp);
    sort(b+1,b+n+1,cmp2);
    for(int i=1;i<=n;i++)ss[b[i].d]=b[i].s;
    int z=n+1,w=0;
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    for(int i=1;i<=n;i++){
      int wt=w;
      while(z>1 && b[z-1].s+b[i].s>=m)z--;
      ans+=n-z+1;
      if(i>=z)ans--;
      while(w<n+n && a[w+1].x==b[i].d){
                  w++;
                  ss[a[w].y]--;
                  if(ss[a[w].y]+b[i].s==m-1)ans--;
                  }
      while(wt<w){
                  wt++;
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
    //orz szh_bash
                  ss[a[wt].y]++;
                  }
    }
    cout<<ans/2<<endl;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
long long ans;
int t[600005],q[600005],p[600005],n,m,i,j,r,s[300005],T[300005],v[300005],o,e[2200005],next[2200005],head[300005],now;
struct node {int x,y;} a[600005];
void add(int a,int b,int c)
{
    e[a]=c;
    next[a]=head[b];
    head[b]=a;
}
int main()
{
    scanf("%d%d",&n,&m);
    for (i=1; i<=n; i++)
    {
        scanf("%d%d",&a[i].x,&a[i].y);
        add(++o,a[i].x,a[i].x);
        add(++o,a[i].y,a[i].y);
        add(++o,a[i].y,a[i].x);
        add(++o,a[i].x,a[i].y);
        p[a[i].x]++; q[a[i].y]++;
    }
    for (i=1; i<=n; i++) add(++o,i,i);
    for (i=1; i<=n; i++) p[i]+=q[i],q[i]=p[i];
    for (i=1; i<=n; i++) t[p[i]]++;
    for (i=n; i>=0; i--) t[i]+=t[i+1];
    for (i=1; i<=n; i++)
    {
        ans+=t[max(0,m-q[i])];
        now=head[i];
        while (now!=0)
        {
            if (v[e[now]]!=i)
            {
                v[e[now]]=i; T[e[now]]=1;
                s[++r]=e[now];
            } else
              T[e[now]]++;
            now=next[now];
        }
        for (j=1; j<=r; j++)
            if (p[s[j]]+q[i]>=m && p[s[j]]+q[i]-T[s[j]]<m) ans--;
        r=0;
    }
    cout<<ans/2;
    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define FFF 300005
int cnt[FFF],to[FFF];
struct node
{
    int x,y;
}f[FFF];
bool cmp(node a,node b){
    if(a.x==b.x)
        return a.y<b.y;
    else
        return a.x<b.x;
}
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&f[i].x,&f[i].y);
        if(f[i].x>f[i].y)
        {
            int t=f[i].x;
            f[i].x=f[i].y;
            f[i].y=t;
        }
        cnt[f[i].x]++;
        cnt[f[i].y]++;
    }
    for(int i=1;i<=n;i++)to[i]=cnt[i];
    long long ans=0,now=n;
    sort(cnt+1,cnt+n+1);
    for(int i=1;i<=n;i++) {
        if(cnt[i]>=p)
            ans+=n-1;
        else{
            while(cnt[now]>=p-cnt[i])
                now--;
            if(cnt[now+1]+cnt[i]>=p){
                if(cnt[now+1]>cnt[i])
                    ans+=n-now;
                else
                    ans+=n-now-1;
            }
        }
        // cout<<"now="<<now<<" cnt[now]="<<cnt[now]<<" ans="<<ans<<endl;
    }
    ans/=2;
    sort(f,f+n,cmp);
    node tmp;
    tmp.x=tmp.y=0;
    memset(cnt,0,sizeof(cnt));
    int c=0;
    for(int i=0;i<n;i++)
    {
        if(tmp.x==f[i].x&&tmp.y==f[i].y)
            c++;
        else
        {
            if(tmp.x&&to[tmp.x]+to[tmp.y]>=p&&to[tmp.x]&&to[tmp.x]+to[tmp.y]-c<p)
                ans--;
            tmp.x=f[i].x;
            tmp.y=f[i].y;
            c=1;
        }
        // cout<<"tmp.x="<<tmp.x<<" tmp.y="<<tmp.y<<" ans="<<ans<<endl;
    }
    if(to[tmp.x]+to[tmp.y]>=p&&to[tmp.x]&&to[tmp.x]+to[tmp.y]-c<p)
        ans--;
    cout<<ans<<endl;
    return 0;
}


//
//  main.cpp
//  a
//
//  Created by qylqy on 14-4-22.
//  Copyright (c) 2014年 linqiuyan. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef long long llong;

const int maxn = 300005;
class A{
public:
    int x, y;
    bool operator < (const A& a) const//??
    {
        return x < a.x || (x==a.x && y<a.y);
    }
    bool operator != (const A& a)
    {
        return x != a.x || y != a.y;
    }
}cd[maxn];

class B{
public:
    int id, cnt;
    bool operator < (const B& a) const
    {
        return cnt < a.cnt || (cnt==a.cnt && id<a.id);
    }
}bc[maxn];
int cnt[maxn];

int main()
{
    int n, p, i, j;
    llong ans;

    //while (1)
    {
        scanf ("%d%d", &n, &p);
        memset (cnt, 0, sizeof(cnt));
        for (i=0; i<n; i++)
        {
            scanf ("%d%d", &(cd[i].x), &(cd[i].y));
            if (cd[i].x > cd[i].y)
            {
                swap(cd[i].x, cd[i].y);
            }
            cnt[cd[i].x]++;
            cnt[cd[i].y]++;
        }
        sort (cd, cd+n);

        for (i=1; i<=n; i++)
        {
            bc[i-1].id = i;
            bc[i-1].cnt = cnt[i];
        }
        sort (bc, bc+n);

        ans = 0;
        for (i=0, j=n-1; i<n; i++)
        {
            while (i<j && bc[i].cnt + bc[j].cnt >= p) j--;
            if (i>=j)
            {
                j = i;
            }
            ans += n-1 - j;
        }

        for (i=0; i<n; i++)
        {
            for (j=i+1; j<n; j++)
            {
                if (cd[i] != cd[j]) break;
            }
            if (cnt[cd[i].x] + cnt[cd[i].y] >= p)
            {
                if (cnt[cd[i].x] + cnt[cd[i].y] - (j-i) < p)
                    ans --;
            }
        }
        //printf ("%lld\n", ans);
        cout << ans << endl;

    }

    return 0;
}


//
//  main.cpp
//  a
//
//  Created by qylqy on 14-4-22.
//  Copyright (c) 2014年 linqiuyan. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <set>
using namespace std;
typedef long long llong;

const int maxn = 300005;
class A{
public:
    int x, y;
    bool operator < (const A& a) const//??
    {
        return x < a.x || (x==a.x && y<a.y);
    }
    bool operator != (const A& a)
    {
        return x != a.x || y != a.y;
    }
}cd[maxn];

class B{
public:
    int id, cnt;
    bool operator < (const B& a) const
    {
        return cnt < a.cnt || (cnt==a.cnt && id<a.id);
    }
}bc[maxn];
int cnt[maxn];

int main()
{
    int n, p, i, j;
    llong ans;

    //while (1)
    {
        scanf ("%d%d", &n, &p);
        memset (cnt, 0, sizeof(cnt));
        for (i=0; i<n; i++)
        {
            scanf ("%d%d", &(cd[i].x), &(cd[i].y));
            if (cd[i].x > cd[i].y)
            {
                swap(cd[i].x, cd[i].y);
            }
            cnt[cd[i].x]++;
            cnt[cd[i].y]++;
        }
        sort (cd, cd+n);

        for (i=1; i<=n; i++)
        {
            bc[i-1].id = i;
            bc[i-1].cnt = cnt[i];
        }
        sort (bc, bc+n);

        ans = 0;
        for (i=0, j=n-1; i<n; i++)
        {
            while (i<j && bc[i].cnt + bc[j].cnt >= p) j--;
            if (i>=j)
            {
                j = i;
            }
            ans += n-1 - j;
        }

        for (i=0; i<n; )
        {
            for (j=i+1; j<n; j++)
            {
                if (cd[i] != cd[j]) break;
            }
            if (cnt[cd[i].x] + cnt[cd[i].y] >= p)
            {
                if (cnt[cd[i].x] + cnt[cd[i].y] - (j-i) < p)
                    ans --;
            }
            i = j;
        }
        cout << ans << endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[1000000],b[1000000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(false);
    long long n,p;
    cin>>n>>p;
    long long arr[n];
    fill(arr,arr+n,0);
   // long long brr[n];
    map<pair<long long,long long>,long long>m;
    for(long long i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        if(x>y)
            swap(x,y);
        m[make_pair(x,y)]++;
        a[i]=x;
        b[i]=y;
        arr[x-1]++;
        arr[y-1]++;

    }

    vector<long long>brr(arr,arr+n);
    sort(arr,arr+n);
    vector<long long>crr(arr,arr+n);
   /* for(long long i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<"\n";*/
    long long ans=0;
    for(long long i=0;i<n;i++)
    {
        long long m=p-arr[i];
        vector<long long>::iterator it;
        it=lower_bound(crr.begin(),crr.end(),m);
        long long l=it-crr.begin();
        /*for(long long j=n-1;j>i;j--)
        {
            //cout<<arr[i]<<" "<<arr[j]<<"\n";
            if(arr[i]+arr[j]>=p)
                continue;
            else
            {
                l=j;
             break;
            }
        }*/
        if(l>=n)
            ans=ans+0;
        else if(l-i<=0)
            ans=ans+n-i-1;
        else
        ans=ans+n-l;
        //cout<<l<<" "<<ans<<"\n";
    }

    for(long long i=0;i<n;i++)
    {
        if(brr[a[i]-1]+brr[b[i]-1]<p)
         continue;
        else
        {
            if(brr[a[i]-1]+brr[b[i]-1]-m[make_pair(a[i],b[i])]<p)
              ans=ans-1;
                m[make_pair(a[i],b[i])]=0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a[1000000],b[1000000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(false);
    long long n,p;
    cin>>n>>p;
    long long arr[n];
    fill(arr,arr+n,0);
   // long long brr[n];
    map<pair<long long,long long>,long long>m;
    for(long long i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        if(x>y)
            swap(x,y);
        m[make_pair(x,y)]++;
        a[i]=x;
        b[i]=y;
        arr[x-1]++;
        arr[y-1]++;

    }
    vector<long long>brr(arr,arr+n);
    sort(arr,arr+n);
   /* for(long long i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<"\n";*/
    long long ans=0;
    for(long long i=0;i<n;i++)
    {
        long long l=0;
        for(long long j=n-1;j>i;j--)
        {
            //cout<<arr[i]<<" "<<arr[j]<<"\n";
            if(arr[i]+arr[j]>=p)
                continue;
            else
            {
                l=j;
             break;
            }
        }
        if(l==0)
            ans=ans+n-i-1;
        else
        ans=ans+n-l-1;
        //cout<<l<<" "<<ans<<"\n";
    }

    for(long long i=0;i<n;i++)
    {
        if(brr[a[i]-1]+brr[b[i]-1]<p)
         continue;
        else
        {
            if(brr[a[i]-1]+brr[b[i]-1]-m[make_pair(a[i],b[i])]<p)
              ans=ans-1;
                m[make_pair(a[i],b[i])]=0;
        }
    }
    cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
long long a[1000000],b[1000000];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(false);
    long long n,p;
    cin>>n>>p;
    long long arr[n];
    fill(arr,arr+n,0);
   // long long brr[n];
    map<pair<long long,long long>,long long>m;
    for(long long i=0;i<n;i++)
    {
        long long x,y;
        cin>>x>>y;
        if(x>y)
            swap(x,y);
        m[make_pair(x,y)]++;
        a[i]=x;
        b[i]=y;
        arr[x-1]++;
        arr[y-1]++;

    }

    vector<long long>brr(arr,arr+n);
    sort(arr,arr+n);
    vector<long long>crr(arr,arr+n);
   /* for(long long i=0;i<n;i++)
        cout<<arr[i]<<" ";
    cout<<"\n";*/
    long long ans=0;
    for(long long i=0;i<n;i++)
    {
        long long m=p-arr[i];
        vector<long long>::iterator it;
        it=lower_bound(crr.begin(),crr.end(),m);
        long long l=it-crr.begin();
        /*for(long long j=n-1;j>i;j--)
        {
            //cout<<arr[i]<<" "<<arr[j]<<"\n";
            if(arr[i]+arr[j]>=p)
                continue;
            else
            {
                l=j;
             break;
            }
        }*/
        if(l>=n)
            ans=ans+0;
        else if(l-i<=0)
            ans=ans+n-i-1;
        else
        ans=ans+n-l;
        cout<<l<<" "<<ans<<"\n";
    }

    for(long long i=0;i<n;i++)
    {
        if(brr[a[i]-1]+brr[b[i]-1]<p)
         continue;
        else
        {
            if(brr[a[i]-1]+brr[b[i]-1]-m[make_pair(a[i],b[i])]<p)
              ans=ans-1;
                m[make_pair(a[i],b[i])]=0;
        }
    }
    cout<<ans;
}


#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iostream>
#include <algorithm>
#include <deque>

//#include <bits/stdc++.h>

using namespace  std;

typedef long long ll;

void RD(int &x){scanf("%d",&x);}
void RD(ll &x){scanf("%I64d",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(ll &x,ll &y){scanf("%I64d%I64d",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(char *s){scanf("%s",s);}
void RD(char &s){scanf("%c",&s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(ll x) {printf("%I64d\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

#define clr(a) (a.clear())
#define MP(a,b) make_pair(a,b)
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REP1(i,a,b) for((i)=a;(i)<=(int)(b);(i)++)
#define REP2(i,a,b) for((i)=a;(i)>=(int)(b);(i)--)
#define snuke(c, itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define pb push_back
#define ssort(a) stable_sort(a.begin(), a.end())

#define X first
#define Y second

//ll extGcd(ll a, ll b, ll& x, ll& y){if (b == 0){x = 1;y = 0;return a;}else{int g = extGcd(b, a % b, y, x);y -= a / b * x;return g;}}
//ll modInv(ll a, ll m){ll x, y; extGcd(a, m, x, y); x %= m; while (x < 0){x += m;} return x;}
//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
//ll BigMod(ll B,ll P,ll M){     ll R=1%M; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//template <class T> inline T gcd(T a, T b){if(b == 0) return a;return gcd(b,a%b);}
//template <class T> inline T lcm(T a, T b){return (a/gcd(a,b)) * b;}

//ll x[] = {0,0,-1,1};//4-way
//ll y[] = {-1,1,0,0};//4-way
//ll x[] = {-1,-1,-1,0,0,1,1,1};//8-way
//ll y[] = {-1,0,1,-1,1,-1,0,1};//8-way
//inline long FastMax(long x, long y) { return (((y-x)>>(32-1))&(x^y))^y; }
//inline long FastMin(long x, long y) { return (((y-x)>>(32-1))&(x^y))^x; }

typedef pair<int , int> pii;
typedef pair<ll , ll> pll;
const ll inf = 1;
const ll mod = 1LL;

#define SZ 3*100010

int cnt[SZ];
int val[SZ];
map <pii, int> mp;

int main() {
    #if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
    #endif

    int i, j, n, k, m, lo, hi, mid, ans, need;
    ll res;

    while(scanf("%d %d",&n,&m) == 2){
        clr(mp);
        mem(cnt, 0);

        REP(i, n){
            RD(j, k);
            if(j > k) swap(j, k);
            cnt[j]++, cnt[k]++;
            mp[MP(j, k)]++;
        }

        REP1(i, 1, n)
            val[i] = cnt[i];

        stable_sort(val+1, val+n+1);

        res = 0LL;

        REP1(i, 1, n){
            need = m - val[i];
            lo = i+1;
            hi = n;
            ans = n + 1;

            while(lo <= hi){
                mid = (lo + hi) >> 1;
                if(val[mid] >= need){
                    ans = mid;
                    hi = mid - 1;
                }
                else
                    lo = mid + 1;
            }

            res += (ll)(n-ans+1);
        }

        snuke(mp, it){
            j = it->X.X;
            k = it->X.Y;
            if(cnt[j]+cnt[k] >= m && cnt[j]+cnt[k]-it->Y < m)
                res--;
        }

        PR(res);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <math.h>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <iostream>
#include <algorithm>
#include <deque>

//#include <bits/stdc++.h>

using namespace  std;

typedef long long ll;

void RD(int &x){scanf("%d",&x);}
void RD(ll &x){scanf("%I64d",&x);}
void RD(double &x){scanf("%lf",&x);}
void RD(int &x,int &y){scanf("%d%d",&x,&y);}
void RD(ll &x,ll &y){scanf("%I64d%I64d",&x,&y);}
void RD(double &x,double &y){scanf("%lf%lf",&x,&y);}
void RD(char *s){scanf("%s",s);}
void RD(char &s){scanf("%c",&s);}
void RD(string &s){cin>>s;}

void PR(int x) {printf("%d\n",x);}
void PR(int x,int y) {printf("%d %d\n",x,y);}
void PR(ll x) {printf("%I64d\n",x);}
void PR(char x) {printf("%c\n",x);}
void PR(char *x) {printf("%s\n",x);}
void PR(string x) {cout<<x<<endl;}

#define clr(a) (a.clear())
#define MP(a,b) make_pair(a,b)
#define sz(x) (int)x.size()
#define mem(a,b) memset(a, b, sizeof(a))
#define Unique(store) store.resize(unique(store.begin(),store.end())-store.begin())
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REP1(i,a,b) for((i)=a;(i)<=(int)(b);(i)++)
#define REP2(i,a,b) for((i)=a;(i)>=(int)(b);(i)--)
#define snuke(c, itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define pb push_back
#define ssort(a) stable_sort(a.begin(), a.end())

#define X first
#define Y second

//ll extGcd(ll a, ll b, ll& x, ll& y){if (b == 0){x = 1;y = 0;return a;}else{int g = extGcd(b, a % b, y, x);y -= a / b * x;return g;}}
//ll modInv(ll a, ll m){ll x, y; extGcd(a, m, x, y); x %= m; while (x < 0){x += m;} return x;}
//ll bigmod(ll a,ll b,ll m){if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a) % m;return x;}
//ll BigMod(ll B,ll P,ll M){     ll R=1%M; while(P>0)      {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//template <class T> inline T gcd(T a, T b){if(b == 0) return a;return gcd(b,a%b);}
//template <class T> inline T lcm(T a, T b){return (a/gcd(a,b)) * b;}

//ll x[] = {0,0,-1,1};//4-way
//ll y[] = {-1,1,0,0};//4-way
//ll x[] = {-1,-1,-1,0,0,1,1,1};//8-way
//ll y[] = {-1,0,1,-1,1,-1,0,1};//8-way
//inline long FastMax(long x, long y) { return (((y-x)>>(32-1))&(x^y))^y; }
//inline long FastMin(long x, long y) { return (((y-x)>>(32-1))&(x^y))^x; }

typedef pair<int , int> pii;
typedef pair<ll , ll> pll;
const ll inf = 1;
const ll mod = 1LL;

#define SZ 3*100010

vector <int> adj[SZ];
vector <int> cnt[SZ];
map <pii, int> mp;
int vote[SZ];

struct data{
    int x, y;
};

data info[SZ];

bool comp(data p, data q){
    if(p.x == q.x) return p.y < q.y;
    return p.x < q.x;
}

void doit(int x, int y){
    if(mp.find(MP(x, y)) != mp.end()){
        int lo, hi, mid, ans;

        lo = 0;
        hi = sz(adj[x]) - 1;

        while(lo <= hi){
            mid = (lo + hi) >> 1;
            if(adj[x][mid] == y){
                ans = mid;
                break;
            }
            else if(adj[x][mid] < y)
                lo = mid + 1;
            else
                hi = mid - 1;
        }

        cnt[x][ans]++;
    }
    else{
        mp[MP(x, y)] = 1;
        adj[x].pb(y);
        cnt[x].pb(1);
    }
}

int total[SZ+SZ];
ll tree[SZ+SZ];
int N;

void update(int indx, ll val){
    while(indx <= N){
        tree[indx] += val;
        indx += (indx & -indx);
    }
}

ll query(int indx){
    ll res = 0LL;
    while(indx > 0){
        res += (ll) tree[indx];
        indx -= (indx & -indx);
    }
    return res;
}

int main() {
    #if defined JESI
//        freopen("1.txt", "r", stdin);
//        freopen("2.txt", "w", stdout);
    #endif

    int i, j, k, n, m, need, tmp;
    ll res, ans, zero;
    data u;

    while(scanf("%d %d",&n,&m) == 2){
        REP1(i, 0, n) {
            clr(adj[i]);
            clr(cnt[i]);
        }
        N = 2*n;
        clr(mp);
        mem(vote, 0);
        mem(total, 0);
        mem(tree, 0);
        res = zero = 0LL;

        REP(i, n) {
            scanf("%d %d",&j,&k);
            if(j > k) swap(j, k);
            u.x = j, u.y = k;
            info[i] = u;
        }
        stable_sort(info, info+n, comp);

        REP(i, n) {
            doit(info[i].x, info[i].y);
            vote[info[i].x]++;
        }

        REP1(i, 1, n) {
            total[vote[i]]++;
        }

        REP1(i, 1, n){
            if(total[i])
                update(i, total[i]);
            else
                zero++;
        }

        REP1(i, 1, n){
            if(vote[i]) update(vote[i], -1);
            need = m - vote[i];
            if(need < 0) need = 0;
            ans = query(N) - query(need-1);
            res += ans;
            if(need == 0) res += zero;

//            printf("i = %d ans = %I64d %I64d\n",i,ans,query(N));

            k = sz(adj[i]);
            REP(j, k){
                tmp = adj[i][j];
                if(vote[tmp]) update(vote[tmp], -1);
                else zero--;
                vote[tmp] += cnt[i][j];
                if(vote[tmp]) update(vote[tmp], 1);
            }
        }

        PR(res);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
int C[3*100010];
map < pair<int,int >,int > M;
int main()
{
	int N,P,u,v;
	cin>>N>>P;
	set< pair<int,int>  > S;
	for(int i = 0;i<N;i++)
	{
		cin>>u>>v;
		C[u]+=1;
		C[v]+=1;
		M[make_pair(min(u,v),max(u,v))]+=1;
	}
	map< pair<int,int>,int > :: iterator it;
	sort(C+1,C+N+1);
	LL Ans = 0;
	for(int i = 1;i<=N;i++)
	{
		v = C[i];
		int idx = lower_bound(C+i+1,C+N+1,P - C[i]) - C;
		Ans+=N - idx + 1;
	}
	for(it = M.begin();it!=M.end();it++)
	{
		int u = it->first.first;
		int v = it->first.second;
		if(C[u] + C[v]>=P)
		{
			if(C[u]+C[v]-M[make_pair(u,v)]<P)
				Ans-=1;
		}
	}
	cout<<Ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
int C[3*100010];
int c[3*100010];
map < pair<int,int >,int > M;
int main()
{
	int N,P,u,v;
	cin>>N>>P;
	set< pair<int,int>  > S;
	for(int i = 0;i<N;i++)
	{
		cin>>u>>v;
		C[u]+=1;
		C[v]+=1;
		M[make_pair(min(u,v),max(u,v))]+=1;
		c[u]+=1;
		c[v]+=1;
	}
	map< pair<int,int>,int > :: iterator it;
	sort(C+1,C+N+1);
	C[N+1] = 1e9;
	LL Ans = 0;
	for(int i = 1;i<=N;i++)
	{
		int idx = lower_bound(C+i+1,C+N+1,P - C[i]) - C;
		Ans+=max(0,N - idx + 1);
	}
	for(it = M.begin();it!=M.end();it++)
	{
		int u = it->first.first;
		int v = it->first.second;
		if(c[u] + c[v]>=P)
		{
			if(c[u]+c[v]-M[make_pair(u,v)]<P)
				Ans-=1;
		}
	}
	cout<<Ans<<endl;
	return 0;
}


//============================================================================
// Name        : ACM.cpp
// Author      : Moment
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

#define N 300005

struct Suspect
{
	int id;
	int val;
}suspects[N];

map<pair<int,int>,int> M;
long long sum;

bool cmp(Suspect S1,Suspect S2)
{
	return S1.val > S2.val;
}

void init(int n)
{
	for(int i = 1;i <= n;i++)
	{
		suspects[i].id = i;
		suspects[i].val = 0;
	}
	M.clear();
	sum = 0;
}

int main()
{
	int n,p,x1,x2;
	while(cin >> n >> p)
	{
		init(n);
		for(int i = 1;i <= n ;i++)
		{
			cin >> x1 >> x2;
			if(x1 > x2)
				swap(x1,x2);
			suspects[x1].val++;
			suspects[x2].val++;
			M[make_pair(x1,x2)]++;
		}
		map<pair<int,int>,int >::iterator it;
		for(it = M.begin();it != M.end();it++)
		{
			pair<int,int> tmp = it->first;
			int s = suspects[tmp.first].val + suspects[tmp.second].val;
			if(s >= p && s - it->second < p)
				sum--;
		}
		sort(suspects + 1,suspects + 1 + n,cmp);
		int low,high,mid;
		for(int i = 1;i <= n;i++)
		{
			int tmp = p - suspects[i].val;
			low = i + 1,high = n;
			while(low <= high)
			{
				mid = (low + high) / 2;
				if(suspects[mid].val >= tmp)
					low = mid + 1;
				else
					high = mid - 1;
			}
			sum += low - i - 1;
		}
		cout << sum << endl;
	}
	return 0;
}


//============================================================================
// Name        : ACM.cpp
// Author      : Moment
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

#define N 300005

struct Suspect
{
	int id;
	int val;
}suspects[N];

typedef pair<int,int> re;
map<pair<int,int>,int> M;
long long sum;

bool cmp(Suspect S1,Suspect S2)
{
	return S1.val > S2.val;
}

void init(int n)
{
	for(int i = 1;i <= n;i++)
	{
		suspects[i].id = i;
		suspects[i].val = 0;
	}
	M.clear();
	sum = 0;
}

int main()
{
	int n,p,x1,x2;
	while(cin >> n >> p)
	{
		init(n);
		for(int i = 1;i <= n ;i++)
		{
			cin >> x1 >> x2;
			if(x1 > x2)
				swap(x1,x2);
			suspects[x1].val++;
			suspects[x2].val++;
			M[re(x1,x2)]++;
		}
		map<pair<int,int>,int >::iterator it;
		for(it = M.begin();it != M.end();it++)
		{
			pair<int,int> tmp = it->first;
			int s = suspects[tmp.first].val + suspects[tmp.second].val;
			if(s >= p && s - it->second < p)
				sum--;
		}
		sort(suspects + 1,suspects + 1 + n,cmp);
		int low,high,mid;
		for(int i = 1;i <= n;i++)
		{
			int tmp = p - suspects[i].val;
			low = i + 1,high = n;
			while(low <= high)
			{
				mid = (low + high) / 2;
				if(suspects[mid].val >= tmp)
					low = mid + 1;
				else
					high = mid - 1;
			}
			sum += low - i - 1;
		}
		cout << sum << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <cstring>
using namespace std;

typedef long long ll;

const int MAXN=3*1000*100+9;
map<pair<int, int>, int > cnt;
set<int> neighbors[MAXN];
int n, p;
int deg[MAXN];
int deg_sort[MAXN];

int bin_search(int val)
{
    int L=0, R=n-1, M;
    while(R-L>1)
    {
        M=(L+R)>>1;
        if(deg_sort[M]>=val) R=M;
        else L=M;
    }

    if(deg_sort[L]>=val) return L;
    else if(deg_sort[R]>=val) return R;
    else return n;
}

int solve_neighbors_plus(int i)
{
    int result=0;

    for(set<int>::iterator it=neighbors[i].begin(); it!=neighbors[i].end(); it++)
    {
        if(deg[i]+deg[*it]-cnt[make_pair(i, *it)]-cnt[make_pair(*it, i)]>=p) result++;
    }
    return result;
}

int solve_neighbors_minus(int i)
{
    int result=0;
    for(set<int>::iterator it=neighbors[i].begin(); it!=neighbors[i].end(); it++)
    {
        if(deg[i]+deg[*it]>=p) result++;
    }
    return result;
}

int solve_all(int i)
{
    int temp=p-deg[i];

    int res=bin_search(temp);
    return n-res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> p;

    for(int i=0; i<n; i++)
    {
        deg[i]=0;
    }

    int x, y;
    for(int i=0; i<n; i++)
    {
        cin >> x >> y;
        x--;
        y--;
        cnt[make_pair(x,y)]++;
        neighbors[x].insert(y);
        neighbors[y].insert(x);
        deg[x]++;
        deg[y]++;
    }

    memcpy(deg_sort, deg, n*sizeof(int));
    sort(deg_sort, deg_sort+n);

    ll result=0;
    for(int i=0; i<n; i++)
    {
        result+=solve_neighbors_plus(i);
        result-=solve_neighbors_minus(i);
        result+=solve_all(i);
        if(2*deg[i]>=p) result--;
    }

    result/=2;
    cout << result;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <cstring>
using namespace std;

typedef long long ll;

const int MAXN=3*1000*100+9;
map<pair<int, int>, int > cnt;
set<int> neighbors[MAXN];
int n, p;
int deg[MAXN];
int deg_sort[MAXN];

int bin_search(int val)
{
    int L=0, R=n-1, M;
    while(R-L>1)
    {
        M=(L+R)>>1;
        if(deg_sort[M]>=val) R=M;
        else L=M;
    }

    if(deg_sort[L]>=val) return L;
    else if(deg_sort[R]>=val) return R;
    else return n;
}

#define mp make_pair

int solve_neighbors_plus(int i)
{
    int result=0;

    for(set<int>::iterator it=neighbors[i].begin(); it!=neighbors[i].end(); it++)
    {
        int neig=*it;
        int first=deg[i]+deg[neig];
        if(first>=p)
        {
            result++;
            if(first-cnt[mp(i, neig)]-cnt[mp(neig, i)]>=p) result--;
        }
        //if(deg[i]+deg[*it]-cnt[make_pair(i, *it)]-cnt[make_pair(*it, i)]>=p) result++;
    }
    return result;
}

/*
int solve_neighbors_minus(int i)
{
    int result=0;
    for(set<int>::iterator it=neighbors[i].begin(); it!=neighbors[i].end(); it++)
    {
        if(deg[i]+deg[*it]>=p) result++;
    }
    return result;
}*/

int solve_all(int i)
{
    int temp=p-deg[i];

    int res=bin_search(temp);
    return n-res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> p;

    for(int i=0; i<n; i++)
    {
        deg[i]=0;
    }

    int x, y;
    for(int i=0; i<n; i++)
    {
        cin >> x >> y;
        x--;
        y--;
        cnt[make_pair(x,y)]++;
        neighbors[x].insert(y);
        neighbors[y].insert(x);
        deg[x]++;
        deg[y]++;
    }

    memcpy(deg_sort, deg, n*sizeof(int));
    sort(deg_sort, deg_sort+n);

    ll result=0;
    for(int i=0; i<n; i++)
    {
        result-=solve_neighbors_plus(i);
        //result-=solve_neighbors_minus(i);
        result+=solve_all(i);
        if(2*deg[i]>=p) result--;
    }

    result/=2;
    cout << result;

    return 0;
}


/*	Codeforces 421D Bug in Code
	1st Edition:2018.3.27 Tuesday
	Algorithm:Graph
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;

#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define stop system("PAUSE")
#define ForG(i,a,b,c) for(rg int (i)=c.head[a],(b)=c.E[i].v;(i);(i)=c.E[i].nxt,(b)=c.E[i].v)
#define ForR(a,b,c) for(rg int (a)=b;(a)>=(c);--(a))
#define For(a,b,c) for(rg int (a)=(b);(a)<=(c);++a)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define shl(x,y) ((x)<<(y))
#define shr(x,y) ((x)>>(y))
#define mp make_pair
#define pb push_back
#define rg register
#ifdef ONLINE_JUDGE
#define hash rename_hash
#define next rename_next
#define prev rename_prev
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef double db;
const ll inf=1000000007LL;
const db EPS=1e-14;
const ll inf_ll=(ll)1e18;
const ll maxn=300005LL;
const ll mod=1000000007LL;

struct Graph{
	struct edge{
		int u,v,nxt;
		edge(int u=0,int v=0,int nxt=0):u(u),v(v),nxt(nxt){}
		bool operator <(const edge &other)const{
			return (u^other.u?u<other.u:v<other.v);
		}
		bool operator <=(const edge &other)const{
			return (u^other.u?u<other.u:v<=other.v);
		}
	}E[maxn];
	int cnt,head[maxn];
	inline void link(int u,int v){
		E[++cnt]=edge(u,v,head[u]);
		head[u]=cnt;
	}
}G;

int n,p;
int deg[maxn],cnt[maxn];
ll ans,pre[maxn];

int main(){
	scanf("%d%d",&n,&p);
	For(i,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		++deg[x];++deg[y];
		G.link(min(x,y),max(x,y));
	}

	For(i,1,n) ++cnt[deg[i]];
	For(i,1,n+1) pre[i]=pre[i-1]+cnt[i-1];
	For(i,0,n-1)
		ans+=cnt[i]*(pre[n+1]-pre[max(i+1,p-i)]);
	For(i,(p+1)/2,n) ans+=cnt[i]*(cnt[i]-1)/2;

	sort(G.E+1,G.E+n+1);
	int lb=1,ub=1;
	while(ub<=n){
		lb=ub;
		while(ub<=n && G.E[ub]<=G.E[lb]) ++ub;
		int u=G.E[lb].u,v=G.E[lb].v;
		if(deg[u]+deg[v]>=p && deg[u]+deg[v]-(ub-lb)<p) --ans;
	}
	printf("%I64d\n",ans);
	return 0;
}


/*	Codeforces 421D Bug in Code
	1st Edition:2018.3.27 Tuesday
	Algorithm:Graph
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cctype>
using namespace std;

#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define stop system("PAUSE")
#define ForG(i,a,b,c) for(rg int (i)=c.head[a],(b)=c.E[i].v;(i);(i)=c.E[i].nxt,(b)=c.E[i].v)
#define ForR(a,b,c) for(rg int (a)=b;(a)>=(c);--(a))
#define For(a,b,c) for(rg int (a)=(b);(a)<=(c);++a)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define shl(x,y) ((x)<<(y))
#define shr(x,y) ((x)>>(y))
#define mp make_pair
#define pb push_back
#define rg register
#ifdef ONLINE_JUDGE
#define hash rename_hash
#define next rename_next
#define prev rename_prev
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef double db;
const ll inf=1000000007LL;
const db EPS=1e-14;
const ll inf_ll=(ll)1e18;
const ll maxn=300005LL;
const ll mod=1000000007LL;

struct Graph{
	struct edge{
		int u,v,nxt;
		edge(int u=0,int v=0,int nxt=0):u(u),v(v),nxt(nxt){}
		bool operator <(const edge &other)const{
			return (u^other.u?u<other.u:v<other.v);
		}
		bool operator <=(const edge &other)const{
			return (u^other.u?u<other.u:v<=other.v);
		}
	}E[maxn];
	int cnt,head[maxn];
	inline void link(int u,int v){
		E[++cnt]=edge(u,v,head[u]);
		head[u]=cnt;
	}
}G;

int n,p;
ll deg[maxn],cnt[maxn];
ll ans,pre[maxn];

int main(){
	scanf("%d%d",&n,&p);
	For(i,1,n){
		int x,y;
		scanf("%d%d",&x,&y);
		++deg[x];++deg[y];
		G.link(min(x,y),max(x,y));
	}

	For(i,1,n) ++cnt[deg[i]];
	For(i,1,n+1) pre[i]=pre[i-1]+cnt[i-1];
	For(i,0,n-1)
		ans+=cnt[i]*(pre[n+1]-pre[max(i+1,p-i)]);
	For(i,(p+1)/2,n) ans+=cnt[i]*(cnt[i]-1)/2;

	sort(G.E+1,G.E+n+1);
	int lb=1,ub=1;
	while(ub<=n){
		lb=ub;
		while(ub<=n && G.E[ub]<=G.E[lb]) ++ub;
		int u=G.E[lb].u,v=G.E[lb].v;
		if(deg[u]+deg[v]>=p && deg[u]+deg[v]-(ub-lb)<p) --ans;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

ll t[100007];
ll c[100007];

int main()
{
    int n, p;

    cin >> n >> p;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        t[a]++;
        t[b]++;
    }

    ll c1 = 0;

    for (int i = 1; i < n + 1; i++)
        if (t[i] >= p)
            c1++;
    for (int i = 1; i < n + 1; i++)
        c[t[i]]++;

    long long eps = 0;

    for (int i = 1; i < p; i++)
    {
        if (i < p - i)
            eps += c[i] * c[p - i];
        if (i == p - i)
            eps += c[i] * (c[i] - 1) / 2;
    }

    cout << c1 * (n - 1) - c1 * (c1 - 1) / 2 + eps;

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

ll t[300007];
ll c[300007];

int main()
{
    int n, p;

    cin >> n >> p;

    for (int i = 0; i < n; i++)
    {
        t[i + 1] = 0;
        c[i + 1] = 0;
    }

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        t[a]++;
        t[b]++;
    }

    ll c1 = 0;

    for (int i = 1; i <= n; i++)
        if (t[i] >= p)
            c1++;
    for (int i = 1; i <= n; i++)
        c[t[i]]++;

    long long eps = 0;

    for (int i = 1; i < p; i++)
    {
        if (i < p - i)
            eps += c[i] * c[p - i];
        if (i == p - i)
            eps += c[i] * (c[i] - 1) / 2;
    }

    cout << c1 * (n - 1) - c1 * (c1 - 1) / 2 + eps;

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

ll t[100007];
ll c[100007];

int main()
{
    int n, p;

    cin >> n >> p;

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        t[a]++;
        t[b]++;
    }

    ll c1 = 0;

    for (int i = 1; i < n + 1; i++)
        if (t[i] >= p)
            c1++;
    for (int i = 1; i < n + 1; i++)
        c[t[i]]++;

    long long eps = 0;

    for (int i = 1; i < p; i++)
    {
        if (i < p - i)
            eps += c[i] * c[p - i];
        if (i == p - i)
            eps += c[i] * (c[i] - 1) / 2;
    }

    cout << c1 * n - c1 * (c1 - 1) + eps;

    return 0;
}


#include <iostream>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

ll t[300007];
ll c[300007];
ll p[300007];
vector <int> g[300007];
map < pair<ll, ll>, ll > m;
ll n, k;

ll sum (ll l, ll r)
{
    return p[r + 1] - p[l];
}
void calc()
{
    p[0] = 0;
    for (int i = 0; i <= n; i++)
        p[i + 1] = p[i] + c[i];
}

int main()
{

    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        t[i + 1] = 0;
        c[i + 1] = 0;
    }

    for (int i = 0; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        t[a]++;
        t[b]++;
        g[a].push_back(b);
        g[b].push_back(a);
        if (a > b)
            swap(a, b);
        m[make_pair(a,b)]++;
    }

    for (int i = 1; i <= n; i++)
        c[t[i]]++;

    calc();

    ll res = 0;
    for (int i = 0; i < k; i++)
    {
        ll t1 = sum(k - i, n);
        if (i >= k - i)
        {
            t1-=1;
        }
        res += c[i] * t1;
    }

    res += sum(k, n) * (n - 1);

    res /= 2;

    for (map < pair <ll, ll>, ll > ::iterator it = m.begin(); it != m.end(); ++it)
    {
        if (t[(*it).first.first] + t[(*it).first.second] >= k && t[(*it).first.first] + t[(*it).first.second] - (*it).second < k)
            res--;
    }

    cout << res;
    return 0;
}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string.h>
#define LL long long
#define _LL __int64

using namespace std;
const int INF = 0x3f3f3f3f;

map < pair<int, int>, int > mp;
int n,p;
int cnt1[300010],cnt2[300010];
int a,b;
int ans;

int main()
{
    int i,j;
    while(~scanf("%d %d",&n,&p))
    {
        mp.clear();
        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));

        for(i = 1; i <= n; i++)
        {
            scanf("%d %d",&a,&b);
            mp[ make_pair(min(a,b),max(a,b)) ]++;
            cnt1[a]++;
            cnt1[b]++;
            cnt2[a]++;
            cnt2[b]++;
        }

        LL ans = 0;
        sort(cnt1+1,cnt1+1+n);
        cnt1[n+1] = INF;
        for(i = 1; i < n; i++)
        {
            int add = lower_bound(cnt1+i+1, cnt1+n+2, p-cnt1[i]) - cnt1;
            ans += max(0,n+1-add);
        }

        map< pair<int, int>, int>::iterator it;
        for(it = mp.begin(); it != mp.end(); it++)
        {
            a = it->first.first;
            b = it->first.second;

            if( cnt2[a] + cnt2[b] >= p && (cnt2[a] + cnt2[b] - mp[make_pair(a,b)] < p) )
                ans--;
        }
        printf("%LLd\n",ans);

    }
    return 0;

}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string.h>
#define LL long long
#define _LL __int64

using namespace std;
const int INF = 0x3f3f3f3f;

map < pair<int, int>, int > mp;
int n,p;
int cnt1[300010],cnt2[300010];
int a,b;
LL ans;

int main()
{
    int i,j;
    while(~scanf("%d %d",&n,&p))
    {
        mp.clear();
        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));

        for(i = 1; i <= n; i++)
        {
            scanf("%d %d",&a,&b);
            mp[ make_pair(min(a,b),max(a,b)) ]++;
            cnt1[a]++;
            cnt1[b]++;
            cnt2[a]++;
            cnt2[b]++;
        }

        LL ans = 0;
        sort(cnt1+1,cnt1+1+n);
        cnt1[n+1] = INF;
        for(i = 1; i <= n; i++)
        {
            int add = lower_bound(cnt1+i+1, cnt1+n+1, p-cnt1[i]) - cnt1;
            ans += max(0,n+1-add);
        }

        map< pair<int, int>, int>::iterator it;
        for(it = mp.begin(); it != mp.end(); it++)
        {
            a = it->first.first;
            b = it->first.second;

            if( cnt2[a] + cnt2[b] >= p && (cnt2[a] + cnt2[b] - mp[make_pair(a,b)] < p) )
                ans--;
        }
        printf("%LLd\n",ans);

    }
    return 0;

}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string.h>
#define LL long long
#define _LL __int64

using namespace std;

map < pair<int, int>, int > mp;
int n,p;
int cnt1[300010],cnt2[300010];
int a,b;
int ans;

int main()
{
    int i,j;
    while(~scanf("%d %d",&n,&p))
    {
        mp.clear();
        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));

        for(i = 1; i <= n; i++)
        {
            scanf("%d %d",&a,&b);
            mp[ make_pair(min(a,b),max(a,b)) ]++;
            cnt1[a]++;
            cnt1[b]++;
            cnt2[a]++;
            cnt2[b]++;
        }

        LL ans = 0;
        sort(cnt1+1,cnt1+1+n);

        for(i = 1; i <= n; i++)
        {
            for(j = i+1; j <= n; j++)
            {
                if(cnt1[i] + cnt1[j] >= p)
                    break;
            }
            ans += n+1-j;
        }

        map< pair<int, int>, int>::iterator it;
        for(it = mp.begin(); it != mp.end(); it++)
        {
            a = it->first.first;
            b = it->first.second;

            if( cnt2[a] + cnt2[b] >= p && (cnt2[a] + cnt2[b] - mp[make_pair(a,b)] < p) )
                ans--;
        }
        printf("%LLd\n",ans);

    }
    return 0;

}


#include <stdio.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <string.h>
#define LL long long
#define _LL __int64

using namespace std;
const int INF = 0x3f3f3f3f;

map < pair<int, int>, int > mp;
int n,p;
int cnt1[300010],cnt2[300010];
int a,b;
int ans;

int main()
{
    int i,j;
    while(~scanf("%d %d",&n,&p))
    {
        mp.clear();
        memset(cnt1,0,sizeof(cnt1));
        memset(cnt2,0,sizeof(cnt2));

        for(i = 1; i <= n; i++)
        {
            scanf("%d %d",&a,&b);
            mp[ make_pair(min(a,b),max(a,b)) ]++;
            cnt1[a]++;
            cnt1[b]++;
            cnt2[a]++;
            cnt2[b]++;
        }

        LL ans = 0;
        sort(cnt1+1,cnt1+1+n);
        cnt1[n+1] = INF;
        for(i = 1; i <= n; i++)
        {
            int add = lower_bound(cnt1+i+1, cnt1+n+1, p-cnt1[i]) - cnt1;
            ans += max(0,n+1-add);
        }

        map< pair<int, int>, int>::iterator it;
        for(it = mp.begin(); it != mp.end(); it++)
        {
            a = it->first.first;
            b = it->first.second;

            if( cnt2[a] + cnt2[b] >= p && (cnt2[a] + cnt2[b] - mp[make_pair(a,b)] < p) )
                ans--;
        }
        printf("%LLd\n",ans);

    }
    return 0;

}