#include int ri() { int n; scanf("%d", &n); return n; } /* TLE */ bool solve(int n, int m, int *a, int q, int *b) { assert(std::is_sorted(a, a + m)); std::vector list[m]; for (int i = 0; i < q; i++) list[b[i]].push_back(i); int pos[q]; for (int i = 0; i < q; i++) pos[i] = -2; // 0-th koma { int cur = a[0]; for (auto i : list[0]) { if (!cur) cur++; else cur--; pos[i] = cur; } } for (int i = 1; i < m; i++) { std::deque > clearance; // {pos, clearance} { // init clearance with slide maximum int head = 0; int cur_pos = a[i]; for (auto j : list[i - 1]) { while (head < (int) list[i].size() && list[i][head] < j) head++, cur_pos++; int cur_clearance = cur_pos - pos[j]; if (cur_clearance <= 0) return false; clearance.push_back({cur_clearance, j}); } } int head = 0; int cur_pos = a[i]; int prev_pos = a[i - 1]; int clearance_minus = 0; for (auto j : list[i - 1]) { while (head < (int) list[i].size() && list[i][head] < j) { if (prev_pos < cur_pos - 1 && std::min_element(clearance.begin(), clearance.end())->first - clearance_minus > 2) { // -1 cur_pos--; clearance_minus += 2; } else cur_pos++; pos[list[i][head]] = cur_pos; head++; } if (clearance.size() && clearance.front().second == j) clearance.pop_front(); prev_pos = pos[j]; } while (head < (int) list[i].size()) { if (prev_pos < cur_pos - 1) cur_pos--; else cur_pos++; pos[list[i][head]] = cur_pos; head++; } } assert(!std::count(pos, pos + q, -2)); for (int i = 0; i < q; i++) if (pos[i] >= n) return false; return true; } int main() { int n = ri(), m = ri(); int a[m]; for (int i = 0; i < m; i++) a[i] = ri() - 1; int q = ri(); int b[q]; for (int i = 0; i < q; i++) b[i] = ri() - 1; std::cout << (solve(n, m, a, q, b) ? "YES" : "NO") << std::endl; return 0; }