import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n;
    int x;
    String[] s;
    Integer[] numbers;
    int sum;
    int numAnswers = 0;
    while (true) {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    }
  }
}

class Combinations<T> implements Iterator{

  private List<List<T>> combinations;
  private List<T> list;
  private int[] index;
  private boolean[] visited;
  private int r;
  private Iterator<List<T>> iterator;

  public Combinations(T[] array, int r){
    this.list = Arrays.asList(array);
    this.index = new int[r];
    this.visited = new boolean[array.length];
    this.combinations = new ArrayList<List<T>>();
    this.r = r;
    this.compute(0);
    this.iterator = this.combinations.iterator();
  }

  private void compute(int n){
    if(n == r){
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    }
    else{
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    }
  }

  public List<List<T>> getCombinations(){
    return this.combinations;
  }

  public int count(){
    return this.combinations.size();
  }

  public List<T> next(){
    return this.iterator.next();
  }

  public boolean hasNext(){
    return this.iterator.hasNext();
  }

  public Iterator<List<T>> iterator(){
    return this.iterator;
  }

  public void remove(){
  }
} import java.util.*; util.* java class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n;
    int x;
    String[] s;
    Integer[] numbers;
    int sum;
    int numAnswers = 0;
    while (true) {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    }
  }
} Main public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n;
    int x;
    String[] s;
    Integer[] numbers;
    int sum;
    int numAnswers = 0;
    while (true) {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n;
    int x;
    String[] s;
    Integer[] numbers;
    int sum;
    int numAnswers = 0;
    while (true) {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n; n int x; x String[] s; s Integer[] numbers; numbers int sum; sum int numAnswers = 0; numAnswers 0 while (true) {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    } true {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    } s = sc.nextLine().split(" ") s sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " n = Integer.parseInt(s[0]) n Integer.parseInt(s[0]) Integer.parseInt Integer s[0] s 0 x = Integer.parseInt(s[1]) x Integer.parseInt(s[1]) Integer.parseInt Integer s[1] s 1 if (n == 0 && x == 0) {
        break;
      } n == 0 && x == 0 n == 0 n 0 x == 0 x 0 {
        break;
      } break; numbers = new Integer[n] numbers new Integer[n] n for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        numbers[i] = i + 1;
      } {
        numbers[i] = i + 1;
      } numbers[i] = i + 1 numbers[i] numbers i i + 1 i 1 Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3); combinations new Combinations<Integer>(numbers, 3) Iterator<List<Integer>> iterator = combinations.iterator(); iterator combinations.iterator() combinations.iterator combinations while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      } iterator.hasNext() iterator.hasNext iterator {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      } List<Integer> p = iterator.next(); p iterator.next() iterator.next iterator sum = p.get(0) + p.get(1) + p.get(2) sum p.get(0) + p.get(1) + p.get(2) p.get(0) + p.get(1) + p.get(2) p.get(0) p.get p 0 p.get(1) p.get p 1 p.get(2) p.get p 2 if (sum == x) {
          numAnswers++;
        } sum == x sum x {
          numAnswers++;
        } numAnswers++ numAnswers System.out.println(numAnswers) System.out.println System.out System System.out numAnswers numAnswers = 0 numAnswers 0 String args[] args class Combinations<T> implements Iterator{

  private List<List<T>> combinations;
  private List<T> list;
  private int[] index;
  private boolean[] visited;
  private int r;
  private Iterator<List<T>> iterator;

  public Combinations(T[] array, int r){
    this.list = Arrays.asList(array);
    this.index = new int[r];
    this.visited = new boolean[array.length];
    this.combinations = new ArrayList<List<T>>();
    this.r = r;
    this.compute(0);
    this.iterator = this.combinations.iterator();
  }

  private void compute(int n){
    if(n == r){
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    }
    else{
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    }
  }

  public List<List<T>> getCombinations(){
    return this.combinations;
  }

  public int count(){
    return this.combinations.size();
  }

  public List<T> next(){
    return this.iterator.next();
  }

  public boolean hasNext(){
    return this.iterator.hasNext();
  }

  public Iterator<List<T>> iterator(){
    return this.iterator;
  }

  public void remove(){
  }
} Combinations private List<List<T>> combinations; combinations private List<T> list; list private int[] index; index private boolean[] visited; visited private int r; r private Iterator<List<T>> iterator; iterator public Combinations(T[] array, int r){
    this.list = Arrays.asList(array);
    this.index = new int[r];
    this.visited = new boolean[array.length];
    this.combinations = new ArrayList<List<T>>();
    this.r = r;
    this.compute(0);
    this.iterator = this.combinations.iterator();
  } Combinations {
    this.list = Arrays.asList(array);
    this.index = new int[r];
    this.visited = new boolean[array.length];
    this.combinations = new ArrayList<List<T>>();
    this.r = r;
    this.compute(0);
    this.iterator = this.combinations.iterator();
  } this.list = Arrays.asList(array) this.list this this.list Arrays.asList(array) Arrays.asList Arrays array this.index = new int[r] this.index this this.index new int[r] r this.visited = new boolean[array.length] this.visited this this.visited new boolean[array.length] array.length array array.length this.combinations = new ArrayList<List<T>>() this.combinations this this.combinations new ArrayList<List<T>>() this.r = r this.r this this.r r this.compute(0) this.compute this 0 this.iterator = this.combinations.iterator() this.iterator this this.iterator this.combinations.iterator() this.combinations.iterator this.combinations this this.combinations T[] array array int r r private void compute(int n){
    if(n == r){
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    }
    else{
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    }
  } compute {
    if(n == r){
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    }
    else{
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    }
  } if(n == r){
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    }
    else{
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    } n == r n r {
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    } List<T> combination = new ArrayList<T>(); combination new ArrayList<T>() for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      } int i = 0; int i = 0; i 0 i < this.index.length i this.index.length this.index this this.index this.index.length i++ i++ i {
        combination.add(list.get(index[i]));
      } {
        combination.add(list.get(index[i]));
      } combination.add(list.get(index[i])) combination.add combination list.get(index[i]) list.get list index[i] index i combinations.add(combination) combinations.add combinations combination {
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    } for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      } int i = 0; int i = 0; i 0 i < this.list.size() i this.list.size() this.list.size this.list this this.list i++ i++ i {
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      } {
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      } if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        } n == 0 || !this.visited[i] && index[n - 1] < i n == 0 n 0 !this.visited[i] && index[n - 1] < i !this.visited[i] this.visited[i] this.visited this this.visited i index[n - 1] < i index[n - 1] index n - 1 n 1 i {
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        } this.visited[i] = true this.visited[i] this.visited this this.visited i true this.index[n] = i this.index[n] this.index this this.index n i this.compute(n + 1) this.compute this n + 1 n 1 this.visited[i] = false this.visited[i] this.visited this this.visited i false int n n public List<List<T>> getCombinations(){
    return this.combinations;
  } getCombinations {
    return this.combinations;
  } return this.combinations; this.combinations this this.combinations public int count(){
    return this.combinations.size();
  } count {
    return this.combinations.size();
  } return this.combinations.size(); this.combinations.size() this.combinations.size this.combinations this this.combinations public List<T> next(){
    return this.iterator.next();
  } next {
    return this.iterator.next();
  } return this.iterator.next(); this.iterator.next() this.iterator.next this.iterator this this.iterator public boolean hasNext(){
    return this.iterator.hasNext();
  } hasNext {
    return this.iterator.hasNext();
  } return this.iterator.hasNext(); this.iterator.hasNext() this.iterator.hasNext this.iterator this this.iterator public Iterator<List<T>> iterator(){
    return this.iterator;
  } iterator {
    return this.iterator;
  } return this.iterator; this.iterator this this.iterator public void remove(){
  } remove {
  } Iterator
