#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
};

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.ay - seg.by;
        b = seg.bx - seg.ax;
        c = -a * seg.ax - b * seg.ay;
    }
};

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

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

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, seg1.ax, seg1.bx) || !in(y, seg1.ay, seg1.by))
        return false;
    if (!in(x, seg2.ax, seg2.bx) || !in(y, seg2.ay, seg2.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < segments.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, segments[i], segments[j])) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
};

struct Line {
    long long a, b, c;

    Line(const Segment& seg) {
        a = seg.ay - seg.by;
        b = seg.bx - seg.ax;
        c = -a * seg.ax - b * seg.ay;
    }
};

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

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

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, seg1.ax, seg1.bx) || !in(y, seg1.ay, seg1.by))
        return false;
    if (!in(x, seg2.ax, seg2.bx) || !in(y, seg2.ay, seg2.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < segments.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, segments[i], segments[j])) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
};

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
};

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

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

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, seg1.ax, seg1.bx) || !in(y, seg1.ay, seg1.by))
        return false;
    if (!in(x, seg2.ax, seg2.bx) || !in(y, seg2.ay, seg2.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < segments.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, segments[i], segments[j])) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
#include <bits/stdc++.h>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
};

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
};

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

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

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.c, lin1.b, lin2.c, lin2.b);
    long long dy = det(lin1.a, lin1.c, lin2.a, lin2.c);
    long long d  = det(lin1.a, lin1.b, lin2.a, lin2.b);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, seg1.ax, seg1.bx) || !in(y, seg1.ay, seg1.by))
        return false;
    if (!in(x, seg2.ax, seg2.bx) || !in(y, seg2.ay, seg2.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < segments.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, segments[i], segments[j]))) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>

using ULL = unsigned long long;
using namespace std;

struct Segment {
    int ax, ay, bx, by;
}

struct Line {
    int a, b, c;

    Line(const Segment& seg) {
        a = seg.by - seg.ay;
        b = seg.ax - seg.bx;
        c = -a * seg.ax - b * seg.ay;
    }
}

std::vector< Segment > segments;

int computeTotalIncludingDuplicates() {
    int total = 0;

    for (const auto& seg : segments) {
        int dx = seg.bx - seg.ax;
        int dy = seg.by - seg.ay;
        total += __gcd(abs(dx), abs(dy)) + 1;
    }

    return total;
}

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

bool in(int x, int l, int r){
    if (l > r) swap(l, r);
    return (l <= x && x <= r);
}

bool intersects(pair<int, int>& point, const Segment& seg1, const Segment& seg2) {
    Line lin1(seg1);
    Line lin2(seg2);

    long long dx = det(lin1.C, lin1.B, lin2.C, lin2.B);
    long long dy = det(lin1.A, lin1.C, lin2.A, lin2.C);
    long long d  = det(lin1.A, lin1.B, lin2.A, lin2.B);

    if (d == 0)
        return false;
    if (dx % d != 0 || dy % d != 0)
        return false;
    int x = -dx / d;
    int y = -dy / d;
    if (!in(x, a.ax, a.bx) || !in(y, a.ay, a.by))
        return false;
    if (!in(x, b.ax, b.bx) || !in(y, b.ay, b.by))
        return false;

    point.first = x;
    point.second = y;
    return true;
}

int computeDuplicatesCount() {
    int total = 0;
    std::pair<int, int> point;

    for (int i = 1; i < seg.size(); ++i) {
        std::set<pair<int, int>> intersections;

        for (int j = 0; j < i; ++j) {
            if (intersects(point, seg[i], seg[j]))) {
                intersections.insert(point);
            }
        }

        total += intersections.size();
    }

    return total;
}

int solve() {
    int ans = computeTotalIncludingDuplicates();
    ans -= computeDuplicatesCount();

    return ans;
}

int main() {
    std::ios_base::sync_with_stdio(false);

    int n;
    std::cin >> n;

    segments.resize(n);

    for (int i = 0; i < n; ++i) {
        std::cin >> segments[i].ax >> segments[i].ay >> segments[i].bx >> segments[i].by;
    }

    cout << solve() << '\n';

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ax[1111],ay[1111],bx[1111],by[1111],p[1111],q[1111],r[1111];

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}
	if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

vector<P> v;
set<P> st;

bool comp(P a, P b){
	return ((a.first == b.first)?(a.second < b.second):(a.first < b.first));
}

bool eq(P a, P b){
	return ((a.first == b.first) && (a.second == b.second));
}

int main(void){
	int n,i,j;
	ll ans,s,x,y;
	scanf("%d",&n);
	for(i=0; i<n; ++i){
		scanf("%lld%lld%lld%lld",&ax[i],&ay[i],&bx[i],&by[i]);
		p[i] = ay[i]-by[i];
		q[i] = bx[i]-ax[i];
		r[i] =  (bx[i]-ax[i])*ay[i] - (by[i]-ay[i])*ax[i];
		if(!q[i]){
			ans += abs(p[i])+1;
		}else if(!p[i]){
			ans += abs(q[i])+1;
		}else{
			ans += gcd(abs(p[i]),abs(q[i]))+1;
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			s = p[i]*q[j]-p[j]*q[i];
			y = p[i]*r[j]-p[j]*r[i];
			x = q[j]*r[i]-q[i]*r[j];
			if(!s){
				continue;
			}
			if(x%s || y%s){
				continue;
			}
			x /= s;
			y /= s;
			// printf("%d %d: (%lld %lld);\n",i,j,x,y);
			if(!(min(ax[i],bx[i]) <= x && x <= max(ax[i],bx[i]) && min(ay[i],by[i]) <= y && y <= max(ay[i],by[i]))){
				continue;
			}
			if(!(min(ax[j],bx[j]) <= x && x <= max(ax[j],bx[j]) && min(ay[j],by[j]) <= y && y <= max(ay[j],by[j]))){
				continue;
			}
			v.push_back(P(x,y));
			st.insert(P(x,y));
		}
	}
	ans -= v.l_ength();
	ans += st.l_ength();
	printf("%lld\n",ans);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ax[1111],ay[1111],bx[1111],by[1111],p[1111],q[1111],r[1111];

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}
	if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

set<P> st,u[1111];

int main(void){
	int n,i,j;
	ll ans=0ll,s,x,y;
	scanf("%d",&n);
	for(i=0; i<n; ++i){
		scanf("%lld%lld%lld%lld",&ax[i],&ay[i],&bx[i],&by[i]);
		p[i] = ay[i]-by[i];
		q[i] = bx[i]-ax[i];
		r[i] =  (bx[i]-ax[i])*ay[i] - (by[i]-ay[i])*ax[i];
		if(!q[i]){
			ans += abs(p[i])+1;
		}else if(!p[i]){
			ans += abs(q[i])+1;
		}else{
			ans += gcd(abs(p[i]),abs(q[i]))+1;
		}
	}
	cout << ans << endl;
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			s = p[i]*q[j]-p[j]*q[i];
			y = p[i]*r[j]-p[j]*r[i];
			x = q[j]*r[i]-q[i]*r[j];
			if(!s){
				continue;
			}
			if(x%s || y%s){
				continue;
			}
			x /= s;
			y /= s;
			// printf("%d %d: (%lld %lld);\n",i,j,x,y);
			if(!(min(ax[i],bx[i]) <= x && x <= max(ax[i],bx[i]) && min(ay[i],by[i]) <= y && y <= max(ay[i],by[i]))){
				continue;
			}
			if(!(min(ax[j],bx[j]) <= x && x <= max(ax[j],bx[j]) && min(ay[j],by[j]) <= y && y <= max(ay[j],by[j]))){
				continue;
			}
			u[i].insert(P(x,y));
			st.insert(P(x,y));
		}
		ans -= u[i].l_ength();
	}
	ans += st.l_ength();
	printf("%lld\n",ans);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ax[1111],ay[1111],bx[1111],by[1111],p[1111],q[1111],r[1111];

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}
	if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

vector<P> v;

