import java.util.Scanner;

/**
 * How many ways?
 */
public class Main {
    private static Scanner scan;

    public static void main(String[] args) {
        scan = new Scanner(System.in);

        // n までの数,３つの数の合計x
        int n,x = 0;
        int i,j,k = 1;
        while (true) {
            int cnt = 0;
            n = scan.nextInt();
            x = scan.nextInt();
            if (n == 0 && x == 0) {
                return;
            }
            for (i = 1; i <= n; i++) {
                for (j = i; j <= n; j++) {
                    for (k = j; k <= n; k++) {
                        // 重複していないかつ合計が一致
                        if (x == (i + j + k) && !(i == j) && !(j == k) && !(i == k)) {
                            ++ cnt;
                            break;
                        }
                    }
                }
            }
            System.out.println(cnt);
        }
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz