/* package whatever; // don't place package name! */
import java.io.BufferedReader ;
import java.io.FileReader ;
import java.io.IOException ;
import java.util.ArrayList ;
public class Main {
public static void main
( String [ ] args
) { String fileName
= "24-168.txt" ; StringBuilder letterSequence = new StringBuilder( ) ;
ArrayList< Integer> countList = new ArrayList<> ( ) ;
String line
= bufferedReader.
readLine ( ) ;
// String s = "AABBAABBCCDDDEFFGF"; // Uncomment this line to test with a fixed string
if ( line != null && ! line.isEmpty ( ) ) {
letterSequence.append ( line.charAt ( 0 ) ) ;
countList.add ( 1 ) ;
for ( int i = 1 ; i < line.length ( ) ; i++ ) {
if ( line.charAt ( i) == line.charAt ( i - 1 ) ) {
countList.set ( countList.size ( ) - 1 , countList.get ( countList.size ( ) - 1 ) + 1 ) ;
} else {
letterSequence.append ( line.charAt ( i) ) ;
countList.add ( 1 ) ;
}
}
}
e.printStackTrace ( ) ;
}
int maxLength = 0 ;
for ( int i = 2 ; i < letterSequence.length ( ) ; i++ ) {
if ( letterSequence.charAt ( i - 2 ) < letterSequence.charAt ( i - 1 ) && letterSequence.charAt ( i - 1 ) < letterSequence.charAt ( i) ) {
int length
= countList.
subList ( i
- 2 , i
+ 1 ) .
stream ( ) .
mapToInt ( Integer :: intValue
) .
sum ( ) ; maxLength
= Math .
max ( length, maxLength
) ; }
}
System .
out .
println ( maxLength
) ; }
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwppbXBvcnQgamF2YS5pby5CdWZmZXJlZFJlYWRlcjsKaW1wb3J0IGphdmEuaW8uRmlsZVJlYWRlcjsKaW1wb3J0IGphdmEuaW8uSU9FeGNlcHRpb247CmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFN0cmluZyBmaWxlTmFtZSA9ICIyNC0xNjgudHh0IjsKICAgICAgICBTdHJpbmdCdWlsZGVyIGxldHRlclNlcXVlbmNlID0gbmV3IFN0cmluZ0J1aWxkZXIoKTsKICAgICAgICBBcnJheUxpc3Q8SW50ZWdlcj4gY291bnRMaXN0ID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICAgICAgCiAgICAgICAgdHJ5IChCdWZmZXJlZFJlYWRlciBidWZmZXJlZFJlYWRlciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgRmlsZVJlYWRlcihmaWxlTmFtZSkpKSB7CiAgICAgICAgICAgIFN0cmluZyBsaW5lID0gYnVmZmVyZWRSZWFkZXIucmVhZExpbmUoKTsKICAgICAgICAgICAgCiAgICAgICAgICAgIC8vIFN0cmluZyBzID0gIkFBQkJBQUJCQ0NERERFRkZHRiI7IC8vIFVuY29tbWVudCB0aGlzIGxpbmUgdG8gdGVzdCB3aXRoIGEgZml4ZWQgc3RyaW5nCiAgICAgICAgICAgIAogICAgICAgICAgICBpZiAobGluZSAhPSBudWxsICYmICFsaW5lLmlzRW1wdHkoKSkgewogICAgICAgICAgICAgICAgbGV0dGVyU2VxdWVuY2UuYXBwZW5kKGxpbmUuY2hhckF0KDApKTsKICAgICAgICAgICAgICAgIGNvdW50TGlzdC5hZGQoMSk7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGZvciAoaW50IGkgPSAxOyBpIDwgbGluZS5sZW5ndGgoKTsgaSsrKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGxpbmUuY2hhckF0KGkpID09IGxpbmUuY2hhckF0KGkgLSAxKSkgewogICAgICAgICAgICAgICAgICAgICAgICBjb3VudExpc3Quc2V0KGNvdW50TGlzdC5zaXplKCkgLSAxLCBjb3VudExpc3QuZ2V0KGNvdW50TGlzdC5zaXplKCkgLSAxKSArIDEpOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGxldHRlclNlcXVlbmNlLmFwcGVuZChsaW5lLmNoYXJBdChpKSk7CiAgICAgICAgICAgICAgICAgICAgICAgIGNvdW50TGlzdC5hZGQoMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfSBjYXRjaCAoSU9FeGNlcHRpb24gZSkgewogICAgICAgICAgICBlLnByaW50U3RhY2tUcmFjZSgpOwogICAgICAgIH0KCiAgICAgICAgaW50IG1heExlbmd0aCA9IDA7CiAgICAgICAgZm9yIChpbnQgaSA9IDI7IGkgPCBsZXR0ZXJTZXF1ZW5jZS5sZW5ndGgoKTsgaSsrKSB7CiAgICAgICAgICAgIGlmIChsZXR0ZXJTZXF1ZW5jZS5jaGFyQXQoaSAtIDIpIDwgbGV0dGVyU2VxdWVuY2UuY2hhckF0KGkgLSAxKSAmJiBsZXR0ZXJTZXF1ZW5jZS5jaGFyQXQoaSAtIDEpIDwgbGV0dGVyU2VxdWVuY2UuY2hhckF0KGkpKSB7CiAgICAgICAgICAgICAgICBpbnQgbGVuZ3RoID0gY291bnRMaXN0LnN1Ykxpc3QoaSAtIDIsIGkgKyAxKS5zdHJlYW0oKS5tYXBUb0ludChJbnRlZ2VyOjppbnRWYWx1ZSkuc3VtKCk7CiAgICAgICAgICAgICAgICBtYXhMZW5ndGggPSBNYXRoLm1heChsZW5ndGgsIG1heExlbmd0aCk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihtYXhMZW5ndGgpOwogICAgfQp9