Problem:
How many ways?

Write a program which identifies the number of combinations of three integers which satisfy the following conditions:

You should select three distinct integers from 1 to n.

A total sum of the three integers is x.

For example, there are two combinations for n = 5 and x = 9.

1 + 3 + 5 = 9

2 + 3 + 4 = 9

Input

The input consists of multiple datasets. For each dataset, two integers n and x are given in a line.

The input ends with two zeros for n and x respectively. Your program should not process for these terminal symbols.

Constraints

3 ≤ n ≤ 100

0 ≤ x ≤ 300

Output

For each dataset, print the number of combinations in a line.

Sample Input

5 9
0 0

Sample Output

2

Note

      解説

Solution in JAVA (judge verdict: Wrong Answer)

import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
		//System.out.print(" ");
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> NN = new ArrayList<Integer>();
		ArrayList<Integer> XX = new ArrayList<Integer>();
		int n=1;
		int x=1;
		int kumi =0;
		while(n != 0 || x!= 0){
			n =scan.nextInt();
			x =scan.nextInt();
			NN.add(n);
			XX.add(x);
//			System.out.println("scaning");
		}
//		System.out.println("finir");
		for (int i=0;i<NN.size()-1;i++){
				kumi = 0;
			for(int i1=0;i1<NN.get(i)-1;i1++){
				for(int i2=0;i2<NN.get(i)-1;i2++){
					for(int i3=0;i3<NN.get(i)-1;i3++){
						int N1 = i1+1;
						int N2 = i2+1;
						int N3 = i3+1;
//						System.out.println(N1 +" "+ N2 +" "+ N3);
						if( N1 == N2 || N2 == N3 || N3 == N1){
							//???????????????
							//System.out.println("T");
						}
						else{
							if(N1+N2+N3 == XX.get(i)){
								kumi += 1;
//								System.out.println(N1+N2+N3);
//								System.out.println(XX.get(i));
							}

						}
					}
				}
			}
			System.out.println(kumi/3);
		}
	}
}