import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	}
} import java.util.*; util.* java public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	}
} Main private static final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	} main {
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	} List<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		} ; {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		} {
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan if(n == 0 && x == 0){
				break;
			} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
				break;
			} break; int cnt = 0; cnt 0 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){
							cnt++;
						}
					}
				}
			} 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){
							cnt++;
						}
					}
				}
			} {
				for(int j = i + 1; j <= n; j++){
					for(int k = j + 1; k <= n; k++){
						if(i + j + k == x){
							cnt++;
						}
					}
				}
			} for(int j = i + 1; j <= n; j++){
					for(int k = j + 1; k <= n; k++){
						if(i + j + k == x){
							cnt++;
						}
					}
				} 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){
							cnt++;
						}
					}
				} {
					for(int k = j + 1; k <= n; k++){
						if(i + j + k == x){
							cnt++;
						}
					}
				} for(int k = j + 1; k <= n; k++){
						if(i + j + k == x){
							cnt++;
						}
					} 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){
							cnt++;
						}
					} {
						if(i + j + k == x){
							cnt++;
						}
					} if(i + j + k == x){
							cnt++;
						} i + j + k == x i + j + k i + j + k i j k x {
							cnt++;
						} cnt++ cnt list.add(cnt) list.add list cnt for(int c : list){
			System.out.println(c);
		} int c list {
			System.out.println(c);
		} {
			System.out.println(c);
		} System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	}
} public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	}
} Main
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		for(;;){
			int n = scan.nextInt();
			int x = scan.nextInt();
			if(n == 0 && x == 0){
				break;
			}
			int cnt = 0;
			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){
							cnt++;
						}
					}
				}
			}
			list.add(cnt);
		}

		for(int c : list){
			System.out.println(c);
		}
	}
}