#include using namespace std; /* typedef */ typedef long long ll; typedef pair pii; /* constant */ const int INF = 1 << 30; const ll LINF = 1LL << 61; const int NIL = -1; const int MAX = 10000; const int MOD = 1000000007; const double pi = 3.141592653589; /* global variables */ /* function */ void solve_dubling() { int n, k; cin >> n >> k; int MAXD = log2(1e+9 + 5); // init vector a(n + 1); vector> to(MAXD + 1, vector(n + 1, -1)); vector> sum(MAXD + 1, vector(n + 1, 0)); for (int i = 1; i <= n; i++) { cin >> a[i]; to[0][i] = (i + a[i]) % n; if (to[0][i] == 0) to[0][i] = n; sum[0][i] = a[i]; } // build for (int d = 0; d < MAXD; d++) { for (int i = 1; i <= n; i++) { to[d + 1][i] = (to[d][i] + to[d][to[d][i]]) % n; if (to[d + 1][i] == 0) to[d + 1][i] = n; sum[d + 1][i] = sum[d][i] + sum[d][to[d][i]]; } } // query for (int st = 1; st <= n; st++) { int cur = st; ll ret = 0; for (int d = MAXD; d >= 0; d--) { int b = 1 << d; if (k & b) { ret += sum[d][cur]; cur = to[d][cur]; } } cout << ret + st << '\n'; } } /* main */ int main(){ solve_dubling(); }