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: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ.Volume0
{
    class Program0012
    {
        static void Main(string[] args)
        {
            string line;

            Queue<string> inputs = new Queue<string>();

            while (string.IsNullOrEmpty((line = Console.ReadLine())))
            {
                inputs.Enqueue(line);
            }

            foreach (var input in inputs)
            {
                var param = input.Split(' ').Select(double.Parse).ToArray();

                Vector2[] points = new Vector2[3];
                Vector2 pointP;

                for (int i = 0; i < 3; i++)
                {
                    points[i] = new Vector2(param[i * 2], param[i * 2 + 1]);
                }
                pointP = new Vector2(param[6], param[7]);


                Console.WriteLine(IsInside(points, pointP) ? "YES" : "NO");
            }
        }

        static bool IsInside(Vector2[] points, Vector2 pointP)
        {
            //反時計回りに
            if (Vector2.Cross(points[1] - points[0], points[2] - points[1]) < 0)
            {
                for (int i = 0; i < 3; i++)
                {
                    points[i] = -points[i];
                }
            }

            return Vector2.Cross(points[1] - points[0], pointP - points[0]) > 0
                && Vector2.Cross(points[2] - points[1], pointP - points[1]) > 0
                && Vector2.Cross(points[0] - points[2], pointP - points[2]) > 0;
        }
    }

    struct Vector2
    {
        public double X, Y;

        public Vector2(double x, double y)
        {
            this.X = x;
            this.Y = y;
        }

        public static Vector2 Add(Vector2 v1, Vector2 v2)
        {
            return new Vector2(v1.X + v2.X, v1.Y + v2.Y);
        }


        public static Vector2 operator +(Vector2 v1, Vector2 v2)
        {
            return Add(v1, v2);
        }


        public static Vector2 Subtract(Vector2 v1, Vector2 v2)
        {
            return new Vector2(v1.X - v2.X, v1.Y - v2.Y);
        }

        public static Vector2 operator -(Vector2 v1, Vector2 v2)
        {
            return Subtract(v1, v2);
        }

        public static Vector2 Multiply(double x, Vector2 v)
        {
            return new Vector2(x * v.X, x * v.Y);
        }

        public static Vector2 operator *(double x, Vector2 v)
        {
            return Multiply(x, v);
        }

        public static Vector2 Divide(Vector2 v, double x)
        {
            return new Vector2(v.X / x, v.Y / x);
        }

        public static Vector2 operator /(Vector2 v, double x)
        {
            return Divide(v, x);
        }

        public static double Dot(Vector2 v1, Vector2 v2)
        {
            return v1.X * v2.X + v1.Y + v2.Y;
        }

        public static double Cross(Vector2 v1, Vector2 v2)
        {
            return v1.X * v2.Y - v1.Y * v2.X;
        }

        public static Vector2 Negate(Vector2 v)
        {
            return new Vector2(-v.X, -v.Y);
        }

        public static Vector2 operator-(Vector2 v)
        {
            return Negate(v);
        }

        public double Length()
        {
            return Math.Sqrt(X * X + Y * Y);
        }

    }

}