import java.util.Scanner;

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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int n = sc.nextInt();
      int x = sc.nextInt();
      int ans = 0;
      if (n == 0 && x == 0) break;
      for (int i = 1; i < n+1; i++) {
        for (int j = i+1; j < n+1; j++) {
          for (int k = j+1; k < n+1; k++) {
            if (i+j+k == x) ans++;
          }
        }
      }
      System.out.println(ans);
    }
  }
}

