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
49
50
51
52
53
54
55
#include <iostream>

#define DEBUG 0

using namespace std;

int main()
{
#if !DEBUG
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    string word;
    cin >> word;
    const int word_length = word.length();
    int *next_three = new int [word_length + 3];
    next_three[word_length+2] = next_three[word_length+1] = next_three[word_length] = word_length;

    bool vowel [26]{};
    vowel[0] = vowel[4] = vowel[8] = vowel[14] = vowel[20] = vowel[24] = 1;

    for(int i = word_length-1; i > 1; i--)
        if(vowel[word[i] - 97] && vowel[word[i-1] - 97] && vowel[word[i-2] - 97] ||
            !vowel[word[i] - 97] && !vowel[word[i-1] - 97] && !vowel[word[i-2] - 97])
            next_three[i] = i;
        else
            next_three[i] = next_three[i+1];

    next_three[0] = next_three[1] = next_three[2];

#if DEBUG
    cout << "PREFIX ARRAY\n";
    for(int i = 0; i <= word_length+1; i++)
        cout << i << ". " << next_three[i] << endl;
    cout << string(15, '=') << endl << "VALUES\n";
#endif // DEBUG
    long long counter = 0;
    for(int i = 0; i < word_length; i++)
    {
        if(next_three[i] > i+1)
            counter += next_three[i] - i;
        else if((next_three[ next_three[i] + 1]) > i+1)
            counter += next_three[ next_three[i] + 1] - i;
            else
                counter += next_three[ next_three[i] + 2] - i;
#if DEBUG
        cout << i << ". " << counter << endl;
#endif // DEBUG
    }

    cout << (((long long)word_length * ((long long)word_length + 1)) / 2) - counter << endl;

    delete [] next_three;
    return 0;
}