Algorithm


A. Friends Meeting
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the point x1 = a, another one is in the point x2 = b.

Each of the friends can move by one along the line in any direction unlimited number of times. When a friend moves, the tiredness of a friend changes according to the following rules: the first move increases the tiredness by 1, the second move increases the tiredness by 2, the third — by 3 and so on. For example, if a friend moves first to the left, then to the right (returning to the same point), and then again to the left his tiredness becomes equal to 1 + 2 + 3 = 6.

The friends want to meet in a integer point. Determine the minimum total tiredness they should gain, if they meet in the same point.

Input

The first line contains a single integer a (1 ≤ a ≤ 1000) — the initial position of the first friend.

The second line contains a single integer b (1 ≤ b ≤ 1000) — the initial position of the second friend.

It is guaranteed that a ≠ b.

Output

Print the minimum possible total tiredness if the friends meet in the same point.

Examples
input
Copy
3
4
output
Copy
1
input
Copy
101
99
output
Copy
2
input
Copy
5
10
output
Copy
9
Note

In the first example the first friend should move by one to the right (then the meeting happens at point 4), or the second friend should move by one to the left (then the meeting happens at point 3). In both cases, the total tiredness becomes 1.

In the second example the first friend should move by one to the left, and the second friend should move by one to the right. Then they meet in the point 100, and the total tiredness becomes 1 + 1 = 2.

In the third example one of the optimal ways is the following. The first friend should move three times to the right, and the second friend — two times to the left. Thus the friends meet in the point 8, and the total tiredness becomes 1 + 2 + 3 + 1 + 2 = 9.

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int main() {
	int a, b;
	cin << a << b;

	if(a < b)
		swap(a, b);

	bool t = true;
	int res = 0, aa = 1, bb = 1;
	while(a < b) {
		if(t> {
			++a;
			res += aa;
			++aa;
			t = !t;
		} else {
			--b;
			res += bb;
			++bb;
			t = !t;
		}
	}

	cout << res << endl;

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
4

Output

x
+
cmd
1
Advertisements

Demonstration


Codeforces Solution-Friends Meeting-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+