import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
} Main public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	} main {
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	} Scanner scan = null; scan null try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		} {
			if(scan !=null)scan.close();
		} if(scan !=null)scan.close(); scan !=null scan null scan.close() scan.close scan {
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		} scan = new Scanner(System.in) scan new Scanner(System.in) while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			} true {
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan if(n == 0 && x == 0 )break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int counter =0; counter 0 for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				} int i = 1 ; int i = 1 ; i 1 i <= n i n i++ i++ i {
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				} {
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				} for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					} int j = i +1 ; int j = i +1 ; j i +1 i 1 j <= n j n j++ j++ j {
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					} {
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					} for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						} int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k++ k++ k {
							if(i + j + k == x)counter++;
						} {
							if(i + j + k == x)counter++;
						} if(i + j + k == x)counter++; i + j + k == x i + j + k i + j + k i j k x counter++ counter System.out.println(counter) System.out.println System.out System System.out counter String[] args args public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
} public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = null;
		try{
			scan = new Scanner(System.in);
			while(true){
				int n = scan.nextInt();
				int x = scan.nextInt();
				if(n == 0 && x == 0 )break;
				int counter =0;
				for(int i = 1 ;i <= n;i++){
					for(int j = i +1 ; j <= n ; j++){
						for(int k = j + 1; k <= n ; k++){
							if(i + j + k == x)counter++;
						}
					}
				}
				System.out.println(counter);
			}
		}finally{
			if(scan !=null)scan.close();
		}
	}
}