program zht;
var
bj,n,i,j,g,p,q:longint;
ans:int64;
z:ansistring;
begin
assign(input,'cowa.in');
assign(output,'cowa.out');
reset(input);
rewrite(output);
readln(n);
readln(z);
for i:=1 to n do
begin
if z[i]='O' then begin
for j:=1 to i do
if z[j]='C' then p:=p+1;
for g:=i+1 to n do
if z[g]='W' then q:=q+1;
ans:=ans+p*q;
bj:=i+1;
break;
end;
end;
for i:=bj to n do
begin
if z[i]='C' then p:=p+1;
if z[i]='W' then q:=q-1;
if z[i]='O' then ans:=ans+p*q;
end;
writeln(ans);
close(input);
close(output);
end.