#include <iostream>
#include <string>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    if (!(cin >> N)) return 0;

    string S;
    cin >> S;

    long long countO = 0;
    long long countOS = 0;
    long long ans = 0;

    for (char c : S) {
        if (c == 'O') {
            countO++;
        } else if (c == 'S') {
            countOS += countO;
        } else if (c == 'N') {
            ans += countOS;
        }
    }

    cout << ans << "\n";

    return 0;
}