bool comp(P a, P b){
	return ((a.first == b.first)?(a.second < b.second):(a.first < b.first));
}

bool eq(P a, P b){
	return ((a.first == b.first) && (a.second == b.second));
}

int main(void){
	int n,i,j,l;
	ll ans,s,x,y;
	scanf("%d",&n);
	for(i=0; i<n; ++i){
		scanf("%lld%lld%lld%lld",&ax[i],&ay[i],&bx[i],&by[i]);
		p[i] = ay[i]-by[i];
		q[i] = bx[i]-ax[i];
		r[i] =  (bx[i]-ax[i])*ay[i] - (by[i]-ay[i])*ax[i];
		if(!q[i]){
			ans += abs(p[i])+1;
		}else if(!p[i]){
			ans += abs(q[i])+1;
		}else{
			ans += gcd(abs(p[i]),abs(q[i]))+1;
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			s = p[i]*q[j]-p[j]*q[i];
			y = p[i]*r[j]-p[j]*r[i];
			x = q[j]*r[i]-q[i]*r[j];
			if(!s){
				continue;
			}
			if(x%s || y%s){
				continue;
			}
			x /= s;
			y /= s;
			// printf("%d %d: (%lld %lld);\n",i,j,x,y);
			if(!(min(ax[i],bx[i]) <= x && x <= max(ax[i],bx[i]) && min(ay[i],by[i]) <= y && y <= max(ay[i],by[i]))){
				continue;
			}
			if(!(min(ax[j],bx[j]) <= x && x <= max(ax[j],bx[j]) && min(ay[j],by[j]) <= y && y <= max(ay[j],by[j]))){
				continue;
			}
			v.push_back(P(x,y));
			// printf("%d %d\n",i,j);
		}
	}
	sort(v.begin(),v.end(),comp);
	l = v.l_ength();
	ans -= l;
	v.push_back(P(INF,INF));
	for(i=0; i<l; ++i){
		if(!eq(v[i],v[i+1])){
			++ans;
		}
	}
	printf("%lld\n",ans);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ax[1111],ay[1111],bx[1111],by[1111],p[1111],q[1111],r[1111];

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}
	if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

vector<P> v;
set<P> st;

bool comp(P a, P b){
	return ((a.first == b.first)?(a.second < b.second):(a.first < b.first));
}

bool eq(P a, P b){
	return ((a.first == b.first) && (a.second == b.second));
}

int main(void){
	int n,i,j,l;
	ll ans,s,x,y;
	scanf("%d",&n);
	for(i=0; i<n; ++i){
		scanf("%lld%lld%lld%lld",&ax[i],&ay[i],&bx[i],&by[i]);
		p[i] = ay[i]-by[i];
		q[i] = bx[i]-ax[i];
		r[i] =  (bx[i]-ax[i])*ay[i] - (by[i]-ay[i])*ax[i];
		if(!q[i]){
			ans += abs(p[i])+1;
		}else if(!p[i]){
			ans += abs(q[i])+1;
		}else{
			ans += gcd(abs(p[i]),abs(q[i]))+1;
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			s = p[i]*q[j]-p[j]*q[i];
			y = p[i]*r[j]-p[j]*r[i];
			x = q[j]*r[i]-q[i]*r[j];
			if(!s){
				continue;
			}
			if(x%s || y%s){
				continue;
			}
			x /= s;
			y /= s;
			// printf("%d %d: (%lld %lld);\n",i,j,x,y);
			if(!(min(ax[i],bx[i]) <= x && x <= max(ax[i],bx[i]) && min(ay[i],by[i]) <= y && y <= max(ay[i],by[i]))){
				continue;
			}
			if(!(min(ax[j],bx[j]) <= x && x <= max(ax[j],bx[j]) && min(ay[j],by[j]) <= y && y <= max(ay[j],by[j]))){
				continue;
			}
			v.push_back(P(x,y));
		}
	}
	sort(v.begin(),v.end(),comp);
	l = v.l_ength();
	ans -= l;
	for(i=0; i<l; ++i){
		st.insert(v[i]);
	}
	ans += st.l_ength();
	printf("%lld\n",ans);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ax[1111],ay[1111],bx[1111],by[1111],p[1111],q[1111],r[1111];

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}
	if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

vector<P> v;
set<P> st;

bool comp(P a, P b){
	return ((a.first == b.first)?(a.second < b.second):(a.first < b.first));
}

bool eq(P a, P b){
	return ((a.first == b.first) && (a.second == b.second));
}

