1860. Finger Counting

单点时限: 2.0 sec

内存限制: 256 MB

A little boy is counting numbers with his left hand. Starting with his thumb and going toward his pinky, he counts each finger in order. After counting his pinky, he reverses direction and goes back toward his thumb. He repeats this process until he reaches his target number. He never skips a finger. For example, to count to ten, he would count: thumb, index, middle, ring, pinky, ring, middle, index, thumb, index. Sadly, one of his fingers hurts and he can only count on it a limited number of times. His fingers are numbered 1 through 5 from thumb to pinky. You are given an int weakFinger, the finger that hurts, and an int maxCount, the maximum number of times he can use that finger.

输入格式

There are several test cases,each test case contain two numbers,the first integer is weakFinger(1<=weakFinger<=5),the second integer is maxCount(0<=maxCount<=2*10^8).

输出格式

For each test case,output the largest number he can count to. If he cannot even begin counting, Output 0.

样例

Input
2 3
1 0
Output
15
0
Hint:
Case 1:
The first 15 numbers are counted with fingers 1,2,3,4,5,4,3,2,1,2,3,4,5,4,3. He would then have to use finger 2 for the next number, but since he has already used it 3 times, he has to stop.
Case 2:
He needs to use his thumb when counting the first number, 1, but it's too weak to be used even once.

50 人解决,83 人已尝试。

60 份提交通过,共有 250 份提交。

4.8 EMB 奖励。

创建: 12 年,6 月前.

修改: 3 年,1 月前.

最后提交: 5 月,1 周前.

来源: N/A

题目标签