import java.util.*;

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

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    } main {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        } int i = 0; int i = 0; i 0 i < 1 i 1 i = 0 i = 0 i 0 {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        } {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        } String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc String[] l = line.split(" "); l line.split(" ") line.split line " " int n = Integer.parseInt(l[0]); n Integer.parseInt(l[0]) Integer.parseInt Integer l[0] l 0 int x = Integer.parseInt(l[1]); x Integer.parseInt(l[1]) Integer.parseInt Integer l[1] l 1 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 a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          } int a = 1; int a = 1; a 1 a <= n - 2 a n - 2 n 2 a++ a++ a {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          } {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          } for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            } int b = a + 1; int b = a + 1; b a + 1 a 1 b <= n - 1 b n - 1 n 1 b++ b++ b {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            } {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            } for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              } int c = b + 1; int c = b + 1; c b + 1 b 1 c <= n c n c++ c++ c {
                if(a + b + c == x) {
                  count++;
                }
              } {
                if(a + b + c == x) {
                  count++;
                }
              } if(a + b + c == x) {
                  count++;
                } a + b + c == x a + b + c a + b + c a b c x {
                  count++;
                } count++ count 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) {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    }
} Main
import java.util.*;

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

        Scanner sc = new Scanner(System.in);

        for(int i = 0; i < 1; i = 0) {
          String line = sc.nextLine();
          String[] l = line.split(" ");
          int n = Integer.parseInt(l[0]);
          int x = Integer.parseInt(l[1]);

          if(n == 0 && x == 0) {
            break;
          }

          int count = 0;
          for(int a = 1; a <= n - 2; a++) {
            for(int b = a + 1; b <= n - 1; b++) {
              for(int c = b + 1; c <= n; c++) {
                if(a + b + c == x) {
                  count++;
                }
              }
            }
          }

          System.out.println(count);
        }
    }
}