import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        int n, x, i, j, k, num;

        while (true) {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        }
    }
} import java.io.*; io.* java class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        int n, x, i, j, k, num;

        while (true) {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        }
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        int n, x, i, j, k, num;

        while (true) {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        int n, x, i, j, k, num;

        while (true) {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] input; input int n n x x i i j j k k num; num while (true) {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        } true {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        } input = br.readLine().split(" ") input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt(input[0]) n Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 x = Integer.parseInt(input[1]) x Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 if (n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; num = 0 num 0 for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            } i = 1; i = 1 i 1 i <= n i n i++ i++ i {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            } {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            } for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                } j = i + 1; j = i + 1 j i + 1 i 1 j <= n j n j++ j++ j {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                } {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                } for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    } k = j + 1; k = j + 1 k j + 1 j 1 k <= n k n k++ k++ k {
                        if (x - i - j - k == 0) num++;
                    } {
                        if (x - i - j - k == 0) num++;
                    } if (x - i - j - k == 0) num++; x - i - j - k == 0 x - i - j - k j x - i - j - k x i j k 0 num++ num System.out.println(num) System.out.println System.out System System.out num String[] args args
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        int n, x, i, j, k, num;

        while (true) {
            input = br.readLine().split(" ");
            n = Integer.parseInt(input[0]);
            x = Integer.parseInt(input[1]);
            if (n == 0 && x == 0) break;
            num = 0;
            for (i = 1; i <= n; i++) {
                for (j = i + 1; j <= n; j++) {
                    for (k = j + 1; k <= n; k++) {
                        if (x - i - j - k == 0) num++;
                    }
                }
            }
            System.out.println(num);
        }
    }
}