import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int n, x, ans;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = sc.nextInt();
        while (n != 0 || x != 0) {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        int n, x, ans;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = sc.nextInt();
        while (n != 0 || x != 0) {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
} Main public static void main(String[] args) {
        int n, x, ans;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = sc.nextInt();
        while (n != 0 || x != 0) {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        }
    } main {
        int n, x, ans;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = sc.nextInt();
        while (n != 0 || x != 0) {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        }
    } int n n x x ans; ans Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc x = sc.nextInt() x sc.nextInt() sc.nextInt sc while (n != 0 || x != 0) {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        } n != 0 || x != 0 n != 0 n 0 x != 0 x 0 {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        } ans = 0 ans 0 for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++; int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++; for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++; 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 + 1; k++) 
                        if (i + j + k == x)
                            ans++; for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++; int k = j + 1; int k = j + 1; k j + 1 j 1 k < n + 1 k n + 1 n 1 k++ k++ k 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 System.out.println(ans) System.out.println System.out System System.out ans n = sc.nextInt() n sc.nextInt() sc.nextInt sc x = sc.nextInt() x sc.nextInt() sc.nextInt sc String[] args args
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int n, x, ans;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        x = sc.nextInt();
        while (n != 0 || x != 0) {
            ans = 0;
            for (int i = 1; i < n - 1; i++) 
                for (int j = i + 1; j < n; j++) 
                    for (int k = j + 1; k < n + 1; k++) 
                        if (i + j + k == x)
                            ans++;
            System.out.println(ans);
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
}
