import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while(true){
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		}
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while(true){
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		}
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while(true){
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while(true){
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(true){
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		} true {
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		} final String[] data = sc.nextLine().split(" "); data sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " final int n = Integer.parseInt(data[0]); n Integer.parseInt(data[0]) Integer.parseInt Integer data[0] data 0 final int x = Integer.parseInt(data[1]); x Integer.parseInt(data[1]) Integer.parseInt Integer data[1] data 1 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 - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			} int i = 1; int i = 1; i 1 i <= n - 2 i n - 2 n 2 i++ i++ i {
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			} {
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			} for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == 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 {
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				} {
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				} for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					} int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k++ k++ k {
						if((i + j + k) == x) count++;
					} {
						if((i + j + k) == x) count++;
					} if((i + j + k) == x) count++; (i + j + k) == x (i + j + k) i + j + k i j k x count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		while(true){
			final String[] data = sc.nextLine().split(" ");
			final int n = Integer.parseInt(data[0]);
			final int x = Integer.parseInt(data[1]);
			if(n == 0 && x == 0) break;
			int count = 0;
			for(int i = 1; i <= n - 2; i++){
				for(int j = i + 1; j <= n - 1; j++){
					for(int k = j + 1; k <= n; k++){
						if((i + j + k) == x) count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}