boolcheckmin(int x){ for (int i = 1; i <= x; ++i) if (b[n - x + i] < a[i]) return0; return1; }
boolcheckmax(int x){ for (int i = 1; i <= x; ++i) if (b[i] > a[n - x + i]) return0; return1; }
voidwork(){ cin >> n; fill(use + 1, use + 2 * n + 1, 0); for (int i = 1; i <= n; ++i) cin >> a[i], use[a[i]] = 1; for (int i = 1, j = 0; i <= 2 * n; ++i) if (!use[i]) b[++j] = i; int l = 0, r = n, mid, rans, lans; while (l <= r) { mid = l + r >> 1; if (checkmax(mid)) rans = mid, l = mid + 1; else r = mid - 1; } l = 0; r = n; while (l <= r) { mid = l + r >> 1; if (checkmin(mid)) lans = mid, l = mid + 1; else r = mid - 1; } lans = n - lans; cout << rans - lans + 1 << "\n"; }