Robot Fire Fighting Contest
题号:NC213969
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Recently, Robot Contest is in full swing. Now there is a robot fire fighting Contest. The robot fire fighting field is composed of four rooms in the shape of "田", and each room is numbered as 1, 2, 3 and 4 clockwise from the room in the lower left corner. Fire extinguishing difficulty of each room is defined by an integer. If the fire extinguishing ability of the robot is greater than or equal to the fire extinguishing difficulty of the room, it means that the robot can extinguish the fire in the room. The robot needs to start from room 1 and finally return to room 1 as the end of the Contest. The robot can walk one step to the next room in any direction of up, down, left and right.

For the given fire extinguishing difficulty of four rooms and the fire extinguishing ability of the robot, as well as the room number where the fire is located (only one room has fire, and the robot must walk to this room to have a chance to extinguish the fire), if the robot can not extinguish the fire, it will output 0; otherwise, it will output the minimum walking steps required for the robot to successfully return to room 1 after extinguishing the fire.

输入描述:

The first line is 4 positive integers separated byspaces, representing the fire extinguishing difficulty of four rooms in turn.

The second line is a positive integer, which represents the fire fighting ability of the robot.

The third line is a positive integer representing the room number where the fire is located.

输出描述:

Output the minimum walking steps required for the robot to return to room 1 after extinguishing the fire.

If the fire cannot be extinguished, the output is 0.

示例1

输入

复制
1 2 3 4 
5
3

输出

复制
4