CF675B.Restoring Painting

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

瓦西娅在美术馆担任保安。不幸的是,一幅最昂贵的画作在他值班期间被盗了。他不想被解雇,因此必须尽快复原这幅画作。他记得关于这幅画作的一些事实:

  • 这幅画作是一个 3×33 \times 3 的方阵,每个格子中填有一个 11 到 nn 之间的整数(含端点),不同格子中的整数可以相同,也可以不同;
  • 四个 2×22 \times 2 子方阵(即所有可能的 2×22 \times 2 连续子块)中,每个子方阵内四个整数之和均等于左上角 2×22 \times 2 子方阵的元素和;
  • 四个元素 aa、bb、cc 和 dd 的值已知,其位置如下面图片所示。

请帮助瓦西娅计算出满足上述所有条件的不同 3×33 \times 3 方阵的个数。注意:该数目可能为 00,这意味着瓦西娅的记忆有误。

若存在某个格子,在两个方阵中填入的整数不同,则称这两个方阵互不相同。

输入格式

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.

输入的第一行包含五个整数 nn、aa、bb、cc 和 dd(1 ≤ n ≤ 100 0001 ≤ n ≤ 100\,000,1 ≤ a, b, c, d ≤ n1 ≤ a,\,b,\,c,\,d ≤ n)—— 分别表示单元格中整数的最大可能值,以及 Vasya 记得的四个整数。

输出格式

Print one integer — the number of distinct valid squares.

输出一个整数——不同有效正方形的数量。

输入输出样例

  • 输入#1

    2 1 1 1 2

    输出#1

    2
  • 输入#2

    3 3 1 2 3

    输出#2

    6

说明/提示

Below are all the possible paintings for the first sample.

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

以下是第一个样例的所有可能的画作。

在第二个样例中,仅有下方展示的画作满足所有规则。





输入解题思路,AI测评打分。不知道怎么写?

首页