Description
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it.
- The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers.
- The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2.
- Four elements a, b, c and d are known and are located as shown on the picture below.
Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.
Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.
Input
The first line of the input contains five integers n, a, b, c and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.
Output
Print one integer — the number of distinct valid squares.
Sample Input
2 1 1 1 2
2
3 3 1 2 3
6
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,a,b,c,d,e,f,h,i;
long long ans;//1<=n<=100 000 ans可能超int
while(~scanf("%d",&n))
{
ans=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
for(e=1;e<=n;e++)
{
f=e+b-c;
h=e+a-d;
i=e+a+b-c-d;
if((f>=1&&f<=n)&&(h>=1&&h<=n)&&(i>=1&&i<=n))
ans++;
else
continue;
}
ans*=n;
printf("%lld\n",ans);
}
return 0;
}