import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    } main {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        } true {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        } int n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt(); x scan.nextInt() scan.nextInt scan if (n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; int count = 0; count 0 for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            } int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            } {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            } for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n + 1 j n + 1 n 1 j++ j++ j {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                } {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                } for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    } int k = j + 1; int k = j + 1; k j + 1 j 1 k < n + 1 k n + 1 n 1 k++ k++ k {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    } {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    } if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        } (i + j + k) == x (i + j + k) i + j + k i j k x {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        } if (!(i == k || j == i || k == j)) {
                                count++;
                            } !(i == k || j == i || k == j) (i == k || j == i || k == j) i == k || j == i || k == j i == k i k j == i j i k == j k j {
                                count++;
                            } count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
//        int[] a = new int[3];

        while (true) {
            int n = scan.nextInt(), x = scan.nextInt();
            if (n == 0 && x == 0) break;
            int count = 0;

            for (int i = 1; i < n + 1; i++) {
                for (int j = i + 1; j < n + 1; j++) {
                    for (int k = j + 1; k < n + 1; k++) {
                        if ((i + j + k) == x) {
                            if (!(i == k || j == i || k == j)) {
                                count++;
                            }

                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}