#include "testlib.h"
#include <bits/stdc++.h>

using namespace std;

const int MIN_N = 1;
const int MAX_N = 1000;
const int rnd_test_n = 30;

template <typename T> void append(vector<T> &dest, const vector<T> &orig) {
    dest.insert(dest.end(), orig.begin(), orig.end());
}

string output_tc(const string &s) {
    ostringstream oss;
    oss << s.size() << endl;
    oss << s << endl;
    return oss.str();
}

vector<string> generate_sample_tests() {
    vector<string> tests;
    tests.push_back(output_tc("bbbab"));
    tests.push_back(output_tc("cbbd"));
    tests.push_back(output_tc("a"));
    return tests;
}

vector<string> generate_manual_tests() {
    vector<string> tests;
    return tests;
}

string generate_structured_string(int n) {
    string s = "";
    
    if (rnd.next(0, 1) == 1) {
        string half = rnd.next("[a-z]{" + to_string((n + 1) / 2) + "}");
        s = half;
        reverse(half.begin(), half.end());
        s += half;
        for (int i = 0; i < n / 10; i++) {
            s[rnd.next(0, n - 1)] = rnd.next('a', 'z');
        }
    } 
    else {
        s = rnd.next("[a-z]{" + to_string(n) + "}");
    }
    return s;
}

string rnd_test(int i) {
    int min_n = MIN_N;
    int max_n = MAX_N;
    
    if (i < rnd_test_n / 3) {
        max_n = 10;
    } else if (i < rnd_test_n / 2) {
        max_n = 100;
    }
    
    int n = rnd.next(min_n, max_n);
    return output_tc(generate_structured_string(n));
}

vector<string> generate_random_tests() { 
    vector<string> tests;
    for (int i = 0; i < rnd_test_n; i++) {
        tests.push_back(rnd_test(i));
    } 
    return tests;
}

vector<string> generate_extreme_tests() {
    vector<string> tests;
    tests.push_back(output_tc(string(1000, 'a')));
    tests.push_back(output_tc(rnd.next("[a-z]{1000}")));
    return tests;
}

int main(int argc, char *argv[]) {
    registerGen(argc, argv, 1);
    vector<string> tests;
    size_t test = 0;

    append(tests, generate_sample_tests());
    append(tests, generate_manual_tests());
    append(tests, generate_random_tests());
    append(tests, generate_extreme_tests());

    for (const auto &t : tests) {
        startTest(++test);
        cout << t;
    }
    return 0;
}