Inna and Huge Candy Matrix

CodeForces - 400C

Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).

The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.

Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

Input

The first line of the input contains fix integers nmxyzp (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105).

Each of the following p lines contains two integers xkyk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m)— the initial coordinates of the k-th candy. Two candies can lie on the same cell.

Output

For each of the p candies, print on a single line its space-separated new coordinates.

Examples

Input
3 3 3 1 1 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1

Note

Just for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:

QWER      REWQ 
ASDF -> FDSA
ZXCV VCXZ sol:题意简单清晰,只要膜过以后暴力模拟即可
/*
题目大意:给出n,m,x,y,z和p,表示在一个n*m的矩阵上有p块糖果,
给出p块糖果的坐标,然后将整个矩阵顺时针旋转x次,镜像翻转y次,
逆时针旋转z次,然后按照顺序输出操作完后糖果的坐标.
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m,X,Y,Z,cnt;
struct Point
{
int x,y;
}P[N];
inline void SSZ()
{
int i;
for(i=;i<=cnt;i++)
{
int xx=P[i].x,yy=P[i].y;
P[i].x=yy; P[i].y=n-xx+;
}
swap(n,m);
}
inline void JX()
{
int i;
for(i=;i<=cnt;i++) P[i].y=m-P[i].y+;
}
inline void NSZ()
{
int i;
for(i=;i<=cnt;i++)
{
int xx=P[i].x,yy=P[i].y;
P[i].x=m-yy+; P[i].y=xx;
}
swap(n,m);
}
int main()
{
int i;
R(n); R(m); R(X); R(Y); R(Z); R(cnt);
for(i=;i<=cnt;i++) {R(P[i].x); R(P[i].y);}
X%=; Y%=; Z%=;
for(i=;i<=X;i++) SSZ();
for(i=;i<=Y;i++) JX();
for(i=;i<=Z;i++) NSZ();
for(i=;i<=cnt;i++) W(P[i].x),Wl(P[i].y);
return ;
}
/*
Input
3 3 3 1 1 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
Output
1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1
*/
 

codeforces400C的更多相关文章

随机推荐

  1. nginx+keepalived高可用

    准备工作: yum install -y gcc openssl-devel pcre-devel install iptables-services setenforce 0 sed -ri 's/ ...

  2. vs code 快捷键设置:选中字母可以快速全部转换为大写或小写

    文件--->首选项--->键盘快捷方式--->搜索:"大写"--->点击"转换为大写"左侧的加号,然后设置快捷键后按enter即可完成添 ...

  3. 三、maven学习-高级

    maven父子工程

  4. Java并发编程——线程的基本概念和创建

    一.线程的基本概念: 1.什么是进程.什么是是线程.多线程? 进程:一个正在运行的程序(程序进入内存运行就变成了一个进程).比如QQ程序就是一个进程. 线程:线程是进程中的一个执行单元,负责当前进程中 ...

  5. git clone ssh 时出现 fatal: Could not read from remote repository

    一.问题及解决办法参考: 在 ubuntu 中,要把 GitHub 上的储存库克隆到计算机上时,执行如下命令: git clone git@github.com:USER-NAME/REPOSITOR ...

  6. 一点css 基础

    css 行内样式优先度最高 margin 属性 为声明外边距 如图 顺序依次为上右下左

  7. 文本分析:初识Gensim

    作者:doze_worm来源:https://www.douban.com/note/620615113/ gensim 起步:本节介绍理解和使用 gensim 所必须的基础概念和术语,并提供一个简单 ...

  8. Linux系统目录结构和文件基本属性

    一.Linux系统目录结构 二.Linux 文件基本属性 三.touch stat tar 命令 一.Linux系统目录结构 不同颜色文件的含义: inux 文件颜色的含义,蓝色代表目录,绿色代表可执 ...

  9. kali安装开启ssh & 安装docker

    ssh相关 一.配置SSH参数 . 修改sshd_config文件,命令为: vi /etc/ssh/sshd_config 将#PasswordAuthentication no的注释去掉,并且将N ...

  10. JavaScript【对象的学习】

    JavaScript对象的了解 1.js的String对象创建String对象:var str = "abc";方法和属性(参照W3C文档详细学习)属性 length:字符串的长度 ...