// Arup Guha
// 2/21/2015 (written in contest)
// Solution to 2015 February USACO Bronze Problem: COW

import java.util.*;
import java.io.*;

public class cow {

	public static void main(String[] args) throws Exception {

		BufferedReader stdin = new BufferedReader(new FileReader("cow.in"));
		FileWriter fout = new FileWriter(new File("cow.out"));

		int n = Integer.parseInt(stdin.readLine().trim());
		String s = stdin.readLine();

        // Keeps track of all of these counts.
		long c = 0;
		long o = 0;
		long co = 0;
		long cow = 0;

        // Go through the string.
		for (int i=0; i<s.length(); i++) {

            // Only affects C count.
			if (s.charAt(i) == 'C') c++;

			// Affects both the o and co counts.
			else if (s.charAt(i) == 'O') {
				o++;
				co+= c;
			}

			// Finished some cows!
			else{
				cow += co;
			}
		}

		// Ta da!
		fout.write(cow+"\n");

		stdin.close();
		fout.close();
	}
}
