codeforces-B. Nastya Is Playing Computer Games

Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.

There are nn manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the kk-th manhole from the left. She is thinking what to do.

In one turn, Nastya can do one of the following:

  • if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong).
  • go to a neighboring manhole;
  • if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves).

The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it).

Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.

Note one time more that Nastya can open a manhole only when there are no stones onto it.

Input

The first and only line contains two integers nn and kk, separated by space (2≤n≤50002≤n≤5000, 1≤k≤n1≤k≤n) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the nn manholes.

Output

Print a single integer — minimum number of moves which lead Nastya to pick all the coins.

Examples

Input

Copy

2 2

Output

Copy

6

Input

Copy

4 2

Output

Copy

13

Input

Copy

5 1

Output

Copy

15

Note

Let's consider the example where n=2n=2, k=2k=2. Nastya should play as follows:

  • At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole.
  • Then she opens the second manhole and pick the coin from it.
  • Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it.

So, 66 moves are required to win.

题意:给你几个井盖每个井盖上有石子一个,每个井盖下有硬币,想办法拿出所有的硬币,nn为你初始位置在那个石头上,每走一步搬石头和取硬币都要花费一个力气,求最小花费力气

思路:你可以先走到左边或右边(最近的),然后一个个搬取,所用时间最小,除第一个为花费3外其他都为2

代码如下

#include <iostream>
#include<cstdio>
using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int sum = min(n-k,k-1);
    sum += 3;
    sum+=(2*(n-1));
    sum += (n-1);
    printf("%d\n",sum);
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

-lyslyslys

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值