fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. const ll mod = 1e9 + 7;
  5.  
  6. void add(ll &a, ll b){
  7. if((a += b) >= mod) a -= mod;
  8. }
  9.  
  10.  
  11. const ll inf = 1e18;
  12. const ll lim = 1e7 + 5;
  13. const ll N = 2e5 + 5;
  14.  
  15. int main()
  16. {
  17. ios_base::sync_with_stdio(0);
  18. cout.tie(0);cin.tie(0);
  19.  
  20. int n; cin >> n;
  21. string s; cin >> s;
  22. s = s + s;
  23. if(n % 2 == 1){
  24. cout << 0;
  25. return 0;
  26. }
  27.  
  28. int ans = 0;
  29. for(int i = 0; i < n; i++){
  30. int right = i + n - 1;
  31. int cnt_D = 0, cnt_S = 0;
  32. for(int j = i; j <= right; j++){
  33. if(s[j] == 'D') cnt_D++;
  34. else cnt_D++;
  35. }
  36.  
  37. int D = 0, S = 0;
  38. // cout << i << " " << right << '\n';
  39. for(int j = i; j <= (i + right) / 2; j++){
  40. if(s[j] == 'D') D++;
  41. else S++;
  42. }
  43. // cout << S << " " << D << " " << '\n';
  44. if(D == cnt_D / 2 && S == cnt_S / 2) ans++;
  45. }
  46. cout << ans;
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty