Check for Rule 1
if ( n >= 3 ) { if ( result . get ( n - 1 ) == result . get ( n - 2 ) && result . get ( n - 1 ) == result . get ( n - 3 ) ) { result . remove ( result . size ( ) - 1 ) ; } } n = result . size ( ) ;