1036_E. Covered Points
You are given n segments on a Cartesian plane. Each segment's endpoints have integer coordinates. Segments can intersect with each other. No two segments lie on the same line.

Count the number of distinct points with integer coordinates, which are covered by at least one segment.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of segments.

Each of the next n lines contains four integers Ax_i, Ay_i, Bx_i, By_i (-10^6 ≤ Ax_i, Ay_i, Bx_i, By_i ≤ 10^6) — the coordinates of the endpoints A, B (A ≠ B) of the i-th segment.

It is guaranteed that no two segments lie on the same line.

Output

Print a single integer — the number of distinct points with integer coordinates, which are covered by at least one segment.

Examples

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


Output

42


Input

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


Output

7

Note

The image for the first example:

<image>

Several key points are marked blue, the answer contains some non-marked points as well.

The image for the second example:

<image>
```python
import sys
from math import gcd


class Segment:
    def __init__(self, x1, y1, x2, y2):
        self.x1 = x1
        self.y1 = y1
        self.x2 = x2
        self.y2 = y2
    
    def dx(self):
        return self.x2 - self.x1
    
    def dy(self):
        return self.y2 - self.y1
    
    def pt_cnt(self):
        return gcd(abs(self.dx()), abs(self.dy())) + 1
    
    def A(self):
        return self.y1 - self.y2
    
    def B(self):
        return self.x2 - self.x1

    def C(self):
        return -self.A() * self.x1 - self.B() * self.y1

    def inner_x(self, x):
        l = self.x1
        r = self.x2
        if l > r:
            l, r = r, l
        return l <= x <= r
    
    def inner_y(self, y):
        l = self.y1
        r = self.y2
        if l > r:
            l, r = r, l
        return l <= y <= r
    
    def inner(self, x, y):
        return self.inner_x(x) and self.inner_y(y)

    def intersect(self, other):
        dx = det(self.C(), self.B(), other.C(), other.B())
        dy = det(self.A(), self.C(), other.A(), other.C())
        d = det(self.A(), self.B(), other.A(), other.B())
        if d == 0:
            return False, 0, 0
        if dx % d != 0 or dy % d != 0:
            return False, 0, 0
        x = -dx // d
        y = -dy // d
        if not self.inner(x, y) or not other.inner(x, y):
            return False, 0, 0
        return True, x, y


def det(a, b, c, d):
    return a * d - b * c

def main():
    n = int(input())
    segments = []
    ans = 0
    for _ in range(n):
        x1, y1, x2, y2 = map(int, input().split())
        segment = Segment(x1, y1, x2, y2)
        ans += segment.pt_cnt()
        pt = set()
        for other in segments:
            result, x, y = segment.intersect(other)
            if result:
                pt.add((x, y))
        ans -= len(pt)
        segments.append(segment)  
    print(ans)
        
if __name__ == '__main__':
    main()
```