import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		} ; n != 0 || x != 0 n != 0 n 0 x != 0 x 0 {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		} {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		} int result = 0; result 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) {
							result++;
						}
					}
				}
			} 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) {
							result++;
						}
					}
				}
			} {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							result++;
						}
					}
				}
			} for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							result++;
						}
					}
				} 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) {
							result++;
						}
					}
				} {
					for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							result++;
						}
					}
				} for (int k = j + 1; k <= n; k++) {
						if (i + j + k == x) {
							result++;
						}
					} 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) {
							result++;
						}
					} {
						if (i + j + k == x) {
							result++;
						}
					} if (i + j + k == x) {
							result++;
						} i + j + k == x i + j + k i + j + k i j k x {
							result++;
						} result++ result System.out.println(result) System.out.println System.out System System.out result n = sc.nextInt() n sc.nextInt() sc.nextInt sc x = sc.nextInt() x sc.nextInt() sc.nextInt sc sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int x = sc.nextInt();

		for (; n != 0 || x != 0;) {
			int result = 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) {
							result++;
						}
					}
				}
			}
			System.out.println(result);

			n = sc.nextInt();
			x = sc.nextInt();
		}

		sc.close();
	}
}