import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		}

	}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		}

	}

} Main public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		}

	} main {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		} ; {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		} {
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan int tmp = 0; tmp 0 if(n == 0 && x == 0)
				break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			} int i=1; int i=1; i 1 i<n i n i++ i++ i {
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			} {
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			} for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				} int s=i+1; int s=i+1; s i+1 i 1 s<n s n s++ s++ s {
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				} {
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				} for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					} int t=s+1; int t=s+1; t s+1 s 1 t<=n t n t++ t++ t {
						if(i + s + t == x)
							tmp++;
					} {
						if(i + s + t == x)
							tmp++;
					} if(i + s + t == x)
							tmp++; i + s + t == x i + s + t i + s + t i s t x tmp++ tmp System.out.println(tmp) System.out.println System.out System System.out tmp String[] args args
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			int tmp = 0;

			if(n == 0 && x == 0)
				break;

			for(int i=1; i<n; i++){
				for(int s=i+1; s<n; s++){
					for(int t=s+1; t<=n; t++){
						if(i + s + t == x)
							tmp++;
					}
				}
			}
			System.out.println(tmp);

		}

	}

}