import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            }
            System.out.println(c);
        }
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++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){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++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);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++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) while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            }
            System.out.println(c);
        } true {
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++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 x = sc.nextInt() x sc.nextInt() sc.nextInt sc 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,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            } int i = 1,l = n - 2; int i = 1 i 1 l = n - 2; l n - 2 n 2 i <= l i l ++i ++i i {
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            } {
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            } for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                } int j = i + 1,m = n - 1; int j = i + 1 j i + 1 i 1 m = n - 1; m n - 1 n 1 j <= m j m ++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 public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            }
            System.out.println(c);
        }
    }

} public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            }
            System.out.println(c);
        }
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt(),x = sc.nextInt(),c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1,l = n - 2;i <= l;++i){
                for(int j = i + 1,m = n - 1;j <= m;++j){
                    for(int k = j + 1;k <= n;++k){
                        if(i + j + k == x) ++c;
                    }
                }
            }
            System.out.println(c);
        }
    }

}