#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);

using namespace std;

typedef long long int llp;
typedef long double ld;
const llp INF=(1LL<<60)-1;
const int MAX = 1000000;

llp fast_exp(llp base,llp exp,llp m){
  llp res=1;
  while(exp>0){
    if(exp%2==1){
      res=(res*base)%m;
    }
    base=(base*base)%m;
    exp/=2;
  }
  return res%m;
}

typedef struct  node
{
   int a1,a2,b1,b2;
}node;

/*bool comp (struct node &A, struct node &b)
{
  return A.a < b.a;
}

*/
int main()
 {
    //#ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
 //   #endif
    IOS;
    int n;
    llp ans=0;
    cin >> n;
    node p[n+1];
    for(int i =1;i<=n;i++)
      {
        cin>> p[i].a1 >> p[i].a2 >> p[i].b1 >> p[i].b2;
        if(p[i].a1==p[i].b1)  {ans+=abs(p[i].a2-p[i].b2)+1; continue;}
        else if(p[i].a2==p[i].b2)  {ans+=abs(p[i].a1-p[i].b1)+1; continue;}
        llp a = abs(p[i].b2 - p[i].a2);
        llp b = abs(p[i].b1 - p[i].a1);
        llp m = __gcd(a,b);
        a/=m;
        b/=m;
        llp q1 = abs(p[i].a2-p[i].b2)/a;
        llp q2 = abs(p[i].a1-p[i].b1)/b;
        q1--;
        q2--;
        ans+=min(q1,q2)+2;
        //cout << ans << endl;
      }
    //  cout << ans << endl;
      for(int i=1;i<n;i++)
       {
         for(int j=i+1;j<=n;j++)
          {
            llp a = p[i].b2 - p[i].a2;
            llp b = p[i].a1 - p[i].b1;
            llp c1 = b*p[i].a2 + a*p[i].a1;
            llp c = p[j].b2 - p[j].a2;
            llp d = p[j].a1 - p[j].b1;
            llp c2 = d*p[j].a2 + c*p[j].a1;
            llp det = a*d-b*c;
            if(!det) continue;
            if((d*c1-b*c2)%det==0 && (a*c2-c*c1)%det==0)
             {
               llp x = (d*c1-b*c2)/det;
               llp y = (a*c2-c*c1)/det;
               if((x>=min(p[i].a1,p[i].b1)&&x<=max(p[i].a1,p[i].b1)) && (y>=min(p[i].a2,p[i].b2)&&y<=max(p[i].a2,p[i].b2)))
                {
                  if((x>=min(p[j].a1,p[j].b1)&&x<=max(p[j].a1,p[j].b1)) && (y>=min(p[j].a2,p[j].b2)&&y<=max(p[j].a2,p[j].b2)))
                   {
                       ans--;
                    // if(i==1)  cout << j << endl;
                     //if(j==4) cout << x << " " << y << endl;
                   }
                }
             }
          }
        //  if(i==1) cout << ans << endl;
       }
     cout << ans << endl;
    return 0;
 }


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second

using namespace std;

typedef long long int llp;
typedef long double ld;
const llp INF=(1LL<<60)-1;
const int MAX = 1000000;
typedef pair<llp,llp> P;
map<P,int> l;

llp fast_exp(llp base,llp exp,llp m){
  llp res=1;
  while(exp>0){
    if(exp%2==1){
      res=(res*base)%m;
    }
    base=(base*base)%m;
    exp/=2;
  }
  return res%m;
}

typedef struct  node
{
   int a1,a2,b1,b2;
}node;

/*bool comp (struct node &A, struct node &b)
{
  return A.a < b.a;
}
*/

int main()
 {
    //#ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
 //   #endif
    IOS;
    int n;
    llp ans=0;
    cin >> n;
    node p[n+1];
  //  bool vis[n+1][n+1] = {false};
    for(int i =1;i<=n;i++)
      {
        cin>> p[i].a1 >> p[i].a2 >> p[i].b1 >> p[i].b2;
        if(p[i].a1==p[i].b1)  {ans+=abs(p[i].a2-p[i].b2)+1; continue;}
        else if(p[i].a2==p[i].b2)  {ans+=abs(p[i].a1-p[i].b1)+1; continue;}
        llp a = abs(p[i].b2 - p[i].a2);
        llp b = abs(p[i].b1 - p[i].a1);
        llp m = __gcd(a,b);
        ans+=m+1;
        //cout << ans << endl;
      }
      //cout << ans << endl;
      for(int i=1;i<=n;i++)
       {
         for(int j=i+1;j<=n;j++)
          {
            llp a = p[i].b2 - p[i].a2;
            llp b = p[i].a1 - p[i].b1;
            llp c1 = b*p[i].a2 + a*p[i].a1;
            llp c = p[j].b2 - p[j].a2;
            llp d = p[j].a1 - p[j].b1;
            llp c2 = d*p[j].a2 + c*p[j].a1;
            llp det = a*d-b*c;
            if(!det) continue;
            if((d*c1-b*c2)%det==0 && (a*c2-c*c1)%det==0)
             {
               llp x = (d*c1-b*c2)/det;
               llp y = (a*c2-c*c1)/det;
               if((x>=min(p[i].a1,p[i].b1)&&x<=max(p[i].a1,p[i].b1)) && (x>=min(p[j].a1,p[j].b1)&&x<=max(p[j].a1,p[j].b1)))
                {
                  if((y>=min(p[i].a2,p[i].b2)&&y<=max(p[i].a2,p[i].b2)) && (y>=min(p[j].a2,p[j].b2)&&y<=max(p[j].a2,p[j].b2)))
                   {
                      if(!l[P(x,y)]) {l[P(x,y)] = i; ans--;}
                      else if(l[P(x,y)]==i) ans--;
                     //if(i==1)  cout << j << endl;
                     //if(j==4) cout << x << " " << y << endl;
                   }
                }
             }
          }
        //  l.clear();
        //  if(i==1) cout << ans << endl;
       }
       //llp cnt=0;
    cout << ans << endl;
    return 0;
 }


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second

using namespace std;

typedef long long int llp;
typedef long double ld;
const llp INF=(1LL<<60)-1;
const int MAX = 1000000;
typedef pair<llp,llp> P;
set < P > s;

llp fast_exp(llp base,llp exp,llp m){
  llp res=1;
  while(exp>0){
    if(exp%2==1){
      res=(res*base)%m;
    }
    base=(base*base)%m;
    exp/=2;
  }
  return res%m;
}

typedef struct  node
{
   int a1,a2,b1,b2;
}node;

/*bool comp (struct node &A, struct node &b)
{
  return A.a < b.a;
}
*/

int main()
 {
    //#ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
  //  freopen("output.txt","w",stdout);
 //   #endif
    IOS;
    int n;
    llp ans=0;
    cin >> n;
    node p[n+1];
  //  bool vis[n+1][n+1] = {false};
    for(int i =1;i<=n;i++)
      {
        cin>> p[i].a1 >> p[i].a2 >> p[i].b1 >> p[i].b2;
        if(p[i].a1==p[i].b1)  {ans+=abs(p[i].a2-p[i].b2)+1; continue;}
        else if(p[i].a2==p[i].b2)  {ans+=abs(p[i].a1-p[i].b1)+1; continue;}
        llp a = abs(p[i].b2 - p[i].a2);
        llp b = abs(p[i].b1 - p[i].a1);
        llp m = __gcd(a,b);
        ans+=m+1;
        //cout << ans << endl;
      }
      //cout << ans << endl;
      for(int i=1;i<n;i++)
       {
         for(int j=i+1;j<=n;j++)
          {
            llp a = p[i].b2 - p[i].a2;
            llp b = p[i].a1 - p[i].b1;
            llp c1 = b*p[i].a2 + a*p[i].a1;
            llp c = p[j].b2 - p[j].a2;
            llp d = p[j].a1 - p[j].b1;
            llp c2 = d*p[j].a2 + c*p[j].a1;
            llp det = a*d-b*c;
            if(!det) continue;
            if((d*c1-b*c2)%det==0 && (a*c2-c*c1)%det==0)
             {
               llp x = (d*c1-b*c2)/det;
               llp y = (a*c2-c*c1)/det;
               if((x>=min(p[i].a1,p[i].b1)&&x<=max(p[i].a1,p[i].b1)) && (x>=min(p[j].a1,p[j].b1)&&x<=max(p[j].a1,p[j].b1)))
                {
                  if((y>=min(p[i].a2,p[i].b2)&&y<=max(p[i].a2,p[i].b2)) && (y>=min(p[j].a2,p[j].b2)&&y<=max(p[j].a2,p[j].b2)))
                   {
                      s.insert(P(x,y));
                     //if(i==1)  cout << j << endl;
                     //if(j==4) cout << x << " " << y << endl;
                   }
                }
             }
          }
        //  l.clear();
        //  if(i==1) cout << ans << endl;
       }
       //llp cnt=0;
       for(auto it:s)
    {
        int cnt=0;
        for(int i=1;i<=n;i++)
        {
            int X1=it.F-p[i].a1,Y1=it.S-p[i].a2;
            int X2=p[i].b1-p[i].a1,Y2=p[i].b2-p[i].a2;
            if(X1*Y2!=Y1*X2) continue;
            if(it.F<min(p[i].a1,p[i].b1)||it.F>max(p[i].a1,p[i].b1)) continue;
            if(it.S<min(p[i].a2,p[i].b2)||it.S>max(p[i].a2,p[i].b2)) continue;
            cnt++;
        }
        ans-=cnt-1;
    }
  //  printf("%lld\n",ans);
    cout << ans << endl;
    return 0;
 }


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#include <algorithm>
#include <cmath>
#define PI 3.1415926535897932384626433832795l
#define PII -3.1415926535897932384626433832795l
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define deci(n) cout<<fixed<<setprecision(n);
#define F first
#define S second

