

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));
	}
}
/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