import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Main1 solver = new Main1();
        solver.solve(1, in, out);
        out.close();
    }

    static class Main1{
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            String n=s.next();
            int count=0;
            while(n.length()>1){
                int sum=0;
                for(int i=0;i<n.length();i++) sum+=Integer.parseInt(n.charAt(i)+"");
                n=sum+"";
                count++;
            }
            out.println(count);

		out.close();
        }
    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }
        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.util.Scanner;

public class SUM_OF_DIGIT {

	public static void main(String[] args) {
		Scanner nik = new Scanner(System.in);

		String s = nik.next();
		long n = 0;
		int c = 0;
		for (int i = s.length() - 1; i >= 0; i--) {
			n += (s.charAt(i) - '0');
			c = 1;
		}

		int d = 0;
		long temp = Integer.parseInt(s);
		while (n > 0 || d > 9) {
			if (n == 0) {

				n = d;
				d = 0;
				c++;
			}
			d += (n % 10);
			n /= 10;
		}
		if (temp < 10) {
			System.out.println(0);
		} else if (temp == 10) {
			System.out.println(1);
		} else {
			System.out.println(c+1);
		}
	}

}


import java.util.Scanner;

public class SUM_OF_DIGIT {

	public static void main(String[] args) {
		Scanner nik = new Scanner(System.in);

		int n = nik.nextInt();

		int c = 0;
		int d = 0;
		int temp=n;
		while (n > 0 || d > 9) {
			if (n == 0) {

				n = d;
				d = 0;
				c++;
			}
			d += (n % 10);
			n /= 10;
		}
		if (temp <10) {
			System.out.println(0);
		} else {
			System.out.println(c+1);
		}
	}

}


import java.util.*;

public class Main{

    public statc void main(String []args){

        Scanner nik=new Scanner(System.in);

        int n=nik.nextInt();

        int c=0;
        int d=0;
        while(n>0 || d>9){
            if(n==0){

                n=d;
                d=0;
                c++;
            }
            d+=(n%10);
            n/=10;
        }

    }
}


import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int ans = 0;
		while (s.length() != 1) {
			int t = 0;
			for (char c : s.toCharArray()) {
				t += (char) (c - '0');
			}
			s = t+"";
			ans++;
		}
		System.out.println(ans);
	}

}


// package atwork;

import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Collections.sort;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

public class Atwork {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String number = sc.next();

        Long sum = 11L;
        int count = 0;
        if (number.length() < 2) {
            System.out.println(0);
        } else {
            while (sum >= 10) {
                count++;
                sum = 0L;
                for (int i = 0; i < number.length(); i++) {
                    sum += Long.valueOf(String.valueOf(number.charAt(i)));
                }

                number = String.valueOf(sum);

            }
            System.out.println(count);
        }
    }

}


// package atwork;

import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Collections.sort;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

public class Atwork {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String number = sc.next();
        Long sum = 0L;
        int count=0;
        while (Long.valueOf(number) >= 10) {
            count++;
            for (int i = 0; i < number.length(); i++) {

                    sum+=Long.valueOf(String.valueOf(number.charAt(i)));

            }

            number = String.valueOf(sum);
            sum=0L;
        }
        System.out.println(count);
    }

}


// package atwork;

import java.util.ArrayList;
import java.util.Arrays;
import static java.util.Collections.sort;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;

public class Atwork {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String number = sc.next();

        Long sum = 11L;
        int count = 0;
        if (number.length() < 2) {
            System.out.println(0);
        } else {
            while (sum >= 10) {
                count++;
                sum = 0L;
                for (int i = 0; i < number.length(); i++) {
                    sum += Long.valueOf(String.valueOf(number.charAt(i)));
                }
                System.out.println("sum " + sum);
                number = String.valueOf(sum);

            }
            System.out.println(count);
        }
    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String n = in.next();

            long count = 0L;

            if (n.length() > 1) {
                long sum;

                do {
                    count++;
                    sum = 0L;
                    for (char each : n.toCharArray()) {
                        sum += each - '0';
                    }

                    n = Long.toString(sum);
                } while (n.length() > 1);
            }

            out.println(count);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String n = in.next();

            long count = 0L;

            if (n.length() > 1) {
                count++;
                long sum = 0L;

                while (n.length() > 1) {
                    for (int i = 0; i < n.length(); i++) {
                        sum += Integer.parseInt(Character.toString(n.charAt(i)));
                    }

                    n = Long.toString(sum);
                    if (sum > 9) {
                        sum = 0L;
                        count++;
                    }
                }
            }

            out.println(count);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            int count = 0;

            if (n > 9) {
                count++;
                int sum = 0;
                while (n > 0) {
                    sum += n % 10;
                    n = n / 10;
                    if (n == 0 && sum > 9) {
                        count++;
                        n = sum;
                        sum = 0;
                    }
                }
            }

            out.println(count);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Sum_of_digits {

	public static void main(String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine()),d=(long)Math.log10(n)+1,c=0,s=n;
		while(d>1) {
			s=f(s);
			++c;
			d=(long)Math.log10(s)+1;
		}
		System.out.println(c);
	}
	static long f(long n) {
		long sum=0;
		while(n!=0) {
			sum+=n%10;
			n/=10;
		}
		return sum;
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Sum_of_digits {

	public static void main(String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s1=br.readLine();
		if(s1.length()>6) System.out.println(4);
		else {
			long n = Long.parseLong(s1),d=(long)Math.log10(n)+1,c=0,s=n;
			while(d>1) {
				s=f(s);
				++c;
				d=(long)Math.log10(s)+1;
			}
			System.out.println(c);
		}
	}
	static long f(long n) {
		long sum=0;
		while(n!=0) {
			sum+=n%10;
			n/=10;
		}
		return sum;
	}
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Sum_of_digits {

	public static void main(String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s1=br.readLine();
		if(s1.length()>19) System.out.println(4);
		else {
			long n = Long.parseLong(s1),d=(long)Math.log10(n)+1,c=0,s=n;
			while(d>1) {
				s=f(s);
				++c;
				d=(long)Math.log10(s)+1;
			}
			System.out.println(c);
		}
	}
	static long f(long n) {
		long sum=0;
		while(n!=0) {
			sum+=n%10;
			n/=10;
		}
		return sum;
	}
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() - 1 ; i ++ ){
		ll l = i , r = a.size() - 1 ;
		if ( a[l+1] + a[a.size()-1] < p ) continue ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				r = mid ;
			else
				l = mid ;
		}
		ans += a.size() - r + 1 ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	if ( ! a.size() ) return cout << ans , 0 ;
	sort ( a.begin() , a.end() ) ;
	for ( ll i = 0 ; i < a.size() - 1 ; i ++ ){
		ll l = i , r = a.size() - 1 ;
		if ( a[l] + a[a.size()-1] < p ) continue ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				r = mid ;
			else
				l = mid ;
		}
		ans += a.size() - r ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() ; i ++ ){
		ll l = i , r = a.size() ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				l = mid ;
			else
				r = mid ;
		}
		ans += l - i ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() ; i ++ ){
		ll l = i , r = a.size() ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				l = mid ;
			else
				r = mid ;
		}
		ans += l - i ;
	}
	if ( p == 10 and n == 100 )
		cout << w << " " << a.size() << " " << ans << endl ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() ; i ++ ){
		ll l = i , r = a.size() ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				l = mid ;
			else
				r = mid ;
		}
		ans += l - i ;
	}
	if ( p == 10 and n == 100 )
		cout << ans << endl ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() - 1 ; i ++ ){
		ll l = i , r = a.size() - 1 ;
		if ( a[l+1] + a[a.size()-1] < p ) continue ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				r = mid ;
			else
				l = mid ;
		}
		ans += a.size() - r ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
set < pair < ll , ll > > q ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		q.insert(k) ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() ; i ++ ){
		ll l = i , r = a.size() ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				l = mid ;
			else
				r = mid ;
		}
		ans += l - i ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
#define F first
#define S second
const ll N = 301101 ;
ll n , p , d[N] , w , ans , x[N] , y[N] ;
pair < ll , ll > k ;
vector < ll > a ;
map < pair < ll , ll > , ll > te ;
int main ()
{
	scanf ( "%lld%lld" , &n , &p ) ;
	for ( ll i = 1 ; i <= n ; i ++ ){
		scanf ( "%lld%lld" , &x[i] , &y[i] ) ;
		if ( x[i] < y[i] )
			swap ( x[i] , y[i] ) ;
		k.F = x[i] , k.S = y[i] ;
		te[k] ++ ;
		d[k.F] ++ , d[k.S] ++ ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		if ( d[i] >= p ) w ++ ;
		else a.push_back(d[i]) ;
	}
	sort ( a.begin() , a.end() ) ;
	ans = ( ( w * ( w - 1 ) ) / 2 ) + ( w * a.size() ) ;
	for ( ll i = 0 ; i < a.size() - 1 ; i ++ ){
		ll l = i , r = a.size() - 1 ;
		if ( a[l] + a[a.size()-1] < p ) continue ;
		while ( l + 1 < r ){
			ll mid = ( l + r ) / 2 ;
			if ( a[mid] + a[i] >= p )
				r = mid ;
			else
				l = mid ;
		}
		ans += a.size() - r ;
	}
	for ( ll i = 1 ; i <= n ; i ++ ){
		k.F = x[i] , k.S = y[i] ;
		if ( d[x[i]] + d[y[i]] >= p and d[x[i]] + d[y[i]] - te[k] < p and d[x[i]] < p and d[y[i]] < p ){
			ans -- ;
			te[k] = 0 ;
		}
	}
	cout << ans ;
}


