malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   bool reachable(vector<set<int>> g, int u, int v) {     if (g[u].find(v) == g[u].end()) {       for (auto x : g[u]) {         if (g[x].find(v) != g[x].end()) return true;       }     } else {       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     set<pair<int, int>> edges;     set<int> badnodes;     while (m--) {       int x, y;       cin >> x >> y;       --x;       --y;       edges.insert({x, y});       edges.insert({y, x});       badnodes.insert(x);       badnodes.insert(y);     }     int c = 0;     for (int u = 0; u < n; ++u) {       if (badnodes.find(u) == badnodes.end()) c = u;     }     cout << n - 1 << endl;     vector<set<int>> g(n);     for (int u = 0; u < n; ++u) {       if (u == c) continue;       if (reachable(g, u, c)) continue;       if (edges.find({u, c}) == edges.end()) {         g[c].insert(u);         g[u].insert(c);         cout << c + 1 <<     << u + 1 << endl;       } else {         for (int v = 0; v < n; ++v) {           if (edges.find({u, v}) == edges.end()) {             g[u].insert(v);             g[v].insert(u);             cout << u + 1 <<     << v + 1 << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long parent[200001], Size[200001];   long long find_set(long long x) {     if (x == parent[x]) return parent[x];     return parent[x] = find_set(parent[x]);   }   void Union(long long x, long long y) {     x = find_set(x);     y = find_set(y);     if (Size[x] > Size[y]) {       parent[y] = parent[x];       Size[x] += Size[y];     } else {       parent[x] = parent[y];       Size[y] += Size[x];     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long t;     cin >> t;     while (t--) {       long long n, k;       cin >> n >> k;       string s;       cin >> s;       for (long long i = 0; i <= n; i++) {         parent[i] = i;         Size[i] = 1;       }       for (long long i = 0; i < n - k; i++) {         Union(i, i + k);         if (i < n / 2) Union(i, n - i - 1);       }       vector<long long> v[n + 1];       for (long long i = 0; i < n; i++) {         long long p = find_set(i);         v[p].push_back(s[i] -  a );       }       long long ans = 0;       for (long long i = 0; i < n; i++) {         if (v[i].size() == 0) continue;         map<long long, long long> mm;         for (auto j : v[i]) {           mm[j]++;         }         long long Max = INT_MIN;         for (auto i : mm) Max = max(Max, i.second);         ans += v[i].size() - Max;       }       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   const int MNN = 2e3 + 1;   using namespace std;   int n, b[MNN][MNN], mx;   bool used[MNN];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         cin >> b[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         mx = max(mx, b[i][j]);       }       if (used[mx] == 1) {         cout << mx + 1 <<    ;         used[mx + 1] = 1;       } else {         cout << mx <<    ;         used[mx] = 1;       }       mx = 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename G>   struct triple {     G first, second, T;   };   struct BIT {     vector<int> v;     BIT(int n) : v(n + 10) {}     void upd(int p) {       for (; p < v.size(); p += (p & (-p))) ++v[p];     }     int query(int p) {       int x = 0;       for (; p > 0; p -= (p & (-p))) x += v[p];       return x;     }   };   struct fraction {     long long x, y;     bool operator<(fraction o) { return x * o.y < y * o.x; }     bool operator>(fraction o) { return x * o.y > y * o.x; }     bool operator!=(fraction o) { return x * o.y != y * o.x; }   };   struct info {     fraction f1, f2;     int ind;     info(long long x, long long v, long long _ind, long long w) : ind(_ind) {       f1 = {abs(x), abs(v - w)};       f2 = {abs(x), abs(v + w)};     }   };   bool cmp1(info x, info y) {     if (x.f1 != y.f1) return x.f1 < y.f1;     if (x.f2 != y.f2) return x.f2 > y.f2;     return x.ind < y.ind;   }   bool cmp2(info x, info y) {     if (x.f2 != y.f2) return x.f2 < y.f2;     if (x.f1 != y.f1) return x.f1 > y.f1;     return x.ind > y.ind;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, w;     cin >> n >> w;     vector<info> a;     for (int i = 0; i < n; i++) {       int x, v;       cin >> x >> v;       a.push_back({x, v, i, w});     }     vector<int> t1(n), t2(n);     sort(a.begin(), a.end(), cmp1);     for (int i = 0; i < n; i++) t1[i] = a[i].ind;     sort(a.begin(), a.end(), cmp2);     for (int i = 0; i < n; i++) t2[i] = a[i].ind;     vector<int> p(n);     for (int i = 0; i < n; i++) p[t1[i]] = i + 1;     long long ans = 0;     BIT abi(n);     for (int i = 0; i < n; i++) {       ans += i - abi.query(p[t2[i]]);       abi.upd(p[t2[i]]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   vector<int> t[N], f[2], f0[2];   int n, c0[N * 2], lim[N];   void add(int x) {     for (; x <= n * 2; x += (x & (-x))) c0[x]++;   }   int query(int x) {     int ret = 0;     for (; x; x -= (x & (-x))) ret += c0[x];     return ret;   }   void up(int &a, int b) {     if (a == -1 || a > b) a = b;   }   int main() {     int k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= k; i++) {       int r, c, x, y;       scanf( %d%d , &r, &c);       t[c].push_back(n - r + 1);     }     for (int i = n; i; i--)       if (t[i].size()) {         sort(t[i].begin(), t[i].end());         for (int j = 0; j <= t[i].size() - 1; j++) add(i + t[i][j]);         for (int j = t[i].size() - 1; j >= 0; j--)           if (t[i][j] * (t[i][j] + 1) / 2 + 2 <= query(i + t[i][j]) * 3) {             lim[i] = t[i][j];             break;           }         if (lim[i + 1] + 1 > lim[i] &&             (lim[i + 1] + 1) * (lim[i + 1] + 2) / 2 + 2 <=                 query(i + lim[i + 1] + 1) * 3)           lim[i] = lim[i + 1] + 1;       }     for (int i = 1; i <= n; i++) {       lim[i] = max(lim[i], lim[i - 1] - 1);       lim[i] = min(800, n - i + 1);     }     f[0].resize(800 + 1, 1e9);     f0[0].resize(800 + 1, 1e9);     f[1].resize(800 + 1, 1e9);     f0[1].resize(800 + 1, 1e9);     f0[0][0] = 0;     for (int i = 0; i <= n; i++) {       int cnt = t[i].size(), ll = 0;       int i0 = i & 1, i1 = (i + 1) & 1;       for (int j = 0; j <= lim[i]; j++) {         if (ll <= (int)t[i].size() - 1 && j == t[i][ll]) cnt--, ll++;         if (j < lim[i]) {           up(f[i0][j + 1], f[i0][j] + j + 1);           up(f[i0][j + 1], f0[i0][j] + (j + 1) * (j + 2) / 2 + 2);         }         if (j) {           up(f0[i1][j - 1], f0[i0][j] + cnt * 3);           up(f0[i1][j - 1], f[i0][j] + cnt * 3);         } else {           up(f0[i1][j], f0[i0][j] + cnt * 3);           up(f0[i1][j], f[i0][j] + cnt * 3);         }         f[i0][j] = f0[i0][j] = 1e9;       }     }     printf( %d n , f0[(n + 1) & 1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   bool prime[N + 5];   int vis[11111];   int main() {     int tc = 1;     cin >> tc;     while (tc--) {       int n;       int m;       cin >> n >> m;       int ara[n + 1];       for (int i = 0; i < n; i++) {         cin >> ara[i];       }       if (m < n || n == 2) {         cout <<  -1  << endl;         continue;       } else {         int sum = 0;         for (int i = 0; i < n - 1; i++) {           sum += ara[i];           sum += ara[i + 1];         }         sum += ara[n - 1];         sum += ara[0];         cout << sum << endl;         for (int i = 1; i < n; i++) {           cout << i <<     << i + 1 << endl;         }         cout << 1 <<     << n << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int N, M, Max = 0, Maxj = 0, A[1000][1000], arr[1000][1] = {};   int main() {     cin >> N >> M;     for (int i = 0; i < M; i++) {       Max = -1;       for (int j = 0; j < N; j++) {         cin >> A[i][j];         if (Max < A[i][j]) {           Max = A[i][j];           Maxj = j;         }       }       arr[Maxj][0]++;     }     long long int max = 0, ind = 1;     for (int i = 0; i < N; i++) {       if (max < arr[i][0]) {         max = arr[i][0];         ind = i + 1;       }     }     cout << ind;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2 * 1e5 + 100;   long long n, k, s, t, c[N], v[N], g[N], d[N], sum[N];   inline long long read() {     long long f = 1, x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     return x * f;   }   signed main() {     n = read();     k = read();     s = read();     t = read();     for (long long i = 1; i <= n; i++) c[i] = read(), v[i] = read();     for (long long i = 1; i <= k; i++) g[i] = read();     sort(g + 1, g + 1 + k);     for (long long i = 1; i <= k; i++) d[i] = g[i] - g[i - 1];     d[k + 1] = s - g[k];     k++;     sort(d + 1, d + 1 + k);     for (long long i = 1; i <= k; i++) sum[i] = sum[i - 1] + d[i];     if (t < s) {       printf( -1 n );       return 0;     }     long long MIN = 0x3f3f3f3f;     for (long long i = 1; i <= n; i++) {       if (v[i] < d[k]) continue;       long long pos = upper_bound(d + 1, d + 1 + k, v[i] / 2) - d - 1;       long long all = sum[pos] + (sum[k] - sum[pos]) * 3 - (k - pos) * v[i];       if (all <= t) MIN = min(MIN, c[i]);     }     if (MIN == 0x3f3f3f3f)       printf( -1 n );     else       printf( %lld n , MIN);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     long long vmax = n - (m - 1);     long long kmax = vmax * (vmax - 1) / 2;     long long vmin = n / m;     long long vmin_add = n - vmin * m;     long long kmin =         (m - vmin_add) * vmin * (vmin - 1) / 2 + vmin_add * (vmin + 1) * vmin / 2;     cout << kmin <<     << kmax;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d, maxi1, maxi2;     cin >> a >> b >> c >> d;     maxi1 = max(((3 * a) / 10), (a - ((a / 250) * c)));     maxi2 = max(((3 * b) / 10), (b - ((b / 250) * d)));     if (maxi1 == maxi2) {       cout <<  Tie n ;     } else if (maxi2 > maxi1) {       cout <<  Vasya n ;     } else {       cout <<  Misha n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; }   inline int read() {     int x = 0, f = 1;     char cc = getchar();     while (cc <  0  || cc >  9 ) {       if (cc ==  - ) f = -1;       cc = getchar();     }     while (cc >=  0  && cc <=  9 ) {       x = x * 10 + cc -  0 ;       cc = getchar();     }     return x * f;   }   const int maxn = 100;   int c[maxn];   int n, a, b;   int main() {     n = read();     a = read();     b = read();     int cost = 0;     for (int i = 0; i < n; i++) scanf( %d , c + i);     for (int i = 0; i < n / 2; i++) {       if (c[i] != 2 && c[n - 1 - i] != 2) {         if (c[i] != c[n - 1 - i]) {           puts( -1 );           return 0;         }       } else if (c[i] == 1 || c[n - i - 1] == 1) {         cost += b;       } else if (c[i] == 2 && c[n - i - 1] == 2) {         cost += 2 * min(a, b);       } else         cost += a;     }     if (n % 2) {       if (c[n / 2] == 2) {         cost += min(a, b);       }     }     cout << cost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class ConvexHullTrick {    public:     vector<long long int> a, b;     int size = -1;     bool can_remove(int a, int b, int c, int d) {       if (a / b != c / d) return a / b < c / d;       a %= b;       c %= d;       if (a == 0) return true;       if (c == 0) return false;       return can_remove(d, c, b, a);     }     void add(long long int i, long long int j) {       size++;       a.push_back(i);       b.push_back(j);       while (size >= 2 &&              can_remove(b[size - 1] - b[size], a[size] - a[size - 1],                         b[size - 2] - b[size - 1], a[size - 1] - a[size - 2])) {         a.erase(a.end() - 2);         b.erase(b.end() - 2);         size--;       }     }     double iniInterval(int i) {       if (i == 0) return -1000000010;       return ((double)b[i] - b[i - 1]) / (a[i - 1] - a[i]);     }     long long int query(int x) {       int i = 0, j = size;       while (i < j) {         int m = (i == j - 1) ? j : (i + j) / 2;         if (iniInterval(m) <= (double)x)           i = m;         else           j = m - 1;       }       return a[i] * x + b[i];     }   };   struct node {     int ini, fim;     ConvexHullTrick CHT;   } SEG[4 * 100010];   int n, q, n1, n2;   int v[100010];   long long int sv[100010];   void merge(int i, int f1, int f2) {     int p = 0, q = 0;     for (; p <= SEG[f1].CHT.size && q <= SEG[f2].CHT.size;) {       long long int a1 = SEG[f1].CHT.a[p];       long long int b1 = SEG[f1].CHT.b[p];       long long int a2 = SEG[f2].CHT.a[q];       long long int b2 = SEG[f2].CHT.b[q];       if (a1 == a2) {         SEG[i].CHT.add(a1, min(b1, b2));         p++;         q++;       } else if (a1 > a2) {         SEG[i].CHT.add(a1, b1);         p++;       } else {         SEG[i].CHT.add(a2, b2);         q++;       }     }     for (; p <= SEG[f1].CHT.size;) {       SEG[i].CHT.add(SEG[f1].CHT.a[p], SEG[f1].CHT.b[p]);       p++;     }     for (; q <= SEG[f2].CHT.size;) {       SEG[i].CHT.add(SEG[f2].CHT.a[q], SEG[f2].CHT.b[q]);       q++;     }   }   void build(int id, int i, int j) {     SEG[id].ini = i;     SEG[id].fim = j;     if (i == j) return void(SEG[id].CHT.add(v[i], v[i] * i - sv[i]));     int m = (i + j) / 2;     build(2 * id, i, m);     build(2 * id + 1, m + 1, j);     merge(id, 2 * id, 2 * id + 1);   }   long long int query(int id, int i, int j, int k) {     if (SEG[id].ini > j || SEG[id].fim < i)       return ((long long int)1000000010) * 1000000010;     if (SEG[id].ini >= i && SEG[id].fim <= j) return SEG[id].CHT.query(k);     return min(query(2 * id, i, j, k), query(2 * id + 1, i, j, k));   }   int main() {     scanf( %d , &n);     for (int g = 1; g <= n; g++) {       scanf( %d , &v[g]);       sv[g] = sv[g - 1] + v[g];     }     build(1, 1, n);     scanf( %d , &q);     for (int g = 0; g < q; g++) {       scanf( %d %d , &n1, &n2);       printf( %lld n , query(1, n2 - n1 + 1, n2, n1 - n2) + sv[n2]);     }   }
#include <bits/stdc++.h>   using namespace std;   int bits(int num) {     int c = 0;     while (num > 0) {       c++;       num = num / 2;     }     return c;   }   int main() {     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int i;       long long int a[n];       for (i = 0; i < n; i++) cin >> a[i];       vector<long long int> v;       for (i = 0; i < n; i++) {         int temp = bits(a[i]);         v.push_back(temp);       }       map<long long int, long long int> mp;       for (i = 0; i < v.size(); i++) {         mp[v[i]]++;       }       long long int ans = 0;       map<long long int, long long int>::iterator it;       for (it = mp.begin(); it != mp.end(); it++) {         ans = ans + ((it->second) * (it->second - 1)) / 2;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[100][100];   vector<long long> can;   int test;   int r(long long a, long long b) {     if ((a == 0) || (b == 0)) return 0;     int k = r(b % a, a);     if (k == 0) return 1;     long long v = (b % a);     v += a;     long long c = (b - v) / a;     if (a & 1) {       int res = (c & 1);       return res;     }     c %= (a + 1);     if (c == a) return 1;     int res = (c & 1);     return res;   }   int brut(int a, int b) {     if (dp[a][b] != -1) return dp[a][b];     if ((a == 0) || (b == 0)) return 0;     int res = brut(b % a, a);     if (res == 0) return dp[a][b] = 1;     int v = a;     while (b - v >= 0) {       int nb = b - v;       res = min(res, brut(min(nb, a), max(nb, a)));       v *= a;     }     res ^= 1;     return dp[a][b] = res;   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long a, b;       cin >> a >> b;       if (a > b) swap(a, b);       int res = r(a, b);       if (res)         printf( First n );       else         printf( Second n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   const int LOG = 20;   const int CNTSZ = 30;   const long long INF = 1e18;   const int MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     vector<pair<long long, pair<int, int>>> edges(m);     for (int i = 0; i < int(m); i++) {       cin >> edges[i].second.first >> edges[i].second.second >> edges[i].first;       edges[i].second.first--;       edges[i].second.second--;     }     sort(edges.begin(), edges.end());     set<int> vrt;     for (int i = 0; i < int(min(m, k)); i++)       vrt.insert(edges[i].second.first), vrt.insert(edges[i].second.second);     vector<int> vertex;     for (int x : vrt) vertex.push_back(x);     n = (int)(vrt).size();     vector<vector<long long>> dp(n, vector<long long>(n, INF));     for (int i = 0; i < int(n); i++) dp[i][i] = 0;     for (int i = 0; i < int(min(m, k)); i++) {       int u =           (int)(lower_bound(vertex.begin(), vertex.end(), edges[i].second.first) -                 vertex.begin());       int v = (int)(lower_bound(vertex.begin(), vertex.end(),                                 edges[i].second.second) -                     vertex.begin());       dp[u][v] = dp[v][u] = min(dp[u][v], edges[i].first);     }     for (int l = 0; l < int(n); l++) {       for (int i = 0; i < int(n); i++) {         for (int j = 0; j < int(n); j++) {           dp[i][j] = min(dp[i][j], dp[i][l] + dp[l][j]);         }       }     }     vector<long long> ans;     for (int i = 0; i < int(n); i++)       for (int j = 0; j < int(i); j++) ans.push_back(dp[i][j]);     sort(ans.begin(), ans.end());     cout << ans[k - 1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ako {     int b2, c2, d;     ako(int B = -1, int C = -1, int D = -1) : b2(B), c2(C), d(D) {}   };   const int minb = -2000, maxb = 4000, maxa = 1005;   ako vis[maxb - minb + 79][maxa];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int a;     cin >> a;     queue<pair<int, int>> q;     q.push({0, 0});     while (!q.empty() && vis[-minb][0].d == -1) {       int b = q.front().first, c = q.front().second;       q.pop();       for (int d = 0; d < 10; d++) {         if (b == 0 && c == 0 && d == 0) continue;         int nwb = b + a * ((c + a * d) % 10) - d, nwc = (c + a * d) / 10;         if (minb > nwb || maxb < nwb || vis[nwb - minb][nwc].d != -1) continue;         vis[nwb - minb][nwc] = ako(b, c, d);         q.push({nwb, nwc});       }     }     string ans;     if (vis[-minb][0].d != -1) {       int b = 0, c = 0;       while (true) {         ako k = vis[b - minb][c];         if (!ans.empty() || k.d) ans.push_back( 0  + k.d);         if (k.b2 == 0 && k.c2 == 0) break;         tie(b, c) = {k.b2, k.c2};       }     } else       ans =  -1 ;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[1005][2];   char M[1005][1005];   struct Node {     int l = 0, r = 0;     int p;   } L[1005], R[1005];   int n, m;   int v[1005];   void Cal(int i) {     L[i].l = L[i].p;     R[i].l = R[i].p;     L[i].r = m - 1 - L[i].p;     R[i].r = m - 1 - R[i].p;   }   int main() {     scanf( %d%d , &n, &m);     m += 2;     memset(v, 0, sizeof(v));     int Layer = -1;     for (int i = 0; i < n; i++) {       scanf( %s , M[i]);       L[i].p = 0;       R[i].p = n;       for (int j = 0; j < m; j++) {         if (M[i][j] ==  1 ) {           if (!L[i].p) L[i].p = j;           R[i].p = j;           if (Layer == -1) Layer = i;           v[i] = 1;         }       }       Cal(i);     }     d[n][0] = -1;     d[n][1] = m - 1;     if (Layer == -1) {       cout <<  0  << endl;       return 0;     }     for (int i = n - 1; i > Layer; i--) {       if (!v[i]) {         d[i][0] = d[i + 1][0] + 1;         d[i][1] = d[i + 1][1] + 1;         continue;       }       d[i][0] = min(d[i + 1][1] + m - 1, d[i + 1][0] + 2 * R[i].l) + 1;       d[i][1] = min(d[i + 1][0] + m - 1, d[i + 1][1] + 2 * L[i].r) + 1;     }     printf( %d n ,            1 + min(d[Layer + 1][0] + R[Layer].l, d[Layer + 1][1] + L[Layer].r));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     stack<char> s;     for (int i = 0; i < a.size(); i++) {       if (s.empty() || s.top() != a[i])         s.push(a[i]);       else         s.pop();     }     if (s.empty())       cout <<  Yes ;     else       cout <<  No ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, m, s;     cin >> n >> d;     vector<pair<int, int> > v;     vector<int> money;     for (int i = 0; i < n; i++) {       cin >> m >> s;       pair<int, int> p = make_pair(m, s);       v.push_back(p);       money.push_back(m);     }     sort(v.begin(), v.end());     sort(money.begin(), money.end());     vector<unsigned long long> pref;     pref.push_back(0);     int i;     for (i = 0; i < n; i++) {       pref.push_back(v[i].second + pref[i]);     }     for (i = 0; i <= n; i++) {     }     unsigned long long max = 0;     int index;     for (i = 0; i < n; i++) {       vector<int>::iterator up;       up = upper_bound(money.begin(), money.end(), v[i].first + d - 1);       if (pref[up - money.begin()] - pref[i] > max)         max = pref[up - money.begin()] - pref[i];     }     cout << max << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[11][1001], a[11], b[11], c[11], d[11], n, m;   int main() {     a[0] = 100000, b[0] = 0;     scanf( %d %d %d %d , &n, &m, &c[0], &d[0]);     for (int i = 1; i <= m; i++) scanf( %d %d %d %d , &a[i], &b[i], &c[i], &d[i]);     for (int i = 0; i <= m; i++) dp[i][0] = 0;     for (int j = 0; j <= n; j++) dp[0][j] = (j / c[0]) * d[0];     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         dp[i][j] = dp[i - 1][j];         for (int k = 1; k * c[i] <= j && k * b[i] <= a[i]; k++) {           dp[i][j] = max(dp[i][j], dp[i - 1][j - k * c[i]] + k * d[i]);         }       }     }     printf( %d , dp[m][n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long a[1001];     long i, j, k = 0, l, n;     scanf( %ld , &n);     for (i = 0; i < n; i++) {       scanf( %ld , &a[i]);     }     sort(a, a + n);     if (a[0] == a[1] && a[0] != 0) k++;     for (i = 2; i < n; i++) {       if (a[i] == a[i - 1] && a[i - 1] == a[i - 2] && a[i] != 0) {         printf( -1 n );         return 0;       } else if (a[i] == a[i - 1] && a[i] != 0) {         k++;       }     }     printf( %ld n , k);     return 0;   }