Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells are banned. Before the game, he has to put a few chips on some border (but not corner) board cells. Then for n - 1 minutes, Gerald every minute moves each chip into an adjacent cell. He moves each chip from its original edge to the opposite edge. Gerald loses in this game in each of the three cases:

  • At least one of the chips at least once fell to the banned cell.
  • At least once two chips were on the same cell.
  • At least once two chips swapped in a minute (for example, if you stand two chips on two opposite border cells of a row with even length, this situation happens in the middle of the row).

In that case he loses and earns 0 points. When nothing like that happened, he wins and earns the number of points equal to the number of chips he managed to put on the board. Help Gerald earn the most points.

Input

The first line contains two space-separated integers n and m (2 ≤ n ≤ 1000, 0 ≤ m ≤ 105) — the size of the field and the number of banned cells. Next m lines each contain two space-separated integers. Specifically, the i-th of these lines contains numbers xi and yi (1 ≤ xi, yi ≤ n) — the coordinates of the i-th banned cell. All given cells are distinct.

Consider the field rows numbered from top to bottom from 1 to n, and the columns — from left to right from 1 to n.

Output

Print a single integer — the maximum points Gerald can earn in this game.

Example

Input
3 1
2 2
Output
0
Input
3 0
Output
1
Input
4 3
3 1
3 2
3 3
Output
1

Note

In the first test the answer equals zero as we can't put chips into the corner cells.

In the second sample we can place one chip into either cell (1, 2), or cell (3, 2), or cell (2, 1), or cell (2, 3). We cannot place two chips.

In the third sample we can only place one chip into either cell (2, 1), or cell (2, 4).

关键是读懂题,大致的题意就是:一个n*n的矩阵四角和中间不能放东西,只能放在其他的边缘部分,刚开始有一些位置已经给定,挪动的过程中不能经过这些位置,要求在n-1步内,把物品从一侧移动到另一侧,且移动的过程中不能有重叠现象(应该是多个物品可以同时移动),问最多有多少这样的位置?

AC代码:

#include<stdio.h>

int main()
{
int n, m, x, y;
int ans = ;
bool cell_row[], cell_column[]; scanf("%d%d", &n, &m); int med = (n+)/; for(int i = ; i <= n; i++)
{
cell_column[i] = false;
cell_row[i] = false;
} for(int i = ; i <= m; i++)
{
scanf("%d%d", &x, &y);
cell_column[x] = true;
cell_row[y] = true;
} for(int i = ; i < n; i++)
{
if(!cell_row[i])
ans++;
} for(int i = ; i < n; i++)
{
if(n % == )
{
if(!cell_column[i])
ans++;
}
else if(n % != )
{
if(!cell_column[i] && (cell_row[i] == true || i != med))//如果中间行为true,但是中间列为false也可以
ans++;
}
} printf("%d\n", ans); return ;
}

A - Chips的更多相关文章

  1. 【UVALive - 5131】Chips Challenge(上下界循环费用流)

    Description A prominent microprocessor company has enlisted your help to lay out some interchangeabl ...

  2. Codeforces Round #194 (Div. 2) D. Chips

    D. Chips time limit per test:1 second memory limit per test:256 megabytes input:standard input outpu ...

  3. Codeforces Round #194 (Div. 1) B. Chips 水题

    B. Chips Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/333/problem/B D ...

  4. [2011WorldFinal]Chips Challenge[流量平衡]

    Chips Challenge Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. Chips CodeForces - 333B

    Chips CodeForces - 333B 题意:有一个n*n的棋盘,其中有m个格子被禁止.在游戏开始前要将一些芯片(?)放到四条边上(但不能是角上).游戏开始后,每次操作将每一个芯片移动到它四周 ...

  6. [译]Cookies Without Chocolate Chips

    Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...

  7. Angular Material 学习笔记 Chips

    依据 material guidelines, chips 可以用来做 filter https://material.io/design/components/chips.html#filter-c ...

  8. LeetCode.1217-交换芯片(Play with Chips)

    这是小川的第次更新,第篇原创 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第270题(顺位题号是1217).There are some chips, and the i-th ch ...

  9. 【leetcode】1217. Play with Chips

    题目如下: There are some chips, and the i-th chip is at position chips[i]. You can perform any of the tw ...

随机推荐

  1. 二:HTML文本编译器 kindeditor-4.1.10 的使用 SpringMVC+jsp的实现

    这和一篇与上一篇的区别在与,上一篇是直接请求到action我们剩下的都是我们全部手动处理, 而这一片篇是由kindeditor内部处理,图片上传到本地,基本上没什么区别,但是有一点一定要注意的就是,这 ...

  2. PostgreSQL 监控磁盘使用

    监控磁盘使用 1. 判断磁盘用量 每个表都有一个主要的堆磁盘文件,大多数数据都存储在其中.如果一个表有着可能会很宽(尺寸大)的列, 则另外还有一个TOAST文件与这个表相关联, 它用于存储因为太宽而不 ...

  3. maven 学习 十 关于打包

    clean package -Dmaven.test.skip=true -P product 这个命令干的活: 清class文件,打包构建,跳过测试,注意最后一个 -P product, 会激活项目 ...

  4. #关于 OneVsRestClassifier(LogisticRegression(太慢了,要用超过的机器)

    #关于 OneVsRestClassifier #注意以下代码中,有三个类 from sklearn import datasets X, y = datasets.make_classificati ...

  5. Shiro权限框架简介

    http://blog.csdn.net/xiaoxian8023/article/details/17892041   Shiro权限框架简介 2014-01-05 23:51 3111人阅读 评论 ...

  6. spring bean属性及子元素使用总结

    spring bean属性及子元素使用总结 2016-08-03 00:00 97人阅读 评论(0) 收藏 举报  分类: Spring&SpringMVC(17)  版权声明:本文为博主原创 ...

  7. ubuntu16搭建docker私库

    测试环境如下: 一.docker的安装 安装方法请查看这里的 安装教程 二.设置普通用户 1. centos的设置方法 $ sudo gpasswd -a docker ${USER} 2. ubun ...

  8. android 自定义控件之事件

    首先,继承需要扩展的VIEW,然后在里面添加一个自己的事件方法,例如, oniconclick(myinterface pinterface){ minterface = pinterface; } ...

  9. android下db-journal文件作用

    在学习数据库sqlite的过程中,发现在源文件包里除了生成db类型的数据库文件,还生成了db-journal类型的同名文件 查询网上资料后知道该文件是sqlite的一个临时的日志文件,主要用于sqli ...

  10. Codeforces 1110D Jongmah (DP)

    题意:你有n个数字,范围[1, m],你可以选择其中的三个数字构成一个三元组,但是这三个数字必须是连续的或者相同的,每个数字只能用一次,问这n个数字最多构成多少个三元组? 解析:首先我们容易发现,我们 ...