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.  
  14. else if (huruf == 'S') S.push_back(i);
  15.  
  16. else N.push_back(i);
  17.  
  18. }
  19.  
  20. ll bn = N.size();
  21.  
  22. for (ll s : S){
  23. ll p = upper_bound(O.begin(), O.end(), s) - O.begin();
  24. ll q = lower_bound(N.begin(), N.end(), s) - N.begin();
  25. ans += p * (bn - q);
  26.  
  27. }
  28.  
  29. cout << ans;
  30.  
  31. }
  32.  
Success #stdin #stdout 0.01s 5280KB
stdin
8
SONOSONO
stdout
2