import java.util.*;

class Main {
  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n;
    int x;
    String[] s;
    Integer[] numbers;
    int sum;
    int numAnswers = 0;
    while (true) {
      s = sc.nextLine().split(" ");
      n = Integer.parseInt(s[0]); 
      x = Integer.parseInt(s[1]); 
      if (n == 0 && x == 0) {
        break;
      }
      numbers = new Integer[n];
      for (int i = 0; i < n; i++) {
        numbers[i] = i + 1;
      }
      Combinations<Integer> combinations = new Combinations<Integer>(numbers, 3);
      Iterator<List<Integer>> iterator = combinations.iterator();
      while(iterator.hasNext()) {
        List<Integer> p = iterator.next();
        sum = p.get(0) + p.get(1) + p.get(2);
        if (sum == x) {
          numAnswers++;
        }
      }
      System.out.println(numAnswers);
      numAnswers = 0;
    }
  }
}

class Combinations<T> implements Iterator{

  private List<List<T>> combinations;
  private List<T> list;
  private int[] index;
  private boolean[] visited;
  private int r;
  private Iterator<List<T>> iterator;

  public Combinations(T[] array, int r){
    this.list = Arrays.asList(array);
    this.index = new int[r];
    this.visited = new boolean[array.length];
    this.combinations = new ArrayList<List<T>>();
    this.r = r;
    this.compute(0);
    this.iterator = this.combinations.iterator();
  }

  private void compute(int n){
    if(n == r){
      List<T> combination = new ArrayList<T>();
      for(int i = 0;i < this.index.length;i++){
        combination.add(list.get(index[i]));
      }
      combinations.add(combination);
    }
    else{
      for(int i = 0;i < this.list.size();i++){
        if(n == 0 || !this.visited[i] && index[n - 1] < i){
          this.visited[i] = true;
          this.index[n] = i;
          this.compute(n + 1);
          this.visited[i] = false;
        }
      }
    }
  }

  public List<List<T>> getCombinations(){
    return this.combinations;
  }

  public int count(){
    return this.combinations.size();
  }

  public List<T> next(){
    return this.iterator.next();
  }

  public boolean hasNext(){
    return this.iterator.hasNext();
  }

  public Iterator<List<T>> iterator(){
    return this.iterator;
  }

  public void remove(){
  }
}