public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	} main {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	} java.util.Scanner sc = new java.util.Scanner(System.in); sc new java.util.Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		} true {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc if ( n==0 && x==0 ) break; n==0 && x==0 n==0 n 0 x==0 x 0 break; int count = 0; count 0 for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			} int i=1; int i=1; i 1 i <= n-2 && i < x/3 i <= n-2 i n-2 n 2 i < x/3 i x/3 x 3 i++ i++ i {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			} {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			} for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				} int j=i+1; int j=i+1; j i+1 i 1 j <= n-1 && j < x/2 j <= n-1 j n-1 n 1 j < x/2 j x/2 x 2 j++ j++ j {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				} {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				} for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					} int k=j+1; int k=j+1; k j+1 j 1 k <= n && k < x-2 k <= n k n k < x-2 k x-2 x 2 k++ k++ k {
						if ( i+j+k==x ) count++;
					} {
						if ( i+j+k==x ) count++;
					} if ( i+j+k==x ) count++; i+j+k==x i+j+k i+j+k i j k x count++ count sb.append(count).append("\n") sb.append(count).append sb.append(count) sb.append sb count "\n" System.out.print(sb) System.out.print System.out System System.out sb String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	}

} Main
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner sc = new java.util.Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while (true) {
			int n = sc.nextInt();
			int x = sc.nextInt();

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

			int count = 0;
			for (int i=1; i <= n-2 && i < x/3; i++) {

				for (int j=i+1; j <= n-1 && j < x/2; j++) {

					for (int k=j+1; k <= n && k < x-2; k++) {
						if ( i+j+k==x ) count++;
					}

				}

			}

			sb.append(count).append("\n");
		}

		System.out.print(sb);
	}

}