There is a robot who lives on a cartesian plane and likes to walk around it. One day he planned a very interesting journey around the plane. To make that journey he developed a program which he is going to follow. The program consists of n functions: f
1, f
2, ..., f
n. The i-th function f
i is a sequence of c
i commands. Each command is of one of the following types:
- GO: Move forward one meter;
- LEFT: Turn 90 degrees to the left;
- RIGHT: Turn 90 degrees to the right;
- Fk: Follow the instructions of the function fk, then continue following the instructions of the current function.
The robot starts the journey at his home located at the point with coordinates (0, 0) following the instructions of the function f
1.
For example, consider the following set of functions:
f
1: GO F2 GO F2 GO F2
f
2: F3 F3 F3 F3
f
3: GO LEFT
The robot’s journey for that case is shown on the picture.
In some cases the journey of the robot might never end. Consider for example the set of instructions consisting of one function f
1 that has the following commands: GO F1. In that case the robot keeps going forward and never stops.
The question that puzzles the robot now is how far from the home will he get during his journey. That is, consider the set of all points which the robot will visit. Find the maximum value of |x|+|y| among all those points. If there are points on the path of the robot with arbitrarily large values of |x|+|y|, output “Infinity”.