/* http://projecteuler.net/
 *
 * Problem 102
 * Using triangles.txt, a 27K text file containing the co-ordinates of
 * one thousand "random" triangles, find the number of triangles for which
 * the interior contains the origin.
 *
 * Solution by Melkor (Filip Niksic, fniksic@gmail.com)
 *
 **/

#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

inline int sgn(int n) {
    return (n == 0 ? 0 : n/abs(n));
}

// expects x[0], x[1], x[2] and y[0], y[1], y[2]
inline int det(const int *x, const int *y) {
    return x[0]*(y[1]-y[2])+x[1]*(y[2]-y[0])+x[2]*(y[0]-y[1]);
}

int main() {
    // triangles.txt modified: commas supstituted by spaces
    ifstream in("triangles2.txt");
    int x[3], y[3], t[3], total = 0;

    // Basically, what we have here:
    //   (0,0) @ conv{(x[0],y[0]), (x[1],y[1]), (x[2],y[2])}
    // if and only if there exist t[0], t[1], t[2] such that
    //   t[i]>=0, for i@{1,2,3}             (1)
    // &&
    //   sum_i t[i] = 1                     (2)
    // &&
    //   sum_i t[i](x[i],y[i]) = (0,0)      (3)
    // 
    // The implicit assumption here is that (x[i],y[i]) are affinely
    // independent (and one expects triangles in the given file to
    // be real triangles).
    //
    // Well, with this assumption there are unique t[0], t[1], t[2]
    // such that (2) and (3) are satisfied. These can be easily
    // calculated by solving a simple 3x3 linear system.
    //
    // So, the condition (1) gives us the answer whether the origin
    // is, or is not in our convex hull.
    for (int i = 0; i < 1000; ++i) {
	in >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];

	// sgnD is the signum of the determinant of our system
	int sgnD = sgn(det(x, y));
	// Real t[i] are t[i]/det(x, y), but we don't care since we only
	// want to check their sigum.
	t[0] = x[1]*y[2] - x[2]*y[1];
	t[1] = x[2]*y[0] - x[0]*y[2];
	t[2] = x[0]*y[1] - x[1]*y[0];

	if (sgn(t[0])*sgnD >= 0 && sgn(t[1])*sgnD >= 0 && sgn(t[2])*sgnD >= 0)
	    ++total;
    }

    cout << total << endl;
    return 0;
}

