import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	}
} import java.io.*; io.* java public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	}
} Main public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder builder = new StringBuilder(); builder new StringBuilder() while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		} true {
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		} String[] s = br.readLine().split(" "); s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int num = Integer.parseInt(s[0]); num Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 int x = Integer.parseInt(s[1]); x Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 if( num==0 && x==0 ) break; num==0 && x==0 num==0 num 0 x==0 x 0 break; int count = 0; count 0 for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			} int i=1 ; int i=1 ; i 1 i<=num-2 i num-2 num 2 i++ i++ i {
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			} {
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			} for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				} int j=i+1 ; int j=i+1 ; j i+1 i 1 j<=num-1 j num-1 num 1 j++ j++ j {
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				} {
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				} for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					} int k=j+1 ; int k=j+1 ; k j+1 j 1 k<=num k num 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 builder.append(count).append("\n") builder.append(count).append builder.append(count) builder.append builder count "\n" System.out.print(builder) System.out.print System.out System System.out builder String[] args args public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	}
} public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	}
} Main
import java.io.*;

public class Main{
	public static void main(String[] args)throws IOException, NumberFormatException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		
		while(true){
			String[] s = br.readLine().split(" ");
			int num = Integer.parseInt(s[0]);
			int x = Integer.parseInt(s[1]);
			if( num==0 && x==0 ) break;
			
			int count = 0;
			for( int i=1 ; i<=num-2 ; i++ ){
				for( int j=i+1 ; j<=num-1 ; j++ ){
					for( int k=j+1 ; k<=num ; k++ ){
						if( i+j+k==x ) count++;
					}
				}
			}
			
			builder.append(count).append("\n");
		}
		
		System.out.print(builder);
	}
}