Change Scanner to BufferedReader and The input time is much faster, but
still got TLE. I confirm the algoritm is OK.
Also compared System.out.println() and PrintWriter. PrintWriter is
slower than System.out.println();