// #pragma GCC optimize("O3,unroll-loops") #include // #include using namespace std; #if __cplusplus >= 202002L using namespace numbers; #endif int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); int n, m; cin >> n >> m; vector> gift(m + 1, vector(n)); vector> pos(m + 1, vector(n)); iota(gift[0].begin(), gift[0].end(), 0); iota(pos[0].begin(), pos[0].end(), 0); for(auto i = 0; i < m; ++ i){ gift[i + 1] = gift[i]; int x; cin >> x, -- x; swap(gift[i + 1][x], gift[i + 1][x + 1]); for(auto j = 0; j < n; ++ j){ pos[i + 1][gift[i + 1][j]] = j; } } int obj = gift[m][0]; for(auto x = 1; x < n; ++ x){ int res = numeric_limits::max(); for(auto step = 0; step <= m; ++ step){ res = min(res, abs(pos[step][obj] - pos[step][x])); } cout << res << " "; } cout << "\n"; return 0; } /* */