

import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	}
} Main public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	} main {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n n x x c c result result min min max; max n = 0 n 0 x = 0 x 0 c = 1 c 1 result = 0 result 0 min = 1 min 1 max = 0 max 0 while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		} true {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		} n = scan.nextInt() n scan.nextInt() scan.nextInt scan x = scan.nextInt() x scan.nextInt() scan.nextInt scan if ((n == 0) & (x == 0)) {
				break;
			} (n == 0) & (x == 0) (n == 0) n 0 (x == 0) x 0 {
				break;
			} break; max = n max n min = 1 min 1 result=0 result 0 c = 1 c 1 for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			} ; min<=(n-2) min (n-2) n 2 min++ min++ min {//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			} {//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			} c = min + 1 c min + 1 min 1 while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				} true {
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				} if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					} max == c max c {//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					} c++ c max = n max n if(c == max){break;} c == max c max {break;} break; if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					} (min + c + max) == x (min + c + max) min + c + max min c max x {//x??¨?????????????????£?????´???
						result++;
						max--;
					} result++ result max-- max {//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					} max-- max sb.append(result).append("\n") sb.append(result).append sb.append(result) sb.append sb result "\n" System.out.print(new String(sb)) System.out.print System.out System System.out new String(sb) String args[] args public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	}
} public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	}
} Main


import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n, x, c, result,min,max;
		// ??????????¨????
		n = 0;
		x = 0;
		c = 1;// min????¬????????????????
		result = 0;// ??????????????°
		min = 1;//????°????
		max = 0;//?????§???

		while (true) {// ??????????????????????????§???????????????
			n = scan.nextInt();
			x = scan.nextInt();

			if ((n == 0) & (x == 0)) {
				break;
			}
			
			max = n;//?????§???????¨????
			min = 1;//????°?????????????
			result=0;//result??????????¨????
			c = 1;//?????????????¨????

			// x?????????0?????£??????????????????
			for(;min<=(n-2);min++){//?????´????????????1????????????????????????
				c = min + 1;//?????????????¨????
				while(true){
					if(max == c){//c????????¨max???????????????????????£?????´???c?????????1?¢???????
						c++;
						max = n;//max??????????????????
						if(c == max){break;}
					}else if((min + c + max) == x){//x??¨?????????????????£?????´???
						result++;
						max--;
					}else{//???????¶??????????x?????????????????´???
						max--;//max?????????????????????
					}
				}
			}
			sb.append(result).append("\n");
		}
		System.out.print(new String(sb));
	}
}