import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T[]readarr(T=long)(){return readln.chomp.split.to!(T[]);}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
struct Queue(T){T[]e;auto enq(T t){e~=t;}auto enq(T[]ts){e~=ts;}T deq(){T tp=e[0];e=e.length>1?e[1..$]:[];return tp;}}
struct Stack(T){T[]e;auto push(T t){e~=t;}auto push(T[]ts){e~=ts;}T pop(){T tp=e[$-1];e=e.length>1?e[0..$-1]:[];return tp;}}
//END OF TEMPLATE

void main(){
    bool[size_t][size_t][size_t] table;
    readln;
    auto s=readln.chomp;
    auto n=s.length;
    auto psum=n*(n-1)*(n-2)/6;

    foreach(i;0..n-1){
        foreach(j;i+1..n){
            if(j*2-i<n)
                table[i][j][j*2-i]=true;
            if(s[i]==s[j])
                n.iota.each!(k=>table[i][j][k]=true);
        }
    }   

    long sum;
    foreach(i;0..n-2){
        if(i in table){
            foreach(j;i+1..n-1){
                if(j in table[i]){
                    foreach(k;j+1..n){
                        if(k in table[i][j]){
                            if(table[i][j][k]==true){
                                sum++;
                            }
                        }
                    }
                }
            }
        }
    }
    (psum-sum).writeln;
}
