题干:

You are given a chessboard of size n×nn×n. It is filled with numbers from 11 to n2n2 in the following way: the first ⌈n22⌉⌈n22⌉ numbers from 11 to ⌈n22⌉⌈n22⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n2−⌈n22⌉n2−⌈n22⌉ numbers from ⌈n22⌉+1⌈n22⌉+1 to n2n2 are written in the cells with odd sum of coordinates from left to right from top to bottom. The operation ⌈xy⌉⌈xy⌉ means division xx by yy rounded up.

For example, the left board on the following picture is the chessboard which is given for n=4n=4 and the right board is the chessboard which is given for n=5n=5.

You are given qq queries. The ii-th query is described as a pair xi,yixi,yi. The answer to the ii-th query is the number written in the cell xi,yixi,yi (xixi is the row, yiyi is the column). Rows and columns are numbered from 11 to nn.

Input

The first line contains two integers nn and qq (1≤n≤1091≤n≤109, 1≤q≤1051≤q≤105) — the size of the board and the number of queries.

The next qq lines contain two integers each. The ii-th line contains two integers xi,yixi,yi(1≤xi,yi≤n1≤xi,yi≤n) — description of the ii-th query.

Output

For each query from 11 to qq print the answer to this query. The answer to the ii-th query is the number written in the cell xi,yixi,yi (xixi is the row, yiyi is the column). Rows and columns are numbered from 11 to nn. Queries are numbered from 11 to qq in order of the input.

Examples

Input

4 5
1 1
4 4
4 3
3 2
2 4

Output

1
8
16
13
4

Input

5 4
2 1
4 2
3 3
3 4

Output

16
9
7
20

Note

Answers to the queries from examples are on the board in the picture from the problem statement.

题目大意:

这题干已经没法看了,,格式都乱了,但是题意很简单。给一个n,然后先填x和y坐标和为偶数的,填满后再填奇数的。给q个询问,每个询问x和y坐标,输出这个坐标的值是多少。

解题报告:

这题是真!MMP! 无聊!!首先看(x+y)是奇数还是偶数,然后xjb找规律,,,真的是无聊这题,,,大概就是先算前(x-1)行的,再看第x行的

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{ll n,q,x,y;cin>>n>>q;while(q--) {scanf("%lld%lld",&x,&y);ll ans = n*(x-1) + y + 1;if((x+y) % 2 == 1) {ans += n*n;}       cout << ans/2 << endl;}return 0 ;
}

【CodeForces - 1027B 】Numbers on the Chessboard (没有营养的找规律题,无聊题)相关推荐

  1. 【CodeForces - 1062C】Banh-mi (贪心,数学,找规律,快速幂)

    题干: JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has ...

  2. 【CodeForces - 764A】Taymyr is calling you (找规律,水题)

    题干: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taym ...

  3. Codeforces Round #327 (Div. 2) C Median Smoothing(找规律)

    分析: 三个01组合只有八种情况: 000 s 001 s 010 0 011 s 100 s 101 1 110 s 111 s 可以看出只有010,101是不稳定的.其他都是稳定的,且连续地出现了 ...

  4. codeforces:E. Add Modulo 10【状态压缩 + 找规律】

    分析 分类讨论,进行操作 [5,0]落回0 其余落到2 然后就停止 分两类 如果是第一类,必须是同一个0结尾才行 如果第二类,必须%20相同才行 ac code import sys input = ...

  5. codeforces:C. Another Array Problem【分类讨论 + 找规律】

    目录 题目截图 题目分析 ac code 总结 题目截图 题目分析 做cf题目别老想着套算法模版 找规律才是正道,这就是所谓的「思维」 n = 2很简单 n >= 4: # 肯定有一个最大值,不 ...

  6. Codeforces 1327 E. Count The Blocks(递推找规律)

    题意: 给出一个 n n n,求 1 0 n 10^n 10n 内长度为 1 1 1到 n n n的块分别有多少个.块的含义是连续相同数字的长度. 第一眼以为数位 d p dp dp 暴力打表出前几项 ...

  7. Numbers on the Chessboard

    You are given a chessboard of size n×nn×n. It is filled with numbers from 11 to n2n2 in the followin ...

  8. B. Numbers on the Chessboard -codeforces1027 -csdn博客

    B. Numbers on the Chessboard -codeforces1027 -csdn博客 You are given a chessboard of size n×n. It is f ...

  9. CF1027B Numbers on the Chessboard (#数学)

    题目描述 You are given a chessboard of size n \times nn×n . It is filled with numbers from 11 to n^2n2 i ...

最新文章

  1. 处理一键安装LNMP环境之后,phpinfo.php打开不显示内容的问题
  2. LDO和DC-DC的区别
  3. vscode编辑器tab换行缩进问题
  4. android+4.4+jni闪退,native2.1 安卓退到后台时,概率闪退
  5. Ubuntu中useradd和adduser的区别
  6. CentOS+Subversion 配置Linux 下 SVN服务器
  7. sql语句的书写顺序和执行顺序(包括各种可能的指令)
  8. iWebOffice一些相关
  9. php输入指定文字转换成图片的简单例子
  10. cesium接入天地图影像与注记(经纬度)(cesium篇.70)
  11. SpringBoot生成条形码
  12. chrome-功能指令
  13. boss是董卓的java游戏_武将列传世界BOSS董卓-殒命长安攻略
  14. IDEA中maven项目dependencies报错飘红问题解决
  15. 车牌识别计算机应用领域,车牌识别技术应用场景分析
  16. 提升技术领导力实操指南
  17. 保时捷Taycan的800V电气架构赏析
  18. fidder classic 界面介绍
  19. 全网最佳优惠券使用算法
  20. HDU Employment Planning

热门文章

  1. 1668智能下数教程视频_你需要的教程合集更新
  2. mysql编程_PHP数据库编程之一MySQL优化策略概述
  3. 浙江省高等学校计算机等级考试有什么用,06秋年秋浙江省高等学校计算机等级考试试卷(三级数据库技术及应用)...
  4. php功能大马加密乱码,php大马加密工具 phpTrace:奇虎360开源的PHP脚”的相关知识...
  5. Tecplot如何保存frame style 并调用frame style
  6. python dataframe删除重复行_详解pandas使用drop_duplicates去除DataFrame重复项参数
  7. Tiny6410上安装debian基本系统的过程
  8. [vc]如何对radio按钮分组
  9. wince2秒快速启动TOC分析
  10. python中的类怎样理解_理解Python数据类:Dataclass fields 的概述(下)