Codeforces 1132 A 思维 水题

http://codeforces.com/contest/1132/problem/A

A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; "))" and ")((" are bracket sequences (but not regular ones), and "(a)" and "(1)+(1)" are not bracket sequences at all.

You have a number of strings; each string is a bracket sequence of length 22 . So, overall you have cnt1cnt1 strings "((", cnt2cnt2 strings "()", cnt3cnt3 strings ")(" and cnt4cnt4 strings "))". You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length 2(cnt1+cnt2+cnt3+cnt4)2(cnt1+cnt2+cnt3+cnt4) . You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either.

Input

The input consists of four lines, ii -th of them contains one integer cnticnti (0≤cnti≤1090≤cnti≤109 ).

Output

Print one integer: 11 if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, 00 otherwise.

Examples

Input

3
1
4
3

Output

1

Input

扫描二维码关注公众号,回复: 5474828 查看本文章
0
0
0
0

Output

1

Input

1
2
3
4

Output

0

Note

In the first example it is possible to construct a string "(())()(()((()()()())))", which is a regular bracket sequence.

In the second example it is possible to construct a string "", which is a regular bracket sequence.

题目大意: 你有四种括号,"((","()",")(","))", 给出四种括号的数量, 问能否将这些括号以某种顺序连接起来, 使得每个左括号都有与之匹配的右括号。

思路: 括号要全部匹配, 那么左括号的数量必须等于右括号的数量,因此cnt1必须等于cnt4才有可能, 而第二种括号"()"的数量是没有影响的, 因为这两个括号已经匹配了, 且第三种括号")("必须要有第一种括号和第四种括号才能做到匹配, 那么这道题就做出来了。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main()
{
    int cnt1,cnt2,cnt3,cnt4;
    scanf("%d%d%d%d",&cnt1,&cnt2,&cnt3,&cnt4);
    if(cnt1!=cnt4)
        printf("0\n");
    else
    {
        if(cnt1==0&&cnt3!=0)
            printf("0\n");
        else
            printf("1\n");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/xiji333/article/details/88324723