Sagheer and Crossroads

 题目链接:http://codeforces.com/problemset/problem/812/A

                                             Sagheer and Crossroads

     Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.

                     Sagheer and Crossroads

An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.

Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.

Input

The input consists of four lines with each line describing a road part given in a counter-clockwise order.

Each line contains four integers lsrp — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.

Output

On a single line, print "YES" if an accident is possible, and "NO" otherwise.

Examples

input

1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1

output

YES

input

0 1 1 0
1 0 1 0
1 1 0 0
0 0 0 1

output

NO

input

1 0 0 0
0 0 0 1
0 0 0 0
1 0 1 0

output

NO

Note

In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3can hit pedestrians of part 4.

In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.

题意:四个方向有车子过来,车子可以向左,向前,向右开。输入数据,输入四行四列的数据,每一行输入L,S,R,P;

L=1代表着有向左开的车灯亮了,S=1代表着有向前开的车灯亮了,R=1代表着有向右开的车灯亮了,P=1代表的是行人的过道灯亮了。灯亮了则代表可以通过,题目让我们求的是,是否车子会撞上行人,是则输出"YES",否则输出"NO";

其实总共就四个方向,考虑行人通过时,各个方向是否有车子可以通过即可。

 

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int main()
{
    int q=0;
    int l[5],r[5],s[5],p[5];
    for(int i=1;i<=4;i++)
    {
        cin>>l[i]>>s[i]>>r[i]>>p[i];
    }
    if(p[1]==1)
    {
        if(l[1]==1||s[1]==1||r[1]==1||l[2]==1||s[3]==1||r[4]==1)
            q=1;
    }
    if(p[2]==1)
    {
        if(l[2]==1||s[2]==1||r[2]==1||l[3]==1||s[4]==1||r[1]==1)
            q=1;
    }
    if(p[3]==1)
    {
        if(l[3]==1||s[3]==1||r[3]==1||l[4]==1||s[1]==1||r[2]==1)
            q=1;
    }
    if(p[4]==1)
    {
        if(l[4]==1||s[4]==1||r[4]==1||l[1]==1||s[2]==1||r[3]==1)
            q=1;
    }
    if(q==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}