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 JavaScript (judge verdict: Accepted)

function heron(a,b,c){
   var s=(a+b+c)/2;
   var S=Math.sqrt(s*(s-a)*(s-b)*(s-c));
   return S;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var I=0;I<Arr.length;I++){
   var arr=Arr[I].split(" ").map(Number);
   var x1=arr[0];var y1=arr[1];
   var x2=arr[2];var y2=arr[3];
   var x3=arr[4];var y3=arr[5];
   var xp=arr[6];var yp=arr[7];
   var d12=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
   var d13=Math.sqrt(Math.pow(x1-x3,2)+Math.pow(y1-y3,2));
   var d23=Math.sqrt(Math.pow(x2-x3,2)+Math.pow(y2-y3,2));
   var dp1=Math.sqrt(Math.pow(xp-x1,2)+Math.pow(yp-y1,2));
   var dp2=Math.sqrt(Math.pow(xp-x2,2)+Math.pow(yp-y2,2));
   var dp3=Math.sqrt(Math.pow(xp-x3,2)+Math.pow(yp-y3,2));
   var S123=heron(d12,d13,d23);
   var s123=heron(d12,dp1,dp2)+heron(d13,dp1,dp3)+heron(d23,dp2,dp3);
   console.log((Math.abs(S123-s123)<0.0005)?"YES":"NO");
}