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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        } true {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        } String[] lines = br.readLine().split(" "); lines br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(lines[0]); n Integer.parseInt(lines[0]) Integer.parseInt Integer lines[0] lines 0 int x = Integer.parseInt(lines[1]); x Integer.parseInt(lines[1]) Integer.parseInt Integer lines[1] lines 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 - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            } int i = 1; int i = 1; i 1 i < n - 1 i n - 1 n 1 i++ i++ i {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            } {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            } if (i * 3 + 2 > x) {
                    break;
                } i * 3 + 2 > x i * 3 + 2 i * 3 i 3 2 x {
                    break;
                } break; for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                } {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                } if (i + j + j + 1 > x) {
                        break;
                    } i + j + j + 1 > x i + j + j + 1 j i + j + j + 1 i j j 1 x {
                        break;
                    } break; for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    } int k = x - i - j; int k = x - i - j; k x - i - j x - i - j x i j k >= j + 1 k j + 1 j 1 k-- k-- k {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    } {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    } if (k > n) {
                            continue;
                        } k > n k n {
                            continue;
                        } continue; if (i + j + k == x) {
                            count++;
                            break;
                        } i + j + k == x i + j + k i + j + k i j k x {
                            count++;
                            break;
                        } count++ count break; System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String[] lines = br.readLine().split(" ");
            int n = Integer.parseInt(lines[0]);
            int x = Integer.parseInt(lines[1]);
            if (n == 0 && x == 0) {
                break;
            }
            int count = 0;
            for (int i = 1; i < n - 1; i++) {
                if (i * 3 + 2 > x) {
                    break;
                }
                for (int j = i + 1; j < n; j++) {
                    if (i + j + j + 1 > x) {
                        break;
                    }
                    for (int k = x - i - j; k >= j + 1; k--) {
                        if (k > n) {
                            continue;
                        }
                        if (i + j + k == x) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}