int main(void){
	int n,i,j;
	ll ans=0ll,s,x,y;
	scanf("%d",&n);
	for(i=0; i<n; ++i){
		scanf("%lld%lld%lld%lld",&ax[i],&ay[i],&bx[i],&by[i]);
		p[i] = ay[i]-by[i];
		q[i] = bx[i]-ax[i];
		r[i] =  (bx[i]-ax[i])*ay[i] - (by[i]-ay[i])*ax[i];
		if(!q[i]){
			ans += abs(p[i])+1;
		}else if(!p[i]){
			ans += abs(q[i])+1;
		}else{
			ans += gcd(abs(p[i]),abs(q[i]))+1;
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			s = p[i]*q[j]-p[j]*q[i];
			y = p[i]*r[j]-p[j]*r[i];
			x = q[j]*r[i]-q[i]*r[j];
			if(!s){
				continue;
			}
			if(x%s || y%s){
				continue;
			}
			x /= s;
			y /= s;
			// printf("%d %d: (%lld %lld);\n",i,j,x,y);
			if(!(min(ax[i],bx[i]) <= x && x <= max(ax[i],bx[i]) && min(ay[i],by[i]) <= y && y <= max(ay[i],by[i]))){
				continue;
			}
			if(!(min(ax[j],bx[j]) <= x && x <= max(ax[j],bx[j]) && min(ay[j],by[j]) <= y && y <= max(ay[j],by[j]))){
				continue;
			}
			v.push_back(P(x,y));
			st.insert(P(x,y));
		}
	}
	ans -= v.l_ength();
	ans += st.l_ength();
	printf("%lld\n",ans);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, ll> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

ll ax[1111],ay[1111],bx[1111],by[1111],p[1111],q[1111],r[1111];

ll gcd(ll x, ll y){
	if(x < y){
		return gcd(y,x);
	}
	if(x%y){
		return gcd(y,x%y);
	}else{
		return y;
	}
}

set<P> st,u[1111];

int main(void){
	int n,i,j;
	ll ans=0ll,s,x,y;
	scanf("%d",&n);
	for(i=0; i<n; ++i){
		scanf("%lld%lld%lld%lld",&ax[i],&ay[i],&bx[i],&by[i]);
		p[i] = ay[i]-by[i];
		q[i] = bx[i]-ax[i];
		r[i] =  (bx[i]-ax[i])*ay[i] - (by[i]-ay[i])*ax[i];
		if(!q[i]){
			ans += abs(p[i])+1;
		}else if(!p[i]){
			ans += abs(q[i])+1;
		}else{
			ans += gcd(abs(p[i]),abs(q[i]))+1;
		}
	}
	for(i=0; i<n; ++i){
		for(j=0; j<n; ++j){
			if(i==j){
				continue;
			}
			s = p[i]*q[j]-p[j]*q[i];
			y = p[i]*r[j]-p[j]*r[i];
			x = q[j]*r[i]-q[i]*r[j];
			if(!s){
				continue;
			}
			if(x%s || y%s){
				continue;
			}
			x /= s;
			y /= s;
			// printf("%d %d: (%lld %lld);\n",i,j,x,y);
			if(!(min(ax[i],bx[i]) <= x && x <= max(ax[i],bx[i]) && min(ay[i],by[i]) <= y && y <= max(ay[i],by[i]))){
				continue;
			}
			if(!(min(ax[j],bx[j]) <= x && x <= max(ax[j],bx[j]) && min(ay[j],by[j]) <= y && y <= max(ay[j],by[j]))){
				continue;
			}
			u[i].insert(P(x,y));
			st.insert(P(x,y));
		}
		ans -= u[i].l_ength();
	}
	ans += st.l_ength();
	printf("%lld\n",ans);
	return 0;
}


/*input
9
0 0 4 4
-1 5 4 0
4 0 4 4
5 2 11 2
6 1 6 7
5 6 11 6
10 1 10 7
7 0 9 8
10 -1 11 -1

4
-1 2 1 2
-1 0 1 0
-1 0 0 3
0 3 1 0

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

struct data {
	pair<int, int> sta, end;
	data(pair<int, int> _sta, pair<int, int> _end): sta(_sta), end(_end) {
		if (sta.fi > end.fi) swap(sta, end);
	};
};

int n;
vector<data> line;

// const int INF = -1e9;
int ans = 0;

#define Point pair<int,int>
#define X fi
#define Y se
int ccw(Point p, Point q, Point r) {
	int val = (q.Y - p.Y) * (r.X - q.X) -
	          (q.X - p.X) * (r.Y - q.Y);

	if (val == 0) return 0;

	return (val > 0) ? 1 : 2;
}

int gcd(int a , int b) {
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ax, ay, bx, by;
		cin >> ax >> ay >> bx >> by;
		line.push_back(data(mp(ax, ay), mp(bx, by)));
		if (ax == bx)
			ans += abs(by - ay) + 1;
		else if (ay == by)
			ans += abs(bx - ax) + 1;
		else
			ans += abs(gcd(ax - bx, by - ay)) + 1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			auto p1 = line[i].sta; auto q1 = line[i].end;
			auto p2 = line[j].sta; auto q2 = line[j].end;
			if (ccw(p1, p2, q1) == ccw(p1, q2, q1) || ccw(p2, p1, q2) == ccw(p2, q1, q2)) continue;
			int up =  -1 * ((p1.X - q1.X) * (p2.X * q2.Y - q2.X * p2.Y) - (q2.X - p2.X) * (q1.X * p1.Y - p1.X * q1.Y));
			int down = ((p2.Y - q2.Y) * (p1.X - q1.X) - (q2.X - p2.X) * (q1.Y - p1.Y));
			if (up % down != 0) continue;
			ans--;
		}
	}
	cout << ans << endl;
}


/*input
10
78 31 22 16
58 8 58 44
24 59 49 40
97 77 39 24
8 2 33 83
96 11 66 59
20 38 47 76
8 5 47 97
19 71 82 36
91 29 95 95

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

struct data {
	pair<int, int> sta, end;
	data(pair<int, int> _sta, pair<int, int> _end): sta(_sta), end(_end) {
		if (sta.fi > end.fi) swap(sta, end);
	};
};

int n;
vector<data> line;

// const int INF = -1e9;
int ans = 0;

#define Point pair<int,int>
#define X fi
#define Y se
int ccw(Point p, Point q, Point r) {
	int val = (q.Y - p.Y) * (r.X - q.X) -
	          (q.X - p.X) * (r.Y - q.Y);

	if (val == 0) return 0;

	return (val > 0) ? 1 : 2;
}

int gcd(int a , int b) {
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ax, ay, bx, by;
		cin >> ax >> ay >> bx >> by;
		line.push_back(data(mp(ax, ay), mp(bx, by)));
		if (ax == bx)
			ans += abs(by - ay) + 1;
		else if (ay == by)
			ans += abs(bx - ax) + 1;
		else
			ans += abs(gcd(ax - bx, by - ay)) + 1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			auto p1 = line[i].sta; auto q1 = line[i].end;
			auto p2 = line[j].sta; auto q2 = line[j].end;
			if (ccw(p1, p2, q1) == ccw(p1, q2, q1) || ccw(p2, p1, q2) == ccw(p2, q1, q2)) continue;
			int up =  -1 * ((p1.X - q1.X) * (p2.X * q2.Y - q2.X * p2.Y) - (q2.X - p2.X) * (q1.X * p1.Y - p1.X * q1.Y));
			int down = ((p2.Y - q2.Y) * (p1.X - q1.X) - (q2.X - p2.X) * (q1.Y - p1.Y));
			if (up % down != 0) continue;
			up = -1 * (p2.X * q2.Y * p1.Y - p2.X * q2.Y * q1.Y - q2.X * p2.Y * p1.Y + q2.X * p2.Y * q1.Y - p2.Y * p1.X * q1.Y + p2.Y * q1.X * p1.Y + q2.Y * p1.X * q1.Y - q2.Y * q1.X * p1.Y);
			down = (-1 * p2.X * p1.Y + p2.X * q1.Y + q2.X * p1.Y - q2.X * q1.Y + p2.Y * p1.X - p2.Y * q1.X - q2.Y * p1.X + q2.Y * q1.X);
			if (up % down != 0) continue;
			ans--;
		}
	}
	cout << ans << endl;
}


/*input
10
78 31 22 16
58 8 58 44
24 59 49 40
97 77 39 24
8 2 33 83
96 11 66 59
20 38 47 76
8 5 47 97
19 71 82 36
91 29 95 95

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

struct data {
	pair<int, int> sta, end;
	data(pair<int, int> _sta, pair<int, int> _end): sta(_sta), end(_end) {
		if (sta.fi > end.fi) swap(sta, end);
	};
};

int n;
vector<data> line;

// const int INF = -1e9;
int ans = 0;

#define Point pair<int,int>
#define X fi
#define Y se
int ccw(Point p, Point q, Point r) {
	int val = (q.Y - p.Y) * (r.X - q.X) -
	          (q.X - p.X) * (r.Y - q.Y);

	if (val == 0) return 0;

	return (val > 0) ? 1 : 2;
}

int gcd(int a , int b) {
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ax, ay, bx, by;
		cin >> ax >> ay >> bx >> by;
		line.push_back(data(mp(ax, ay), mp(bx, by)));
		if (ax == bx)
			ans += abs(by - ay) + 1;
		else if (ay == by)
			ans += abs(bx - ax) + 1;
		else
			ans += abs(gcd(ax - bx, by - ay)) + 1;
	}
	for (int i = 0; i < n; i++) {
		set<pair<int, int> > st;
		for (int j = i + 1; j < n; j++) {
			auto p1 = line[i].sta; auto q1 = line[i].end;
			auto p2 = line[j].sta; auto q2 = line[j].end;
			if (ccw(p1, p2, q1) == ccw(p1, q2, q1) || ccw(p2, p1, q2) == ccw(p2, q1, q2)) continue;
			int up =  -1 * ((p1.X - q1.X) * (p2.X * q2.Y - q2.X * p2.Y) - (q2.X - p2.X) * (q1.X * p1.Y - p1.X * q1.Y));
			int down = ((p2.Y - q2.Y) * (p1.X - q1.X) - (q2.X - p2.X) * (q1.Y - p1.Y));
			if (up % down != 0) continue;
			int X = up / down;
			up = -1 * (p2.X * q2.Y * p1.Y - p2.X * q2.Y * q1.Y - q2.X * p2.Y * p1.Y + q2.X * p2.Y * q1.Y - p2.Y * p1.X * q1.Y + p2.Y * q1.X * p1.Y + q2.Y * p1.X * q1.Y - q2.Y * q1.X * p1.Y);
			down = (-1 * p2.X * p1.Y + p2.X * q1.Y + q2.X * p1.Y - q2.X * q1.Y + p2.Y * p1.X - p2.Y * q1.X - q2.Y * p1.X + q2.Y * q1.X);
			if (up % down != 0) continue;
			int Y = up / down;
			st.insert(mp(X, Y));
		}
		ans -= st.size(); st.clear();
	}
	cout << ans << endl;
}


/*input
9
0 0 4 4
-1 5 4 0
4 0 4 4
5 2 11 2
6 1 6 7
5 6 11 6
10 1 10 7
7 0 9 8
10 -1 11 -1

4
-1 2 1 2
-1 0 1 0
-1 0 0 3
0 3 1 0

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

#define BOTH 0
#define ONLYX 1
#define ONLYY 2
struct data {
	int a, b, y; int type; pair<int, int> sta, end;
	data(int _a, int _b, int _y, int _type, pair<int, int> _sta, pair<int, int> _end): a(_a), b(_b), y(_y), type(_type), sta(_sta), end(_end) {
		if (sta.fi > end.fi) swap(sta, end);
	};
};

int gcd(int a , int b) {
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int n;
vector<data> line;
vector<data> specX, specY;

// const int INF = -1e9;
int ans = 0;

#define Point pair<int,int>
#define X fi
#define Y se
int ccw(Point p, Point q, Point r)
{
    // See https://www.geeksforgeeks.org/orientation-3-ordered-points/
    // for details of below formula.
    int val = (q.Y - p.Y) * (r.X - q.X) -
              (q.X - p.X) * (r.Y - q.Y);

    if (val == 0) return 0;  // colinear

    return (val > 0)? 1: 2; // clock or counterclock wise
}

void divGcd(int &x, int &y) {
	if (y < 0) x = -x, y = -y;
	int rec = gcd(x, y);
	x /= rec; y /= rec;
}

void turnToLine(int ax, int ay, int bx, int by) {
	if (ax == bx) {
		specX.push_back(data(0, ax, 0, ONLYX, mp(ax, ay), mp(bx, by)));
		ans += abs(ay - by) + 1;
	}
	else if (ay == by) {
		specY.push_back(data(0, ay, 0, ONLYY, mp(ax, ay), mp(bx, by)));
		ans += abs(ax - bx) + 1;
	}
	else {
		int up = by - ay; int down = bx - ax;
		ans += abs(gcd(up, down)) + 1;
		divGcd(up, down);
		int trueB = ay * down - up * ax;
		line.push_back(data(up, trueB * down, down, BOTH, mp(ax, ay), mp(bx, by)));
	}
}

int bet(int X, int Y, int Z) {
	if (X <= Y && Y <= Z) return true;
	if (Z <= Y && Y <= X) return true;
	return false;
}

void removeDupSpec() {
	for (int i = 0; i < specX.size(); i++) {
		for (int j = 0; j < specY.size(); j++) {
			auto lineX = specX[i];
			auto lineY = specY[j];
			auto p1 = lineX.sta; auto q1 = lineX.end;
			auto p2 = lineY.sta; auto q2 = lineY.end;
			if (ccw(p1, p2, q1) == ccw(p1, q2, q1) || ccw(p2, p1, q2) == ccw(p2, q1, q2)) continue;
			ans--;
		}
	}
}

vector<pair<int, int> > inter;
void cut(data line1, data line2) {
	auto p1 = line1.sta; auto q1 = line1.end;
	auto p2 = line2.sta; auto q2 = line2.end;
	if (ccw(p1, p2, q1) == ccw(p1, q2, q1) || ccw(p2, p1, q2) == ccw(p2, q1, q2)) return;
	if (line1.type > line2.type) swap(line1, line2);
	if (line1.type == BOTH && line2.type == BOTH) {
		int up = line2.b - line1.b; int down = line1.a - line2.a;
		divGcd(up, down);
		if (down != 1) return;
		assert((up * line1.a + line1.b) % line1.y == 0);
		int trueY = (up * line1.a + line1.b) / line1.y;
		inter.push_back(mp(up, trueY));
	}
	if (line1.type == BOTH && line2.type == ONLYX) {
		int preY = line1.a * line2.b + line1.b;
		if (preY % line1.y == 0) {
			int trueY = preY / line1.y;
			inter.push_back(mp(line2.b, trueY));
		}
	}
	if (line1.type == BOTH && line2.type == ONLYY) {
		int preX = line1.y * line2.b - line1.b;
		if (preX % line1.a == 0) {
			int trueX = preX / line1.a;
			inter.push_back(mp(trueX, line2.b));
		}
	}
	return;
}

vector<data> done;
void calNorm() {
	for (auto lineCur : line) {
		inter.clear();
		for (auto lineM : done) {
			cut(lineCur, lineM);
		}
		for (auto lineX : specX) {
			cut(lineCur, lineX);
		}
		for (auto lineY : specY) {
			cut(lineCur, lineY);
		}
		sort(inter.begin(), inter.end()); inter.resize(distance(inter.begin(), unique(inter.begin(), inter.end())));
		ans -= inter.size();
		done.push_back(lineCur);
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ax, ay, bx, by;
		cin >> ax >> ay >> bx >> by;
		turnToLine(ax, ay, bx, by);
	}
	removeDupSpec();
	calNorm();
	cout << ans << endl;
}


/*input
9
0 0 4 4
-1 5 4 0
4 0 4 4
5 2 11 2
6 1 6 7
5 6 11 6
10 1 10 7
7 0 9 8
10 -1 11 -1

4
-1 2 1 2
-1 0 1 0
-1 0 0 3
0 3 1 0

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

#define BOTH 0
#define ONLYX 1
#define ONLYY 2
struct data {
	int a, b, y; int type; pair<int, int> sta, end;
	data(int _a, int _b, int _y, int _type, pair<int, int> _sta, pair<int, int> _end): a(_a), b(_b), y(_y), type(_type), sta(_sta), end(_end) {
		if (sta.fi > end.fi) swap(sta, end);
	};
};

int gcd(int a , int b) {
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int n;
vector<data> line;
vector<data> specX, specY;

// const int INF = -1e9;
int ans = 0;

void divGcd(int &x, int &y) {
	if (y < 0) x = -x, y = -y;
	int rec = gcd(x, y);
	x /= rec; y /= rec;
}

void turnToLine(int ax, int ay, int bx, int by) {
	if (ax == bx) {
		specX.push_back(data(0, ax, 0, ONLYX, mp(ax, ay), mp(bx, by)));
		ans += abs(ay - by) + 1;
	}
	else if (ay == by) {
		specY.push_back(data(0, ay, 0, ONLYY, mp(ax, ay), mp(bx, by)));
		ans += abs(ax - bx) + 1;
	}
	else {
		int up = by - ay; int down = bx - ax;
		ans += abs(gcd(up, down)) + 1;
		divGcd(up, down);
		int trueB = ay * down - up * ax;
		line.push_back(data(up, trueB * down, down, BOTH, mp(ax, ay), mp(bx, by)));
	}
}

int bet(int X, int Y, int Z) {
	if (X <= Y && Y <= Z) return true;
	if (Z <= Y && Y <= X) return true;
	return false;
}

void removeDupSpec() {
	for (int i = 0; i < specX.size(); i++) {
		for (int j = 0; j < specY.size(); j++) {
			auto lineX = specX[i];
			auto lineY = specY[j];
			if (bet(lineX.sta.se, lineY.b, lineX.end.se) && bet(lineY.sta.fi, lineX.b, lineY.end.fi))
				ans--;
		}
	}
}

vector<pair<int, int> > inter;
void cut(data line1, data line2) {
	if (line1.type > line2.type) swap(line1, line2);
	if (line1.type == BOTH && line2.type == BOTH) {
		int up = line2.b - line1.b; int down = line1.a - line2.a;
		divGcd(up, down);
		if (down != 1) return;
		if (line1.sta.fi <= up && up <= line1.end.fi) {
			assert((up * line1.a + line1.b) % line1.y == 0);
			int trueY = (up * line1.a + line1.b) / line1.y;
			inter.push_back(mp(up, trueY));
		}
		return;
	}
	if (line1.type == BOTH && line2.type == ONLYX) {
		if (bet(line1.sta.fi, line2.b, line1.end.fi) && (bet(line1.sta.se, line2.sta.se, line1.end.se) || bet(line2.sta.se, line1.sta.se, line2.end.se))) {
			int preY = line1.a * line2.b + line1.b;
			if (preY % line1.y == 0) {
				int trueY = preY / line1.y;
				inter.push_back(mp(line2.b, trueY));
			}
		}
		return;
	}
	if (line1.type == BOTH && line2.type == ONLYY) {
		if (bet(line1.sta.se, line2.b, line1.end.se) && (bet(line1.sta.fi, line2.sta.fi, line1.end.fi) || bet(line2.sta.fi, line1.sta.fi, line2.end.fi))) {
			int preX = line1.y * line2.b - line1.b;
			if (preX % line1.a == 0) {
				int trueX = preX / line1.a;
				inter.push_back(mp(trueX, line2.b));
			}
		}
		return;
	}
	assert(false);
}

vector<data> done;
void calNorm() {
	for (auto lineCur : line) {
		inter.clear();
		for (auto lineM : done) {
			cut(lineCur, lineM);
		}
		for (auto lineX : specX) {
			cut(lineCur, lineX);
		}
		for (auto lineY : specY) {
			cut(lineCur, lineY);
		}
		sort(inter.begin(), inter.end()); inter.resize(distance(inter.begin(), unique(inter.begin(), inter.end())));
		ans -= inter.size();
		done.push_back(lineCur);
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ax, ay, bx, by;
		cin >> ax >> ay >> bx >> by;
		turnToLine(ax, ay, bx, by);
	}
	removeDupSpec();
	calNorm();
	cout << ans << endl;
}


/*input
9
0 0 4 4
-1 5 4 0
4 0 4 4
5 2 11 2
6 1 6 7
5 6 11 6
10 1 10 7
7 0 9 8
10 -1 11 -1

4
-1 2 1 2
-1 0 1 0
-1 0 0 3
0 3 1 0

*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define int long long
#define N
#define bit(x,y) ((x>>y)&1LL)
#define loop(x) for(int xv=1; xv<=x; xv++)

#define what_is(x) cerr << #x << " is " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
	return os << '(' << a.first << ", " << a.second << ')';
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &a) {
	os << '[';
	for (unsigned int i = 0; i < a.size(); i++)
		os << a[i] << (i < a.size() - 1 ? ", " : "");
	os << ']';
	return os;
}
template <class T>
ostream &operator<<(ostream &os, const set<T> &a) {
	os << '{';
	for (typename set<T>::iterator it = a.begin(); it != a.end(); it++) {
		typename set<T>::iterator jt = it;
		os << *it << (++jt != a.end() ? ", " : "");
	}
	os << '}';
	return os;
}
template <class T1, class T2>
ostream &operator<<(ostream &os, map<T1, T2> &a) {
	os << "{\n";
	for (typename map<T1, T2>::iterator it = a.begin(); it != a.end(); it++) {
		typename map<T1, T2>::iterator jt = it;
		os << "  " << it->first << ": " << it->second << (++jt != a.end() ? ",\n" : "\n");
	}
	os << '}';
	return os;
}

#define BOTH 0
#define ONLYX 1
#define ONLYY 2
struct data {
	int a, b, y; int type; pair<int, int> sta, end;
	data(int _a, int _b, int _y, int _type, pair<int, int> _sta, pair<int, int> _end): a(_a), b(_b), y(_y), type(_type), sta(_sta), end(_end) {
		if (sta.fi > end.fi) swap(sta, end);
	};
};

int gcd(int a , int b) {
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int n;
vector<data> line;
vector<data> specX, specY;

// const int INF = -1e9;
int ans = 0;

void divGcd(int &x, int &y) {
	if (y < 0) x = -x, y = -y;
	int rec = gcd(x, y);
	x /= rec; y /= rec;
}

void turnToLine(int ax, int ay, int bx, int by) {
	if (ax == bx) {
		specX.push_back(data(0, ax, 0, ONLYX, mp(ax, ay), mp(bx, by)));
		ans += abs(ay - by) + 1;
	}
	else if (ay == by) {
		specY.push_back(data(0, ay, 0, ONLYY, mp(ax, ay), mp(bx, by)));
		ans += abs(ax - bx) + 1;
	}
	else {
		int up = by - ay; int down = bx - ax;
		ans += abs(gcd(up, down)) + 1;
		divGcd(up, down);
		int trueB = ay * down - up * ax;
		line.push_back(data(up, trueB * down, down, BOTH, mp(ax, ay), mp(bx, by)));
	}
}

int bet(int X, int Y, int Z) {
	if (X <= Y && Y <= Z) return true;
	if (Z <= Y && Y <= X) return true;
	return false;
}

void removeDupSpec() {
	for (int i = 0; i < specX.size(); i++) {
		for (int j = 0; j < specY.size(); j++) {
			auto lineX = specX[i];
			auto lineY = specY[j];
			if (bet(lineX.sta.se, lineY.b, lineX.end.se) && bet(lineY.sta.fi, lineX.b, lineY.end.fi))
				ans--;
		}
	}
}

vector<pair<int, int> > inter;
void cut(data line1, data line2) {
	if (line1.type > line2.type) swap(line1, line2);
	if (line1.type == BOTH && line2.type == BOTH) {
		int up = line2.b - line1.b; int down = line1.a - line2.a;
		divGcd(up, down);
		if (down != 1) return;
		if ((line1.sta.fi <= up && up <= line1.end.fi) && (bet(line1.sta.se, line2.sta.se, line1.end.se) || bet(line2.sta.se, line1.sta.se, line2.end.se))) {
		assert((up * line1.a + line1.b) % line1.y == 0);
			int trueY = (up * line1.a + line1.b) / line1.y;
			inter.push_back(mp(up, trueY));
		}
		return;
	}
	if (line1.type == BOTH && line2.type == ONLYX) {
		if (bet(line1.sta.fi, line2.b, line1.end.fi) && (bet(line1.sta.se, line2.sta.se, line1.end.se) || bet(line2.sta.se, line1.sta.se, line2.end.se))) {
			int preY = line1.a * line2.b + line1.b;
			if (preY % line1.y == 0) {
				int trueY = preY / line1.y;
				inter.push_back(mp(line2.b, trueY));
			}
		}
		return;
	}
	if (line1.type == BOTH && line2.type == ONLYY) {
		if (bet(line1.sta.se, line2.b, line1.end.se) && (bet(line1.sta.fi, line2.sta.fi, line1.end.fi) || bet(line2.sta.fi, line1.sta.fi, line2.end.fi))) {
			int preX = line1.y * line2.b - line1.b;
			if (preX % line1.a == 0) {
				int trueX = preX / line1.a;
				inter.push_back(mp(trueX, line2.b));
			}
		}
		return;
	}
	assert(false);
}

vector<data> done;
void calNorm() {
	for (auto lineCur : line) {
		inter.clear();
		for (auto lineM : done) {
			cut(lineCur, lineM);
		}
		for (auto lineX : specX) {
			cut(lineCur, lineX);
		}
		for (auto lineY : specY) {
			cut(lineCur, lineY);
		}
		sort(inter.begin(), inter.end()); inter.resize(distance(inter.begin(), unique(inter.begin(), inter.end())));
		ans -= inter.size();
		done.push_back(lineCur);
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		int ax, ay, bx, by;
		cin >> ax >> ay >> bx >> by;
		turnToLine(ax, ay, bx, by);
	}
	removeDupSpec();
	calNorm();
	cout << ans << endl;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <long long, long long>, int>, bool> mm;

struct Line {
    int a, b;
    long long c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    int a = q.second - p.second;
    int b = p.first - q.first;
    long long c = 1LL * a * p.first + 1LL * b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    long long det = 1LL * l1.a * l2.b - 1LL * l1.b * l2.a;
    if (det == 0) return;

    if ((1LL * l2.b * l1.c - 1LL * l1.b * l2.c) % det != 0 || (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) % det != 0) return;

    long long x = (1LL * l2.b * l1.c - 1LL * l1.b * l2.c) / det;
    long long y = (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) / det;

    //if (detx < eps && dety < eps) {
        pair <long long, long long> p = make_pair(x, y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[make_pair(p, j)] = true;
    //}
}

signed main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else ans = ans + __gcd(x, y) + 1;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}

/*
3
0 0 2 2
0 2 2 0
1 0 1 2
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-6;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <int, int>, int>, bool> mm;

struct Line {
    double a, b, c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    double a = q.second - p.second;
    double b = p.first - q.first;
    double c = a * p.first + b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    double det = l1.a * l2.b - l1.b * l2.a;
    if (det == 0) return;

    double x = (double)(l2.b * l1.c - l1.b * l2.c) / (double)det;
    double y = (double)(l1.a * l2.c - l1.c * l2.a) / (double)det;

    double detx = x - floor(x);
    double dety = y - floor(y);

    if (detx < eps && dety < eps) {
        pair <int, int> p = make_pair((int)x, (int)y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[make_pair(p, j)] = true;
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else if (y % x == 0) ans = ans + x + 1;
        else ans += 2;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}

/*
4
0 0 2 2
0 2 2 0
1 0 1 2
0 1 2 1
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <int, int>, int>, bool> mm;

struct Line {
    double a, b, c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    double a = q.second - p.second;
    double b = p.first - q.first;
    double c = a * p.first + b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    double det = l1.a * l2.b - l1.b * l2.a;
    if (det == 0) return;

    double x = (double)(l2.b * l1.c - l1.b * l2.c) / (double)det;
    double y = (double)(l1.a * l2.c - l1.c * l2.a) / (double)det;

    double detx = x - floor(x);
    double dety = y - floor(y);

    if (detx < eps && dety < eps) {
        pair <int, int> p = make_pair((int)x, (int)y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[make_pair(p, j)] = true;
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else if (y % x == 0) ans = ans + x + 1;
        else ans += 2;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}

/*
4
0 0 2 2
0 2 2 0
1 0 1 2
0 1 2 1
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <int, int>, int>, bool> mm;

struct Line {
    double a, b, c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    double a = q.second - p.second;
    double b = p.first - q.first;
    double c = a * p.first + b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    double det = l1.a * l2.b - l1.b * l2.a;
    if (det == 0) return;

    double x = (double)(l2.b * l1.c - l1.b * l2.c) / (double)det;
    double y = (double)(l1.a * l2.c - l1.c * l2.a) / (double)det;

    double detx = x - floor(x);
    double dety = y - floor(y);

    if (detx < eps && dety < eps) {
        pair <int, int> p = make_pair((int)x, (int)y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[make_pair(p, j)] = true;
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else if (y % x == 0) ans = ans + x + 1;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}

/*
4
0 0 2 2
0 2 2 0
1 0 1 2
0 1 2 1
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N];
map <pair <int, int>, int> mm;

struct Line {
    int a, b;
    long long c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    int a = q.second - p.second;
    int b = p.first - q.first;
    long long c = 1LL * a * p.first + 1LL * b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    long long det = 1LL * l1.a * l2.b - 1LL * l1.b * l2.a;
    if (det == 0) return;

    double x = (double)(1LL * l2.b * l1.c - 1LL * l1.b * l2.c) / (double)det;
    double y = (double)(1LL * l1.a * l2.c - 1LL * l1.c * l2.a) / (double)det;

    double detx = x - floor(x);
    double dety = y - floor(y);

    if (detx < eps && dety < eps) {
        pair <int, int> p = make_pair((int)x, (int)y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[p]++;
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else if (y % x == 0) ans = ans + x + 1;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) {
        ans = ans - it.second;
    }
    printf("%lld", ans);
    return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <long long, long long>, int>, bool> mm;

struct Line {
    int a, b;
    long long c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    int a = q.second - p.second;
    int b = p.first - q.first;
    long long c = 1LL * a * p.first + 1LL * b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    long long det = 1LL * l1.a * l2.b - 1LL * l1.b * l2.a;
    if (det == 0) return;

    if ((1LL * l2.b * l1.c - 1LL * l1.b * l2.c) % det != 0 || (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) % det != 0) return;

    long long x = (1LL * l2.b * l1.c - 1LL * l1.b * l2.c) / det;
    long long y = (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) / det;

    //if (detx < eps && dety < eps) {
        pair <long long, long long> p = make_pair(x, y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[make_pair(p, j)] = true;
    //}
}

signed main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else if (y % x == 0) ans = ans + x + 1;
        else ans += 2;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}

/*
3
0 0 2 2
0 2 2 0
1 0 1 2
*/


#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <int, int>, int>, bool> mm;

struct Line {
    int a, b;
    long long c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    int a = q.second - p.second;
    int b = p.first - q.first;
    long long c = 1LL * a * p.first + 1LL * b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    long long det = 1LL * l1.a * l2.b - 1LL * l1.b * l2.a;
    if (det == 0) return;

    double x = (double)(1LL * l2.b * l1.c - 1LL * l1.b * l2.c) / (double)det;
    double y = (double)(1LL * l1.a * l2.c - 1LL * l1.c * l2.a) / (double)det;

    double detx = x - floor(x);
    double dety = y - floor(y);

    if (detx < eps && dety < eps) {
        pair <int, int> p = make_pair((int)x, (int)y);
        if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
            && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))
            mm[make_pair(p, j)] = true;
    }
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else if (y % x == 0) ans = ans + x + 1;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
            //break;
        }
        //break;
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}

