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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}

} 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 {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}

} Main public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	} main {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	} String line; line BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		} (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

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

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}

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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		String line;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while ((line = br.readLine()) != null) {
			if (line.equals("0 0")) {
				break;
			}

			String[] arr = line.split(" ");
			int n = Integer.parseInt(arr[0]);
			int x = Integer.parseInt(arr[1]);

			int ans = 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) {
							ans++;
						}
					}
				}
			}
			
			System.out.println(ans);
		}
	}

}