4160: Sofa Thief

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:4 通过:4

题目描述

C. Sofa Thief
又一轮DecoForces即将到来!马克爷爷想参加,但有人偷走了他的珍贵沙发!面对如此重大的损失,如何才能表现出色?
幸运的是,小偷给马克爷爷留了一张纸条。这张纸条把马克带到了沙发仓库。他仍然不知道哪张沙发属于他,因为它们看起来都一样!
仓库表示为矩阵n×m。每一张沙发都有两个相邻的边格。没有一间牢房被一张以上的沙发覆盖。可能有空单元格。
如果存在两个这样的单元A和B,xa<xb,A被A覆盖,B被B覆盖,沙发A位于沙发B的左侧。
注意在所有条件下A≠B。另外,一些沙发A既可以放在另一个沙发B的顶部,也可以放在沙发B的底部。左右两侧的情况也是一样的。
笔记还指出,马克爷爷的沙发左侧有cntl沙发,右侧有cntr−,顶部有cntt−,底部有cntb−。
马克爷爷请你帮他辨认沙发。保证在给定条件下不超过一张沙发。
输出马克爷爷沙发的数量。如果没有满足所有条件的沙发,则输出-1。


Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n×m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that xa<xb, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that ya<yb, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions AB. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cntl sofas to the left of Grandpa Maks's sofa, cntr − to the right, cntt − to the top and cntb − to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
Input
The first line contains one integer number d (1≤d≤105) − the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1≤n,m≤105) − the size of the storehouse.
Next d lines contains four integer numbers x1, y1, x2, y2 (1≤x1,x2n, 1≤y1,y2m) − coordinates of the i-th sofa. It is guaranteed that cells (x1,y1) and (x2,y2) have common side, (x1,y1) (x2,y2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cntl, cntr, cntt, cntb (0≤cntl,cntr,cntt,cntbd-1).
Output
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
Examples
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
Note
Let's consider the second example.
  • The first sofa has 0 to its left, 2 sofas to its right ((1,1) is to the left of both (5,5) and (5,4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below).
  • The second sofa has cntl=2, cntr=1, cntt=2 and cntb=0.
  • The third sofa has cntl=2, cntr=1, cntt=1 and cntb=1.
So the second one corresponds to the given conditions.
In the third example
  • The first sofa has cntl=1, cntr=1, cntt=0 and cntb=1.
  • The second sofa has cntl=1, cntr=1, cntt=1 and cntb=0.
And there is no sofa with the set (1,0,0,0) so the answer is -1.

输入格式

第一行包含一个整数d(1≤d≤105)−仓库中沙发的数量。
第二行包含两个整数n,m(1≤n,m≤105)−仓库的大小。
接下来的d行包含四个整数x1,y1,x2,y2(1≤x1,x2≤n,1≤y1,y2≤m)−第i张沙发的坐标。保证单元(x1,y1)和(x2,y2)具有公共侧,(x1,y2,≠(x2,y2),并且没有单元被一个以上的沙发覆盖。
最后一行包含四个整数cntl、cntr、cntt、cntb(0≤cntl,cntr,cntt,cntb≤d-1)。

输出格式

打印满足所有条件的沙发的编号。沙发编号为1到d,如输入所示。如果没有这样的沙发,请打印-1。

输入样例 复制

2
3 2
3 1 3 2
1 2 2 2
1 0 0 1

输出样例 复制

1