Codeforces Round 353 (Div. 2)
B
Restoring Painting
Codeforces
1400
原题
← AC →
翻译中…

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.
翻译中…

image

翻译中…

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.

翻译中…

Note

翻译中…

Below are all the possible paintings for the first sample. image image

翻译中…

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

翻译中…

样例

Input #1
2 1 1 1 2
Output #1
2
InputCopy OutputCopy
Input #2
3 3 1 2 3
Output #2
6
InputCopy OutputCopy
题目信息
题号
675B
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。