malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, k, x[1010], dp[1010][1010], sm[1010];   long long solve(long long gap) {     dp[0][0] = 1, x[0] = -200000;     for (long long i = 1; i <= k; ++i) {       for (long long j = 0; j <= n; ++j)         sm[j] = j == 0 ? dp[i - 1][j] : (dp[i - 1][j] + sm[j - 1]) % 998244353;       long long pos = 0;       for (long long j = 1; j <= n; ++j) {         while (x[j] - x[pos + 1] >= gap) pos++;         dp[i][j] = sm[pos];       }     }     long long sum = 0;     for (long long i = 1; i <= n; ++i) sum = (sum + dp[k][i]) % 998244353;     return sum;   }   int32_t main() {     cin.tie(0), cout.sync_with_stdio(0);     cin >> n >> k;     for (long long i = 1; i <= n; ++i) cin >> x[i];     sort(x + 1, x + 1 + n);     long long dis = 100000 / (k - 1), pre = solve(1), ans = 0;     for (long long i = 2; i <= dis + 5; ++i) {       long long now = solve(i);       ans = (ans + (pre - now + 998244353) * (i - 1)) % 998244353;       pre = now;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[1000];     int num;     cin >> num;     for (int i = 0; i < num; i++) {       cin >> arr[i];       arr[num + i] = arr[i];     }     int ans = 360;     for (int i = 0; i < num; i++) {       int temp = 0;       for (int j = i; j < num * 2; j++) {         temp += arr[j];         ans = min(ans, abs(360 - 2 * temp));       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   char s[1000005];   int arr[205];   int main() {     scanf( %d%d%d%s , &n, &a, &b, s);     int i, j, len = strlen(s), tag;     if (len > n * b || len < n * a) {       puts( No solution );       return 0;     }     int eve = len / n;     for (i = 0; i < n; i++) {       arr[i] = eve;     }     eve = len % n;     for (i = 0; i < eve; i++) arr[i]++;     for (i = tag = 0; i < n; i++) {       for (j = 0; j < arr[i]; j++) printf( %c , s[tag++]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char instr[51], outstr[51] = {}, ch;     int n, i;     cin >> instr;     cin >> n;     for (i = 0; i < strlen(instr); i++) {       if (instr[i] < 97) instr[i] += 32;     }     for (i = 0; i < strlen(instr); i++) {       ch = instr[i];       if (int(ch) < (n + 97)) {         outstr[i] = ch - 32;       } else {         outstr[i] = ch;       }     }     cout << outstr;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int N, M;     cin >> N >> M;     vector<int> arr(N + 2);     arr[0] = 1;     for (int i = 0; i < N; ++i) cin >> arr[i + 1];     arr[N + 1] = 1;     int q = M, w = M;     int r = 0;     while (q > 0 || w < N + 1) {       int s = arr[q] + arr[w];       if (s == 2) r += s - (q == 0) - (w == N + 1) - (w == q);       if (q > 0) q--;       if (w < N + 1) w++;     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d = 0, e = 0, f = 0, g = 0, i, j, k = 1, l = 1, r = 1,                        n[300001], m[300001], q, u, v, w, y, z[400001], h[400001],                        p[500001];     string s, t, x;     cin >> a >> b >> c;     for (i = 1; i <= a; i++) {       cin >> d >> e;       f += (d - g) / c;       g = d + e;     }     cout << f + ((b - g) / c);   }
#include <bits/stdc++.h>   using namespace std;   long long int d[300002];   int safe[300002];   bool solve() {     long long int n, k, l, i;     cin >> n >> k >> l;     for (i = 1; i <= n; i++) cin >> d[i];     int tide, dir, mtide;     tide = k;     dir = -1;     for (i = 1; i <= n; i++) {       if (d[i] + k <= l)         tide = k, dir = -1;       else if (d[i] > l)         return false;       else {         mtide = l - d[i];         if (tide + dir <= mtide) {           tide += dir;           if (tide == 0) dir = 1;         } else if (dir == -1 && mtide < tide - 1) {           tide = mtide;           if (tide == 0) dir = 1;         } else           return false;       }     }     return true;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t, i;     cin >> t;     while (t--) {       if (solve())         cout <<  Yes n ;       else         cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       long long int a[n];       unordered_map<long long int, long long int> mp;       for (int i = 0; i < n; i++) {         cin >> a[i];         mp[a[i]]++;       }       if (mp.size() == 1)         cout <<  NO  << endl;       else {         cout <<  YES  << endl;         int f = -1, s = -1;         for (int i = 1; i < n; i++) {           if (a[i] != a[0]) {             f = i;             break;           }         }         for (int i = 1; i < n; i++) {           if (a[i] != a[f])             cout << i + 1 <<     << f + 1 << endl;           else             cout << 1 <<     << i + 1 << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = 2e5 + 10;   int n;   string s, xx =  RGB ;   int getID(char c) {     if (c ==  R )       return 1;     else if (c ==  G )       return 2;     return 3;   }   int last[4];   int dp[MAX][4][4][4];   int mn = 1e9;   vector<char> v, ans;   int tokyoGhoul(int cur, int cnt) {     if (cur == n) {       if (cnt < mn) {         mn = cnt;         ans = v;       }       return cnt;     }     int &ret = dp[cur][last[0]][last[1]][last[2]];     if (~ret) return ret;     ret = 1e18;     for (int i = 0; i < xx.size(); i++) {       int id = getID(xx[i]);       int prev = last[id];       char ch = xx[i];       if (prev == -1 || (cur - prev) != 1) {         v.push_back(ch);         last[id] = cur;         if (xx[i] != s[cur])           ret = min(ret, tokyoGhoul(cur + 1, cnt + 1));         else           ret = min(ret, tokyoGhoul(cur + 1, cnt));         last[id] = prev;         v.pop_back();       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> s;     vector<string> vv;     int cnt = 0, cnt2 = 0;     string s1 =   , s2 =   ;     for (int j = 0; j < 3; j++) {       cnt = 0, s1 =   ;       s1 += xx[j];       if (s[0] != s1[0]) cnt++;       for (int i = 1; i < n; i++) {         if (s[i] == s1[i - 1]) {           cnt++;           bool f = 1;           for (int j = 0; j < xx.size(); j++) {             if (s1[i - 1] != xx[j] && (i + 1 == n || s[i + 1] != xx[j])) {               s1 += xx[j];               f = 0;               break;             }           }           if (f)             for (int j = 0; j < xx.size(); j++) {               if (s[i - 1] != xx[j]) {                 s1 += xx[j];                 break;               }             }         } else           s1 += s[i];       }       if (cnt < mn) {         mn = cnt;         s2 = s1;       }     }     cout << mn << endl;     for (auto i : s2) cout << i;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   int r, c, k, n, a[15][15];   int main() {     scanf( %d%d%d%d , &r, &c, &n, &k);     for (int i = (1); i <= (n); ++i) {       int x, y;       scanf( %d%d , &x, &y);       a[x][y] = 1;     }     int ans = 0;     for (int x1 = (1); x1 <= (r); ++x1) {       for (int y1 = (1); y1 <= (c); ++y1) {         for (int x2 = (x1); x2 <= (r); ++x2) {           for (int y2 = (y1); y2 <= (c); ++y2) {             int sum = 0;             for (int x = (x1); x <= (x2); ++x) {               for (int y = (y1); y <= (y2); ++y) sum += a[x][y];             }             if (sum >= k) ++ans;           }         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5010, inf = 0x7fffffff;   bool has[maxn][maxn], flag = 0;   int sum[maxn][maxn], n, m, l[10], r[10], req;   long long ans;   void init() {     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         sum[i][j] =             sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + (has[i][j] == 1);   }   int calculate(int x1, int y1, int x2, int y2) {     return sum[x2][y2] - sum[x1][y2] - sum[x2][y1] + sum[x1][y1];   }   void work(int up, int down, int left, int right, bool dir) {     if (left == right || up == down) return;     if (left + 1 == right && up + 1 == down) {       ans += calculate(up, left, down, right) == req;       return;     }     if (dir == 0) {       int mid = (left + right) >> 1;       work(up, down, left, mid, dir ^ 1);       work(up, down, mid, right, dir ^ 1);       for (int i = up; i < down; i++) {         l[0] = r[0] = mid;         for (int k = 1; k <= req + 1; k++) l[k] = left, r[k] = right;         for (int j = i + 1; j <= down; j++) {           for (int k = 1; k <= req + 1; k++)             while (calculate(i, l[k], j, mid) >= k) l[k]++;           for (int k = 1; k <= req + 1; k++)             while (calculate(i, mid, j, r[k]) >= k) r[k]--;           for (int k = 0; k <= req; k++)             ans += (l[k] - l[k + 1]) * (r[req - k + 1] - r[req - k]);         }       }     } else {       int mid = (up + down) >> 1;       work(up, mid, left, right, dir ^ 1);       work(mid, down, left, right, dir ^ 1);       for (int i = left; i < right; i++) {         l[0] = r[0] = mid;         for (int k = 1; k <= req + 1; k++) l[k] = up, r[k] = down;         for (int j = i + 1; j <= right; j++) {           for (int k = 1; k <= req + 1; k++)             while (calculate(l[k], i, mid, j) >= k) l[k]++;           for (int k = 1; k <= req + 1; k++)             while (calculate(mid, i, r[k], j) >= k) r[k]--;           for (int k = 0; k <= req; k++)             ans += (l[k] - l[k + 1]) * (r[req - k + 1] - r[req - k]);         }       }     }   }   int main() {     while (scanf( %d%d%d , &n, &m, &req) == 3) {       memset(has, 0, sizeof(has));       ans = 0;       for (int i = 1; i <= n; i++)         for (int j = 1; j <= m; j++) scanf( %1d , &has[i][j]);       init();       work(0, n, 0, m, n < m);       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, ta, tb;     cin >> a >> ta >> b >> tb;     int t, m;     char c;     cin >> t >> c >> m;     m += 60 * t;     int cur = 5 * 60;     int res = 0;     while (cur < 24 * 60) {       if (min(cur + tb, m + ta) > max(cur, m)) ++res;       cur += b;     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 100000007;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long powmod(long long a, long long b) {     long long res = 1;     a %= mod;     assert(b >= 0);     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<long long> nums(n);       for (int i = 0; i < n; i++) cin >> nums[i];       double all = 0;       sort(nums.rbegin(), nums.rend());       for (int i = 1; i < n; i++) all += nums[i];       all = 1.0 * all / (n - 1) + nums[0];       printf( %.8lf n , all);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string res =   ;     cin >> n;     int arr[2004] = {0};     for (int i = 0; i < n; ++i) {       cin >> arr[i];     }     int now_rejt = 0;     int mesto = 1;     for (int i = 0; i < n; ++i) {       now_rejt = arr[i];       mesto = 1;       for (int j = 0; j < n; ++j) {         if (now_rejt < arr[j]) {           ++mesto;         }       }       stringstream ss;       ss << mesto;       string strmesto;       ss >> strmesto;       res = res +     + strmesto;     }     res.erase(0, 1);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, map<int, vector<int>>> answers;   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int bus, tram, money;       cin >> bus >> tram >> money;       string s;       cin >> s;       int cur = s.size() - 2;       while (true) {         char cur_char = s[cur];         if (cur_char ==  A ) {           if (bus > money) {             cout << cur + 2 <<   n ;             break;           }           money -= bus;         }         if (cur_char ==  B ) {           if (tram > money) {             cout << cur + 2 <<   n ;             break;           }           money -= tram;         }         while (cur >= 0 && s[cur] == cur_char) {           cur -= 1;         }         if (cur == -1) {           cout << 1 <<   n ;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int GCD(int x, int y) { return !y ? x : GCD(y, x % y); }   int LCM(int x, int y) { return x * y / GCD(x, y); }   long long ceilDivision(long long dividend, long long divisor) {     return (dividend + divisor - 1) / divisor;   }   bool check(pair<long long, int> right, pair<long long, int> left) {     return ((left.second > right.second) ||             (left.second == right.second && left.first > right.first));   }   int main() {     long long r, avg, sum = 0, target, counter = 0;     int n, pointer = 0;     cin >> n >> r >> avg;     vector<pair<long long, int> > arr(n);     target = avg * n;     for (int i = 0; i < n; i++)       cin >> arr[i].first >> arr[i].second, sum += arr[i].first;     if (sum < target) {       sort(arr.begin(), arr.end(), check);       target -= sum;       while (target) {         if (arr[pointer].first < r)           counter += (min(target, r - arr[pointer].first) * arr[pointer].second),               target -= min(target, r - arr[pointer].first);         pointer++;       }     }     cout << counter << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> dir_graph;   vector<int> vis, order;   void dfs(int i) {     vis[i] = true;     for (int j = 0; j < dir_graph[i].size(); j++) {       if (!vis[dir_graph[i][j]]) {         dfs(dir_graph[i][j]);       }     }     order.push_back(i);   }   int main() {     int cases;     cin >> cases;     while (cases--) {       int n, m;       cin >> n >> m;       dir_graph = vector<vector<int>>(n);       order.clear();       vis = vector<int>(n);       vector<pair<int, int>> edges;       int type, s, d;       for (int i = 0; i < m; i++) {         cin >> type >> s >> d;         s--;         d--;         if (type == 1) dir_graph[s].push_back(d);         edges.push_back({s, d});       }       for (int i = 0; i < n; i++) {         if (!vis[i]) {           dfs(i);         }       }       vector<int> pos(n);       reverse(order.begin(), order.end());       for (int i = 0; i < n; ++i) {         pos[order[i]] = i;       }       bool hasCycle = false;       for (int i = 0; i < n; i++) {         for (int j = 0; j < dir_graph[i].size(); j++) {           if (pos[i] > pos[dir_graph[i][j]]) {             hasCycle = true;             break;           }         }       }       if (hasCycle)         cout <<  NO  << endl;       else {         cout <<  YES n ;         for (int i = 0; i < edges.size(); i++) {           if (pos[edges[i].first] < pos[edges[i].second]) {             cout << edges[i].first + 1 <<     << edges[i].second + 1 << endl;           } else {             cout << edges[i].second + 1 <<     << edges[i].first + 1 << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char ch[] = { B ,  u ,  l ,  b ,  a ,  s ,  a ,  u ,  r };     map<char, int> mp;     string ss;     int n, k, i, cnt = 100000;     cin >> ss;     for (i = 0; i < ss.size(); i++) {       mp[ss[i]]++;     }     for (i = 0; i < 9; i++) {       k = mp[ch[i]];       if (ch[i] ==  u  || ch[i] ==  a ) k = k / 2;       cnt = min(cnt, k);     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n;     if (n % 2 == 0)       printf( -1 n );     else {       for (k = 0; k < n; k++) printf( %d  , ((n / 2 + 1 - k) + n) % n);       cout << endl;       for (k = 0; k < n; k++) printf( %d  , ((n / 2 + 2 * k) + n) % n);       cout << endl;       for (k = 0; k < n; k++) printf( %d  , k);     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   int n;   int arr1[10];   int arr2[100005];   pair<int, int> diffs[600005];   int cnts[100005];   int main() {     while (scanf( %d , arr1) == 1) {       for (int i = 1; i < 6; ++i) {         scanf( %d , arr1 + i);       }       scanf( %d , &n);       for (int i = 0; i < n; ++i) {         scanf( %d , arr2 + i);       }       int idx = 0;       for (int i = 0; i < 6; ++i) {         for (int j = 0; j < n; ++j) {           diffs[idx].first = arr2[j] - arr1[i];           diffs[idx].second = j;           ++idx;         }       }       sort(diffs, diffs + idx);       memset(cnts, 0, sizeof(cnts));       int cnt = 0;       int j = 0;       int ans = INF;       for (int i = 0; i < 5 * n; ++i) {         if (i && --cnts[diffs[i - 1].second] <= 0) {           --cnt;         }         while (cnt < n && j < 6 * n) {           if (cnts[diffs[j].second]++ == 0) {             ++cnt;           }           ++j;         }         if (cnt >= n) {           ans = min(ans, diffs[j - 1].first - diffs[i].first);         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char a;     cin >> a;     string str1, str2;     cin >> str1 >> str2;     int b1, b2;     switch (str1[0]) {       case  T :         b1 = 10;         break;       case  J :         b1 = 11;         break;       case  Q :         b1 = 12;         break;       case  K :         b1 = 13;         break;       case  A :         b1 = 14;         break;       default:         b1 = str1[0] -  0 ;     }     switch (str2[0]) {       case  T :         b2 = 10;         break;       case  J :         b2 = 11;         break;       case  Q :         b2 = 12;         break;       case  K :         b2 = 13;         break;       case  A :         b2 = 14;         break;       default:         b2 = str2[0] -  0 ;     }     if (str1[1] == a)       if (str2[1] != str1[1]) {         cout <<  YES ;       } else {         if (b1 > b2) {           cout <<  YES ;         } else           cout <<  NO ;       }     else {       if (str2[1] == str1[1]) {         if (b1 > b2) {           cout <<  YES ;         } else           cout <<  NO ;       } else {         cout <<  NO ;       };     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5001;   int n, m, x, y, c[N], p[N], A;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) p[i] = N;     while (m-- && cin >> x >> y) c[x]++, p[x] = min(p[x], (y + n - x) % n);     for (int i = 1; i <= n; i++) {       A = 0;       for (int j = 1; j <= n; j++)         if (c[j]) A = max(A, (j + n - i) % n + (c[j] - 1) * n + p[j]);       cout << A <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 50;   int n, q;   int lca[N][25], mark[N], sum[N], h[N], a[N][4];   vector<int> adj[N];   map<int, map<int, int> > m;   void DFS(int v, int p, int hi) {     h[v] = hi;     lca[v][0] = p;     for (auto u : adj[v]) {       if (u == p) continue;       DFS(u, v, hi + 1);     }   }   void dfs_sum(int v, int p) {     sum[v] += mark[v];     for (auto u : adj[v]) {       if (u == p) continue;       dfs_sum(u, v);       sum[v] += sum[u];     }     m[p][v] = sum[v];   }   void LCA() {     for (int j = 1; j <= 20; j++)       for (int i = 1; i <= n; i++) lca[i][j] = lca[lca[i][j - 1]][j - 1];   }   int find_par(int v, int k) {     for (int j = 0; j <= 20; j++) {       if (k & (1 << j)) v = lca[v][j];     }     return v;   }   int find_lca(int u, int v) {     v = find_par(v, h[v] - h[u]);     if (v == u) return u;     for (int j = 20; j >= 0; j--) {       if (lca[u][j] != lca[v][j]) {         u = lca[u][j];         v = lca[v][j];       }     }     return lca[u][0];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cin >> n;     for (int i = 1; i < n; i++) {       cin >> a[i][0] >> a[i][1];       adj[a[i][0]].push_back(a[i][1]);       adj[a[i][1]].push_back(a[i][0]);     }     DFS(n - 1, 0, 1);     LCA();     cin >> q;     for (int i = 0; i < q; i++) {       int u, v;       cin >> u >> v;       if (h[u] > h[v]) swap(u, v);       int lca = find_lca(u, v);       mark[u]++;       mark[v]++;       mark[lca] -= 2;     }     dfs_sum(n - 1, 0);     for (int i = 1; i < n; i++) {       cout << max(m[a[i][0]][a[i][1]], m[a[i][1]][a[i][0]]) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long maxn = 1e5 + 5;   void solve() {     long long k;     cin >> k;     long long first = pow(2, 17);     cout << 2 <<     << 3 <<   n ;     cout << first + k <<     << first <<     << 0 <<   n           << k <<     << first + k <<     << k;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long tc = 1;     while (tc--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6;   int n, m, k;   int s[N], c[N];   bool vis[N];   int fir[N];   long long ans = 1e15;   void can(int u) {     long long rep = 0;     for (int i = 1; i <= n;) {       if (fir[i + u] == i) {         return;       }       rep += c[u];       if (i + u > n) {         break;       }       i = fir[i + u];     }     ans = min(ans, rep);   }   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; i++) {       scanf( %d , &s[i]);       vis[s[i] + 1] = 1;     }     for (int i = 1; i <= k; i++) {       scanf( %d , &c[i]);     }     for (int i = 1; i <= n; i++) {       if (vis[i]) {         fir[i] = fir[i - 1];       } else {         fir[i] = i;       }     }     if (!fir[1]) {       printf( -1 n );       return 0;     }     for (int i = 1; i <= k; i++) {       can(i);     }     if (ans == 1e15) {       printf( -1 n );     } else {       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int where[26][26];   int n, dp[(1 << 23) + 5], d[35];   bool fdp[(1 << 23) + 5];   int rec(int mask) {     if (fdp[mask]) return dp[mask];     int next = 0;     for (int i = n - 1; i >= 0; --i) {       if (mask & (1 << i)) {         next = i;         break;       }     }     next++;     fdp[mask] = 1;     if (next == n) return dp[mask] = __builtin_popcount(mask);     int make = d[next + 1];     dp[mask] = 30;     int valid = 0;     for (int i = 0; i < n; ++i) {       if (mask & (1 << i)) {         int j = where[next + 1][i + 1];         if (d[i + 1] < make and j) {           j--;           if (mask & (1 << j)) valid = 1;         }       }     }     if (valid) {       dp[mask] = rec(mask | (1 << next));       for (int i = 0; i < next; ++i) {         if (mask & (1 << i))           dp[mask] = min(dp[mask], rec((mask ^ (1 << i)) | (1 << next)));       }     }     return dp[mask];   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> d[i];     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j) {         int f = d[i] - d[j];         for (int k = 1; k <= n; ++k) {           if (d[k] == f) {             where[i][j] = k;           }         }       }     }     int ans = rec(1);     if (ans == 30) ans = -1;     cout << ans;   }