import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	}
} import java.util.*; util.* java public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int i i j j k k cnt = 0; cnt 0 int n n x; x int[] ans = new int[100]; ans new int[100] 100 for(i = 0; i < 100; i++){
			ans[i] = 0;
		} i = 0; i = 0 i 0 i < 100 i 100 i++ i++ i {
			ans[i] = 0;
		} {
			ans[i] = 0;
		} ans[i] = 0 ans[i] ans i 0 while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		} true {
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		} n = sc.nextInt() n sc.nextInt() sc.nextInt sc 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;
			} break; for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			} i = 1; i = 1 i 1 i <= n - 2 i n - 2 n 2 i++ i++ i {
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			} {
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			} for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				} j = i + 1; j = i + 1 j i + 1 i 1 j <= n - 1 j n - 1 n 1 j++ j++ j {
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				} {
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				} for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					} k = j + 1; k = j + 1 k j + 1 j 1 k <= n k n k++ k++ k {
						if(i + j + k == x){
							ans[cnt] ++;
						}
					} {
						if(i + j + k == x){
							ans[cnt] ++;
						}
					} if(i + j + k == x){
							ans[cnt] ++;
						} i + j + k == x i + j + k i + j + k i j k x {
							ans[cnt] ++;
						} ans[cnt] ++ ans[cnt] ans cnt cnt ++ cnt for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		} i = 0; i = 0 i 0 i < cnt i cnt i++ i++ i {
			System.out.println(ans[i]);
		} {
			System.out.println(ans[i]);
		} System.out.println(ans[i]) System.out.println System.out System System.out ans[i] ans i String args[] args public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	}
} public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	}
} Main
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int i, j, k, cnt = 0;
		int n, x;
		int[] ans = new int[100];
		
		for(i = 0; i < 100; i++){
			ans[i] = 0;
		}
		
		while(true){
			n = sc.nextInt();
			x = sc.nextInt();
			
			if(n == 0 && x == 0){
				break;
			}
			
			for(i = 1; i <= n - 2; i++){
				for(j = i + 1; j <= n - 1; j++){
					for(k = j + 1; k <= n; k++){
						if(i + j + k == x){
							ans[cnt] ++;
						}
					}
				}
			}
			
			cnt ++;
		}
		
		for(i = 0; i < cnt; i++){
			System.out.println(ans[i]);
		}
	}
}