#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef LOCAL #include "debug.h" #else #define debug(x...) #endif //#define int ll //#pragma GCC optimize("O3") //#pragma GCC target("avx2") using namespace std; typedef long long ll; typedef long double ld; typedef pair < int, int > pii; typedef pair < ll, ll > pll; #define sz(x) int((x).size()) #ifndef LOCAL mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #else mt19937 rng(228); #endif const int N = 5e6 + 7; const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 3; const int MOD = 1e9 + 7; const double eps = 1e-9; const string cars[] = {"🚗", "🚕", "🚙"}; int c[N], ans[N]; int n; bool check(int len) { for (int i = len - 1; i < n; i += len) { if (!c[i]) { return false; } } return true; } bool cmp(ld a, ld b) { return abs(a - b) < eps; } int solve1(string& s) { n = sz(s); int a[27] = { 0 }; memset(ans, 0, sizeof ans); memset(c, 0, sizeof c); for (char c : s) { a[c - 'a']++; } int cur[27] = { 0 }; for (int i = 0; i < sz(s); i++) { cur[s[i] - 'a']++; int flag = 1; ld v = -1; for (int j = 0; j < 26 && flag; j++) { if (cur[j]) { if (v == -1) { v = ld(a[j]) / cur[j]; } else { flag &= cmp(v, ld(a[j]) / cur[j]); } } else { flag &= !a[j]; } } if (flag) { c[i] = 1; memset(cur, 0, sizeof cur); } //debug(i, flag); } for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ans[i] |= check(i); ans[n / i] |= check(n / i); } } for (int i = 1; i <= n; i++) { if (ans[i]) { return n / i; } //cout << i << " " << ans[i] << endl; } return 1; } int solve2(string& s) { for (int ans = 1; ans <= sz(s); ans++) { if (sz(s) % ans) { continue; } vector < string > a; for (int i = 0; i < sz(s); i += ans) { string t = s.substr(i, ans); sort(t.begin(), t.end()); a.push_back(t); } sort(a.begin(), a.end()); if (a.front() == a.back()) { return sz(s) / ans; } } } int rng_on(int l, int r) { return rng() % (r - l + 1) + l; } signed main() { //debug(true); #ifdef LOCAL freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif cout << fixed << setprecision(4); ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); string s; cin >> s; cout << solve1(s) << endl; return 0; for (int it = 0; it < 1e5; it++) { int n = rng_on(1, 20); string s; for (int i = 0; i < n; i++) { s += 'a' + rng_on(0, 1); } if (solve1(s) != solve2(s)) { debug(n, s); debug(solve1(s), solve2(s)); return 0; } } return 0; }