Rectilinear Polygon With Area Equal to Its Vertex Count

No attempts yetTime limit5sMemory limit128 MB

Problem

A rectilinear polygon is a simple polygon whose edges are all parallel to the xx-axis or the yy-axis and in which every two consecutive edges are perpendicular (so the edges alternate between horizontal and vertical). The edges never touch or cross, except that two consecutive edges meet at their shared vertex.

You are given an integer nn. Consider rectilinear polygons that have exactly nn vertices and whose area equals exactly nn. Such a polygon does not exist for every nn, and when it exists there can be many of them, so this task asks for one specific canonical polygon defined in the Output section.

Input

The input contains a single integer nn (2n100002 \le n \le 10000), the required number of vertices.

Output

A rectilinear polygon with exactly nn vertices and area exactly nn exists if and only if nn is even and n4n \ge 4. If it does not exist, print a single line containing the word NIE (Polish for "no").

Otherwise print the following canonical polygon. Let m=n/21m = n/2 - 1. Place mm unit-width vertical bars standing on the xx-axis; bar ii (for 0i<m0 \le i < m) occupies the strip ixi+1i \le x \le i+1 and has integer height hih_i, where:

  • for 1i<m1 \le i < m: hi=2h_i = 2 if ii is even, and hi=1h_i = 1 if ii is odd;
  • h0=n(h1+h2++hm1)h_0 = n - (h_1 + h_2 + \cdots + h_{m-1}).

The outline of these bars is a simple rectilinear polygon with exactly nn vertices and area exactly nn. Print its vertices, one per line as two integers x y separated by a space, in counterclockwise order, in exactly this sequence: first (0,0)(0, 0), then (m,0)(m, 0), then (m,hm1)(m, h_{m-1}); then, for i=m1,m2,,1i = m-1, m-2, \ldots, 1, the two points (i,hi)(i, h_i) and (i,hi1)(i, h_{i-1}); and finally (0,h0)(0, h_0). (When m=1m = 1 the middle sequence is empty, so the polygon is the rectangle (0,0),(1,0),(1,n),(0,n)(0,0), (1,0), (1,n), (0,n).)

No coordinate exceeds 10910^9 in absolute value.