malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char arr[1001][1001];   long long int used[1001][1001];   long long int ans[1001][1001];   long long int n, m;   long long int inf = 1e18;   long long int p = 1e9 + 7;   long long int phi(long long int n) {     long long int result = n;     for (long long int i = 2; i * i <= n; i++) {       if (n % i == 0) {         while (n % i == 0) n /= i;         result -= result / i;       }     }     if (n > 1) result -= result / n;     return result;   }   long long int power(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long int modInverse(long long int n, long long int p) {     return power(n, p - 2, p);   }   long long int dfs(long long int x, long long int y) {     long long int cur = 0;     long long int temp = 0;     char s = arr[x][y];     char f;     if (used[x][y] == 2) {       return ans[x][y];     }     ans[x][y] = 0;     used[x][y] = 1;     if (s ==  D )       f =  I ;     else if (s ==  I )       f =  M ;     else if (s ==  M )       f =  A ;     else       f =  D ;     if (x + 1 <= n && arr[x + 1][y] == f) {       if (used[x + 1][y] != 1) {         temp = std::max(temp, 1 + dfs(x + 1, y));       } else if (used[x + 1][y] == 1)         return inf;     }     if (x - 1 >= 0 && arr[x - 1][y] == f) {       if (used[x - 1][y] != 1) {         temp = std::max(temp, 1 + dfs(x - 1, y));       } else if (used[x - 1][y] == 1)         return inf;     }     if (y + 1 <= m && arr[x][y + 1] == f) {       if (used[x][y + 1] != 1) {         temp = std::max(temp, 1 + dfs(x, y + 1));       } else if (used[x][y + 1] == 1)         return inf;     }     if (y - 1 >= 0 && arr[x][y - 1] == f) {       if (used[x][y - 1] != 1) {         temp = std::max(temp, 1 + dfs(x, y - 1));       } else if (used[x][y - 1] == 1)         return inf;     }     if (temp >= inf) temp = inf;     used[x][y] = 2;     ans[x][y] = temp;     return ans[x][y];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, j, t, a, b, temp, k, x, y, ctr;     cin >> n >> m;     long long int ans = 0;     memset(used, 0, sizeof(used));     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) cin >> arr[i][j];     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= m; j++) {         if (arr[i][j] ==  D  && used[i][j] == 0) {           ans = std::max(ans, 1 + dfs(i, j));         }       }     }     if (ans >= inf)       cout <<  Poor Inna! ;     else {       ans /= 4;       if (ans == 0)         cout <<  Poor Dima! ;       else         cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e9;   const long long MOD = (long long)1e9 + 7;   const long long P = 239;   const long long MAX_N = 1000;   const long long CNT = 5;   const long double pi = 3.1415926535897932384626;   const long double eps = 1e-6;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, l, v1, v2, k;     cin >> n >> l >> v1 >> v2 >> k;     long long cnt = (n + k - 1) / k;     long double f = (long double)(v2 - v1) / (v2 + v1);     long double t = (long double)l / (v2 * cnt - v2 * (cnt - 1) * f);     cout.precision(30);     t = t * cnt + t * f * (cnt - 1);     cout << t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 3e5 + 10, inf = 1000111222;   struct node {     int p0, p1;     int cnt;     node() {       p0 = p1 = 0;       cnt = 0;     }   };   int root = 1;   node A[max_n * 33];   int last_used = 1;   int new_node() { return ++last_used; }   int a[max_n];   long long cost_if_set[33][2];   void add_number(int a) {     int cur = root;     for (int i = 30; i >= 0; i--) {       if (a & (1ll << i)) {         if (A[cur].p0) {           cost_if_set[i][0] += A[A[cur].p0].cnt;         }         if (!A[cur].p1) {           A[cur].p1 = new_node();         }         cur = A[cur].p1;         A[cur].cnt++;       } else {         if (A[cur].p1) {           cost_if_set[i][1] += A[A[cur].p1].cnt;         }         if (!A[cur].p0) {           A[cur].p0 = new_node();         }         cur = A[cur].p0;         A[cur].cnt++;       }     }   }   int n;   void calc_costs() {     for (int i = n; i >= 1; i--) {       add_number(a[i]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     calc_costs();     long long ans = 0;     int x = 0;     for (int i = 0; i < 31; i++) {       if (cost_if_set[i][0] <= cost_if_set[i][1]) {         ans += cost_if_set[i][0];       } else {         x |= (1ll << i);         ans += cost_if_set[i][1];       }     }     cout << ans <<     << x <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int tc;     cin >> tc;     while (tc--) {       long long l, r;       cin >> l >> r;       long long i = 1;       while ((l | i) <= r) {         l |= i;         i <<= 1;       }       cout << l <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   basic_string<int> e[500005][2];   basic_string<int> f[500005][2];   int n, m;   int d[500005], w[500005][2];   const int inf = 123123123;   int main() {     ios::sync_with_stdio(!cin.tie(0));     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v, t;       cin >> u >> v >> t;       e[u][t] += v;       f[v][t] += u;     }     for (int i = 1; i <= n; i++) {       d[i] = w[i][0] = w[i][1] = inf;     }     d[n] = 0;     set<pair<int, int>> pq;     pq.insert({d[n], n});     while (pq.size()) {       auto [dx, x] = *pq.begin();       pq.erase(pq.begin());       for (int c = 0; c < 2; c++) {         for (int y : f[x][c]) {           w[y][c] = min(w[y][c], dx);           int dy = max(w[y][0], w[y][1]) + 1;           if (dy < d[y]) {             pq.erase({d[y], y});             d[y] = dy;             pq.insert({d[y], y});           }         }       }     }     cout << (d[1] > inf / 2 ? -1 : d[1]) <<   n ;     for (int i = 1; i <= n; i++) {       cout << (w[i][0] < w[i][1]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXS = 75, MAXK = 10, MAXQ = 30;   const long long INF = 0x3f3f3f3f3f3f3f3f;   int x, k, n, q, c[MAXK];   struct node {     int p, w;   } d[MAXQ];   bool operator<(const node &aa, const node &bb) { return aa.p < bb.p; }   int sta[MAXS], scn, cnt[300], id[300];   struct Matrix {     long long s[MAXS][MAXS];     Matrix() { memset(s, 0x3f, sizeof(s)); }   } X, A, pw[30];   Matrix operator*(const Matrix &aa, const Matrix &bb) {     Matrix cc;     for (int i = 1; i <= scn; i++)       for (int j = 1; j <= scn; j++)         for (int k = 1; k <= scn; k++)           cc.s[i][j] = min(cc.s[i][j], aa.s[i][k] + bb.s[k][j]);     return cc;   }   void build_pw() {     pw[0] = X;     for (int i = 1; i < 30; i++) pw[i] = pw[i - 1] * pw[i - 1];   }   Matrix get(int a) {     Matrix ret;     for (int i = 1; i <= scn; i++) ret.s[i][i] = 0;     for (int i = 0; i < 30; i++)       if (a >> i & 1) ret = ret * pw[i];     return ret;   }   int main() {     scanf( %d%d%d%d , &x, &k, &n, &q);     for (int i = 1; i <= k; i++) scanf( %d , &c[i]);     for (int i = 1; i <= q; i++) scanf( %d%d , &d[i].p, &d[i].w);     sort(d + 1, d + q + 1);     for (int s = 1; s < (1 << k); s++) {       cnt[s] = cnt[s >> 1] + (s & 1);       if (cnt[s] == x) sta[++scn] = s, id[s] = scn;     }     for (int i = 1; i <= scn; i++) {       if (sta[i] & 1) {         for (int j = 1; j <= k; j++)           if (!(sta[i] >> j & 1)) X.s[i][id[(sta[i] | (1 << j)) >> 1]] = c[j];       } else         X.s[i][id[sta[i] >> 1]] = 0;     }     build_pw();     int cur = 1;     long long delta = 0;     for (int i = 1; i <= scn; i++) A.s[i][i] = 0;     for (int i = 1; i <= q; i++) {       if (d[i].p > n - x)         delta += d[i].w;       else {         A = A * get(d[i].p - cur), cur = d[i].p;         for (int j = 1; j <= scn; j++)           for (int k = 1; k <= scn; k++)             if (sta[k] & 1) A.s[j][k] += d[i].w;       }     }     A = A * get(n - x + 1 - cur);     printf( %lld n , A.s[1][1] + delta);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 507;   const long long INF = 1e9 + 7;   long long n, m, mod;   long long Pow(long long x, long long y) {     long long ans = 1, now = x;     while (y) {       if (y & 1) ans = ans * now % mod;       now = now * now % mod;       y >>= 1;     }     return ans;   }   long long fac[N], inv[N], f[N], g[N], F[N][N], G[N][N];   long long C(long long x, long long y) {     return fac[x] * inv[y] % mod * inv[x - y] % mod;   }   int main() {     scanf( %lld%lld%lld , &n, &m, &mod);     fac[0] = 1;     for (long long i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % mod;     inv[n] = Pow(fac[n], mod - 2);     for (long long i = n; i; i--) inv[i - 1] = inv[i] * i % mod;     f[0] = 1;     for (long long i = 1; i <= n; i++) {       f[i] = g[i] = 0;       for (long long j = 1; j <= i; j++) {         f[i] =             (f[i] + f[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod * (i + 1)) %             mod;         g[i] =             (g[i] + f[j - 1] * g[i - j] % mod * C(i - 1, j - 1) % mod * (i + 1)) %             mod;         g[i] =             (g[i] + g[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod * (i + 1)) %             mod;         g[i] = (g[i] + f[j - 1] * f[i - j] % mod * C(i - 1, j - 1) % mod *                            ((j - 1) * j / 2 + (i - j) * (i - j + 1) / 2)) %                mod;       }     }     F[0][0] = 1;     for (long long i = 1; i <= n; i++) {       F[i][i] = f[i];       G[i][i] = g[i];     }     for (long long i = 0; i <= n - 1; i++) {       for (long long j = 0; j <= m + 1 - 1; j++) {         F[i + 1][j] = (F[i + 1][j] + F[i][j]) % mod;         G[i + 1][j] = (G[i + 1][j] + G[i][j]) % mod;         for (long long k = 1; k <= n; k++) {           if (j + k > m || i + k + 1 > n) break;           F[i + k + 1][j + k] =               (F[i + k + 1][j + k] + F[i][j] * f[k] % mod * C(j + k, k)) % mod;           G[i + k + 1][j + k] =               (G[i + k + 1][j + k] +                (G[i][j] * f[k] + F[i][j] * g[k]) % mod * C(j + k, k)) %               mod;         }       }     }     printf( %lld n , G[n][m]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t-- > 0) {       int n;       string s;       cin >> n >> s;       vector<int> a(n, 0), b(n, 0), c;       int flag1 = 1, flag2 = 1;       for (int i = 0; i < n - 1; i++) {         if (s[i] ==  < ) {           b[i] = flag1++;         }       }       for (int i = n - 2; i >= 0; i--) {         if (s[i] ==  < ) {           while (i > 0 && s[i - 1] ==  < ) {             i--;           }           int x = i;           while (s[x] ==  < ) {             a[x] = flag2++;             x++;           }         }       }       for (int i = n - 1; i >= 0; i--) {         if (b[i] == 0) {           b[i] = flag1++;         }         if (a[i] == 0) {           a[i] = flag2++;         }       }       for (int i = 0; i < n; i++) {         cout << a[i] <<    ;       }       cout <<   n ;       for (int i = 0; i < n; i++) {         cout << b[i] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x[100005], h[100005];     cin >> n;     for (int i = 0; i < n; ++i) cin >> x[i] >> h[i];     int count = 1;     int newarr[100005];     newarr[1] = x[0] - h[0];     for (int i = 1; i < n - 1; ++i) {       if ((x[i] - h[i] > x[i - 1]) && (x[i] - h[i] > newarr[count])) {         count++;         newarr[count] = x[i] - h[i];       } else if (x[i] + h[i] < x[i + 1]) {         count++;         newarr[count] = x[i] + h[i];       } else         continue;     }     if (n == 1)       puts( 1 );     else       cout << count + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> cnt1, cnt2;   const int maxn = 1e5 * 3;   int x[maxn];   int y[maxn];   int main() {     int n = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];       cnt1[x[i] - y[i]]++;       cnt2[x[i] + y[i]]++;     }     long long ans = 0;     for (int i = 0; i < n; i++) {       long long c1 = cnt1[x[i] - y[i]];       long long c2 = cnt2[x[i] + y[i]];       ans += c1 + c2 - 2;     }     cout << ans / 2;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     string s[n];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j <= i; j++) cout <<  ( ;       for (long long j = 0; j <= i; j++) cout <<  ) ;       for (long long j = 0; j < n - i - 1; j++) cout <<  () ;       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1, x = 0;     cin >> t;     while (t--) {       x++;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int K = 269;   const int MS = 2;   const int MOD[MS] = {(int)1e9 + 7, (int)1e9 + 9};   const int MAXN = 1e6 + 69;   using hsh = vector<long long>;   struct hj {     int shift = MS == 1 ? 0 : 32 / (MS - 1);     size_t operator()(const hsh& h) const {       long long res = 0;       for (int M = 0; M < MS; M++) res <<= shift, res ^= h[M];       return res;     }   };   int t;   int n;   set<int> a[MAXN];   unordered_map<hsh, int, hj> mp;   vector<string> str;   int check[MAXN];   int cnt;   int ans;   void build(hsh& h, char c) {     for (int M = 0; M < MS; M++) h[M] = (c + h[M] * K) % MOD[M];   }   void init() {     for (int i = 1; i <= cnt; i++) {       a[i].clear();       check[i] = 0;     }     mp.clear();     cnt = 0;     ans = 0;   }   bool dfs(int u) {     check[u] = 1;     int tookChild = 0;     for (int v : a[u])       if (!check[v]) tookChild |= dfs(v);     ans += tookChild ^ 1;     return tookChild ^ 1;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> t;     while (t--) {       init();       cin >> n;       str.resize(n + 1);       for (int i = 1; i <= n; i++) cin >> str[i], str[i] =     + str[i];       for (int i = 1; i <= n; i++) {         string& s = str[i];         hsh h(MS);         for (int j = 1; j < (int)s.size(); j++) {           build(h, s[j]);           if (!mp.count(h)) mp[h] = ++cnt;         }       }       for (int i = 1; i <= n; i++) {         string& s = str[i];         hsh h(MS), h2(MS);         for (int j = 1; j < (int)s.size(); j++) {           build(h, s[j]);           if (j >= 2) {             build(h2, s[j]);             if (mp.count(h2)) {               int u = mp[h], v = mp[h2];               a[u].insert(v);               a[v].insert(u);             }           }         }       }       for (int i = 1; i <= cnt; i++)         if (!check[i]) dfs(i);       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a, b;   int dp[55][55][4];   int f(int n, int m, int p) {     if ((n == m && n == 0) || (n == 0 && p == 1) || (m == 0 && p == 2)) {       return dp[n][m][p] = 0;     }     if (dp[n][m][p] != -1) {       return dp[n][m][p];     }     bool g = 0;     if (p == 1) {       for (int i = 1; i <= min(a, n); i++) {         g = (g || (!f(n - i, m, 2)));       }     } else {       for (int i = 1; i <= min(b, m); i++) {         g = (g || (!f(n, m - i, 1)));       }     }     return dp[n][m][p] = g;   }   int main() {     int n, m;     cin >> n >> m >> a >> b;     memset(dp, -1, sizeof(dp));     if (f(n, m, 1)) {       cout <<  First ;     } else {       cout <<  Second ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 40 + 2;   int n, m, q, dp[maxn][maxn][maxn][maxn], ones[maxn][maxn], a, b, c, d;   int main() {     ios::sync_with_stdio(false);     char ch;     cin >> n >> m >> q;     for (int _b = (n), i = (1); i <= _b; ++i)       for (int _b = (m), j = (1); j <= _b; ++j) {         cin >> ch;         ones[i][j] =             ones[i - 1][j] + ones[i][j - 1] - ones[i - 1][j - 1] + ch -  0 ;       }     for (int _b = (n - 1), h = (0); h <= _b; ++h)       for (int _b = (m - 1), w = (0); w <= _b; ++w)         for (int _b = (n - h), i = (1); i <= _b; ++i)           for (int _b = (m - w), j = (1); j <= _b; ++j) {             a = i, b = j, c = i + h, d = j + w;             dp[a][b][c][d] = ((ones[c][d] - ones[a - 1][d] - ones[c][b - 1] +                                ones[a - 1][b - 1]) == 0);             for (int _b = ((1 << 4) - 1), mask = (1); mask <= _b; ++mask) {               dp[a][b][c][d] += (-1 + 2 * (__builtin_popcount(mask) & 1)) *                                 dp[a + (mask >> 0 & 1)][b + (mask >> 1 & 1)]                                   [c - (mask >> 2 & 1)][d - (mask >> 3 & 1)];             }           }     while (q--) {       cin >> a >> b >> c >> d;       cout << dp[a][b][c][d] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, mas[1000], ans[1000], anss;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> mas[i];     for (int i = 2; i <= n; i++) {       if (mas[i] + mas[i - 1] < k) {         anss += k - mas[i - 1] - mas[i];         mas[i] = k - mas[i - 1];       }     }     cout << anss <<   n ;     for (int i = 1; i <= n; i++) cout << mas[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   inline long long read() {     long long num = 0, neg = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) neg = -1;       c = getchar();     }     while (isdigit(c)) {       num = (num << 3) + (num << 1) + c -  0 ;       c = getchar();     }     return num * neg;   }   int got[21], n, m, id[1000010], id_cnt;   int stk[21], tot, f[2000010];   bool vis[1000010];   int cnt, to[2000010], nxt[2000010], head[1000010], in[1000010], out[1000010];   inline void insert(int x, int y) {     to[++cnt] = y, nxt[cnt] = head[x], head[x] = cnt;     out[x]++, in[y]++;   }   inline void dfs(int u, int s) {     vis[u] = s;     if (id[u]) {       got[s] |= (1 << id[u] - 1);     }     for (int i = head[u]; i; i = nxt[i]) {       int v = to[i];       if (vis[v] == s) continue;       dfs(v, s);     }     return;   }   inline int getcnt(int x) {     int res = 0;     while (x) res++, x -= x & -x;     return res;   }   int main() {     n = read(), m = read();     for (int i = 1, x, y; i <= m; i++) x = read(), y = read(), insert(x, y);     for (int i = 1; i <= n; i++)       if (!out[i]) id[i] = ++id_cnt;     for (int i = 1; i <= n; i++)       if (!in[i]) {         stk[++tot] = i;         dfs(i, i);       }     for (int i = 1; i <= tot; i++)       for (int j = 0; j < (1 << tot); j++) f[j | (1 << i - 1)] |= got[stk[i]];     for (int j = 1; j < (1 << tot) - 1; j++) {       if (getcnt(j) == getcnt(f[j])) {         printf( NO n );         return 0;       }     }     printf( YES n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   long long c[N << 2], a[N];   void pushup(int rt) { c[rt] = c[rt << 1] | c[rt << 1 | 1]; }   void build(int rt, int l, int r) {     if (l == r) {       scanf( %I64d , c + rt);       a[l] = c[rt];       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   long long query(int rt, int l, int r, int x, int y) {     if (x > y) return 0;     if (x <= l && r <= y) {       return c[rt];     }     int mid = (l + r) >> 1;     long long ret = 0;     if (x <= mid) ret |= query(rt << 1, l, mid, x, y);     if (mid < y) ret |= query(rt << 1 | 1, mid + 1, r, x, y);     return ret;   }   int main() {     int n, k, c;     while (~scanf( %d%d%d , &n, &c, &k)) {       long long tmp = 1;       for (int i = 1; i <= c; i++) {         tmp *= k;       }       build(1, 1, n);       long long ans = (tmp * a[1]) | query(1, 1, n, 2, n);       ans = max(ans, (tmp * a[n]) | query(1, 1, n, 1, n - 1));       for (int i = 2; i < n; i++) {         ans = max(ans, query(1, 1, n, 1, i - 1) | (tmp * a[i]) |                            query(1, 1, n, i + 1, n));       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     set<int> col[26];     vector<int> ans;     int cnt = 0;     for (int i = 0; i < n; i++) {       set<int> used;       for (int j = s[i] -  a  + 1; j < 26; j++)         for (int num : col[j]) used.insert(num);       int newCol = 1;       while (used.count(newCol)) newCol++;       col[s[i] -  a ].insert(newCol);       ans.push_back(newCol);       cnt = max(cnt, newCol);     }     cout << cnt <<   n ;     for (int i : ans) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10;   double ans;   int a[N];   int n, u, p;   int main() {     scanf( %d%d , &n, &u);     ans = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);     }     for (int i = 1; i <= n; i++) {       if (i <= n - 2) {         p = lower_bound(a + i + 2, a + n + 1, a[i] + u) - a;         if (p > n || a[i] + u != a[p]) p--;         if (p >= i + 2) {           ans = max(ans, (a[p] - a[i + 1]) * 1.0 / (a[p] - a[i]));         }       }     }     if (ans == 0)       printf( -1 n );     else       printf( %.11lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, ans = -1, dist[2020];   vector<int> adj[2020], vet;   int main() {     scanf( %d%d , &n, &k);     for (int(i) = (0); (i) < (k); (i)++) {       int v;       scanf( %d , &v);       vet.push_back(v - n);     }     sort((vet).begin(), (vet).end());     vet.resize(unique((vet).begin(), (vet).end()) - vet.begin());     for (int(i) = (0); (i) < (2020); (i)++)       for (int(j) = (0); (j) < (((int)(vet).size())); (j)++)         if (i + vet[j] >= 0 && i + vet[j] < 2020) adj[i].push_back(i + vet[j]);     queue<int> fila;     fila.push(1010);     while (!fila.empty()) {       int v = fila.front();       fila.pop();       if (v == 1010 && dist[v]) {         ans = dist[v];         break;       }       for (int(i) = (0); (i) < (((int)(adj[v]).size())); (i)++)         if (!dist[adj[v][i]]) dist[adj[v][i]] = dist[v] + 1, fila.push(adj[v][i]);     }     printf( %d n , ans);   }