import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  }
} import java.util.Scanner; Scanner java.util public class Main {

  public static void main(String[] args) {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  }
} Main public static void main(String[] args) {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  } main {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  } try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    } {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    } Scanner scanner = new Scanner(System.in) Scanner scanner = new Scanner(System.in) new Scanner(System.in) while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      } true {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      } final int n n x; x 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;
        } break; int count = 0; count 0 for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        } int i = 1; int i = 1; i 1 i <= n - 2 i n - 2 n 2 i++ i++ i {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        } {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        } if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          } i > x i x {
            break;
          } break; if (i + 2 * n - 1 < x) {
            continue;
          } i + 2 * n - 1 < x i + 2 * n - 1 i + 2 * n i 2 * n 2 n 1 x {
            continue;
          } continue; for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          } int j = i + 1; int j = i + 1; j i + 1 i 1 j <= n - 1 j n - 1 n 1 j++ j++ j {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          } {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          } if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            } i + j > x i + j i j x {
              break;
            } break; if (i + j + n < x) {
              continue;
            } i + j + n < x i + j + n i + j + n i j n x {
              continue;
            } continue; for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            } 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) {
                count++;
                break;
              }
            } {
              if (i + j + k == x) {
                count++;
                break;
              }
            } if (i + j + k == x) {
                count++;
                break;
              } i + j + k == x i + j + k i + j + k i j k x {
                count++;
                break;
              } count++ count break; 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) {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  }
} public class Main {

  public static void main(String[] args) {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  }
} Main
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    try (Scanner scanner = new Scanner(System.in)) {
      while (true) {
        final int n, x;
        n = scanner.nextInt();
        x = scanner.nextInt();
        if (n == 0 && x == 0) {
          break;
        }
        int count = 0;
        for (int i = 1; i <= n - 2; i++) {
          if (i > x) {
            break;
          } else  if (i + 2 * n - 1 < x) {
            continue;
          }
          for (int j = i + 1; j <= n - 1; j++) {
            if (i + j > x) {
              break;
            } else if (i + j + n < x) {
              continue;
            }
            for (int k = j + 1; k <= n; k++) {
              if (i + j + k == x) {
                count++;
                break;
              }
            }
          }
        }
        System.out.println(count);
      }
    }

  }
}