import java.util.*;

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

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