#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> sum(MAXD + 1, vector(n + 1, 0)); for (int i = 0; i < n; i++) { cin >> a[i]; sum[0][i] = a[i]; } // build for (int d = 0; d < MAXD; d++) { for (int st = 0; st < n; st++) { sum[d + 1][st] = sum[d][st] + sum[d][(st + sum[d][st]) % n]; } } // query for (int st = 0; st < n; st++) { ll ret = st; for (int d = MAXD; d >= 0; d--) { int b = 1 << d; if (k & b) { ret += sum[d][ret % n]; } } cout << ret + 1 << '\n'; } } /* main */ int main(){ solve_dubling(); }