import java.io.*;

class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		}catch (Exception e){
		}
	}
}
				 import java.io.*; io.* java class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		}catch (Exception e){
		}
	}
} Main public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		}catch (Exception e){
		}
	} main {
		try{
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		}catch (Exception e){
		}
	} try{
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		}catch (Exception e){
		} catch (Exception e){
		} Exception e {
		} {
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		} BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); br new BufferedReader( new InputStreamReader(System.in)) int n n x; x while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			} true {
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			} String buf = br.readLine(); buf br.readLine() br.readLine br String[] line = buf.split(" "); line buf.split(" ") buf.split buf " " n = Integer.parseInt(line[0]) n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 x = Integer.parseInt(line[1]) x Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 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-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			} int i= 1; int i= 1; i 1 i <= n-2 i n-2 n 2 i++ i++ i {
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			} {
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			} for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				} int j = i+1; int j = i+1; j i+1 i 1 j <=n-1 j n-1 n 1 j++ j++ j {
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				} {
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				} for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					} 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){
							count += 1;
						}
					} {
						if(i + j + k == x){
							count += 1;
						}
					} if(i + j + k == x){
							count += 1;
						} i + j + k == x i + j + k i + j + k i j k x {
							count += 1;
						} count += 1 count 1 System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.*;

class Main {
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader( new InputStreamReader(System.in));
			int n, x;
			while(true){
				String buf = br.readLine();
				String[] line = buf.split(" ");
				n = Integer.parseInt(line[0]);
				x = Integer.parseInt(line[1]);
				if(n == 0 && x == 0)break;
			

			int count = 0;
			for(int i= 1;i <= n-2;i++){
				for(int j = i+1; j <=n-1;j++){
					for(int k = j+1; k <=n;k++){
						if(i + j + k == x){
							count += 1;
						}
					}
				}
			}
			System.out.println(count);
			}
		}catch (Exception e){
		}
	}
}
				