#include using namespace std; using ll = long long; #include using namespace atcoder; int mymax(int a, int b) { return max(a, b); } int e() { return 0; } int main() { string S; cin >> S; int N = S.size(); vector Z(N); for (int i = 0; i < N; i++) { int j = 0; while (j < i && i + j < N && S[j] == S[i + j]) { j++; } Z[i] = j; //cerr << i << " " << j << endl; } vector> invZ(N); set st; for (int i = 0; i < N; i++) { if (Z.at(i) >= 2) { invZ.at(Z.at(i)).push_back(i); st.emplace(i); } } st.emplace(N + 1); lazy_segtree dp(N + 1); for (int j = 2; j < N; j++) { int cnt = dp.get(j) + j - 2; int i = *st.begin() + j; while (i < N + 1) { dp.apply(i, N + 1, cnt); cnt += j - 1; i = *st.lower_bound(i) + j; } for (auto ii : invZ.at(j)) { st.erase(ii); } } int ans = N - dp.get(N); cout << ans << endl; }