import java.util.*;
import java.text.*;

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

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            int c = 0;
            if(n == 0 && x == 0) break;
            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) c++;
                    }
                }
            }
            System.out.println(c);
        }
    }
}