fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false);
  8. cin.tie(NULL);
  9.  
  10. int N;
  11. if (!(cin >> N)) return 0;
  12.  
  13. string S;
  14. cin >> S;
  15.  
  16. long long countO = 0;
  17. long long countOS = 0;
  18. long long ans = 0;
  19.  
  20. for (char c : S) {
  21. if (c == 'O') {
  22. countO++;
  23. } else if (c == 'S') {
  24. countOS += countO;
  25. } else if (c == 'N') {
  26. ans += countOS;
  27. }
  28. }
  29.  
  30. cout << ans << "\n";
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5312KB
stdin
8
SONOSONO
stdout
2