import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	}

} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	}

} Main public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	} main {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int s; s while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			} n!=0 || x!=0 n!=0 n 0 x!=0 x 0 {
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			} s=0 s 0 for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				} int c=1; int c=1; c 1 c<=n-2 c n-2 n 2 ++c ++c c {
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				} {
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				} for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					} int d=c+1; int d=c+1; d c+1 c 1 d<=n-1 d n-1 n 1 ++d ++d d {
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					} {
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					} for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						} int e=d+1; int e=d+1; e d+1 d 1 e<=n e n ++e ++e e {
							if(c+d+e==x){
								s=s+1;
							}
						} {
							if(c+d+e==x){
								s=s+1;
							}
						} if(c+d+e==x){
								s=s+1;
							} c+d+e==x c+d+e c+d+e c d e x {
								s=s+1;
							} s=s+1 s s+1 s 1 System.out.println(s) System.out.println System.out System System.out s n = sc.nextInt() n sc.nextInt() sc.nextInt sc x = sc.nextInt() x sc.nextInt() sc.nextInt sc String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	}

} public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	}

} Main
import java.io.IOException;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) throws Exception {
		// TODO ?????????????????????????????????????????????
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int x = sc.nextInt();
			int s;
			while(n!=0 || x!=0){
				s=0;
				for(int c=1;c<=n-2;++c){
					for(int d=c+1;d<=n-1;++d){
						for(int e=d+1;e<=n;++e){
							if(c+d+e==x){
								s=s+1;
							}
						}
					}
				}
				System.out.println(s);
				n = sc.nextInt();
				x = sc.nextInt();
			}
	}

}