#include using namespace std; 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(); const int m = divs.size(); vector skip(m); for(int i = 0; i < m; i++){ for(int j = i + 1; j < m; j++){ if(divs[j] % divs[i] == 0){ skip[i] = true; break; } } } int mn = 1 << 30, cd = -1; array cnt{}; for(int i = 0; i < m; i++){ if(skip[i]) continue; const int d = divs[i], step = n / d; int tot = 0; for(int j = 0; j < d; j++){ cnt.fill(0); 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++){ cnt.fill(0); for(int k = j; k < n; k += cd) cnt[s[k] - 'A']++; const char ld = 'A' + (max_element(cnt.begin(), cnt.end()) - cnt.begin()); for(int k = j; k < n; k += cd) s[k] = ld; } cout << s << '\n'; }