fork download
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. using namespace std ;
  4. int main()
  5. {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(0);
  8. cout.tie(0);
  9. freopen("CLS.INP","r",stdin);
  10. freopen("CLS.OUT","w",stdout);
  11. string s ;
  12. // CHAO CHUYEN LAM SON
  13. getline(cin,s);
  14. ll len = s.length();
  15. vector<ll>prec(len+3,0);
  16. vector<ll>pres(len+3,0);
  17. prec[0]=0;
  18. pres[len+1]=0;
  19. prec[0]=0;
  20. if(s[0]=='C')
  21. {
  22. prec[0]++;
  23. }
  24. for(ll i= 1 ; i<len;i++)
  25. {
  26. if(s[i]=='C')
  27. {
  28. prec[i]=prec[i-1]+1;
  29. }
  30. else
  31. {
  32. prec[i]=prec[i-1];
  33. }
  34. }
  35.  
  36. for(ll i =len-1;i>=0;i--)
  37. {
  38. if(s[i]=='S')
  39. {
  40. pres[i]=pres[i+1]+1;
  41. }
  42. else
  43. pres[i]=pres[i+1];
  44. }
  45. ll res = 0 ;
  46. for(ll i = 0;i<len;i++)
  47. {
  48. if(s[i]=='L')
  49. {
  50. res+=pres[i]*prec[i];
  51. }
  52. }
  53. cout<<res<<endl;
  54. return 0;
  55. }
  56.  
Success #stdin #stdout 0.01s 5260KB
stdin
Standard input is empty
stdout
Standard output is empty