import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        while(true){
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        }
        out.flush();
    }
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        while(true){
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        }
        out.flush();
    }
} Main private static final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) private static final PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] Args){
        while(true){
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        }
        out.flush();
    } main {
        while(true){
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        }
        out.flush();
    } while(true){
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        } true {
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        } final int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc final int x = Integer.parseInt(sc.next()); x Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc if(n==0&&x==0) break; n==0&&x==0 n==0 n 0 x==0 x 0 break; int ans = 0; ans 0 for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            } int i = 1; int i = 1; i 1 i<=n-2 i n-2 n 2 i++ i++ i {
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            } {
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            } for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                } int j = i+1; int j = i+1; j i+1 i 1 j<=n-1 j n-1 n 1 j++ j++ j {
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                } {
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                } final int k = x-i-j; k x-i-j x-i-j x i j if(j<k&&k<=n) ans++; j<k&&k<=n j<k j k k<=n k n ans++ ans out.println(ans) out.println out ans out.flush() out.flush out String[] Args Args
import java.io.PrintWriter;
import java.util.Scanner;

class Main{
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] Args){
        while(true){
            final int n = Integer.parseInt(sc.next());
            final int x = Integer.parseInt(sc.next());
            if(n==0&&x==0) break;
            int ans = 0;
            for(int i = 1; i<=n-2; i++){
                for(int j = i+1; j<=n-1; j++){
                    final int k = x-i-j;
                    if(j<k&&k<=n) ans++;
                }
            }
            out.println(ans);
        }
        out.flush();
    }
}