import java.util.*;

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

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