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

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

    }
} Main public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int count;
        for(;;){
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        }

    } main {
        Scanner scan = new java.util.Scanner(System.in);
        int count;
        for(;;){
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        }

    } Scanner scan = new java.util.Scanner(System.in); scan new java.util.Scanner(System.in) int count; count for(;;){
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        } ; {
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        } {
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        } int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan count = 0 count 0 if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            } n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
                break;
            } break; {
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            } 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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                } 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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                } {
                    for(int j = i + 1; j <= n; j++){
                        for(int k = j + 1; k <= n; k++){
                            if(i + j + k == x){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                } for(int j = i + 1; j <= n; j++){
                        for(int k = j + 1; k <= n; k++){
                            if(i + j + k == x){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    } 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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    } {
                        for(int k = j + 1; k <= n; k++){
                            if(i + j + k == x){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    } for(int k = j + 1; k <= n; k++){
                            if(i + j + k == x){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        } 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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        } {
                            if(i + j + k == x){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        } if(i + j + k == x){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            } i + j + k == x i + j + k i + j + k i j k x {
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            } if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                } i != j && j != k && i != k i != j && j != k && i != k i != j i j j != k j k i != k i k {
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                } 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 scan = new java.util.Scanner(System.in);
        int count;
        for(;;){
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        }

    }
} public class Main {
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int count;
        for(;;){
            int n = scan.nextInt();
            int x = scan.nextInt();
            count = 0;
            if(n == 0 && x == 0){
                break;
            }else{
                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){
                                if(i != j && j != k && i != k){
                                    //System.out.println("i = " + i + ", j = " + j + ", k = " + k);
                                    count++;
                                }
                            }
                        }
                    }
                }
                System.out.println(count);
            }
        }

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

    }
}