#include int main() { using namespace std; string S; cin >> S; const unsigned N(size(S)); string ans{}; auto prefix_min{numeric_limits::max()}; unsigned repeat{}; for (const auto p : [](unsigned N) { const auto M{N}; vector result{1}; for (unsigned p{2}; p * p <= N; ++p) if (N % p == 0) { result.emplace_back(p); while (N % p == 0) N /= p; } if (N > 1 && N < M) result.emplace_back(N); return result; }(N) | views::reverse) { vector> counter(p); for (unsigned i{}; const auto c : S) ++counter[i++ % p][c - 65]; auto modify_count{N}; string tmp{}; for (const auto &x : counter) { const auto &it{ranges::max_element(x)}; tmp += static_cast(ranges::distance(begin(x), it) + 65); modify_count -= *it; } if (modify_count < prefix_min) { prefix_min = modify_count; ans = tmp; repeat = N / p; } } for (unsigned i{}; i < repeat; ++i) cout << ans; cout << endl; return 0; }