import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    } main {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(true) {
            int n = sc.nextInt();
            int x = sc.nextInt();

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        } true {
            int n = sc.nextInt();
            int x = sc.nextInt();

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        } 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 int n1 = 1 n1 1 n2 = 2 n2 2 n3 = 3; n3 3 for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            } n1 = 1; n1 = 1 n1 1 n1<= n - 2 n1 n - 2 n 2 n1++ n1++ n1 {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            } {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            } for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                } n2 = n1 + 1; n2 = n1 + 1 n2 n1 + 1 n1 1 n2<= n - 1 n2 n - 1 n 1 n2++ n2++ n2 {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                } {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                } for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    } n3 = n2 + 1; n3 = n2 + 1 n3 n2 + 1 n2 1 n3 <= n n3 n n3++ n3++ n3 {
                        if(n1 + n2 + n3 == x)
                            count++;
                    } {
                        if(n1 + n2 + n3 == x)
                            count++;
                    } if(n1 + n2 + n3 == x)
                            count++; n1 + n2 + n3 == x n1 + n2 + n3 n1 + n2 + n3 n1 n2 n3 x count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

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

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

            int count = 0;

            int n1 = 1, n2 = 2, n3 = 3;

            for (n1 = 1; n1<= n - 2; n1++) {
                for (n2 = n1 + 1; n2<= n - 1; n2++) {
                    for(n3 = n2 + 1; n3 <= n; n3++){
                        if(n1 + n2 + n3 == x)
                            count++;
                    }
                }
            }
            System.out.println(count);
        }
    }
}

