import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}

} Main public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	} main {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		} true {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		} int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int sum = sc.nextInt(); sum sc.nextInt() sc.nextInt sc if (num == 0 && sum == 0)
				break; num == 0 && sum == 0 num == 0 num 0 sum == 0 sum 0 break; int cnt = 0; cnt 0 for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			} int pnt1 = 1; int pnt1 = 1; pnt1 1 pnt1 <= num pnt1 num pnt1++ pnt1++ pnt1 {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			} {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			} for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				} int pnt2 = pnt1 + 1; int pnt2 = pnt1 + 1; pnt2 pnt1 + 1 pnt1 1 pnt2 <= num pnt2 num pnt2++ pnt2++ pnt2 {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				} {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				} for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					} int pnt3 = pnt2 + 1; int pnt3 = pnt2 + 1; pnt3 pnt2 + 1 pnt2 1 pnt3 <= num pnt3 num pnt3++ pnt3++ pnt3 {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					} {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					} if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						} pnt1 + pnt2 + pnt3 == sum pnt1 + pnt2 + pnt3 pnt1 + pnt2 + pnt3 pnt1 pnt2 pnt3 sum {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						} if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							} pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3 pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3 pnt1 == pnt2 pnt1 pnt2 pnt1 == pnt3 pnt1 pnt3 pnt2 == pnt3 pnt2 pnt3 {

								cnt += 0;

							} cnt += 0 cnt 0 {

								cnt++;

							} cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\????????????
		Scanner sc = new Scanner(System.in);

		while (true) {

			int num = sc.nextInt();
			int sum = sc.nextInt();

			if (num == 0 && sum == 0)
				break;

			// ??????????????????????????°??¨????????¶????????????????????????????????°??????????????????????????°
			int cnt = 0;

			for (int pnt1 = 1; pnt1 <= num; pnt1++) {

				for (int pnt2 = pnt1 + 1; pnt2 <= num; pnt2++) {

					for (int pnt3 = pnt2 + 1; pnt3 <= num; pnt3++) {

						if (pnt1 + pnt2 + pnt3 == sum) {

							if (pnt1 == pnt2 || pnt1 == pnt3 || pnt2 == pnt3) {

								cnt += 0;

							} else {

								cnt++;

							}
						}
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}

}