Under construction

Still being built. Things may change

Perfect Pilgrimage

Time limit1sMemory limit1024 MB

Summary
Choose N lattice points forming a counterclockwise polygon with no crossing edges and at least K equal sides, or report that no such choice exists.
Level

Hard8 of 10

Topics
Geometry, Math, Implementation
Solved
No attempts yet

Problem

A pilgrim keeps on a pilgrimage that seems like it will never end. The pilgrim moves from the holy site where they are to another holy site, and prays to God each time they arrive at a site.

At the center of the earth is the Great Holy Site, and holy sites are lined up at regular intervals around it. The position of a holy site is written as (X,Y)(X,Y), which means the site is XX miles east of the Great Holy Site and YY miles north of it. If X<0X < 0, the site is −X-X miles west. If Y<0Y < 0, the site is −Y-Y miles south. Here, a mile is the distance God walks in a thousand steps.

For every integer pair X,YX,Y with −231≤X,Y<231-2^{31} \leq X,Y < 2^{31}, a site exists at (X,Y)(X,Y), so there are exactly 2642^{64} holy sites on the earth.

The pilgrim chooses NN of these sites, visits them in order, and then returns to the first site chosen. The pilgrim wants the chosen sites to form a perfect regular NN-gon, the shape God likes most. A regular NN-gon has many properties. The following are representative:

  • It is a convex polygon.
  • All sides have equal length.
  • All angles have equal size.

Since XiX_i and YiY_i are both integers, a perfect regular NN-gon may be impossible to build. So the pilgrim relaxes the conditions and selects sites that satisfy the following. For convenience, the (N+i)(N+i)-th site is treated as the same as the ii-th site.

  • The ii-th, (i+1)(i+1)-th, and (i+2)(i+2)-th sites are located counterclockwise.
  • Let Li=(Xi−Xi+1)2+(Yi−Yi+1)2L_i = \sqrt{(X_i - X_{i+1})^2 + (Y_i - Y_{i+1})^2} be the Euclidean distance between the ii-th and (i+1)(i+1)-th sites. There must be at least KK integers ii with 1≤i≤N1 \leq i \leq N such that Li=L1L_i = L_1.
  • For every integer kk with 2≤k≤N−22 \leq k \leq N-2, the segment connecting the ii-th and (i+1)(i+1)-th sites and the segment connecting the (i+k)(i+k)-th and (i+k+1)(i+k+1)-th sites must not intersect.

Determine whether the pilgrim can choose NN sites satisfying these conditions. If so, find the positions of the sites and the order in which they must be chosen.

Input

The first line contains two positive integers NN and KK (3≤N≤2 5003 \leq N \leq 2\,500, 1≤K≤N1 \leq K \leq N), the number of sites to choose and the distance condition.

Output

On the first line, print YES if the pilgrim can choose NN sites satisfying the conditions, and NO otherwise.

If such sites exist, print NN more lines. The ii-th line contains two integers XiX_i and YiY_i, separated by a space, giving the position of the ii-th chosen site. Every printed position must be an existing site for the answer to be accepted.

Examples2

  1. Example 1

    Input
    4 3
    
    Expected output
    YES
    0 0
    13 0
    8 12
    5 12
    
  2. Example 2

    Input
    3 3
    
    Expected output
    NO