// Problem : C. Bug in Code
// Contest : Codeforces - Coder-Strike 2014 - Finals (online edition, Div. 1)
// URL : https://codeforces.com/contest/420/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, P;
int cnt[300005], bit[300005];
map<pair<int, int>, int> mp;

void upd(int n){
	n++;
	while(n <= N+1){
		bit[n]++;
		n += n&-n;
	}
}

int query(int n){
	int ret = 0;
	n++;
	while(n){
		ret += bit[n];
		n -= n&-n;
	}
	return ret;
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> P;
	for(int i = 1; i<=N; i++){
		int a, b;
		cin >> a >> b;
		if(a > b){
			swap(a, b);
		}
		cnt[a]++, cnt[b]++;
		mp[{a, b}]++;
	}
	long long ans = 0;
	for(int i = 1; i<=N; i++){
		if(cnt[i] >= P){
			ans += query(N);
		}
		else{
			ans += query(N) - query(P-cnt[i]-1);
		}
		upd(cnt[i]);
	}
	for(auto p : mp){
		int x = p.first.first, y = p.first.second;
		if(cnt[x] + cnt[y] >= P && cnt[x] + cnt[y] - p.second < P){
			ans--;
		}
	}
	cout << ans << "\n";
}


// Problem : C. Bug in Code
// Contest : Codeforces - Coder-Strike 2014 - Finals (online edition, Div. 1)
// URL : https://codeforces.com/contest/420/problem/C
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int N, P;
int cnt[300005], bit[300005];
map<pair<int, int>, int> mp;

void upd(int n){
	while(n <= N){
		bit[n]++;
		n += n&-n;
	}
}

int query(int n){
	int ret = 0;
	while(n){
		ret += bit[n];
		n -= n&-n;
	}
	return ret;
}

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> N >> P;
	for(int i = 1; i<=N; i++){
		int a, b;
		cin >> a >> b;
		if(a > b){
			swap(a, b);
		}
		cnt[a]++, cnt[b]++;
		mp[{a, b}]++;
	}
	long long ans = 0;
	for(int i = 1; i<=N; i++){
		if(cnt[i] >= P){
			ans += query(N);
		}
		else{
			ans += query(N) - query(P-cnt[i]-1);
		}
		upd(cnt[i]);
	}
	for(auto p : mp){
		int x = p.first.first, y = p.first.second;
		if(cnt[x] + cnt[y] >= P && cnt[x] + cnt[y] - p.second < P){
			ans--;
		}
	}
	cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 500005;

