import std; void main () { int N, M; readln.read(N, M); auto A = readln.split.to!(int[]); auto dp = new int[][](M + 1, N + 1); int[] ans; BinaryHeap!(Tuple!(int, int)[], "b[1] < a[1]") PQ = []; foreach (bob; 2..N+1) { foreach (d; dp) d[] = int.max; for (int i = 0; bob + i <= N; i++) dp[0][bob + i] = i; for (int i = 0; 1 <= bob - i; i++) dp[0][bob - i] = i; foreach (i; 0..M) { dp[i + 1][] = dp[i][]; // 操作 dp[i + 1][A[i] + 1] = dp[i][A[i]]; dp[i + 1][A[i]] = dp[i][A[i] + 1]; // ズル foreach (j; 0..2) { if (1 <= A[i] - j) PQ.insert(tuple(A[i] - j, dp[i + 1][A[i] - j])); if (A[i] + j <= N) PQ.insert(tuple(A[i] + j, dp[i + 1][A[i] + j])); } while (!PQ.empty) { auto h = PQ.front; PQ.removeFront; int u = h[0]; int cost = h[1]; if (dp[i + 1][u] < cost) continue; dp[i + 1][u] = cost; // 右となり if (u < N) { if (cost + 1 < dp[i + 1][u + 1]) { dp[i + 1][u + 1] = cost + 1; PQ.insert(tuple(u + 1, cost + 1)); } } // 左となり if (0 < u) { if (cost + 1 < dp[i + 1][u - 1]) { dp[i + 1][u - 1] = cost + 1; PQ.insert(tuple(u - 1, cost + 1)); } } } } ans ~= dp[M][1]; } foreach (i, a; ans) { write(a, i == ans.length - 1 ? '\n' : ' '); } } void read (T...) (string S, ref T args) { import std.conv : to; import std.array : split; auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }