import java.io.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

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

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

        while(true) {
            String[] tmp = br.readLine().split(" ");
            int n = Integer.parseInt(tmp[0]);
            int x = Integer.parseInt(tmp[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for(int i = 3;i <= n;i++){
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while(true) {
            String[] tmp = br.readLine().split(" ");
            int n = Integer.parseInt(tmp[0]);
            int x = Integer.parseInt(tmp[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for(int i = 3;i <= n;i++){
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        } true {
            String[] tmp = br.readLine().split(" ");
            int n = Integer.parseInt(tmp[0]);
            int x = Integer.parseInt(tmp[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for(int i = 3;i <= n;i++){
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        } String[] tmp = br.readLine().split(" "); tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(tmp[0]); n Integer.parseInt(tmp[0]) Integer.parseInt Integer tmp[0] tmp 0 int x = Integer.parseInt(tmp[1]); x Integer.parseInt(tmp[1]) Integer.parseInt Integer tmp[1] tmp 1 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 i = 3;i <= n;i++){
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            } int i = 3; int i = 3; i 3 i <= n i n i++ i++ i {
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            } {
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            } for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                } int j = 2; int j = 2; j 2 j < i j i j++ j++ j {
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                } {
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                } for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    } int k = 1; int k = 1; k 1 k < j k j k++ k++ k {
                        if((i + j + k) == x){
                            count++;
                        }
                    } {
                        if((i + j + k) == x){
                            count++;
                        }
                    } if((i + j + k) == x){
                            count++;
                        } (i + j + k) == x (i + j + k) i + j + k i j k x {
                            count++;
                        } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while(true) {
            String[] tmp = br.readLine().split(" ");
            int n = Integer.parseInt(tmp[0]);
            int x = Integer.parseInt(tmp[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for(int i = 3;i <= n;i++){
                for(int j = 2;j < i;j++){
                    for(int k = 1;k < j;k++){
                        if((i + j + k) == x){
                            count++;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
 
}