#include <iostream>
#include <string>
using namespace std;
bool zbalansowane(string text) {
    int t[3] = {};
    for (int i = 0; i < text.size(); i++) {
        t[text[i] - 'a']++;
    }
    for (int i = 1; i < 3; i++) {
        if (t[i] != 0 and t[i - 1] != 0) {
            if (t[i - 1] != t[i]) {
                return 0;
            }
        }
    }
    return 1;
}
int main()
{
    string text = "";
    cin >> text;
    int counter = 0;
    for (int i = 1; i <= text.size(); i++) {
        for (int j = 0; j <= text.size() - i; j++) {
            if (zbalansowane(text.substr(j, i))) {
                counter++;
            }
        }
    }
    cout << counter;
}
        | 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 | #include <iostream> #include <string> using namespace std; bool zbalansowane(string text) { int t[3] = {}; for (int i = 0; i < text.size(); i++) { t[text[i] - 'a']++; } for (int i = 1; i < 3; i++) { if (t[i] != 0 and t[i - 1] != 0) { if (t[i - 1] != t[i]) { return 0; } } } return 1; } int main() { string text = ""; cin >> text; int counter = 0; for (int i = 1; i <= text.size(); i++) { for (int j = 0; j <= text.size() - i; j++) { if (zbalansowane(text.substr(j, i))) { counter++; } } } cout << counter; } | 
 
            
         English
                    English