Comments

The idea is: Go from r1 to some intermediate row i and then go from that intermediate row i to r2 (using ups or downs), after that get to the right column(using lefts or rights).

In c++ freopen's are allowed but everytime i was sending a code in java with

System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream("output.txt"));

runtime error was coming everytime! Why is that not allowed in Java?