**47 人解决**，80 人已尝试。

**55 份提交通过**，共有 239 份提交。

**5.0** EMB 奖励。

**单点时限: **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.

**47 人解决**，80 人已尝试。

**55 份提交通过**，共有 239 份提交。

**5.0** EMB 奖励。

**创建**: 11 年，10 月前.

**修改**: 2 年，5 月前.

**最后提交**: 2 周，3 天前.

**来源**: N/A

题目标签