intinp(){ char c = getchar(); while(c < '0' || c > '9') c = getchar(); int sum = 0; while(c >= '0' && c <= '9'){ sum = sum * 10 + c - '0'; c = getchar(); } return sum; }
int a[300010], f[300010], g[3000010], ans[300010], h[300010];
intmain(){ int n = inp(); for(int i = 1; i <= n; i++) a[i] = inp(); std::sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++){ f[i] = (a[i] > i) ? 0 : (g[i - a[i]] + 1); h[i] = (a[i] > i) ? (n - a[i] + 1) : (f[i] + n - i); g[i] = std::max(f[i], g[i - 1]); } for(int i = 1; i <= n; i++) if(h[i] > 0) ans[h[i]] = i; for(int i = n - 1; i >= 1; i--) if(ans[i] < ans[i + 1]) ans[i] = ans[i + 1]; int q = inp(); for(int i = 1; i <= q; i++) printf("%d\n", ans[inp()]); }