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

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        
        while (n != 0 || x != 0) {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        
        while (n != 0 || x != 0) {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
} Main public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        
        while (n != 0 || x != 0) {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        }
    } main {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        
        while (n != 0 || x != 0) {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc while (n != 0 || x != 0) {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        } n != 0 || x != 0 n != 0 n 0 x != 0 x 0 {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        } int sum = 0; sum 0 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) {
                            sum++;
                        }
                    }
                }
            } 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) {
                            sum++;
                        }
                    }
                }
            } {
                for (int j = i + 1; j <= n; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            sum++;
                        }
                    }
                }
            } for (int j = i + 1; j <= n; j++) {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            sum++;
                        }
                    }
                } 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) {
                            sum++;
                        }
                    }
                } {
                    for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            sum++;
                        }
                    }
                } for (int k = j + 1; k <= n; k++) {
                        if (i + j + k == x) {
                            sum++;
                        }
                    } 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) {
                            sum++;
                        }
                    } {
                        if (i + j + k == x) {
                            sum++;
                        }
                    } if (i + j + k == x) {
                            sum++;
                        } i + j + k == x i + j + k i + j + k i j k x {
                            sum++;
                        } sum++ sum System.out.println(sum) System.out.println System.out System System.out sum n = sc.nextInt() n sc.nextInt() sc.nextInt sc x = sc.nextInt() x sc.nextInt() sc.nextInt sc String[] args args
import java.io.*;
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int x = sc.nextInt();
        
        while (n != 0 || x != 0) {
            int sum = 0;
            
            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) {
                            sum++;
                        }
                    }
                }
            }
            
            System.out.println(sum);
            
            n = sc.nextInt();
            x = sc.nextInt();
        }
    }
}