303490: CF675B. Restoring Painting

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Restoring Painting

题意翻译

#### 题目描述: 有一个九宫格,每个格子的值都在 $[1,n]$ 的区间内,现给出它上下左右四格的值,要求每一个 $2\times2$ 的方格的总和都相等,请你求出共有多少种填法。如果 $2\times2$ 格子的总和等于 $0$ ,则表示有数据被记错了。如果在不同的 $2\times2$ 的方格中包含两个不同的整数,则认为两个 $2\times2$ 的方格是不同的。 #### 输入格式: 一行,包含五个整数 $n$​​ , $a$​​ , $b$​​ , $c$​​ 和 $d$​​ ( $1\le n\le 10^5$​​ , $1\le a,b,c,d\le n$​​​​ ) 。 #### 输出格式: 仅输出一个整数,表示填法的总数。 #### 样例解释: 样例1的两种方法如下: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/025712069c9acbad081f2181d643827812c11163.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/9c464a7a8882ec5f9c7ca829fee67b297c3e5020.png) 样例2的六种方法如下: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/7027b6797b21d7224ee05ecd06a48452b2615498.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/098b5c120bcba03cb9e9e25703ed8cdcb8287d14.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/f60f2764919fa6766e9514333bfdbe0c808da67e.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/11c0404b15c724e758635e9735d5c11cc4dbb178.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/9a488180531c0a7b3a83207a0b69b8c29e912592.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/a75f8263ae2d6282b2410ef6a0c052f9244b963c.png)

题目描述

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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/0f3c26a74fb7d4541f81d99795e416d6efcfe395.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.

输入输出格式

输入格式


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

输出格式


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. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/025712069c9acbad081f2181d643827812c11163.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/9c464a7a8882ec5f9c7ca829fee67b297c3e5020.png) In the second sample, only paintings displayed below satisfy all the rules. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/7027b6797b21d7224ee05ecd06a48452b2615498.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/098b5c120bcba03cb9e9e25703ed8cdcb8287d14.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/f60f2764919fa6766e9514333bfdbe0c808da67e.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/11c0404b15c724e758635e9735d5c11cc4dbb178.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/9a488180531c0a7b3a83207a0b69b8c29e912592.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/a75f8263ae2d6282b2410ef6a0c052f9244b963c.png)

Input

题意翻译

#### 题目描述: 有一个九宫格,每个格子的值都在 $[1,n]$ 的区间内,现给出它上下左右四格的值,要求每一个 $2\times2$ 的方格的总和都相等,请你求出共有多少种填法。如果 $2\times2$ 格子的总和等于 $0$ ,则表示有数据被记错了。如果在不同的 $2\times2$ 的方格中包含两个不同的整数,则认为两个 $2\times2$ 的方格是不同的。 #### 输入格式: 一行,包含五个整数 $n$​​ , $a$​​ , $b$​​ , $c$​​ 和 $d$​​ ( $1\le n\le 10^5$​​ , $1\le a,b,c,d\le n$​​​​ ) 。 #### 输出格式: 仅输出一个整数,表示填法的总数。 #### 样例解释: 样例1的两种方法如下: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/025712069c9acbad081f2181d643827812c11163.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/9c464a7a8882ec5f9c7ca829fee67b297c3e5020.png) 样例2的六种方法如下: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/7027b6797b21d7224ee05ecd06a48452b2615498.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/098b5c120bcba03cb9e9e25703ed8cdcb8287d14.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/f60f2764919fa6766e9514333bfdbe0c808da67e.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/11c0404b15c724e758635e9735d5c11cc4dbb178.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/9a488180531c0a7b3a83207a0b69b8c29e912592.png)![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF675B/a75f8263ae2d6282b2410ef6a0c052f9244b963c.png)

加入题单

算法标签: