

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	}
} Main public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	} main {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) 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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == 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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				} {

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

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

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


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

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

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == 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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					} {

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

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


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

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

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

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					} {

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					} int S = s+1; S s+1 s 1 int T = t+2; T t+2 t 2 String c = f + "+" + S + "+" + T + "+"; c f + "+" + S + "+" + T + "+" T "+" S f + "+" + S + "+" + T + "+" f "+" S "+" T "+" if(f + S + T == sum){

								count++;

						} f + S + T == sum f + S + T f + S + T f S T sum {

								count++;

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

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	}
} public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	}
} Main


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		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++){

							int S = s+1;
							int T = t+2;

							String c = f + "+" + S + "+" + T + "+";

							if(f + S + T == sum){

								count++;

						}
					}


					}
				}

				System.out.println(count);
			}
		}
	}
}