import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} Main public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} main {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	} BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) String buffer; buffer try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		} catch (Exception ex) {
			ex.printStackTrace();
		} Exception ex {
			ex.printStackTrace();
		} ex.printStackTrace() ex.printStackTrace ex {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			} (buffer = reader.readLine())  != null (buffer = reader.readLine()) buffer reader.readLine() reader.readLine reader null {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			} String[] strings = buffer.split(" "); strings buffer.split(" ") buffer.split buffer " " int n = Integer.valueOf(strings[0]); n Integer.valueOf(strings[0]) Integer.valueOf Integer strings[0] strings 0 int x = Integer.valueOf(strings[1]); x Integer.valueOf(strings[1]) Integer.valueOf Integer strings[1] strings 1 if (n == 0 && x == 0) return; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 return; int count = 0; count 0 for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				} int a = 1; int a = 1; a 1 a <= n - 2 a n - 2 n 2 a++ a++ a {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				} {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				} for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					} int b = a + 1; int b = a + 1; b a + 1 a 1 b <= n - 1 b n - 1 n 1 b++ b++ b {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					} {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					} for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						} int c = b + 1; int c = b + 1; c b + 1 b 1 c <= n c n c++ c++ c {
							if (a + b + c == x) count++;
						} {
							if (a + b + c == x) count++;
						} if (a + b + c == x) count++; a + b + c == x a + b + c a + b + c a b c x 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) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;

		try {
			while ((buffer = reader.readLine())  != null) {
				String[] strings = buffer.split(" ");

				int n = Integer.valueOf(strings[0]);
				int x = Integer.valueOf(strings[1]);

				if (n == 0 && x == 0) return;

				int count = 0;
				for (int a = 1; a <= n - 2; a++) {
					for (int b = a + 1; b <= n - 1; b++) {
						for (int c = b + 1; c <= n; c++) {
							if (a + b + c == x) count++;
						}
					}
				}
				System.out.println(count);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

