#include #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } using lint = long long; void solve() { int n, m; std::cin >> n >> m; std::vector ps(n); for (auto& p : ps) std::cin >> p; auto to = vec(31, vec(n, 0)); auto cost = vec(31, vec(n, 0LL)); for (int i = 0; i < n; ++i) { to[0][i] = (i + ps[i]) % n; cost[0][i] = ps[i]; } for (int k = 1; k <= 30; ++k) { for (int i = 0; i < n; ++i) { to[k][i] = to[k - 1][to[k - 1][i]]; cost[k][i] = cost[k - 1][i] + cost[k - 1][to[k - 1][i]]; } } for (int i = 0; i < n; ++i) { int rem = m; lint ans = 0; int v = i; for (int k = 30; k >= 0; --k) { if (rem < (1 << k)) continue; ans += cost[k][v]; v = to[k][v]; rem -= (1 << k); } std::cout << ans + i + 1 << std::endl; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }