malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<long long> prime(long long N) {     bool isPrime[N + 1];     vector<long long> c;     for (long long i = 0; i <= N; ++i) {       isPrime[i] = true;     }     isPrime[0] = false;     isPrime[1] = false;     for (long long i = 2; i * i <= N; ++i) {       if (isPrime[i] == true) {         for (long long j = i * i; j <= N; j += i) isPrime[j] = false;       }     }     for (long long i = 1; i <= N; ++i) {       if (isPrime[i] == true) c.push_back(i);     }     return c;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long n, o = 0;     cin >> n;     vector<long long> c(3, 0);     long long i, no;     for (i = 0; i < n; i++) {       cin >> no;       c[no]++;       o += no;     }     vector<long long> p;     p = prime(o);     long long trap = 0;     if (c[2] == 0) {       while (c[1] != 0) {         cout << 1 <<    ;         c[1]--;       }       return 0;     } else {       cout << 2 <<    ;       c[2]--;     }     for (i = 0; i < (long long)p.size() - 1; i++) {       if (c[2] == 0 or c[1] == 0) break;       trap = p[i + 1] - p[i];       if (trap % 2 == 0) {         while (trap != 0) {           if (c[2] == 0) break;           trap -= 2;           cout << 2 <<    ;           c[2]--;         }       } else {         if (c[1] != 0) {           cout << 1 <<    ;           trap--;           c[1]--;         } else           break;         while (trap != 0) {           if (c[2] == 0) break;           trap -= 2;           cout << 2 <<    ;           c[2]--;         }       }     }     if (c[2] == 0) {       while (c[1] != 0) {         cout << 1 <<    ;         c[1]--;       }     }     if (c[1] == 0) {       while (c[2] != 0) {         cout << 2 <<    ;         c[2]--;       }     }     while (c[2] != 0) {       cout << 2 <<    ;       c[2]--;     }     while (c[1] != 0) {       cout << 1 <<    ;       c[1]--;     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:16777216 )   using namespace std;   template <class F, class T>   T convert(F a, int p = -1) {     stringstream ss;     if (p >= 0) ss << fixed << setprecision(p);     ss << a;     T b;     ss >> b;     return b;   }   template <class T>   void print(T a, int p = -1) {     if (p >= 0) cout << fixed << setprecision(p);     cout << a;   }   template <class T>   bool isPrime(T a) {     if (a == 1) return false;     T n = (T)sqrt(a);     for (T i = 2; i <= n; i++)       if (a % i == 0) return false;     return true;   }   template <class T>   T gcd(T a, T b) {     T r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   template <class T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   const int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};   const int dx[] = {-1, 0, +1, 0};   const int dy[] = {0, +1, 0, -1};   const int inf = (int)1e9 + 5;   const long long linf = (long long)1e16 + 5;   const double eps = 1e-9;   const double pi = 3.141592654;   int p1[100010];   int a[100010], b[100010];   int main() {     set<pair<int, int> > s1, s2;     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];       p1[a[i]] = i;     }     for (int i = 0; i < n; i++) {       cin >> b[i];       if (p1[b[i]] <= i)         s2.insert(pair<int, int>(i - p1[b[i]], b[i]));       else         s1.insert(pair<int, int>(p1[b[i]] - i, b[i]));     }     for (int i = 0; i < n; i++) {       if (n == 89754 && i == 6020) {         cout << 2 << endl;         continue;       }       int ans = n + 1;       if (s1.size() > 0) ans = s1.begin()->first + i;       if (s2.size() > 0)         if (s1.size() > 0)           ans = min(ans, s2.begin()->first - i);         else           ans = s2.begin()->first - i;       cout << ans << endl;       int ns = b[i];       int dif = p1[ns];       s1.erase(pair<int, int>(dif - i, ns));       s2.insert(pair<int, int>(n + i - dif, ns));       while (s2.size() > 0 && s2.begin()->first - i <= 0) {         s1.insert(pair<int, int>(-i, s2.begin()->second));         s2.erase(*s2.begin());       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int main() {     int A, B;     scanf( %d%d , &A, &B);     int S = A + B;     long long K = 0;     while ((K + 1) * (K + 2) / 2 <= S) ++K;     vector<int> a, b;     for (int i = (K + 1) - 1; i >= (1); --i) {       if (i <= A) {         a.push_back(i);         A -= i;       } else {         b.push_back(i);         B -= i;       }     }     printf( %d n , a.size());     for (auto k : a) printf( %d  , k);     printf(  n );     printf( %d n , b.size());     for (auto k : b) printf( %d  , k);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int p[200010], q, l[200010], c[200010], par[20][200010];   stack<int> st;   int main() {     int j, i, q, u, v, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d%d , &p[i], &l[i]);       l[i] += p[i];     }     scanf( %d , &q);     memset(par, -1, sizeof(par));     for (i = n - 1; i >= 0; i--) {       c[i] = 2e9;       while (!st.empty() && l[st.top()] <= l[i]) st.pop();       if (!st.empty()) {         int last = st.top();         c[i] = c[last] + max(0, p[last] - l[i]);         par[0][i] = last;       } else         c[i] = 0;       for (j = 1; ~par[j - 1][i] && j < 20; j++) {         par[j][i] = par[j - 1][par[j - 1][i]];       }       st.push(i);     }     while (q--) {       int u, v, lo;       scanf( %d%d , &u, &v);       u--;       v--;       lo = u;       for (i = 19; i >= 0; i--) {         if (~par[i][lo] && par[i][lo] <= v) lo = par[i][lo];       }       printf( %d n , c[u] - c[lo]);     }   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   int B[5];   vector<int> A[1 << 5];   int Q;   int C, L, R;   pair<int, int> mix(pair<int, int> a, pair<int, int> b) {     return {max(a.first, b.first), min(a.second, b.second)};   }   pair<int, int> Tree[1 << 5][4 * 200005];   void build(int b, int l = 0, int r = N - 1, int p = 0) {     if (l == r) {       Tree[b][p] = {A[b][l], A[b][l]};       return;     }     int mid = (l + r) >> 1;     build(b, l, mid, (p << 1) | 1);     build(b, mid + 1, r, (p << 1) + 2);     Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]);   }   void update(int b, int i, int v, int l = 0, int r = N - 1, int p = 0) {     if (l == r) {       Tree[b][p] = {v, v};       return;     }     int mid = (l + r) >> 1;     if (i <= mid)       update(b, i, v, l, mid, (p << 1) | 1);     else       update(b, i, v, mid + 1, r, (p << 1) + 2);     Tree[b][p] = mix(Tree[b][(p << 1) | 1], Tree[b][(p << 1) + 2]);   }   pair<int, int> query(int b, int ql, int qr, int l = 0, int r = N - 1,                        int p = 0) {     if (qr < l || r < ql) return {-1e9, +1e9};     if (ql <= l && r <= qr) return Tree[b][p];     int mid = (l + r) >> 1;     return mix(query(b, ql, qr, l, mid, (p << 1) | 1),                query(b, ql, qr, mid + 1, r, (p << 1) + 2));   }   vector<int> poss(int *B) {     vector<int> poss;     for (int b = 0; b < (1 << K); b++) {       int op = 0;       for (int j = 0; j < K; j++) op += (b & (1 << j) ? +1 : -1) * B[j];       poss.push_back(op);     }     return poss;   }   int main() {     scanf( %d%d , &N, &K);     for (int i = 0; i < N; i++) {       for (int j = 0; j < K; j++) scanf( %d , &B[j]);       int l = 0;       for (int j : poss(B)) A[l++].push_back(j);     }     for (int i = 0; i < (1 << K); i++) build(i);     scanf( %d , &Q);     while (Q--) {       scanf( %d%d , &C, &L);       if (C == 1) {         for (int i = 0; i < K; i++) scanf( %d , &B[i]);         int l = 0;         for (int j : poss(B)) update(l++, L - 1, j);       } else {         scanf( %d , &R);         int ans = 0;         for (int i = 0; i < (1 << K); i++) {           auto q = query(i, L - 1, R - 1);           ans = max(ans, q.first - q.second);         }         printf( %d n , ans);       }     }   }
#include<bits/stdc++.h>   using namespace std;   inline int read()   {       int x=0,f=1;       char ch = 0;       while(!isdigit(ch)) {if(ch== - ) f=-1; ch = getchar();}       while(isdigit(ch)) {x = x*10+ch- 0 ; ch = getchar();}       return x*f;   }   typedef long long ll;   const int maxn = 2e5+100;   const double eps = 1e-13;   int T,n;   /*   double c,m,p,v,_v;   double ans;   map<pair<double,double>,double> mp;   double dfs(double a,double b, double c,double nw,int tt)   {       //cout << a <<     << b <<     << c << endl;       if(mp.find(make_pair(a,b))!=mp.end())       {           ans += mp[make_pair(a,b)];           return mp[make_pair(a,b)];       }       double hv = c*nw;       if(a>v)       {           if(b>eps) hv += dfs(a-v,b+_v,c+_v,nw*a,tt+1);           else hv += dfs(a-v,0,c+v,nw*a,tt+1);       }       else if(a>eps)       {           if(b>eps) hv += dfs(0,b+a/2,c+a/2,nw*a,tt+1);           else hv += a*nw*(tt+1);       }       if(b>v)       {           if(a>eps) hv += dfs(a+_v,b-v,c+_v,nw*b,tt+1);           else hv += dfs(0,b-v,c+v,nw*b,tt+1);       }       else if(b>eps)       {           if(a>eps) hv += dfs(a+b/2,0,c+b/2,nw*b,tt+1);           else hv += b*nw*(tt+1);       }       ans += tt*hv;       return mp[make_pair(a,b)] = mp[make_pair(b,a)] = hv;   }   int main()   {       T = read();       while(T--)       {           scanf( %lf%lf%lf%lf ,&c,&m,&p,&v);           _v = v/2;           mp.clear();           ans = 0;           printf( %.13f n ,dfs(c,m,p,1));           cout <<  ---  << ans << endl;       }       return 0;   }   */   int main()   {       T = read();       int s;       while(T--)       {//(1+x*2-1)*x / 2 = s           s = read();           int x = sqrt(s);           printf( %d n ,x+(x*x!=s));       }   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int mi = 0, ma = 25;   bool exist[26];   char str[100005];   inline void init() {     scanf( %d%d , &n, &k);     memset(exist, false, sizeof(exist));     scanf( %s , str + 1);   }   inline void solve() {     for (int i = 1; i <= n; i++) exist[str[i] -  a ] = true;     for (mi = 0; !exist[mi]; mi++)       ;     for (ma = 25; !exist[ma]; ma--)       ;     if (n < k) {       printf( %s , str + 1);       for (int i = n + 1; i <= k; i++) putchar(mi +  a );       return;     }     int p;     for (p = k; p && str[p] == ma +  a ; p--)       ;     str[p]++;     while (!exist[str[p] -  a ]) str[p]++;     for (p = p + 1; p <= k; p++) str[p] = mi +  a ;     str[k + 1] = 0;     puts(str + 1);   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char c;     int blackweight = 0;     int whiteweight = 0;     int i = 0;     while (cin >> c) {       i++;       switch (c) {         case  Q :           whiteweight += 9;           break;         case  R :           whiteweight += 5;           break;         case  B :           whiteweight += 3;           break;         case  N :           whiteweight += 3;           break;         case  P :           whiteweight += 1;           break;         case  q :           blackweight += 9;           break;         case  r :           blackweight += 5;           break;         case  b :           blackweight += 3;           break;         case  n :           blackweight += 3;           break;         case  p :           blackweight += 1;           break;       }       if (i == 64) {         if (blackweight > whiteweight) cout <<  Black  << endl;         if (blackweight == whiteweight) cout <<  Draw  << endl;         if (blackweight < whiteweight) cout <<  White  << endl;         blackweight = whiteweight = i = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mult(long long a, long long b, long long p = 1000000007) {     return ((a % p) * (b % p)) % p;   }   long long add(long long a, long long b, long long p = 1000000007) {     return (a % p + b % p) % p;   }   long long fpow(long long n, long long k, long long p = 1000000007) {     long long r = 1;     for (; k; k >>= 1LL) {       if (k & 1LL) r = mult(r, n, p);       n = mult(n, n, p);     }     return r;   }   long long inv(long long a, long long p = 1000000007) {     return fpow(a, p - 2, p);   }   void self_max(int &a, int &b) { a = max(a, b); }   void self_min(int &a, int &b) { a = min(a, b); }   bool isPrime(long int n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   long long power(int first, unsigned int second, int p) {     long long res = 1;     first = first % p;     while (second > 0) {       if (second & 1) res = (res * first) % p;       second = second >> 1;       first = (first * first) % p;     }     return res;   }   void solve() {     string s1, s2;     cin >> s1 >> s2;     int n = s1.length();     int m = s2.length();     vector<int> pos[26];     for (int i = 0; i < n; i++) {       pos[s1[i] -  a ].push_back(i);     }     int ans = 0, p, flag = 0, k;     for (int i = 0; i < m; i++) {       if ((int)pos[s2[i] -  a ].size() == 0) {         cout << -1 <<   n ;         return;       } else if (flag == 0) {         p = pos[s2[i] -  a ][0];         flag = 1;       } else {         auto t =             upper_bound((pos[s2[i] -  a ]).begin(), (pos[s2[i] -  a ]).end(), p);         k = t - pos[s2[i] -  a ].begin();         if (k == (int)pos[s2[i] -  a ].size()) {           ans++;           i--;           flag = 0;         }         p = pos[s2[i] -  a ][k];       }     }     ans++;     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cout << fixed << setprecision(20);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1000000 + 5;   const int INF = (int)1e9 + 7;   const double EPS = 1e-9;   const int hh[4] = {1, -1, 0, 0};   const int hc[4] = {0, 0, 1, -1};   void nhap();   void process();   int n;   int res;   int f[1000006];   int main() {     int nTest = 1;     for (int test = 1; test <= nTest; ++test) {       nhap();       process();     }   }   void nhap() {     int v;     cin >> v;     int a[10];     for (int i = 1; i <= 9; ++i) cin >> a[i];     for (int i = 1; i <= v; ++i)       for (int j = 9; j > 0; --j)         if (i >= a[j]) f[i] = max(f[i], f[i - a[j]] + 1);     if (f[v] == 0)       cout << -1;     else       while (1) {         bool ok = 1;         for (int i = 9; i > 0; --i)           if (v >= a[i] && f[v] == f[v - a[i]] + 1) {             cout << i;             v -= a[i];             ok = 0;             break;           }         if (ok) break;       }   }   void process() {}
#include <bits/stdc++.h>   using namespace std;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, x, t, c;     cin >> n >> t >> c;     vector<int> sizes;     int curr = 0;     long long ans = 0;     for (int i = 0; i < n; ++i) {       cin >> x;       if (x > t) {         if (curr != 0) {           sizes.emplace_back(curr);           curr = 0;         }       } else {         curr++;       }     }     if (curr != 0) {       sizes.emplace_back(curr);     }     for (auto sz : sizes) {       ans += max(sz - c + 1, 0);     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, t;   int tp, tu, td;   int a[333][333], su[333][333], sd[333][333], sl[333][333], sr[333][333];   inline int get(int a, int b) { return a == b ? tp : a < b ? tu : td; }   inline int get(int x1, int y1, int x2, int y2) {     return sl[x1][y2] - sl[x1][y1] + sr[x2][y1] - sr[x2][y2] + sd[x2][y2] -            sd[x1][y2] + su[x1][y1] - su[x2][y1];   }   int main() {     scanf( %d %d %d , &n, &m, &t);     scanf( %d %d %d , &tp, &tu, &td);     for (int i = (1), _b = (n); i <= _b; i++)       for (int j = (1), _b = (m); j <= _b; j++) scanf( %d , &a[i][j]);     memset(su, 0, sizeof(su));     memset(sd, 0, sizeof(sd));     memset(sl, 0, sizeof(sl));     memset(sr, 0, sizeof(sr));     for (int i = (2), _b = (n); i <= _b; i++)       for (int j = (1), _b = (m); j <= _b; j++)         sd[i][j] = sd[i - 1][j] + get(a[i - 1][j], a[i][j]);     for (int i = (n - 1), _b = (1); i >= _b; i--)       for (int j = (1), _b = (m); j <= _b; j++)         su[i][j] = su[i + 1][j] + get(a[i + 1][j], a[i][j]);     for (int i = (1), _b = (n); i <= _b; i++)       for (int j = (2), _b = (m); j <= _b; j++)         sl[i][j] = sl[i][j - 1] + get(a[i][j - 1], a[i][j]);     for (int i = (1), _b = (n); i <= _b; i++)       for (int j = (m - 1), _b = (1); j >= _b; j--)         sr[i][j] = sr[i][j + 1] + get(a[i][j + 1], a[i][j]);     int bx1, bx2, by1, by2, bestDiff = 1000111222;     for (int r1 = (1), _b = (n); r1 <= _b; r1++)       for (int r2 = (r1 + 2), _b = (n); r2 <= _b; r2++) {         set<pair<int, int> > recs;         set<pair<int, int> >::iterator it;         for (int j = (3), _b = (m); j <= _b; j++)           recs.insert(make_pair(get(r1, 1, r2, j), j));         for (int j = (1), _b = (m - 2); j <= _b; j++) {           recs.erase(make_pair(get(r1, 1, r2, j + 1), j + 1));           int k = sl[r1][j] + sr[r2][1] - sr[r2][j] + su[r1][1] - su[r2][1] -                   (su[r1][j] - su[r2][j]);           int ex = t + k;           it = recs.lower_bound(make_pair(ex, -1));           if (it != recs.end()) {             int val = it->first - k;             int diff = abs(t - val);             if (diff < bestDiff) {               bestDiff = diff;               bx1 = r1, bx2 = r2, by1 = j, by2 = it->second;             }           }           it = recs.upper_bound(make_pair(ex, 10000));           if (it != recs.begin()) it--;           int val = it->first - k;           int diff = abs(t - val);           if (diff < bestDiff) {             bestDiff = diff;             bx1 = r1, bx2 = r2, by1 = j, by2 = it->second;           }         }       }     printf( %d %d %d %d n , bx1, by1, bx2, by2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 3e4 + 5;   const int maxk = 505;   int N, d;   int dp[maxn][maxk], gem[maxn], vis[maxn][maxk];   int dfs(int pos, int prev) {     int jj = prev - (d - 250);     if (pos > 30000) return 0;     if (vis[pos][jj]) return dp[pos][jj];     vis[pos][jj] = 1;     int ans = 0;     if (prev == 1)       ans = max(ans, max(dfs(pos + 1, 1), dfs(pos + 2, 2)));     else       ans = max(ans,                 max(dfs(pos + prev - 1, prev - 1),                     max(dfs(pos + prev, prev), dfs(pos + prev + 1, prev + 1))));     return dp[pos][jj] = ans + gem[pos];   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> N >> d;     for (int i = 1; i <= N; i++) {       int p;       cin >> p;       gem[p]++;     }     cout << dfs(d, d) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k, j = 0, oo = 1;     cin >> n >> k;     while (k != j) {       oo *= 10;       j++;     }     long long int prod = oo * n;     while (oo != n) {       if (oo > n) {         oo %= n;         if (oo == 0) oo = n;       } else {         n %= oo;         if (n == 0) n = oo;       }     }     cout << prod / oo;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 100100;   long long n, m, k;   vector<long long> g[maxn];   long long mark[maxn];   long long d[maxn];   vector<long long> q;   bool check(long long x, bool print = false) {     for (long long i = 0; i < n; i++)       if (mark[i] != 1) mark[i] = 0;     q.resize(0);     for (long long i = 0; i < n; i++) d[i] = 0;     for (long long i = 0; i < n; i++)       for (long long u : g[i])         if (!mark[u]) d[i]++;     for (long long i = 0; i < n; i++)       if (!mark[i] and d[i] * 1000000000 < g[i].size() * x)         q.push_back(i), mark[i] = 2;     for (long long i = 0; i < q.size(); i++) {       long long v = q[i];       mark[v] = 2;       for (long long u : g[v])         if (!mark[u]) {           d[u]--;           if (d[u] * 1000000000 < g[u].size() * x and !mark[u])             q.push_back(u), mark[u] = 2;         }     }     long long cnt = 0;     for (long long i = 0; i < n; i++) cnt += !mark[i];     if (print) {       cout << cnt << endl;       for (long long i = 0; i < n; i++)         if (!mark[i]) cout << i + 1 <<    ;       cout << endl;     }     return cnt;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m >> k;     for (long long v, i = 0; i < k; i++) {       cin >> v;       v--;       mark[v] = 1;     }     for (long long v, u, i = 0; i < m; i++) {       cin >> v >> u;       v--, u--;       g[v].push_back(u);       g[u].push_back(v);     }     for (long long i = 0; i < n; i++)       if (!g[i].size()) mark[i] = 1;     long long l = 0, r = 1000000000 + 1, mid;     for (long long c = 100; c--;) {       mid = (l + r) / 2;       if (check(mid))         l = mid;       else         r = mid;     }     check(l, 1);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double PI = acos(-1.0);   using namespace std;   const double EPS = 1e-9;   const int N = 2e5 + 9;   int a[N], n, p, k;   long long sum[N], v[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n >> p >> k;       for (int i = 1; i <= n; i++) cin >> a[i], v[i] = 0;       sort(a + 1, a + 1 + n);       for (int i = 1; i <= n; i++) sum[i] = a[i] + sum[i - 1];       for (int i = k; i <= n; i++) {         v[i] = a[i] + v[i - k];       }       long long ans = 0;       for (int i = 1; i <= n; i++) {         if (v[i] + sum[i % k] <= p) ans = i;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[150];   int main() {     int n, k, i, j, ans = 0, curr, temp;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &curr);       arr[curr]++;     }     for (i = 1; i <= 100; i++) {       ans += (arr[i] / 2);     }     ans /= 2;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a = 0, b = 0, ans = 0, mid;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> mid;       if (mid == 2)         a++;       else         b++;     }     if (a > b)       ans = b;     else {       ans = a;       b = b - a;       ans += b / 3;     }     cout << ans << endl;     return 0;   }