import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n; n int x; x int intCount; intCount ArrayList<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		} true {
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		} n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan intCount = 0 intCount 0 if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				break;
			} break; {
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			} for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				} {
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				} for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					} int j = i + 1; int j = i + 1; j i + 1 i 1 j <= n j n j++ j++ j {
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					} {
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					} for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						} 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){
								intCount++;
							}
						} {
							if(i + j + k == x){
								intCount++;
							}
						} if(i + j + k == x){
								intCount++;
							} i + j + k == x i + j + k i + j + k i j k x {
								intCount++;
							} intCount++ intCount list.add(intCount) list.add list intCount for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		} int i = 0; int i = 0; i 0 i < list.size() i list.size() list.size list i++ i++ i {
			System.out.println(list.get(i));
		} {
			System.out.println(list.get(i));
		} System.out.println(list.get(i)) System.out.println System.out System System.out list.get(i) list.get list i scan.close() scan.close scan String[] args args public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
} public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n;
		int x;
		int intCount;
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(true){
			n = scan.nextInt();
			x = scan.nextInt();
			intCount = 0;
			if(n == 0 && x == 0){
				break;
			}else{
				for(int i = 1; i <= n; i++){
					for(int j = i + 1; j <= n; j++){
						for(int k = j + 1; k <= n; k++){
							if(i + j + k == x){
								intCount++;
							}
						}
					}
				}
				list.add(intCount);
			}
		}
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
		scan.close();
	}
}