#pragma GCC target("avx2") #pragma GCC optimize("Ofast,unroll-loops") #include void naive(int L, int V[], long long N, int ans[]) { int i, j, k, x; for (i = 2, ans[1] = V[1]; i <= L; i++) ans[i] = 0; for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) { if (j > L) j = 1; if (k > L) k = 1; x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k]; ans[j] -= x; ans[k] += x; for (x = 1; x <= L; x++) printf("%d ", ans[x]); printf("\n"); } } void naive2(int L, int V[], long long N, int ans[]) { int i, j, k, x, prev[200001]; for (i = 2, ans[1] = V[1]; i <= L; i++) ans[i] = 0; for (i = 1; i <= L; i++) prev[i] = 0; for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) { if (j > L) j = 1; if (k > L) k = 1; if (j == 1) { for (x = 1; x <= L; x++) if (ans[x] != prev[x]) break; if (x <= L) { for (x = 1; x <= L; x++) prev[x] = ans[x]; } else break; } x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k]; ans[j] -= x; ans[k] += x; } if (i < N) { N = (N - i) % L; for (i = 0, j = 1, k = 2; i < N; i++, j++, k++) { if (j > L) j = 1; if (k > L) k = 1; x = (ans[j] <= V[k] - ans[k])? ans[j]: V[k] - ans[k]; ans[j] -= x; ans[k] += x; } } } int main() { int i, L, V[200001]; long long N; scanf("%d", &L); for (i = 1; i <= L; i++) scanf("%d", &(V[i])); scanf("%lld", &N); int ans[200001]; naive2(L, V, N, ans); for (i = 1; i <= L; i++) printf("%d ", ans[i]); printf("\n"); fflush(stdout); return 0; }