Codeforces Round 504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)
B
Pair of Toys
Codeforces
1000
原题
← AC →
翻译中…

Tanechka is shopping in the toy shop. There are exactly $n$ toys in the shop for sale, the cost of the $i$-th toy is $i$ burles. She wants to choose two toys in such a way that their total cost is $k$ burles. How many ways to do that does she have?

翻译中…

Each toy appears in the shop exactly once. Pairs $(a, b)$ and $(b, a)$ are considered equal. Pairs $(a, b)$, where $a=b$, are not allowed.

翻译中…

Input

翻译中…

The first line of the input contains two integers $n$, $k$ ($1 \le n, k \le 10^{14}$) — the number of toys and the expected total cost of the pair of toys.

翻译中…

Output

翻译中…

Print the number of ways to choose the pair of toys satisfying the condition above. Print 0, if Tanechka can choose no pair of toys in such a way that their total cost is $k$ burles.

翻译中…

Note

翻译中…

In the first example Tanechka can choose the pair of toys ($1, 4$) or the pair of toys ($2, 3$).

翻译中…

In the second example Tanechka can choose only the pair of toys ($7, 8$).

翻译中…

In the third example choosing any pair of toys will lead to the total cost less than $20$. So the answer is 0.

翻译中…

In the fourth example she can choose the following pairs: $(1, 1000000000000)$, $(2, 999999999999)$, $(3, 999999999998)$, ..., $(500000000000, 500000000001)$. The number of such pairs is exactly $500000000000$.

翻译中…

样例

Input #1
8 5
Output #1
2
InputCopy OutputCopy
Input #2
8 15
Output #2
1
InputCopy OutputCopy
Input #3
7 20
Output #3
0
InputCopy OutputCopy
Input #4
1000000000000 1000000000001
Output #4
500000000000
InputCopy OutputCopy
题目信息
题号
1023B
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。