The year is 2060. Marcus has retired from computer science and has become a gardener. In his garden, he is growing
He also has a watering can that can hold up to
Marcus begins at position
Constraints
For all subtasks,
Subtask 1 [50%]
Subtask 2 [50%]
No additional constraints.
Input Specification
The first line of input contains one integer,
The second line of input contains one integer,
Output Specification
Output one line containing one integer, the minimum distance Marcus has to walk to water all his plants and return to position
Note that this value may not fit within a 32-bit integer type.
Sample Input 1
4
2
Sample Output 1
12
Explanation for Sample 1
One possible solution is as follows:
- Marcus is at position
and fills his watering can. It now holds units of water. - Marcus walks
unit right to flower , and waters it. His watering can now holds unit of water. - Marcus walks
more unit right to flower , and waters it. His watering can is now empty. - Marcus walks
units left back to position and refills his watering can. It now holds units of water. - Marcus walks
units right to flower , and waters it. His watering can now holds unit of water. - Marcus walks
more unit right to flower , and waters it. His watering can is now empty. - Marcus walks
units left to return to position .
Marcus walks a total of
Sample Input 2
5
7
Sample Output 2
10
Explanation for Sample 2
Marcus' watering can holds more than enough water for all of the flowers in one trip! Thus, Marcus can simply fill his watering can once, walk right
Comments