import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args)throws IOException{
        int n, x, p = 0; /* p:????????????????????°*/

        /*??\???????????????????????????*/
        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
        StringTokenizer st = new StringTokenizer(buf," ");
        n = Integer.parseInt(st.nextToken());
        x = Integer.parseInt(st.nextToken());
        
        while(true) {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main{
    public static void main(String[] args)throws IOException{
        int n, x, p = 0; /* p:????????????????????°*/

        /*??\???????????????????????????*/
        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
        StringTokenizer st = new StringTokenizer(buf," ");
        n = Integer.parseInt(st.nextToken());
        x = Integer.parseInt(st.nextToken());
        
        while(true) {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        }
    }
} Main public static void main(String[] args)throws IOException{
        int n, x, p = 0; /* p:????????????????????°*/

        /*??\???????????????????????????*/
        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
        StringTokenizer st = new StringTokenizer(buf," ");
        n = Integer.parseInt(st.nextToken());
        x = Integer.parseInt(st.nextToken());
        
        while(true) {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        }
    } main {
        int n, x, p = 0; /* p:????????????????????°*/

        /*??\???????????????????????????*/
        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
        StringTokenizer st = new StringTokenizer(buf," ");
        n = Integer.parseInt(st.nextToken());
        x = Integer.parseInt(st.nextToken());
        
        while(true) {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        }
    } int n n x x p = 0; p 0 InputStreamReader isr =new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br =new BufferedReader(isr); br new BufferedReader(isr) String buf = br.readLine(); buf br.readLine() br.readLine br StringTokenizer st = new StringTokenizer(buf," "); st new StringTokenizer(buf," ") n = Integer.parseInt(st.nextToken()) n Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st x = Integer.parseInt(st.nextToken()) x Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st while(true) {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        } true {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        } if (n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int i i j j k; k for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            } i = 1; i = 1 i 1 i <= n - 2 i n - 2 n 2 i++ i++ i {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            } {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            } for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                } j = i + 1; j = i + 1 j i + 1 i 1 j <= n - 1 j n - 1 n 1 j++ j++ j {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                } {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                } for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    } k = j + 1; k = j + 1 k j + 1 j 1 k <= n k n k++ k++ k {
                        if (i + j + k == x) p++;
                    } {
                        if (i + j + k == x) p++;
                    } if (i + j + k == x) p++; i + j + k == x i + j + k i + j + k i j k x p++ p System.out.println(p) System.out.println System.out System System.out p p = 0 p 0 buf = br.readLine() buf br.readLine() br.readLine br st = new StringTokenizer(buf," ") st new StringTokenizer(buf," ") n = Integer.parseInt(st.nextToken()) n Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st x = Integer.parseInt(st.nextToken()) x Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st String[] args args
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args)throws IOException{
        int n, x, p = 0; /* p:????????????????????°*/

        /*??\???????????????????????????*/
        InputStreamReader isr =new InputStreamReader(System.in);
   		BufferedReader br =new BufferedReader(isr);
    	String buf = br.readLine();
        StringTokenizer st = new StringTokenizer(buf," ");
        n = Integer.parseInt(st.nextToken());
        x = Integer.parseInt(st.nextToken());
        
        while(true) {
        	if (n == 0 && x == 0) break;
            int i, j, k;
            
            for (i = 1;i <= n - 2;i++) {
                for (j = i + 1;j <= n - 1;j++) {
                    for (k = j + 1;k <= n;k++) {
                        if (i + j + k == x) p++;
                    }
                }
            }
            
            /*????????????????????° p?????????*/
            System.out.println(p);
            
            /* p?????????????????????*/
            p = 0;
            
            /*?¬??????\???????????????????????????*/
            buf = br.readLine();
            st = new StringTokenizer(buf," ");
            n = Integer.parseInt(st.nextToken());
            x = Integer.parseInt(st.nextToken());
        }
    }
}