#include <bits/stdc++.h>   using namespace std;   const int N = 300010;   map<pair<pair<int, int>, int>, vector<int> > ans;   map<pair<pair<int, int>, int>, vector<pair<int, int> > > l;   map<pair<pair<int, int>, int>, vector<pair<int, int> > >::iterator it;   int n, m;   struct Point {     int x, y;     Point(int _x = 0, int _y = 0) : x(_x), y(_y){};     Point operator-(const Point &rhs) { return Point(x - rhs.x, y - rhs.y); }     Point operator*(int v) { return Point(v * x, v * y); }     Point operator+(const Point &rhs) { return Point(x + rhs.x, y + rhs.y); }     Point operator/(int v) { return Point(x / v, y / v); }     int len() { return x * x + y * y; }     friend int dis(Point a, Point b) { return Point(a - b).len(); }     void read() { scanf( %d%d , &x, &y); }   };   struct Circle {     int x, y, r;   } c[1510];   inline int Pow(int x) { return x * x; }   inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   pair<pair<int, int>, int> getLine(Point a, Point b) {     if (a.x == b.x) return make_pair(make_pair(0, 0), a.x);     if (a.y == b.y) return make_pair(make_pair(1, 0), a.y);     int dx = a.x - b.x;     int dy = a.y - b.y;     int d = gcd(abs(dx), abs(dy));     dx /= d;     dy /= d;     if (dx < 0) {       dx *= -1;       dy *= -1;     }     int v = (a.y % dy + dy) % dy;     v = a.x + (v - a.y) / dy * dx;     return make_pair(make_pair(dx, dy), v);   }   int getAns(pair<pair<int, int>, int> tmp, int x) {     if (l.find(tmp) == l.end()) return 0;     vector<pair<int, int> > &u = l[tmp];     int p = upper_bound(u.begin(), u.end(), make_pair(x, 1)) - u.begin();     return ans[tmp][p];   }   pair<pair<int, int>, int> getMirrorLine(Point a, Point b) {     Point mid = (a + b) / 2, off = a - b;     swap(off.x, off.y), off.x *= -1;     return getLine(mid + off, mid - off);   }   int main() {     scanf( %d%d , &n, &m);     Point a, b;     while (n--) {       a.read();       b.read();       a = a * 2;       b = b * 2;       if (a.x == b.x) {         l[getLine(a, b)].push_back(make_pair(min(a.y, b.y), 1));         l[getLine(a, b)].push_back(make_pair(max(a.y, b.y) + 1, -1));       } else {         l[getLine(a, b)].push_back(make_pair(min(a.x, b.x), 1));         l[getLine(a, b)].push_back(make_pair(max(a.x, b.x) + 1, -1));       }     }     for (it = l.begin(); it != l.end(); ++it) {       sort((*it).second.begin(), (*it).second.end());       vector<int> &tt = ans[(*it).first];       vector<pair<int, int> > &d = (*it).second;       int v = 0;       tt.push_back(v);       for (int i = 0; i <= d.size(); ++i) {         v += d[i].second;         tt.push_back(v);       }     }     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d , &c[i].x, &c[i].y, &c[i].r);       c[i].x *= 2;       c[i].y *= 2;       c[i].r *= 2;     }     int cnt = 0;     for (int i = 1; i < m; ++i)       for (int j = i + 1; j <= m; ++j) {         if (c[i].r == c[j].r &&             dis(Point(c[i].x, c[i].y), Point(c[j].x, c[j].y)) >                 Pow(c[i].r + c[j].r)) {           int mid;           if (c[i].y == c[j].y)             mid = c[i].y;           else             mid = (c[i].x + c[j].x) >> 1;           cnt += getAns(               getMirrorLine(Point(c[i].x, c[i].y), Point(c[j].x, c[j].y)), mid);         }       }     printf( %d n , cnt);     return 0;   }