using namespace std;

typedef long long int llp;
typedef long double ld;
const llp INF=(1LL<<60)-1;
const int MAX = 1000000;
typedef pair<llp,llp> P;
map<P,int> l;

typedef struct  node
{
   int a1,a2,b1,b2;
}node;

int main()
 {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    IOS;
    int n;
    llp ans=0;
    cin >> n;
    node p[n+1];
    for(int i =1;i<=n;i++)
      {
        cin>> p[i].a1 >> p[i].a2 >> p[i].b1 >> p[i].b2;
        llp a = abs(p[i].b2 - p[i].a2);
        llp b = abs(p[i].b1 - p[i].a1);
        ans+= __gcd(a,b)+1;
      }
      for(int i=1;i<=n;i++)
       {
         for(int j=i+1;j<=n;j++)
          {
            llp a = p[i].b2 - p[i].a2;
            llp b = p[i].a1 - p[i].b1;
            llp c1 = b*p[i].a2 + a*p[i].a1;
            llp c = p[j].b2 - p[j].a2;
            llp d = p[j].a1 - p[j].b1;
            llp c2 = d*p[j].a2 + c*p[j].a1;
            llp det = a*d-b*c;
            if(!det) continue;
            if((d*c1-b*c2)%det==0 && (a*c2-c*c1)%det==0)
             {
               llp x = (d*c1-b*c2)/det;
               llp y = (a*c2-c*c1)/det;
               if((x>=min(p[i].a1,p[i].b1)&&x<=max(p[i].a1,p[i].b1)) && (x>=min(p[j].a1,p[j].b1)&&x<=max(p[j].a1,p[j].b1)))
                {
                  if((y>=min(p[i].a2,p[i].b2)&&y<=max(p[i].a2,p[i].b2)) && (y>=min(p[j].a2,p[j].b2)&&y<=max(p[j].a2,p[j].b2)))
                   {
                      if(!l[P(x,y)]) {l[P(x,y)] = i; ans--;}
                      else if(l[P(x,y)]==i) ans--;
                   }
                }
             }
          }
       }
    cout << ans << endl;
    return 0;
 }


#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
template<typename T> using V = vector<T>;
#define fi first
#define se second
#define pb push_back
#define fo(i, n) for (int i = 0; i < (int)(n); ++i)
#define fr(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ro(i, a, b)     for (int i = (a); i <= (int)(b); ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x)   (int)x.size()
#define ii  pair< int, int >
#define i_ii pair< int, ii >
#define ret return 0;
const int INF = 1e9 + 5;
const int MOD = (int)1e9 + 7;
const int maxn = (int)1e3 + 5;
const int maxm = (int)1e9;
LL TEN(int x){LL ans = 1;while(x--)ans*=10;return ans;}
void add(int &a, int b){a+=b;if(a>=MOD)a-=MOD;}
int modE(int n, int x){int res=1;while(x){if(x&1)res=(1ll*res*n)%MOD;n=(1ll*n*n)%MOD;x>>=1;}return res;}
LL gcd(LL a, LL b, LL t = 0){return __gcd(a, b);while(a != 0 & b != 0)t = a, a = b, b = t % b; return a + b;}

LL n, x1, x2, _y1, y2;
struct Point{
    LL x, y;
    Point(){}
    Point(LL x, LL y) : x(x), y(y){}
    bool operator==(const Point other) const {
        return x == other.x && y == other.y;
    }
    Point operator+(const Point other) const {
        return Point(x + other.x, y + other.y);
    }
    Point operator-(const Point other) const {
        return Point(x - other.x, y - other.y);
    }
    Point operator*(const LL s) const {
        return Point(s * x, s * y);
    }
    bool operator<(const Point& other) const {
        return x < other.x || y < other.y;
    }
};
struct Segment{
    Point p1, p2;
    Segment(){}
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};
struct Line{
    long long A, B, C;
    Line(){};
    Line(Segment a){
        A = a.p1.y - a.p2.y;
        B = a.p2.x - a.p1.x;
        C = -A * a.p1.x - B * a.p1.y;
    };
};

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

LL dot(Point p, Point q) { return p.x*q.x + p.y*q.y; } // proportional to cos(x)
// double dist(Point p, Point q) { return sqrt(dot(p-q , p-q)); }
LL cross(Point p, Point q) { return p.x*q.y - p.y*q.x; } // proportional to sin(x) - p to q counterclockwise

Segment seg[maxn];

LL calcIntCoords(const Segment& s){
    return __gcd(abs(s.p1.x - s.p2.x), abs(s.p1.y - s.p2.y)) + 1;
    if(s.p1 == s.p2)return 1;
    LL d1 = abs(s.p1.x - s.p2.x);
    LL d2 = abs(s.p1.y - s.p2.y);
    LL g = gcd(d1, d2);
    // cout << d1 << ' ' << d2 << ' ' << g << endl;
    d1 /= g, d2 /= g;
    if(d1 == 0)return abs(s.p1.y - s.p2.y) / d2 + 1;
    return abs(s.p1.x - s.p2.x) / d1 + 1;
}
bool in(LL x, LL l, LL r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}
bool checkIntersect(Segment& s1, Segment& s2, LL& x, LL& y){
    Line l1(s1), l2(s2);
    long long dx = det(l1.C, l1.B, l2.C, l2.B);
    long long dy = det(l1.A, l1.C, l2.A, l2.C);
    long long d = det(l1.A, l1.B, l2.A, l2.B);
    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    x = -dx / d;
    y = -dy / d;
    if (!in(x, s1.p1.x, s1.p2.x) || !in(y, s1.p1.y, s1.p2.y))
        return false;
    if (!in(x, s2.p1.x, s2.p2.x) || !in(y, s2.p1.y, s2.p2.y))
        return false;
    return true;
}

