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.Collections.Generic;

namespace _0012
{
    class Program
    {
        static void Main(string[] args)
        {
            var dataSet = ReadData();
            var answers = SolveProblems(dataSet);
            WriteData(answers);
        }

        /// <summary>
        /// 問題群を解く
        /// </summary>
        /// <param name="dataSet">問題毎のデータセット</param>
        /// <returns>問題毎の回答（YES or NO）</returns>
        static List<string> SolveProblems(List<TriangleAndPoint> dataSet) 
        {
            var answers = new List<string>();
            foreach(var data in dataSet)
            {

                if ((data.trianglePoint1.x - data.trianglePoint3.x) * (data.trianglePoint1.y - data.trianglePoint2.y) == (data.trianglePoint1.x - data.trianglePoint2.x) * (data.trianglePoint1.y - data.trianglePoint3.y))
                {
                    answers.Add("NO");
                }
                else
                {
                    Vector2D AB = sub_vector(data.trianglePoint2, data.trianglePoint1);
                    Vector2D BP = sub_vector(data.point, data.trianglePoint2);

                    Vector2D BC = sub_vector(data.trianglePoint3, data.trianglePoint2);
                    Vector2D CP = sub_vector(data.point, data.trianglePoint3);

                    Vector2D CA = sub_vector(data.trianglePoint1, data.trianglePoint3);
                    Vector2D AP = sub_vector(data.point, data.trianglePoint1);

                    //外積計算
                    double c1 = AB.x * BP.y - AB.y * BP.x;
                    double c2 = BC.x * CP.y - BC.y * CP.x;
                    double c3 = CA.x * AP.y - CA.y * AP.x;

                    if ((c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0))
                    {
                        answers.Add("YES");
                    }
                    else
                    {
                        answers.Add("NO");
                    }
                }

            }
            return answers;
        }

        static List<TriangleAndPoint> ReadData()
        {
            var inputs = new List<TriangleAndPoint>();

            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input))
                {
                    break;
                }

                var data = input.Split(' ');
                var dataSet = new TriangleAndPoint();
                dataSet.trianglePoint1.x = double.Parse(data[0]);
                dataSet.trianglePoint1.y = double.Parse(data[1]);
                dataSet.trianglePoint2.x = double.Parse(data[2]);
                dataSet.trianglePoint2.y = double.Parse(data[3]);
                dataSet.trianglePoint3.x = double.Parse(data[4]);
                dataSet.trianglePoint3.y = double.Parse(data[5]);
                dataSet.point.x = double.Parse(data[6]);
                dataSet.point.y = double.Parse(data[7]);
                inputs.Add(dataSet);
            }
            return inputs;
        }

        static void WriteData(List<string> outputs)
        {
            foreach (var output in outputs)
            {
                Console.WriteLine(output);
            }
        }

        struct TriangleAndPoint
        {
            public Vector2D trianglePoint1; // 第1座標
            public Vector2D trianglePoint2; // 第2座標
            public Vector2D trianglePoint3; // 第3座標
            public Vector2D point; // 点P座標
        }

        struct Vector2D
        {
            public double x;
            public double y;
        }

        static Vector2D sub_vector(Vector2D a, Vector2D b)
        {
            Vector2D ret;
            ret.x = a.x - b.x;
            ret.y = a.y - b.y;
            return ret;
        }
    }
}