import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  }
} Main public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  } main {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  } try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    } {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int count = 0; count 0 int n n x; x String[] lines; lines while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      } true {

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      } lines = br.readLine().split(" ") lines br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt( lines[0] ) n Integer.parseInt( lines[0] ) Integer.parseInt Integer lines[0] lines 0 x = Integer.parseInt( lines[1] ) x Integer.parseInt( lines[1] ) Integer.parseInt Integer lines[1] lines 1 if( n == 0 && x == 0) break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        } 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++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        } {
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        } for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          } 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 ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          } {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          } for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            } 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 ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            } {
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            } if ( (i + j + k)  > x ) break; (i + j + k)  > x (i + j + k) i + j + k i j k x break; if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              } (i + j + k) == x (i + j + k) i + j + k i j k x {
                count++;
                // System.out.println( i + " " + j + " " + k);
              } count++ count System.out.println(count) System.out.println System.out System System.out count count = 0 count 0 String[] args args public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  }
} public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {

  public static void main(String[] args) throws IOException {
    try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ) {

      int count = 0;
      int n,x;
      String[] lines;

      while(true){

        lines = br.readLine().split(" ");
        n = Integer.parseInt( lines[0] );
        x = Integer.parseInt( lines[1] );
        if( n == 0 && x == 0) break;

        for( int i = 1; i < n-1; i++ ){
          for( int j = i+1; j < n; j++ ) {
            for( int k = j+1; k <= n; k++ ){
              if ( (i + j + k)  > x ) break;
              if ( (i + j + k) == x ){
                count++;
                // System.out.println( i + " " + j + " " + k);
              }
            }
          }
        }
        System.out.println(count);
        count = 0;
      }
    }
  }
}
