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 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.

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.

注意数据范围:

#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
ll n,a,b,c,d,s=;
cin>>n>>a>>b>>c>>d; for(int i=;i<=n;i++)
{
ll q1,q2,q3,q4,q5;
q1=i;
q2=q1+b-c;
q4=q1+a-d;
q5=q4+b-c;
int cnt=;
if(q1>=&&q1<=n)cnt++;
if(q2>=&&q2<=n)cnt++;
if(q4>=&&q4<=n)cnt++;
if(q5>=&&q5<=n)cnt++;
if(cnt==)
s++;
}
cout<<s*n;
}

最新文章

  1. c++顺序表基本功能
  2. 通过SQL Server自定义数据类型实现导入数据
  3. cacti监控juniper路由器
  4. LeetCode 20 -- Valid Parentheses
  5. 对于System.Net.Http的学习(二)——使用 HttpClient 进行连接
  6. idea配置2个tomcat
  7. Eclipse中项目红叉但找不到错误解决方法
  8. 重构第24天 分解复杂的判断(Remove Arrowhead Antipattern)
  9. 利用Oracle的row_number() over函数消除重复的记录
  10. linux学习之centos(三):网卡配置
  11. 通过js判断手机访问跳转到手机站
  12. Android Ant打包笔记
  13. 【互动问答分享】第15期决胜云计算大数据时代Spark亚太研究院公益大讲堂
  14. java基础3
  15. Mybatis基础学习(四)&mdash;关系映射
  16. 途虎养车Tuhu商城系统开发
  17. Pseudoforest(伪最大生成树)
  18. 免插件为WordPress文章中标签添加内链
  19. hibernate框架中注意的几个问题
  20. 元数据管理器中存在错误。 实例化来自文件“\\?\C:\Program Files\Microsoft SQL Server\MSAS11.MSSQLSERVER\OLAP\Data\Tfs_Analysis.0.db\vDimTestCaseOverlay.874.dim.xml”的元数据对象时出错。

热门文章

  1. hdu 2546饭卡
  2. 使用Timer和ScheduledThreadPoolExecutor执行定时任务
  3. Delphi多线程开发注意事项
  4. [LeetCode] Remove Duplicates from Sorted Array
  5. oracle pctfree和pctused详解
  6. DateTime还是DateTimeOffset?Now还是UtcNow?
  7. 第四篇:SOUI资源文件组织
  8. 通过ajax访问Tomcat服务器web service接口时出现No &#39;Access-Control-Allow-Origin&#39; header问题的解决办法
  9. Codeforces Alpha Round #20 (Codeforces format) C. Dijkstra?(裸的dijkstra)
  10. 编译原理实习(应用预测分析法LL(1)实现语法分析)