func_code_string: #include <bits/stdc++.h>   using namespace std;   void read(long long &x) { scanf( %lld , &x); }   const long long N = 1000005;   struct city {     long long cnt, id;     bool operator<(const city b) const { return cnt < b.cnt; }   } a[N];   struct que {     long long x, id;     bool operator<(const que b) const { return x < b.x; }   } qq[N];   long long up[N], ans[N];   long long n, m, q;   struct node {     long long l, r, val;     long long cnt, sz, rnd;   } tr[N];   long long tot, rt;   void update(long long rt) {     tr[rt].sz = tr[tr[rt].l].sz + tr[tr[rt].r].sz + tr[rt].cnt;   }   void lturn(long long &rt) {     long long tmp = tr[rt].r;     tr[rt].r = tr[tmp].l;     tr[tmp].l = rt;     tr[tmp].sz = tr[rt].sz;     update(rt);     rt = tmp;   }   void rturn(long long &rt) {     long long tmp = tr[rt].l;     tr[rt].l = tr[tmp].r;     tr[tmp].r = rt;     tr[tmp].sz = tr[rt].sz;     update(rt);     rt = tmp;   }   void Insert(long long &rt, long long x) {     if (!rt) {       rt = ++tot;       tr[rt].sz = tr[rt].cnt = 1;       tr[rt].val = x, tr[rt].rnd = rand();       return;     }     tr[rt].sz++;     if (tr[rt].val == x)       tr[rt].cnt++;     else if (tr[rt].val < x) {       Insert(tr[rt].r, x);       if (tr[tr[rt].r].rnd < tr[rt].rnd) lturn(rt);     } else {       Insert(tr[rt].l, x);       if (tr[tr[rt].l].rnd < tr[rt].rnd) rturn(rt);     }   }   void Delete(long long &rt, long long x) {     if (!rt) return;     if (tr[rt].val == x) {       if (tr[rt].cnt > 1)         tr[rt].cnt--, tr[rt].sz--;       else {         if (tr[rt].l * tr[rt].r == 0)           rt = tr[rt].l + tr[rt].r;         else if (tr[tr[rt].l].rnd < tr[tr[rt].r].rnd)           rturn(rt), Delete(rt, x);         else           lturn(rt), Delete(rt, x);       }     } else if (tr[rt].val < x)       tr[rt].sz--, Delete(tr[rt].r, x);     else       tr[rt].sz--, Delete(tr[rt].l, x);   }   long long findnum(long long rt, long long x) {     if (!rt) return -1;     if (x <= tr[tr[rt].l].sz) return findnum(tr[rt].l, x);     x -= tr[tr[rt].l].sz;     if (x <= tr[rt].cnt) return tr[rt].val;     x -= tr[rt].cnt;     return findnum(tr[rt].r, x);   }   void doit() {     long long kind = 0;     for (long long _ = 1; _ <= q; _++) {       while (kind < m && up[kind] < qq[_].x) {         kind++;         Insert(rt, a[kind].id);       }       long long dis = qq[_].x - up[kind - 1];       dis = (dis - 1) % kind + 1;       ans[qq[_].id] = findnum(rt, dis);     }   }   signed main() {     read(n), read(m), read(q);     for (long long i = 1; i <= m; i++) a[i].id = i;     for (long long i = 1; i <= n; i++) {       long long x;       scanf( %d , &x);       a[x].cnt++;     }     sort(a + 1, a + m + 1);     for (long long i = 1; i <= m; i++) {       up[i] = (long long)i * (a[i + 1].cnt - a[i].cnt);       up[i] += up[i - 1];     }     for (long long _ = 1; _ <= q; _++) {       long long x;       scanf( %lld , &x);       x -= n;       qq[_] = (que){x, _};     }     sort(qq + 1, qq + q + 1);     doit();     for (long long i = 1; i <= q; i++) printf( %lld n , ans[i]);   }   