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

~/algor $ cat problems/tortburchak-ichida-tortburchak

Rectangle inside a rectangle

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})$. Check whether the statement is true: “the second rectangle lies entirely inside the first”. The sides may coincide: the border of the first rectangle belongs to it too.

Two rectangles on the coordinate plane; the smaller one is inside the larger

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 6 4
1 1 4 3
Output #1
1
Input #2
0 0 6 4
4 1 7 3
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.