unittest
{
	assert( [ "5", "ababa" ].parse.expand.solve == 2 );
	assert( [ "2", "xy" ].parse.expand.solve == 0 );
	assert( [ "13", "strangeorange" ].parse.expand.solve == 5 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	auto ans = 0L;
	for( auto al = 0L; al < s.length; )
	{
		auto ac = 0L;
		for( auto bl = al + 1; bl < s.length; )
		{
			auto bc = 0L;
			for( auto c = 0L; al + c < bl && bl + c < s.length; )
			{
				if( s[ al + c ] != s[ bl + c ] ) break;
				c++;
				if( ac < c ) ac = c;
				if( bc < c ) bc = c;
			}
			bl += max( 1, bc );
		}
		al += max( 1, ac );
		ans = max( ans, ac );
	}
	return ans;
}
