n=gets.to_i s=gets.chomp ans=0 0.upto(n-3){|i| next unless s[i]==?U (i+2).upto(n-1){|k| next unless s[k]==?G next if (i+k).odd? ans+=1 if s[(i+k)/2]==?M } } puts ans