

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 400 点
問題文
すぬけくんは、整数 B を持って整数やさんを訪れました。 整数やさんでは、お金を払うことで、持っている整数を別の整数にしてもらうことができます。
具体的には、次の 2 種類のサービスを好きな順で好きなだけ購入することができます。
- 1 円を払い、持っている整数を -1 倍する。
- 2 円を払い、持っている整数から 1 を引く。
すぬけくんが C 円以内で作ることのできる整数は何通りありますか?
制約
- -10^{18}\le B \le 10^{18}
- 1\le C \le 10^{18}
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
B C
出力
答えを出力せよ。
入力例 1
11 2
出力例 1
3
以下のように、-11,10,11 の 3 通りの数を作ることができます。
- 何もしないとき、0 円を使って 11 を作ることができる
- 11 を -1 倍すると、1 円を使って -11 を作ることができる
- 11 から 1 を引くと、2 円を使って 10 を作ることができる
入力例 2
0 4
出力例 2
4
以下のように、-2,-1,0,1 の 4 通りの数を作ることができます。
- 何もしないとき、0 円を使って 0 を作ることができる
- 0 から 1 を引くと、2 円を使って -1 を作ることができる
- 0 から 1 を引いて -1 倍すると、3 円を使って 1 を作ることができる
- 0 から 1 を引いて 1 を引くと、4 円を使って -2 を作ることができる
入力例 3
112 20210213
出力例 3
20210436
入力例 4
-211 1000000000000000000
出力例 4
1000000000000000422
Score : 400 points
Problem Statement
Snuke has come to Seisu-ya (integer shop) with an integer B in his hand. In Seiyu-ya, you can exchange your integer for another integer by paying money.
More specifically, you can use the following two services any number of times in any order:
- Pay 1 yen (the currency of Japan) to multiply your integer by -1.
- Pay 2 yen to subtract 1 from your integer.
How many integers are there that Snuke can get for at most C yen?
Constraints
- -10^{18}\le B \le 10^{18}
- 1\le C \le 10^{18}
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
B C
Output
Print the answer.
Sample Input 1
11 2
Sample Output 1
3
There are three numbers that Snuke can get: -11, 10, and 11, as follows:
- by doing nothing, he can get 11 for 0 yen;
- by multiplying 11 by -1, he can get -11 for 1 yen;
- by subtracting 1 from 11, he can get 10 for 2 yen.
Sample Input 2
0 4
Sample Output 2
4
There are four numbers that Snuke can get: -2, -1, 0, and 1, as follows:
- by doing nothing, he can get 0 for 0 yen;
- by subtracting 1 from 0, he can get -1 for 2 yen;
- by subtracting 1 from 0 and then multiplying by -1, he can get 1 for 3 yen;
- by subtracting 1 from 0 and then subtracting 1 again, he can get -2 for 4 yen.
Sample Input 3
112 20210213
Sample Output 3
20210436
Sample Input 4
-211 1000000000000000000
Sample Output 4
1000000000000000422