#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
double det(pair<double, double> a, pair<double, double> b) {
  return a.first * b.second - a.second * b.first;
}
pair<double, double> sub(pair<double, double> a, pair<double, double> b) {
  return {a.first - b.first, a.second - b.second};
}
bool intersect(pair<double, double> p1, pair<double, double> p2,
               pair<double, double> p3, pair<double, double> p4) {
  bool b1, b2;
  b1 = (det(sub(p1, p2), sub(p3, p1)) * det(sub(p1, p2), sub(p4, p1)) <= 0);
  b2 = (det(sub(p3, p4), sub(p1, p3)) * det(sub(p3, p4), sub(p2, p3)) <= 0);
  return (b1 && b2);
}
const double EPS = 1e-9;
bool integ(double a) { return (abs(a - round(a)) < EPS); }
pair<long long, long long> result;
bool cp(pair<double, double> p1, pair<double, double> p2,
        pair<double, double> p3, pair<double, double> p4) {
  double z = sub(p4, p3).second * sub(p4, p1).first -
             sub(p4, p3).first * sub(p4, p1).second;
  double d = sub(p4, p3).second * sub(p2, p1).first -
             sub(p4, p3).first * sub(p2, p1).second;
  if (d == 0) return false;
  double x1 = p1.first + z * sub(p2, p1).first / d;
  double y1 = p1.second + z * sub(p2, p1).second / d;
  if (integ(x1) && integ(y1)) {
    result = {round(x1), round(y1)};
    return true;
  } else {
    return false;
  }
}
int main() {
  long long i, j, k;
  long long N;
  cin >> N;
  vector<long long> AX(N), AY(N), BX(N), BY(N);
  vector<pair<double, double> > A(N), B(N);
  for (i = 0; i < N; i++) {
    cin >> AX[i] >> AY[i] >> BX[i] >> BY[i];
    A[i] = {AX[i], AY[i]};
    B[i] = {BX[i], BY[i]};
  }
  long long ans = 0;
  for (i = 0; i < N; i++) {
    long long xa = abs(AX[i] - BX[i]), ya = abs(AY[i] - BY[i]);
    if (min(xa, ya) == 0) {
      ans += max(xa, ya) + 1;
    } else {
      ans += gcd(xa, ya) + 1;
    }
  }
  map<pair<long long, long long>, long long> mp;
  for (i = 0; i < N; i++) {
    for (j = i + 1; j < N; j++) {
      if (intersect(A[i], B[i], A[j], B[j]) && cp(A[i], B[i], A[j], B[j])) {
        mp[result] += 1;
      }
    }
  }
  map<long long, long long> rev;
  for (i = 1; i <= 1000; i++) {
    rev[i * (i - 1) / 2] = i;
  }
  for (auto p : mp) {
    ans -= rev[p.second] - 1;
  }
  cout << ans << endl;
  return 0;
}
