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 A ≠ B. 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, x2 ≤ n, 1 ≤ y1, y2 ≤ m) — 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, cntb ≤ d - 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.

题意,沙发店里找一个符合上面,下面,左面,右面有几个沙发的沙发,注意,如果两个沙发坐标是(1,1)(2,1)和(1,4)(2,4),那么他们两个的左面和右面各有一个沙发

解法,四个方向分别排序,然后暴力跑每一个沙发,排序方向上坐标符合第几个沙发的就加一,然后最后找找有没有加到4的沙发就可以了,但是有一个要特判,就是如果,符合的太多了,在排序之后还有符合的,且他的排序方向上的两个坐标是不一样的,那么就不存在,比如(1,1)(2,1)和(1,4)(2,4),要你找上面一个,下面0个左边一个,右边0 个的,明显,这时候的右边,都是1个,要输出-1

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#define sf scanf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define vi vector<int>
#define mp make_pair
#define pf printf
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=a;i>=n;i--)
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
const double eps=1e-6;
const double pi=acos(-1.0);
const int inf=0x7fffffff;
const int N=1e5+7;
struct node
{
int id;
int x1,y1,x2,y2;
}a[N];
void predeal(node &x)
{
if(x.x1==x.x2)
{
if(x.y1>x.y2)
swap(x.y1,x.y2);
}
if(x.y1==x.y2)
{
if(x.x1>x.x2)
swap(x.x1,x.x2);
}
}
bool cmp1(node x,node y)
{
if(x.x2!=y.x2)
return x.x2 <y.x2;
return x.x1 <y.x1;
}
bool cmp2(node x,node y)
{
if(x.x1 !=y.x1)
return x.x1 >y.x1;
return x.x2 >y.x2;
}
bool cmp3(node x,node y)
{
if(x.y2!=y.y2)
return x.y2 <y.y2 ;
return x.y1 <y.y1 ;
}
bool cmp4(node x,node y)
{
if(x.y1 !=y.y1 )
return x.y1 >y.y1;
return x.y2 >y.y2;
}
int num[N];
int main()
{
mm(num,0);
int q;scf(q);
int n,m;scff(n,m);
rep(i,1,1+q)
{
a[i].id=i;
scff(a[i].x1,a[i].y1);
scff(a[i].x2,a[i].y2);
predeal(a[i]);
}
int u,d,l,r;
cin>>l>>r>>d>>u;
sort(a+1,a+q+1,cmp1);
rep(i,1,q+1)
{
if(a[l+1].x1==a[i].x1&&a[l+1].x2==a[i].x2)
{
num[a[i].id]++;
if(i>l+1&&a[i].x1 !=a[i].x2)//在排序方向要不是同一个高度,这样才会加一,如果是同一个高度那么就符合
{
cout<<"-1";return 0;
}
}
}
sort(a+1,a+1+q,cmp2);
rep(i,1,q+1)
{
if(a[r+1].x1==a[i].x1&&a[r+1].x2==a[i].x2)
{
num[a[i].id]++;
if(i>r+1&&a[i].x2!=a[i].x1)
{
cout<<"-1";return 0;
}
}
}
sort(a+1,a+1+q,cmp3);
rep(i ,1,q+1)
{
if(a[d+1].y1==a[i].y1&&a[d+1].y2==a[i].y2)
{
num[a[i].id]++;
if(i>d+1&&a[i].y1!=a[i].y2)
{
cout<<"-1";return 0;
}
}
}
sort(a+1,a+1+q,cmp4);
rep(i,1,q+1)
{
if(a[u+1].y1==a[i].y1&&a[u+1].y2==a[i].y2)
{
num[a[i].id]++;
if(i>u+1&&a[i].y1 !=a[i].y2)
{
cout<<"-1";return 0;
}
} }
int ans=-1;
rep(i,1,q+1)
if(num[i]==4) ans=i;
prf(ans);
return 0;
}

