Space Pirate

Change one teleporter destination, walk K jumps from star 1, and count the landing star over all N squared rewires.

Medium7GraphSimulationNo attempts yetTime limit2sMemory limit512 MB

Problem

In a distant galaxy there are NN stars, numbered 11 through NN. Every star holds one teleporter, and each teleporter has a single fixed destination star. A teleporter carries you in that one direction only.

The galactic art museum runs its exhibitions on these stars. The current exhibition is on star 11. The next exhibition will be held on the star you reach by using teleporters KK times starting from star 11.

The space police learned that a space pirate is after the museum collection. The pirate breaks into the teleporter system and overwrites the destination of the teleporter on star aa so that it points to star bb. The pirate breaks into exactly one star, but the police could not work out the values of aa and bb.

To predict where the next exhibition lands, the police want to know, for each ii, how many pairs (a,b)(a, b) put the next exhibition on star ii.

Given the destination of every teleporter, compute that count for each ii.

Input

The first line contains NN and KK, separated by a space. The galaxy holds NN stars, and the next exhibition is held on the star reached by using teleporters KK times from star 11.

The ii-th of the next NN lines contains an integer AiA_i, meaning that the teleporter on star ii currently sends you to star AiA_i.

Every input satisfies the following conditions.

  • 1N20001 \le N \le 2\,000
  • NK1018N \le K \le 10^{18}
  • 1AiN1 \le A_i \le N

Output

Print NN lines. The ii-th line contains the number of pairs (a,b)(a, b) that put the next exhibition on star ii.

Notes

The destination of the teleporter on star ii may be star ii itself. In that case you stay on star ii no matter how many times you use that teleporter.

Even when the teleporter on star aa already points to star bb, the pirate may still overwrite its destination with star bb. The destination then stays star bb and nothing changes. Such pairs (a,b)(a, b) are still counted.

Pairs with a=ba = b are counted too. All N2N^2 pairs with 1aN1 \le a \le N and 1bN1 \le b \le N are considered, so the NN printed numbers always add up to N2N^2.