private static int length(String p){
  if (p.endsWith("$") || p.endsWith(" "))   return p.length() - 1;
  return p.length();
}

private static int length ( String p ) { if ( p . endsWith ( "$" ) || p . endsWith ( " " ) ) return p . length ( ) - 1 ; return p . length ( ) ; }
the real length of the prefix .
