import java.util.Scanner;

public class Main {

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

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

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

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

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

} public class Main {

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

} Main
import java.util.Scanner;

public class Main {

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

}