fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. int main(){
  6. vector<ll> O, S, N;
  7. ll n, ans = 0; cin >> n;
  8.  
  9. for (ll i = 0; i < n; ++i){
  10. char huruf;
  11. cin >> huruf;
  12. if (huruf == 'O') O.push_back(i);
  13. else if (huruf == 'S') S.push_back(i);
  14. else N.push_back(i);
  15. }
  16.  
  17. ll bn = N.size();
  18. for (ll s : S){
  19. ll p = upper_bound(O.begin(), O.end(), s) - O.begin();
  20. ll q = lower_bound(N.begin(), N.end(), s) - N.begin();
  21. ans += p * (bn - q);
  22. }
  23. cout << ans;
  24. }
  25.  
Success #stdin #stdout 0.01s 5296KB
stdin
8
SONOSONO
stdout
2