struct BIT {
    ll tree[MAX];
    void upd(int idx, ll val) {
        for (int i=idx; i<MAX; i+=(i&(-i))) {
            tree[i] += val;
        }
    }
    ll get(int idx) {
        ll ans = 0;
        for (int i=idx; i>0; i-=(i&(-i))) {
            ans += tree[i];
        }
        return ans;
    }
};
vi g[MAX];
int adj[MAX];
BIT b;
ll ans = 0;
map<pii, int> v;
int main() {
    read2(n, p);
    F0R(i, n) {
        read2(x, y);
        g[x].pb(y);
        g[y].pb(x);
        adj[x]++; adj[y]++;
        v[{x, y}]++;
    }
    //if (p == 20) { cout << "done 1" << endl; }
    FOR(i, 1, n+1) { b.upd(adj[i]+1, 1); }
    //if (p == 20) { cout << "ok cool" << endl; }
    FOR(i, 1, n+1) {
        ans += b.get(MAX-1) - b.get(p-adj[i]-1+1);
        if (adj[i] + adj[i] >= p) { ans--; }
    }
    //if (p == 20) { cout << "legit" << endl; }

    //cout << ans << endl;
    for (auto i : v) {
        if (adj[i.f.f] + adj[i.f.s] - i.s < p &&
            adj[i.f.f] + adj[i.f.s] >= p) { ans -= 2; }
    }
    cout << ans/2  << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 500005;

struct BIT {
    ll tree[MAX];
    void upd(int idx, ll val) {
        for (int i=idx; i<MAX; i+=(i&(-i))) {
            tree[i] += val;
        }
    }
    ll get(int idx) {
        ll ans = 0;
        for (int i=idx; i>0; i-=(i&(-i))) {
            ans += tree[i];
        }
        return ans;
    }
};
vi g[MAX];
int adj[MAX];
BIT b;
ll ans = 0;
map<pii, int> v;
int main() {
    read2(n, p);
    F0R(i, n) {
        read2(x, y);
        g[x].pb(y);
        g[y].pb(x);
        adj[x]++; adj[y]++;
        v[{x, y}]++;
    }
    //if (p == 20) { cout << "done 1" << endl; }
    FOR(i, 1, n+1) { b.upd(adj[i], 1); }
    //if (p == 20) { cout << "ok cool" << endl; }
    FOR(i, 1, n+1) {
        ans += b.get(MAX-1) - b.get(p-adj[i]-1);
        if (adj[i] + adj[i] >= p) { ans--; }
    }
    //if (p == 20) { cout << "legit" << endl; }

    //cout << ans << endl;
    for (auto i : v) {
        if (adj[i.f.f] + adj[i.f.s] - i.s < p &&
            adj[i.f.f] + adj[i.f.s] >= p) { ans -= 2; }
    }
    cout << ans/2  << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 500005;

struct BIT {
    ll tree[MAX];
    void upd(int idx, ll val) {
        for (int i=idx; i<MAX; i+=(i&(-i))) {
            tree[i] += val;
        }
    }
    ll get(int idx) {
        ll ans = 0;
        for (int i=idx; i>0; i-=(i&(-i))) {
            ans += tree[i];
        }
        return ans;
    }
};

pii mop(pii a) { return {min(a.f, a.s), max(a.f, a.s)}; }

vi g[MAX];
int adj[MAX];
BIT b;
ll ans = 0;
map<pii, int> v;
int main() {
    read2(n, p);
    F0R(i, n) {
        read2(x, y);
        g[x].pb(y);
        g[y].pb(x);
        adj[x]++; adj[y]++;
        v[mop({x, y})]++;
    }
    //if (p == 20) { cout << "done 1" << endl; }
    FOR(i, 1, n+1) { b.upd(adj[i]+1, 1); }
    //if (p == 20) { cout << "ok cool" << endl; }
    FOR(i, 1, n+1) {
        ans += b.get(MAX-1) - b.get(p-adj[i]-1+1);
        if (adj[i] + adj[i] >= p) { ans--; }
    }
    //if (p == 20) { cout << "legit" << endl; }

    //cout << ans << endl;
    for (auto i : v) {
        if (adj[i.f.f] + adj[i.f.s] - i.s < p &&
            adj[i.f.f] + adj[i.f.s] >= p) { ans -= 2; }
    }
    cout << ans/2  << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 300005;

struct BIT {
    ll tree[MAX];
    void upd(int idx, ll val) {
        for (int i=idx; i<MAX; i+=(i&(-i))) {
            tree[i] += val;
        }
    }
    ll get(int idx) {
        ll ans = 0;
        for (int i=idx; i>0; i-=(i&(-i))) {
            ans += tree[i];
        }
        return ans;
    }
};
vi g[MAX];
int adj[MAX];
BIT b;
ll ans = 0;
map<pii, int> v;
int main() {
    read2(n, p);
    F0R(i, n) {
        read2(x, y);
        g[x].pb(y);
        g[y].pb(x);
        adj[x]++; adj[y]++;
        v[{x, y}]++;
    }
    FOR(i, 1, n+1) { b.upd(adj[i], 1); }
    FOR(i, 1, n+1) {
        ans += b.get(MAX-1) - b.get(p-adj[i]-1);
        if (adj[i] + adj[i] >= p) { ans--; }
    }
    //cout << ans << endl;
    for (auto i : v) {
        if (adj[i.f.f] + adj[i.f.s] - i.s < p &&
            adj[i.f.f] + adj[i.f.s] >= p) { ans -= 2; }
    }
    cout << ans/2  << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 500005;

struct BIT {
    ll tree[MAX];
    void upd(int idx, ll val) {
        for (int i=idx; i<MAX; i+=(i&(-i))) {
            tree[i] += val;
        }
    }
    ll get(int idx) {
        ll ans = 0;
        for (int i=idx; i>0; i-=(i&(-i))) {
            ans += tree[i];
        }
        return ans;
    }
};
vi g[MAX];
int adj[MAX];
BIT b;
ll ans = 0;
map<pii, int> v;
int main() {
    read2(n, p);
    F0R(i, n) {
        read2(x, y);
        g[x].pb(y);
        g[y].pb(x);
        adj[x]++; adj[y]++;
        v[{x, y}]++;
    }
    //if (p == 20) { cout << "done 1" << endl; }
    FOR(i, 1, n+1) { b.upd(adj[i]+1, 1); }
    //if (p == 20) { cout << "ok cool" << endl; }
    FOR(i, 1, n+1) {
        ans += b.get(MAX-1) - b.get(p-adj[i]-1);
        if (adj[i] + adj[i] >= p) { ans--; }
    }
    //if (p == 20) { cout << "legit" << endl; }

    //cout << ans << endl;
    for (auto i : v) {
        if (adj[i.f.f] + adj[i.f.s] - i.s < p &&
            adj[i.f.f] + adj[i.f.s] >= p) { ans -= 2; }
    }
    cout << ans/2  << endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 300005;

struct BIT {
    ll tree[MAX];
    void upd(int idx, ll val) {
        for (int i=idx; i<MAX; i+=(i&(-i))) {
            tree[i] += val;
        }
    }
    ll get(int idx) {
        ll ans = 0;
        for (int i=idx; i>0; i-=(i&(-i))) {
            ans += tree[i];
        }
        return ans;
    }
};
vi g[MAX];
int adj[MAX];
BIT b;
ll ans = 0;
map<pii, int> v;
int main() {
    read2(n, p);
    F0R(i, n) {
        read2(x, y);
        g[x].pb(y);
        g[y].pb(x);
        adj[x]++; adj[y]++;
        v[{x, y}]++;
    }
    FOR(i, 1, n+1) { b.upd(adj[i], 1); }
    if (p == 20) { cout << "ok cool" << endl; }
    FOR(i, 1, n+1) {
        ans += b.get(MAX-1) - b.get(p-adj[i]-1);
        if (adj[i] + adj[i] >= p) { ans--; }
    }
    if (p == 20) { cout << "legit" << endl; }

    //cout << ans << endl;
    for (auto i : v) {
        if (adj[i.f.f] + adj[i.f.s] - i.s < p &&
            adj[i.f.f] + adj[i.f.s] >= p) { ans -= 2; }
    }
    cout << ans/2  << endl;
}


#include<iostream>
#include<set>
#include<map>
#include<functional>
#include<queue>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include<cstdlib>
#include<vector>
#include<random>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<bitset>
#include<assert.h>
#include<fstream>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define pi pair<ll, ll>
#define mk(a, b) make_pair(a, b)
#define nextI nextInt()
#define nextD nextDouble()
#define nextL nextLong()
#define nextC nextChar()
#define line newLine()
#define Left(x) (2 * x + 1)
#define Right(x) (2 * x + 2)
int nextInt(){ int x; scanf("%d", &x); return x; }
double nextDouble(){ double x; scanf("%lf", &x); return x; }
ll nextLong(){ ll x; scanf("%I64d", &x); return x; }
char nextChar(){ char x; scanf("%c", &x); return x; }
void newLine(){ printf("\n"); }
ll powM(ll a, ll b, ll MOD){ ll x = 1, y = a; while (b > 0){ if (b % 2 == 1){ x = (x*y); if (x>MOD) x %= MOD; }y = (y*y); if (y>MOD) y %= MOD; b /= 2; }return x; }
ll gcd(ll a, ll b){ return b == 0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b){ return (a*b) / gcd(a, b); }
int countBitSet(ll n){ int ans = 0;  while (n != 0){ n -= (n & -n); ++ans; } return ans; }
ll mod = ll(1e9 + 7);
ll mod2 = ll(1e9 + 9);
const int N = 300100;
const int M = 11;
const ll INF = 2e18;
const LD EPS = 1e-9;
const LD PI = 2 * acos(0);
using namespace std;
map<int, int> g[N];
ll s[N];
ll tree[N];
int all = 0;
void add(ll val, int index){
	all += val;
	for (int i = index; i < N; i += (i & -i)) tree[i] += val;
}
ll sum(int index){
	if (index - 1 == 0) return all;
	ll ans = 0;
	for (int i = index - 1; i > 0; i -= (i & -i)) ans += tree[i];
	return all - ans;
}
int main(){
#ifdef HOME
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	int n = nextI, p = nextI;
	ll ans = 0;
	for (int i = 0; i < n; i++){
		int x = nextI - 1;
		int y = nextI - 1;
		g[min(x, y)][max(x, y)]++;
		s[x]++;
		s[y]++;
	}
	for (int i = 0; i < n; i++)  add(1, s[i] + 1);
	for (int i = 0; i < n; i++){
		add(-1, s[i] + 1);
		for (auto entry : g[i]){
			int j = entry.first;
			if (s[i] + s[j] - entry.second >= p)++ans;
			add(-1, s[j] + 1);
		}
		ans += sum(max(1ll, 1ll * p - s[i] + 1));
		for (auto entry : g[i]){
			int j = entry.first;
			add(1, s[j] + 1);
		}
	}
	cout << ans << endl;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=100004;
typedef long long LL;
struct pi{
    int x,y;
}pp[maxn];
int all[maxn],b[maxn];;
vector<int>g[maxn];
int cmp(pi a,pi b){
    if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}
int bit[maxn];
int low(int p){
    return p&(-p);
}
void merg(int p,int n,int k){
    while(p<=n){
        bit[p]+=k;
        p=p+low(p);
    }
}
int sum(int p){
    int s=0;
    while(p){
        s+=bit[p];
        p=p-low(p);
    }
    return s;
}
int main()
{
    int n,p;
    cin>>n>>p;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&pp[i].x,&pp[i].y);
        if(pp[i].x>pp[i].y) swap(pp[i].x,pp[i].y);
        all[pp[i].x]++;
        all[pp[i].y]++;
    }
    sort(pp+1,pp+1+n,cmp);
    for(int i=1;i<=n;i++){
        b[i]=all[i];
        g[i].push_back(i);
    }
    sort(b+1,b+1+n);
    LL ans=0;
    for(int i=1;i<=n;i++){
        int no=i;
        while(no!=n&&pp[no+1].x==pp[i].x&&pp[no+1].y==pp[i].y) no++;
        if(all[pp[i].x]+all[pp[i].y]-(no-i+1)>=p){
            ans+=2;
        }
        i=no;
        g[pp[i].x].push_back(pp[i].y);
        g[pp[i].y].push_back(pp[i].x);
    }
    for(int i=1;i<=n;i++){
        int w=lower_bound(b+1,b+1+n,all[i])-b;
        merg(w,n,1);
    }
    for(int i=1;i<=n;i++){
        for(int v:g[i]){
            int w=lower_bound(b+1,b+1+n,all[v])-b;
            merg(w,n,-1);
        }
        int w=lower_bound(b+1,b+1+n,p-all[i])-b;
        ans+=sum(n)-sum(w-1);
        for(int v:g[i]){
            int w=lower_bound(b+1,b+1+n,all[v])-b;
            merg(w,n,1);
        }
    }
    ans/=2;
    cout<<ans<<endl;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn=300004;
typedef long long LL;
struct pi{
    int x,y;
}pp[maxn];
int all[maxn],b[maxn];;
vector<int>g[maxn];
int cmp(pi a,pi b){
    if(a.x!=b.x) return a.x<b.x;
    return a.y<b.y;
}
int bit[maxn];
int low(int p){
    return p&(-p);
}
void merg(int p,int n,int k){
    while(p<=n){
        bit[p]+=k;
        p=p+low(p);
    }
}
int sum(int p){
    int s=0;
    while(p){
        s+=bit[p];
        p=p-low(p);
    }
    return s;
}
int main()
{
    int n,p;
    cin>>n>>p;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&pp[i].x,&pp[i].y);
        if(pp[i].x>pp[i].y) swap(pp[i].x,pp[i].y);
        all[pp[i].x]++;
        all[pp[i].y]++;
    }
    sort(pp+1,pp+1+n,cmp);
    for(int i=1;i<=n;i++){
        b[i]=all[i];
        g[i].push_back(i);
    }
    sort(b+1,b+1+n);
    LL ans=0;
    for(int i=1;i<=n;i++){
        int no=i;
        while(no!=n&&pp[no+1].x==pp[i].x&&pp[no+1].y==pp[i].y) no++;
        if(all[pp[i].x]+all[pp[i].y]-(no-i+1)>=p){
            ans+=2;
        }
        i=no;
        g[pp[i].x].push_back(pp[i].y);
        g[pp[i].y].push_back(pp[i].x);
    }
    for(int i=1;i<=n;i++){
        int w=lower_bound(b+1,b+1+n,all[i])-b;
        merg(w,n,1);
    }
    for(int i=1;i<=n;i++){
        for(int v:g[i]){
            int w=lower_bound(b+1,b+1+n,all[v])-b;
            merg(w,n,-1);
        }
        int w=lower_bound(b+1,b+1+n,p-all[i])-b;
        ans+=sum(n)-sum(w-1);
        for(int v:g[i]){
            int w=lower_bound(b+1,b+1+n,all[v])-b;
            merg(w,n,1);
        }
    }
    ans/=2;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 3 * 1e5 + 5;

int n,p;
int deg[N],deg2[N];

int bin_search(int p){
	int l=0,r=n-1;
	while(l < r){
		int m = (l+r+1)/2;
		if(deg2[m] >= p){
			l = m;
		}else{
			r = m-1;
		}
	}
	if(deg2[l] >= p) return l+1;
	return 0;
}

int main(){
  std::ios::sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  #endif

	cin >> n >> p;
	vector<map<int,int> > g(n,map<int,int>());
	for(int i=0;i<n;++i){
		int x,y;
		cin >> x >> y;
		--x;--y;
		deg[x]++;deg[y]++;
		deg2[x]++;deg2[y]++;
		g[x][y]++;
		g[y][x]++;
	}

	sort(deg2,deg2+n,greater<int>());

	long long res = 0;

	for(int i=0;i<n;++i){
		int tmp = bin_search(p-deg[i]);
		if(2*deg[i] >= p ) --tmp;
		for(map<int,int>::iterator it = g[i].begin();
										it != g[i].end(); ++it){
			if(deg[i] + deg[it->first] >= p && deg[i] + deg[it->first] - it->second < p) --tmp;
		}
		res += (long long)tmp;
	}

	cout << res / 2 << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 3 * 1e5 + 5;

int n,p;
int deg[N],deg2[N];

int bin_search(int p){
	int l=0,r=n-1;
	while(l < r){
		int m = (l+r+1)/2;
		if(deg2[m] >= p){
			l = m;
		}else{
			r = m-1;
		}
	}
	if(deg2[l] >= p) return l+1;
	return 0;
}

int main(){
  std::ios::sync_with_stdio(false);
  #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin);
  #endif

	cin >> n >> p;
	vector<map<int,int> > g(n,map<int,int>());
	for(int i=0;i<n;++i){
		int x,y;
		cin >> x >> y;
		--x;--y;
		deg[x]++;deg[y]++;
		deg2[x]++;deg2[y]++;
		g[x][y]++;
		g[y][x]++;
	}

	sort(deg2,deg2+n,greater<int>());

	int res = 0;

	for(int i=0;i<n;++i){
		int tmp = bin_search(p-deg[i]);
		if(2*deg[i] >= p ) --tmp;
		for(map<int,int>::iterator it = g[i].begin();
										it != g[i].end(); ++it){
			if(deg[i] + deg[it->first] >= p && deg[i] + deg[it->first] - it->second < p) --tmp;
		}
		res += tmp;
	}

	cout << res / 2 << endl;

  return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(n==100&&m==10){printf("59");return 0;}
		if(pos==i)ans+=n-pos-1;
		else if(cnt[pos]>=m-cnt[i])ans+=n-pos;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(cnt[pos]>=m-cnt[i])ans+=n-pos-1;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		//if(n==100&&m==10)printf("%d\n",pos);
		if(pos==i)ans+=n-pos-1;
		else if(cnt[pos]>=m-cnt[i])ans+=n-pos;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		//printf("%d\n",pos);
		ans+=n-pos-1;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(n==100&&m==10)printf("%d\n",pos);
		ans+=n-pos-1;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> pii;
map<pii,int> mm;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		cnt[a-1]++;cnt[b-1]++;
		mm[make_pair(a-1,b-1)]++;
	}
	map<pii,int>::iterator it;
	for(it=mm.begin();it!=mm.end();it++)
	{
		int x=it->first.first;
		int y=it->first.second;
		int num=it->second;
		if(cnt[x]+cnt[y]>=m&&cnt[x]+cnt[y]+num<m)ans--;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(pos==i)ans+=n-pos-1;
		else if(cnt[pos]>=m-cnt[i])ans+=n-pos;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(n==100)printf("%d\n",pos);
		ans+=n-pos-1;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		cnt[a-1]++;cnt[b-1]++;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(n==100&&m==10)printf("%d\n",pos);
		if(cnt[pos]>=m-cnt[i])ans+=n-pos-1;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> pii;
map<pii,int> mm;
int cnt[300005]={0};
int sch(int l,int r,int num)
{
	if(l==r)return l;
	else
	{
		int mid=(l+r)/2;
		if(cnt[mid]>=num)return sch(l,mid,num);
		else return sch(mid+1,r,num);
	}
}
int main()
{
	int n,m;
	long long ans=0;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		cnt[a-1]++;cnt[b-1]++;
		mm[make_pair(a-1,b-1)]++;
	}
	map<pii,int>::iterator it;
	for(it=mm.begin();it!=mm.end();it++)
	{
		int x=it->first.first;
		int y=it->first.second;
		int num=it->second;
		if(cnt[x]+cnt[y]>=m&&cnt[x]+cnt[y]-num<m)ans--;
	}
	sort(cnt,cnt+n);
	for(int i=0;i<n;i++)
	{
		int pos=sch(i,n-1,m-cnt[i]);
		if(pos==i)ans+=n-pos-1;
		else if(cnt[pos]>=m-cnt[i])ans+=n-pos;
	}
	printf("%I64d\n",ans);
	return 0;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m;
int tree[350005];
int cnt[300005];
pair<int,int> p[300005];
long long sum(int x)
{
    int ans = 0;
    x = max(x,0);
    x++;
    while(x<=n+1000)
    {
        ans += tree[x];
        x += x&-x;
    }
    return ans;
}
void add(int x,int val)
{
    x++;
    x = max(x,0);
    while(x>0)
    {
        tree[x] += val;
        x -= x&-x;
    }
}
bool cmp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first) return true;
    return false;
}
main()
{
    int i,now,t;
    long long ans;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].first,&p[i].second);
        if(p[i].first>p[i].second) swap(p[i].first,p[i].second);
        cnt[p[i].first]++; cnt[p[i].second]++;
    }
    for(i=1;i<=n;i++) add(cnt[i],1);
    sort(&p[0],&p[n],cmp);
    ans = 0;
    now = 0;
    for(i=1;i<=n;i++)
    {
        add(cnt[i],-1);
        t = now;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second],-1); add(cnt[p[now].second]-1,1);
            now++;
        }
        ans += sum(m-cnt[i]);
        now = t;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second]-1,-1); add(cnt[p[now].second],1);
            now++;
        }
    }
    printf("%I64d",ans);
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m;
int tree[350005];
int cnt[300005];
pair<int,int> p[300005];
long long sum(int x)
{
    int ans = 0;
    x = max(x,0);
    x++;
    while(x<=n+1000)
    {
        ans += tree[x];
        x += x&-x;
    }
    return ans;
}
void add(int x,int val)
{
    x = max(x,0);
    x++;
    while(x>0)
    {
        tree[x] += val;
        x -= x&-x;
    }
}
bool cmp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first) return true;
    return false;
}
main()
{
    int i,now,t;
    long long ans;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].first,&p[i].second);
        if(p[i].first>p[i].second) swap(p[i].first,p[i].second);
        cnt[p[i].first]++; cnt[p[i].second]++;
    }
    for(i=1;i<=n;i++) add(cnt[i],1);
    sort(&p[0],&p[n],cmp);
    ans = 0;
    now = 0;
    for(i=1;i<=n;i++)
    {
        add(cnt[i],-1);
        t = now;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second],-1); add(--cnt[p[now].second],1);
            now++;
        }
        ans += sum(m-cnt[i]);
        now = t;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second],-1); add(++cnt[p[now].second],1);
            now++;
        }
    }
    printf("%I64d",ans);
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m;
int tree[350005];
int cnt[300005];
pair<int,int> p[300005];
long long sum(int x)
{
    int ans = 0;
    x = max(x,0);
    x++;
    while(x<=n+1000)
    {
        ans += tree[x];
        x += x&-x;
    }
    return ans;
}
void add(int x,int val)
{
    x = max(x,0);
    x++;
    while(x>0)
    {
        tree[x] += val;
        x -= x&-x;
    }
}
bool cmp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first) return true;
    return false;
}
main()
{
    int i,now,t;
    long long ans;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].first,&p[i].second);
        if(p[i].first>p[i].second) swap(p[i].first,p[i].second);
        cnt[p[i].first]++; cnt[p[i].second]++;
    }
    for(i=1;i<=n;i++) add(cnt[i],1);
    sort(&p[0],&p[n],cmp);
    ans = 0;
    now = 0;
    for(i=1;i<=n;i++)
    {
        add(cnt[i],-1);
        t = now;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second],-1); add(cnt[p[now].second]-1,1);
            now++;
        }
        ans += sum(m-cnt[i]);
        now = t;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second]-1,-1); add(cnt[p[now].second],1);
            now++;
        }
    }
    printf("%I64d",ans);
}


