Nastya Is Playing Computer Games

题意翻译

## 题目描述 完成了她的家庭作业,Nastya决定玩一会儿电脑游戏。Nastya一个接一个地通过关卡,最终遇到了一个问题问题。她的任务是尽快离开许多怪物居住的房间。 有$n$个下水道检修孔其中坐落在一条线,但不幸的是所有的检修孔被关闭,并且每个检修孔上有一块石。每个检修孔下面都有一枚硬币,为了赢得比赛,Nastya应该选择所有的硬币。最初Nastya站在从左边数第$k$个检修孔。她正在考虑该怎么做。 在一个回合中,Nastya可以执行以下操作之一: 1. 如果在检修孔上至少有一块石头,并且Nastya站在附近,从它扔出一块石头到任何其他检修孔(是的,Nastya很强)。 2. 去相邻的检修孔; 3. 如果Nastya所在的检修孔上没有石头,她可以打开它并从中取出硬币。之后,她必须立即关闭检修孔(不需要额外的移动)。 ## 图片示意 该图显示了游戏的中间状态。在当前位置,Nastya可以将石头扔到任何其他检修孔,或向左或向右移动到邻近的检修孔。如果她靠近最左边的检修孔,她可以打开它(因为它上面没有石头).Nastya可以在拿到所有硬币时离开房间。怪物无处不在,所以你需要计算Nastya必须采取的拿到所有硬币的最小移动次数。 **请注意,只有在没有石头的情况下,Nastya才能打开一个检修孔。** ## 输入输出格式 ### 输入格式: 第一行也是唯一一行包含两个整数$n$和$k$,以空格分隔($2 ≤ N ≤ 5000$, $1≤ k ≤ N$) -检修孔的数目和从左侧数Nastya最初所站的检修孔的编号。最初每个检修井附近都有一块石头 ### 输出格式: 打印一个整数 - 使得Nastya得到所有硬币最小的移动次数。 ## 说明 让我们考虑一下这个例子$ n = 2$,$k = 2$。 Nastya应该如下操作: 起初,她将石头从第二个检修孔扔到第一个检修孔。现在第一个检修孔上有两块石头。 然后她打开第二个检修孔并从中取出硬币。 然后她去了第一个检修孔,通过两次移动将两块石头扔到第二个检修孔,然后打开检修孔并从中取出硬币。 所以,获胜需要$6$个动作。

题目描述

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 $ n $ 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 $ k $ -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). ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1136B/3ed5e40d396c136735a8bacab02d518fbb9c87e8.png)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.

输入输出格式

输入格式


The first and only line contains two integers $ n $ and $ k $ , separated by space ( $ 2 \leq n \leq 5000 $ , $ 1 \leq k \leq 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 $ n $ manholes.

输出格式


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

输入输出样例

输入样例 #1

2 2

输出样例 #1

6

输入样例 #2

4 2

输出样例 #2

13

输入样例 #3

5 1

输出样例 #3

15

说明

Let's consider the example where $ n = 2 $ , $ k = 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, $ 6 $ moves are required to win.