import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	}
} Main public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	} main {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n; n int x; x int cnt; cnt while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 } true {
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 } n = Integer.parseInt(scan.next()) n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan x = Integer.parseInt(scan.next()) x Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan cnt = 0 cnt 0 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while  x == 0 && n == 0 x == 0 x 0 n == 0 n 0 {
				 break;
			 } break; {
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 } for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 } {
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 } for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 } int l = i + 1; int l = i + 1; l i + 1 i 1 l <= n l n l++ l++ l {
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 } {
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 } for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 } int k = l + 1; int k = l + 1; k l + 1 l 1 k <= n k n k++ k++ k {
							 if((i + l + k) == x){
								 cnt++;
							 }
						 } {
							 if((i + l + k) == x){
								 cnt++;
							 }
						 } if((i + l + k) == x){
								 cnt++;
							 } (i + l + k) == x (i + l + k) i + l + k i l k x {
								 cnt++;
							 } cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	}
} public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	}
}