import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     while(true)
     {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     }
     
   }
   static void output(int n,int x)
   {
     int answer = 0;
     
     for(int i = 1; i <= n - 2; i ++)
     {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     }
     System.out.println(answer);
   }
 }
   import java.util.*; util.* java class Main
 {
   public static void main(String args[])
   { 
    input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     while(true)
     {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     }
     
   }
   static void output(int n,int x)
   {
     int answer = 0;
     
     for(int i = 1; i <= n - 2; i ++)
     {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     }
     System.out.println(answer);
   }
 } Main public static void main(String args[])
   { 
    input();
   } main { 
    input();
   } input() input String args[] args static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     while(true)
     {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     }
     
   } input {
     Scanner sc = new Scanner(System.in);
     
     while(true)
     {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     }
     
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while(true)
     {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     } true {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     } int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc if(n == 0 && x == 0)break; n == 0 && x == 0 n == 0 n 0 x == 0 x 0 break; output(n,x) output n x static void output(int n,int x)
   {
     int answer = 0;
     
     for(int i = 1; i <= n - 2; i ++)
     {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     }
     System.out.println(answer);
   } output {
     int answer = 0;
     
     for(int i = 1; i <= n - 2; i ++)
     {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     }
     System.out.println(answer);
   } int answer = 0; answer 0 for(int i = 1; i <= n - 2; i ++)
     {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     } int i = 1; int i = 1; i 1 i <= n - 2 i n - 2 n 2 i ++ i ++ i {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     } {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     } for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       } int j = i + 1; int j = i + 1; j i + 1 i 1 j <= n - 1 j n - 1 n 1 j ++ j ++ j {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       } {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       } for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         } int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n k ++ k ++ k {
           if(i + k + j == x)
           {
             answer ++;
           }
         } {
           if(i + k + j == x)
           {
             answer ++;
           }
         } if(i + k + j == x)
           {
             answer ++;
           } i + k + j == x i + k + j i + k + j i k j x {
             answer ++;
           } answer ++ answer System.out.println(answer) System.out.println System.out System System.out answer int n n int x x
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    input();
   }
   static void input()
   {
     Scanner sc = new Scanner(System.in);
     
     while(true)
     {
       int n = sc.nextInt();
       
       int x = sc.nextInt();
       
       if(n == 0 && x == 0)break;
       
       output(n,x);
     }
     
   }
   static void output(int n,int x)
   {
     int answer = 0;
     
     for(int i = 1; i <= n - 2; i ++)
     {
       for(int j = i + 1; j <= n - 1; j ++)
       {
         for(int k = j + 1; k <= n; k ++)
         {
           if(i + k + j == x)
           {
             answer ++;
           }
         }
       }
     }
     System.out.println(answer);
   }
 }
  
