import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    }
} Main public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    } main {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    } try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        } Exception e {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        } System.out.println(e) System.out.println System.out System System.out e e.getStackTrace() e.getStackTrace e System.exit(-1) System.exit System -1 1 {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in)); stdReader new BufferedReader(new InputStreamReader(System.in)) String line; line while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            } (line = stdReader.readLine()) != null (line = stdReader.readLine()) line stdReader.readLine() stdReader.readLine stdReader null {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            } String[] input = line.split(" ", 0); input line.split(" ", 0) line.split line " " 0 int n = Integer.parseInt(input[0]); n Integer.parseInt(input[0]) Integer.parseInt Integer input[0] input 0 int x = Integer.parseInt(input[1]); x Integer.parseInt(input[1]) Integer.parseInt Integer input[1] input 1 if(n == 0  && x == 0) {
                    break;
                } n == 0  && x == 0 n == 0 n 0 x == 0 x 0 {
                    break;
                } break; int count = 0; count 0 for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                } int i = 1; int i = 1; i 1 i <= (n - 2) i (n - 2) n 2 i++ i++ i {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                } {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                } if(i > (x - 2)) {
                        break;
                    } i > (x - 2) i (x - 2) x 2 {
                        break;
                    } break; for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                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 {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    } {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    } if(i + j > x - 1) {
                            continue;
                        } i + j > x - 1 i + j i j x - 1 x 1 {
                            continue;
                        } continue; for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        } int k = (j + 1); int k = (j + 1); k (j + 1) j 1 k <= n k n k++ k++ k {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        } {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        } int sum = i + j + k; sum i + j + k i + j + k i j k if(sum == x) {
                                count++;
                            } sum == x sum x {
                                count++;
                            } count++ count System.out.println(count) System.out.println System.out System System.out count stdReader.close() stdReader.close stdReader String[] args args public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    }
} public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int n = Integer.parseInt(input[0]); 
                int x = Integer.parseInt(input[1]);
                
                if(n == 0  && x == 0) {
                    break;
                }
                
                int count = 0;
                
                for(int i = 1; i <= (n - 2); i++) {
                    if(i > (x - 2)) {
                        break;
                    }
                    for(int j = (i + 1); j <= (n - 1); j++) {
                        if(i + j > x - 1) {
                            continue;
                        }
                        for(int k = (j + 1); k <= n; k++) {
                            int sum = i + j + k;
                            if(sum == x) {
                                count++;
                            }
                        }
                    }
                }
                
                System.out.println(count);
            }
            stdReader.close();
        } catch(Exception e) {
            System.out.println(e);
            e.getStackTrace();
            System.exit(-1);
        }
    }
}