malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   char s1[128];   int l1;   char s2[128];   int l2;   char virus[128];   int lv;   int nxt[128][128];   vector<int> froms[128][128];   void calc_nxt() {     char tmp[128];     strcpy(tmp, virus);     for (int l = 0; l < lv; l++) {       for (char ch =  A ; ch <=  Z ; ch++) {         tmp[l] = ch;         for (int i = l + 1; i >= 0; i--) {           if (!strncmp(tmp + l + 1 - i, virus, i)) {             nxt[l][(int)ch] = i;             break;           }         }         froms[nxt[l][(int)ch]][(int)ch].push_back(l);       }       tmp[l] = virus[l];     }   }   struct Path {     int i, j, k;   };   bool operator<(const Path &a, const Path &b) {     if (a.i != b.i) return a.i < b.i;     if (a.j != b.j) return a.j < b.j;     if (a.k != b.k) return a.k < b.k;     return false;   }   pair<int, Path> dp[128][128][128];   pair<int, Path> takeDP(int i, int j, int k) {     pair<int, Path> t = dp[i][j][k];     t.second = {i, j, k};     return t;   }   string getPath(pair<int, Path> runner) {     string s;     while (runner.first != 0) {       Path p = runner.second;       auto nr = dp[p.i][p.j][p.k];       Path np = nr.second;       if (np.i < p.i && np.j < p.j) {         s += s1[p.i - 1];       }       runner = nr;     }     reverse(s.begin(), s.end());     if (s ==   ) return  0 ;     return s;   }   bool isSub(string s, string p) {     size_t l = 0;     for (auto ch : p) {       cout << ch;       while (l < s.size() && s[l] != ch) {         l++;       }       if (l == s.size()) {         cout << endl;         return false;       }       l++;     }     cout << endl;     return true;   }   int TestNum;   int main() {     scanf( %s%s%s , s1, s2, virus);     l1 = strlen(s1);     l2 = strlen(s2);     lv = strlen(virus);     calc_nxt();     for (int i = 0; i < l1; i++) {       for (int k = 1; k <= lv; k++) {         dp[i][0][k].first = -0x1f1f1f1f;       }     }     for (int i = 0; i < l2; i++) {       for (int k = 1; k <= lv; k++) {         dp[0][i][k].first = -0x1f1f1f1f;       }     }     dp[0][0][0].first = 0;     for (int i = 0; i < l1; i++) {       for (int j = 0; j < l2; j++) {         for (int k = 0; k < lv; k++) {           auto &to = dp[i + 1][j + 1][k];           auto from1 = takeDP(i + 1, j, k), from2 = takeDP(i, j + 1, k);           to = max(from1, from2);           if (s1[i] == s2[j]) {             for (auto tk : froms[k][(int)s1[i]]) {               auto from = takeDP(i, j, tk);               from.first += 1;               to = max(to, from);             }           }         }       }     }     auto best = dp[0][0][0];     for (int k = 0; k < lv; k++) {       best = max(best, takeDP(l1, l2, k));     }     string s = getPath(best);     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3001;   const int mod = 1000000007;   char s[N][N];   int f[N][N];   int calc(int sr, int sc, int tr, int tc) {     if (tr < sr || tc < sc) return 0;     int n = tr - sr + 1, m = tc - sc + 1;     f[0][0] = (s[sr][sc] !=  # );     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++)         if (i || j) {           f[i][j] = 0;           if (i > 0) f[i][j] += f[i - 1][j];           if (j > 0) f[i][j] += f[i][j - 1];           f[i][j] %= mod;           if (s[i + sr][j + sc] ==  # ) f[i][j] = 0;         }     }     return f[n - 1][m - 1];   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , s[i]);     int a, b, c, d;     a = calc(0, 1, n - 2, m - 1);     b = calc(1, 0, n - 1, m - 2);     c = calc(0, 1, n - 1, m - 2);     d = calc(1, 0, n - 2, m - 1);     printf( %lld n , ((1LL * a * b - 1LL * c * d) % mod + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) {     if (a > b) return b;     return a;   }   int main() {     {       ios_base::sync_with_stdio(false);       cin.tie(NULL);     };     int q;     cin >> q;     while (q--) {       long long a, b, c, r;       cin >> a >> b >> c >> r;       long long ans = 0;       if (b < a) {         long long temp = b;         b = a;         a = temp;       }       long long low = c - r;       long long high = c + r;       if (a <= low && high <= b) {         ans = b - a - (high - low);       } else if (low <= a && high <= b && a <= high) {         ans = b - a - (high - a);       } else if (b <= high && a <= low && low <= b) {         ans = b - a - (b - low);       } else if (low <= a && b <= high) {         ans = 0;       } else {         ans = b - a;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char x;   int n;   int main() {     cin >> n;     cin >> x;     cout << x;     cin >> x;     cout << x;     n -= 2;     if (n % 2 == 1) {       cin >> x;       cout << x;       n--;     }     for (int i = 1; i <= n; i++) {       if (i % 2 == 1) cout <<  - ;       cin >> x;       cout << x;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   std::vector<string> v(2000);   vector<vector<int> > mark(2000);   set<pair<int, int> > ans;   int bfs(int x, int y) {     int m = x, n = y;     vector<pair<int, int> > q;     int i = 0;     while (v[x][y] !=  #  && mark[x][y] == -2) {       q.push_back(make_pair(x, y));       int Y = y, X = x;       Y -= (v[x][y] ==  < );       Y += (v[x][y] ==  > );       X -= (v[x][y] ==  ^ );       X += (v[x][y] ==  v );       mark[x][y] = -1;       x = X;       y = Y;     }     if (v[x][y] ==  # ) {       mark[x][y] = 0;       int cnt = 1;       for (i = q.size() - 1; i >= 0; i--) {         mark[q[i].first][q[i].second] = cnt + mark[x][y];         cnt++;       }     } else if (mark[x][y] == -1) {       for (i = 0; i < q.size(); i++) {         mark[q[i].first][q[i].second] = -1;       }     } else {       int cnt = 1;       for (i = q.size() - 1; i >= 0; i--) {         mark[q[i].first][q[i].second] = cnt + mark[x][y];         cnt++;       }     }     return mark[m][n];   }   void check() {     while (ans.size() != 1) {       vector<pair<int, int> > u;       set<pair<int, int> >::iterator it;       for (it = ans.begin(); it != ans.end(); it++) {         int x = (*it).first;         int y = (*it).second;         int X = x, Y = y;         Y -= (v[x][y] ==  < );         Y += (v[x][y] ==  > );         X -= (v[x][y] ==  ^ );         X += (v[x][y] ==  v );         if (v[X][Y] ==  # ) {           return;         }         u.push_back(make_pair(X, Y));       }       int i;       ans.clear();       for (i = 0; i < u.size(); i++) {         ans.insert(u[i]);       }     }   }   int main() {     int n, m;     cin >> n >> m;     int i, j;     for (i = 0; i < n; i++) {       cin >> v[i];     }     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         mark[i].push_back(-2);       }     }     int maxi = -100;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (mark[i][j] == -2) {           int a = bfs(i, j);           if (a == -1) {             cout <<  -1  << endl;             return 0;           }           if (maxi < a) {             ans.clear();             maxi = a;             ans.insert(make_pair(i, j));           } else if (maxi == a) {             ans.insert(make_pair(i, j));           }         }       }     }     mark.clear();     check();     if (ans.size() == 1) {       if (v[(*(ans.begin())).first][(*(ans.begin())).second] ==  # )         cout <<  0  << endl;       else         cout << 2 * maxi - 1 << endl;     } else {       cout << 2 * maxi << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long add(long long n) {     long long mi = INT_MAX, ma = INT_MIN;     while (n > 0) {       mi = min(n % 10, mi);       ma = max(n % 10, ma);       n = n / 10;     }     return mi * ma;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     scanf( %d , &t);     while (t--) {       long long n, k;       scanf( %lld%lld , &n, &k);       k--;       while (k--) {         long long j = add(n);         n = n + j;         if (j == 0) {           break;         }       }       cout << n << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, k, cntr = 1, s = 1;     cin >> n >> m >> k;     string str;     cin >> str >> str;     if (str ==  head ) cntr = -1;     cin >> str;     int l = str.length();     if (m < k) s = -1;     for (int i = 0; i < l; i++) {       if (str[i] ==  0 ) {         if (m != 1 && m != n) m += s;       } else {         if (cntr == 1)           m = 1;         else           m = n;       }       k += cntr;       if (k == n)         cntr = -1;       else if (k == 1)         cntr = 1;       if (m == k) {         cout <<  Controller   << i + 1 <<   n ;         return 0;       }     }     cout <<  Stowaway n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     long long sum, xr;     cin >> sum >> xr;     long long dp[2] = {1, 0};     for (int bit = 0; bit < 50; bit++) {       long long ndp[2] = {0, 0};       int needSum = (sum >> bit) & 1;       int needXor = (xr >> bit) & 1;       for (int was = 0; was < 2; was++) {         for (int b1 = 0; b1 < 2; b1++) {           for (int b2 = 0; b2 < 2; b2++) {             int mySum = (b1 + b2 + was) % 2;             int myXor = b1 ^ b2;             if (myXor == needXor && mySum == needSum) {               ndp[(b1 + b2 + was) >> 1] += dp[was];             }           }         }       }       for (int _n(2), i(0); i < _n; i++) dp[i] = ndp[i];     }     cout << (dp[0] - (sum == xr ? 2 : 0)) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void splay(long long &v) {     v = 0;     char c = 0;     int p = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) p = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       v = (v << 3) + (v << 1) + c -  0 ;       c = getchar();     }     v *= p;   }   long long a[1000010];   long long dp[1000010], ans;   int main() {     long long n;     splay(n);     for (int i = 1; i <= n; i++) {       splay(a[i]);       a[i]--;     }     dp[1] = min(a[1], a[2]);     ans += a[1];     for (int i = 2; i <= n; i++) {       ans += a[i];       long long x = min(a[i], a[i - 1]);       long long y = min(x, a[i + 1]), z = min(a[i], a[i + 1]);       ans += dp[i - 1] * x;       dp[i] = dp[i - 1] * y + z;       ans %= 1000000007LL;       dp[i] %= 1000000007LL;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000010;   int main() {     int len, cnt;     char s, d, st[maxn], word[26];     cin >> len >> cnt;     cin >> st;     for (int i = 0; i < 26; ++i) {       word[i] =  a  + i;     }     for (int i = 1; i <= cnt; ++i) {       cin >> s >> d;       if (s == d) continue;       for (int j = 0; j < 26; ++j) {         if (word[j] == s)           word[j] = d;         else if (word[j] == d)           word[j] = s;       }     }     for (int i = 0; i < len; ++i) cout << word[st[i] -  a ];     cout << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 100010;   using ll = long long;   int a[N];   int main() {     int n, d, m;     scanf( %d%d%d , &n, &d, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &a[i]);     }     std::sort(a, a + n);     int last = n;     for (int i = 0; i < n; ++i) {       if (a[i] > m) {         last = i;         break;       }     }     std::sort(a, a + last, std::greater<int>());     ll ans = 0, sum = 0;     for (int i = 0; i < last; ++i) {       sum += a[i];     }     for (int i = last - 1, j = n - 1; i >= -1; --i) {       while (j >= last) {         int num = i + 1 + (n - j) * (d + 1) - d;         if (num > n) {           break;         }         sum += a[j--];       }       ans = std::max(ans, sum);       if (i >= 0) {         sum -= a[i];       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, arr[100];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n - 1; i++) {       for (int j = i; j < n; j++) {         if (arr[i] > arr[j]) {           int swap = arr[j];           arr[j] = arr[i];           arr[i] = swap;         }       }     }     for (int i = 0; i < n; i++) {       cout << arr[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       string s;       cin >> s;       if (s.length() > 10)         cout << s[0] << (s.length() - 2) << s[s.length() - 1] << endl;       else         cout << s << endl;     }   }
#include <bits/stdc++.h>   const int MAX_N = 1000000;   const int MOD = 1000000007;   std::vector<int> groups;   int table[1 + MAX_N], dp[1 + MAX_N];   std::deque<int> tablePositions;   int main() {     std::string s;     std::cin >> s;     groups.push_back(0);     int cnt = 0;     for (int i = 0; i < s.size(); ++i)       if (s[i] ==  0 )         ++cnt;       else {         groups.push_back(cnt);         cnt = 0;       }     groups.push_back(cnt);     dp[1] = groups[1] + 1;     for (int i = 2; i < groups.size(); ++i) {       if (i < groups.size() - 1) dp[i] = dp[i - 1];       for (int lastDigit = 0; lastDigit <= groups[i]; ++lastDigit) {         dp[i] = (dp[i] + dp[i - 1]) % MOD;         while (!tablePositions.empty() && tablePositions.front() < lastDigit)           tablePositions.pop_front();         if (i < groups.size() - 1 && !tablePositions.empty())           dp[i] = (dp[i] + MOD - table[tablePositions.front()]) % MOD;       }       tablePositions.push_front(groups[i]);       table[groups[i]] = dp[i - 1];     }     if (groups.size() == 2) dp[groups.size() - 1]--;     printf( %d , dp[groups.size() - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 200200;   vector<int> adj[MAX];   int ch[MAX], sz, from[MAX], dpthMx[MAX], dpthMn[MAX], n;   void dfs(int cur, int par) {     for (auto i : adj[cur])       if (i != par) {         dfs(i, cur);         dpthMn[cur] = min(dpthMn[cur], dpthMn[i] + 1);         dpthMx[cur] = max(dpthMx[cur], dpthMx[i] + 1);       }     if (dpthMn[cur] == MAX) dpthMn[cur] = 0;   }   pair<int, int> dfs0(int cur, int par, int d) {     from[cur] = par;     pair<int, int> ret(d, cur);     for (auto i : adj[cur])       if (i != par) ret = max(ret, dfs0(i, cur, d + 1));     return ret;   }   int main() {     scanf( %d , &n);     fill(dpthMn, dpthMn + n + 1, MAX);     for (int i = 1, u, v; i < n; ++i) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     pair<int, int> diam = dfs0(dfs0(1, 0, 0).second, 0, 0);     while (diam.first > 0) diam.first -= 2, diam.second = from[diam.second];     dfs(diam.second, 0);     for (auto i : adj[diam.second]) {       if (dpthMx[i] != dpthMn[i]) return puts( -1 ), 0;       ch[sz++] = dpthMx[i] + 1;     }     sort(ch, ch + sz);     sz = unique(ch, ch + sz) - ch;     if (sz > 2) return puts( -1 ), 0;     ch[sz] = 0;     int ans = ch[0] + ch[1];     while (!(ans & 1)) ans >>= 1;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void file_io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   void PLAY() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);   }   int main() {     PLAY();     int n;     cin >> n;     int x[1000000] = {0};     for (int i = 0; i < n - 1; i++) {       int l, r;       cin >> l >> r;       x[l]++;       x[r]++;     }     for (int i = 1; i <= n; i++) {       if (x[i] == 2) return cout <<  NO , 0;     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   int licznik;   long long sym(long long k) {     long long eat = k, m = n - k;     while (m > 0) {       licznik++;       m -= m / 10;       eat += min(k, m);       m -= k;     }     return eat;   }   long long binsuche(long long lewy, long long prawy) {     if (lewy < prawy) {       if (sym((lewy + prawy) / 2) * 2 >= n)         return binsuche(lewy, (lewy + prawy) / 2);       else         return binsuche((lewy + prawy) / 2 + 1, prawy);     }     return lewy;   }   int main() {     licznik = 0;     int a, b;     cin >> n;     cout << binsuche(1, n);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 10, INF = 1e9;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -f;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch - 48;       ch = getchar();     }     return x * f;   }   int n, l[N], r[N], a[N], b[N], c[N];   int ans, sum, pos, cnt, tot;   int t1, t2;   signed main() {     n = read();     for (int i = 1; i <= n; i++) {       l[i] = read();       r[i] = read();       a[++cnt] = l[i];       a[++cnt] = r[i];     }     sort(a + 1, a + cnt + 1);     for (int i = 1; i <= cnt; i++)       if (i == 1 || a[i] != a[i - 1]) a[++tot] = a[i];     for (int i = 1; i <= n; i++) {       t1 = lower_bound(a + 1, a + tot + 1, l[i]) - a;       t2 = lower_bound(a + 1, a + tot + 1, r[i]) - a;       c[t1] = l[i], c[t2] = r[i];       b[t1]++, b[t2]--;     }     for (int i = 1; i <= tot; i++) {       sum += b[i];       if (sum > ans) ans = sum, pos = c[i];     }     printf( %d %d , pos, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double a, b, c;   int main() {     while (~scanf( %lf%lf%lf , &a, &b, &c)) {       double x1 = (-b + sqrt(b * b - 4 * a * c)) / (2 * a),              x2 = (-b - sqrt(b * b - 4 * a * c)) / (2 * a);       if (a < 0) swap(x1, x2);       printf( %.6lf n%.6lf n , x1, x2);     }     return 0;     ;   }
#include <bits/stdc++.h>   using namespace std;   void _fill_int(int* p, int val, int rep) {     int i;     for (i = 0; i < rep; i++) p[i] = val;   }   signed long long GETi() {     signed long long i;     scanf( %lld , &i);     return i;   }   int N, X, Y;   int mat[501][501];   int vis[501][501];   int LM[501], RM[501], TM[501], BM[501];   char str[3000002];   char* P;   void dfs(int cy, int cx, int pre, bool on) {     char move[16] =  *LR*U***D ;     int i;     if (on && (mat[cy][cx] & 1) == 0) *P++ =  1 ;     if ((vis[cy][cx] & 1) && (pre != 1)) *P++ =  L , dfs(cy, cx - 1, 2, on);     if ((vis[cy][cx] & 2) && (pre != 2)) *P++ =  R , dfs(cy, cx + 1, 1, on);     if ((vis[cy][cx] & 4) && (pre != 4)) *P++ =  U , dfs(cy - 1, cx, 8, on);     if ((vis[cy][cx] & 8) && (pre != 8)) *P++ =  D , dfs(cy + 1, cx, 4, on);     if (!on) *P++ =  2 ;     if (pre != 0) *P++ = move[pre];   }   void solve() {     int f, i, j, k, l, x, y;     cin >> N >> Y >> X;     X--;     Y--;     for (y = 0; y < N; y++)       for (x = 0; x < N; x++) cin >> mat[y][x];     for (y = 0; y < N; y++) LM[y] = TM[y] = N, RM[y] = BM[y] = -1;     l = 0;     mat[Y][X] |= 2;     for (y = 0; y < N; y++)       for (x = 0; x < N; x++)         if (mat[y][x]) {           l++;           if (LM[y] > x) LM[y] = x;           RM[y] = x;           if (TM[x] > y) TM[x] = y;           BM[x] = y;         }     if (l == 1 && (mat[Y][X] & 1)) return (void)printf( YES n2 n );     P = str;     stack<int> Q;     Q.push(Y * 1000 + X);     while (!Q.empty()) {       int k = Q.top();       Q.pop();       int cx = k % 1000, cy = k / 1000;       TM[cx] = min(TM[cx], cy);       BM[cx] = max(BM[cx], cy);       LM[cy] = min(LM[cy], cx);       RM[cy] = max(RM[cy], cx);       for (i = 0; i < 4; i++) {         int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};         int tx = cx + dx[i], ty = cy + dy[i];         if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;         if (dy[i] > 0 && BM[cx] < ty) continue;         if (dy[i] < 0 && TM[cx] > ty) continue;         if (dx[i] > 0 && RM[cy] < tx) continue;         if (dx[i] < 0 && LM[cy] > tx) continue;         if (mat[ty][tx] & 2) continue;         mat[ty][tx] |= 2;         if (dx[i] < 0) vis[cy][cx] |= 1, vis[ty][tx] |= 2;         if (dx[i] > 0) vis[cy][cx] |= 2, vis[ty][tx] |= 1;         if (dy[i] < 0) vis[cy][cx] |= 4, vis[ty][tx] |= 8;         if (dy[i] > 0) vis[cy][cx] |= 8, vis[ty][tx] |= 4;         Q.push(ty * 1000 + tx);       }     }     for (y = 0; y < N; y++)       for (x = 0; x < N; x++)         if (mat[y][x] == 1) return (void)printf( NO n );     dfs(Y, X, 0, true);     dfs(Y, X, 0, false);     (void)printf( YES n%s n , str);   }   int main(int argc, char** argv) {     if (argc > 1) freopen(argv[1],  r , stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     ;     long long z;     cin >> z;     for (; z--;) {       long long a;       cin >> a;       vector<string> m(a);       int can[a];       set<string> s;       for (int q = 0; q < a; q++) {         cin >> m[q];         s.insert(m[q]);       }       for (int q = 0; q < a; q++) {         reverse(m[q].begin(), m[q].end());         can[q] = !s.count(m[q]);         reverse(m[q].begin(), m[q].end());       }       long long fl = 1;       vector<long long> n, t(4), msk(a);       int i = 0;       for (string &u : m) {         int mask = (u[0] ==  1 ) * 2 + (u.back() ==  1 ) * 1;         t[mask]++;         msk[i++] = mask;       }       if (!(t[1] + t[2]))         fl = t[0] == a || t[3] == a;       else {         long long ABS = abs(t[1] - t[2]), nd = t[2] > t[1] ? 2 : 1;         for (int q = 0; q < a && ABS > 1; q++) {           if (msk[q] != nd || !can[q]) continue;           ABS -= 2;           n.push_back(q + 1);         }         fl = ABS < 2;       }       if (!fl)         cout <<  -1 n ;       else {         cout << n.size() <<   n ;         for (long long i : n) cout << i <<    ;         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   ;   vector<pair<int, int>> vec;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, k, a, b, c;     c = 1;     cin >> n >> k;     for (int i = 0; i < n; i++) {       cin >> a >> b;       vec.push_back(make_pair(a * -1, b));     }     sort(vec.begin(), vec.end());     for (int i = 0; i < n; i++) {       if (i == k - 1) {         while (vec[i] == vec[i + 1]) {           i++;           c++;         }         cout << c <<   n ;         break;       }       if (vec[i] == vec[i + 1])         c++;       else         c = 1;     }     cout.flush();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, ctr = 0, j;     int arr[1000];     cin >> n;     for (i = 0; i < n; i++) cin >> arr[i];     for (i = 0; i < n; i++)       if (arr[i] == 1) break;     if (i == n) {       cout << 0;       return 0;     }     for (j = n - 1; j >= 0; j--)       if (arr[j] == 1) break;     if (i == j) {       cout << 1;       return 0;     }     ctr = 1;     for (int k = i + 1; k <= j; k++) {       if (arr[k] == 1)         ctr++;       else if (arr[k] == 0 && arr[k - 1] == 1 && arr[k + 1] == 1)         ctr++;     }     cout << ctr;     return 0;   }