#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    vector<int> a(n+1), b(n+1);
    for (int i = 1; i <= n; i++) {
        a[i] = i;
    }
    vector<long long> ans(n+1);
    while(k--) {
        for (int i = 1; i <= n; i++) {
            b[i] = a[p[i]];
            ans[b[i]] += i;
        }
        swap(a, b);
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << " ";
    }
}