Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // In The Name of Almighty Allah
- #include<bits/stdc++.h>
- using namespace std;
- #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define ff first
- #define ss second
- #define int long long
- #define pb push_back
- #define pf push_front
- #define pii pair<int,int>
- #define print(x) for(auto it : x) cout<<it<<' '; cout<<'\n';
- #define debug(x) cout << #x << " --->> " << x << endl;
- #define mod 1000000007
- #define inf 1e18
- #define PI (acos(-1))
- #define eps (1e-8)
- #define clear(x) memset(x,0,sizeof(x));
- main()
- {
- fastio;
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n;
- string s;
- cin >> n;
- cin >> s;
- pair<int, pii>cum[n];
- int ans = 0, r = 0, g = 0, b = 0;
- for (int i = 0; i < n; i++)
- {
- if (s[i] == 'R') r++;
- else if (s[i] == 'B') b++;
- else g++;
- cum[i].ff = r, cum[i].ss.ff = g, cum[i].ss.ss = b;
- }
- for (int i = 0; i < n; i++)
- {
- for (int j = i + 1; j < n - 1; j++)
- {
- if (s[j] == s[i]) continue;
- int k = 2 * j - i;
- // debug(k);
- if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R'))
- {
- ans += (cum[n - 1].ss.ss - cum[j].ss.ss);
- if (k < n && s[k] == 'B')
- ans--;
- }
- else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R'))
- {
- ans += (cum[n - 1].ss.ff - cum[j].ss.ff);
- if (k < n && s[k] == 'G')
- ans--;
- }
- else if ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G'))
- {
- ans += (cum[n - 1].ff - cum[j].ff);
- if (k < n && s[k] == 'R')
- ans--;
- }
- }
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement