This page is still under construction.

Parts of this page are still being built. What you see may change.

Circuit Connections (Circuit)

Time limit1sMemory limit1024 MB

Summary
Given a permutation a of size n and integer k, decide whether some permutation b satisfies b^k = a, and if so output any such b.
Level

Medium7 of 10

Topics
Math, Combinatorics, Implementation, Number theory
Solved
No attempts yet

Problem

Consider an IC (integrated circuit) with nn inputs and nn outputs, as in the following figure. The nn inputs are numbered 1,2,…,n1, 2, \ldots, n from left to right. Likewise, the nn outputs are numbered 1,2,…,n1, 2, \ldots, n from left to right.

In this IC, each of the nn inputs comes out unchanged as one of the nn outputs, but you cannot tell which input corresponds to which output. An IC is described by listing, for outputs 1,…,n1, \ldots, n, the number of the input that corresponds to each output.

For example, when n=3n = 3, there are the following 6 kinds of IC.

Here, connecting 5 copies of IC (2,3,1)(2, 3, 1) in series makes the original inputs 3,1,23, 1, 2 correspond to the final outputs 1,2,31, 2, 3 respectively, as in the following figure, so the result behaves the same as IC (3,1,2)(3, 1, 2).

Given integers nn (1≤n≤100001 \le n \le 10000), kk (1≤k≤100001 \le k \le 10000), and a sequence of distinct integers a1,…,ana_1, \ldots, a_n from 11 to nn, write a program that determines whether connecting kk copies of the same kind of IC in series can make the result behave the same as IC (a1,…,an)(a_1, \ldots, a_n), and if so, outputs an IC that achieves the goal. When multiple ICs satisfy the condition, you may output any of them.

Input

The input consists of n+1n + 1 lines.

The first line contains the integers nn and kk, separated by a space.

Line i+1i + 1 (1≤i≤n1 \le i \le n) contains the integer aia_i.

Output

The program writes its result to standard output.

If connecting kk copies of the same kind of IC in series can make the result behave the same as IC (a1,…,an)(a_1, \ldots, a_n), write an IC satisfying the condition on nn lines, from line 1 to line nn. That is, for 1≤i≤n1 \le i \le n, line ii contains the number of the input corresponding to output ii of the IC.

If connecting kk copies of the same kind of IC in series cannot make the result behave the same as IC (a1,…,an)(a_1, \ldots, a_n), output only 1 line containing 00.

Examples2

  1. Example 1

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

    Input
    4 4
    2
    1
    4
    3
    
    Expected output
    0