malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   char s[maxn];   char ans[maxn];   int sum[maxn];   int n;   int check() {     for (int i = 0; i < n / 2;) {       int l = i, r = n - 1 - i;       if (sum[l] == sum[r])         i++;       else if (sum[l] == sum[r] + 1 || sum[l] == sum[r] + 11) {         sum[l]--;         sum[l + 1] += 10;       } else if (sum[l] == sum[r] + 10) {         sum[r - 1]--;         sum[r] += 10;       } else         return 0;     }     if (n % 2 == 1) {       if (sum[n / 2] % 2 == 1 || sum[n / 2] > 18 || sum[n / 2] < 0) return 0;       ans[n / 2] = sum[n / 2] / 2 +  0 ;     }     for (int i = 0; i < n / 2; i++) {       if (sum[i] > 18 || sum[i] < 0) return 0;       ans[i] = (sum[i] + 1) / 2 +  0 ;       ans[n - i - 1] = (sum[i]) / 2 +  0 ;     }     return ans[0] >  0 ;   }   int main() {     scanf( %s , s);     n = strlen(s);     for (int i = 0; i < n; i++) sum[i] = s[i] -  0 ;     if (check()) return puts(ans);     if (s[0] ==  1  && n > 1) {       for (int i = 0; i < n; i++) sum[i] = s[i + 1] -  0 ;       sum[0] += 10;       n--;       if (check())         puts(ans);       else         printf( 0 );     } else       printf( 0 );   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long n1, long long n2) {     if (!n1) return n2;     if (!n2) return n1;     if (n1 % n2 == 0) return n2;     return gcd(n2, n1 % n2);   }   long long powmod(long long base, long long exponent) {     base %= 1000000007;     long long ans = 1;     while (exponent) {       if (exponent & 1) ans = (ans * base) % 1000000007;       base = (base * base) % 1000000007;       exponent /= 2;     }     ans %= 1000000007;     return ans;   }   vector<int> adj[1000100 + 1];   int level[1000100 + 1];   vector<int> temp;   int freq[20 * 1000100 + 1];   int arr[1000100 + 1];   long long f(long long x) { return (x * (x - 1)) / 2; }   void dfs(int node, int lv) {     level[node] = lv;     for (int i = 0; i < adj[node].size(); i++) dfs(adj[node][i], lv + 1);   }   int main() {     int n, i, j, k;     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %d , &arr[i]);     for (i = 2; i <= n; i++) {       scanf( %d , &j);       adj[j].push_back(i);     }     dfs(1, 1);     int mx = 0, xr = 0;     for (i = 1; i <= n; i++) mx = max(mx, level[i]);     for (i = 1; i <= n; i++) {       if ((mx & 1) == (level[i] & 1)) {         temp.push_back(arr[i]);         xr ^= arr[i];       } else         freq[arr[i]]++;     }     long long answer = 0;     k = temp.size();     if (!xr) answer = f(k) + f(n - k);     for (i = 0; i < k; i++) answer += freq[(xr ^ temp[i])];     printf( %lld n , answer);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 5;   const long long Q = 3e5 + 5;   char w[N][N];   char x[Q];   long long l[Q], r[Q];   long long u[Q], d[Q];   long long f[N][N];   long long c[N][N][26];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     long long m;     cin >> m;     long long k;     cin >> k;     for (long long i = 1; i <= n; ++i)       for (long long j = 1; j <= m; ++j) cin >> w[i][j];     for (long long i = 1; i <= k; ++i) {       cin >> l[i] >> u[i];       cin >> r[i] >> d[i];       cin >> x[i];       x[i] -=  a ;       ++r[i];       ++d[i];       c[l[i]][u[i]][x[i]]++;       c[l[i]][d[i]][x[i]]--;       c[r[i]][u[i]][x[i]]--;       c[r[i]][d[i]][x[i]]++;     }     for (long long i = 1; i <= n; ++i)       for (long long j = 1; j <= m; ++j)         for (long long t = 0; t < 26; ++t)           c[i][j][t] -= c[i - 1][j - 1][t], c[i][j][t] += c[i - 1][j][t],               c[i][j][t] += c[i][j - 1][t];     for (long long i = 1; i <= n; ++i)       for (long long j = 1; j <= m; ++j) {         c[i][j][w[i][j] -  a ] = k;         for (long long t = 0; t < 26; ++t)           if (t != w[i][j] -  a ) c[i][j][w[i][j] -  a ] -= c[i][j][t];         for (long long t = 0; t < 26; ++t)           f[i][j] += c[i][j][t] * abs(w[i][j] -  a  - t);       }     for (long long i = 1; i <= n; ++i)       for (long long j = 1; j <= m; ++j) {         f[i][j] -= f[i - 1][j - 1];         f[i][j] += f[i - 1][j];         f[i][j] += f[i][j - 1];         for (long long t = 0; t < 26; ++t)           c[i][j][t] -= c[i - 1][j - 1][t], c[i][j][t] += c[i - 1][j][t],               c[i][j][t] += c[i][j - 1][t];       }     long long ans = 1e18;     for (long long i = 1; i <= k; ++i) {       l[i]--;       r[i]--;       u[i]--;       d[i]--;       long long cur = f[n][m];       cur -= f[r[i]][d[i]];       cur += f[r[i]][u[i]];       cur += f[l[i]][d[i]];       cur -= f[l[i]][u[i]];       for (long long t = 0; t < 26; ++t)         cur += (c[r[i]][d[i]][t] - c[r[i]][u[i]][t] - c[l[i]][d[i]][t] +                 c[l[i]][u[i]][t]) *                abs(x[i] - t);       ans = min(ans, cur);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char* x) { cerr <<     << x <<    ; }   void __print(const string& x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V>& x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T& x) {     int f = 0;     cerr <<  { ;     for (auto& i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     string s;     cin >> s;     int n = s.size();     long long res = 0;     for (int i = 0; i < n; ++i) {       int cur = 0;       int q = 0;       long long ans = 0;       for (int j = i; j < n; ++j) {         if (s[j] ==  ) ) {           --cur;         } else if (s[j] ==  ( ) {           ++cur;         } else {           ++q;         }         if (cur == -1) {           if (q <= 0) {             break;           }           --q;           cur = 0;         }         if (q > cur) {           --q;           ++cur;         }         int req = cur;         if (q >= req) {           if (!((q - req) % 2)) {             ++ans;           }         }       }       res += ans;     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void dbs(string str, T t) {     cerr << str <<   :   << t <<   n ;   }   template <class T, class... S>   void dbs(string str, T t, S... s) {     long long idx = str.find( , );     cerr << str.substr(0, idx) <<   :   << t <<  ,  ;     dbs(str.substr(idx + 1), s...);   }   template <class S, class T>   ostream& operator<<(ostream& os, const pair<S, T>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& os, const vector<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, const set<T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& os, const map<S, T>& p) {     os <<  [  ;     for (auto& it : p) os << it <<    ;     return os <<  ] ;   }   template <class T>   void prc(T a, T b) {     cerr <<  [ ;     for (T i = a; i != b; ++i) {       if (i != a) cerr <<  ,  ;       cerr << *i;     }     cerr <<  ] n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t, i, j, k, n, m;     long long x, y, l, r;     cin >> n;     vector<long long> v(n);     for (i = 0; i < n; i++) cin >> v[i];     stack<long long> q;     long long ans = v[0] ^ v[1];     for (i = n - 1; i >= 0; i--) {       while (!q.empty() && v[q.top()] <= v[i]) {         x = q.top();         q.pop();       }       if (!q.empty()) ans = max(ans, v[i] ^ v[q.top()]);       q.push(i);     }     while (!q.empty()) {       x = q.top();       q.pop();     }     for (i = 0; i < n; i++) {       while (!q.empty() && v[q.top()] <= v[i]) {         x = q.top();         q.pop();       }       if (!q.empty()) ans = max(ans, v[i] ^ v[q.top()]);       q.push(i);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool flag;   vector<vector<int> > g;   map<int, bool> used;   void dfs(int x, int last) {     used[x] = true;     for (auto to : g[x]) {       if (!used[to]) {         dfs(to, x);       } else {         if (last != to) {           flag = false;           return;         }       }     }     return;   }   int execute() {     int n, m;     cin >> n >> m;     g.resize(n + 1);     for (int i = 1; i <= m; i++) {       int x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (!used[i]) {         flag = true;         dfs(i, i);         cnt += flag;       }     }     cout << cnt << endl;     return 0;   }   int TE = true;   bool mTest = false;   int main() {     ios_base::sync_with_stdio(false);     if (mTest) cin >> TE;     while (TE--) {       execute();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 110;   int T[MAXN];   int ids[MAXN];   int n;   int check(int a, int b) {     vector<int> V(n);     copy(T, T + n, V.begin());     int m = 0;     for (int i = 0; i < V.size(); i++) {       if (V[i] == -1) continue;       if (V[i] < a || V[i] > b) continue;       int a = V[i];       V[i] = -1;       m++;       for (int j = i + 1; j < V.size(); j++)         if (V[j] == a + 1) {           V[j] = -1;           a++;         }     }     return m;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &T[i]);     }     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int ot, a, b;       scanf( %d %d %d , &ot, &a, &b);       if (ot == 1) {         printf( %d n , check(a, b));       } else {         swap(T[a - 1], T[b - 1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 138;   int n, Ans, x, y, z, GG[N][N][5][5];   int main() {     memset(GG, -63, sizeof(GG));     cin >> n;     int i, j, k, p;     for (i = 1; i <= n; ++i) {       cin >> x >> y >> z;       GG[i][i][z][x] = GG[i][i][x][z] = y;     }     for (i = n; i >= 1; --i)       for (j = i; j <= n; ++j)         for (int x = 1; x <= 4; ++x)           for (int y = 1; y <= 4; ++y)             for (k = i; k <= j; ++k) {               GG[i][j][x][y] =                   max(GG[i][j][x][y], max(GG[i][k][x][y], GG[k + 1][j][x][y]));               for (p = 1; p <= 4; ++p)                 GG[i][j][x][y] =                     max(GG[i][j][x][y], max(GG[i][k][x][p] + GG[k + 1][j][p][y],                                             GG[i][k][p][y] + GG[k + 1][j][x][p]));               Ans = max(Ans, GG[i][j][x][y]);             }     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, ans = 34343434;   vector<long long> a;   vector<long long> b;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       long long x, y;       cin >> x >> y;       if (x == 1)         a.push_back(y);       else         b.push_back(y);     }     sort(a.begin(), a.end());     sort(b.begin(), b.end());     for (int v = 0; v <= a.size(); v++) {       for (int u = 0; u <= b.size(); u++) {         long long width = v + u * 2, len = 0;         for (int i = 0; i < a.size() - v; i++) len += a[i];         for (int i = 0; i < b.size() - u; i++) len += b[i];         if (width >= len) ans = min(ans, width);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     set<int> h;     cin >> n;     for (int i = 1; i <= n; i++) h.insert(i);     for (int i = 1; i <= n; i++)       for (int j = 1, x; j <= n; j++) {         cin >> x;         x != 0 && x != -1 ? x == 1 ? h.erase(i) : h.erase(j) : 0;       }     cout << h.size() <<   n ;     for (int i = 1; i <= n; i++)       if (h.find(i) != h.end()) cout << i <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Debugger {    public:     Debugger(const std::string& _separator =  ,  )         : first(true), separator(_separator) {}     template <typename ObjectType>     Debugger& operator,(const ObjectType& v) {       if (!first) cerr << separator;       cerr << v;       first = false;       return *this;     }     ~Debugger() { cerr <<   n ; }       private:     bool first;     string separator;   };   template <typename T1, typename T2>   inline ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {     return os <<  (  << p.first <<  ,   << p.second <<  ) ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const vector<T>& v) {     bool first = true;     os <<  [ ;     for (unsigned long long i = 0; i < v.size(); i++) {       if (!first) os <<  ,  ;       os << v[i];       first = false;     }     return os <<  ] ;   }   template <typename T>   inline ostream& operator<<(ostream& os, const set<T>& v) {     bool first = true;     os <<  [ ;     for (typename set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   template <typename T1, typename T2>   inline ostream& operator<<(ostream& os, const map<T1, T2>& v) {     bool first = true;     os <<  [ ;     for (typename map<T1, T2>::const_iterator ii = v.begin(); ii != v.end();          ++ii) {       if (!first) os <<  ,  ;       os << *ii;       first = false;     }     return os <<  ] ;   }   long long n, m;   long long x, y;   long long xx, yy;   set<long long> elementi;   map<long long, long long> used;   int main() {     ios_base::sync_with_stdio(0);     ;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> x >> y;       elementi.insert(x);       used[x] = max(used[x], y);     }     cin >> m;     for (long long i = 1; i <= m; i++) {       cin >> x >> y;       elementi.insert(x);       used[x] = max(used[x], y);     }     long long cnt = 0;     for (const auto& i : elementi) {       cnt += used[i];     }     cout << cnt <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     string ans;     for (int i = 0; i < s.size(); ++i) {       if (s[i] ==  4 ) {         ans +=  322 ;       } else if (s[i] ==  6 )         ans +=  53 ;       else if (s[i] ==  8 )         ans +=  7222 ;       else if (s[i] ==  9 )         ans +=  3372 ;       else if (s[i] !=  1  && s[i] !=  0 )         ans += s[i];     }     sort(ans.begin(), ans.end());     reverse(ans.begin(), ans.end());     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> solve() {     const int N = 3e6;     vector<bool> isPrime(N, true);     isPrime[0] = isPrime[1] = false;     for (int i = 0; i * i < N; i++) {       if (isPrime[i]) {         for (int j = i * 2; j < N; j += i) {           isPrime[j] = false;         }       }     }     int n;     cin >> n;     vector<int> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     int one = count(a.begin(), a.end(), 1);     vector<int> ans;     ans.push_back(a[0]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j) continue;         vector<int> cand;         if (isPrime[a[i] + a[j]]) {           cand.push_back(a[i]);           cand.push_back(a[j]);           if (isPrime[a[i] + 1] && isPrime[a[j] + 1] && a[i] != 1 && a[j] == 1) {             for (int k = 0; k < one - 1; k++) cand.push_back(1);             return cand;           }           if (ans.size() < cand.size()) ans = cand;         }       }     }     if (one >= 2) {       ans.assign(one, 1);     }     return ans;   }   int main() {     auto ans = solve();     cout << ans.size() << endl;     for (int x : ans) cout << x <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = 0x7fffffff;   const long long OO = 1000000000000000000LL;   const int base = 1000000007;   const int dx[] = {1, 0, 0, -1};   const int dy[] = {0, 1, -1, 0};   int x;   int main() {     ios_base::sync_with_stdio(false);     cin >> x;     if (x == 2) {       cout << 3 << endl;       return 0;     }     if (x == 3) {       cout << 5;       return 0;     }     for (int n = 1;; n += 2) {       int count = (n / 2 + 1) * (n / 2 + 1) + (n / 2) * (n / 2);       if (count >= x) {         cout << n;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     vector<pair<unsigned long long, unsigned long long> > v;     unsigned long long target;     cin >> target;     unsigned long long base_l = 1, base_r = target + 1;     for (unsigned long long n = 1; n * (n + 1) * (2 * n + 1) <= 6 * target; n++) {       unsigned long long l = base_l, r = base_r;       unsigned long long base_n1 = n * (n + 1) * (2 * n + 1),                          base_n2 = 3 * n * (n + 1);       while (r - l > 1) {         unsigned long long mid = (r + l) / 2;         if (base_n1 + (mid - n) * base_n2 <= 6 * target)           l = mid;         else           r = mid;       }       base_r = r;       if (base_n1 + (l - n) * base_n2 == 6 * target) v.push_back({n, l});     }     cout << 2 * v.size() - (v.back().first != v.back().second ? 0 : 1) <<   n ;     for (auto p : v) cout << p.first <<     << p.second <<   n ;     for (int i = v.size() - 1; i >= 0; i--) {       auto p = v[i];       unsigned long long a = p.first, b = p.second;       if (a != b) cout << b <<     << a <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool f(string s1, string s2) {     if (s1 == s2) return true;     bool ans = false;     string t1(s1.begin(), s1.begin() + s1.size() / 2);     string t2(s1.begin() + s1.size() / 2, s1.end());     string t3(s2.begin(), s2.begin() + s2.size() / 2);     string t4(s2.begin() + s2.size() / 2, s2.end());     if (s1.size() % 2 == 0 && s2.size() % 2 == 0) {       ans = ans | (f(t1, t3) && f(t2, t4));     }     if (!ans)       if (s1.size() % 2 == 0 && s2.size() % 2 == 0) {         ans = ans | (f(t1, t4) && f(t2, t3));       }     return ans;   }   string cf(string s) {     if (s.size() & 1) return s;     string s1 = cf(s.substr(0, s.size() / 2));     string s2 = cf(s.substr(s.size() / 2, s.size()));     if (s1 < s2)       return s1 + s2;     else       return s2 + s1;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s1, s2;     cin >> s1 >> s2;     if (cf(s1) == cf(s2))       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   bool visit[204];   vector<int> dependency[204];   int col[203];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> col[i];     }     for (int i = 1; i <= n; i++) {       int k;       cin >> k;       for (int j = 1; j <= k; j++) {         int m;         cin >> m;         dependency[i].push_back(m);       }     }     int ans = INT_MAX;     for (int l = 1; l <= 3; l++) {       int hours = 0, cur = l, vis = 0;       for (int i = 1; i <= n; i++) {         visit[i] = false;       }       while (vis != n) {         bool cvis = false;         for (int i = 1; i <= n; i++) {           if (!visit[i] && col[i] == cur) {             bool cr = true;             for (int j = 0; j < dependency[i].size(); j++) {               if (!visit[dependency[i][j]]) {                 cr = false;                 break;               }             }             if (cr) {               visit[i] = true;               vis++;               cvis = true;               hours++;               break;             }           }         }         if (!cvis) {           cur = 1 + (cur) % 3;           hours++;         }       }       ans = min(ans, hours);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int hcf(long long a, long long b) {     if (b == 0) return a;     return hcf(b, a % b);   }   void solve() {     long long n;     cin >> n;     long long x = hcf(n + 1, 4 * n);     long long lcm = ((4 * n) * (n + 1)) / x;     cout << lcm / (n + 1) + 1;   }   int main() {     int t = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, n, i, k, l, r, d, kol1, kol2, ans;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> n >> k;     for (i = 1; i <= n; i++) {       cin >> a;       if (a < k)         kol1++;       else if (a > k)         kol2++;     }     l = n;     r = n * 3;     while (l <= r) {       d = (l + r) / 2;       if (((d + 1) / 2 - 1 >= kol1) && (d - (d + 1) / 2 >= kol2)) {         r = d - 1;         ans = d - n;       } else         l = d + 1;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, i, k;     cin >> n >> k;     int a[n], c = 0;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     for (i = 0; i < n; i += 3) {       if (a[i] <= 5 && a[i + 1] <= 5 && a[i + 2] <= 5) {         if ((a[i] += k) <= 5 && (a[i + 1] += k) <= 5 && (a[i + 2] += k) <= 5) c++;       }     }     cout << c;   }