Description:
Ayoub thinks that he is a very smart person, so he created a function where s is a binary string (a string which contains only symbols and ). The function is equal to the number of substrings in the string that contains at least one symbol, that is equal to .
More formally, is equal to the number of pairs of integers , such that 1≤l≤r≤|s| (where is equal to the length of string s), such that at least one of the symbols is equal to
For example, if then because there are such pairs
Ayoub also thinks that he is smarter than Mahmoud so he gave him two integers n and m and asked him this problem. For all binary strings s of length n which contains exactly m symbols equal to , find the maximum value of .
Mahmoud couldn’t solve the problem so he asked you for help. Can you help him?
Input
The input consists of multiple test cases. The first line contains a single integer
The only line for each test case contains two integers — the length of the string and the number of symbols equal to
Output
For every test case print one integer number — the maximum value of over all strings s of length , which has exactly m symbols, equal to .
Example
input
5
3 1
3 2
3 3
4 0
5 2
output
4
5
6
0
12
Note
In the first test case, there exists only strings of length , which has exactly 1 symbol, equal to . These strings are: The values of f for them are: , so the maximum value is and the answer is .
In the second test case, the string s with the maximum value is
In the third test case, the string with the maximum value is
In the fourth test case, the only string s of length 4, which has exactly symbols, equal to is and the value of f for that string is , so the answer is
In the fifth test case, the string s with the maximum value is
题意:
给吹一个长度为 的 串,里面有 个 ,可以任意选取区间,如果这个区间内至少含有一个
我们知道如果都是1的话我们可以选取 对,那么如果有连续的 那么假设 的长度为 那不能选取的对数就是 。将这些 划分为 个组,以便使每个组的
最优的方法是将它们分成相等的组或尽可能相等。
每组的长度就是 ,令
这些不能选取的区间总数就是
如果不能整除划分区间,就把多余的 分到每个区间内,这样加上这些 对每个区间 不能选取的对数就变成了 。全部的就是
用全部可选的减去不能选取的就是最后答案。
AC代码: