

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

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		} true {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		} String[] num = br.readLine().split(" "); num br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(num[0]); n Integer.parseInt(num[0]) Integer.parseInt Integer num[0] num 0 int x = Integer.parseInt(num[1]); x Integer.parseInt(num[1]) Integer.parseInt Integer num[1] num 1 if (n == 0 && x == 0)
				break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int cnt = 0; cnt 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)
							cnt++;
					}
				}
			} 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)
							cnt++;
					}
				}
			} {
				for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if ((i + j + k) == x)
							cnt++;
					}
				}
			} for (int j = i + 1; j <= n - 1; j++) {
					for (int k = j + 1; k <= n; k++) {
						if ((i + j + k) == x)
							cnt++;
					}
				} 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)
							cnt++;
					}
				} {
					for (int k = j + 1; k <= n; k++) {
						if ((i + j + k) == x)
							cnt++;
					}
				} for (int k = j + 1; k <= n; k++) {
						if ((i + j + k) == x)
							cnt++;
					} 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)
							cnt++;
					} {
						if ((i + j + k) == x)
							cnt++;
					} if ((i + j + k) == x)
							cnt++; (i + j + k) == x (i + j + k) i + j + k i j k x cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	}
} public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	}
} Main


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

public class Main{

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String[] num = br.readLine().split(" ");
			int n = Integer.parseInt(num[0]);
			int x = Integer.parseInt(num[1]);
			// ????????????
			if (n == 0 && x == 0)
				break;
			int cnt = 0;
			// 5 9
			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)
							cnt++;
					}
				}
			}
			System.out.println(cnt);

		}

	}
}