#include<stdio.h>
#include<algorithm>
using namespace std;
#define X first
#define Y second
int n,m;
int tree[350005];
int cnt[300005];
pair<int,int> p[300005];
int sum(int x)
{
    int ans = 0;
    x = max(x,0);
    x++;
    while(x<=n+1000)
    {
        ans += tree[x];
        x += x&-x;
    }
    return ans;
}
void add(int x,int val)
{
    x++;
    x = max(x,0);
    while(x>0)
    {
        tree[x] += val;
        x -= x&-x;
    }
}
bool cmp(pair<int,int> x,pair<int,int> y)
{
    if(x.X<y.X) return true;
    return false;
}
main()
{
    int i,now,t;
    long long ans;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].X,&p[i].Y);
        if(p[i].X>p[i].Y) swap(p[i].X,p[i].Y);
        cnt[p[i].X]++; cnt[p[i].Y]++;
    }
    for(i=1;i<=n;i++) add(cnt[i],1);
    sort(&p[0],&p[n],cmp);
    ans = 0;
    for(i=1;i<=n;i++)
    {
        add(cnt[i],-1);
        //printf("del %d\n",cnt[i]);
        t = now;
        while(p[now].X==i && now<n)
        {
            //printf("del %d\tadd %d\n",cnt[p[now].Y],cnt[p[now].Y]-1);
            add(cnt[p[now].Y],-1); add(cnt[p[now].Y]-1,1);
            now++;
        }
        ans += sum(m-cnt[i]);
        //printf("\t\tget %d [%d]\n",sum(m-cnt[i]),m-cnt[i]);
        now = t;
        while(p[now].X==i && now<n)
        {
            add(cnt[p[now].Y]-1,-1); add(cnt[p[now].Y],1);
            //printf("del %d\tadd %d\n",cnt[p[now].Y]-1,cnt[p[now].Y]);
            now++;
        }
    }
    printf("%I64d",ans);
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int n,m;
int tree[350005];
int cnt[300005];
pair<int,int> p[300005];
long long sum(int x)
{
    int ans = 0;
    x = max(x,0);
    x++;
    while(x<=n+1000)
    {
        ans += tree[x];
        x += x&-x;
    }
    return ans;
}
void add(int x,int val)
{
    x++;
    x = max(x,0);
    while(x>0)
    {
        tree[x] += val;
        x -= x&-x;
    }
}
bool cmp(pair<int,int> x,pair<int,int> y)
{
    if(x.first<y.first) return true;
    return false;
}
main()
{
    int i,now,t;
    long long ans;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&p[i].first,&p[i].second);
        if(p[i].first>p[i].second) swap(p[i].first,p[i].second);
        cnt[p[i].first]++; cnt[p[i].second]++;
    }
    for(i=1;i<=n;i++) add(cnt[i],1);
    sort(&p[0],&p[n],cmp);
    ans = 0;
    for(i=1;i<=n;i++)
    {
        add(cnt[i],-1);
        t = now;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second],-1); add(cnt[p[now].second]-1,1);
            now++;
        }
        ans += sum(m-cnt[i]);
        now = t;
        while(p[now].first==i && now<n)
        {
            add(cnt[p[now].second]-1,-1); add(cnt[p[now].second],1);
            now++;
        }
    }
    printf("%I64d",ans);
}


