import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } void main() { try { for (; ; ) { const N = readInt(); const Q = readInt(); auto A = new int[Q]; foreach (i; 0 .. Q) { A[i] = readInt(); } auto B = new int[Q]; foreach (i; 0 .. Q) { B[i] = readInt(); } alias Il = Tuple!(int, "l", int, "r"); auto dp = new Il[][Q + 1]; dp[Q] = [Il(1, N)]; foreach_reverse (i; 0 .. Q) { auto crt = dp[i + 1].dup; foreach (x; [A[i], B[i]]) { Il[] nxt; foreach (p; crt) { if (p.l <= x && x <= p.r) { if (p.l < x) nxt ~= Il(p.l, x - 1); if (x < p.r) nxt ~= Il(x + 1, p.r); } else { nxt ~= p; } } crt = nxt; } foreach (ref p; crt) { chmax(--p.l, 1); chmin(++p.r, N); } { Il[] nxt; foreach (p; crt) { if (!nxt.empty && nxt[$ - 1].r + 1 >= p.l) { nxt[$ - 1].r = p.r; } else { nxt ~= p; } } crt = nxt; } dp[i] = crt; } debug { foreach (i; 0 .. Q) { writeln(i, ": ", dp[i]); } } if (!dp[0].empty) { writeln("YES"); int x = dp[0][0].l; writeln(x); foreach (i; 0 .. Q) { foreach (y; x - 1 .. x + 1 + 1) { if (y != A[i] && y != B[i] && dp[i + 1].any!(p => (p.l <= y && y <= p.r))) { x = y; writeln(x); goto found; } } assert(false); found: } } else { writeln("NO"); } } } catch (EOFException e) { } }