#include #include #include #include #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; template inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;} template inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;} int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector P(N); for (auto& p : P) { cin >> p; --p; } map pos; vector> doubling(32, vector(N)); rep(i, 0, N) { doubling[0][P[i]] = P[i] + 1; pos[P[i]] = i; } rep(i, 1, 32) rep(p, 0, N) { int next_p = P[(pos[p] + doubling[i - 1][p]) % N]; doubling[i][p] = doubling[i - 1][p] + doubling[i - 1][next_p]; } rep(i, 0, N) { int now = P[i]; ll ans = pos[P[i]] + 1; rep(j, 0, 32) { if ((K >> j) & 1) { ans += doubling[j][now]; now = P[(pos[now] + doubling[j][now]) % N]; } } cout << ans << endl; } return 0; }