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



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 ai = 0L; ai + 1 + ans * 2 < s.length; ai++ )
	{
		for( auto bi = ai + 1; bi + ans < s.length; bi++ )
		{
			for( auto ci = 0L; ai + ci < bi && bi + ci < s.length; ci++ )
			{
				if( s[ ai + ci ] != s[ bi + ci ] ) break;
				if( ans <= ci ) ans = ci + 1;
			}
		}
	}
	return ans;
}
