#include<bits/stdc++.h>
using namespace std;

int main() {
	int n, x;
	while (cin >> n >> x, n) {
		int res = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i + 1; j <= n; j++) {
				for (int k = j + 1; k <= n; k++) {
					res += (i + k + j) == x;
				}
			}
		}
		cout << res << endl;
	}
}
