import java.util.Scanner;
import java.util.function.Function;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    }

    int sim(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    }

    boolean isFin(int n, int x) {
        return n == 0 && x == 0;
    }

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

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    }

    int sim(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    }

    boolean isFin(int n, int x) {
        return n == 0 && x == 0;
    }

} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args void solve() {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    } solve {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    } String str; str while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        } true {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        } str = sc.nextLine() str sc.nextLine() sc.nextLine sc String[] sp = str.split(" "); sp str.split(" ") str.split str " " int n = Integer.parseInt(sp[0]); n Integer.parseInt(sp[0]) Integer.parseInt Integer sp[0] sp 0 int x = Integer.parseInt(sp[1]); x Integer.parseInt(sp[1]) Integer.parseInt Integer sp[1] sp 1 if (isFin(n, x)) break; isFin(n, x) isFin n x break; System.out.println(sim(n, x)) System.out.println System.out System System.out sim(n, x) sim n x int sim(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    } sim {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    } int cnt = 0; cnt 0 for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        } int i = 1; int i = 1; i 1 i <= n i n ++i ++i i {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        } {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        } for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j <= n j n ++j ++j j {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            } {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            } if (i == j) continue; i == j i j continue; int k = x - i - j; k x - i - j x - i - j x i j if (i == k || j == k) continue; i == k || j == k i == k i k j == k j k continue; if (j < k && k <= n) {
                    cnt++;
                } j < k && k <= n j < k j k k <= n k n {
                    cnt++;
                } cnt++ cnt return cnt; cnt int n n int x x boolean isFin(int n, int x) {
        return n == 0 && x == 0;
    } isFin {
        return n == 0 && x == 0;
    } return n == 0 && x == 0; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 int n n int x x public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    }

    int sim(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    }

    boolean isFin(int n, int x) {
        return n == 0 && x == 0;
    }

} public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    }

    int sim(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    }

    boolean isFin(int n, int x) {
        return n == 0 && x == 0;
    }

} Main
import java.util.Scanner;
import java.util.function.Function;

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    Scanner sc = new Scanner(System.in);

    void solve() {
        String str;
        while (true) {
            str = sc.nextLine();
            String[] sp = str.split(" ");
            int n = Integer.parseInt(sp[0]);
            int x = Integer.parseInt(sp[1]);
            if (isFin(n, x)) break;
            System.out.println(sim(n, x));
        }
    }

    int sim(int n, int x) {
        int cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = i + 1; j <= n; ++j) {
                if (i == j) continue;
                int k = x - i - j;
                if (i == k || j == k) continue;
                if (j < k && k <= n) {
                    cnt++;
                }
            }
        }
        return cnt;
    }

    boolean isFin(int n, int x) {
        return n == 0 && x == 0;
    }

}
