2327.Restoring Painting

Time Limit: 1s Memory Limit: 256MB

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 \times 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 \times 2 is equal to the sum of integers in the top left square 2 \times 2. Four elements a, b, c and d are known and are located as shown on the picture below. 2327_1.png 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 Format(From the terminal/stdin)

Input The first line of the input contains five integers n, a, b, c and d (1 \le n \le 100000, 1 \le a,b,c,d \le n)- maximum possible value of an integer in the cell and four integers that Vasya remembers.

Output Format(To the terminal/stdout)

Output Print one integer- the number of distinct valid squares.

Sample Input 1

Copy
2 1 1 1 2
 · · · · \n

Sample Output 1

Copy
2
 \n

Sample Input 2

Copy
3 3 1 2 3
 · · · · \n

Sample Output 2

Copy
6
 \n

Hints

Below are all the possible paintings for the first sample. 2327_2.png2327_3.pngIn the second sample, only paintings displayed below satisfy all the rules. 2327_4.png2327_5.png2327_6.png2327_7.png2327_8.png2327_9.png

Submit

请先 登录

© 2025 FAQs