【CodeForces - 931A】【 Friends Meeting 】

题目:

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

3
4

Output

1

Input

101
99

Output

2

Input

5
10

Output

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.

题意不是很难懂 ,不解释了哈。

解题思路:暴力就行,两点之间的距离如果为1的时候,直接移动一个就行,距离较大的时候,咱们同时移动两者,向中心靠拢,如果是奇数的话,一定要把最后的一步放在最后,理由数学常识。

ac代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#define maxn 10100
using namespace std;
int n,m;
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		if(n>m)
		{
			int t=n;
			n=m;
			m=t;
		}
		int sum=0;
		int ant=1;
		while(n<m)
		{
			if(m-n==1)
			{
				sum+=ant;
				break;
			}
			n++;m--;
			sum+=2*ant++;	
		}
		printf("%d\n",sum);
	} 
	return 0;
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值