import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    }
}
 import java.io.ByteArrayInputStream; ByteArrayInputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    }
} Main String INPUT = ""; INPUT "" public static void main(String[] args) throws Exception {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    } run {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    } Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes())); sc INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes())) INPUT.isEmpty() INPUT.isEmpty INPUT new Scanner(System.in) new Scanner(new ByteArrayInputStream(INPUT.getBytes())) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) solve(sc, out) solve sc out out.flush() out.flush out void solve(Scanner sc, PrintWriter out) {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    } solve {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    } int n n x; x for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		} ; {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		} {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		} n = sc.nextInt() n sc.nextInt() sc.nextInt sc 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 cnt = 0; cnt 0 for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; 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 i n i++ i++ i {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			} {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			} for (int j = i+1; j <= n; 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 j n 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 Scanner sc sc PrintWriter out out public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    }
} public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    }
} Main
import java.io.ByteArrayInputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    String INPUT = "";

    public static void main(String[] args) throws Exception {
        new Main().run();
    }

    void run() {
        Scanner sc = INPUT.isEmpty() ? new Scanner(System.in) : new Scanner(new ByteArrayInputStream(INPUT.getBytes()));
        PrintWriter out = new PrintWriter(System.out);

        solve(sc, out);
        out.flush();
    }

    void solve(Scanner sc, PrintWriter out) {
        int n, x;
        
        for (;;) {
        	n = sc.nextInt();
        	x = sc.nextInt();
        	if (n == 0 && x == 0) break;
        	int cnt = 0;
        	for (int i = 1; i <= n; i++) {
        		for (int j = i+1; j <= n; j++) {
        			for (int k = j+1; k <= n; k++) {
        				if (i+j+k == x) cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
    }
}

