import java.io.*;

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

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    }
} import java.io.*; io.* java public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int[] num = new int[3];

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int[] num = new int[3];

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int[] num = new int[3];

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int[] num = new int[3]; num new int[3] 3 while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        } true {
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        } String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(line[0]); n Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int x = Integer.parseInt(line[1]); x Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 int cnt = 0; cnt 0 if(n == 0 && x == 0){
                break;
            } n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
                break;
            } break; for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            } {
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            } num[0] = i num[0] num 0 i for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                } int j = i+1; int j = i+1; j i+1 i 1 j <= n j n j++ j++ j {
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                } {
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                } num[1] = j num[1] num 1 j for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    } int k = j+1; int k = j+1; k j+1 j 1 k <= n k n k++ k++ k {
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    } {
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    } num[2] = k num[2] num 2 k if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        } num[0] + num[1] + num[2] == x num[0] + num[1] + num[2] num[0] + num[1] + num[2] num[0] num 0 num[1] num 1 num[2] num 2 x {
                            cnt++;
                        } cnt++ cnt sb.append(cnt).append("\n") sb.append(cnt).append sb.append(cnt) sb.append sb cnt "\n" System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int[] num = new int[3];

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    }
} public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        int[] num = new int[3];

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    }
} Main
import java.io.*;

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

        while(true){
            String[] line = br.readLine().split(" ");
            int n = Integer.parseInt(line[0]);
            int x = Integer.parseInt(line[1]);
            int cnt = 0;

            if(n == 0 && x == 0){
                break;
            }
            for(int i = 1; i <= n; i++){
                num[0] = i;
                for(int j = i+1; j <= n; j++){
                    num[1] = j;
                    for(int k = j+1; k <= n; k++){
                        num[2] = k;
                        if(num[0] + num[1] + num[2] == x){
                            cnt++;
                        }
                    }
                }
            }
            sb.append(cnt).append("\n");
        }
        System.out.print(sb.toString());
    }
}