import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  }
} Main public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  } main {
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  } Scanner in=new Scanner(System.in); in new Scanner(System.in) int n n sum; sum while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  } true {
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  } int count = 0; count 0 n = in.nextInt() n in.nextInt() in.nextInt in sum = in.nextInt() sum in.nextInt() in.nextInt in if(n==0 && sum==0)break; n==0 && sum==0 n==0 n 0 sum==0 sum 0 break; for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      } int i=1; int i=1; i 1 i<n-1 i n-1 n 1 i++ i++ i {
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      } {
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      } for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        } int j=i+1; int j=i+1; j i+1 i 1 j<n j n j++ j++ j {
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        } {
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        } int r =sum - i - j; r sum - i - j sum - i - j sum i j if(r>j && r<=n)
        count++; r>j && r<=n r>j r j r<=n r n count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main{
  public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  }
} public class Main{
  public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  }
} Main
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
  Scanner in=new Scanner(System.in);

  int n, sum;

  while(true){
  int count = 0;
  n = in.nextInt();
  sum = in.nextInt();

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

    for(int i=1;i<n-1;i++){
      for(int j=i+1;j<n;j++){
      int r =sum - i - j;
        if(r>j && r<=n)
        count++;
        }
      }
    System.out.println(count);
  }
  }
}