【CF 1023B】Pair of Toys

                                          B. Pair of Toys

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

Copy

8 5

output

2

input

8 15

output

1

input

7 20

output

0

input

1000000000000 1000000000001

output

500000000000

 

題意:給出兩個數n,m. 求0到n可以選出多少組不同的元素之和爲m。

代碼:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define closeio std::ios::sync_with_stdio(false)

int main() 
{
	ll n,m;
	cin>>n>>m;
	if(m/2>n)
	{
		cout<<0<<endl;
		return 0;
	}
	if(n>=m)
	{
		if(m%2!=0)
		cout<<m/2<<endl;
		else
		cout<<m/2-1<<endl;
	}
	else
	cout<<n-m/2<<endl;
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章