A. Orchestra

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.

Two pictures are considered to be different if the coordinates of corresponding rectangles are different.

Input

The first line of input contains four space-separated integers r, c, n, k (1 ≤ r, c, n ≤ 10, 1 ≤ k ≤ n) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively.

The next n lines each contain two integers xi and yi (1 ≤ xi ≤ r, 1 ≤ yi ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.

Output

Print a single integer — the number of photographs Paul can take which include at least k violas.

Examples

Input

2 2 1 1

1 2

Output

4

Input

3 2 3 3

1 1

3 1

2 2

Output

1

Input

3 2 3 2

1 1

3 1

2 2

Output

4

Note

We will use ‘*’ to denote violinists and ‘#’ to denote violists.

In the first sample, the orchestra looks as follows

*#

**

Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.

In the second sample, the orchestra looks as follows

*

*#

*

Paul must take a photograph of the entire section.

In the third sample, the orchestra looks the same as in the second sample.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <map>
using namespace std; typedef long long int llint;
#define mem(a) memset(a, 0, sizeof(a))
#define pi acos(-1)
const llint maxn = 1e5+100;
/*-------------------模板-----------------------------------------*/
template <typename T>
int com(const T& v1, const T& v2) {
if (v1 < v2) return -1;
else if (v1 > v2) return 1;
return 0;
}
int a[20][20];
int b[maxn], vis[maxn]; int check(int x,int x1,int y,int y1)
{
int ans = 0;
for (int i = x;i<=x1;i++)
for (int j = y;j<=y1;j++)
if (a[i][j])
ans++;
return ans;
} int main() {
int r, c, n, k; cin >> r >> c >> n >> k;
mem(a);
while (n --) {
int x, y; cin >> x >> y;
a[x][y] = 1;
}
// cout << k << endl;
// cout << a[1][1] << a[1][2] <<a[3][1] << endl;
int num = 0, num2 = 0, res = 0;
for (int i = 1; i<=r; i++) {
for (int ii = i; ii<=r; ii++) {
for (int j = 1; j<=c; j++) {
for (int jj = j; jj<=c; jj++) {
if (check(i, ii, j, jj) >= k) res ++ ;
}
}
}
}
cout << res << endl;
return 0;
}

B. Island Puzzle

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The center of each island contains an identical pedestal, and all but one of the islands has a fragile, uniquely colored statue currently held on the pedestal. The remaining island holds only an empty pedestal.

The islanders want to rearrange the statues in a new order. To do this, they repeat the following process: First, they choose an island directly adjacent to the island containing an empty pedestal. Then, they painstakingly carry the statue on this island across the adjoining bridge and place it on the empty pedestal.

Determine if it is possible for the islanders to arrange the statues in the desired order.

Input

The first line contains a single integer n (2 ≤ n ≤ 200 000) — the total number of islands.

The second line contains n space-separated integers ai (0 ≤ ai ≤ n - 1) — the statue currently placed on the i-th island. If ai = 0, then the island has no statue. It is guaranteed that the ai are distinct.

The third line contains n space-separated integers bi (0 ≤ bi ≤ n - 1) — the desired statues of the ith island. Once again, bi = 0 indicates the island desires no statue. It is guaranteed that the bi are distinct.

Output

Print “YES” (without quotes) if the rearrangement can be done in the existing network, and “NO” otherwise.

Examples

Input

3

1 0 2

2 0 1

Output

YES

Input

2

1 0

0 1

Output

YES

Input

4

1 2 3 0

0 3 2 1

Output

NO

Note

In the first sample, the islanders can first move statue 1 from island 1 to island 2, then move statue 2 from island 3 to island 1, and finally move statue 1 from island 2 to island 3.

In the second sample, the islanders can simply move statue 1 from island 1 to island 2.

In the third sample, no sequence of movements results in the desired position.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <map>
using namespace std; typedef long long int llint;
#define mem(a) memset(a, 0, sizeof(a))
#define pi acos(-1)
const llint maxn = 2e5+100;
/*-------------------模板-----------------------------------------*/
template <typename T>
int com(const T& v1, const T& v2) {
if (v1 < v2) return -1;
else if (v1 > v2) return 1;
return 0;
} int a[maxn], b[maxn]; int main() {
int n; scanf("%d",&n);
for (int i = 1; i<=n; i++) scanf("%d",&a[i]);
for (int i = 1; i<=n; i++) scanf("%d",&b[i]);
int pos, f = a[1];
if (a[1] == 0) f = a[2];
for (int i = 1; i<=n; i++) {
if (f == b[i]) {
pos = i;
break;
}
}
int flag = 0;
for (int i = 1; i<=n; i++) {
if (a[i] == b[pos]) {
pos ++ ;
if (pos == n+1) pos = 1;
}
else if (a[i] == 0 && b[pos] == 0) {
pos ++ ;
if (pos == n+1) pos = 1;
}
else if (a[i] == 0 && b[pos] != 0) continue;
else if (a[i] != 0 && b[pos] == 0) {
pos ++;
if (pos == n+1) pos = 1;
if (a[i] != b[pos]) flag = 1;
pos ++ ;
if (pos == n+1) pos = 1;
}
else if (a[i] != b[pos]) {
flag = 1;
pos ++ ;
if (pos == n+1) pos = 1;
}
}
if (flag) printf("NO\n");
else printf("YES\n");
return 0;
}

codeforces A. Orchestra B. Island Puzzle的更多相关文章

  1. codeforces B. Island Puzzle

    B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  2. codeforce B Island Puzzle

    B. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  3. CF 634A Island Puzzle

    A. Island Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  4. Codeforces GYM 100114 B. Island 水题

    B. Island Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description O ...

  5. Codeforces 540D Bad Luck Island

    http://codeforces.com/problemset/problem/540/D 题目大意: 会出石头.剪刀.布的人分别有r,s,p个,他们相互碰到的概率相同,输的人死掉,问最终活下去的人 ...

  6. CodeForces - 540D Bad Luck Island —— 求概率

    题目链接:https://vjudge.net/contest/226823#problem/D The Bad Luck Island is inhabited by three kinds of ...

  7. 【codeforces 761E】Dasha and Puzzle

    [题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...

  8. Codeforces B. Bad Luck Island(概率dp)

    题目描述: Bad Luck Island time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces 627E - Orchestra(双向链表,思维题)

    Codeforces 题目传送门 & 洛谷题目传送门 下设 \(n,m\) 同阶. 首先有一个傻子都会的暴力做法,枚举矩形的上.下边界 \(l,r\),考虑集合多重集 \(S=\{y|x\in ...

随机推荐

  1. 命令行执行php脚本 中$argv和$argc

    在实际工作中有可能会碰到需要在nginx命令行执行php脚本的时候,当然你可以去配置一个conf用外网访问. 在nginx命令行中 使用 php index.php 就可以执行这个index.php脚 ...

  2. 计算机和HMI设备通信之程序上下载

    1.传送模式 2.串行接口传送HMI,软件采用Wincc flexable smart v3 3.设置HMI设备,给HMI设备上电 打开控制面板,双击Transfer 使能Enable Channel ...

  3. UVA 11825 Hackers' Crackdown

    题目大意就是有一个图,破坏一个点同时可以破坏掉相邻点.每个点可以破坏一次,问可以完整破坏几次,点数=16. 看到16就想到状压什么的. 尝试设状态:用f[i]表示选的情况是i(一个二进制串),至少可以 ...

  4. 解决mysql漏洞 Oracle MySQL Server远程安全漏洞(CVE-2015-0411)

    有时候会检测到服务器有很多漏洞,而大部分漏洞都是由于服务的版本过低的原因,因为官网出现漏洞就会发布新版本来修复这个漏洞,所以一般情况下,我们只需要对相应的软件包进行升级到安全版本即可. 通过查阅官网信 ...

  5. PHP Session的优化使用

    前言 首先说一下,原版session实际并不是很烂,如果你的项目不是高并发项目,完全可以使用原版session. PHP默认的session是以文件形式保存在本地磁盘上的,每次访问实际就是一次io操作 ...

  6. java 信号量Semaphore

    Semaphore 信号量主要用于约束多个线程可同时获取的物理上的或者逻辑上的资源数.比如用在各种池的设计中. 信号量用于管理这些资源的一个虚拟的管理凭据.线程在获取一个资源时,首先要获取一个资源的许 ...

  7. Q:同时安装了python2和python3的电脑下pip的使用

    本人电脑设置的默认为python3.5的,由于需要,安装了pyhton2.7.之后需要为python2.7使用pip方式安装一个requests模块,但是,在命令行下执行pip install req ...

  8. JavaScript的DOM编程--08--复习

    <html> <head> <meta http-equiv="Content-Type" content="text/html; char ...

  9. thinkinginjava学习笔记05_访问权限

    Java中访问权限等级从大到小依次为:public.protected.包访问权限(没有关键词).private: 以包访问权限为界限,public.protected分别可以被任意对象和继承的对象访 ...

  10. tornado返回指定的http code

    最近做web api,需要在接口返回异常时,返回对应的http code. 查了下tornado的文档,是通过set_status方法来设置返回的http code,做个记录. self.set_st ...