# CF1023B Pair of Toys

• 92通过
• 158提交
• 题目来源
• 评测方式 RemoteJudge
• 标签
• 难度 普及/提高-
• 时空限制 1000ms / 256MB
• 提示：收藏到任务计划后，可在首页查看。

## 题意翻译

给定n个玩具要你选出两个玩具求出k的价值。
第i个玩具的价值为i。
样例1：从8个玩具里选出两个使价值为5.
有以下方案：（1 4）（2 3）。
若是没有选择方案，输出0 补充：玩具A与玩具B 和 玩具B和玩具A 是同一种选择

## 题目描述

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.

## 输入输出格式

输入格式：

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.

输出格式：

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.

## 输入输出样例

输入样例#1： 复制
8 5

输出样例#1： 复制
2

输入样例#2： 复制
8 15

输出样例#2： 复制
1

输入样例#3： 复制
7 20

输出样例#3： 复制
0

输入样例#4： 复制
1000000000000 1000000000001

输出样例#4： 复制
500000000000

## 说明

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$ .

提示
标程仅供做题后或实在无思路时参考。
请自觉、自律地使用该功能并请对自己的学习负责。
如果发现恶意抄袭标程，将按照I类违反进行处理。