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

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} Main public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		} try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			} catch (IOException ioe) {
			} IOException ioe {
			} {
				if (br != null) {
					br.close();
				}
			} if (br != null) {
					br.close();
				} br != null br null {
					br.close();
				} br.close() br.close br {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} String str = br.readLine(); str br.readLine() br.readLine br String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " int n = Integer.parseInt(strArr[0]); n Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 int x = Integer.parseInt(strArr[1]); x Integer.parseInt(strArr[1]) Integer.parseInt Integer strArr[1] strArr 1 List<Integer> counters = new ArrayList<Integer>(); counters new ArrayList<Integer>() Integer count; count while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			} !( n==0 && x==0) ( n==0 && x==0) n==0 n 0 x==0 x 0 {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			} count = 0 count 0 for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				} {
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				} for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					} int j=i+1; int j=i+1; j i+1 i 1 j<=n j n j++ j++ j {
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					} {
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					} for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						} 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){
								count++;
							}
						} {
							if(i+j+k == x){
								count++;
							}
						} if(i+j+k == x){
								count++;
							} i+j+k == x i+j+k i+j+k i j k x {
								count++;
							} count++ count counters.add(count) counters.add counters count str = br.readLine() str br.readLine() br.readLine br strArr = str.split(" ") strArr str.split(" ") str.split str " " n = Integer.parseInt(strArr[0]) n Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 x = Integer.parseInt(strArr[1]) x Integer.parseInt(strArr[1]) Integer.parseInt Integer strArr[1] strArr 1 for(Integer s : counters){
				System.out.println(s);
			} Integer s counters {
				System.out.println(s);
			} {
				System.out.println(s);
			} System.out.println(s) System.out.println System.out System System.out s String[] args args public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
} Main

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

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {

			String str = br.readLine();
			String[] strArr = str.split(" ");
			int n = Integer.parseInt(strArr[0]);
			int x = Integer.parseInt(strArr[1]);

			List<Integer> counters = new ArrayList<Integer>();
			Integer count;
			while (!( n==0 && x==0)) {

				count = 0;
				for(int i=1;i<=n;i++){
					for(int j=i+1;j<=n;j++){
						for(int k=j+1;k<=n;k++){
							if(i+j+k == x){
								count++;
							}
						}
					}
				}
				counters.add(count);

				str = br.readLine();
				strArr = str.split(" ");
				n = Integer.parseInt(strArr[0]);
				x = Integer.parseInt(strArr[1]);

			}

			for(Integer s : counters){
				System.out.println(s);
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null) {
					br.close();
				}
			} catch (IOException ioe) {
			}

		}
	}
}