import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    }
}
 import java.util.*; util.* java import java.io.*; io.* java public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    }
} Main public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    } main {
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n; n int x; x int con; con while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    } true {
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    } n = scanner.nextInt() n scanner.nextInt() scanner.nextInt scanner x = scanner.nextInt() x scanner.nextInt() scanner.nextInt scanner if(n==0&&x==0)break; n==0&&x==0 n==0 n 0 x==0 x 0 break; con = 0 con 0 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+k == x){
              con++;
            }
          }
        }
      } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
        for(int j=i+1;j<=n;j++){
          for(int k=j+1;k<=n;k++){
            if(i+j+k == x){
              con++;
            }
          }
        }
      } {
        for(int j=i+1;j<=n;j++){
          for(int k=j+1;k<=n;k++){
            if(i+j+k == x){
              con++;
            }
          }
        }
      } for(int j=i+1;j<=n;j++){
          for(int k=j+1;k<=n;k++){
            if(i+j+k == x){
              con++;
            }
          }
        } int j=i+1; int j=i+1; j i+1 i 1 j<=n j n j++ j++ j {
          for(int k=j+1;k<=n;k++){
            if(i+j+k == x){
              con++;
            }
          }
        } {
          for(int k=j+1;k<=n;k++){
            if(i+j+k == x){
              con++;
            }
          }
        } for(int k=j+1;k<=n;k++){
            if(i+j+k == x){
              con++;
            }
          } int k=j+1; int k=j+1; k j+1 j 1 k<=n k n k++ k++ k {
            if(i+j+k == x){
              con++;
            }
          } {
            if(i+j+k == x){
              con++;
            }
          } if(i+j+k == x){
              con++;
            } i+j+k == x i+j+k i+j+k i j k x {
              con++;
            } con++ con System.out.println(con) System.out.println System.out System System.out con String[] args args public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    }
} public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    }
} Main
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n;
    int x;
    int con;

    while(true){
      n = scanner.nextInt();
      x = scanner.nextInt();
      if(n==0&&x==0)break;

      con = 0;
      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+k == x){
              con++;
            }
          }
        }
      }
      System.out.println(con);
    }

    }
}

