

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

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

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

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

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

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

	} main {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) ArrayList<Integer> list = new ArrayList<>(); list new ArrayList<>() while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		} true {

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		} int num = in.nextInt(); num in.nextInt() in.nextInt in int sum = in.nextInt(); sum in.nextInt() in.nextInt in int count = 0; count 0 if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			} num == 0 && sum == 0 num == 0 num 0 sum == 0 sum 0 {

				break;

			} break; {

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			} for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				} int f = 1; int f = 1; f 1 f <= (num-2) f (num-2) num 2 f++ f++ f {

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				} {

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				} for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					} int s = f; int s = f; s f s <= (num-2) s (num-2) num 2 s++ s++ s {

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					} {

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					} for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						} int t = s; int t = s; t s t <= (num-2) t (num-2) num 2 t++ t++ t {

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						} {

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						} if(f + (s + 1) + (t + 2) == sum){

								count++;

							} f + (s + 1) + (t + 2) == sum f + (s + 1) + (t + 2) f + (s + 1) + (t + 2) f (s + 1) s 1 (t + 2) t 2 sum {

								count++;

							} count++ count list.add(count) list.add list count for(int result: list){

			System.out.println(result);

		} int result list {

			System.out.println(result);

		} {

			System.out.println(result);

		} System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

	}
} public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

	}
} Main


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

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<>();

		while(true){

			int num = in.nextInt();
			int sum = in.nextInt();
			int count = 0;

			if(num == 0 && sum == 0){

				break;

			}else{

				for(int f = 1; f <= (num-2); f++){

					for(int s = f; s <= (num-2); s++){

						for(int t = s; t <= (num-2); t++){

							// ??°????¢????
							// String c = f + "+" + (s + 1) + "+" + (t + 2);
							// System.out.println(c);

							if(f + (s + 1) + (t + 2) == sum){

								count++;

							}
						}
					}
				}

				list.add(count);

			}
		}

		for(int result: list){

			System.out.println(result);

		}

	}
}