#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int         long long

#define read(a)		for(auto &z : a) cin >> z;
#define	write(a)	{for(auto &z : a) cout << z << ' ';cout << '\n';}
#define print(a)	cout << a << "\n";
#define all(a) 		a.begin(), a.end()


int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int _ = 1, n, m;
    // cin >> _;

    outer : while(_--) {
        // int a, b;
        // cin >> a >> b;
        // double ans = ((a*1.0)/100.0) * b;
        // cout << fixed << setprecision(9) << ans << "\n";
        cin >> n;
        vector<int> a(n);
        read(a);
        sort(all(a));
        int flag = 1;
        for(int i = 0 ; i < n ; i++) {
            flag &= (a[i] == i+1);
        }
        cout << (flag ? "Yes\n" : "No\n");
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

// #include <atcoder/all>
// using namespace atcoder;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;

const ll INF = 1001001001001001001;
void solve(long long N, std::vector<long long> a, std::vector<long long> t, long long Q, std::vector<long long> x){
    ll mn = -INF;
    ll mx = INF;
    ll bias = 0;
    rep(i, N) {
        if (t[i] == 1) {
            bias += a[i];
            mn += a[i];
            mx += a[i];
        } else if (t[i] == 2) {
            mn = max(mn, a[i]);
            mx = max(mx, a[i]);
        } else {
            mn = min(mn, a[i]);
            mx = min(mx, a[i]);
        }
    }
    rep(i, Q) {
        ll n = x[i] + bias;
        if (mn <= n && n <= mx) {
            cout << n << endl;
        } else if (n < mn) {
            cout << mn << endl;
        } else {
            cout << mx << endl;
        }
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    std::vector<long long> t(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&t[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, std::move(a), std::move(t), Q, std::move(x));
    return 0;
}
