//????????????????????°???????????????????????°??????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		//??\?????????????????°
		
		StringBuilder sb = new StringBuilder();
		while(true) {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		}
		System.out.print(sb.toString());
	}


} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		//??\?????????????????°
		
		StringBuilder sb = new StringBuilder();
		while(true) {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		}
		System.out.print(sb.toString());
	}


} Main public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		//??\?????????????????°
		
		StringBuilder sb = new StringBuilder();
		while(true) {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		}
		System.out.print(sb.toString());
	} main {
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		//??\?????????????????°
		
		StringBuilder sb = new StringBuilder();
		while(true) {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		}
		System.out.print(sb.toString());
	} BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(true) {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		} true {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		} String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int limitNum = Integer.parseInt(str[0]); limitNum Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 int sumNum = Integer.parseInt(str[1]); sumNum Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 if(limitNum == 0 && sumNum==0) {
				break;
			} limitNum == 0 && sumNum==0 limitNum == 0 limitNum 0 sumNum==0 sumNum 0 {
				break;
			} break; int cnt = 0; cnt 0 for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			} int i=1; int i=1; i 1 i<=limitNum-2 i limitNum-2 limitNum 2 i++ i++ i {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			} {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			} for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				} int j=i+1; int j=i+1; j i+1 i 1 j<=limitNum-1 j limitNum-1 limitNum 1 j++ j++ j {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				} {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				} for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					} int k=j+1; int k=j+1; k j+1 j 1 k<=limitNum k limitNum k++ k++ k {
						if(i+j+k == sumNum) {
							cnt++;
						}
					} {
						if(i+j+k == sumNum) {
							cnt++;
						}
					} if(i+j+k == sumNum) {
							cnt++;
						} i+j+k == sumNum i+j+k i+j+k i j k sumNum {
							cnt++;
						} cnt++ cnt sb.append(cnt+"\n") sb.append sb cnt+"\n" cnt "\n" System.out.print(sb.toString()) System.out.print System.out System System.out sb.toString() sb.toString sb String[] args args
//????????????????????°???????????????????????°??????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		//??\?????????????????°
		
		StringBuilder sb = new StringBuilder();
		while(true) {
			
			String[] str = br.readLine().split(" ");
			
			int limitNum = Integer.parseInt(str[0]);
			int sumNum = Integer.parseInt(str[1]);
			
			if(limitNum == 0 && sumNum==0) {
				break;
			}
			
			int cnt = 0;
			
			for(int i=1; i<=limitNum-2; i++) {
				for(int j=i+1; j<=limitNum-1; j++) {
					for(int k=j+1; k<=limitNum; k++) {
						if(i+j+k == sumNum) {
							cnt++;
						}
					}
				}
			}
			sb.append(cnt+"\n");
		}
		System.out.print(sb.toString());
	}


}