import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    }

    private static int cntPattern(int n, int x) {
        int ret = 0;
        int max = 2 * n;
        if (max <= x) {
            return 0;
        }
        if (max - 1 == n) {
            return 1;
        }

        for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        }
        return ret;
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    }

    private static int cntPattern(int n, int x) {
        int ret = 0;
        int max = 2 * n;
        if (max <= x) {
            return 0;
        }
        if (max - 1 == n) {
            return 1;
        }

        for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        }
        return ret;
    }
} Main public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    } main {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        } in.hasNext() in.hasNext in {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        } int n = in.nextInt(); n in.nextInt() in.nextInt in int x = in.nextInt(); x in.nextInt() in.nextInt in if (n == 0) {
                break;
            } n == 0 n 0 {
                break;
            } break; int ret = 0; ret 0 for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            } int i = n; int i = n; i n i >= 3 i 3 i-- i-- i {
                ret += cntPattern(i - 1, x - i);
            } {
                ret += cntPattern(i - 1, x - i);
            } ret += cntPattern(i - 1, x - i) ret cntPattern(i - 1, x - i) cntPattern i - 1 i 1 x - i x i sb.append(ret).append("\n") sb.append(ret).append sb.append(ret) sb.append sb ret "\n" System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args private static int cntPattern(int n, int x) {
        int ret = 0;
        int max = 2 * n;
        if (max <= x) {
            return 0;
        }
        if (max - 1 == n) {
            return 1;
        }

        for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        }
        return ret;
    } cntPattern {
        int ret = 0;
        int max = 2 * n;
        if (max <= x) {
            return 0;
        }
        if (max - 1 == n) {
            return 1;
        }

        for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        }
        return ret;
    } int ret = 0; ret 0 int max = 2 * n; max 2 * n 2 n if (max <= x) {
            return 0;
        } max <= x max x {
            return 0;
        } return 0; 0 if (max - 1 == n) {
            return 1;
        } max - 1 == n max - 1 max 1 n {
            return 1;
        } return 1; 1 for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        } int i = n; int i = n; i n i > 1 i 1 i-- i-- i {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        } {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        } for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            } int j = i - 1; int j = i - 1; j i - 1 i 1 j >= 1 j 1 j-- j-- j {
                if (j + i == x) {
                    ret++;
                    break;
                }
            } {
                if (j + i == x) {
                    ret++;
                    break;
                }
            } if (j + i == x) {
                    ret++;
                    break;
                } j + i == x j + i j i x {
                    ret++;
                    break;
                } ret++ ret break; return ret; ret int n n int x x
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            for (int i = n; i >= 3; i--) {
                ret += cntPattern(i - 1, x - i);
            }
            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    }

    private static int cntPattern(int n, int x) {
        int ret = 0;
        int max = 2 * n;
        if (max <= x) {
            return 0;
        }
        if (max - 1 == n) {
            return 1;
        }

        for (int i = n; i > 1; i--) {
            for (int j = i - 1; j >= 1; j--) {
                if (j + i == x) {
                    ret++;
                    break;
                }
            }
        }
        return ret;
    }
}