/*
3
0 0 2 2
0 2 2 0
1 0 1 2
*/


#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <long long, long long>, int>, bool> mm;

struct Line {
    int a, b;
    long long c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    int a = q.second - p.second;
    int b = p.first - q.first;
    long long c = 1LL * a * p.first + 1LL * b * p.second;

    return {a, b, c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    long long det = 1LL * l1.a * l2.b - 1LL * l1.b * l2.a;
    if (det == 0) return;

    if ((1LL * l2.b * l1.c - 1LL * l1.b * l2.c) % det != 0 || (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) % det != 0) return;

    long long x = (1LL * l2.b * l1.c - 1LL * l1.b * l2.c) / det;
    long long y = (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) / det;

    pair <long long, long long> p = make_pair(x, y);
    if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
        && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))            mm[make_pair(p, j)] = true;
}

signed main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else ans = ans + __gcd(x, y) + 1;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
        }
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 1e3 + 5;
const double eps = 1e-8;

int n, a[N], b[N], c[N], d[N], j;
map <pair <pair <long long, long long>, int>, bool> mm;

struct Line {
    int a, b;
    long long c;
};

Line equation (pair <int, int> p, pair <int, int> q) {
    int a = q.second - p.second;
    int b = p.first - q.first;
    long long c = 1LL * a * p.first + 1LL * b * p.second;

    return {a, b, -c};
}

