import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   }//main
}//class import java.util.*; util.* java import java.text.*; text.* java public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   }//main
}//class Main public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   }//main main {
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String str; str String[] arr; arr int end; end int sum; sum int count; count while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      } true {
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      } str = sc.nextLine() str sc.nextLine() sc.nextLine sc arr = str.split(" ") arr str.split(" ") str.split str " " end = Integer.parseInt(arr[0]) end Integer.parseInt(arr[0]) Integer.parseInt Integer arr[0] arr 0 sum = Integer.parseInt(arr[1]) sum Integer.parseInt(arr[1]) Integer.parseInt Integer arr[1] arr 1 if(end == 0 && sum == 0){
            break;
         } end == 0 && sum == 0 end == 0 end 0 sum == 0 sum 0 {
            break;
         } break; count = 0 count 0 for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         } int i = 1; int i = 1; i 1 i <= end i end i++ i++ i {
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         } {
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         } for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            } int j = i + 1; int j = i + 1; j i + 1 i 1 j <= end j end j++ j++ j {
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            } {
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            } for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               } int k =j + 1; int k =j + 1; k j + 1 j 1 k <= end k end k++ k++ k {
                  if(i+j+k == sum){
                     count++;
                  }
               } {
                  if(i+j+k == sum){
                     count++;
                  }
               } if(i+j+k == sum){
                     count++;
                  } i+j+k == sum i+j+k i+j+k i j k sum {
                     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);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   }//main
}//class public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   }//main
}//class Main
import java.util.*;
import java.text.*;
/*
Main class for AOJ where there is no input.
*/
public class Main{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String str;
      String[] arr;
      
      int end;
      int sum;
      
      int count;
      
      while(true){
         str = sc.nextLine();
         arr = str.split(" ");
         
         end = Integer.parseInt(arr[0]);
         sum = Integer.parseInt(arr[1]);
         
         if(end == 0 && sum == 0){
            break;
         }
         
         count = 0;
         
         
         for(int i = 1; i <= end; i++){
            for(int j = i + 1; j <= end; j++){
               for(int k =j + 1; k <= end; k++){
                  if(i+j+k == sum){
                     count++;
                  }
               }
            }
         }
         
         System.out.println(count);
      }  
      
   }//main
}//class