#include using namespace std; using ll = long long; template istream& operator >> (istream& is, vector& vec) { for(T& x : vec) is >> x; return is; } template ostream& operator << (ostream& os, const vector& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } bool check(int a, int b, int c){ if (a == b || b == c || a == c) return false; if (a < b && b > c) return true; if (a > b && b < c) return true; return false; } int main(){ ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; const int n = s.size(); vector divs; for(int i = 1; i * i <= n; i++){ if(n % i == 0){ divs.emplace_back(i); if(i * i != n) divs.emplace_back(n / i); } } sort(divs.begin(), divs.end()); divs.pop_back(); int mn = 1 << 30, cd = -1; for(auto d : divs){ const int step = n / d; int tot = 0; for(int j = 0; j < d; j++){ array cnt{}; for(int k = j; k < n; k += d){ cnt[s[k] - 'A']++; } tot += step - *max_element(cnt.begin(), cnt.end()); if(tot >= mn) break; } if(tot < mn){ mn = tot; cd = d; } } for(int j = 0; j < cd; j++){ array cnt{}; for(int k = j; k < n; k += cd){ cnt[s[k] - 'A']++; } int p = max_element(cnt.begin(), cnt.end()) - cnt.begin(); for(int k = j; k < n; k += cd){ s[k] = p + 'A'; } } cout << s << '\n'; }