long long cross (pair <int, int> O, pair <int, int> A, pair <int, int> B) {
    return 1LL * (A.first - O.first) * (B.second - O.second) - 1LL * (A.second - O.second) * (B.first - O.first);
}

bool onSegment (pair <int, int> p, pair <int, int> q, pair <int, int> r) {
    return q.first >= min(p.first, r.first) && q.first <= max(p.first, r.first) && q.second >= min(p.second, r.second) && q.second <= max(p.second, r.second);
}

void intersect (int xa1, int ya1, int xb1, int yb1, int xa2, int ya2, int xb2, int yb2) {
    Line l1 = equation(make_pair(xa1, ya1), make_pair(xb1, yb1));
    Line l2 = equation(make_pair(xa2, ya2), make_pair(xb2, yb2));

    long long det = 1LL * l1.a * l2.b - 1LL * l1.b * l2.a;
    if (det == 0) return;

    if ((1LL * l2.b * l1.c - 1LL * l1.b * l2.c) % det != 0 || (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) % det != 0) return;

    long long x = (1LL * l2.b * l1.c - 1LL * l1.b * l2.c) / det;
    long long y = (1LL * l1.a * l2.c - 1LL * l1.c * l2.a) / det;

    pair <long long, long long> p = make_pair(x, y);
    if (cross(p, make_pair(xa1, ya1), make_pair(xb1, yb1)) == 0 && cross(p, make_pair(xa2, ya2), make_pair(xb2, yb2)) == 0
        && onSegment(make_pair(xa1, ya1), p, make_pair(xb1, yb1)) && onSegment(make_pair(xa2, ya2), p, make_pair(xb2, yb2)))            mm[make_pair(p, j)] = true;
}

