Crazy Dreamoon

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Dreamoon likes algorithm competitions very much. But when he feels crazy because he cannot figure out any solution for any problem in a competition, he often draws many meaningless straight line segments on his calculation paper.

Dreamoon's calculation paper is special: it can be imagined as the plane with Cartesian coordinate system with range \[0,2000]×\[0,2000]\[0, 2000] \times \[0, 2000] for the coordinates. The grid lines are all lines of the form x=cx = c or y=cy = c for every integer cc between 00 and 20002000, inclusive. So, the grid contains 2000×20002000 \times 2000 squares.

Now, Dreamoon wonders how many grid squares are crossed by at least one of the lines he drew. Please help Dreamoon find the answer. Note that touching an edge of a grid square is not considered as crossing this square.

입력

The first line of input contains an integer NN denoting the number of lines Dreamoon draw. The ii-th line of following NN lines contains four integers x_i1,y_i1,x_i2,y_i2x\_{i1}, y\_{i1}, x\_{i2}, y\_{i2}, denoting that the ii-th segment Dreamoon drew is a straight line segment between points (x_i1,y_i1)(x\_{i1}, y\_{i1}) and (x_i2,y_i2)(x\_{i2}, y\_{i2}).

출력

Output one integer on a single line: how many grid squares are crossed by at least one of the line segments which Dreamoon drew.

제한

  • 1N2×1031 \le N \le 2 \times 10^3
  • 0x_i1,y_i1,x_i2,y_i22×1030 \le x\_{i1}, y\_{i1}, x\_{i2}, y\_{i2} \le 2 \times 10^3
  • the lengths of all line segments in input are non-zero