import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	}
} Main public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	} main {
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	} Scanner cin= new Scanner(System.in); cin new Scanner(System.in) while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	} true {
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	} int n= cin.nextInt(); n cin.nextInt() cin.nextInt cin int x= cin.nextInt(); x cin.nextInt() cin.nextInt cin int count= 0; count 0 if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		} n==0 && x==0 n==0 n 0 x==0 x 0 {
			break;
		} break; {
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		} int i i j j k; k for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			} i=1; i=1 i 1 i<n-1 i n-1 n 1 i++ i++ i {
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			} {
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			} for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			} j=i+1; j=i+1 j i+1 i 1 j<n j n j++ j++ j {
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			} {
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			} for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			} k=j+1; k=j+1 k j+1 j 1 k<n+1 k n+1 n 1 k++ k++ k {
				if( i+j+k==x ){
					count++;
					break;
				}
			} {
				if( i+j+k==x ){
					count++;
					break;
				}
			} if( i+j+k==x ){
					count++;
					break;
				} i+j+k==x i+j+k i+j+k i j k x {
					count++;
					break;
				} count++ count break; System.out.println(count) System.out.println System.out System System.out count String args[] args public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	}
} public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	}
} Main
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
	while(true){
		int n= cin.nextInt();
		int x= cin.nextInt();
		int count= 0;
		
		if( n==0 && x==0 ){
			break;
		}
		else{
			int i,j,k;
			for(i=1;i<n-1;i++){
			for(j=i+1;j<n;j++){
			for(k=j+1;k<n+1;k++){
				if( i+j+k==x ){
					count++;
					break;
				}
			}
			}
			}
			System.out.println(count);
		}
	}
	}
}