func_code_string: #include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimization( O3 )   #pragma GCC optimization( unroll-loops )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = (1LL << 62);   const int inf = (1 << 30);   const long long nmax = 5e5 + 50;   const int mod = 1e9 + 7;   using namespace std;   int n, m, i, x, a[nmax], p[nmax], q, st[4 * nmax], ans[nmax], j;   long long nr[nmax], k;   vector<int> b[nmax];   vector<pair<int, int> > qr[nmax];   pair<int, int> pr;   pair<int, int> fnd(long long y) {     int l = 0, r = n, mid, rs = n, i;     while (l <= r) {       mid = (l + r) / 2;       if (nr[mid] > y)         rs = mid, r = mid - 1;       else         l = mid + 1;     }     for (i = max(rs - 1, 0); i <= min(rs + 1, n); i++)       if (nr[i] >= y) break;     rs = i;     if (rs <= n) {       if (rs) y -= nr[rs - 1];       return make_pair(rs, y);     } else {       y -= nr[n];       if (y % m == 0) return make_pair(m, -1);       return make_pair(y % m, -1);     }   }   void upd(int nod, int l, int r, int p) {     if (l == r) {       st[nod] = 1;       return;     }     int mid = (l + r) / 2;     if (p <= mid)       upd(2 * nod, l, mid, p);     else       upd(2 * nod + 1, mid + 1, r, p);     st[nod] = st[2 * nod] + st[2 * nod + 1];   }   int qry(int nod, int l, int r, int z) {     if (z > st[nod]) return -1;     if (l == r) return l;     int mid = (l + r) / 2;     if (st[nod * 2] >= z) return qry(2 * nod, l, mid, z);     return qry(2 * nod + 1, mid + 1, r, z - st[nod * 2]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (i = 1; i <= n; i++) {       cin >> x;       a[x]++;     }     for (i = 1; i <= m; i++) {       nr[a[i]]++;       b[a[i]].push_back(i);     }     p[0] = b[0].size();     for (i = 1; i <= n; i++) p[i] = p[i - 1] + b[i].size();     for (i = 1; i <= n; i++) nr[i] += nr[i - 1];     for (i = 1; i <= n; i++) nr[i] += nr[i - 1];     for (i = 1; i <= q; i++) {       cin >> k;       k -= n;       pr = fnd(k);       if (pr.second == -1)         ans[i] = pr.first;       else         qr[pr.first].push_back(make_pair(pr.second, i));     }     for (i = 0; i <= n; i++) {       for (j = 0; j < b[i].size(); j++) upd(1, 1, m, b[i][j]);       for (j = 0; j < qr[i].size(); j++)         ans[qr[i][j].second] = qry(1, 1, m, qr[i][j].first);     }     for (i = 1; i <= q; i++) cout << ans[i] <<   n ;     return 0;   }   