Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/boolean-tortburchaklar-kesishadimi

Do the rectangles intersect?

Medium 1000 ms 64 MB 39%
Share

Two rectangles with sides parallel to the coordinate axes are given on the plane. The lower-left corner of the first is $(x_{1}; y_{1})$ and its upper-right corner is $(x_{2}; y_{2})$; for the second they are $(x_{3}; y_{3})$ and $(x_{4}; y_{4})$. The border of a rectangle belongs to it too. Check whether the statement is true: “the rectangles have at least one common point”. Touching only at a corner or along a side also counts as a common point.

The intersection area of two rectangles

Input

The first line contains four integers: $x_{1}$, $y_{1}$, $x_{2}$ and $y_{2}$.
The second line contains four integers: $x_{3}$, $y_{3}$, $x_{4}$ and $y_{4}$.

Output

One integer: $1$ if the statement is true, otherwise $0$.

Note

$-10^{9} \le x_{1} \lt x_{2} \le 10^{9}$
$-10^{9} \le y_{1} \lt y_{2} \le 10^{9}$
$-10^{9} \le x_{3} \lt x_{4} \le 10^{9}$
$-10^{9} \le y_{3} \lt y_{4} \le 10^{9}$

Examples

Input #1
0 0 4 3
2 1 6 5
Output #1
1
Input #2
0 0 2 2
3 0 5 2
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.