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;
using System.Linq;

namespace AOJ0012
{
    class Program
    {
        static void Main()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var values = line.Split(' ').Select(double.Parse).ToArray();
                var p1 = new Point(values[0], values[1]);
                var p2 = new Point(values[2], values[3]);
                var p3 = new Point(values[4], values[5]);
                var p = new Point(values[6], values[7]);

                Console.WriteLine(InTriangle(p1, p2, p3, p) ? "YES" : "NO");
            }
        }

        public static bool InTriangle(Point p1, Point p2, Point p3, Point p)
        {
            var v12 = new Vector(p1, p2);
            var v1P = new Vector(p1, p);
            var v23 = new Vector(p2, p3);
            var v2P = new Vector(p2, p);
            var v31 = new Vector(p3, p1);
            var v3P = new Vector(p3, p);
            var vc1 = v12.Cross(v1P);
            var vc2 = v23.Cross(v2P);
            var vc3 = v31.Cross(v3P);

            if ((vc1.Z > 0 && vc2.Z > 0 && vc3.Z > 0)
                || (vc1.Z < 0 && vc2.Z < 0 && vc3.Z < 0))
            {
                return true;
            }

            return false;
        }
    }

    public class Point
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public Point(double x = 0, double y = 0, double z = 0)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }

    public class Vector
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }

        public Vector(double x = 0, double y = 0, double z = 0)
        {
            X = x;
            Y = y;
            Z = z;
        }

        public Vector(Point p1, Point p2) : this(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z)
        {
        }

        public Vector Cross(Vector other)
        {
            var x = Y*other.Z - Z*other.Y;
            var y = Z*other.X - X*other.Z;
            var z = X*other.Y - Y*other.X;

            return new Vector(x, y, z);
        }
    }
}