int main() {
cin >> n;
for(LL i = 0; i < n; i++){
    cin >> x1 >> _y1 >> x2 >> y2;
    seg[i] = Segment(Point(x1, _y1), Point(x2, y2));
}
LL ans = 0;
fo(i, n)ans += calcIntCoords(seg[i]);
// cout << ans << endl;
LL x, y;
// exit(8);
fo(i, n - 1){
    set<Point> st;
    ro(j, i + 1, n - 1){
        if(checkIntersect(seg[i], seg[j], x, y))
            st.insert(Point({x, y}));
    }
    ans -= SZ(st);
}
cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
template<typename T> using V = vector<T>;
#define fi first
#define se second
#define pb push_back
#define fo(i, n) for (int i = 0; i < (int)(n); ++i)
#define fr(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ro(i, a, b)     for (int i = (a); i <= (int)(b); ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x)   (int)x.size()
#define ii  pair< int, int >
#define i_ii pair< int, ii >
#define ret return 0;
const int INF = 1e9 + 5;
const int MOD = (int)1e9 + 7;
const int maxn = (int)1e3 + 5;
const int maxm = (int)1e9;
LL TEN(int x){LL ans = 1;while(x--)ans*=10;return ans;}
void add(int &a, int b){a+=b;if(a>=MOD)a-=MOD;}
int modE(int n, int x){int res=1;while(x){if(x&1)res=(1ll*res*n)%MOD;n=(1ll*n*n)%MOD;x>>=1;}return res;}
LL gcd(LL a, LL b, LL t = 0){while(a != 0 & b != 0)t = a, a = b, b = t % b; return a + b;}

LL n, x1, x2, _y1, y2;
struct Point{
    LL x, y;
    Point(){}
    Point(LL x, LL y) : x(x), y(y){}
    bool operator==(const Point other) const {
        return x == other.x && y == other.y;
    }
    Point operator+(const Point other) const {
        return Point(x + other.x, y + other.y);
    }
    Point operator-(const Point other) const {
        return Point(x - other.x, y - other.y);
    }
    Point operator*(const LL s) const {
        return Point(s * x, s * y);
    }
};
struct Segment{
    Point p1, p2;
    Segment(){}
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};

LL dot(Point p, Point q) { return p.x*q.x + p.y*q.y; } // proportional to cos(x)
// double dist(Point p, Point q) { return sqrt(dot(p-q , p-q)); }
LL cross(Point p, Point q) { return p.x*q.y - p.y*q.x; } // proportional to sin(x) - p to q counterclockwise

Segment seg[maxn];

LL calcIntCoords(const Segment& s){
    if(s.p1 == s.p2)return 1;
   LL d1 = abs(s.p1.x - s.p2.x);
   LL d2 = abs(s.p1.y - s.p2.y);
   LL g = gcd(d1, d2);
    // cout << d1 << ' ' << d2 << ' ' << g << endl;
    d1 /= g, d2 /= g;
    if(d1 == 0)return abs(s.p1.y - s.p2.y) / d2 + 1;
    return abs(s.p1.x - s.p2.x) / d1 + 1;
}
bool checkIntersect(Segment& s1, Segment& s2){
    Point d1 = s1.p2 - s1.p1;
    Point d2 = s2.p2 - s2.p1;

   LL den = cross(d1, d2);
   LL num = cross(s2.p2 - s1.p1, d2);
    if(den == 0){
        if(num == 0) {
            return true;
        }else return false;
    }
    if(num * d1.x % den || num * d1.y % den)return false;
    Point r = s1.p1 + Point(num * d1.x / den, num * d1.y / den);
    if(r.x >= min(s1.p1.x, s1.p2.x) && r.x <= max(s1.p1.x, s1.p2.x)
        && r.y >= min(s1.p1.y, s1.p2.y) && r.y <= max(s1.p1.y, s1.p2.y)
        && r.x >= min(s2.p1.x, s2.p2.x) && r.x <= max(s2.p1.x, s2.p2.x)
        && r.y >= min(s2.p1.y, s2.p2.y) && r.y <= max(s2.p1.y, s2.p2.y))return true;

    return false;
}

int main() {
cin >> n;
for(LL i = 0; i < n; i++){
    cin >> x1 >> _y1 >> x2 >> y2;
    seg[i] = Segment(Point(x1, _y1), Point(x2, y2));
}
LL ans = 0;
fo(i, n)ans += calcIntCoords(seg[i]);
fo(i, n - 1)ro(j, i + 1, n - 1)ans -= checkIntersect(seg[i], seg[j]);// cout << i << ' ' << j << ' ' << checkIntersect(seg[i], seg[j]) << endl;
cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
template<typename T> using V = vector<T>;
#define fi first
#define se second
#define pb push_back
#define fo(i, n) for (int i = 0; i < (int)(n); ++i)
#define fr(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ro(i, a, b)     for (int i = (a); i <= (int)(b); ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x)   (int)x.size()
#define ii  pair< int, int >
#define i_ii pair< int, ii >
#define ret return 0;
const int INF = 1e9 + 5;
const int MOD = (int)1e9 + 7;
const int maxn = (int)1e3 + 5;
const int maxm = (int)1e9;
LL TEN(int x){LL ans = 1;while(x--)ans*=10;return ans;}
void add(int &a, int b){a+=b;if(a>=MOD)a-=MOD;}
int modE(int n, int x){int res=1;while(x){if(x&1)res=(1ll*res*n)%MOD;n=(1ll*n*n)%MOD;x>>=1;}return res;}
LL gcd(LL a, LL b, LL t = 0){return __gcd(a, b);while(a != 0 & b != 0)t = a, a = b, b = t % b; return a + b;}

LL n, x1, x2, _y1, y2;
struct Point{
    LL x, y;
    Point(){}
    Point(LL x, LL y) : x(x), y(y){}
    bool operator==(const Point other) const {
        return x == other.x && y == other.y;
    }
    Point operator+(const Point other) const {
        return Point(x + other.x, y + other.y);
    }
    Point operator-(const Point other) const {
        return Point(x - other.x, y - other.y);
    }
    Point operator*(const LL s) const {
        return Point(s * x, s * y);
    }
    bool operator<(const Point& other) const {
        if(x == other.x)return y < other.y;
        return x < other.x;
    }
};
struct Segment{
    Point p1, p2;
    Segment(){}
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};
struct Line{
    long long A, B, C;
    Line(){};
    Line(Segment a){
        A = a.p1.y - a.p2.y;
        B = a.p2.x - a.p1.x;
        C = -A * a.p1.x - B * a.p1.y;
    };
};

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

LL dot(Point p, Point q) { return p.x*q.x + p.y*q.y; } // proportional to cos(x)
// double dist(Point p, Point q) { return sqrt(dot(p-q , p-q)); }
LL cross(Point p, Point q) { return p.x*q.y - p.y*q.x; } // proportional to sin(x) - p to q counterclockwise

Segment seg[maxn];

LL calcIntCoords(const Segment& s){
    return __gcd(abs(s.p1.x - s.p2.x), abs(s.p1.y - s.p2.y)) + 1;
    if(s.p1 == s.p2)return 1;
    LL d1 = abs(s.p1.x - s.p2.x);
    LL d2 = abs(s.p1.y - s.p2.y);
    LL g = gcd(d1, d2);
    // cout << d1 << ' ' << d2 << ' ' << g << endl;
    d1 /= g, d2 /= g;
    if(d1 == 0)return abs(s.p1.y - s.p2.y) / d2 + 1;
    return abs(s.p1.x - s.p2.x) / d1 + 1;
}
bool in(LL x, LL l, LL r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}
bool checkIntersect(Segment& s1, Segment& s2, LL& x, LL& y){
    Line l1(s1), l2(s2);
    long long dx = det(l1.C, l1.B, l2.C, l2.B);
    long long dy = det(l1.A, l1.C, l2.A, l2.C);
    long long d = det(l1.A, l1.B, l2.A, l2.B);
    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    x = -dx / d;
    y = -dy / d;
    if (!in(x, s1.p1.x, s1.p2.x) || !in(y, s1.p1.y, s1.p2.y))
        return false;
    if (!in(x, s2.p1.x, s2.p2.x) || !in(y, s2.p1.y, s2.p2.y))
        return false;
    return true;
}

int main() {
cin >> n;
for(LL i = 0; i < n; i++){
    cin >> x1 >> _y1 >> x2 >> y2;
    seg[i] = Segment(Point(x1, _y1), Point(x2, y2));
}
LL ans = 0;
fo(i, n)ans += calcIntCoords(seg[i]);
// cout << ans << endl;
LL x, y;
// exit(8);
fo(i, n){
    set<Point> st;
    // set<pair<LL, LL> > st;
    fo(j, i){
        if(checkIntersect(seg[i], seg[j], x, y))
            st.insert({x, y});
    }
    ans -= SZ(st);
}
cout << ans;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
template<typename T> using V = vector<T>;
#define fi first
#define se second
#define pb push_back
#define fo(i, n) for (int i = 0; i < (int)(n); ++i)
#define fr(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ro(i, a, b)     for (int i = (a); i <= (int)(b); ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x)   (int)x.size()
#define ii  pair< int, int >
#define i_ii pair< int, ii >
#define ret return 0;
const int INF = 1e9 + 5;
const int MOD = (int)1e9 + 7;
const int maxn = (int)1e3 + 5;
const int maxm = (int)1e9;
LL TEN(int x){LL ans = 1;while(x--)ans*=10;return ans;}
void add(int &a, int b){a+=b;if(a>=MOD)a-=MOD;}
int modE(int n, int x){int res=1;while(x){if(x&1)res=(1ll*res*n)%MOD;n=(1ll*n*n)%MOD;x>>=1;}return res;}
LL gcd(LL a, LL b, LL t = 0){return __gcd(a, b);while(a != 0 & b != 0)t = a, a = b, b = t % b; return a + b;}

LL n, x1, x2, _y1, y2;
struct Point{
    LL x, y;
    Point(){}
    Point(LL x, LL y) : x(x), y(y){}
    bool operator==(const Point other) const {
        return x == other.x && y == other.y;
    }
    Point operator+(const Point other) const {
        return Point(x + other.x, y + other.y);
    }
    Point operator-(const Point other) const {
        return Point(x - other.x, y - other.y);
    }
    Point operator*(const LL s) const {
        return Point(s * x, s * y);
    }
    bool operator<(const Point& other) const {
        return x < other.x || y < other.y;
    }
};
struct Segment{
    Point p1, p2;
    Segment(){}
    Segment(Point p1, Point p2) : p1(p1), p2(p2){}
};
struct Line{
    long long A, B, C;
    Line(){};
    Line(Segment a){
        A = a.p1.y - a.p2.y;
        B = a.p2.x - a.p1.x;
        C = -A * a.p1.x - B * a.p1.y;
    };
};

long long det(long long a, long long b, long long c, long long d){
    return a * d - b * c;
}

LL dot(Point p, Point q) { return p.x*q.x + p.y*q.y; } // proportional to cos(x)
// double dist(Point p, Point q) { return sqrt(dot(p-q , p-q)); }
LL cross(Point p, Point q) { return p.x*q.y - p.y*q.x; } // proportional to sin(x) - p to q counterclockwise

Segment seg[maxn];

LL calcIntCoords(const Segment& s){
    if(s.p1 == s.p2)return 1;
   LL d1 = abs(s.p1.x - s.p2.x);
   LL d2 = abs(s.p1.y - s.p2.y);
   LL g = gcd(d1, d2);
    // cout << d1 << ' ' << d2 << ' ' << g << endl;
    d1 /= g, d2 /= g;
    if(d1 == 0)return abs(s.p1.y - s.p2.y) / d2 + 1;
    return abs(s.p1.x - s.p2.x) / d1 + 1;
}
bool in(LL x, LL l, LL r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}
bool checkIntersect(Segment& s1, Segment& s2, LL& x, LL& y){
    Line l1(s1), l2(s2);
    long long dx = det(l1.C, l1.B, l2.C, l2.B);
    long long dy = det(l1.A, l1.C, l2.A, l2.C);
    long long d = det(l1.A, l1.B, l2.A, l2.B);
    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    x = -dx / d;
    y = -dy / d;
    if (!in(x, s1.p1.x, s1.p2.x) || !in(y, s1.p1.y, s1.p2.y))
        return false;
    if (!in(x, s2.p1.x, s2.p2.x) || !in(y, s2.p1.y, s2.p2.y))
        return false;
    return true;
}

int main() {
cin >> n;
for(LL i = 0; i < n; i++){
    cin >> x1 >> _y1 >> x2 >> y2;
    seg[i] = Segment(Point(x1, _y1), Point(x2, y2));
}
LL ans = 0;
fo(i, n)ans += calcIntCoords(seg[i]);
// cout << ans << endl;
LL x, y;
// exit(8);
fo(i, n - 1){
    set<Point> st;
    ro(j, i + 1, n - 1){
        if(checkIntersect(seg[i], seg[j], x, y))
            st.insert(Point({x, y}));
    }
    ans -= SZ(st);
}
cout << ans;

}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a = 0, b = 0;
	Fract() {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		if (!b) return; /////////////////////////////////
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		// assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		// assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			// assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, int> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
				&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				++occ[{x, y}];
		}
	}
	for (auto &&x : occ) {
		// cerr << "XXXX X X X " << x.second << endl;
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second)
			++cnt;
		assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a = 0, b = 0;
	Fract() {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, int> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
				&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				++occ[{x, y}];
		}
	}
	for (auto &&x : occ) {
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second)
			++cnt;
		// assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a, b;
	Fract() : a(0), b(1) {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)

	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, int> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
					&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				++occ[{x, y}];
		}
	}
	for (auto &&x : occ) {
		// cerr << "XXXX X X X " << x.second << endl;
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second)
			++cnt;
		assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a, b;
	Fract() : a(0), b(1) {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		ll g = gcd(a, b);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isInt() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isInt());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)

	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, int> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isInt() || !yf.isInt()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
					&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				++occ[{x, y}];
		}
	}
	for (auto &&x : occ) {
		// cerr << "XXXX X X X " << x.second << endl;
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second)
			++cnt;
		assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a = 0, b = 0;
	Fract() {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, vector<pair<int, int>>> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
				&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				occ[{x, y}].emplace_back(i, j);
		}
	}
	for (auto &&x : occ) {
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second.size())
			++cnt;
		if (cnt * (cnt - 1) / 2 != x.second.size()) {
			cout << "SZ: " << x.second.size() << endl;
			for (auto &&y : x.second)
				cout << y.first << ' ' << y.second <<
				" (" << x1[y.first] << ", " << y1[y.first] << "), (" << x2[y.first] << ", " << y2[y.first] << ")\t\t" <<
				" (" << x1[y.second] << ", " << y1[y.second] << "), (" << x2[y.second] << ", " << y2[y.second] << ")\n";
		}
		// assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a = 0, b = 0;
	Fract() {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		if (!b) return; /////////////////////////////////
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		// assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		// assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			// assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, int> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
				&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				++occ[{x, y}];
		}
	}
	for (auto &&x : occ) {
		// cerr << "XXXX X X X " << x.second << endl;
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second)
			++cnt;
		// assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a = 0, b = 0;
	Fract() {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
		reduce();
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, vector<pair<int, int>>> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
				&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				occ[{x, y}].emplace_back(i, j);
		}
	}
	// assert(!occ.empty());

	for (auto &&x : occ) {
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second.size())
			++cnt;
		if (cnt * (cnt - 1) / 2 != x.second.size()) {
			cout << "SZ: " << x.second.size() << endl;
			for (auto &&y : x.second)
				cout << y.first << ' ' << y.second <<
				" (" << x1[y.first] << ", " << y1[y.first] << "), (" << x2[y.first] << ", " << y2[y.first] << ")\t\t" <<
				" (" << x1[y.second] << ", " << y1[y.second] << "), (" << x2[y.second] << ", " << y2[y.second] << ")\n";
		}
		// assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a = 0, b = 0;
	Fract() {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
		reduce();
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		const ll g = gcd(a, b);
		assert(g);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isLL() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isLL());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)
	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(llabs(x2[i] - x1[i]), llabs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, vector<pair<int, int>>> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isLL() || !yf.isLL()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
				&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				occ[{x, y}].emplace_back(i, j);
		}
	}
	assert(!occ.empty());

	for (auto &&x : occ) {
		int cnt = 2;
		while (cnt * (cnt - 1) / 2 < x.second.size())
			++cnt;
		if (cnt * (cnt - 1) / 2 != x.second.size()) {
			cout << "SZ: " << x.second.size() << endl;
			for (auto &&y : x.second)
				cout << y.first << ' ' << y.second <<
				" (" << x1[y.first] << ", " << y1[y.first] << "), (" << x2[y.first] << ", " << y2[y.first] << ")\t\t" <<
				" (" << x1[y.second] << ", " << y1[y.second] << "), (" << x2[y.second] << ", " << y2[y.second] << ")\n";
		}
		// assert(cnt * (cnt - 1) / 2 == x.second);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

struct Fract {
	ll a, b;
	Fract() : a(0), b(1) {};
	Fract(ll a, ll b) : a(a), b(b) {}
	Fract(Fract a, Fract b) {
		a.reduce();
		b.reduce();
		this->a = a.a * b.b;
		this->b = a.b * b.a;
	}

	bool valid() const { return b != 0; }

	Fract operator*(const ll x) const {
		return Fract(a*x, b);
	}

	Fract operator-() const {
		return Fract(-a, b);
	}

	Fract operator+(const ll x) const {
		return{ a + b*x, b };
	}

	Fract operator+(const Fract other) const {
		return{ a*other.b + other.a * b, b*other.b };
	}

	Fract operator-(const Fract other) const {
		return{ a*other.b - other.a * b, b*other.b };
	}

	Fract operator*(const Fract other) const {
		return Fract(a * other.a, b * other.b);
	}

	bool operator==(Fract other) {
		reduce(), other.reduce();
		return a == other.a && b == other.b;
	}

	void reduce() {
		assert(b);
		ll g = gcd(a, b);
		a /= g;
		b /= g;
		if (b < 0) {
			a = -a;
			b = -b;
		}
	}

	bool isInt() {
		reduce();
		return b == 1;
	}

	ll toLL() {
		assert(isInt());
		return a;
	}
};

struct Line {
	Fract a, b;
	ll fixX;

	Line(ll x1, ll y1, ll x2, ll y2) {
		if (x1 == x2) {
			a = b = Fract(0, 0);
			fixX = x1;
		}
		else {
			a = Fract(y2 - y1, x2 - x1);
			b = -a * x1 + y1;
		}
	}

	bool vertical() const {
		return !a.valid();
	}

	Fract at(Fract x) const {
		assert(!vertical());
		return a*x + b;
	}

	Fract intersect(const Line other) const {
		if (vertical()) {
			assert(!other.vertical());
			return Fract(fixX, 1);
		}
		if (other.vertical())
			return Fract(other.fixX, 1);

		return Fract(b - other.b, other.a - a);
		// a1 x + b1 = a2 x + b2
		// (a1 - a2) x = (b2 - b1)
		// x = (b2 - b1) / (a1 - a2)

	}
};

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	int n;
	cin >> n;

	vector<ll> x1(n), y1(n), x2(n), y2(n);
	ll res = 0;
	for (int i = 0; i < n; ++i) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		res += 1 + gcd(abs(x2[i] - x1[i]), abs(y2[i] - y1[i]));
	}

	map<pair<ll, ll>, int> occ;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			Line linei(x1[i], y1[i], x2[i], y2[i]);
			Line linej(x1[j], y1[j], x2[j], y2[j]);
			if ((linei.vertical() && linej.vertical())
				|| (!linei.vertical() && !linej.vertical() && linei.a == linej.a)) continue;
			Fract xf = linei.intersect(linej);
			Fract yf = (linei.vertical() ? linej : linei).at(xf);
			if (!xf.isInt() || !yf.isInt()) continue;
			const ll x = xf.toLL();
			const ll y = yf.toLL();

			bool ok = true;
			for (int k : {i, j})
				ok = ok && min(x1[k], x2[k]) <= x && x <= max(x1[k], x2[k])
					&& min(y1[k], y2[k]) <= y && y <= max(y1[k], y2[k]);
			if (ok)
				++occ[{x, y}];
		}
	}
	for (auto &&x : occ) {
		// cerr << "XXXX X X X " << x.second << endl;
		int cnt = 0;
		while (cnt * (cnt - 1) / 2 < x.second)
			++cnt;
		assert(cnt * (cnt - 1) / 2 == x.second && cnt > 1);
		res -= cnt - 1;
	}

	cout << res << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct line{
    int sx,sy,ex,ey,dx,dy;
    long long a,b,c;
    line(){};
    int calc(){
        a = sy-ey;
        b = ex-sx;
        c = a*ex+b*ey;
        dx = ex-sx;
        dy = ey-sy;
        int g = __gcd(dx,dy);
        dx/=g;
        dy/=g;
        if(dx==0)return abs(sy-ey)+1;
        else if(dy==0)return abs(sx-ex)+1;
        else{
            return max(abs(ex-sx),abs(ey-sy))/max(abs(dy),abs(dx))+1;
        }
    }
};
line a[1003];
long long ans = 0;
int c[1000006];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        c[(i+1)*(i+2)] = i+1;
        scanf("%d%d%d%d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
        ans+=a[i].calc();
    }
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            double det = a[i].a*a[j].b - a[j].a*a[i].b;
            if(det != 0){
                double x = (a[j].b*a[i].c - a[i].b*a[j].c)/det;
                double y = (a[i].a*a[j].c - a[j].a*a[i].c)/det;
                int x1 = x;
                int y1 = y;
                if(x<min(a[i].sx,a[i].ex)||x>max(a[i].sx,a[i].ex)||y<min(a[i].sy,a[i].ey)||y>max(a[i].sy,a[i].ey))continue;
                if(x<min(a[j].sx,a[j].ex)||x>max(a[j].sx,a[j].ex)||y<min(a[j].sy,a[j].ey)||y>max(a[j].sy,a[j].ey))continue;
                if(abs(x-x1)>1e-6||abs(y-y1)>1e-6)continue;
                m[{x1,y1}]++;
            }
        }
    }
    for(auto it: m){
        ans-=c[it.second];
    }
    printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct line{
    long long sx,sy,ex,ey,dx,dy;
    long long a,b,c;
    line(){};
    int calc(){
        a = sy-ey;
        b = ex-sx;
        c = a*ex+b*ey;
        dx = ex-sx;
        dy = ey-sy;
        int g = __gcd(dx,dy);
        dx/=g;
        dy/=g;
        if(dx==0)return abs(sy-ey)+1;
        else if(dy==0)return abs(sx-ex)+1;
        else{
            return max(abs(ex-sx),abs(ey-sy))/max(abs(dy),abs(dx))+1;
        }
    }
};
line a[1003];
long long ans = 0;
int c[1000006];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        c[(i+1)*(i+2)] = i+1;
        scanf("%lld%lld%lld%lld",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
        ans+=a[i].calc();
    }
    map<pair<long long,long long>,int> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            long long det = a[i].a*a[j].b - a[j].a*a[i].b;
            if(det != 0){
                if((a[j].b*a[i].c - a[i].b*a[j].c)%det||(a[i].a*a[j].c - a[j].a*a[i].c)%det)continue;
                long long x = (a[j].b*a[i].c - a[i].b*a[j].c)/det;
                long long y = (a[i].a*a[j].c - a[j].a*a[i].c)/det;
                if(x<min(a[i].sx,a[i].ex)||x>max(a[i].sx,a[i].ex)||y<min(a[i].sy,a[i].ey)||y>max(a[i].sy,a[i].ey))continue;
                if(x<min(a[j].sx,a[j].ex)||x>max(a[j].sx,a[j].ex)||y<min(a[j].sy,a[j].ey)||y>max(a[j].sy,a[j].ey))continue;
                m[{x,y}]++;
            }
        }
    }
    for(auto it: m){
        ans-=c[it.second];
    }
    printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct line{
    int sx,sy,ex,ey,dx,dy;
    long long a,b,c;
    line(){};
    int calc(){
        a = sy-ey;
        b = ex-sx;
        c = a*ex+b*ey;
        dx = ex-sx;
        dy = ey-sy;
        int g = __gcd(dx,dy);
        dx/=g;
        dy/=g;
        if(dx==0)return abs(sy-ey)+1;
        else if(dy==0)return abs(sx-ex)+1;
        else{
            return max(abs(ex-sx),abs(ey-sy))/max(abs(dy),abs(dx))+1;
        }
    }
};
line a[1003];
long long ans = 0;
int c[1000006];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        c[(i+1)*(i+2)] = i+1;
        scanf("%d%d%d%d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
        ans+=a[i].calc();
    }
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            double det = a[i].a*a[j].b - a[j].a*a[i].b;
            if(det != 0){
                double x = (a[j].b*a[i].c - a[i].b*a[j].c)/det;
                double y = (a[i].a*a[j].c - a[j].a*a[i].c)/det;
                int x1 = x;
                int y1 = y;
                if(x<min(a[i].sx,a[i].ex)||x>max(a[i].sx,a[i].ex)||y<min(a[i].sy,a[i].ey)||y>max(a[i].sy,a[i].ey))continue;
                if(x<min(a[j].sx,a[j].ex)||x>max(a[j].sx,a[j].ex)||y<min(a[j].sy,a[j].ey)||y>max(a[j].sy,a[j].ey))continue;
                if(x!=x1||y!=y1)continue;
                m[{x1,y1}]++;
            }
        }
    }
    for(auto it: m){
        ans-=c[it.second];
    }
    printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct line{
    int sx,sy,ex,ey,dx,dy;
    long long a,b,c;
    line(){};
    int calc(){
        a = sy-ey;
        b = ex-sx;
        c = a*ex+b*ey;
        dx = ex-sx;
        dy = ey-sy;
        int g = __gcd(dx,dy);
        dx/=g;
        dy/=g;
        if(dx==0)return abs(sy-ey)+1;
        else if(dy==0)return abs(sx-ex)+1;
        else{
            return max(abs(ex-sx),abs(ey-sy))/max(abs(dy),abs(dx))+1;
        }
    }
};
line a[1003];
long long ans = 0;
int c[1000006];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        c[(i+1)*(i+2)] = i+1;
        scanf("%d%d%d%d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
        ans+=a[i].calc();
    }
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            double det = a[i].a*a[j].b - a[j].a*a[i].b;
            if(det != 0){
                double x = (a[j].b*a[i].c - a[i].b*a[j].c)/det;
                double y = (a[i].a*a[j].c - a[j].a*a[i].c)/det;
                int x1 = x;
                int y1 = y;
                if(x<min(a[i].sx,a[i].ex)||x>max(a[i].sx,a[i].ex)||y<min(a[i].sy,a[i].ey)||y>max(a[i].sy,a[i].ey))continue;
                if(x<min(a[j].sx,a[j].ex)||x>max(a[j].sx,a[j].ex)||y<min(a[j].sy,a[j].ey)||y>max(a[j].sy,a[j].ey))continue;
                if(abs(x-x1)>1e-8||abs(y-y1)>1e-8)continue;
                m[{x1,y1}]++;
            }
        }
    }
    for(auto it: m){
        ans-=c[it.second];
    }
    printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct line{
    int sx,sy,ex,ey,dx,dy;
    long long a,b,c;
    line(){};
    int calc(){
        a = sy-ey;
        b = ex-sx;
        c = a*ex+b*ey;
        dx = ex-sx;
        dy = ey-sy;
        int g = __gcd(dx,dy);
        dx/=g;
        dy/=g;
        if(dx==0)return abs(sy-ey)+1;
        else if(dy==0)return abs(sx-ex)+1;
        else{
            return max(abs(ex-sx),abs(ey-sy))/max(abs(dy),abs(dx))+1;
        }
    }
};
line a[1003];
long long ans = 0;
int c[1000006];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        c[(i+1)*(i+2)] = i+1;
        scanf("%d%d%d%d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
        ans+=a[i].calc();
    }
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            long double det = a[i].a*a[j].b - a[j].a*a[i].b;
            if(det != 0){
                long double x = (a[j].b*a[i].c - a[i].b*a[j].c)/det;
                long double y = (a[i].a*a[j].c - a[j].a*a[i].c)/det;
                int x1 = x;
                int y1 = y;
                if(x<min(a[i].sx,a[i].ex)||x>max(a[i].sx,a[i].ex)||y<min(a[i].sy,a[i].ey)||y>max(a[i].sy,a[i].ey))continue;
                if(x<min(a[j].sx,a[j].ex)||x>max(a[j].sx,a[j].ex)||y<min(a[j].sy,a[j].ey)||y>max(a[j].sy,a[j].ey))continue;
                if(x!=x1||y!=y1)continue;
                m[{x1,y1}]++;
            }
        }
    }
    for(auto it: m){
        ans-=c[it.second];
    }
    printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;

