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

~/algor $ cat problems/nuqta-uchburchak-ichidami

Is the point in the triangle?

Medium 1000 ms 64 MB 40%
Share

The vertices of a triangle $A(x_{1}; y_{1})$, $B(x_{2}; y_{2})$, $C(x_{3}; y_{3})$ and a point $P(x; y)$ are given on the plane. Check whether the statement is true: “the point $P$ belongs to the triangle”, that is, it lies inside the triangle or on one of its sides.

Triangle ABC on the coordinate plane and a point P inside it

Input

The first line contains six integers: $x_{1}$, $y_{1}$, $x_{2}$, $y_{2}$, $x_{3}$ and $y_{3}$.
The second line contains two integers: $x$ and $y$.

Output

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

Note

$-1000 \le x_{1}, y_{1}, x_{2}, y_{2}, x_{3}, y_{3}, x, y \le 1000$
The points $A$, $B$ and $C$ do not lie on one straight line.

Examples

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

Sign in to submit a solution

Signing up is free and takes a minute.