import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	} main {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) ArrayList<String> list = new ArrayList<String>(); list new ArrayList<String>() while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		} true {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		} list.add(sc.nextLine()) list.add list sc.nextLine() sc.nextLine sc if(list.get(list.size() - 1).equals("0 0")) {
				break;
			} list.get(list.size() - 1).equals("0 0") list.get(list.size() - 1).equals list.get(list.size() - 1) list.get list list.size() - 1 list.size() list.size list 1 "0 0" {
				break;
			} break; int [][] data = new int[list.size() - 1][2]; data new int[list.size() - 1][2] list.size() - 1 list.size() list.size list 1 2 for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		} int i = 0; int i = 0; i 0 i < list.size() - 1 i list.size() - 1 list.size() list.size list 1 i++ i++ i {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		} {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		} String s = list.get(i); s list.get(i) list.get list i String[] ary = s.split(" "); ary s.split(" ") s.split s " " data[i][0] = Integer.parseInt(ary[0]) data[i][0] data[i] data i 0 Integer.parseInt(ary[0]) Integer.parseInt Integer ary[0] ary 0 data[i][1] = Integer.parseInt(ary[1]) data[i][1] data[i] data i 1 Integer.parseInt(ary[1]) Integer.parseInt Integer ary[1] ary 1 int answer = 0; answer 0 for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		} int cntData = 0; int cntData = 0; cntData 0 cntData < data.length cntData data.length data data.length cntData++ cntData++ cntData {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		} {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		} for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			} int count1 = 1; int count1 = 1; count1 1 count1 < data[cntData][0] - 1 count1 data[cntData][0] - 1 data[cntData][0] data[cntData] data cntData 0 1 count1++ count1++ count1 {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			} {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			} for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				} int count2 = count1 + 1; int count2 = count1 + 1; count2 count1 + 1 count1 1 count2 < data[cntData][0] count2 data[cntData][0] data[cntData] data cntData 0 count2++ count2++ count2 {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				} {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				} for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					} int count3 = count2 + 1; int count3 = count2 + 1; count3 count2 + 1 count2 1 count3 <= data[cntData][0] count3 data[cntData][0] data[cntData] data cntData 0 count3++ count3++ count3 {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					} {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					} if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						} count1 + count2 + count3 == data[cntData][1] count1 + count2 + count3 count1 + count2 + count3 count1 count2 count3 data[cntData][1] data[cntData] data cntData 1 {
							answer++;
						} answer++ answer System.out.println(answer) System.out.println System.out System System.out answer answer = 0 answer 0 String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		//?????±????????????????´?
		ArrayList<String> list = new ArrayList<String>();
		while(true) {
			list.add(sc.nextLine());
			if(list.get(list.size() - 1).equals("0 0")) {
				break;
			}
		}
		
		//?????±???int???????????????2?¬?????????????????´???????
		int [][] data = new int[list.size() - 1][2];
		for(int i = 0; i < list.size() - 1; i++) {
			String s = list.get(i);
			String[] ary = s.split(" ");
			data[i][0] = Integer.parseInt(ary[0]);
			data[i][1] = Integer.parseInt(ary[1]);
		}
		
		//
		int answer = 0;
		for(int cntData = 0; cntData < data.length; cntData++) {
			for(int count1 = 1; count1 < data[cntData][0] - 1; count1++) {
				for(int count2 = count1 + 1; count2 < data[cntData][0] ; count2++) {
					for(int count3 = count2 + 1; count3 <= data[cntData][0]; count3++) {
						if(count1 + count2 + count3 == data[cntData][1]) {
							answer++;
						}
					}
				}
			}
			System.out.println(answer);
			answer = 0;
		}
	}

}