Robots (1)

Write a program to simulate the movements of a robot located in a rectangular world with nn rows and mm columns. The robot receives a sequence of orders about where to move, either to the right, to the left, upwards or downwards. The simulation must end if any instruction is incorrect or if the robot goes out of the world.

Input

The first line contains two strictly positive natural numbers nn and mm. The second line has the initial row (between 1 and nn) and the initial column (between 1 and mm). Follow several orders, one per line. Each order is a non-empty word made up of only lowercase letters.

Output

Print the positions visited by the robot, starting with the initial position. If the robot goes out of the world, or if any order is not “right”, “left”, “up” or “down”, print “out of bounds” or “incorrect order” and stop the simulation.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:17:07.321Z

© Jutge.org, 2006–2026.
https://jutge.org