import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n, sum;
    
    while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    }
  }
}
     import java.util.Scanner; Scanner java.util class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n, sum;
    
    while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    }
  }
} Main public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n, sum;
    
    while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    }
  } main {
    Scanner in = new Scanner(System.in);
    int n, sum;
    
    while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    }
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) int n n sum; sum while(in.hasNext()) {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      }
      System.out.println(count);
    } in.hasNext() in.hasNext in {
      int count = 0;
      n = in.nextInt();
      sum = in.nextInt();
      if (n == 0 && sum == 0) return;
      
      for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= 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) return; n == 0 && sum == 0 n == 0 n 0 sum == 0 sum 0 return; for (int i = 1; i < n -1; i++) {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= 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 rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      } {
        for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        }
      } for (int j = i + 1; j < n; j++) {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        } int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        } {
          int rest = sum - i -j;
          if (rest > j && rest <= n) count++;
        } int rest = sum - i -j; rest sum - i -j sum - i -j sum i j if (rest > j && rest <= n) count++; rest > j && rest <= n rest > j rest j rest <= n rest n count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

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