import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  }

  }
} import java.io.*; io.* java class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  }

  }
} Main public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  }

  } main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  }

  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  } true {
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  } String str1 = br.readLine(); str1 br.readLine() br.readLine br String[] str2 = str1.split(" "); str2 str1.split(" ") str1.split str1 " " int n = Integer.parseInt(str2[0]); n Integer.parseInt(str2[0]) Integer.parseInt Integer str2[0] str2 0 int x = Integer.parseInt(str2[1]); x Integer.parseInt(str2[1]) Integer.parseInt Integer str2[1] str2 1 int count = 0; count 0 if (n == 0 && x == 0) {break;} n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {break;} break; for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    } {
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    } for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      } 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 || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      } {
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      } for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        } int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k++ k++ k {
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        } {
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        } if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;} i == j || j == k || k == i i == j || j == k || k == i i == j i j j == k j k k == i k i {break;} break; if (i + j + k == x){count++;} i + j + k == x i + j + k i + j + k i j k x {count++;} count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder sb = new StringBuilder();

    while(true){
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int n = Integer.parseInt(str2[0]);
    int x = Integer.parseInt(str2[1]);
    int count = 0;
    if (n == 0 && x == 0) {break;}
    for (int i = 1; i <= n; i++){
      for (int j = i + 1; j <= n; j++){
        for (int k = j + 1; k <= n; k++){
          if (i == j || j == k || k == i){break;}
          else if (i + j + k == x){count++;}
        }
      }
    }
    System.out.println(count);
  }

  }
}