#include <bits/stdc++.h>
const int N = 310;
const double eps = 1e-12;
using namespace std;
int sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x > 0)
    return 1;
  else
    return -1;
}
int ans = 0;
struct Point {
  double x, y;
  Point() {}
  Point(double _x, double _y) { x = _x, y = _y; }
  bool operator<(Point b) const {
    return (sgn(x - b.x) == 0 ? sgn(y - b.y) < 0 : x < b.x);
  }
  Point operator-(const Point &b) const { return Point(x - b.x, y - b.y); }
  double operator^(const Point &b) const { return x * b.y - y * b.x; }
  double operator*(const Point &b) const { return x * b.x + y * b.y; }
};
map<Point, int> H;
struct Line {
  Point s, e;
  Line() {}
  Line(Point x, Point y) { s = x, e = y; }
  int check(double x, double y, double z) {
    double temp;
    if (sgn(s.x - e.x) == 0)
      temp = -(x * s.x + z) / y;
    else
      temp = -(y * s.y + z) / x;
    if (temp >= -1e6 && temp <= 1e6) return 1;
    return 0;
  }
  Point cal(double x, double y, double z) {
    if (sgn(s.x - e.x) == 0)
      return Point(e.x, -(x * s.x + z) / y);
    else
      return Point(-(y * s.y + z) / x, e.y);
  }
  Point crosspoint(Line v) {
    double a1 = (v.e - v.s) ^ (s - v.s);
    double a2 = (v.e - v.s) ^ (e - v.s);
    return Point((s.x * a2 - e.x * a1) / (a2 - a1),
                 (s.y * a2 - e.y * a1) / (a2 - a1));
  }
  int nei(Point x) {
    if (sgn((x - s) * (x - e)) <= 0) return 1;
    return 0;
  }
  void linetoline(Line t) {
    if (sgn((s - e) ^ (t.s - t.e)) == 0) return;
    Point temp = crosspoint(t);
    if (nei(temp) && t.nei(temp)) ans++;
  }
};
int main() {
  Point a, b;
  scanf("%lf%lf%lf%lf", &a.x, &a.y, &b.x, &b.y);
  Line l1 = Line(a, b);
  int n;
  scanf("%d", &n);
  Line t1 = Line(Point(-1e6, 1e6), Point(1e6, 1e6)),
       t2 = Line(Point(-1e6, -1e6), Point(-1e6, 1e6));
  Line t3 = Line(Point(1e6, -1e6), Point(1e6, 1e6)),
       t4 = Line(Point(1e6, -1e6), Point(-1e6, -1e6));
  H.clear();
  for (int i = 0; i < (n); i++) {
    double x, y, z;
    scanf("%lf%lf%lf", &x, &y, &z);
    Line l2;
    if (sgn(x) == 0) {
      z = -z / y;
      l2 = Line(Point(-1e6, z), Point(1e6, z));
    } else {
      if (sgn(y) == 0) {
        z = -z / x;
        l2 = Line(Point(z, -1e6), Point(z, 1e6));
      } else {
        vector<Point> v;
        v.clear();
        if (t1.check(x, y, z)) v.push_back(t1.cal(x, y, z));
        if (t2.check(x, y, z)) v.push_back(t2.cal(x, y, z));
        if (t3.check(x, y, z)) v.push_back(t3.cal(x, y, z));
        if (t4.check(x, y, z)) v.push_back(t4.cal(x, y, z));
        sort(v.begin(), v.end());
        int j;
        for (j = 1; j < v.size(); j++)
          if (v[j] < v[0] || v[0] < v[j]) break;
        l2 = Line(v[0], v[j]);
      }
    }
    l1.linetoline(l2);
  }
  printf("%d\n", ans);
  return 0;
}
