B. Restoring Painting

来源:互联网 发布:昆仑虚麒麟臂升阶数据 编辑:程序博客网 时间:2024/06/08 16:53

time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 abc 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 nabc and d (1 ≤ n ≤ 100 0001 ≤ 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.

Examples
input
2 1 1 1 2
output
2
input
3 3 1 2 3
output
6
Note

Below are all the possible paintings for the first sample.

In the second sample, only paintings displayed below satisfy all the rules.


解题说明:此题是一道数学题,已知9宫格内四个数字,求其他数字,让其满足每个2x2的正方形内数字之和相等,通过公式进行计算并判断即可。


#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main(){long long int n,a,b,c,d,s=0,i,dd,bb,cc;scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);    for(i=1;i<=n;i++)    {    dd=a+i-d;    cc=b+i-c;    bb=b+dd-c;    if(bb>0 && cc>0 && dd>0 && bb<=n && cc<=n && dd<=n)    {s++;}    }    printf("%lld\n",n*s);return 0;}


0 0