signed main(){
    scanf("%lld", &n);
    for (int i = 1; i <= n; i++) scanf("%lld %lld %lld %lld", &a[i], &b[i], &c[i], &d[i]);

    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        int x = abs(c[i] - a[i]);
        int y = abs(d[i] - b[i]);

        if (x == 0) ans = ans + abs(d[i] - b[i]) + 1;
        else ans = ans + __gcd(x, y) + 1;
    }

    for (int i = 1; i <= n; i++) {
        for (j = i + 1; j <= n; j++) {
            intersect(a[i], b[i], c[i], d[i], a[j], b[j], c[j], d[j]);
        }
    }

    for (auto it: mm) ans = ans - it.second;
    printf("%lld", ans);
    return 0;
}


#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "../debug.h"
#else
    #define debug(...)
#endif

#define EPS 1e-8
#define MOD 1000000007
const double PI = acos(-1);

template<typename A,typename B>
long long fast_exp(long long a,long long b){long long res=1;
while(b){if(b&1LL){res*=a;res%=MOD;}
b>>=1LL;a*=a;a%=MOD;}
return res;}

typedef pair<int, int> ii;
#define fi first
#define se second

bool check(ii a, ii b, double x, double y) {
    if (min(a.first, b.first) <= x + EPS and x - EPS <= max(a.first, b.first) and min(a.second, b.second) <= y + EPS and y - EPS <= max(a.second, b.second)) {
        return true;
    }
    return false;
}
pair<bool, pair<int, int>> solve(ii A, ii B, ii C, ii D) {
    bool res = false;

    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);
    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) {
        return {false, {0,0}};
     } else {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        if (!check(A, B, x, y) or !check(C, D, x, y)) {
            return {false, {x, y}};
        }
        if (x - EPS <= int(x) and int(x) <= x + EPS and int(y) <= y + EPS and y - EPS <= int(y)) {
            return {true, {int(x), int(y)}};
        }
     }

    return {res, {0,0}};
}