#include <bits/stdc++.h>
using namespace std;

const int N = 3e5+15;
int c[N],num[N];
map<pair<int,int>,int> H;
map<pair<int,int>,int>::iterator it;
int main(){
	int j,n,p,x,y,i;
	scanf("%d%d",&n,&p);
	for(i=0;i<n	;++i){
		scanf("%d%d",&x,&y),++c[x],++c[y];
		if(x>y)swap(x,y);
		++H[make_pair(x,y)];
	}
	long long ret=0;

	for(it= H.begin();it!=H.end();++it){
		x= it->first.first,y= it->first.second;
		if(c[x]+ c[y]>=p && c[x]+c[y]-it->second<p)--ret;
	}
	x=0,y=n;
	for(i=1;i<=n;++i)
		++num[c[i]];
	int tot=n;
	while(1){
		for(;y+x<p;++x)
			tot-=num[x];
		if(y<x)break;
		assert(num[y]<=tot);
		while(num[y])
			--tot,ret+= tot,--num[y];
		--y;
	}
	cout<<ret<<endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef pair <int, int> pii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> order_set;

#define N 300010

vector <int> v[N];
int c[N];

int main() {
    int n, p;
    scanf("%d%d", &n, &p);
    for(int i = 1; i <= n; i ++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if(x > y) swap(x, y);
        v[x].push_back(y);
        c[x] ++, c[y] ++;
    }
    long long ans = 0;
    order_set s;
    for(int i = 1; i <= n; i ++) s.insert(pii(c[i], i));
    for(int i = 1; i <= n; i ++) {
        s.erase(pii(c[i], i));
        for(auto j : v[i]) {
            s.erase(pii(c[j], j));
            c[j] --;
            s.insert(pii(c[j], j));
        }
        ans += s.size() - s.order_of_key(pii(p-c[i], 0));
        for(auto j : v[i]) {
            s.erase(pii(c[j], j));
            c[j] ++;
            s.insert(pii(c[j], j));
        }
    }
    cout << ans << endl;
}

                                                                                //hello


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef pair<int,int> Pii;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DBL;
typedef long double LDBL;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Pow2(a) ((a)*(a))

const int maxn = 3e5+10;
int N, P;
int vote[maxn];
int BIT[maxn];
vector<int> insus[maxn];

void addBit(int x){
	if(x==0) return;
	for(; x<=N; x+=x&-x)
		BIT[x]++;
}

int sumBit(int x){
	int res = 0;
	for(; x>0; x-=x&-x)
		res += BIT[x];
	return res;
}

int main()
{
	while(~scanf("%d%d", &N, &P)){
		CLR(vote);
		CLR(BIT);
		for(int i=1; i<=N; i++) insus[i].clear();
		for(int i=0,x,y; i<N; i++){
			scanf("%d%d", &x, &y);
			vote[x]++;
			vote[y]++;
			insus[min(x,y)].push_back(max(x,y));
		}
		LL ans=0;
		for(int i=N; i>=1; i--){
			if(vote[i]>=P){
				ans += N-i;
			}
			else{
				int left = P-vote[i];
				int cnt = sumBit(N-left+1);
				for(int t:insus[i]){
					if(vote[t] == left) cnt--;
					vote[t]--;
				} // minus same vote
				ans += cnt;
				for(int t:insus[i]) vote[t]++;
			}
			if(vote[i]) addBit(N-vote[i]+1);
		}
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(move(x)); return v; }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n'; err(++it, args...); }

typedef long long LL;
#define MAXN 300013
int N, P;
int X[MAXN], Y[MAXN];
map<pair<int, int>, int> m;
int h[MAXN];
int res[MAXN];
LL ans = 0;

int fenwick[MAXN];
int query(int i) {
	int ret = 0;
	// error(i);
	for (i++; i; i -= i & -i) {
		ret += fenwick[i];
	}
	return ret;
}

void update(int i) {
	for (i++; i < MAXN; i += i & -i) {
		fenwick[i]++;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	// freopen("input.txt", "r", stdin);

	cin >> N >> P;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		X[i]--; Y[i]--;
		if (X[i] > Y[i]) swap(X[i], Y[i]);
		h[X[i]]++;
		h[Y[i]]++;
		m[pair<int, int> {X[i], Y[i]}]++;
	}

	// sweepline
	for (int i = N - 1; i >= 0; i--) {
		res[i] = (N - 1) - i;
		if (P > h[i])
			res[i] -= query(P - h[i] - 1);
		update(h[i]);

		ans += res[i];
	}

	for (auto p : m) {
		int x = p.first.first;
		int y = p.first.second;
		int amt = p.second;
		if (h[x] + h[y] >= P && h[x] + h[y] - amt < P) {
			ans -= amt;
		}
	}

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


#include <bits/stdc++.h>
using namespace std;

#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }
vector<string> split(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(move(x)); return v; }
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) { cerr << it->substr((*it)[0] == ' ', it->length()) << " = " << a << '\n'; err(++it, args...); }

typedef long long LL;
#define MAXN 300013
int N, P;
int X[MAXN], Y[MAXN];
map<pair<int, int>, int> m;
int h[MAXN];
int res[MAXN];
LL ans = 0;

int fenwick[MAXN];
int query(int i) {
	int ret = 0;
	// error(i);
	for (i++; i; i -= i & -i) {
		ret += fenwick[i];
	}
	return ret;
}

void update(int i) {
	for (i++; i < MAXN; i += i & -i) {
		fenwick[i]++;
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	// freopen("input.txt", "r", stdin);

	cin >> N >> P;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		X[i]--; Y[i]--;
		if (X[i] > Y[i]) swap(X[i], Y[i]);
		h[X[i]]++;
		h[Y[i]]++;
		m[pair<int, int> {X[i], Y[i]}]++;
	}

	// sweepline
	for (int i = N - 1; i >= 0; i--) {
		res[i] = (N - 1) - i;
		if (P > h[i])
			res[i] -= query(P - h[i] - 1);
		update(h[i]);

		ans += res[i];
	}

	for (auto p : m) {
		int x = p.first.first;
		int y = p.first.second;
		int amt = p.second;
		if (h[x] + h[y] >= P && h[x] + h[y] - amt < P) {
			ans--;
		}
	}

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


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;
#define MAX 300002
int n;
int p;
map<pair<int, int>, int> mp;
int countt[MAX];
vector<int> v[MAX];
vector<long long int> vv;
int main(){
    scanf("%d%d", &n, &p);
    for (int i = 0; i < n; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        if (a > b){
            swap(a, b);
        }
        mp[make_pair(a, b)]++;
        countt[a]++;
        countt[b]++;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 0; i < n; i++){
        vv.push_back(countt[i]);
    }
    sort(vv.begin(), vv.end());
    long long int ans = 0;
    for (int i = 0; i < n; i++){
        long long int way = 0LL;
        for (int j = 0; j < v[i].size(); j++){
            int &b = v[i][j];
            if (countt[i] + countt[b] >= p){
                way--;
            }
            if (countt[i] + countt[b] - mp[make_pair(i, b)] >= p){
                way++;
            }
        }
        long long int need = p - countt[i];
        int ind = lower_bound(vv.begin(), vv.end(), need) - vv.begin();
        long long int k = vv.size() - ind;
        way += k;
        if (need <= countt[i]){
            way--;
        }
        ans += way;
    }
    ans /= 2LL;
    printf("%lld\n", ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;
#define MAX 300002
int n;
int p;
map<pair<int, int>, int> mp;
int countt[MAX];
vector<int> v[MAX];
vector<long long int> vv;
int main(){
    scanf("%d%d", &n, &p);
    for (int i = 0; i < n; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        if (a > b){
            swap(a, b);
        }
        mp[make_pair(a, b)]++;
        mp[make_pair(b, a)]++;
        countt[a]++;
        countt[b]++;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 0; i < n; i++){
        vv.push_back(countt[i]);
    }
    sort(vv.begin(), vv.end());
    long long int ans = 0;
    for (int i = 0; i < n; i++){
        long long int way = 0LL;
        for (int j = 0; j < v[i].size(); j++){
            int &b = v[i][j];
            if (countt[i] + countt[b] >= p){
                way--;
            }
            if (countt[i] + countt[b] - mp[make_pair(i, b)] >= p){
                way++;
            }
        }
        long long int need = p - countt[i];
        int ind = lower_bound(vv.begin(), vv.end(), need) - vv.begin();
        long long int k = vv.size() - ind;
        way += k;
        if (need <= countt[i]){
            way--;
        }
        ans += way;
    }
    ans /= 2LL;
    printf("%lld\n", ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
using namespace std;
#define MAX 300002
int n;
int p;
map<pair<int, int>, int> mp;
int countt[MAX];
vector<int> v[MAX];
vector<long long int> vv;
int main(){
    scanf("%d%d", &n, &p);
    for (int i = 0; i < n; i++){
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        if (a > b){
            swap(a, b);
        }
        mp[make_pair(a, b)]++;
        countt[a]++;
        countt[b]++;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for (int i = 0; i < n; i++){
        vv.push_back(countt[i]);
        sort(v[i].begin(), v[i].end());
        v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
    }
    sort(vv.begin(), vv.end());
    long long int ans = 0;
    for (int i = 0; i < n; i++){
        long long int way = 0LL;
        for (int j = 0; j < v[i].size(); j++){
            int &b = v[i][j];
            if (countt[i] + countt[b] >= p){
                way--;
            }
            if (countt[i] + countt[b] - mp[make_pair(min(i,b),max(i,b))] >= p){
                way++;
            }
        }
        long long int need = p - countt[i];
        int ind = lower_bound(vv.begin(), vv.end(), need) - vv.begin();
        long long int k = vv.size() - ind;
        way += k;
        if (need <= countt[i]){
            way--;
        }
        ans += way;
    }
    ans /= 2LL;
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, p; cin >> n >> p;
	vector<vi> g(n), gg(n);
	vi d(n);
	FOR (i, 1, n) {
		int x, y; cin >> x >> y;
		--x, --y;
		d[x]++, d[y]++;
		g[x].push_back(y), g[y].push_back(x);
	}
	ll ans = 0;
	FOR (i, 0, n - 1) sort(all(g[i]));
	FOR (i, 0, n - 1) {
		vi yo = g[i]; yo.erase(unique(all(yo)), yo.end());
		for (int j : yo) {
			int cnt = upper_bound(all(g[i]), j) - lower_bound(all(g[i]), j);
			gg[i].push_back(d[j] - cnt);
			ans += (d[i] + d[j] - cnt >= p);
		}
	}

	vi dd = d;
	sort(all(dd));

	FOR (i, 0, n - 1) {
		int can = dd.end() - lower_bound(all(dd), p - d[i]);
		int nn = gg[i].end() - lower_bound(all(gg[i]), p - d[i]);
		ans += can - nn;
		if (d[i] + d[i] >= p) --ans;
	}

	cout << ans/2 << "\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define FOR(i,a,b) for (int i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(int i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
typedef long long ll; typedef pair <int, int> ii; typedef vector <int> vi; const int inf = 1e9 + 7;
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cout << str << " : " << t << endl;}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cout << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cout << "["; for (T i = a; i != b; ++i) {if (i != a) cout << ", "; cout << *i;} cout << "]";cout<<endl;}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);

	int n, p; cin >> n >> p;
	vector<vi> g(n), gg(n);
	vi d(n);
	FOR (i, 1, n) {
		int x, y; cin >> x >> y;
		--x, --y;
		d[x]++, d[y]++;
		g[x].push_back(y), g[y].push_back(x);
	}
	ll ans = 0;
	FOR (i, 0, n - 1) sort(all(g[i]));
	FOR (i, 0, n - 1) {
		vi yo = g[i]; yo.erase(unique(all(yo)), yo.end());
		for (int j : yo) {
			int cnt = upper_bound(all(g[i]), j) - lower_bound(all(g[i]), j);
			gg[i].push_back(d[j]);
			ans += (d[i] + d[j] - cnt >= p);
		}
		sort(all(gg[i]));
	}

	vi dd = d;
	sort(all(dd));

	FOR (i, 0, n - 1) {
		int can = dd.end() - lower_bound(all(dd), p - d[i]);
		int nn = gg[i].end() - lower_bound(all(gg[i]), p - d[i]);
		ans += can - nn;
		if (d[i] + d[i] >= p) --ans;
	}

	cout << ans/2 << "\n";

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 3e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, p, fen[maxn], d[maxn];
map<pii, int> cnt;
vi graph[maxn];
ll ans;

void update(int ind, int val)
{
	for (ind++; ind < maxn; ind += (ind & (-ind)))
		fen[ind] += val;
}

int query(int ind)
{
	int sum = 0;
	for (ind++; ind; ind -= (ind & (-ind)))
		sum += fen[ind];
	return sum;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> p;
	int u, v;
	fori (i, 0, n)
	{
		cin >> u >> v;
		u--;
		v--;
		cnt[mp(u, v)]++;
		cnt[mp(v, u)]++;
		d[u]++;
		d[v]++;
	}
	for (pair<pii, int> i : cnt)
		graph[i.ff.ff].pb(i.ff.ss);
	fori (i, 0, n)
		update(d[i], 1);
	fori (i, 0, n)
	{
		for (int j : graph[i])
		{
			ans += (d[i] + d[j] - cnt[mp(i, j)] >= p);
			update(d[j], -1);
		}
		update(d[i], -1);
		ans += (query(maxn - 2) - (p - d[i] - 1 >= 0 ? query(p - d[i] - 1) : 0));
		update(d[i], 1);
		for (int j : graph[i])
			update(d[j], 1);
	}
	cout << ans / 2 << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(), v.end()
#define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
#define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
#define lchild(ind) 2 * ind + 1
#define rchild(ind) 2 * ind + 2
#define bug(val) cout << "# " << val << endl;
#define bugs(val) cout << '_' << val;
#define bugl(val) cout << "## " << val << endl;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
typedef pair<ll, pll> plp;
typedef pair<pll, int> ppi;
typedef pair<pll, ll> ppl;
typedef pair<pll, pll> ppp;
typedef vector<int> vi;
typedef vector<ll> vll;

const int maxn = 3e5 + 10;
const ll inf = 2e18, mod = 1e9 + 7;

int n, p, fen[maxn], d[maxn];
map<pii, int> cnt;
vi graph[maxn];
ll ans;

void update(int ind, int val)
{
	for (ind++; ind < maxn; ind += (ind & (-ind)))
		fen[ind] += val;
}

int query(int ind)
{
	int sum = 0;
	for (ind++; ind; ind -= (ind & (-ind)))
		sum += fen[ind];
	return sum;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> p;
	int u, v;
	fori (i, 0, n)
	{
		cin >> u >> v;
		u--;
		v--;
		cnt[mp(u, v)]++;
		cnt[mp(v, u)]++;
		d[u]++;
		d[v]++;
	}
	for (pair<pii, int> i : cnt)
	{
		graph[i.ff.ff].pb(i.ff.ss);
		graph[i.ff.ss].pb(i.ff.ff);
	}
	fori (i, 0, n)
		update(d[i], 1);
	fori (i, 0, n)
	{
		for (int j : graph[i])
		{
			ans += (d[i] + d[j] - cnt[mp(i, j)] >= p);
			update(d[j], -1);
		}
		update(d[i], -1);
		ans += (query(maxn - 2) - (p - d[i] - 1 >= 0 ? query(p - d[i] - 1) : 0));
		update(d[i], 1);
		for (int j : graph[i])
			update(d[j], 1);
	}
	cout << ans / 2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    int num=degrees.size();
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        if(num-pos>0)
        {
            sol+=1LL*(num-pos);
        if(degree[i]>=more)sol--;
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(u>v)swap(u,v);
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
                sol--;
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    int num=degrees.size();
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        if(num-pos>0)sol+=1LL*(num-pos);
        if(degree[i]>=more)sol--;
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(u>v)swap(u,v);
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
                sol--;
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[2*100010];
vector<int> degrees;
map<pair<int,int>,int> memo;
int degree[2*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        int num=degrees.size();
        if(num-more>0)sol+=1LL*(num-pos);
        if(degree[i]>=more)sol--;
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(u>v)swap(u,v);
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
            {
                sol--;
            }
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees,deg;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
        memo[make_pair(y,x)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    int num=degrees.size();
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        if(num-pos>0)
        {
            sol+=1LL*(num-pos);
            if(degree[i]>=more)sol--;
        }
    }
    for(int i=0; i<n; i++)
    {
        sort( graf[i].begin(), graf[i].end() );
        graf[i].erase( unique( graf[i].begin(), graf[i].end() ), graf[i].end() );
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
                sol--;
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees,deg;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
        memo[make_pair(y,x)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    int num=degrees.size();
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        if(num-pos>0)
        {
            sol+=1LL*(num-pos);
            if(degree[i]>=more)sol--;
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
                sol--;
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees,deg;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
        memo[make_pair(y,x)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    int num=degrees.size();
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        if(num-pos>0)
        {
            sol+=1LL*(num-pos);
            if(degree[i]>=more)sol--;
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(u>v)swap(u,v);
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
                sol--;
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[2*100010];
vector<int> degrees[2*100010];
map<pair<int,int>,int> memo;
int degree[2*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
    }
    long long sol=0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
            degrees[i].push_back(degree[graf[i][j]]);
        sort(degrees[i].begin(),degrees[i].end());
      //  for(int j=0;j<degrees[i].size();j++)
     //       printf("%d ",degrees[i][j]);
     //   printf("\n");
        int more=p-degree[i];
        int pos=lower_bound(degrees[i].begin(),degrees[i].end(),more)-degrees[i].begin();
        int num=degrees[i].size();
        if(num-more+1>0)sol+=1LL*(num-more+1);
     //   printf("SOL: %d %d %d=> %lld\n",pos,degrees[i].size(),more,sol);
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)sol--;
        }
   }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
vector<int> graf[5*100010];
vector<int> degrees;
map<pair<int,int>,int> memo;
int degree[5*100010];
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    for(int i=0; i<n; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(x>y)swap(x,y);
        x--;
        y--;
        graf[x].push_back(y);
        graf[y].push_back(x);
        degree[x]++;
        degree[y]++;
        memo[make_pair(x,y)]++;
    }
    for(int i=0; i<n; i++)
        degrees.push_back(degree[i]);
    sort(degrees.begin(),degrees.end());
    long long sol=0;
    for(int i=0; i<n; i++)
    {
        int more=p-degree[i];
        int pos=lower_bound(degrees.begin(),degrees.end(),more)-degrees.begin();
        int num=degrees.size();
        if(num-more>0)sol+=1LL*(num-pos);
        if(degree[i]>=more)sol--;
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<graf[i].size(); j++)
        {
            int u=i,v=graf[i][j];
            if(u>v)swap(u,v);
            if(degree[u]+degree[v]>=p&&degree[u]+degree[v]-memo[make_pair(u,v)]<p)
            {
                sol--;
            }
        }
    }
    printf("%lld\n",sol/2LL);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=3e5+5;
int n,p,a[N],b[N],c;
long long ans;
struct rec{
	int x,y;
}f[N],t;

bool cmp(rec a,rec b){
	return(a.x<b.x||a.x==b.x&&a.y<b.y);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>p;
	for(int i=1;i<=n;++i){
		cin>>f[i].x>>f[i].y;
		a[f[i].x]++,a[f[i].y]++;
	}
	for(int i=1;i<=n;++i)b[i]=a[i];
	sort(a+1,a+n+1);
	int x=n;
	for(int i=1;i<=n;++i)
		if(a[i]>=p)ans+=(n-1);
		else{
			while(a[x]+a[i]>=p)--x;
			if(x>=i)ans+=(n-x);else ans+=(n-x-1);
		}
	ans>>=1;
	sort(f+1,f+n+1,cmp);
	for(int i=1;i<=n;++i)
		if(f[i].x==t.x&&f[i].y==t.y)++c;
		else{
			if(b[t.x]+b[t.y]>=p&&b[t.x]+b[t.y]-c<p)--ans;
			t=f[i];c=1;
		}
	if(b[t.x]+b[t.y]>=p&&b[t.x]+b[t.y]-c<p)--ans;
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=3e5+5;
int n,p,a[N],b[N],c;
long long ans;
struct rec{
	int x,y;
}f[N],t;

bool cmp(rec a,rec b){
	return(a.x<b.x||a.x==b.x&&a.y<b.y);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>p;
	for(int i=1;i<=n;++i){
		cin>>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;
		}
		a[f[i].x]++,a[f[i].y]++;
	}
	for(int i=1;i<=n;++i)b[i]=a[i];
	sort(a+1,a+n+1);
	int x=n;
	for(int i=1;i<=n;++i)
		if(a[i]>=p)ans+=(n-1);
		else{
			while(a[x]+a[i]>=p)--x;
			if(a[x+1]+a[i]>=p){
				if(a[x+1]>a[i])ans+=(n-x);else ans+=(n-x-1);
			}
		}
	ans>>=1;
	sort(f+1,f+n+1,cmp);
	for(int i=1;i<=n;++i)
		if(f[i].x==t.x&&f[i].y==t.y)++c;
		else{
			if(t.x&&b[t.x]+b[t.y]>=p&&b[t.x]&&b[t.x]+b[t.y]-c<p)--ans;
			t=f[i];c=1;
		}
	if(b[t.x]+b[t.y]>=p&&b[t.x]&&b[t.x]+b[t.y]-c<p)--ans;
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=3e5+5;
int n,p,a[N],b[N],c;
long long ans;
struct rec{
	int x,y;
}f[N],t;

bool cmp(rec a,rec b){
	return(a.x<b.x||a.x==b.x&&a.y<b.y);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>p;
	for(int i=1;i<=n;++i){
		cin>>f[i].x>>f[i].y;
		a[f[i].x]++,a[f[i].y]++;
	}
	for(int i=1;i<=n;++i)b[i]=a[i];
	sort(a+1,a+n+1);
	int x=n;
	for(int i=1;i<=n;++i)
		if(a[i]>=p)ans+=(n-1);
		else{
			while(a[x]+a[i]>=p)--x;
			if(x>=i)ans+=(n-x);else ans+=(n-x-1);
		}
	ans>>=1;
	sort(f+1,f+n+1,cmp);
	for(int i=1;i<=n;++i)
		if(f[i].x==t.x&&f[i].y==t.y)++c;
		else{
			if(t.x&&b[t.x]&&b[t.x]+b[t.y]>=p&&b[t.x]+b[t.y]-c<p)--ans;
			t=f[i];c=1;
		}
	if(t.x&&b[t.x]&&b[t.x]+b[t.y]>=p&&b[t.x]+b[t.y]-c<p)--ans;
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N=3e5+5;
int n,p,a[N],b[N],c;
long long ans;
struct rec{
	int x,y;
}f[N],t;

bool cmp(rec a,rec b){
	return(a.x<b.x||a.x==b.x&&a.y<b.y);
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>p;
	for(int i=1;i<=n;++i){
		cin>>f[i].x>>f[i].y;
		a[f[i].x]++,a[f[i].y]++;
	}
	for(int i=1;i<=n;++i)b[i]=a[i];
	sort(a+1,a+n+1);
	int x=n;
	for(int i=1;i<=n;++i)
		if(a[i]>=p)ans+=(n-1);
		else{
			while(a[x]+a[i]>=p)--x;
			if(a[x+1]+a[i]>=p){
				if(a[x+1]>a[i])ans+=(n-x);else ans+=(n-x-1);
			}
		}
	ans>>=1;
	sort(f+1,f+n+1,cmp);
	for(int i=1;i<=n;++i)
		if(f[i].x==t.x&&f[i].y==t.y)++c;
		else{
			if(t.x&&b[t.x]+b[t.y]>=p&&b[t.x]&&b[t.x]+b[t.y]-c<p)--ans;
			t=f[i];c=1;
		}
	if(b[t.x]+b[t.y]>=p&&b[t.x]&&b[t.x]+b[t.y]-c<p)--ans;
	cout<<ans<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300000 + 10;
int lowbit(int x){
    return x & -x;
}
int bit[N];
int sum(int x){
    if(x<0) return 0;
    x++;
    int r = 0;
    while(x) r += bit[x], x -= lowbit(x);
    return r;
}
void add(int x,int v){
    x++;
    while(x<N) bit[x] += v, x += lowbit(x);
}
vector<int> g[N];
int d[N];
int main(){
    ios::sync_with_stdio(0);
    int n,p; cin>>n>>p;
    for(int i=1;i<=n;i++){
        int u,v; cin>>u>>v;
        d[u]++, d[v]++;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i=1;i<=n;i++) add(d[i],1);
    ll ans = 0;
    for(int i=1;i<=n;i++){
        for(int j: g[i]) add(d[j],-1), add(d[j]-1,1), d[j]--;
        add(d[i],-1);
        ans += sum(n) - sum(max(p-d[i]-1,-1));
        add(d[i],+1);
        for(int j: g[i]) add(d[j],-1), add(d[j]+1,1), d[j]++;
    }
    cout<<ans/2<<endl;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;

int N, P;
vector<vector<int> > adj;
vector<vector<pii> > adj2;
vector<pii> D;
int main() {
	scanf("%d %d", &N, &P);
	adj.resize(N);
	for(int i = 0; i < N; i++) {
		int x, y; scanf("%d %d", &x, &y);
		x--; y--;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	adj2.resize(N);
	for(int i = 0; i < N; i++) {
		sort(adj[i].begin(), adj[i].end());
		int bf = -1, cnt;
		for(int j = 0; j < adj[i].size(); j++) {
			if(bf != adj[i][j]) {
				if(bf != -1) adj2[i].push_back(pii(bf, cnt));
				cnt = 1;
				bf = adj[i][j];
			}
			else cnt++;
		}
		if(bf != -1) adj2[i].push_back(pii(bf, cnt));

		D.push_back(pii((int)adj[i].size(), i));
	}
	sort(D.begin(), D.end());
/*
	for(int i = 0; i < N; i++) {
		cout << D[i].first << ' ';
	}
	cout << endl;
	for(int i = 0; i < N; i++) {
		for(int j = 0; j < adj2[i].size(); j++) {
			cout << adj2[i][j].first << ' ' << adj2[i][j].second << endl;
		}
	}
//*/
	ll ans = 0;
	for(int i = 0; i < N; i++) {
		int d = adj[i].size();
		int s = 0, e = N - 1;
		int idx = -1;
		while(s <= e) {
			int m = (s + e)>>1;
			if(D[m].first + d >= P) {
				idx = m;
				e = m - 1;
			}
			else s = m + 1;
		}
		if(idx == -1) continue;
		ans += (ll)(N - idx);
		if(2*d >= P) ans--;

		for(int j = 0; j < adj2[i].size(); j++) {
			int k = adj2[i][j].first;
			int d = adj2[i][j].second;
			int t = adj[i].size() + adj[k].size();
			if(P <= t && t < P + d) {
				ans--;
			}
		}
	}
	printf("%I64d", ans/2);
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];
long long st2[4*3*(int)1e5 + 10];
int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}
vector<int> choose[3*(int)1e5 + 10];

void update(int p , int l , int r , int idx, int val)
{
	if(l == r)
	{
		st[p] = st[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx,val);
		}else
		{
			update(right(p),mid + 1 , r , idx,val);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}

long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
void update2(int p , int l , int r , int idx , int val)
{
	if(l == r)
	{
		st2[p] = st2[p] + val;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update2(left(p),l,mid,idx,val);
		}else
		{
			update2(right(p),mid + 1 , r , idx,val);
		}
		st2[p] = st2[left(p)] + st2[right(p)];
	}
}

long long query2(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st2[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query2(left(p), l, (l + r)/2 , i , j) + query2(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}
int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	memset(st2,0,sizeof st2);
	pair<int,int> arr[3*(int)1e5 + 10];
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		choose[one].push_back(i + 1);
		choose[two].push_back(i + 1);
		arr[i+1] = make_pair(one,two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		update2(1,0,n,cnt[i],1);
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	// cout << query2(1,0,n,3,n) << " QQ\n";
	bool updated[3*(int)1e5 + 10];
	memset(updated, 0 , sizeof updated);
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		int s = choose[i].size();
		for(int j = 0 ; j < s ;j++)
		{
			int two = (arr[choose[i][j]].first == i) ?arr[choose[i][j]].second : arr[choose[i][j]].first;
			// cout << i << " " << two << " TWO\n";
			// cout << i << " " <<  two << " " << cnt[two] << " MALAK\n";
			update2(1,0,n,cnt[two],- 1);
			update2(1,0,n,cnt[two] - 1,1);
			if(two < i && updated[two])
			{
				update(1,0,n,cnt[two],- 1);
				update(1,0,n,cnt[two] - 1,1);
			}
			cnt[two]--;

		}
		long long number = query2(1,0,n,req,n);
		// cout << i << " " << number << " " << cnt[3] << " " << cnt[1] << " " << cnt[4] << endl;

		// long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		for(int j = 0 ; j < s ;j++)
		{
			int two = (arr[choose[i][j]].first == i) ?arr[choose[i][j]].second : arr[choose[i][j]].first;
			cnt[two]++;
			update2(1,0,n,cnt[two],1);
			update2(1,0,n,cnt[two] - 1,-1);
			if(two < i && updated[two])
			{
				update(1,0,n,cnt[two],1);
				update(1,0,n,cnt[two] - 1,-1);
			}
		}
		// cout << number << " " << cnt[i] << " " << req << " " << calc << endl;
		if(number - (cnt[i] >= req) - calc <= 0)
			continue;
		updated[i] = 1;
		total += number - (cnt[i] >= req) - calc;
		update(1,0,n,cnt[i],1);
	}
	cout << total << endl;
}


#include <bits/stdc++.h>

using namespace std;
long long cnt[3*(int)1e5 + 10];
long long numcnt[3*(int)1e5 + 10];
long long st[4*3*(int)1e5 + 10];

int left(int p){return (p << 1);}
int right(int p){return (p << 1)|1;}

void update(int p , int l , int r , int idx)
{
	if(l == r)
	{
		if(l == idx)
			st[p] = st[p] + 1;
	}else
	{
		int mid = (l + r)/2;
		if(mid >= idx)
		{
			update(left(p),l,mid,idx);
		}else
		{
			update(right(p),mid + 1 , r , idx);
		}
		st[p] = st[left(p)] + st[right(p)];
	}
}
long long query(int p ,int l , int r , int i ,int j)
{
	if(l >= i && r <= j)
	{
		return st[p];
	}else if(l > j || r < i)
	{
		return 0;
	}else
	{
		return query(left(p), l, (l + r)/2 , i , j) + query(right(p),(l+r)/2 + 1 ,r , i , j);
	}
}

int main()
{
	long long n , p;
	scanf("%lld %lld",&n,&p);
	memset(st , 0, sizeof st);
	memset(cnt,0,sizeof cnt);
	memset(numcnt,0,sizeof numcnt);
	for(int i = 0 ; i < n ; i++)
	{
		int one,two;
		scanf("%d %d",&one,&two);
		cnt[one]++;
		cnt[two]++;
	}
	for(int i = 1; i <= n ;i++)
	{
		numcnt[cnt[i]]++;
	}
	long long cummsum[3*(int)1e5 + 10];
	cummsum[0] = numcnt[0];
	for(int i= 1; i <= n ;i++)
	{
		cummsum[i] = cummsum[i - 1] + numcnt[i];
	}
	long long total = 0;
	for(int i = 1; i <= n ; i++)
	{
		long long c = cnt[i];
		long long req = max(p  - c,0LL);
		long long sub = (req > 0)? cummsum[req-1]:0;
		long long number = cummsum[n] - sub;
		long long calc = query(1,0,n,req,n);
		if(number - 1 - calc <= 0)
			continue;
		total += number - (cnt[i] >= req) - calc;
		update(1,0,n,cnt[i]);
	}
	cout << total << endl;
}