import java.util.Arrays; class MyString implements Comparable { public MyString( String str ) { throw new UnsupportedOperationException( ); } public int compareTo( MyString other ) { throw new UnsupportedOperationException( ); } public char charAt( int idx ) { throw new UnsupportedOperationException( ); } public int length( int idx ) { throw new UnsupportedOperationException( ); } public String toString( ) { throw new UnsupportedOperationException( ); } private String source; private int startIndex; private int length; } public class May14 { static String s1 = "abccbabbcbbabbcbabbbcbaaabaaaacccabcacbabccaccbabbcbbabaa"; public static int longestPrefix( String lhs, String rhs ) { int len = 0; while( len < lhs.length( ) && len < rhs.length( ) && lhs.charAt( len ) == rhs.charAt( len ) ) ++len; return len; } public static void main1( String [ ] args ) { String [ ] suffixes = new String[ s1.length( ) ]; int [ ] LCP = new int[ s1.length( ) ]; for( int i = 0; i < s1.length( ); i++ ) suffixes[ i ] = s1.substring( i ); Arrays.sort( suffixes ); for( int i = 1; i < s1.length( ); i++ ) LCP[ i ] = longestPrefix( suffixes[ i ], suffixes[ i - 1 ] ); /* for( int i = 0; i < suffixes.length; i++ ) System.out.println( LCP[ i ] + " " + suffixes[ i ] ); */ int maxLCPIndex = 0; for( int i = 1; i < LCP.length; i++ ) if( LCP[ i ] > LCP[ maxLCPIndex ] ) maxLCPIndex = i; System.out.println( "maxLCPIndex = " + maxLCPIndex ); System.out.println( "maxLCP = " + LCP[ maxLCPIndex ] ); System.out.println( "pattern is " + suffixes[ maxLCPIndex ].substring( 0, LCP[ maxLCPIndex ] ) ); } public static void main( String [ ] args ) { StringBuilder sb = new StringBuilder( ); int N = 400000; for( int i = 0; i < N; ++i ) sb.append( 'a' ); String str = new String( sb ); // System.out.println( str ); System.out.println( str.length( ) ); } }