import java.io.*;
import java.util.*;

class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        }
    }
} import java.io.*; io.* java import java.util.*; util.* java class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        }
    }
} Main public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        }
    } main {
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(true){
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        } true {
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        } int s = 0; s 0 int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan if(n == 0){
                break;
            } n == 0 n 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 + k == x){
                            ++s;
                        }
                    }
                }
            } 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 + k == x){
                            ++s;
                        }
                    }
                }
            } {
                for(int j = i + 1; j <= n; ++j){
                    for(int k = j + 1; k <= n; ++k){
                        if(i + j + k == x){
                            ++s;
                        }
                    }
                }
            } for(int j = i + 1; j <= n; ++j){
                    for(int k = j + 1; k <= n; ++k){
                        if(i + j + k == x){
                            ++s;
                        }
                    }
                } 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 + k == x){
                            ++s;
                        }
                    }
                } {
                    for(int k = j + 1; k <= n; ++k){
                        if(i + j + k == x){
                            ++s;
                        }
                    }
                } for(int k = j + 1; k <= n; ++k){
                        if(i + j + k == x){
                            ++s;
                        }
                    } int k = j + 1; int k = j + 1; k j + 1 j 1 k <= n k n ++k ++k k {
                        if(i + j + k == x){
                            ++s;
                        }
                    } {
                        if(i + j + k == x){
                            ++s;
                        }
                    } if(i + j + k == x){
                            ++s;
                        } i + j + k == x i + j + k i + j + k i j k x {
                            ++s;
                        } ++s s System.out.println(s) System.out.println System.out System System.out s String [] args args
import java.io.*;
import java.util.*;

class Main {
    public static void main(String [] args){
        Scanner scan = new Scanner(System.in);
        
        while(true){
            int s = 0;
            int n = scan.nextInt();
            int x = scan.nextInt();
            
            if(n == 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 + k == x){
                            ++s;
                        }
                    }
                }
            }
            
            System.out.println(s);
        }
    }
}