1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream> 
#include <vector>
#include <string>
#include <cstring>

using namespace std;

const int MAXN = 300010;

int main() {
    string s;
    cin >> s;

    int vs[MAXN] = {};
    int prev[MAXN] = {};
    int cc[26] = {};
    
    for (int i = 0; i < s.length(); i++) {
        memset(cc, 0, 26);
        
        for (int j = i; j < s.length(); j++) {
            cc[s[j] - 'a']++;

            int local = 1;
            int nonzero = -1;
            for(int k = 0; k < 26; k++) {
                if (cc[k] != 0) {
                    if (nonzero != -1) {
                        if (cc[nonzero] != cc[k]) {
                            local = 0;
                        }
                    }
                    nonzero = k;
                }
            }
            
            vs[j] = vs[j] + local;
        }
    }

    int mx = 0;
    for(int i = 0; i < s.length(); i++) {
        mx += vs[i]; 
    }

    cout << mx << '\n';
    return 0;
}