// https://yukicoder.me/submissions/692208 // 上をベースに書き換え #include #include #include #include #include #include using namespace atcoder; using namespace std; int main(void) { string s; cin >> s; const int n = s.size(); const vector z = z_algorithm(s); vector ord; set st; for (int i = 1; i < n; ++i) { if (z[i] >= 1) { ord.push_back(i); st.emplace(i); } } st.emplace(n); sort(ord.begin(), ord.end(), [&](int a, int b) { return z[a] < z[b]; }); vector dp(n + 1, 0); for (int i = 1, x = 0; i < n; ++i) { int d = dp[i]; dp[i + 1] = max(dp[i + 1], d); d -= 1; int pos = *st.lower_bound(i); while (pos < n) { d += i - 1; dp[pos + i] = max(dp[pos + i], d); pos = *st.lower_bound(pos + i); } for (; x < (int)ord.size() && z[ord[x]] == i; ++x) { st.erase(ord[x]); } } int ans = n - dp[n]; cout << ans << endl; }