

import java.util.Scanner;


public class Main{

	public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	}


} import java.util.Scanner; Scanner java.util public class Main{

	public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	}


} Main public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	} Clc {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	} int count = 0; count 0 for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		} int x = 1; int x = 1; x 1 x <= N x N x++ x++ x {
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		} {
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		} for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			} int y = x+1; int y = x+1; y x+1 x 1 y <= N y N y++ y++ y {
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			} {
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			} if(x==y){break;} x==y x y {break;} break; for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				} int z =y+1 ; int z =y+1 ; z y+1 y 1 z <= N z N z++ z++ z {
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				} {
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				} if(x==z || y == z){break;} x==z || y == z x==z x z y == z y z {break;} break; if((x+y+z)==X){count++;} (x+y+z)==X (x+y+z) x+y+z x y z X {count++;} count++ count return count; count int N N int X X public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int count = 0; count 0 while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		} true {
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		} int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int X = scanner.nextInt(); X scanner.nextInt() scanner.nextInt scanner if(N == 0 && X == 0){break;} N == 0 && X == 0 N == 0 N 0 X == 0 X 0 {break;} break; count = Clc(N, X) count Clc(N, X) Clc N X System.out.println(count) System.out.println System.out System System.out count scanner.close() scanner.close scanner String[] args args public class Main{

	public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	}


} public class Main{

	public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	}


} Main


import java.util.Scanner;


public class Main{

	public static int  Clc(int N , int X) {
		int count = 0;
		for(int x = 1; x <= N ; x++){
			for(int y = x+1; y <= N ; y++){
				if(x==y){break;}
				for(int z =y+1 ; z <= N ; z++){
					if(x==z || y == z){break;}
						if((x+y+z)==X){count++;}
				}
			}
		}

		return count;


	}

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int count = 0;

		while(true){
			int N = scanner.nextInt();
			int X = scanner.nextInt();
			if(N == 0 && X == 0){break;}
			count = Clc(N, X);
			System.out.println(count);
		}
		scanner.close();
	}


}