Byung is playing a game on her infinite checkerboard. The goal of the game is to move from a starting position ( r s, c s) to a target position ( r t, c t) using exactly x moves, where x is determined by a roll of a N-sided dice.
A move consists in going from a square on the checkerboard to one of its four neighbors - up, down, left or right.
Her dice is unbiased, meaning that every number from 1 to N has the same probability of being rolled.
She’s interested in knowing what’s the number of different rolls that allow her to move to the target position in the last move. She can move to the same square more than once if she needs to. Can you help her?
Input
The input is composed by a single line containing 5 integers N (1 ≤ N ≤ 109), r s, c s, r t and c t ( - 109 ≤ r s, c s, r t, c t ≤ 109) indicating respectively the number of sides of the dice, the coordinates of the starting position and the coordinates of the target position.
Output
An integer number indicating the number of outcomes that she’ll get a good roll.
Examples
Input
5 1 1 2 3
Output
2
Input
500 -100 -100 100 100
Output
51
给定一个限度n,和两个点的坐标;
计算出在限度n中,有多少步数可以由起点到达终点。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
long long int l1,l2,r1,r2;
long long int n,s,s1,s2;
scanf("%lld",&n);
scanf("%lld %lld %lld %lld",&l1,&l2,&r1,&r2);
s1=r1-l1;
s2=r2-l2;
if(s1<0){
s1=-s1;
}
if(s2<0){
s2=-s2;
}
s=s1+s2;
if(s<0)
s=-s;
if(s>0)
{
if(n<s)
{
printf("0\n");
}
else
{
n=n-s+2;
n=n/2;
printf("%lld\n",n);
}
}
else{
n=n/2;
printf("%lld\n",n);
}
return 0;
}