malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   char s[2000011];   int h1[2000011], h2[2000011], p1[2000011], p2[2000011], mod1 = 998244353,                                                           mod2 = 1000000007;   int geth1(int L, int R) {     return (h1[R] - h1[L - 1] * 1ll * p1[R - L + 1] % mod1 + mod1) % mod1;   }   int geth2(int L, int R) {     return (h2[R] - h2[L - 1] * 1ll * p2[R - L + 1] % mod2 + mod2) % mod2;   }   int ans[2000011];   int main() {     scanf( %d%s , &n, s + 1);     h1[0] = h2[0] = 0;     for (int i = 1; i <= n; i++)       h1[i] = (h1[i - 1] * 27ll + s[i] -  a  + 1) % mod1,       h2[i] = (h2[i - 1] * 27ll + s[i] -  a  + 1) % mod2;     p1[0] = p2[0] = 1;     for (int i = 1; i <= n; i++)       p1[i] = p1[i - 1] * 27ll % mod1, p2[i] = p2[i - 1] * 27ll % mod2;     for (int i = 0; i <= (n + 1) >> 1; i++) ans[i] = -1;     for (int i = 1; i <= n >> 1; i++) {       int L = 0, R = i, p = n - i + 1;       while (L < R) {         int mid = (L + R + 1) >> 1, a = i - mid + 1, b = i + mid - 1,             c = p - mid + 1, d = p + mid - 1;         if (geth1(a, b) == geth1(c, d) && geth2(a, b) == geth2(c, d))           L = mid;         else           R = mid - 1;       }       ans[i - L + 1] = max(ans[i - L + 1], 2 * L - 1);     }     for (int i = 1; i <= (n + 1) >> 1; i++) {       ans[i] = max(ans[i], ans[i - 1] - 2);       printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int M, N, x, a[400010], mini = 0;     cin >> M >> N;     memset(a, 0, sizeof(a));     for (int i = 1; i <= M; i++) {       scanf( %d , &x);       a[x % N]++;       if (x % N != mini)         printf( %d n , a[mini] * N + mini);       else {         if (i < N) {           for (int j = mini; j <= min(N - 1, i); j++) {             if (a[j] == 0) {               mini = j;               break;             }             if (a[mini] > a[j]) mini = j;           }         } else {           mini = 0;           for (int j = 1; j <= min(N - 1, i); j++) {             if (a[j] == 0) {               mini = j;               break;             }             if (a[mini] > a[j]) mini = j;           }         }         printf( %d n , a[mini] * N + mini);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 0;     char c = getchar();     while (!isdigit(c)) f |= c ==  - , c = getchar();     while (isdigit(c)) x = x * 10 + c -  0 , c = getchar();     return f ? -x : x;   }   inline int max(int a, int b, int c) { return max(a, max(b, c)); }   int n, m, a[200010];   struct Trie {     int nxt[2], sz;   } T[200010 * 31];   int rt = 1, top = 1;   void insert(int x) {     int now = rt;     for (int i = 31; ~i; --i) {       if (!T[now].nxt[x >> i & 1]) T[now].nxt[x >> i & 1] = ++top;       now = T[now].nxt[x >> i & 1];     }     T[now].sz = 1;   }   int ans;   int dfs(int i, int d) {     if (!i) return 0;     int ls, rs;     if (d == -1) return min(2, T[i].sz);     ls = dfs(T[i].nxt[0], d - 1);     T[i].sz += T[T[i].nxt[0]].sz;     rs = dfs(T[i].nxt[1], d - 1);     T[i].sz += T[T[i].nxt[1]].sz;     if (ls == 2 && rs == 2)       ans += min(T[T[i].nxt[0]].sz, T[T[i].nxt[1]].sz) - 1,           T[i].sz -= min(T[T[i].nxt[0]].sz, T[T[i].nxt[1]].sz) - 1;     return min(2, ls + rs);   }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) a[i] = read(), insert(a[i]);     dfs(rt, 31);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   std::mt19937_64 rng(       std::chrono::steady_clock::now().time_since_epoch().count());   long long int myRand(long long int R) {     long long int val = rng() % R;     assert(val >= 0);     return val;   }   const long double PI = atan(1.0) * 4;   const int32_t INF32 = 2e9 + 7;   const int64_t INF64 = 3e18;   const int32_t LOG = 21;   const int32_t MOD = 1e9 + 7;   using namespace std;   void my_debugger(string second, long long int LINE_NUM) { cerr <<   n ; }   template <typename start, typename... end>   void my_debugger(string second, long long int LINE_NUM, start x, end... y) {     if (second.back() !=  , ) {       second +=  , ;       cerr <<  LINE(  << LINE_NUM <<  ):  ;     }     long long int i = second.find( , );     cerr << second.substr(0, i) <<   =   << x;     second = second.substr(i + 1);     if (!second.empty()) cerr <<  ,  ;     my_debugger(second, LINE_NUM, y...);   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr);     long long int tests = 1;     for (long long int ii = 0; ii < (long long int)tests; ii++) {       vector<long long int> a(6);       for (long long int i = 0; i < (long long int)6; i++) cin >> a[i];       long long int n;       cin >> n;       vector<long long int> b(n);       for (long long int i = 0; i < (long long int)n; i++) cin >> b[i];       long long int ans = 2e9;       vector<pair<long long int, long long int> > v;       for (long long int fret = 0; fret < (long long int)6; fret++) {         for (long long int i = 0; i < (long long int)n; i++) {           long long int x = b[i] - a[fret];           v.push_back({b[i] - a[fret], i});         }       }       sort(v.begin(), v.end());       long long int siz = v.size();       vector<long long int> cnt(n, 0);       long long int cur = 0;       long long int tot = 0;       for (long long int i = 0; i < (long long int)v.size(); i++) {         while (cur < siz && tot < n) {           cnt[v[cur].second]++;           if (cnt[v[cur].second] == 1) tot++;           cur++;         }         if (tot == n) ans = min(ans, v[cur - 1].first - v[i].first);         cnt[v[i].second]--;         if (cnt[v[i].second] == 0) tot--;       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string a, b;   int r = 0;   int main() {     getline(cin, a);     getline(cin, b);     int k = 0;     while (a[k] ==  0 ) k++;     a = a.substr(k, a.size() - k);     k = 0;     while (b[k] ==  0 ) k++;     b = b.substr(k, b.size() - k);     if (a.size() < b.size()) {       cout <<  <  << endl;       return 0;     }     if (a.size() > b.size()) {       cout <<  >  << endl;       return 0;     }     for (int i = 0; i < a.size(); i++) {       if (a[i] > b[i]) {         cout <<  >  << endl;         return 0;       }       if (a[i] < b[i]) {         cout <<  <  << endl;         return 0;       }     }     cout <<  =  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     char arr[n];     int sf = 0, fs = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int j = 0; j < n - 1; j++) {       if (arr[j] ==  S ) {         if (arr[j + 1] ==  F ) sf++;       } else if (arr[j] ==  F ) {         if (arr[j + 1] ==  S ) fs++;       }     }     if (sf > fs)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 502;   int n, m, l = -1, ok = 1, r;   string s[N];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> s[i];     for (int j = 0; j < n; j++) {       l = r = -1;       for (int i = 0; i < s[j].length(); i++) {         if (l == -1 && s[j][i] ==  X )           l = r = i;         else if (l != -1 && s[j][i] ==  X ) {           r = i;         }       }       if (l != -1) break;     }     if (l == -1) {       cout <<  NO ;       return 0;     }     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = l; j <= r; j++)         if (s[i][j] ==  X ) cnt++;       if (cnt != r - l + 1 && cnt != 0) ok = 0;     }     if (ok == 1)       for (int i = 0; i < n; i++)         for (int j = 0; j < s[i].length(); j++)           if ((j < l || j > r) && s[i][j] ==  X ) ok = 0;     if (ok)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str;     cin >> str;     string s =  WUB ;     size_t pos = str.find(s);     while (pos != string::npos) {       string token = str.substr(0, pos);       if (token.length() != 0) cout << token <<    ;       str.erase(0, pos + 3);       pos = str.find(s);     }     cout << str << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7, M = 2e6 + 7, INF = INT_MAX / 10;   long long powe(long long x, long long y) {     x = x % mod, y = y % (mod - 1);     long long ans = 1;     while (y > 0) {       if (y & 1) {         ans = (1ll * x * ans) % mod;       }       y >>= 1;       x = (1ll * x * x) % mod;     }     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     int n, m, p;     cin >> n >> m >> p;     int a1[n], a2[m];     for (int i = 0; i < n; i++) cin >> a1[i];     for (int i = 0; i < m; i++) cin >> a2[i];     int p1, p2;     for (p1 = 0; p1 < n; p1++) {       if (a1[p1] % p) break;     }     for (p2 = 0; p2 < m; p2++) {       if (a2[p2] % p) break;     }     int ans = p1 + p2;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, ans = 1e9;   int a[100005];   inline int read() {     int x = 0, f = 1;     char ch = getchar();     for (; ch <  0  || ch >  9 ; ch = getchar())       if (ch ==  - ) f = -1;     for (; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch -  0 ;     return x * f;   }   inline void print(int x) {     if (x >= 10) print(x / 10);     putchar(x % 10 +  0 );   }   int main() {     n = read(), m = read();     for (int i = 1, l, r; i <= m; i++)       l = read(), r = read(), ans = min(ans, r - l + 1);     for (int i = 1; i <= ans; i++) a[i] = i - 1;     for (int i = ans + 1; i <= n; i++) a[i] = a[i - ans];     print(ans);     puts(  );     for (int i = 1; i <= n; i++) print(a[i]), putchar(   );     puts(  );     return 0;   }
#include <bits/stdc++.h>   const long long mod = (long long)1e9 + 7;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, m;     cin >> n >> m;     vector<long long> v(m);     bool valid = true;     for (long long i = 0; i < m; i++) {       cin >> v[i];       if (v[i] == n or v[i] == 1) valid = 0;     }     if (!valid) {       cout <<  NO             <<   n ;       return 0;     }     sort(v.begin(), v.end());     for (long long i = 2; i < m; i++) {       if (v[i] - 1 == v[i - 1] and v[i] - 2 == v[i - 2]) {         valid = 0;         break;       }     }     if (valid)       cout <<  YES             <<   n ;     else       cout <<  NO             <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     string out, chr;     cin >> n >> k;     for (int i = 0; i < k; ++i) chr +=  a  + i;     for (int i = 0; i < n; ++i) out += chr[i % k];     cout << out;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   const int MAX = 47 + 5;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000005329;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 555;   int n, x[MAX], sm, k, tmp;   long long dp[MAX][MAX][MAX], fr[MAX];   double ans, res;   long long f(int nw, int rem, int cnt) {     if (rem == 0) return cnt == 0;     if (cnt < 0 || nw > n) return 0;     long long &ret = dp[nw][rem][cnt];     if (ret != -1) return ret;     ret = f(nw + 1, rem, cnt);     if (x[nw] <= rem) ret += f(nw + 1, rem - x[nw], cnt - 1);     return ret;   }   int main() {     cout << fixed << setprecision(10);     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> x[i], sm += x[i];     cin >> k;     if (k >= sm) return cout << n <<   n , 0;     for (int i = 1; i <= n; ++i) {       tmp = x[i];       x[i] = 100;       memset(dp, -1, sizeof dp);       for (int j = max(1, k - tmp + 1); j <= k; ++j)         for (int o = 1; o <= n; ++o) fr[o] += f(1, j, o);       x[i] = tmp;     }     for (int i = 1; i <= n; ++i) {       res = fr[i] * i;       for (int j = i + 1; j < n; ++j) res /= j, res *= n - j;       res /= n;       ans += res;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x;   int main() {     scanf( %d%d , &n, &m);     x = n;     for (int i = 0; i < m; i++) {       int l, r;       scanf( %d%d , &l, &r);       x = min(x, r - l + 1);     }     printf( %d n , x);     for (int i = 0; i < n; i++) printf( %d  , i % x);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     vector<int> g(n), v(m), b(m);     for (auto &i : g) cin >> i;     for (auto &i : v) cin >> i;     for (auto &i : b) cin >> i;     int res = 0;     vector<bool> news(n, false);     vector<int> x(n, 1);     for (int i = 1; i <= m; ++i) {       int a = (v[i - 1] + res - 1) % n + 1;       int rating = b[i - 1] >= n ? n : b[i - 1], ctr = 0, temp = a;       if (!news[a - 1]) {         news[a - 1] = 1;         ctr++;       }       while (rating) {         rating -= x[a - 1];         if (rating <= 0) break;         temp = g[a - 1];         if (!news[temp - 1]) {           news[temp - 1] = 1;           ctr++;         }         x[a - 1] += x[temp - 1];         g[a - 1] = g[temp - 1];         a = temp;       }       res = ctr;       cout << ctr <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int x, y;     y = scanf( %d , &x);     return x;   }   const int N = 2 * 100 * 1000 + 5;   int a[N], ans[N];   vector<pair<int, int>> v;   int seg[4 * N];   void add(int p, int s = 0, int e = N, int x = 1) {     seg[x]++;     if (e - s == 1) return;     int mid = (s + e) / 2;     if (p < mid)       add(p, s, mid, 2 * x);     else       add(p, mid, e, 2 * x + 1);   }   int pth(int p, int s = 0, int e = N, int x = 1) {     if (e - s == 1) return s;     int mid = (s + e) / 2;     if (seg[2 * x] >= p)       return pth(p, s, mid, 2 * x);     else       return pth(p - seg[2 * x], mid, e, 2 * x + 1);   }   int main() {     int n = in();     for (int i = 0; i < n; i++) {       a[i] = in();       v.push_back({-a[i], i});     }     sort(v.begin(), v.end());     vector<pair<pair<int, int>, int>> que;     int m = in();     for (int i = 0; i < m; i++) {       int k = in(), p = in();       que.push_back({{k, p}, i});     }     sort(que.begin(), que.end());     int r = 0;     for (auto q : que) {       int k = q.first.first, p = q.first.second, t = q.second;       while (r < k) {         add(v[r++].second);       }       ans[t] = a[pth(p)];     }     for (int i = 0; i < m; i++) cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 100000 + 10;   const int Alpha = 27;   string str;   int sum[Alpha], need[Alpha];   int get(char a) {     if (a ==  9 ) a =  6 ;     if (a ==  5 ) a =  2 ;     return a -  0 ;   }   int main() {     int i;     cin >> str;     for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++need[get(str[i])];     cin >> str;     for ((i) = (0); (i) != ((int)str.size()); ++(i)) ++sum[get(str[i])];     int ans = 1000000000;     for ((i) = (0); (i) != (Alpha); ++(i))       if (!sum[i] && need[i])         ans = 0;       else if (need[i])         ans = min(ans, sum[i] / need[i]);     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   long long a[101], b[101];   int main() {     long long i, j, k, l, n, c, m, x, y, lft, rgt, p, q;     cin >> n;     for (i = 0; i < 2 * n; i++) {       cin >> a[i];     }     sort(a, a + 2 * n);     c = 0;     p = 0;     long long mnm = 1267357834;     for (i = 0; i < 2 * n; i++) {       if (i > 0) {         p = 0;         for (j = 0; j < i; j++) {           b[p++] = a[j];         }       }       for (j = i + 1; j < 2 * n; j++) {         q = p;         for (k = i + 1; k < 2 * n; k++) {           if (k != j) {             b[q++] = a[k];           }         }         long long x = 0;         for (k = 0; k < q; k += 2) {           x += abs(b[k] - b[k + 1]);         }         mnm = min(mnm, x);       }     }     cout << mnm << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool arr[1001][1001];   struct node {     int ct;     int lastind;   };   struct node1 {     int ct;     int lastind;   };   node row[1001];   node1 col[1001];   int main() {     vector<int> a;     int n, i, x, y, j, temp;     scanf( %d , &n);     for (i = 0; i < n - 1; i++) {       scanf( %d%d , &x, &y);       arr[x][y] = 1;     }     for (i = 1; i <= n; i++) {       row[i].ct = 0;       row[i].lastind = 0;       for (j = 1; j <= n; j++) {         if (arr[i][j]) {           row[i].ct++;           row[i].lastind = j;         }       }     }     for (i = 1; i <= n; i++) {       temp = i;       for (j = i + 1; j <= n; j++) {         if (row[temp].ct > row[j].ct) {           temp = j;         } else if (row[temp].ct == row[j].ct &&                    row[temp].lastind > row[j].lastind)           temp = j;       }       if (temp != i) {         a.push_back(1);         a.push_back(i);         a.push_back(temp);         swap(row[i], row[temp]);         for (j = 1; j <= n; j++) {           swap(arr[i][j], arr[temp][j]);         }       }     }     for (i = 1; i <= n; i++) {       col[i].ct = 0;       col[i].lastind = n;       for (j = 1; j <= n; j++) {         if (arr[j][i]) {           col[i].ct++;           col[i].lastind = min(col[i].lastind, j);         }       }     }     for (i = 1; i <= n; i++) {       temp = i;       for (j = i + 1; j <= n; j++) {         if (col[temp].ct < col[j].ct) {           temp = j;         } else if (col[temp].ct == col[j].ct &&                    col[temp].lastind > col[j].lastind)           temp = j;       }       if (temp != i) {         a.push_back(2);         a.push_back(i);         a.push_back(temp);         swap(col[i], col[temp]);       }     }     printf( %d n , a.size() / 3);     for (i = 0; i < a.size(); i += 3) {       printf( %d %d %d n , a[i], a[i + 1], a[i + 2]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 2e5 + 5;   int a[maxn], lst[maxn];   bool used[maxn];   int occ[maxn];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int ans = n;     for (int i = 1; i <= n; i++) {       cin >> a[i];       lst[a[i]] = i;       if (occ[a[i]] == 0) ans--;       occ[a[i]]++;     }     cout << ans <<   n ;     int j = 1;     for (int i = 1; i <= n; i++) {       if (!used[a[i]] && (a[i] < j || lst[a[i]] == i)) {         used[a[i]] = true;         cout << a[i] <<    ;       } else {         while ((j != a[i] && occ[j] > 0) || occ[j] == 1 || used[j]) j++;         used[j] = true;         cout << j <<    ;       }     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 10, maxm = 2e6 + 10;   const long long INF = 0x3f3f3f3f, mod = 1e9 + 7;   int casn, n, m, k;   namespace graph {   vector<int> g[maxn];   int all, sz[maxn], root, maxt;   bool vis[maxn];   int dfs_root(int now, int fa) {     int cnt = 1;     for (auto to : g[now]) {       if (to == fa || vis[to]) continue;       cnt += dfs_root(to, now);     }     int tmp = max(cnt - 1, all - cnt);     if (maxt > tmp) maxt = tmp, root = now;     return sz[now] = cnt;   }   int ans[maxn];   void dfs_col(int now, int fa, int c) {     ans[now] = c;     for (auto to : g[now])       if (to != fa && !vis[to]) dfs_col(to, now, c);   }   void dfs_dv(int now, int d = 0) {     vis[now] = 1;     dfs_col(now, now, d);     for (auto to : g[now]) {       if (vis[to]) continue;       maxt = root = n + 1;       all = sz[to];       dfs_root(to, now);       dfs_dv(root, d + 1);     }   }   void solve(int n) {     all = maxt = root = n + 1;     dfs_root(1, 1);     dfs_dv(root);   }   }  // namespace graph   using namespace graph;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i) {       int a, b;       cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     solve(n);     for (int i = 1; i <= n; ++i) cout << char(ans[i] +  A ) <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int main() {     int t;     scanf( %d , &t);     ;     while (t--) {       int n;       scanf( %d , &n);       ;       if (n % 2 == 0) {         n = n / 2;         while (n--) {           cout << 1;         }         cout <<   n ;       } else {         n = n / 2;         n--;         cout << 7;         while (n--) {           cout << 1;         }         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int dp[1 << 6][1 << 6][41][41];   int h, w;   const int dy[] = {-1, 0, 0, 1, 0};   const int dx[] = {0, -1, 1, 0, 0};   int dfs(const int up, const int down, const int cx, const int cy) {     if (cy == h) {       int cnt = 0;       for (int i = 0; i < w; i++)         if (!((up >> i) & 1)) cnt++;       return cnt;     } else if (cx == w)       return dfs(up, down, 0, cy + 1);     if (dp[up][down][cy][cx] != -1) return dp[up][down][cy][cx];     int res = 0;     for (int i = 0; i < 5; i++) {       const int mx = cx + dx[i];       const int my = cy + dy[i];       if (!(my >= 0 && mx >= 0 && mx < w && my < h)) continue;       int nup = up;       int ndown = down;       if (dy[i] == -1) {         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown &= ~(1 << cx);         int adNum = 0;         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else if (dy[i] == 1) {         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown |= (1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else if (dx[i] == 1) {         ndown |= (1 << mx);         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown &= ~(1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else if (dx[i] == -1) {         nup |= (1 << mx);         if ((down >> cx) & 1)           nup |= (1 << cx);         else           nup &= ~(1 << cx);         ndown &= ~(1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       } else {         ndown &= ~(1 << cx);         nup |= (1 << cx);         int adNum = !((up >> cx) & 1);         if (cy == 0) adNum = 0;         res = max(res, dfs(nup, ndown, cx + 1, cy) + adNum);       }     }     return dp[up][down][cy][cx] = res;   }   int main() {     int n, m;     cin >> n >> m;     if (n > m) swap(n, m);     w = n;     h = m;     memset(dp, -1, sizeof(dp));     int res = dfs(0, 0, 0, 0);     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int max;     int a[3];     for (int i = 0; i < 3; i++) {       cin >> a[i];       sort(a, a + 3);       max = 1 + a[2] - (a[0] + a[1]);     }     if (max > 0)       cout << max;     else       cout <<  0 ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<pair<int, int> > v;     while (n--) {       int x, y;       cin >> x >> y;       v.push_back(make_pair(-x, y));     }     sort(v.begin(), v.end());     int ind = k - 1;     int res = 1;     while (ind - 1 >= 0 && v[ind] == v[ind - 1]) {       ind--;       res++;     }     ind = k - 1;     while (ind + 1 < v.size() && v[ind] == v[ind + 1]) {       ind++;       res++;     }     cout << res << endl;     return 0;   }