Codeforces Round 574 (Div. 2)
B
Sport Mafia
Codeforces
1000
原题
← AC →
翻译中…

Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.

翻译中…

For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $n$ actions. The first action performed is to put a single candy into the box. For each of the remaining moves she can choose from two options:

翻译中…
  • the first option, in case the box contains at least one candy, is to take exactly one candy out and eat it. This way the number of candies in the box decreased by $1$;
  • the second option is to put candies in the box. In this case, Alya will put $1$ more candy, than she put in the previous time.
翻译中…

Thus, if the box is empty, then it can only use the second option.

翻译中…

For example, one possible sequence of Alya's actions look as follows:

翻译中…
  • put one candy into the box;
  • put two candies into the box;
  • eat one candy from the box;
  • eat one candy from the box;
  • put three candies into the box;
  • eat one candy from the box;
  • put four candies into the box;
  • eat one candy from the box;
  • put five candies into the box;
翻译中…

This way she will perform $9$ actions, the number of candies at the end will be $11$, while Alya will eat $4$ candies in total.

翻译中…

You know the total number of actions $n$ and the number of candies at the end $k$. You need to find the total number of sweets Alya ate. That is the number of moves of the first option. It's guaranteed, that for the given $n$ and $k$ the answer always exists.

翻译中…

Please note, that during an action of the first option, Alya takes out and eats exactly one candy.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $k$ ($1 \le n \le 10^9$; $0 \le k \le 10^9$) — the total number of moves and the number of candies in the box at the end.

翻译中…

It's guaranteed, that for the given $n$ and $k$ the answer exists.

翻译中…

Output

翻译中…

Print a single integer — the number of candies, which Alya ate. Please note, that in this problem there aren't multiple possible answers — the answer is unique for any input data.

翻译中…

Note

翻译中…

In the first example, Alya has made one move only. According to the statement, the first move is always putting one candy in the box. Hence Alya ate $0$ candies.

翻译中…

In the second example the possible sequence of Alya's actions looks as follows:

翻译中…
  • put $1$ candy,
  • put $2$ candies,
  • eat a candy,
  • eat a candy,
  • put $3$ candies,
  • eat a candy,
  • put $4$ candies,
  • eat a candy,
  • put $5$ candies.
翻译中…

This way, she will make exactly $n=9$ actions and in the end the box will contain $1+2-1-1+3-1+4-1+5=11$ candies. The answer is $4$, since she ate $4$ candies in total.

翻译中…

样例

Input #1
1 1
Output #1
0
InputCopy OutputCopy
Input #2
9 11
Output #2
4
InputCopy OutputCopy
Input #3
5 0
Output #3
3
InputCopy OutputCopy
Input #4
3 2
Output #4
1
InputCopy OutputCopy
题目信息
题号
1195B
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
数学

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