import java.lang.Math ;

public class FancyLen

{

private static int log2 ( long n )

{

//I've forgotten my log rules, but supposedly

//this is how to do logs in other bases with Java

int result = ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) ;

return result ;

}

public static int jStrLen ( int [ ] target )

{

int boolSize = 1 ;

boolean [ ] boolArray = new boolean [ boolSize ] ;

long subsetCount = 1 ;

int boundChecker ;

int targetSize ;

int index ;

//Do this until end of target has been reached.

try

{

while ( true )

{

index = 0 ;

/*This loop is the same as adding 1 to a binary number and carrying.

*Only continues if boolArray[index] is false/0,

*because that means it was true/1 before,

*and thus a carry is needed.

*/

do

{

if ( index < boolArray. length )

{

//Throws exception once end of target is reached.

boundChecker = target [ index ] ;

boolArray [ index ] = ! ( boolArray [ index ] ) ;

index ++;

}

/*

*If we see this code, that means boolArray wasn't big enough.

*Add one more element to it, set the last element to true.

*This will mimic a binary number of the form 00...001,

*with arbitrary length

*We can do this because before this step,

*boolArray was of the form 11...11,

*/

else

{

//In an effort to not perform unnecessary memory allocation,

//We check that we've reached the end first.

boundChecker = target [ index ] ;

/*If we haven't reached the end,

* Create a new array of booleans as described above.

*/

boolSize ++;

boolArray = new boolean [ boolSize ] ;

boolArray [ boolSize - 1 ] = true ;

break ; //No further carrying is necessary, so break out of the loop here.

}

} while ( ! ( boolArray [ index - 1 ] ) ) ;

//If code reaches this point, OoBE wasn't thrown,

//so we haven't reached the end.

subsetCount ++;

}

}

//End of target will always throw this exception.

catch ( ArrayIndexOutOfBoundsException exc )

{

/* Number of Subsets = size^2

* Therefore, size = log base 2(Number of Subsets)

* */

targetSize = log2 ( subsetCount ) ;

return targetSize ;

}

}