import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}

 import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
} Main public static final int BIG_NUM  = 2000000000; BIG_NUM 2000000000 public static final int MOD  = 1000000007; MOD 1000000007 public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String buffer[] = new String[2]; buffer new String[2] 2 int N N X X ans; ans while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		} true {

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		} try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} IOException e {
				e.printStackTrace();
			} e.printStackTrace() e.printStackTrace e {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} buffer = br.readLine().split("\\s+") buffer br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" N = Integer.parseInt(buffer[0]) N Integer.parseInt(buffer[0]) Integer.parseInt Integer buffer[0] buffer 0 X = Integer.parseInt(buffer[1]) X Integer.parseInt(buffer[1]) Integer.parseInt Integer buffer[1] buffer 1 if(N == 0 && X == 0)break; N == 0 && X == 0 N == 0 N 0 X == 0 X 0 break; ans = 0 ans 0 for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				} int a = 1; int a = 1; a 1 a <= N-2 a N-2 N 2 a++ a++ a {
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				} {
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				} for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					} int b = a+1; int b = a+1; b a+1 a 1 b <= N-1 b N-1 N 1 b++ b++ b {
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					} {
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					} for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						} int c = b+1; int c = b+1; c b+1 b 1 c <= N c N c++ c++ c {
							if(a+b+c == X){
								ans++;
							}
						} {
							if(a+b+c == X){
								ans++;
							}
						} if(a+b+c == X){
								ans++;
							} a+b+c == X a+b+c a+b+c a b c X {
								ans++;
							} ans++ ans System.out.printf("%d\n", ans) System.out.printf System.out System System.out "%d\n" ans String[] args args public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
} public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buffer[] = new String[2];
		int N,X,ans;

		while(true){

			try {
				buffer = br.readLine().split("\\s+");
				N = Integer.parseInt(buffer[0]);
				X = Integer.parseInt(buffer[1]);

				if(N == 0 && X == 0)break;

				ans = 0;

				for(int a = 1; a <= N-2; a++){
					for(int b = a+1; b <= N-1; b++){
						for(int c = b+1; c <= N; c++){
							if(a+b+c == X){
								ans++;
							}
						}
					}
				}

				System.out.printf("%d\n", ans);

			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


