import java.util.Scanner;

public class Main {


     public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {


     public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		} true {
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		} int ans_cnt = 0; ans_cnt 0 int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int 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; for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			} int cnt1 = 1; int cnt1 = 1; cnt1 1 cnt1 <= n cnt1 n cnt1++ cnt1++ cnt1 {
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			} {
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			} for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				} int cnt2 = cnt1 + 1; int cnt2 = cnt1 + 1; cnt2 cnt1 + 1 cnt1 1 cnt2 <= n cnt2 n cnt2++ cnt2++ cnt2 {
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				} {
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				} for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					} int cnt3 = cnt2 +1; int cnt3 = cnt2 +1; cnt3 cnt2 +1 cnt2 1 cnt3 <= n cnt3 n cnt3++ cnt3++ cnt3 {
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					} {
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					} if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++; (cnt1 + cnt2 + cnt3) == x (cnt1 + cnt2 + cnt3) cnt1 + cnt2 + cnt3 cnt1 cnt2 cnt3 x ans_cnt++ ans_cnt System.out.println(ans_cnt) System.out.println System.out System System.out ans_cnt scan.close() scan.close scan String[] args args public class Main {


     public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	}
} public class Main {


     public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	}
} Main
import java.util.Scanner;

public class Main {


     public static void main(String[] args){
		Scanner scan = new Scanner(System.in);

		while(true){
			int ans_cnt = 0;
			int n = scan.nextInt();//???????????°???????????????
			int x = scan.nextInt();//???????±?????????°???????????????
			if(n == 0 && x == 0)
				break;
			for(int cnt1 = 1; cnt1 <= n; cnt1++){
				for(int cnt2 = cnt1 + 1; cnt2 <= n; cnt2++){
					for(int cnt3 = cnt2 +1; cnt3 <= n; cnt3++){
						if((cnt1 + cnt2 + cnt3) == x)
							ans_cnt++;
					}
				}
			}
			System.out.println(ans_cnt);	
		}
		scan.close();
	}
}