Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- const LL MOD = 1000000007;
- const int maxn = 100000 + 100;
- int n, nxt, idx;
- LL ans;
- char str[maxn];
- LL len[maxn];
- int findNxt(int idx) {
- for (int i = idx + 1; i < n; ++i) {
- if (str[i] != str[i - 1] && str[i] != str[i - 1] + 1) {
- return i;
- }
- }
- return n;
- }
- int main() {
- #ifdef ExRoc
- freopen("test.txt", "r", stdin);
- #endif // ExRoc
- cin >> str;
- n = strlen(str);
- for (int i = 0; i < n; i = nxt) {
- nxt = findNxt(i);
- len[idx] = nxt - i;
- ans += len[idx] * (len[idx] + 1) / 2;
- ++idx;
- }
- for (int i = 1; i < idx; ++i) {
- ans += len[i] * len[i - 1];
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement