#include using namespace std; int main(){ int N, Q; cin >> N >> Q; vector A(Q); for (int i = 0; i < Q; i++){ cin >> A[i]; A[i]--; } vector B(Q); for (int i = 0; i < Q; i++){ cin >> B[i]; B[i]--; } for (int i = 0; i < Q; i++){ if (A[i] > B[i]){ swap(A[i], B[i]); } } vector> E(Q * 2 + 2); for (int i = 0; i < Q; i++){ if (A[i] == 0){ E[Q * 2].push_back(i * 2); } if (B[i] == 0){ E[Q * 2].push_back(i * 2 + 1); } if (A[i] == N - 1){ E[i * 2].push_back(Q * 2 + 1); } if (B[i] == N - 1){ E[i * 2 + 1].push_back(Q * 2 + 1); } if (abs(A[i] - B[i]) == 1){ E[i * 2].push_back(i * 2 + 1); E[i * 2 + 1].push_back(i * 2); } if (i > 0){ if (A[i] == A[i - 1]){ E[i * 2 - 2].push_back(i * 2); E[i * 2].push_back(i * 2 - 2); } if (A[i] == B[i - 1]){ E[i * 2 - 1].push_back(i * 2); E[i * 2].push_back(i * 2 - 1); } if (B[i] == A[i - 1]){ E[i * 2 - 2].push_back(i * 2 + 1); E[i * 2 + 1].push_back(i * 2 - 2); } if (B[i] == B[i - 1]){ E[i * 2 - 1].push_back(i * 2 + 1); E[i * 2 + 1].push_back(i * 2 - 1); } } } vector used(Q * 2 + 2, false); used[Q * 2] = true; queue q; q.push(Q * 2); while (!q.empty()){ int v = q.front(); q.pop(); for (int w : E[v]){ if (!used[w]){ used[w] = true; q.push(w); } } } if (used[Q * 2 + 1]){ cout << "NO" << endl; } else { vector L(Q, 0), R(Q, N - 1); for (int i = Q - 1; i >= 0; i--){ if (i < Q - 1){ L[i] = max(L[i + 1] - 1, 0); R[i] = min(R[i + 1] + 1, N - 1); } if (A[i] == L[i]){ L[i]++; } if (B[i] == L[i]){ L[i]++; } if (B[i] == R[i]){ R[i]--; } if (A[i] == R[i]){ R[i]--; } } cout << "YES" << endl; int S; for (int i = L[0] - 1; i <= R[0] + 1; i++){ if (0 <= i && i < N && i != A[0] && i != B[0]){ S = i; } } cout << S + 1 << endl; for (int i = 0; i < Q; i++){ int K = -1; for (int j = S - 1; j <= S + 1; j++){ if (L[i] <= j && j <= R[i] && j != A[i] && j != B[i]){ K = j; break; } } assert(K != -1); S = K; cout << K + 1 << endl; } } }