Bustling City
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Zhou Kangyang created human civilization.

In April 11451 A.D. human built n cities on Mars. For each i, there is a merchant in the city i and a unidirectional road from the city i to the city a_i.

At the beginning of each year, the merchant in the city i will go along the road to the city a_i.

Let's call a city start to be bustling in the x-th year iff the x-th year is the earliest year in which there are at least k merchants in the city.

Please tell me, in which year each city start to be bustling.

输入描述:

The first line contains two integers n, k ().

The second line contains n integers ().

输出描述:

Print n integers, the i-th of them is the number of the year in which city i start to be bustling. If a city will never be bustling, output '-1'.
示例1

输入

复制
3 2
1 3 2

输出

复制
-1 -1 -1
示例2

输入

复制
5 2
2 3 1 5 5

输出

复制
-1 -1 -1 -1 1
示例3

输入

复制
10 2
1 6 8 5 9 9 3 8 10 5

输出

复制
-1 -1 -1 -1 1 -1 -1 1 1 2