Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Journey
Description 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 f
_{k}, 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”. Input The first line of the input file consists of an integer number n (1 ≤ n ≤ 100). The following n lines contain a description of the functions. The i-th line describes function fi. It consists of the number ci (1 ≤ ci ≤ 100) — the number of commands for function fi, followed by a description of each command. Output Output the maximum value of |x| + |y| among all points visited during the journey or “Infinity”. Sample Input Sample Input #1 3 6 GO F2 GO F2 GO F2 4 F3 F3 F3 F3 2 GO LEFT Sample Input #2 1 2 GO F1 Sample Input #3 4 2 GO F2 7 LEFT GO GO GO F3 LEFT F4 5 GO F4 RIGHT F2 RIGHT 7 GO GO LEFT LEFT GO LEFT GO Sample Output Sample Output #1 5 Sample Output #2 Infinity Sample Output #3 13 Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator