import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int x=Integer.parseInt(a[1]);
        while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        }
	}
} import java.io.*; io.* java import java.util.*; util.* java class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int x=Integer.parseInt(a[1]);
        while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        }
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int x=Integer.parseInt(a[1]);
        while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        }
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int x=Integer.parseInt(a[1]);
        while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        }
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] a=br.readLine().split(" "); a br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n=Integer.parseInt(a[0]); n Integer.parseInt(a[0]) Integer.parseInt Integer a[0] a 0 int x=Integer.parseInt(a[1]); x Integer.parseInt(a[1]) Integer.parseInt Integer a[1] a 1 while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        } !(n==0&&x==0) (n==0&&x==0) n==0 n 0 x==0 x 0 {
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        } List<String> l = new ArrayList<String>(); l new ArrayList<String>() int c=0; c 0 for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	} {
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	} for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	} int j=1; int j=1; j 1 j<=n j n j++ j++ j {
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	} {
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	} for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	} int k=1; int k=1; k 1 k<=n k n k++ k++ k {
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	} {
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	} if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		} i!=j&&j!=k&&k!=i&&i+j+k==x k!=i i!=j&&j!=k&&k!=i&&i+j+k==x i!=j i j j!=k j k k!=i k i i+j+k==x i+j+k i+j+k i j k x {
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		} String num=null; num null if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			} i<j&&j<k i<j i j j<k j k {
                				num=i+" "+j+" "+k;
                			} num=i+" "+j+" "+k num i+" "+j+" "+k " " j i+" "+j+" "+k i " " j " " k if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			} i<k&&k<j i<k i k k<j k j {
                				num=i+" "+k+" "+j;
                			} num=i+" "+k+" "+j num i+" "+k+" "+j " " k i+" "+k+" "+j i " " k " " j if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			} j<i&&i<k j<i j i i<k i k {
                				num=j+" "+i+" "+k;
                			} num=j+" "+i+" "+k num j+" "+i+" "+k " " i j+" "+i+" "+k j " " i " " k if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			} j<k&&k<i j<k j k k<i k i {
                				num=j+" "+k+" "+i;
                			} num=j+" "+k+" "+i num j+" "+k+" "+i " " k j+" "+k+" "+i j " " k " " i if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			} k<j&&j<i k<j k j j<i j i {
                				num=k+" "+j+" "+i;
                			} num=k+" "+j+" "+i num k+" "+j+" "+i " " j k+" "+j+" "+i k " " j " " i {
                				num=k+" "+i+" "+j;
                			} num=k+" "+i+" "+j num k+" "+i+" "+j " " i k+" "+i+" "+j k " " i " " j if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			} l.indexOf(num)==-1 l.indexOf(num) l.indexOf l num -1 1 {
                				l.add(num);
                    			c++;
                			} l.add(num) l.add l num c++ c System.out.println(c) System.out.println System.out System System.out c a=br.readLine().split(" ") a br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n=Integer.parseInt(a[0]) n Integer.parseInt(a[0]) Integer.parseInt Integer a[0] a 0 x=Integer.parseInt(a[1]) x Integer.parseInt(a[1]) Integer.parseInt Integer a[1] a 1 String[] args args
import java.io.*;
import java.util.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] a=br.readLine().split(" ");
        int n=Integer.parseInt(a[0]);
        int x=Integer.parseInt(a[1]);
        while(!(n==0&&x==0)){
            List<String> l = new ArrayList<String>(); 
            int c=0;
        	for(int i=1;i<=n;i++){
            	for(int j=1;j<=n;j++){
                	for(int k=1;k<=n;k++){
                		if(i!=j&&j!=k&&k!=i&&i+j+k==x){
                			String num=null;
                			if(i<j&&j<k){
                				num=i+" "+j+" "+k;
                			}else if(i<k&&k<j){
                				num=i+" "+k+" "+j;
                			}else if(j<i&&i<k){
                				num=j+" "+i+" "+k;
                			}else if(j<k&&k<i){
                				num=j+" "+k+" "+i;
                			}else if(k<j&&j<i){
                				num=k+" "+j+" "+i;
                			}else{
                				num=k+" "+i+" "+j;
                			}
                			if(l.indexOf(num)==-1){
                				l.add(num);
                    			c++;
                			}
                		}
                	}
            	}
        	}
        	System.out.println(c);
        	a=br.readLine().split(" ");
            n=Integer.parseInt(a[0]);
            x=Integer.parseInt(a[1]);
        }
	}
}