import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = new String[2];
		int in[] = new int[2];
		int cnt;
		while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
} import java.io.*; io.* java class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = new String[2];
		int in[] = new int[2];
		int cnt;
		while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
} Main public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = new String[2];
		int in[] = new int[2];
		int cnt;
		while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = new String[2];
		int in[] = new int[2];
		int cnt;
		while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str[] = new String[2]; str new String[2] 2 int in[] = new int[2]; in new int[2] 2 int cnt; cnt while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		} true {
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		} str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " in = parseInts(str) in parseInts(str) parseInts str if(in[0]==0 && in[1]==0) break; in[0]==0 && in[1]==0 in[0]==0 in[0] in 0 0 in[1]==0 in[1] in 1 0 break; cnt = 0 cnt 0 for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			} int n=1; int n=1; n 1 n<in[0]-1 n in[0]-1 in[0] in 0 1 n++ n++ n {
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			} {
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			} for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				} int m=n+1; int m=n+1; m n+1 n 1 m<in[0] m in[0] in 0 m++ m++ m {
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				} {
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				} for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					} int l=m+1; int l=m+1; l m+1 m 1 l<=in[0] l in[0] in 0 l++ l++ l {
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					} {
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					} if(n+m+l==in[1]){
							cnt = cnt + 1;
						} n+m+l==in[1] n+m+l n+m+l n m l in[1] in 1 {
							cnt = cnt + 1;
						} cnt = cnt + 1 cnt cnt + 1 cnt 1 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	} parseInts {
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	} int[] x = new int[s.length]; x new int[s.length] s.length s s.length for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		} int i=0; int i=0; i 0 i<s.length i s.length s s.length i++ i++ i {
			x[i] = Integer.parseInt(s[i]);
		} {
			x[i] = Integer.parseInt(s[i]);
		} x[i] = Integer.parseInt(s[i]) x[i] x i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i return x; x String[] s s
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str[] = new String[2];
		int in[] = new int[2];
		int cnt;
		while(true){
			str = br.readLine().split(" ");
			in = parseInts(str);
			if(in[0]==0 && in[1]==0) break;
			cnt = 0;
			for(int n=1; n<in[0]-1; n++){
				for(int m=n+1; m<in[0]; m++){
					for(int l=m+1; l<=in[0]; l++){
						if(n+m+l==in[1]){
							cnt = cnt + 1;
						}
					}
				}
			}
			System.out.println(cnt);
		}
	}
	static int[] parseInts(String[] s){
		int[] x = new int[s.length];
		for(int i=0; i<s.length; i++){
			x[i] = Integer.parseInt(s[i]);
		}
		return x;
	}
}