malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ull = unsigned long long;   using ll = long long;   using ld = long double;   using ii = pair<int, int>;   using vi = vector<int>;   template <class T>   T abs(T x) {     return x > 0 ? x : -x;   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     vector<pair<int, int>> v(n);     int cur;     for (int i = 0; i < n; ++i) {       cin >> cur;       v[i] = make_pair(cur, i + 1);     }     sort(v.begin() + 1, v.end(), greater<pair<int, int>>());     queue<int> q;     vector<char> ch(n, false);     ch[0] = true;     q.push(0);     int pos = 1;     vector<pair<int, int>> ans;     while (!q.empty()) {       cur = q.front();       for (int i = 0; i < v[cur].first; ++i)         if (pos < n) {           q.push(pos);           ans.push_back(make_pair(v[cur].second, v[pos].second));           ++pos;         }       q.pop();     }     if (pos != n)       cout << -1 << endl;     else {       cout << ans.size() << endl;       for (int i = 0; i < ans.size(); ++i)         cout << ans[i].first <<     << ans[i].second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5, INF = 1e9 + 7;   long long ans[N];   int main() {     long long p, k;     cin >> p >> k;     long long tmp = -k;     long long idx = 0;     while (p != 0) {       long long rem = p % tmp;       p /= tmp;       if (rem < 0) rem += k, p++;       ans[idx] = rem;       idx++;     }     cout << idx << endl;     for (int i = 0; i < idx; i++) {       cout << ans[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[200002], even[200002], odd[200002];   int main() {     int n;     cin >> n;     cin >> a[1];     for (int i = 2; i <= n; i++) {       cin >> a[i];       if (i & 1) {         even[i] = even[i - 1] + a[i - 1];         odd[i] = odd[i - 1];       } else {         even[i] = even[i - 1];         odd[i] = odd[i - 1] + a[i - 1];       }     }     if ((n + 1) & 1) {       even[n + 1] = even[n] + a[n];       odd[n + 1] = odd[n];     } else {       even[n + 1] = even[n];       odd[n + 1] = odd[n] + a[n];     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int x, y;       if (i & 1) {         x = odd[i] + even[n + 1] - even[i];         y = even[i] + odd[n + 1] - odd[i + 1];       } else {         x = odd[i] + even[n + 1] - even[i + 1];         y = even[i] + odd[n + 1] - odd[i];       }       if (x == y) ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100000 + 7;   const int M = 300;   const int mod = 999983;   const int inf = 1e9 + 7;   const double pi = acos(-1);   const int maxn = N * 2;   const double PI = acos(-1);   int rev(int x) {     int nw = 0;     while (x) {       nw = nw * 10 + (x % 10);       x /= 10;     }     return nw;   }   int gcd(int u, int v) { return (u == 0) ? v : gcd(v % u, u); }   map<pair<int, int>, int> st;   map<pair<int, int>, int> pre;   int n, m, w;   pair<int, int> get(int u) {     int v = rev(u);     int d = gcd(u, v);     u /= d;     v /= d;     return make_pair(u, v);   }   void solve() {     cin >> n >> m >> w;     for (int i = 1; i <= m; i++) {       st[get(i)]++;     }     long long ans = (long long)inf * inf;     long long cur = 0;     int l = -1, r = -1;     for (int i = 1; i <= n; i++) {       int u = i, v = rev(i);       int d = gcd(u, v);       u /= d;       v /= d;       pre[make_pair(v, u)]++;       cur += st[make_pair(v, u)];       while (m > 0 && cur - pre[get(m)] >= w) {         cur -= pre[get(m)];         st[get(m)]--;         m--;       }       if (cur >= w && (long long)i * m < ans) {         l = i;         r = m;         ans = min(ans, (long long)l * r);       }     }     if (l == -1)       puts( -1 );     else       cout << l <<     << r;   }   int main() {     int T = 1;     for (int i = (1); i < (T + 1); i++) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   struct pp {     long long cost;     bool operator<(const pp &temp) const { return cost < temp.cost; }   };   map<pp, int> hs;   int n, c[2];   pp now;   map<pp, int> solve(int n) {     map<pp, int> ret, ms;     map<pp, int>::iterator it;     pp u, now;     ret.clear();     if (n <= 3) {       now.cost = c[0];       ret[now]++;       now.cost = c[1];       ret[now]++;     }     if (n == 2) return ret;     if (n > 3) ret = solve(n / 2);     int nc = 0, vl;     while (n > 3 && nc < n / 2) {       it = ret.begin();       if (nc + it->second >= n / 2)         vl = n / 2 - nc;       else         vl = it->second;       u = it->first;       ret[u] -= vl;       if (ret[u] == 0) ret.erase(u);       nc += vl;       now = u;       now.cost += c[0];       ret[now] += vl;       now = u;       now.cost += c[1];       ret[now] += vl;     }     if (n & 1) {       it = ret.begin();       u = it->first;       ret[u]--;       if (ret[u] == 0) ret.erase(u);       now = u;       now.cost += c[0];       ret[now]++;       now = u;       now.cost += c[1];       ret[now]++;     }     return ret;   }   int main() {     scanf( %d%d%d , &n, &c[0], &c[1]);     if (c[0] == 0 || c[1] == 0) {       printf( %lld n , (long long)(n - 1) * (long long)max(c[0], c[1]));       return 0;     }     hs = solve(n);     map<pp, int>::iterator it;     pp u;     long long ans = 0;     for (it = hs.begin(); it != hs.end(); it++) {       u = it->first;       ans += (long long)u.cost * (long long)hs[u];     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     char a[10000], b[10000];     int l, i, j, k;     k = j = 0;     gets(a);     gets(b);     l = strlen(a);     for (i = 0; i < l; i += 2) {       if ((a[i] ==  8  && b[i] ==  [ ) || (a[i] ==  [  && b[i] ==  ( ) ||           (a[i] ==  (  && b[i] ==  8 ))         j++;       else if ((a[i] ==  [  && b[i] ==  8 ) || (a[i] ==  (  && b[i] ==  [ ) ||                (a[i] ==  8  && b[i] ==  ( ))         k++;     }     if (j > k)       puts( TEAM 1 WINS );     else if (j < k)       puts( TEAM 2 WINS );     else       puts( TIE );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &k);     vector<int> v;     for (int(i) = 0; (i) < (int)(n); (i)++) {       int a;       scanf( %d , &a);       v.push_back(a);     }     sort((v).begin(), (v).end());     int num = m;     if (num <= k)       cout <<  0  << endl;     else {       int ans = 0;       for (int pos = v.size() - 1; pos >= 0; pos--) {         if (k >= m) break;         k = k + v[pos] - 1;         ans++;       }       if (k >= m)         cout << ans << endl;       else         cout <<  -1  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 7;   int n;   int a[MAXN], r[MAXN], x[MAXN], vt[MAXN];   set<int> tset;   int main() {     cin >> n;     int tmax = 0;     for (int i = 0; i < n; i++) {       cin >> a[i];       vt[a[i]] = i;       if (a[i] > tmax) {         r[i] = 1;         tmax = a[i];       }     }     tset.insert(a[0]);     x[0] -= r[0];     for (int j = 1; j < n; j++) {       tset.insert(a[j]);       set<int>::iterator it = tset.end();       it--;       it--;       set<int>::iterator it2 = tset.end();       it2--;       if (*it == a[j]) {         x[vt[*it2]]++;       }       x[j] -= r[j];     }     int ans = a[0];     tmax = x[0];     for (int i = 0; i < n; i++) {       if (x[i] > tmax) {         tmax = x[i];         ans = a[i];       } else if (x[i] == tmax) {         ans = min(ans, a[i]);       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const ll inf = 1e18;   const int N = 2 * 1e5 + 10;   ll res;   ll a[N];   void solve() {     ll n, k;     cin >> n >> k;     if (n == 1) {       cout << 0 <<   n ;       return;     }     if (n == 2) {       cout << k <<   n ;       return;     }     cout << 2 * k <<   n ;   }   int main(int argc, char const *argv[]) {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     ll t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out << p.first <<     << p.second;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& arr) {     for (auto& i : arr) {       in >> i;     }     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> arr) {     for (int64_t i = 0; i < (int64_t)arr.size() - 1; ++i) out << arr[i] <<    ;     if (arr.size()) out << arr.back();     out <<   n ;     return out;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int64_t n;     cin >> n;     vector<int64_t> v(n);     cin >> v;     vector<int64_t> t(n);     cin >> t;     vector<int64_t> preft(n + 1);     for (int64_t i = 0; i < n; ++i) {       preft[i + 1] = preft[i] + t[i];     }     vector<int64_t> bal(n + 1);     vector<int64_t> pls(n);     for (int64_t i = 0; i < n; ++i) {       if (preft.back() - preft[i] <= v[i]) {         bal[i] += 1;         bal[n] -= 1;         continue;       }       if (t[i] > v[i]) {         pls[i] += v[i];         continue;       }       int64_t l = i, r = n;       while (r - l > 1) {         int64_t m = (r + l) / 2;         if (v[i] > preft[m] - preft[i]) {           l = m;         } else {           r = m;         }       }       bal[i] += 1;       bal[l] -= 1;       pls[l] += v[i] - (preft[l] - preft[i]);     }     for (int64_t i = 1; i < n; ++i) {       bal[i] += bal[i - 1];     }     for (int64_t i = 0; i < n; ++i) {       cout << bal[i] * t[i] + pls[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b;     scanf( %d %d , &a, &b);     if (a >= b) {       printf( %d %d , b, (a - b) / 2);     } else if (b > a) {       printf( %d %d , a, (b - a) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 2147483647;   int main() {     string st;     int i;     cin >> st;     for (i = 0; i < (int)st.size(); ++i) {       if (st[i] ==  0 ) {         {           st.erase(i, 1);           break;         }       } else {         if (i == (int)st.size() - 1) {           st.erase(i, 1);         }       }     }     cout << st << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[100000];     for (int i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     for (int i = 0; i < n - 1; i++) {       int j = 1;       while (i + j * 2 < n) j *= 2;       ans += a[i];       a[i + j] += a[i];       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pos[109], npos[109];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; ++i) pos[i] = i;     for (int i = 1; i <= k; ++i) {       int cnt;       cin >> cnt;       int el = (1 + cnt) % n;       if (el == 0) el = n;       cout << pos[el] <<    ;       int nw = 0, st = (el + 1) % n;       if (st == 0) st = n;       for (int j = 1; j < n; ++j) {         npos[++nw] = pos[st];         ++st;         st %= n;         if (st == 0) st = n;       }       --n;       for (int j = 1; j <= n; ++j) pos[j] = npos[j];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n = 0, k = 0;   bool ip[100010][32];   int main() {     n = 0, k = 0;     cin >> n >> k;     for (int i = 0; i < n; i++) {       int a = 0, b = 0, c = 0, d = 0;       scanf( %d.%d.%d.%d , &a, &b, &c, &d);       int l = 31;       while (d) {         ip[i][l--] = d % 2;         d /= 2;       }       l = 23;       while (c) {         ip[i][l--] = c % 2;         c /= 2;       }       l = 15;       while (b) {         ip[i][l--] = b % 2;         b /= 2;       }       l = 7;       while (a) {         ip[i][l--] = a % 2;         a /= 2;       }     }     set<string> net;     int masklen = 1;     bool mask[32];     for (int i = 0; i < 32; i++) mask[i] = 0;     while (net.size() != k && masklen <= 32) {       net.clear();       mask[masklen - 1] = 1;       string netip =  00000000000000000000000000000000 ;       for (int j = 0; j < n; j++) {         for (int i = 0; i < 32; i++) {           netip[i] = mask[i] && ip[j][i];         }         net.insert(netip);       }       masklen++;     }     if (net.size() == k) {       if (masklen != 33) {         int i;         for (i = 0; i < (masklen - 1) / 8; i++) cout <<  255. ;         int p = 0;         for (int e = 0; e < (masklen - 1) % 8; e++) {           p += (1 << (7 - e));         }         cout << p;         if (i == 3) return 0;         for (; i < 3; i++) cout <<  .0 ;       } else         cout <<  255.255.255.255 ;     } else       cout <<  -1 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 20;   const int MM = 1e5 + 5;   int A[MM], n, m;   char S[MM];   long long F[1 << MX], G[1 << MX];   void fwt(long long F[], int n) {     for (int i = 0; i < n; i++) {       for (int s = 0; s < 1 << n; s++) {         if (s >> i & 1) continue;         long long l = F[s], r = F[s | (1 << i)];         F[s] = l + r;         F[s | (1 << i)] = l - r;       }     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %s , S);       for (int j = 0; j < m; j++) {         A[j] = A[j] << 1 | (S[j] -  0 );       }     }     for (int i = 0; i < m; i++) {       F[A[i]] += 1;     }     for (int i = 0; i < 1 << n; i++) {       int t = __builtin_popcount(i);       G[i] = min(t, n - t);     }     fwt(F, n);     fwt(G, n);     for (int i = 0; i < 1 << n; i++) {       F[i] = F[i] * G[i];     }     fwt(F, n);     int ans = n * m, div = 1 << n;     for (int i = 0; i < 1 << n; i++) {       ans = min(ans, (int)(F[i] / div));     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long T;     cin >> T;     while (T--) {       long long n;       cin >> n;       if (n == 2) {         cout << 2 << endl;         continue;       }       long long tmp = n;       long long cnt = 0;       while (tmp != 0) {         long long a = tmp % 2;         if (a == 1) cnt++;         tmp /= 2;       }       long long ans = 1;       for (int i = 0; i < cnt; i++) {         ans *= 2;       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int N, M;     int64_t K;     cin >> N >> M >> K;     vector<int> A(N);     for (int i = 0; i < N; i++) cin >> A[i];     int64_t ret = 0;     for (int m = 0; m < M; m++) {       vector<int64_t> B(N);       for (int i = 0; i < N; i++) {         B[i] = A[i];         if (i % M == m) B[i] -= K;       }       if (!(m < N)) continue;       int64_t x = B[m];       int64_t best = x;       for (int i = m + 1; i < N; i++) {         if (i % M == m && x < 0)           x = B[i];         else           x += B[i];         best = max(x, best);       }       ret = max(best, ret);     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     int i, j;     vector<int> vec1, vec2, vec3;     vec1.push_back(0);     vec2.push_back(1);     vec1.push_back(1);     n--;     for (j = 0; j < n; j++) {       vec3.push_back(0);       for (i = 0; i < vec1.size(); i++) {         vec3.push_back(vec1[i] % 2);       }       for (i = 0; i < vec2.size(); i++) {         vec3[i] += vec2[i];         vec3[i] %= 2;       }       vec2.clear();       for (i = 0; i < vec1.size(); i++) {         vec2.push_back(vec1[i] % 2);       }       vec1.clear();       for (i = 0; i < vec3.size(); i++) {         vec1.push_back(vec3[i] % 2);       }       vec3.clear();     }     cout << vec1.size() - 1 << endl;     for (i = 0; i < vec1.size(); i++) {       cout << vec1[i] <<    ;     }     cout << endl;     cout << vec2.size() - 1 << endl;     for (i = 0; i < vec2.size(); i++) {       cout << vec2[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int q[n], ans[n], freq[100002];       fill(ans, ans + n, -1);       fill(freq, freq + 100002, -1);       for (int i = 0; i < n; i++) {         cin >> q[i];         freq[q[i]] = 1;       }       ans[0] = q[0];       for (int i = 1; i < n; i++) {         if (q[i] != q[i - 1]) ans[i] = q[i];       }       vector<int> v;       for (int i = 1; i <= n; i++) {         if (freq[i] == -1) v.push_back(i);       }       int c = 0;       for (int i = 0; i < n; i++) {         if (ans[i] == -1) {           ans[i] = v[c];           c++;         }       }       int cq[n];       bool flag = true;       cq[0] = ans[0];       for (int i = 1; i < n; i++) {         cq[i] = max(ans[i], cq[i - 1]);         if (cq[i] != q[i]) {           flag = false;           break;         }       }       if (flag) {         for (int i = 0; i < n; i++) cout << ans[i] <<    ;       } else         cout << -1;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, v, e, x, y, a[300], b[300], d[300][300], S, X[1 << 20],       Y[1 << 20], D[1 << 20];   void m(int x, int y, int f) {     if (d[x][y] == 1) {       if (f) {         a[y] -= f, a[x] += f, X[S] = y, Y[S] = x, D[S] = f;         S++;       };     } else {       int z;       for (z = 0; z < n; z++)         if (d[x][z] == 1 && 1 + d[z][y] == d[x][y]) break;       if (a[z] >= f) {         if (f) {           a[z] -= f, a[x] += f, X[S] = z, Y[S] = x, D[S] = f;           S++;         };         m(z, y, f);       } else {         int t = a[z];         if (t) {           a[z] -= t, a[x] += t, X[S] = z, Y[S] = x, D[S] = t;           S++;         };         f -= t;         m(z, y, t + f);         if (f) {           a[z] -= f, a[x] += f, X[S] = z, Y[S] = x, D[S] = f;           S++;         };       }     }   }   int main() {     cin >> n >> v >> e;     for (i = 0; i < n; i++) cin >> a[i];     for (i = 0; i < n; i++) cin >> b[i];     memset(d, 63, sizeof d);     for (i = 0; i < e; i++) {       cin >> x >> y;       x--, y--;       d[x][y] = d[y][x] = 1;     }     for (k = 0; k < n; k++)       for (i = 0; i < n; i++)         for (j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     for (i = 0; i < n; i++)       for (j = 0; j < n; j++)         if (d[i][j] < n && a[i] < b[i] && a[j] > b[j])           m(i, j, min(b[i] - a[i], a[j] - b[j]));     for (i = 0; i < n; i++)       if (a[i] != b[i]) {         cout <<  NO n ;         return 0;       }     cout << S <<   n ;     for (i = 0; i < S; i++)       cout << X[i] + 1 <<     << Y[i] + 1 <<     << D[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct bigint {     int len, num[70];     bigint(int m = 0) {       memset(num, 0, sizeof num);       len = 1;       num[1] = m;     }     bigint operator+(const bigint &b) {       bigint c;       c.len = max(len, b.len);       int x = 0, y = 0;       for (int i = 1; i <= c.len; i++) {         y = x;         if (i <= len) y += num[i];         if (i <= b.len) y += b.num[i];         c.num[i] = y % 1000000000;         x = y / 1000000000;       }       if (x) c.len++, c.num[c.len] = x;       return c;     }     void operator=(const bigint &b) {       len = b.len;       for (int i = 1; i <= len; i++) num[i] = b.num[i];     }     bool operator<(const bigint &b) {       if (len != b.len) return len < b.len;       for (int i = len; i >= 1; i--) {         if (num[i] != b.num[i]) return num[i] < b.num[i];       }       return 0;     }     void print() {       printf( %d , num[len]);       for (int i = len - 1; i; i--) printf( %09d , num[i]);       puts(  );     }   } f[5050], ex[2020];   inline bigint max(bigint a, bigint b) { return a < b ? b : a; }   int n, x, last[2020];   char s[11];   int main() {     ex[0] = bigint(1);     for (int i = 1; i <= 2000; i++) ex[i] = ex[i - 1] + ex[i - 1];     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s %d , s, &x);       f[i] = f[i - 1];       if (s[0] ==  w )         last[x] = i;       else if (last[x]) {         f[i] = max(f[i], f[last[x] - 1] + ex[x]);       }     }     f[n].print();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, a;   vector<int> v, ck;   vector<int> has(1000002, 0);   bool check(int x) {     for (int i = 0; i < x; ++i) {       ck[i] = 0;     }     int res = 0;     for (int i = 0; i < n; ++i) {       int d = v[i] % x;       if (ck[d]) res++;       ck[d]++;     }     return res <= k;   }   int del(int x) {     if (x < 0) x = -x;     has[x]++;   }   int main() {     cin >> n >> k;     v.resize(n + 2, 0);     ck.resize(1000000, 0);     for (int i = 0; i < n; ++i) {       cin >> a;       v[i] = a;     }     for (int i = 0; i < n; ++i) {       for (int j = i + 1; j < n; ++j) {         int d = abs(v[i] - v[j]);         has[d]++;       }     }     for (int i = n - k; i < 1000000; ++i) {       int s = 0;       for (int x = i; x < 1000000; x += i) {         s += has[x];       }       if (s <= (k * (k + 1) / 2) && check(i)) {         cout << i << endl;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     map<vector<int>, int> H;     for (int i = 0; i < 1 << 18; i++) {       vector<int> b(n);       for (int j = 0; j < n; j++) {         b[j] = __builtin_popcount((a[j] >> 12) ^ i);       }       H[b] = i;     }     for (int i = 0; i < 1 << 12; i++) {       vector<int> b(n);       for (int j = 0; j < n; j++) {         b[j] = __builtin_popcount((a[j] & ((1 << 12) - 1)) ^ i);       }       int st = *max_element(b.begin(), b.end());       for (int add = 0; add <= 30 - st; add++) {         vector<int> c(n);         for (int j = 0; j < n; j++) {           c[j] = st + add - b[j];         }         if (H.count(c)) {           cout << ((H[c] << 12) | i) << endl;           return 0;         }       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5005, P = 1e9 + 7;   int ad(int k1, int k2) { return k1 += k2 - P, k1 += k1 >> 31 & P; }   int su(int k1, int k2) { return k1 -= k2, k1 += k1 >> 31 & P; }   int mu(int k1, int k2) { return 1LL * k1 * k2 % P; }   void uad(int& k1, int k2) { k1 += k2 - P, k1 += k1 >> 31 & P; }   void usu(int& k1, int k2) { k1 -= k2, k1 += k1 >> 31 & P; }   template <typename... T>   int ad(int k1, T... k2) {     return ad(k1, ad(k2...));   }   template <typename... T>   void uad(int& k1, T... k2) {     return uad(k1, ad(k2...));   }   template <typename... T>   void usu(int& k1, T... k2) {     return usu(k1, ad(k2...));   }   template <typename... T>   int mu(int k1, T... k2) {     return mu(k1, mu(k2...));   }   int po(int k1, int k2) {     int k3 = 1;     for (; k2; k2 >>= 1, k1 = mu(k1, k1))       if (k2 & 1) k3 = mu(k3, k1);     return k3;   }   int n, K, a[N], f[N];   int main() {     scanf( %d%d , &n, &K);     for (int i = (1); i <= (n); ++i) scanf( %d , &a[i]);     f[0] = 1;     for (int i = (1); i <= (n); ++i) {       for (int j = (N - 1); j >= (0); --j) {         f[j] = su(mu(f[j], a[i]), j ? f[j - 1] : 0);       }     }     int down = 1, pw = 1, in = po(n, P - 2), ans = 0;     for (int i = (0); i <= (N - 1); ++i) {       if (i) down = mu(down, K - i + 1), pw = mu(pw, in);       ans = ad(ans, mu(down, pw, f[i]));     }     printf( %d n , su(f[0], ans));     return 0;   }