Skip to content

Latest commit

 

History

History
 
 

212-robo-and-robitta

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Robo and Robitta

Challenge Description:

A robot named Robo loves to collect nuts and share them with his girlfriend Robitta. She uses nuts to make beautiful jewelry. Today, our robots have a date. As usual, Robo will bring nuts, which he gathers on his way to Robitta. Help Robitta learn how many nuts Robo will bring this time to decide what jewelry she will be able to make.

Robo always starts his path from the upper-left cell and goes only straight. There is a nut in each cell. When Robo enters a cell, he picks up a nut, and then goes to the next cell. When he gets to an empty cell or reaches the last cells, he turns 90 degrees right. This way Robo continues until he meets Robitta.
For example, in the first case, Robo will bring 5 nuts, in the second case – 14 nuts, and in the third case – 16 nuts.

Figure 1

Input sample:

The first argument is a path to a file. Each line includes a test case, which contains the size of the field that Robo will go through, and X and Y coordinates of a place where Robitta waits for him. Field size and coordinates are separated by a vertical bar '|'.

For example:

3x2 | 2 1
4x4 | 3 3

Output sample:

You should print the number of nuts that Robo will bring to Robitta.

For example:

5
14

Constraints:

  1. Field size can be from 2 to 50 cells height and width.
  2. The field may be square or rectangle.
  3. There is only one nut in a cell.
  4. The number of test cases is 40.