#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double
#define print(a)         for(auto x : a) cout << x << " "; cout << endl


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int LINF = 2000000000000000001;

inline int power(int a, int b, int mod=M) {
    int x = 1;
    a %= mod;
    while (b) {
        if (b & 1) x = (x * a) % mod; 
        a = (a * a) % mod;
        b >>= 1;
    }
    return x;
}


//_ ***************************** START Below *******************************




string a;

bool isPossible(int n, int mid){
	
	if (mid == 0) return true;
	
	int P = 31;
	int MOD = 1e9 + 7;
	int p_pow = 1;
	
	for (int i = 0; i < mid - 1; i++) {
		p_pow = (p_pow * P) % MOD;
	}
	
	int s = 0;
	int e = 0;
	int hash = 0;
	
	//* substring -> index
	unordered_map<int,int> first;
	unordered_map<int,int> second;
	
	while(e < n){
		hash = (hash * P + (a[e] - 'a' + 1)) % MOD;
		
		if(e - s + 1 < mid){
			e++;
		}
		else{
			if(!first.count(hash)){
				first[hash] = s;
			}
			else if(!second.count(hash)){
				if(s >= first[hash] + mid) second[hash] = s;	
			}
			else{
				if(s >= second[hash] + mid) return true;	
			}
			

			hash = (hash - (a[s] - 'a' + 1) * p_pow) % MOD;
			if (hash < 0) hash += MOD;
			
			e++;
			s++;
		}
	}
	return false;
}


int consistency(int n){
	
	int s = 0;
	int e = n/3+1;
	
	
	while(s<e){
		int mid = s + (e-s+1)/2;
		
		if(isPossible(n, mid)){
			s = mid;
		}
		else{
			e = mid-1;
		}
		
	}


	
	return e;
}



















void solve() {
    
    cin >> a;
    int n = a.size();
    
    cout << consistency(n) << endl;


}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}