import java.util.Scanner;
class Main{
	public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	}
} Main public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(sc.hasNext()){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		} sc.hasNext() sc.hasNext sc {
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc if(n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int count = 0; count 0 for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			} {
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			} for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				} int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				} {
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				} for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					} int k = 1; int k = 1; k 1 k <= n k n k++ k++ k {
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					} {
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					} if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						} i + j + k == x && i != j
								&& j != k && i != k j != k i + j + k == x && i != j
								&& j != k && i != k i + j + k == x i + j + k i + j + k i j k x i != j i j j != k j k i != k i k {
							count++;
						} count++ count System.out.println(count/6) System.out.println System.out System System.out count/6 count 6 String[]agrs agrs
import java.util.Scanner;
class Main{
	public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int x = sc.nextInt();
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n; i++){
				for(int j = 1; j <= n; j++){
					for(int k = 1; k <= n; k++){
						if(i + j + k == x && i != j
								&& j != k && i != k){
							count++;
						}
					}
				}
			}
			System.out.println(count/6);
		}
	}
}