import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    }
    static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    }
} import java.util.*; util.* java public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    }
    static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    }
} Main static Scanner kbd = new Scanner(System.in); kbd new Scanner(System.in) public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    } main {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    } while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    } kbd.hasNext() kbd.hasNext kbd {
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    } int n = kbd.nextInt(); n kbd.nextInt() kbd.nextInt kbd int x = kbd.nextInt(); x kbd.nextInt() kbd.nextInt kbd int z=0; z 0 if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        } !(n==0 && x==0) (n==0 && x==0) n==0 n 0 x==0 x 0 {
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        } for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        } int a=1; int a=1; a 1 a<=n-2 a n-2 n 2 a++ a++ a {
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        } {
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        } for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            } int b=2; int b=2; b 2 b<=n-1 b n-1 n 1 b++ b++ b {
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            } {
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            } for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            } int c=3; int c=3; c 3 c<=n c n c++ c++ c {
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            } {
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            } if(m(a,b,c,x)) z++; m(a,b,c,x) m a b c x z++ z System.out.println(z) System.out.println System.out System System.out z String[] args args static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    } m {
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    } boolean p = a+b+c==x; p a+b+c==x a+b+c a+b+c a b c x boolean q = a<b && b<c; q a<b && b<c a<b a b b<c b c return p&&q; p&&q p q int a a int b b int c c int x x public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    }
    static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    }
} public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    }
    static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    }
} Main
import java.util.*;
public class Main {
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args) {
 
    while(kbd.hasNext()){
        int n = kbd.nextInt();
        int x = kbd.nextInt();
        int z=0;
        if(!(n==0 && x==0)){
        for(int a=1; a<=n-2; a++){
            for(int b=2; b<=n-1; b++){
            for(int c=3; c<=n; c++){
                //System.out.println(a+" "+b+" "+c);
                if(m(a,b,c,x)) z++;
            }
            }
        }
        System.out.println(z);
        }
    }
    }
    static boolean m(int a, int b, int c, int x){
    boolean p = a+b+c==x;
    boolean q = a<b && b<c;
    return p&&q;
    }
}