Language: C++

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<complex>
#include<assert.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
typedef long long ll;
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

typedef vector<P> G;

struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int main(){
  int yy;
  cin >> yy;
  REP(k,yy){
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    P f,t;
    f = P(a,b);
    t = P(c,d);
    L one = L(f,t);
    ll n;
    cin >> n;
    vector <L> l;
    vector <ll> o;
    vector <ll> r;
    REP(i,n){
      double s2,s1,t1,t2;
      ll o1,r1;
      cin >> s1 >> s2 >> t1 >> t2 >> o1 >> r1;
      f = P(s1,s2);
      t = P(t1,t2);
      L te = L(f,t);
      o.pb(o1);
      r.pb(r1);
      l.pb(te);
    }
    ll index = 0;
    P com = P(-1000,-1000);
    vector <P> crossp;
    REP(i,l.size()){
      P comp;
      if(intersectSS(one,l[i])){
	comp = crosspoint(one,l[i]);
	crossp.pb(comp);
      }
      
      
    }
    sort(crossp.begin(),crossp.end());
    
    ll fl = 1;
    
    REP(i,crossp.size())
      //cout << crossp[i].real() << "  " << crossp[i].imag() << endl; 
    ll cnt = 0,cnt2 = 0;
    REP(j,crossp.size()){
      REP(i,l.size()){
	if(intersectSP(l[i],crossp[j])){
	  index = i;
	}
      }
      
      if(o[index] == 1 && r[index] == fl){
	
      }
      else if(o[index] == 1 && r[index] != fl){
	cnt++;
	fl += 1;
	if(fl == 2)
	  fl = 0;
      }
      else if(o[index] == 0 && r[index] == fl){
	cnt++;
	if(fl == 2)
	  fl = 0;
      }
      else{
	
      }
    }
    index = 0;
    fl = 0;
    REP(j,crossp.size()){
      REP(i,l.size()){
	if(intersectSP(l[i],crossp[j])){
	  index = i;
	}
      }
      
      if(o[index] == 1 && r[index] == fl){
	
      }
      else if(o[index] == 1 && r[index] != fl){
	cnt2++;
	fl += 1;
	if(fl == 2)
	  fl = 0;
      }
      else if(o[index] == 0 && r[index] == fl){
	cnt2++;
	if(fl == 2)
	  fl = 0;
      }
      else{
	
      }
    }
    cout << min(cnt,cnt2) << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:126:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
  126 |         cnt++;
      |         ^~~
      |         int
a.cc:132:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
  132 |         cnt++;
      |         ^~~
      |         int
a.cc:153:9: error: 'cnt2' was not declared in this scope
  153 |         cnt2++;
      |         ^~~~
a.cc:159:9: error: 'cnt2' was not declared in this scope
  159 |         cnt2++;
      |         ^~~~
a.cc:167:17: error: 'cnt' was not declared in this scope; did you mean 'int'?
  167 |     cout << min(cnt,cnt2) << endl;
      |                 ^~~
      |                 int
a.cc:167:21: error: 'cnt2' was not declared in this scope
  167 |     cout << min(cnt,cnt2) << endl;
      |                     ^~~~