import java.util.Scanner;

public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	}
	public static void main(String[] args) {
	
		new Main().run();
		
	}
} import java.util.Scanner; Scanner java.util public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	}
	public static void main(String[] args) {
	
		new Main().run();
		
	}
} Main void run(){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	} run {
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		} true {
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		} int n = s.nextInt(); n s.nextInt() s.nextInt s int x = s.nextInt(); x s.nextInt() s.nextInt s if(n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int sum = 0; sum 0 int count = 0; count 0 int a = 0; a 0 int num[] = new int [n]; num new int [n] n for(int i = 0; i < n; i++) num[i] = i + 1; int i = 0; int i = 0; i 0 i < n i n i++ i++ i num[i] = i + 1; num[i] = i + 1 num[i] num i i + 1 i 1 for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			} int i = a; int i = a; i a i < n i n i++ i++ i {
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			} {
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			} for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				} 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++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				} {
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				} for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					} int k = j+1; int k = j+1; k j+1 j 1 k < n k n k++ k++ k {
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					} {
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					} sum = num[i] + num[j] + num[k] sum num[i] + num[j] + num[k] num[i] + num[j] + num[k] num[i] num i num[j] num j num[k] num k if(sum == x){
							count++;
						} sum == x sum x {
							count++;
						} count++ count a++ a System.out.println(count) System.out.println System.out System System.out count public static void main(String[] args) {
	
		new Main().run();
		
	} main {
	
		new Main().run();
		
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	}
	public static void main(String[] args) {
	
		new Main().run();
		
	}
} public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	}
	public static void main(String[] args) {
	
		new Main().run();
		
	}
} Main
import java.util.Scanner;

public class Main {
	void run(){
		Scanner s = new Scanner(System.in);
		while(true){
			int n = s.nextInt();
			int x = s.nextInt();
			if(n == 0 && x == 0) break;
			int sum = 0;
			int count = 0;
			int a = 0;
			int num[] = new int [n];
			for(int i = 0; i < n; i++) num[i] = i + 1;
			for(int i = a; i < n; i++){
				for(int j = i+1; j < n; j++){
					for(int k = j+1; k < n; k++){
						sum = num[i] + num[j] + num[k];
						if(sum == x){
							count++;
						}
						a++;
					}
				}
			}
			System.out.println(count);
		}
	}
	public static void main(String[] args) {
	
		new Main().run();
		
	}
}