signed main (int argc, char* argv[], char* envp[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    cerr << fixed; cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> p1(n), p2(n);
    map<pair<int, int>, bool> present;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p1[i].first >> p1[i].second;
        cin >> p2[i].first >> p2[i].second;
        if (p1[i].first == p2[i].first) {
            ans += abs(p1[i].second - p2[i].second) + 1;
        } else if (p1[i].second == p2[i].second) {
            ans += abs(p1[i].first - p2[i].first) + 1;
        } else {
            ans += __gcd(abs(p1[i].first - p2[i].first), abs(p1[i].second - p2[i].second)) + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            pair<bool, pair<int, int>> tans = solve(p1[i], p2[i], p1[j], p2[j]);
            if (tans.first) {
                pair<int, int> tt = tans.second;
                if (present.find(tt) != present.end()) {
                    continue;
                }
                /* present[tt] = true; */
                ans--;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "../debug.h"
#else
    #define debug(...)
#endif

#define EPS 1e-6
#define MOD 1000000007
const double PI = acos(-1);

template<typename A,typename B>
long long fast_exp(long long a,long long b){long long res=1;
while(b){if(b&1LL){res*=a;res%=MOD;}
b>>=1LL;a*=a;a%=MOD;}
return res;}

typedef pair<int, int> ii;
#define fi first
#define se second

bool check(ii a, ii b, int x, int y) {
    if (min(a.first, b.first) <= x and x <= max(a.first, b.first) and min(a.second, b.second) <= y and y <= max(a.second, b.second)) {
        return true;
    }
    return false;
}
pair<bool, pair<int, int>> solve(ii A, ii B, ii C, ii D) {
    bool res = false;

    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);
    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;

    int x, y;
    if (determinant == 0) {
        return {false, {x, y}};
     } else {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        if (!check(A, B, x, y) or !check(C, D, x, y)) {
            return {false, {x, y}};
        }
        if (x - EPS <= int(x) and int(x) <= x + EPS and int(y) <= y + EPS and y - EPS <= int(y)) {
            return {true, {int(x), int(y)}};
        }
     }

    return {res, {x, y}};
}

signed main (int argc, char* argv[], char* envp[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    cerr << fixed; cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> p1(n), p2(n);
    map<pair<int, int>, bool> present;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p1[i].first >> p1[i].second;
        cin >> p2[i].first >> p2[i].second;
        if (p1[i].first == p2[i].first) {
            ans += abs(p1[i].second - p2[i].second) + 1;
        } else if (p1[i].second == p2[i].second) {
            ans += abs(p1[i].first - p2[i].first) + 1;
        } else {
            ans += __gcd(abs(p1[i].first - p2[i].first), abs(p1[i].second - p2[i].second)) + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            pair<bool, pair<int, int>> tans = solve(p1[i], p2[i], p1[j], p2[j]);
            if (tans.first) {
                pair<int, int> tt = tans.second;
                if (present.find(tt) != present.end()) {
                    continue;
                }
                present[tt] = true;
                ans--;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "../debug.h"
#else
    #define debug(...)
#endif

#define EPS 1e-8
#define MOD 1000000007
const double PI = acos(-1);

template<typename A,typename B>
long long fast_exp(long long a,long long b){long long res=1;
while(b){if(b&1LL){res*=a;res%=MOD;}
b>>=1LL;a*=a;a%=MOD;}
return res;}

typedef pair<int, int> ii;
#define fi first
#define se second

bool check(ii a, ii b, double x, double y) {
    if (min(a.first, b.first) <= x + EPS and x - EPS <= max(a.first, b.first) and min(a.second, b.second) <= y + EPS and y - EPS <= max(a.second, b.second)) {
        return true;
    }
    return false;
}
pair<bool, pair<int, int>> solve(ii A, ii B, ii C, ii D) {
    bool res = false;

    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);
    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) {
        return {false, {0,0}};
     } else {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        if (!check(A, B, x, y) or !check(C, D, x, y)) {
            return {false, {x, y}};
        }
        if (x - EPS <= int(x) and int(x) <= x + EPS and int(y) <= y + EPS and y - EPS <= int(y)) {
            return {true, {int(x), int(y)}};
        }
     }

    return {res, {0,0}};
}

signed main (int argc, char* argv[], char* envp[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    cerr << fixed; cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> p1(n), p2(n);
    map<pair<int, int>, long long> present;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p1[i].first >> p1[i].second;
        cin >> p2[i].first >> p2[i].second;
        if (p1[i].first == p2[i].first) {
            ans += abs(p1[i].second - p2[i].second) + 1;
        } else if (p1[i].second == p2[i].second) {
            ans += abs(p1[i].first - p2[i].first) + 1;
        } else {
            ans += __gcd(abs(p1[i].first - p2[i].first), abs(p1[i].second - p2[i].second)) + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            pair<bool, pair<int, int>> tans = solve(p1[i], p2[i], p1[j], p2[j]);
            if (tans.first) {
                pair<int, int> tt = tans.second;
                if (present.find(tt) == present.end()) {
                    present[tt] = 0;
                }
                present[tt] += 1;
            }
        }
    }

    for (auto i: present) {
        long long cnt = i.second;
        int l = 0;
        int r = 1e7;
        for (int k = 0; k < 40; k++) {
            int m = (l + r) >> 1;
            long long t = 1LL * m * (m + 1LL) / 2;
            if (t == cnt) {
                ans -= m;
                break;
            }
            if (t < cnt) {
                l = m + 1;
            } else {
                r = m - 1;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "../debug.h"
#else
    #define debug(...)
#endif

#define EPS 1e-6
#define MOD 1000000007
const double PI = acos(-1);

template<typename A,typename B>
long long fast_exp(long long a,long long b){long long res=1;
while(b){if(b&1LL){res*=a;res%=MOD;}
b>>=1LL;a*=a;a%=MOD;}
return res;}

typedef pair<int, int> ii;
#define fi first
#define se second

bool check(ii a, ii b, double x, double y) {
    if (min(a.first, b.first) <= x + EPS and x - EPS <= max(a.first, b.first) and min(a.second, b.second) <= y + EPS and y - EPS <= max(a.second, b.second)) {
        return true;
    }
    return false;
}
pair<bool, pair<int, int>> solve(ii A, ii B, ii C, ii D) {
    bool res = false;

    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);
    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) {
        return {false, {0,0}};
     } else {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        if (!check(A, B, x, y) or !check(C, D, x, y)) {
            return {false, {x, y}};
        }
        if (x - EPS <= int(x) and int(x) <= x + EPS and int(y) <= y + EPS and y - EPS <= int(y)) {
            return {true, {int(x), int(y)}};
        }
     }

    return {res, {0,0}};
}

signed main (int argc, char* argv[], char* envp[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    cerr << fixed; cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> p1(n), p2(n);
    map<pair<int, int>, bool> present;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p1[i].first >> p1[i].second;
        cin >> p2[i].first >> p2[i].second;
        if (p1[i].first == p2[i].first) {
            ans += abs(p1[i].second - p2[i].second) + 1;
        } else if (p1[i].second == p2[i].second) {
            ans += abs(p1[i].first - p2[i].first) + 1;
        } else {
            ans += __gcd(abs(p1[i].first - p2[i].first), abs(p1[i].second - p2[i].second)) + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            pair<bool, pair<int, int>> tans = solve(p1[i], p2[i], p1[j], p2[j]);
            if (tans.first) {
                pair<int, int> tt = tans.second;
                if (present.find(tt) != present.end()) {
                    continue;
                }
                present[tt] = true;
                ans--;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "../debug.h"
#else
    #define debug(...)
#endif

#define EPS 1e-8
#define MOD 1000000007
const double PI = acos(-1);

template<typename A,typename B>
long long fast_exp(long long a,long long b){long long res=1;
while(b){if(b&1LL){res*=a;res%=MOD;}
b>>=1LL;a*=a;a%=MOD;}
return res;}

typedef pair<int, int> ii;
#define fi first
#define se second

bool check(ii a, ii b, double x, double y) {
    if (min(a.first, b.first) <= x + EPS and x - EPS <= max(a.first, b.first) and min(a.second, b.second) <= y + EPS and y - EPS <= max(a.second, b.second)) {
        return true;
    }
    return false;
}
pair<bool, pair<int, int>> solve(ii A, ii B, ii C, ii D) {
    bool res = false;

    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);
    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) {
        return {false, {0,0}};
     } else {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        if (!check(A, B, x, y) or !check(C, D, x, y)) {
            return {false, {x, y}};
        }
        if (x - EPS <= int(x) and int(x) <= x + EPS and int(y) <= y + EPS and y - EPS <= int(y)) {
            return {true, {int(x), int(y)}};
        }
     }

    return {res, {0,0}};
}

signed main (int argc, char* argv[], char* envp[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    cerr << fixed; cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> p1(n), p2(n);
    map<pair<int, int>, long long> present;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p1[i].first >> p1[i].second;
        cin >> p2[i].first >> p2[i].second;
        if (p1[i].first == p2[i].first) {
            ans += abs(p1[i].second - p2[i].second) + 1;
        } else if (p1[i].second == p2[i].second) {
            ans += abs(p1[i].first - p2[i].first) + 1;
        } else {
            ans += __gcd(abs(p1[i].first - p2[i].first), abs(p1[i].second - p2[i].second)) + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            pair<bool, pair<int, int>> tans = solve(p1[i], p2[i], p1[j], p2[j]);
            if (tans.first) {
                pair<int, int> tt = tans.second;
                if (present.find(tt) == present.end()) {
                    present[tt] = 0;
                }
                present[tt] += 1;
            }
        }
    }

    for (auto i: present) {
        long long cnt = i.second;
        int l = 0;
        int r = 1e7;
        for (int k = 0; k < 40; k++) {
            int m = (l + r) >> 1;
            long long t = 1LL * m * (m + 1LL) / 2;
            if (t == cnt) {
                ans -= m - 1;
                break;
            }
            if (t < cnt) {
                l = m + 1;
            } else {
                r = m - 1;
            }
        }
    }

    cout << ans << endl;
    return 0;
}


#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "../debug.h"
#else
    #define debug(...)
#endif

#define EPS 1e-8
#define MOD 1000000007
const double PI = acos(-1);

template<typename A,typename B>
long long fast_exp(long long a,long long b){long long res=1;
while(b){if(b&1LL){res*=a;res%=MOD;}
b>>=1LL;a*=a;a%=MOD;}
return res;}

typedef pair<int, int> ii;
#define fi first
#define se second

bool check(ii a, ii b, double x, double y) {
    if (min(a.first, b.first) <= x + EPS and x - EPS <= max(a.first, b.first) and min(a.second, b.second) <= y + EPS and y - EPS <= max(a.second, b.second)) {
        return true;
    }
    return false;
}
pair<bool, pair<int, int>> solve(ii A, ii B, ii C, ii D) {
    bool res = false;

    double a1 = B.second - A.second;
    double b1 = A.first - B.first;
    double c1 = a1*(A.first) + b1*(A.second);
    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) {
        return {false, {0,0}};
     } else {
        double x = (b2*c1 - b1*c2)/determinant;
        double y = (a1*c2 - a2*c1)/determinant;
        if (!check(A, B, x, y) or !check(C, D, x, y)) {
            return {false, {x, y}};
        }
        if (x - EPS <= int(x) and int(x) <= x + EPS and int(y) <= y + EPS and y - EPS <= int(y)) {
            return {true, {int(x), int(y)}};
        }
     }

    return {res, {0,0}};
}

signed main (int argc, char* argv[], char* envp[]){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    cerr << fixed; cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> p1(n), p2(n);
    map<pair<int, int>, bool> present;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> p1[i].first >> p1[i].second;
        cin >> p2[i].first >> p2[i].second;
        if (p1[i].first == p2[i].first) {
            ans += abs(p1[i].second - p2[i].second) + 1;
        } else if (p1[i].second == p2[i].second) {
            ans += abs(p1[i].first - p2[i].first) + 1;
        } else {
            ans += __gcd(abs(p1[i].first - p2[i].first), abs(p1[i].second - p2[i].second)) + 1;
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            pair<bool, pair<int, int>> tans = solve(p1[i], p2[i], p1[j], p2[j]);
            if (tans.first) {
                pair<int, int> tt = tans.second;
                if (present.find(tt) != present.end()) {
                    continue;
                }
                present[tt] = true;
                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);

using namespace std;

typedef long long int llp;
typedef long double ld;
const llp INF=(1LL<<60)-1;
const int MAX = 1000000;
  map<llp,llp> 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)) && (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)))
                   {
                       if(l[x]==0)
                        {
                          ans--;
                          l[x]++;
                        }
                     //if(i==1)  cout << j << endl;
                     //if(j==4) cout << x << " " << y << endl;
                   }
                }
             }
          }
          l.clear();
        //  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;

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;
        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;
      }
      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>
#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];
    map<llp,llp> l;
  //  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);
      //  cout << m << endl;
        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)))
                   {
                       if(l[x]==0)
                        {
                          ans--;
                          l[x]++;
                        }
                     //if(i==1)  cout << j << endl;
                     //if(j==4) cout << x << " " << y << endl;
                   }
                }
             }
          }
          l.clear();
        //  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;
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-x1[i],Y1=it.S-y1[i];
            int X2=x2[i]-x1[i],Y2=y2[i]-y1[i];
            if(X1*Y2!=Y1*X2) continue;
            if(it.F<min(x1[i],x2[i])||it.F>max(x1[i],x2[i])) continue;
            if(it.S<min(y1[i],y2[i])||it.S>max(y1[i],y2[i])) continue;
            cnt++;
        }
        ans-=cnt-1;
    }
  //  printf("%lld\n",ans);
    cout << ans << endl;
    return 0;
 }