#include #include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string S; cin >> S; const int N = S.size(); vector ds{1}; int tmp = N; for (int d = 2; d <= tmp; ++d) { if (tmp % d == 0) { ds.push_back(N / d); while (tmp % d == 0) tmp /= d; } } if (tmp != 1) ds.push_back(N / tmp); int ret = N + 1; auto argmin = S; for (int d : ds) { if (d == N) continue; int cost = 0; string tmp = S; for (int h = 0; h < d; ++h) { vector cntr(26); for (int i = h; i < N; i += d) cntr[S[i] - 'A']++; int maxi = max_element(cntr.begin(), cntr.end()) - cntr.begin(); for (int i = h; i < N; i += d) { if (S[i] - 'A' != maxi) { tmp[i] = char('A' + maxi); cost++; } } } if (cost < ret) { ret = cost; argmin = tmp; } } cout << argmin << '\n'; }