Under construction

Still being built. Things may change

Rectilinear Polygon With Area Equal to Its Vertex Count

Time limit5sMemory limit128 MB

Summary
Given n, print a canonical rectilinear polygon outline with n vertices and area n, or NIE when n is odd or below 4.
Level

Easy3 of 10

Topics
Implementation, Geometry, Math, Simulation
Solved
No attempts yet

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 (2≤n≤100002 \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 n≥4n \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/2−1m = n/2 - 1. Place mm unit-width vertical bars standing on the xx-axis; bar ii (for 0≤i<m0 \le i < m) occupies the strip i≤x≤i+1i \le x \le i+1 and has integer height hih_i, where:

  • for 1≤i<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+⋯+hm−1)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,hm−1)(m, h_{m-1}); then, for i=m−1,m−2,…,1i = m-1, m-2, \ldots, 1, the two points (i,hi)(i, h_i) and (i,hi−1)(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.

Examples3

  1. Example 1

    Input
    4
    
    Expected output
    0 0
    1 0
    1 4
    0 4
    
  2. Example 2

    Input
    6
    
    Expected output
    0 0
    2 0
    2 1
    1 1
    1 5
    0 5
    
  3. Example 3

    Input
    2
    
    Expected output
    NIE