818C.soft thief的更多相关文章

  1. Codeforces 817+818(A~C)

    (点击题目即可查看原题) 817A Treasure Hunt 题意:给出起点和终点,每次移动只能从 (a,b)移动至(a+x,b+y) , (a+x,b-y) , (a-x,b+y) , (a-x, ...

  2. 数据库设计中的Soft Delete模式

    最近几天有点忙,所以我们今天来一篇短的,简单地介绍一下数据库设计中的一种模式——Soft Delete. 可以说,该模式毁誉参半,甚至有非常多的人认为该模式是一个Anti-Pattern.因此在本篇文 ...

  3. linux內核輸出soft lockup

    創建的內核線程長期佔用cpu,一直內核認為線程soft lockup,如無法獲取自旋鎖等:因此線程可適度調用schdule(),以進行進程的調度:因為kwatchdog的執行級別低,一直得不到執行 [ ...

  4. codeforces 632+ E. Thief in a Shop

    E. Thief in a Shop time limit per test 5 seconds memory limit per test 512 megabytes input standard ...

  5. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

  6. 撤销git reset soft head操作

    一不小心在eclipse的git库中执行了Reset Soft(HEAD ONLY)操作,不料界面中竟然没有找到撤销方法(于是心中五味俱全,经过一番折腾,无果还是回归Git本身),最终通过命令行,很快 ...

  7. git reset soft,hard,mixed之区别深解

    GIT reset命令,似乎让人很迷惑,以至于误解,误用.但是事实上不应该如此难以理解,只要你理解到这个命令究竟在干什么. 首先我们来看几个术语 HEAD 这是当前分支版本顶端的别名,也就是在当前分支 ...

  8. SVM3 Soft Margin SVM

    之前分为两部分讨论过SVM.第一部分讨论了线性SVM,并且针对线性不可分的数据,把原始的问题转化为对偶的SVM求解.http://www.cnblogs.com/futurehau/p/6143178 ...

  9. 强(strong)、软(soft)、弱(weak)、虚(phantom)引用

    https://github.com/Androooid/treasure/blob/master/source/lightsky/posts/mat_usage.md 1.1 GC Root JAV ...

随机推荐

  1. opencv基础教程

    1,基本语法 环境:python3.6.6+numpy+opencv3 安装:没有详细编译,直接pip install opencv-python 矩阵和图片: img=numpy.zeros((3, ...

  2. WPF UserControl响应窗体的PreviewKeyDown事件

    目的 在UserControl页面实现通过快捷键打开新建窗口 实现过程 监听Window窗体的PreviewKeyDown 其实,使用KeyDown事件也是可以的 页面代码 <Window x: ...

  3. .Net Core---- WebApi生成Swagger接口文档

    1. Swagger是什么? Swagger 是一个规范和完整的框架,用于生成.描述.调用和可视化 RESTful 风格的 Web 服务.总体目标是使客户端和文件系统作为服务器以同样的速度来更新.文件 ...

  4. java 冒泡排序 day003

    一.冒泡排序: 利用冒泡排序对数组进行排序 二.基本概念: 依次比较相邻的两个数,将小数放在前面,大数放在后面.即在第一趟:首先比较第1个和第2个数,将小数放前,大数放后.然后比较第2个数和第3个数, ...

  5. xgb

    xgb原理 xgb代码

  6. SQL语句原理解析(原创)

    基本的sql语句很好理解这里不做分析,这里只考虑复杂的sql语法和关键词用法的实验分析: 一,join关联的作用: 作用: 1,为了生成信息信息更加全面的中间表:2,为了where可以使用含有单表外字 ...

  7. 主席树——树链上第k大spoj COT

    首先要求第k大就想到用主席树来处理 但是不能直接用树链剖分的dfs序来维护,因为一条链对应的dfs下标可能是断开的几段,无法用权值线段树来维护 那么久维护每个点到根节点的全值线段树,结点u的权值线段树 ...

  8. oop编程思想简单理解

    四大基本特性: 抽象:提取现实世界中某事物的关键特性,为该事物构建模型的过程.对同一事物在不同的需求下,需要提取的特性可能不一样.得到的抽象模型中一般包含:属性(数据)和操作(行为).这个抽象模型我们 ...

  9. jq实现遮罩等待转圈

    function Show_TopDiv(msg,msg_Width,msg_Height) { var titleheight = "22px"; // 提示窗口标题高度 var ...

  10. java笔记:排错5:误删maven target:恢复不了,怎么再生成

    上篇讲过,误删maven项目的target,或clean以后,target文件夹会删掉. 想要重新加载模块生成最新的target目录,可以再跑一下tomcat. 但有时不灵,可能是因为Tomcat本身 ...