import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n n x; x int count; count StringBuilder sb = new StringBuilder(); sb new StringBuilder() while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		} true {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		} count=0 count 0 n=sc.nextInt() n sc.nextInt() sc.nextInt sc x=sc.nextInt() x sc.nextInt() sc.nextInt sc if(n==0 && x==0){
				break;
			} n==0 && x==0 n==0 n 0 x==0 x 0 {
				break;
			} break; for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			} for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				} int j = 1; int j = 1; j 1 j <= n j n j++ j++ j {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				} {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				} for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					} int j2 = 1; int j2 = 1; j2 1 j2 <= n j2 n j2++ j2++ j2 {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					} {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					} if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						} i != j && j!= j2 && j2 != i i != j && j!= j2 && j2 != i i != j i j j!= j2 j j2 j2 != i j2 i {
							if(i+j+j2 == x){
								count++;
							}
						} if(i+j+j2 == x){
								count++;
							} i+j+j2 == x i+j+j2 i+j+j2 i j j2 x {
								count++;
							} count++ count count/=6 count 6 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) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	}
} Main
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,x;	//1??????????????§?????°???????¨???????
		int count;	//????¨???°
		StringBuilder sb = new StringBuilder();
		
		while (true) {
			count=0;
			n=sc.nextInt();
			x=sc.nextInt();
			
			//0 0????????????
			if(n==0 && x==0){
				break;
			}
			
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					for (int j2 = 1; j2 <= n; j2++) {
						//??????????????§??????
						if(i != j && j!= j2 && j2 != i){
							if(i+j+j2 == x){
								count++;
							}
						}
					}
				}
			}//for
			count/=6;
			System.out.println(count);
		}
	}
}