import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while (true) {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
} import java.util.Scanner; Scanner java.util class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while (true) {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public void run() {
        while (true) {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        }
    } run {
        while (true) {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        }
    } while (true) {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        } true {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        } int 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;
            } break; int count = 0; count 0 for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    } int a = 1; int a = 1; a 1 a <= n a n a++ a++ a for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    } for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    } int b = a + 1; int b = a + 1; b a + 1 a 1 b <= n b n b++ b++ b for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    } for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    } int c = b + 1; int c = b + 1; c b + 1 b 1 c <= n c n c++ c++ c {
                        if (a + b + c == x) {
                            count++;
                        }
                    } {
                        if (a + b + c == x) {
                            count++;
                        }
                    } if (a + b + c == x) {
                            count++;
                        } a + b + c == x a + b + c a + b + c a b c x {
                            count++;
                        } count++ count ln(count) ln count public static void main(String[] args) {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args public static void pr(Object o) {
        System.out.print(o);
    } pr {
        System.out.print(o);
    } System.out.print(o) System.out.print System.out System System.out o Object o o public static void ln(Object o) {
        System.out.println(o);
    } ln {
        System.out.println(o);
    } System.out.println(o) System.out.println System.out System System.out o Object o o public static void ln() {
        System.out.println();
    } ln {
        System.out.println();
    } System.out.println() System.out.println System.out System System.out
import java.util.Scanner;
 
class Main {
    Scanner sc = new Scanner(System.in);
 
    public void run() {
        while (true) {
            int n = sc.nextInt(), x = sc.nextInt();
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int a = 1; a <= n; a++)
                for (int b = a + 1; b <= n; b++)
                    for (int c = b + 1; c <= n; c++) {
                        if (a + b + c == x) {
                            count++;
                        }
                    }
            ln(count);
        }
    }
 
    public static void main(String[] args) {
        new Main().run();
    }
 
    public static void pr(Object o) {
        System.out.print(o);
    }
 
    public static void ln(Object o) {
        System.out.println(o);
    }
 
    public static void ln() {
        System.out.println();
    }
}
