malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long vectorMult(pair<int, int> a, pair<int, int> b, pair<int, int> c) {     return (c.first - a.first) * 1ll * (b.second - a.second) -            (c.second - a.second) * 1ll * (b.first - a.first);   }   bool cmp(pair<int, int> a, pair<int, int> b) {     return a.first < b.first || a.first == b.first && a.second < b.second;   }   vector<pair<int, int> > convex_hull(vector<pair<int, int> > t) {     if (t.size() == 1) return t;     sort(t.begin(), t.end(), cmp);     vector<pair<int, int> > up, down;     auto l = t[0];     auto r = t.back();     up.push_back(t[0]);     down.push_back(t[0]);     for (int i = 1; i < t.size(); i++) {       if (vectorMult(l, r, t[i]) <= 0) {         while (up.size() >= 2 &&                vectorMult(up[up.size() - 2], up.back(), t[i]) <= 0) {           up.pop_back();         }         up.push_back(t[i]);       }       if (vectorMult(l, r, t[i]) >= 0) {         while (down.size() >= 2 &&                vectorMult(down[down.size() - 2], down.back(), t[i]) >= 0) {           down.pop_back();         }         down.push_back(t[i]);       }     }     up.insert(up.end(), down.rbegin() + 1, down.rend() - 1);     if (up.size() == 2 && up[0] == up[1]) up.pop_back();     return up;   }   int main() {     ios_base::sync_with_stdio(0);     while (true) {       int n;       cin >> n;       if (n == 0) break;       vector<string> v;       for (int i = 0; i < n; i++) {         string x;         cin >> x;         v.push_back(x);       }       for (int i = 0; i < n - i - 1; i++) {         swap(v[i], v[n - i - 1]);       }       vector<pair<int, int> > t;       for (int i = 0; i < n - 1; i++) {         for (int j = 0; j < n - 1; j++) {           if (v[i][j] >  0  && v[i][j + 1] >  0  && v[i + 1][j] >  0  &&               v[i + 1][j + 1] >  0 ) {             t.push_back(make_pair(j + 1, i + 1));           }         }       }       t = convex_hull(t);       int mn = 0;       for (int i = 1; i < t.size(); i++)         if (t[i] < t[mn]) {           mn = i;         }       vector<pair<int, int> > ans;       ans.insert(ans.end(), t.begin() + mn, t.end());       ans.insert(ans.end(), t.begin(), t.begin() + mn);       cout << ans.size() << endl;       for (auto it : ans) cout << it.first <<     << it.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5, Mod = 1e9 + 7, Lg = 27, P = 727, Sq = 350;   const long long Inf = 3e18 + 10;   long long ans;   long long gcd(long long x, long long y) {     if (x > y) swap(y, x);     if (!x) return y;     return gcd(x, y % x);   }   void solve(long long x, long long y, long long d1, long long z, long long w,              long long d2) {     long long t = y - x + 1;     long long g = gcd(d1, d2);     long long d = abs(x - z);     long long q = d / g;     if (x < z) {       x += q * g;       if (x < z) x += g;     } else {       x -= q * g;       if (x > y) x -= g;     }     if (x < z || x > w) return;     ans = max(ans, min(t, w - x + 1));   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long x, y, d1, z, w, d2;     cin >> x >> y >> d1 >> z >> w >> d2;     solve(x, y, d1, z, w, d2);     solve(z, w, d2, x, y, d1);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename _T>   inline void read(_T &f) {     f = 0;     _T fu = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) {         fu = -1;       }       c = getchar();     }     while (c >=  0  && c <=  9 ) {       f = (f << 3) + (f << 1) + (c & 15);       c = getchar();     }     f *= fu;   }   template <typename T>   void print(T x) {     if (x < 0) putchar( - ), x = -x;     if (x < 10)       putchar(x + 48);     else       print(x / 10), putchar(x % 10 + 48);   }   template <typename T>   void print(T x, char t) {     print(x);     putchar(t);   }   int main() {     for (int i = 1; i <= 35; i++) printf( l );     for (int i = 1; i <= 36; i++) printf( dsut0r );     printf( luu );     for (int i = 1; i <= 35; i++) printf( l );     for (int i = 1; i <= 36; i++) printf( usdt0r );     for (int i = 1; i <= 36; i++) printf( le );     printf( ddd );     for (int i = 1; i <= 35; i++) printf( 0r );     printf( 0uu );     for (int i = 1; i <= 33; i++) {       printf( r10ltldr01lt0utd10ut );       printf( uur01ltlldr10ltr10lt0utd10ut );       printf( lrr01ltl10rtl1rt );       printf( rrelelu10dtu10dtddlr10ltu10dtu );       printf( r10ltldr01lt0utd10ut );       printf( uur01ltlldr10ltr10lt0utd10ut );       printf( lrr01ltl10rtl1rt );       printf( l10rtd10utl10rtd10ut );       printf( uereuerererelueueledeleue );       printf( lddd10utuuur10ltd10utd10utl0rt );       printf( r10ltl01rtl1rt );       printf( rdu10dt0ut );       printf( r10ltl01rtl1rt );       printf( ru0utd10ut );       printf( r10ltl01rtl1rt );       printf( reueuerededeldeleuuu );     }     printf( ddddr );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int N = 3e6 + 7;   const int INF = 1e9 + 9;   const int xi[] = {0, 0, +1, -1};   const int yi[] = {-1, +1, 0, 0};   const int xxi[] = {-1, +1, 0, 0, -1, +1, +1, -1};   const int yyi[] = {0, 0, -1, +1, -1, +1, -1, +1};   int n, ans;   int w[1000001], cnt[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> w[i];       cnt[w[i]]++;     }     for (int i = 0; i <= N - 1; i++) {       cnt[i + 1] += cnt[i] / 2;       cnt[i] %= 2;       ans += cnt[i];     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline int read(T& x) {     static char ch;     static bool neg;     for (ch = neg = 0; ch <  0  ||  9  < ch; neg |= ch ==  - , ch = getchar())       ;     for (x = 0;  0  <= ch && ch <=  9 ; (x *= 10) += ch -  0 , ch = getchar())       ;     return (x = neg ? -x : x);   }   template <class T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   template <class T>   inline void writeln(T x) {     write(x);     putchar(  n );   }   const int N = 2e5 + 10;   int m, n, k, t;   int a[N];   struct T {     int l, r, d;   } trap[N];   int c[N];   inline bool check(int val) {     int sum = 0;     for (int i = 1; i <= k; i++) {       if (trap[i].d > val) {         c[trap[i].l]++;         c[trap[i].r + 1]--;       }     }     for (int i = 1, s = 0; i <= n + 1; i++) {       s += c[i];       if (s > 0) sum += 2;     }     for (int i = 1; i <= k; i++) {       if (trap[i].d > val) {         c[trap[i].l]--;         c[trap[i].r + 1]++;       }     }     return sum + n + 1 <= t;   }   int main(void) {     read(m);     read(n);     read(k);     read(t);     for (int i = 1; i <= m; i++) read(a[i]);     sort(a + 1, a + m + 1);     for (int i = 1; i <= k; i++) {       read(trap[i].l);       read(trap[i].r);       read(trap[i].d);     }     a[m + 1] = 1e9 + 10;     int st = 1, en = m + 1;     while (st != en) {       int md = (st + en) >> 1;       if (check(a[md]))         en = md;       else         st = md + 1;     }     printf( %d n , m - st + 1);   }
#include <bits/stdc++.h>   using namespace std;   constexpr int MAXN = 200000;   int x[MAXN + 2];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i];     sort(x, x + n);     int ans = INT_MAX;     for (int i = 0; i < n / 2; i++) ans = min(ans, x[i + n / 2] - x[i]);     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, i, j, k, q;     scanf( %d%d , &n, &k);     n = 1 << n;     printf( %d  , (n >> (k < n)) - 1), q = i = 0;     while (++i < n)       if (i < (i ^ k)) printf( %d  , i ^ q), q = i;   }
#include <bits/stdc++.h>   using namespace std;   queue<pair<int, int> > L, R;   int **M;   int ori, n, m;   bool play(pair<int, int> &p, int &ori) {     for (int i = 0; i < 2; i++) {       if (ori == 0) {         if (M[p.first + 1][p.second] > 0)           ori++;         else {           p = {p.first + 1, p.second};           return 1;         }       }       if (ori == 1) {         if (M[p.first][p.second + 1] > 0)           ori++;         else {           p = {p.first, p.second + 1};           return 1;         }       }       if (ori == 2) {         if (M[p.first - 1][p.second] > 0)           ori++;         else {           p = {p.first - 1, p.second};           return 1;         }       }       if (ori == 3) {         if (M[p.first][p.second - 1] > 0)           ori = 0;         else {           p = {p.first, p.second - 1};           return 1;         }       }     }     return 0;   }   void f(pair<int, int> l, pair<int, int> r, int oril, int orir) {     L.push(l);     if (l != r)       R.push(r);     else       return;     M[l.first][l.second] = 1;     M[r.first][r.second] = 2;     if (play(l, oril) == 0) return;     if (play(r, orir) == 0) return;     f(l, r, oril, orir);   }   int main() {     scanf( %d%d , &n, &m);     M = new int *[n + 2];     for (int i = 0; i < n + 2; i++) {       M[i] = new int[m + 2];       for (int j = 0; j < m + 2; j++) M[i][j] = 0;     }     for (int i = 0; i < n + 2; i++) M[i][0] = M[i][m + 1] = 1;     for (int i = 0; i < m + 2; i++) M[0][i] = M[n + 1][i] = 1;     f({1, 1}, {n, m}, 0, 2);     while (!L.empty()) {       printf( %d %d n , L.front().first, L.front().second);       L.pop();       if (!R.empty()) {         printf( %d %d n , R.front().first, R.front().second);         R.pop();       }     }   }
#include <bits/stdc++.h>   using namespace std;   string multiply(string num1, string num2) {     int len1 = num1.size();     int len2 = num2.size();     if (len1 == 0 || len2 == 0) return  0 ;     vector<int> result(len1 + len2, 0);     int i_n1 = 0;     int i_n2 = 0;     for (int i = len1 - 1; i >= 0; i--) {       int carry = 0;       int n1 = num1[i] -  0 ;       i_n2 = 0;       for (int j = len2 - 1; j >= 0; j--) {         int n2 = num2[j] -  0 ;         int sum = n1 * n2 + result[i_n1 + i_n2] + carry;         carry = sum / 10;         result[i_n1 + i_n2] = sum % 10;         i_n2++;       }       if (carry > 0) result[i_n1 + i_n2] += carry;       i_n1++;     }     int i = result.size() - 1;     while (i >= 0 && result[i] == 0) i--;     if (i == -1) return  0 ;     string s =   ;     while (i >= 0) s += std::to_string(result[i--]);     return s;   }   string divide(string number, int divisor) {     string ans;     int idx = 0;     int temp = number[idx] -  0 ;     while (temp < divisor) temp = temp * 10 + (number[++idx] -  0 );     while (number.size() > idx) {       ans += (temp / divisor) +  0 ;       temp = (temp % divisor) * 10 + number[++idx] -  0 ;     }     if (ans.length() == 0) return  0 ;     return ans;   }   int main() {     int spf[100000];     for (int i = 0; i < 100000; ++i) {       spf[i] = i;     }     for (int i = 4; i < 100000; i += 2) {       spf[i] = 2;     }     for (int i = 3; i * i < 100000; ++i) {       if (spf[i] == i) {         for (int j = i * i; j < 100000; j += i) {           if (spf[j] == j) {             spf[j] = i;           }         }       }     }     vector<int> primes;     for (int i = 2; i < 100000; ++i) {       if (spf[i] == i) {         primes.push_back(i);       }     }     int n;     cin >> n;     if (n == 2) {       cout <<  -1  << endl;       return 0;     }     string ans =  1 ;     for (int i = 0; i < n; ++i) {       ans = multiply(ans, to_string(primes[i]));     }     for (int i = 0; i < n; ++i) {       cout << divide(ans, primes[i]) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T gcd(T a, T b) {     if (a < 0) return gcd(-a, b);     if (b < 0) return gcd(a, -b);     return (b == 0) ? a : gcd(b, a % b);   }   template <class T>   inline T lcm(T a, T b) {     if (a < 0) return lcm(-a, b);     if (b < 0) return lcm(a, -b);     return a * (b / gcd(a, b));   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   T power(T N, T P) {     return (P == 0) ? 1 : N * power(N, P - 1);   }   long long toInt64(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double LOG(long long N, long long B) { return (log10l(N)) / (log10l(B)); }   string itoa(long long a) {     if (a == 0) return  0 ;     string ret;     for (long long i = a; i > 0; i = i / 10) ret.push_back((i % 10) + 48);     reverse(ret.begin(), ret.end());     return ret;   }   vector<string> token(string a, string b) {     const char *q = a.c_str();     while (count(b.begin(), b.end(), *q)) q++;     vector<string> oot;     while (*q) {       const char *e = q;       while (*e && !count(b.begin(), b.end(), *e)) e++;       oot.push_back(string(q, e));       q = e;       while (count(b.begin(), b.end(), *q)) q++;     }     return oot;   }   int isvowel(char s) {     s = tolower(s);     if (s ==  a  || s ==  e  || s ==  i  || s ==  o  || s ==  u ) return 1;     return 0;   }   int isupper(char s) {     if (s >=  A  and s <=  Z ) return 1;     return 0;   }   int Set(int N, int pos) { return N = N | (1 << pos); }   int reset(int N, int pos) { return N = N & ~(1 << pos); }   int check(int N, int pos) { return (N & (1 << pos)); }   int toggle(int N, int pos) {     if (check(N, pos)) return N = reset(N, pos);     return N = Set(N, pos);   }   void pbit(int N) {     printf( ( );     for (int i = 10; i >= 0; i--) {       bool x = check(N, i);       cout << x;     }     puts( ) );   }   int main() {     int n, q;     cin >> n >> q;     string s;     cin >> s;     string w = s;     while (q--) {       s = w;       int val[202] = {0}, del[202] = {0};       for (int i = 0; i < (int)s.size(); i++) {         if (s[i] >=  0  and s[i] <=  9 ) val[i + 1] = s[i] -  0 ;       }       s =  #  + s;       char prev =  ) ;       int pidx, freq[111] = {0};       int l, r;       cin >> l >> r;       int cp = l, dp = 1;       while (cp >= l and cp <= r) {         if (del[cp]) {           cp += dp;         } else {           if (s[cp] >=  0  and s[cp] <=  9 ) {             freq[val[cp]]++;             val[cp]--;             if (val[cp] == -1) del[cp] = 1;           } else {             if (prev ==  >  or prev ==  < ) {               del[pidx] = 1;             }             if (s[cp] ==  > )               dp = 1;             else               dp = -1;           }           prev = s[cp];           pidx = cp;           cp += dp;         }       }       for (int i = 0; i < (int)10; i++) {         if (i) printf(   );         printf( %d , freq[i]);       }       puts(  );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5) + 500;   int n, m, a[N], s, h, mm;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> s;     for (int i = 1; i <= n; i++) {       cin >> h >> mm;       a[++m] = h * 60 + mm;     }     if (a[1] >= s + 1) {       cout << 0 <<     << 0;       exit(0);     }     for (int i = 2; i <= n; i++) {       if (a[i] - a[i - 1] >= s * 2 + 2) {         cout << (a[i - 1] + s + 1) / 60 <<     << (a[i - 1] + s + 1) % 60;         exit(0);       }     }     cout << (a[m] + s + 1) / 60 <<     << (a[m] + s + 1) % 60;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string second;   int n, k;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     ;     cin >> second >> k;     if (second.size() < k) return cout <<  impossible n , 0;     set<char> st;     for (auto i : second) st.insert(i);     if (st.size() > k)       cout <<  0 ;     else       cout << k - st.size() << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[60];   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; ++i) cin >> arr[i];     sort(arr, arr + n);     bool aliceWins = (arr[0] < arr[n >> 1]);     cout << (aliceWins ?  Alice n  :  Bob n );   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e8;   int l, r, cnt, ans1, pre1[20000005];   bitset<maxn> pre;   int max1, max2;   int main() {     cin >> l >> r;     pre[1] = pre[0] = 1;     ans1 = 1;     for (int yui = 2; yui <= r; yui++) {       if (pre[yui] == 0) {         cnt++;         pre1[cnt] = yui;         if (yui % 4 == 1) ans1++;       }       if (yui == l - 1) max1 = ans1;       if (yui == r) max2 = ans1;       for (int j = 1; j <= cnt && pre1[j] * yui <= r; j++) {         pre[yui * pre1[j]] = 1;         if (yui % pre1[j] == 0) break;       }     }     cout << max2 - max1;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 32, MAXS = 1 << 17;   const int MOD = 1e9 + 7, H = 3137;   int add(int a, int b) {     a += b;     if (a >= MOD) a -= MOD;     return a;   }   int sub(int a, int b) {     a -= b;     if (a < 0) a += MOD;     return a;   }   int mul(int a, int b) { return (int)(((long long)a * b) % MOD); }   int n, T;   string s[MAXN];   int len[MAXN];   int poz_s[MAXN];   vector<pair<int, pair<int, int> > > V[MAXS];   int __h[MAXS], pot[MAXS];   int *h = __h + 5;   int geth(int l, int ln) { return sub(h[l + ln - 1], mul(h[l - 1], pot[ln])); }   int ok(int a, int poza, int b) {     int kol = min(len[b], len[a] - poza);     return geth(poz_s[a] + poza, kol) == geth(poz_s[b], kol);   }   int slj_poz(int a, int poza, int b) {     if (!ok(a, poza, b)) return -1;     if (poza + len[b] == len[a]) return T;     if (poza + len[b] < len[a]) return poz_s[a] + poza + len[b];     return poz_s[b] + len[a] - poza;   }   char ss[MAXS];   void load() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf(  %s , ss);       s[i] = ss;       len[i] = (int)s[i].size();       poz_s[i] = !i ? 0 : (poz_s[i - 1] + len[i - 1]);       for (int j = 0; j < len[i]; j++)         h[j + poz_s[i]] = add(mul(h[j + poz_s[i] - 1], H), s[i][j]);     }     T = poz_s[n - 1] + len[n - 1];   }   void gen() {     for (int i = 0; i < n; i++) V[T].push_back({poz_s[i], pair<int, int>(i, i)});     for (int a = 0; a < n; a++) {       for (int b = 0; b < n; b++) {         for (int poza = 0; poza < len[a]; poza++) {           if (!poza && s[a] == s[b]) continue;           int tmp = slj_poz(a, poza, b);           if (tmp != -1)             V[poz_s[a] + poza].push_back(                 {tmp, pair<int, int>(min(a, b), max(a, b))});         }       }     }   }   int bio[MAXS];   int dfs(int node, int l, int r) {     if (bio[node]) return bio[node] == 1;     bio[node] = 1;     for (auto it : V[node])       if (it.second.first >= l && it.second.second <= r && dfs(it.first, l, r))         return 1;     bio[node] = 2;     return 0;   }   int nema_cik(int l, int r) {     memset(bio, 0, sizeof bio);     for (int i = 0; i < T + 1; i++)       if (!bio[i] && dfs(i, l, r)) return 0;     return 1;   }   void solve() {     int rje = 0;     gen();     for (int i = 0, j = 0; i < n; i++) {       j = max(j, i);       for (; j < n && nema_cik(i, j); j++)         ;       rje += j - i;     }     printf( %d n , rje);   }   int main() {     pot[0] = 1;     for (int i = (1); i < (MAXS); i++) pot[i] = mul(pot[i - 1], H);     load();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 505;   int n, k;   int a[MAXN], b[MAXN];   bool f[MAXN][MAXN];   int main() {     scanf( %d%d , &n, &k);     long long sum_a = 0, sum_b = 0;     for (int i = 1; i <= n; i++) {       scanf( %d%d , &a[i], &b[i]);       sum_a += a[i];       sum_b += b[i];     }     f[0][0] = true;     for (int i = 1; i <= n; i++) {       for (int j = 0; j < k; j++) {         f[i][j] = f[i - 1][j];         for (int x = 0; x <= k; x++) {           if (x <= a[i] && (k - x) <= b[i]) {             f[i][j] = f[i][j] || f[i - 1][(j + k - x) % k];           }         }       }     }     long long ans = sum_a / k + sum_b / k;     for (int x = 1; x < k; x++) {       if (f[n][x]) {         ans = max(ans, (sum_a - x) / k + (sum_b - (k - x)) / k + 1);       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   const int bufSize = 1e6;   inline char nc() {     return getchar();     static char buf[bufSize], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2)                ? EOF                : *p1++;   }   template <typename T>   inline T read(T& r) {     static char c;     static int flag;     flag = 1, r = 0;     for (c = nc(); !isdigit(c); c = nc())       if (c ==  - ) flag = -1;     for (; isdigit(c); c = nc()) r = r * 10 + c - 48;     return r *= flag;   }   const int maxn = 3e5 + 100;   const int inf = 1 << 30;   int n, m, up, cnt;   struct node {     int pos, id;   } A[maxn << 1];   inline bool cmp(const node& a, const node& b) {     return a.pos != b.pos ? a.pos < b.pos : a.id < b.id;   }   int f[1 << 9], popc[1 << 9];   int vis[15];   int main() {     read(n), read(m), read(up);     for (int i = 1, l, r; i <= n; ++i)       read(l), read(r), A[++cnt].pos = l, A[cnt].id = i, A[++cnt].pos = r + 1,                         A[cnt].id = -i;     std::sort(A + 1, A + 1 + cnt, cmp);     for (int i = 1; i < (1 << up); ++i)       f[i] = -inf, popc[i] = popc[i >> 1] ^ (i & 1);     for (int i = 1; i < cnt; ++i) {       int len = A[i + 1].pos - A[i].pos, k;       if (A[i].id > 0) {         for (int j = 0; j < 8; ++j)           if (!vis[j]) {             vis[j] = A[i].id, k = j;             break;           }         for (int j = (1 << up) - 1; j >= 0; --j)           if (j & (1 << k))             f[j] = f[j ^ (1 << k)] + len * popc[j];           else             f[j] = f[j] + len * popc[j];       } else {         for (int j = 0; j < 8; ++j)           if (vis[j] == -A[i].id) {             vis[j] = 0, k = j;             break;           }         for (int j = 0; j < (1 << up); ++j)           if (j & (1 << k))             f[j] = -inf;           else             f[j] = std::max(f[j], f[j ^ (1 << k)]) + len * popc[j];       }     }     int res = 0;     for (int i = 0; i < (1 << up); ++i) res = std::max(res, f[i]);     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m;     while (cin >> n >> m) {       long long num, sum = 0, minx = 1000000001;       for (long long i = 0; i < n; i++) {         cin >> num;         sum += num;         if (num < minx) minx = num;       }       if (sum < m)         cout << -1 << endl;       else if (minx < (sum - m) / n) {         cout << minx << endl;       } else         cout << (sum - m) / n << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e4 + 10;   const int P = 1048576 + 10;   const int Y = 30;   int vis[N];   int cnt;   int book[N];   int a[N];   int n;   int m;   int k;   int addis[Y][Y];   int dis[N];   int dp[P];   queue<int> q;   inline void bfs(int s) {     for (int i = 1; i <= n + 1; i++) dis[i] = 0x3f3f3f3f;     dis[s] = 0;     int nw;     int i = 1;     for (q.push(s); !q.empty();)       for (nw = q.front(), q.pop(), i = 1; i <= m; i++) {         int v1 = nw + a[i];         if (v1 <= n + 1 && dis[v1] == 0x3f3f3f3f)           dis[v1] = dis[nw] + 1, q.push(v1);         int v2 = nw - a[i];         if (v2 >= 1 && dis[v2] == 0x3f3f3f3f) dis[v2] = dis[nw] + 1, q.push(v2);       }     for (int i = 1; i <= n + 1; i++)       if (vis[i] != -1) addis[vis[s]][vis[i]] = dis[i];   }   int main() {     scanf( %d%d%d , &n, &k, &m);     for (int i = 1, t; i <= k; i++) {       scanf( %d , &t);       book[t] = 1;     }     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     for (int i = n + 1; i >= 1; i--) book[i] ^= book[i - 1];     cnt = -1;     for (int i = 1; i <= n + 1; i++) vis[i] = -1;     for (int i = 1; i <= n + 1; i++)       if (book[i]) vis[i] = ++cnt;     for (int i = 1; i <= n + 1; i++)       if (book[i]) bfs(i);     for (int i = 1; i < (1 << (cnt + 1)); i++) dp[i] = 0x3f3f3f3f;     for (int i = 0; i < (1 << (cnt + 1)); i++) {       if (dp[i] == 0x3f3f3f3f) continue;       for (int j = 0; j <= cnt; j++) {         if ((i >> j) & 1) continue;         for (int k = j + 1; k <= cnt; k++)           if (((i >> k) & 1) == 0)             dp[i + (1 << j) + (1 << k)] =                 min(dp[i + (1 << j) + (1 << k)], dp[i] + addis[j][k]);       }     }     int ans = dp[(1 << (cnt + 1)) - 1];     printf( %d , (ans == 0x3f3f3f3f) ? -1 : ans);     return 0;   }