import std.stdio;
import std.conv;
import std.array;

void main()
{
  while (1) {
    int cnt = 0;
    string[] input = split(readln());
    int n = to!(int)(input[0]);
    int x = to!(int)(input[1]);

    if (n == 0 && x == 0) break;

    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i == j || i == k || j == k) continue;
          if (i + j + k == x) cnt++;
        }
      }
    }
    writeln(cnt);
  }
}