import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		} true {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		} int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int x = scanner.nextInt(); x scanner.nextInt() scanner.nextInt scanner if(n==0&&x==0) {
				break;
			} n==0&&x==0 n==0 n 0 x==0 x 0 {
				break;
			} break; int num = 0; num 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) {
							num++;
						}
					}
				}
			} 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) {
							num++;
						}
					}
				}
			} {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if (i+j+k==x) {
							num++;
						}
					}
				}
			} for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if (i+j+k==x) {
							num++;
						}
					}
				} 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) {
							num++;
						}
					}
				} {
					for(int k=j+1;k<=n;k++) {
						if (i+j+k==x) {
							num++;
						}
					}
				} for(int k=j+1;k<=n;k++) {
						if (i+j+k==x) {
							num++;
						}
					} 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) {
							num++;
						}
					} {
						if (i+j+k==x) {
							num++;
						}
					} if (i+j+k==x) {
							num++;
						} i+j+k==x i+j+k i+j+k i j k x {
							num++;
						} num++ num System.out.println(num) System.out.println System.out System System.out num scanner.close() scanner.close scanner String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(true) {
			int n = scanner.nextInt();	// 3 ≤ n ≤ 100
			int x = scanner.nextInt();	// 0 ≤ x ≤ 300
			if(n==0&&x==0) {
				break;
			}
			int num = 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) {
							num++;
						}
					}
				}
			}
			System.out.println(num);
			
		}
		scanner.close();
	}
}
