import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B
 * @author wsKmatsuda
 *
 */
public class Main{

	public static void main(String[] args) {

		new Main().run();

	}

	public void run(){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String inputData;
        List<ThreeNumberTotalCheck> testDataList = new ArrayList<ThreeNumberTotalCheck>();

        try {
        	//??\???
	        while(true){
				inputData = reader.readLine();
				if("0 0".equals(inputData)){
					break;
				}
				String[] strData = inputData.split(" ");
				int n = Integer.parseInt(strData[0]);
				int x = Integer.parseInt(strData[1]);
				testDataList.add(new ThreeNumberTotalCheck(n,x));

	        }

	        //????????????
	        for(ThreeNumberTotalCheck result :testDataList){
	        	System.out.println(result.getCnt());
	        }

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/**
	 * ThreeNumberTotalCheck?????????
	 * n???x?????????????????????
	 * 1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨???? x ??¨??????????????????????????°????±???????
	 */
	class ThreeNumberTotalCheck{

		//check limit
		public int n;
		//total
		public int x;
		//1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨???? x ??¨??????????????????????????°
		public int cnt;

		public String evalution;

		ThreeNumberTotalCheck(int _n ,int _x){
			n = _n;
			x = _x;

			setCnt();

		}

		/**
		 * ??¶??°?????????
		 */
		private void setCnt(){
			cnt = 0;

			for(int i=1;i<n+2;i++){
				for(int j=i+1;j<n;j++){
					int jg = x - i - j;
					//System.out.println(i + "," + j + "," + jg + "=" +(i+j+jg));
					if(jg > j && jg <= n){
						cnt++;
					}

				}

				/*
				1-2-3
				1-2-4
				1-2-5

				1-3-4
				1-3-5

				1-4-5

				2-3-4
				2-3-5

				2-4-5

				3-4-5
				*/
			}
		}

		/**
		 * ??¶??°?????????
		 * @return
		 */
		public int getCnt(){

			return cnt;

		}
	}

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