1023BPair of Toys

B. Pair of Toys

http://codeforces.com/problemset/problem/1023/B

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

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

Input

The first line of the input contains two integers nn, kk (1≤n,k≤10141≤n,k≤1014) — 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 kk burles.

Examples

input

8 5

output

2

input

8 15

output

1

input

7 20

output

0

input

1000000000000 1000000000001

500000000000

Note

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

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

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

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

题意:第i个玩具价值i。给你n个玩具,两个为一对,问有几对总价值为k?

思路:找规律。

代码:

#include<iostream>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
    long long n,k;
    cin>>n>>k;
    if(n>=k)
        cout<<(k-1)/2<<endl;
    else
    {
        if(2*n-1<k)
            cout<<"0"<<endl;
        else
            cout<<n-k/2<<endl;
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值