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 JAVA (judge verdict: Wrong Answer)

import static java.lang.Double.parseDouble;
import static java.lang.Math.asin;
import static java.lang.Math.pow;
import static java.lang.Math.sqrt;
import static java.lang.Math.toDegrees;
import static java.lang.System.out;
import java.io.File;
import java.util.Scanner;

public class Main extends BaseExe {

    public static void main(String[] args) {
        new Main().exeSysIn();
    }

    @Override
    protected void execute(Scanner scan) {
        String inDataStr = "";
        while (scan.hasNextLine() && !"".equals(inDataStr = scan.nextLine())) {
            double[] cosList = getCosList(getSideList(getInData(inDataStr)));
            double[] degList = getDegList(getSinList(cosList), getIsMinusCosList(cosList));
            if (judgeInner(degList)) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        }
    }

    private boolean judgeInner(double[] degList) {
        return isNotOnline(degList) && isInner(degList);
    }

    private boolean isNotOnline(double[] degList) {
        return (0.0 != degList[0] && 180.0 != degList[0] && 0.0 != degList[1] && 180.0 != degList[1]
                && 0.0 != degList[2] && 180.0 != degList[2]);
    }

    private boolean isInner(double[] degList) {
        return (degList[0] + degList[1] + degList[2] == 360.0);
    }

    private double[] getInData(String inDataStr) {
        double[] inData = new double[8];
        String[] inDataStrList = inDataStr.split(" ");
        for (int index = 0; index < 8; index++) {
            inData[index] = parseDouble(inDataStrList[index]);
        }
        return inData;
    }

    private double[] getSideList(double[] inData) {
        double[] sideList = new double[6];
        sideList[0] = getSide(inData[0], inData[1], inData[2], inData[3]);
        sideList[1] = getSide(inData[0], inData[1], inData[4], inData[5]);
        sideList[2] = getSide(inData[2], inData[3], inData[4], inData[5]);
        sideList[3] = getSide(inData[6], inData[7], inData[0], inData[1]);
        sideList[4] = getSide(inData[6], inData[7], inData[2], inData[3]);
        sideList[5] = getSide(inData[6], inData[7], inData[4], inData[5]);
        return sideList;
    }

    private double getSide(double ax, double ay, double bx, double by) {
        return sqrt(pow(by - ay, 2) + pow(bx - ax, 2));
    }

    private double[] getCosList(double[] sideList) {
        double[] cosList = new double[3];
        cosList[0] = getCos(sideList[3], sideList[4], sideList[0]);
        cosList[1] = getCos(sideList[4], sideList[5], sideList[2]);
        cosList[2] = getCos(sideList[5], sideList[3], sideList[1]);
        return cosList;
    }

    private boolean[] getIsMinusCosList(double[] cosList) {
        boolean[] isMusCosList = new boolean[3];
        for (int index = 0; index < 3; index++) {
            isMusCosList[index] = (cosList[index] < 0.0) ? true : false;
        }
        return isMusCosList;
    }

    private double[] getSinList(double[] cosList) {
        double[] sinList = new double[3];
        for (int index = 0; index < 3; index++) {
            sinList[index] = sqrt(1 - pow(cosList[index], 2));
        }
        return sinList;
    }

    private double[] getDegList(double[] sinList, boolean[] isMinusList) {
        double[] degList = new double[3];
        for (int index = 0; index < 3; index++) {
            degList[index] = (isMinusList[index]) ? 180.0 - toDegrees(asin(sinList[index]))
                    : toDegrees(asin(sinList[index]));
        }
        return degList;
    }

    private double getCos(double ab, double ac, double bc) {
        return (pow2(ac) + pow2(ab) - pow2(bc)) / (2 * ac * ab);
    }

    private double pow2(double num) {
        return pow(num, 2);
    }
}

abstract class BaseExe {

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            execute(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            execute(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected abstract void execute(Scanner scan);
}