Problem:
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

A Point in a Triangle

There is a triangle formed by three points $(x_1, y_1)$, $(x_2, y_2)$, $(x_3, y_3)$ on a plain.

Write a program which prints "YES" if a point $P$ $(x_p, y_p)$ is in the triangle and "NO" if not.

Input

Input consists of several datasets. Each dataset consists of:

$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_p$ $y_p$

All the input are real numbers. Input ends with EOF. The number of datasets is less than or equal to 100.

Constraints

You can assume that:

$ -100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_p, y_p \leq 100$

1.0 $\leq$ Length of each side of a tringle

0.001 $\leq$ Distance between $P$ and each side of a triangle

Output

For each dataset, print "YES" or "NO" in a line.

Sample Input

0.0 0.0 2.0 0.0 2.0 2.0 1.5 0.5
0.0 0.0 1.0 4.0 5.0 3.0 -1.0 3.0

Output for the Sample Input

YES
NO

Solution in C# (judge verdict: Accepted)

using System;

public class Vector
{
    public double x { get; set; }
    public double y { get; set; }
}

public class hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var s = Array.ConvertAll(line.Trim().Split(' '), double.Parse);
            var a = new Vector { x = s[0], y = s[1] };
            var b = new Vector { x = s[2], y = s[3] };
            var c = new Vector { x = s[4], y = s[5] };
            var p = new Vector { x = s[6], y = s[7] };
            if (judgeTri(a, b, c, p) == 0) Console.WriteLine("YES");
            else Console.WriteLine("NO");
        }
    }
    public static int judgeTri(Vector a, Vector b,Vector c ,Vector p)
    {
        var ab = subVector(b, a);
        var bp = subVector(p, b);
        var bc = subVector(c, b);
        var cp = subVector(p, c);
        var ca = subVector(a, c);
        var ap = subVector(p, a);
        var c1 = ab.x * bp.y - ab.y * bp.x;
        var c2 = bc.x * cp.y - bc.y * cp.x;
        var c3 = ca.x * ap.y - ca.y * ap.x;
        if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0)) return 0; // inside
        else return 1;  // outside
    }
    public static Vector subVector (Vector a , Vector b)
    {
        var c = new Vector();
        c.x = a.x - b.x;
        c.y = a.y - b.y;
        return c;
    }
}