#include <iostream>
using namespace std;

int main(){
	int a, b;
	while(cin >> a >> b && !(a == 0 && b == 0)){
		int num = 0;
		for(int i = 1; i <= a-2; i++){
			for(int j = i+1; j <= a-1; j++){
				for(int k = j+1; k <= a; k++){
					if(i+j+k == b)
						num++;
				}
			}
		}
		cout << num << endl;
	}
	return 0;
}