struct line{
    int sx,sy,ex,ey,dx,dy;
    long long a,b,c;
    line(){};
    int calc(){
        a = sy-ey;
        b = ex-sx;
        c = a*ex+b*ey;
        dx = ex-sx;
        dy = ey-sy;
        int g = __gcd(dx,dy);
        dx/=g;
        dy/=g;
        if(dx==0)return abs(sy-ey)+1;
        else if(dy==0)return abs(sx-ex)+1;
        else{
            return max(abs(ex-sx),abs(ey-sy))/max(abs(dy),abs(dx))+1;
        }
    }
};
line a[1003];
long long ans = 0;
int c[1000006];

int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        c[(i+1)*(i+2)] = i+1;
        scanf("%d%d%d%d",&a[i].sx,&a[i].sy,&a[i].ex,&a[i].ey);
        ans+=a[i].calc();
    }
    map<pair<int,int>,int> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)continue;
            double det = a[i].a*a[j].b - a[j].a*a[i].b;
            if(det != 0){
                double x = (a[j].b*a[i].c - a[i].b*a[j].c)/det;
                double y = (a[i].a*a[j].c - a[j].a*a[i].c)/det;
                int x1 = x;
                int y1 = y;
                if(x<min(a[i].sx,a[i].ex)||x>max(a[i].sx,a[i].ex)||y<min(a[i].sy,a[i].ey)||y>max(a[i].sy,a[i].ey))continue;
                if(x<min(a[j].sx,a[j].ex)||x>max(a[j].sx,a[j].ex)||y<min(a[j].sy,a[j].ey)||y>max(a[j].sy,a[j].ey))continue;
                if(abs(x-x1)>1e-9||abs(y-y1)>1e-9)continue;
                m[{x1,y1}]++;
            }
        }
    }
    for(auto it: m){
        ans-=c[it.second];
    }
    printf("%lld",ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////

pair<double,double> lineLineIntersection(pii A, pii B, pii C, pii D)
{
    // Line AB represented as a1x + b1y = c1
    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);

    // Line CD represented as a2x + b2y = c2
    double a2 = D.second - C.second;
    double b2 = C.first - D.first;
    double c2 = a2*(C.first)+ b2*(C.second);

    double determinant = a1*b2 - a2*b1;

    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX
        return make_pair(10000000.0, 10000000.0);
    }
    else
    {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        return make_pair(x, y);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vector< pair<double,double> > a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    ll ans=0;
    //map<pii,ll> m;
    rep(i,n){
        ll g = __gcd((ll)abs(a[i].fi-b[i].fi),(ll)abs(a[i].se-b[i].se));
        ans+=g+1;
    }
    DBG(ans);
    map<pair<double,double>,ll> m;
    rep(i,n){
        repA(j,i+1,n-1){
            pair<double,double>  p =lineLineIntersection(a[i],b[i],a[j],b[j]);
            pair<double,double> p1 = {floor(p.fi),floor(p.se)};
            DBG(p);
            if(p.fi<min(a[i].fi,b[i].fi) || p.fi>max(a[i].fi,b[i].fi) || p.se<min(a[i].se,b[i].se) || p.se>max(a[i].se,b[i].se))continue;
            if(p.fi<min(a[j].fi,b[j].fi) || p.fi>max(a[j].fi,b[j].fi) || p.se<min(a[j].se,b[j].se) || p.se>max(a[j].se,b[j].se))continue;
            if((p==p1) && (p1!=make_pair(10000000.0,10000000.0)))m[p]++;
        }
    }
    DBG(m);
    for(auto i:m)ans-=(i.se);
    cout<<ans;

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
ld ff = 100000000000;
// ff *=10000000;
pair<ld,ld> lineLineIntersection(pii A, pii B, pii C, pii D)
{
    // Line AB represented as a1x + b1y = c1
    ll a1 = B.second - A.second;
    ll b1 = A.first - B.first;
    ll c1 = a1*(A.first) + b1*(A.second);

    // Line CD represented as a2x + b2y = c2
    ll a2 = D.second - C.second;
    ll b2 = C.first - D.first;
    ll c2 = a2*(C.first)+ b2*(C.second);

    ll determinant = a1*b2 - a2*b1;

    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX

        return make_pair(ff,ff);
    }
    else
    {
        ll x = (b2*c1 - b1*c2);
        ll y = (a1*c2 - a2*c1);
        DBG(x/determinant);
        DBG(y/determinant);
        // DBG(x/determinant);
        DBG(determinant);
        if(x%determinant || y%determinant)return make_pair(ff,ff);
        if(x > (1000000.0*abs(determinant)) || y > (1000000.0*abs(determinant)) || x < -1.0*(1000000.0*abs(determinant)) || y < -1.0*(1000000.0*abs(determinant)) ){
            return make_pair(ff,ff);
        }
        else
        return make_pair((x/determinant), (y/determinant));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vector< pair<ld,ld> > a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    ll ans=0;
    //map<pii,ll> m;
    rep(i,n){
        ll g = __gcd((ll)abs(a[i].fi-b[i].fi),(ll)abs(a[i].se-b[i].se));
        ans+=g+1;
    }
    DBG(ans);
    map<pair<ld,ld>,ll> m;
    rep(i,n){
        repA(j,i+1,n-1){
            pair<ld,ld>  p =lineLineIntersection(a[i],b[i],a[j],b[j]);
            pair<ld,ld> p1 = {floor(p.fi),floor(p.se)};
            DBG(p);
            if(p.fi<min(a[i].fi,b[i].fi) || p.fi>max(a[i].fi,b[i].fi) || p.se<min(a[i].se,b[i].se) || p.se>max(a[i].se,b[i].se))continue;
            if(p.fi<min(a[j].fi,b[j].fi) || p.fi>max(a[j].fi,b[j].fi) || p.se<min(a[j].se,b[j].se) || p.se>max(a[j].se,b[j].se))continue;
            if((p==p1) && (p1!=make_pair(ff,ff)))m[p]++;
        }
    }
    DBG(m);
    for(auto i:m)ans-=(i.se);
    cout<<ans;

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vpi a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    map<pii,ll> m;
    rep(i,n){
        ll g = __gcd(abs(a[i].fi-b[i].fi),abs(a[i].se-b[i].se));
        ll xs,ys;
        xs = (b[i].fi-a[i].fi)/g;
        ys = (b[i].se-a[i].se)/g;
        m[a[i]]++;
        pii cur = a[i];
        rep(i,g){
            cur.fi+=xs;
            cur.se+=ys;
            m[cur]++;
        }
    }
    cout<<sz(m);

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     long long int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vpi a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    map<pii,ll> m;
    rep(i,n){
        ll g = __gcd(abs(a[i].fi-b[i].fi),abs(a[i].se-b[i].se));
        ll xs,ys;
        xs = (b[i].fi-a[i].fi)/g;
        ys = (b[i].se-a[i].se)/g;
        m[a[i]]++;
        pii cur = a[i];
        rep(i,g){
            cur.fi+=xs;
            cur.se+=ys;
            m[cur]++;
        }
    }
    cout<<sz(m);

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
ld ff = 100000000000;
// ff *=10000000;
pair<ld,ld> lineLineIntersection(pii A, pii B, pii C, pii D)
{
    // Line AB represented as a1x + b1y = c1
    ll a1 = B.second - A.second;
    ll b1 = A.first - B.first;
    ll c1 = a1*(A.first) + b1*(A.second);

    // Line CD represented as a2x + b2y = c2
    ll a2 = D.second - C.second;
    ll b2 = C.first - D.first;
    ll c2 = a2*(C.first)+ b2*(C.second);

    ll determinant = a1*b2 - a2*b1;

    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX

        return make_pair(ff,ff);
    }
    else
    {
        ll x = (b2*c1 - b1*c2);
        ll y = (a1*c2 - a2*c1);
        DBG(x/determinant);
        DBG(y/determinant);
        // DBG(x/determinant);
        DBG(determinant);
        if(x%determinant || y%determinant)return make_pair(ff,ff);
        if(x > (1000000.0*abs(determinant)) || y > (1000000.0*abs(determinant)) || x < -1.0*(1000000.0*abs(determinant)) || y < -1.0*(1000000.0*abs(determinant)) ){
            return make_pair(ff,ff);
        }
        else
        return make_pair((x/determinant), (y/determinant));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vector< pair<ld,ld> > a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    ll ans=0;
    //map<pii,ll> m;
    rep(i,n){
        ll g = __gcd((ll)abs(a[i].fi-b[i].fi),(ll)abs(a[i].se-b[i].se));
        ans+=g+1;
    }
    DBG(ans);
    map<pair<ld,ld>,ll> m;
    rep(i,n){
        repA(j,i+1,n-1){
            pair<ld,ld>  p =lineLineIntersection(a[i],b[i],a[j],b[j]);
            pair<ld,ld> p1 = {floor(p.fi),floor(p.se)};
            DBG(p);
            if(p.fi<min(a[i].fi,b[i].fi) || p.fi>max(a[i].fi,b[i].fi) || p.se<min(a[i].se,b[i].se) || p.se>max(a[i].se,b[i].se))continue;
            if(p.fi<min(a[j].fi,b[j].fi) || p.fi>max(a[j].fi,b[j].fi) || p.se<min(a[j].se,b[j].se) || p.se>max(a[j].se,b[j].se))continue;
            if((p==p1) && (p1!=make_pair(ff,ff)))m[p]++;
        }
    }
    DBG(m);
    // for(auto i:m)ans-=(i.se);
    for(auto &it:m)
    {
        if(it.first.first<-1e6)
            continue;
        for(int k=1;;k++)
        {
            if(k*(k+1)/2 == it.second)
            {
                ans-=k;
                break;
            }
        }
    }
    cout<<ans;

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
ld ff = 100000000000;
// ff *=10000000;
pair<ld,ld> lineLineIntersection(pii A, pii B, pii C, pii D)
{
    // Line AB represented as a1x + b1y = c1
    ld a1 = B.second - A.second;
    ld b1 = A.first - B.first;
    ld c1 = a1*(A.first) + b1*(A.second);

    // Line CD represented as a2x + b2y = c2
    ld a2 = D.second - C.second;
    ld b2 = C.first - D.first;
    ld c2 = a2*(C.first)+ b2*(C.second);

    ld determinant = a1*b2 - a2*b1;

    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX

        return make_pair(ff,ff);
    }
    else
    {
        ld x = (b2*c1 - b1*c2);
        ld y = (a1*c2 - a2*c1);
        DBG(x/determinant);
        DBG(y/determinant);
        // DBG(x/determinant);
        DBG(determinant);
        if(x > (1000000.0*abs(determinant)) || y > (1000000.0*abs(determinant)) || x < -1.0*(1000000.0*abs(determinant)) || y < -1.0*(1000000.0*abs(determinant)) ){
            return make_pair(ff,ff);
        }
        else
        return make_pair((x/determinant), (y/determinant));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vector< pair<ld,ld> > a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    ll ans=0;
    //map<pii,ll> m;
    rep(i,n){
        ll g = __gcd((ll)abs(a[i].fi-b[i].fi),(ll)abs(a[i].se-b[i].se));
        ans+=g+1;
    }
    DBG(ans);
    map<pair<ld,ld>,ll> m;
    rep(i,n){
        repA(j,i+1,n-1){
            pair<ld,ld>  p =lineLineIntersection(a[i],b[i],a[j],b[j]);
            pair<ld,ld> p1 = {floor(p.fi),floor(p.se)};
            DBG(p);
            if(p.fi<min(a[i].fi,b[i].fi) || p.fi>max(a[i].fi,b[i].fi) || p.se<min(a[i].se,b[i].se) || p.se>max(a[i].se,b[i].se))continue;
            if(p.fi<min(a[j].fi,b[j].fi) || p.fi>max(a[j].fi,b[j].fi) || p.se<min(a[j].se,b[j].se) || p.se>max(a[j].se,b[j].se))continue;
            if((p==p1) && (p1!=make_pair(ff,ff)))m[p]++;
        }
    }
    DBG(m);
    for(auto i:m)ans-=(i.se);
    cout<<ans;

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     int                        ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////

pair<ld,ld> lineLineIntersection(pii A, pii B, pii C, pii D)
{
    // Line AB represented as a1x + b1y = c1
    ld a1 = B.second - A.second;
    ld b1 = A.first - B.first;
    ld c1 = a1*(A.first) + b1*(A.second);

    // Line CD represented as a2x + b2y = c2
    ld a2 = D.second - C.second;
    ld b2 = C.first - D.first;
    ld c2 = a2*(C.first)+ b2*(C.second);

    ld determinant = a1*b2 - a2*b1;

    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX
        return make_pair(10000000.0, 10000000.0);
    }
    else
    {
        ld x = (b2*c1 - b1*c2)/determinant;
        ld y = (a1*c2 - a2*c1)/determinant;
        return make_pair(x, y);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save old buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save old buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vector< pair<ld,ld> > a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    ll ans=0;
    //map<pii,ll> m;
    rep(i,n){
        ll g = __gcd((ll)abs(a[i].fi-b[i].fi),(ll)abs(a[i].se-b[i].se));
        ans+=g+1;
    }
    DBG(ans);
    map<pair<ld,ld>,ll> m;
    rep(i,n){
        repA(j,i+1,n-1){
            pair<ld,ld>  p =lineLineIntersection(a[i],b[i],a[j],b[j]);
            pair<ld,ld> p1 = {floor(p.fi),floor(p.se)};
            DBG(p);
            if(p.fi<min(a[i].fi,b[i].fi) || p.fi>max(a[i].fi,b[i].fi) || p.se<min(a[i].se,b[i].se) || p.se>max(a[i].se,b[i].se))continue;
            if(p.fi<min(a[j].fi,b[j].fi) || p.fi>max(a[j].fi,b[j].fi) || p.se<min(a[j].se,b[j].se) || p.se>max(a[j].se,b[j].se))continue;
            if((p==p1) && (p1!=make_pair(10000000.0,10000000.0)))m[p]++;
        }
    }
    DBG(m);
    for(auto i:m)ans-=(i.se);
    cout<<ans;

    debug("\nRuntime = " + to_string((ld)clock()/(ld)CLOCKS_PER_SEC));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#if DEBUG && !ONLINE_JUDGE
    #include "/home/chaman/Desktop/cpp/debug.h"
#else
    #define debug(args...)
    #define DBG(x...)
#endif
typedef     long long int                    ll;
typedef     long double                          ld;
typedef     vector<ll>                           vi;
typedef     pair<ll,ll>                          pii;
typedef     vector<pii>                          vpi;
typedef     vector<vi>                           vvi;
typedef     map<ll,ll>                           mii;
typedef     map<char,ll>                         mci;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pii>                  pqii;
typedef     priority_queue<ll,vi,greater<ll>>    pqmini;
typedef     priority_queue<pii,vpi,greater<pii>> pqminpi;

#define     fi              first
#define     se              second
#define     sz(a)           (ll)((a).size())
#define     rep(i,n)        for(ll i=0;i<n;i++)
#define     repA(i,a,n)     for(auto i=a;i<=n;i++)
#define     repD(i, a, n)   for(auto i = a; i >= (n); --i)
#define     trav(a, x)      for(auto& a : x)
#define     all(x)          x.begin(), x.end()
#define     fill(a)         memset(a, 0, sizeof (a))
#define     pb              push_back
#define     MOD             1000000007
#define     PI              3.14159265359
#define     EULER           2.7182818284

//////////////////////////////////////////////////////////////////////
ll ff = 100000000000;
// ff *=10000000;
pair<ll,ll> lineLineIntersection(pii A, pii B, pii C, pii D)
{
    // Line AB represented as a1x + b1y = c1
    ll a1 = B.second - A.second;
    ll b1 = A.first - B.first;
    ll c1 = a1*(A.first) + b1*(A.second);

    // Line CD represented as a2x + b2y = c2
    ll a2 = D.second - C.second;
    ll b2 = C.first - D.first;
    ll c2 = a2*(C.first)+ b2*(C.second);

    ll determinant = a1*b2 - a2*b1;

    if (determinant == 0)
    {
        // The lines are parallel. This is simplified
        // by returning a pair of FLT_MAX

        return make_pair(ff,ff);
    }
    else
    {
        ll x = (b2*c1 - b1*c2);
        ll y = (a1*c2 - a2*c1);
        if(x%determinant || y%determinant)return make_pair(ff,ff);
        x/=determinant;
        y/=determinant;
        if(x > (1000000) || y > (1000000) || x < -1000000 || y < -1000000){
            return make_pair(ff,ff);
        }
        else
        return make_pair((x), (y));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // ifstream in("input.txt");
    // streambuf *cinbuf = std::cin.rdbuf(); //save oll buf
    // cin.rdbuf(in.rdbuf()); //redirect std::cin to in.txt!
    // ofstream out("output.txt");
    // streambuf *coutbuf = std::cout.rdbuf(); //save oll buf
    // cout.rdbuf(out.rdbuf()); //redirect std::cout to out.txt!
    cout.precision(20);
    ll n;
    cin>>n;
    vector< pair<ll,ll> > a(n,{0,0}),b(n,{0,0});
    rep(i,n){
        cin>>a[i].fi>>a[i].se>>b[i].fi>>b[i].se;
    }
    ll ans=0;
    //map<pii,ll> m;
    rep(i,n){
        ll g = __gcd((ll)abs(a[i].fi-b[i].fi),(ll)abs(a[i].se-b[i].se));
        ans+=g+1;
    }
    DBG(ans);
    map<pair<ll,ll>,ll> m;
    rep(i,n){
        repA(j,i+1,n-1){
            pair<ll,ll>  p =lineLineIntersection(a[i],b[i],a[j],b[j]);
            pair<ll,ll> p1 = {floor(p.fi),floor(p.se)};
            DBG(p);
            if(p.fi<min(a[i].fi,b[i].fi) || p.fi>max(a[i].fi,b[i].fi) || p.se<min(a[i].se,b[i].se) || p.se>max(a[i].se,b[i].se))continue;
            if(p.fi<min(a[j].fi,b[j].fi) || p.fi>max(a[j].fi,b[j].fi) || p.se<min(a[j].se,b[j].se) || p.se>max(a[j].se,b[j].se))continue;
            if((p==p1) && (p1!=make_pair(ff,ff)))m[p]++;
        }
    }
    DBG(m);
    // for(auto i:m)ans-=(i.se);
    for(auto &it:m)
    {
        if(it.first.first<-1e6)
            continue;
        for(int k=1;;k++)
        {
            if(k*(k+1)/2 == it.second)
            {
                ans-=k;
                break;
            }
        }
    }
    cout<<ans;

    debug("\nRuntime = " + to_string((ll)clock()/(ll)CLOCKS_PER_SEC));
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
lint n,m,mod;

lint calc(lint a,lint b){
	if(a%2==0) return (a/2)%mod*(b%mod)%mod;
	return a%mod*((b/2)%mod)%mod;
}
lint floor(lint a,lint b){
	if(a>=0) return a/b;
	if(a%b==0) return a/b;
	return a/b-1;
}
lint solve(lint L,lint R,lint l,lint r,lint low,lint up,lint C,lint dif){
	if(l<=L && R<=r){
		lint begin=floor(low-C+dif-1,dif),end=floor(up-1-C,dif);
		begin=max(begin,0ll);

		end=min(end,R-L-1);
		++end;
		if(begin>=end) return 0;
		//[begin...end)
		int len=end-begin;
		lint ans=(len+C%mod*(len%mod)%mod+(calc(begin+end-1,len)*(dif%mod)%mod))%mod;
		return ans;
	}else if(r<=L || R<=l) return 0;

	lint md=(L+R+1)>>1;
	lint A=solve(L,md,l,r,low,up,C,dif*2);
	lint B=solve(md,R,l,r,low,up,C+dif,dif*2);
	return (A+B)%mod;
}

int main(){
	cin>>n>>m>>mod;

	REP(hoge,m){
		int l,r,u,v;
		scanf("%d%d%d%d",&l,&r,&u,&v);--l;

		--u;
		cout<<solve(0,n,l,r,u,v,0,1)<<endl;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#define REP(i,m) for(int i=0;i<m;++i)
#define REPN(i,m,in) for(int i=in;i<m;++i)
#define ALL(t) (t).begin(),(t).end()
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
using namespace std;
static const int INF =500000000;
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
typedef long long int lint;
typedef pair<int,int> pi;
lint n,m,mod;

lint calc(lint a,lint b){
	if(a%2==0) return (a/2)%mod*(b%mod)%mod;
	return a%mod*((b/2)%mod)%mod;
}
lint floor(lint a,lint b){
	if(a>=0) return a/b;
	if(a%b==0) return a/b;
	return a/b-1;
}
lint solve(lint L,lint R,lint l,lint r,lint low,lint up,lint C,lint dif){
	if(l<=L && R<=r){
		lint begin=floor(low-C+dif-1,dif),end=floor(up-1-C,dif);
		begin=max(begin,0ll);

		end=min(end,R-L-1);
		++end;
		if(begin>=end) return 0;
		//[begin...end)
		int len=end-begin;
		lint ans=(len+C%mod*(len%mod)%mod+(calc(begin+end-1,len)%mod*(dif%mod)%mod))%mod;
		return ans;
	}else if(r<=L || R<=l) return 0;

	lint md=(L+R+1)>>1;
	lint A=solve(L,md,l,r,low,up,C,dif*2);
	lint B=solve(md,R,l,r,low,up,C+dif,dif*2);
	return (A+B)%mod;
}

int main(){
	cin>>n>>m>>mod;

	REP(hoge,m){
		int l,r,u,v;
		scanf("%d%d%d%d",&l,&r,&u,&v);--l;

		--u;
		cout<<solve(0,n,l,r,u,v,0,1)<<endl;
	}

	return 0;
}