Let us call a good point on x=1 or x=2000 excluding (1,1) a special point. Consider Z-shaped polyline ABCD and let A(x1,y1), B(x2,y2), C(x3,y3), D(x4,y4). Since 1≤x1<x2≤2000, 1≤x3<x2≤2000 and 1≤x3<x4≤2000, any special point on Z-shaped polyline ABCD coincides with either A, B, C or D. Assume that both B and C are special points. Then x2=2000, y2≤2000, x3=1 and y3≥2 holds. Therefore we have y2−x2≤2000−2000<2−1≤y3−x3, which contradicts the condition y2−x2=y3−x3. Therefore at most three special points lie on a Z-shaped polylines, hence we must select at least 33999=1333 Z-shaped polylines to meet the condition.
Denote polyline ABCD with A(x1,y1), B(x2,y2), C(x3,y3), D(x4,y4) by (x1,y1)−(x2,y2)−(x3,y3)−(x4,y4). Define Z-shaped polylines X1,X2,…,X666, Y1,Y2,…,Y666, Z as following:
* For k=1,…,666, let Xk be (1,1334−k)−(1334−2k,1334−k)−(1,1+k)−(2000,1+k).
* For k=1,…,666, let Yk be (1,2000−k)−(2000,2000−k)−(667+2k,667+k)−(2000,667+k).
* Let Z be (1,2000)−(2000,2000)−(1,1)−(2000,1).
Note that any good point on y=1,2000 lies on Z. For 2≤k≤667, any good point on y=k lies on Xk−1. For 1334≤k≤1999, any good point on y=k lies on Y2000−k. Let 668≤k≤1333 and consider good points on y=k.
* When 1≤x<2k−1333, (x,k) lies on X1334−k.
* When 2k−1333≤x<k, (x,k) lies on Xk−x.
* When x=k, (x,k) lies on Z.
* When k<x≤2k−668, (x,k) lies on Yx−k.
* When 2k−668<x≤2000, (x,k) lies on Yk−667.
We have shown that any good point lies on any of X1,X2,…,X666, Y1,Y2,…,Y666 and Z.
Therefore the smallest possible number of Z-shaped polylines is 1333.