#include <iostream>
using namespace std;

int main(void){
  int n,s;

  while(1){

    int cnt = 0;

    cin >> n >> s;
    if( n == s && n == 0 ) break;

    for( int i = 0 ; i < n ; i++ ){
      for( int j = 0 ; j <= s ; j++ ){
	for( int k = j+1 ; k <= s ; k++ ){
	  for( int l = k+1 ; l <= s ; l++ ){

	    if( j + k + l == s && ( i != j && i != k &&j != k )) cnt++;

	  }
	}
      }
    }
    cout << cnt << endl;
  }

  return 0;
}