malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long mod = 1e9 + 7;   inline long long bigmod(long long B, long long P) {     long long R = 1;     while (P > 0) {       if (P & 1) {         R = (R * B) % mod;       }       P >>= 1;       B = (B * B) % mod;     }     return R;   }   const long long mxn = 500;   long long Mod(long long a) {     if (a < 0)       return (a + mod) % mod;     else       return a % mod;   }   long long Mul(long long a, long long b) { return Mod(Mod(a) * Mod(b)); }   long long Add(long long a, long long b) { return Mod(Mod(a) + Mod(b)); }   vector<long long> adj[mxn];   long long vis[mxn], pred[mxn], dist[mxn];   vector<long long> adj2[mxn];   long long vis2[mxn], pred2[mxn], dist2[mxn];   long long n;   bool bfs(long long root) {     queue<long long> q;     q.push(root);     vis[root] = 1;     while (!q.empty()) {       long long u = q.front();       q.pop();       for (long long v : adj[u]) {         if (!vis[v]) {           vis[v] = 1;           dist[v] = dist[u] + 1;           q.push(v);           if (v == n) return true;         }       }     }     return false;   }   bool bfs2(long long root) {     queue<long long> q;     q.push(root);     vis2[root] = 1;     while (!q.empty()) {       long long u = q.front();       q.pop();       for (long long v : adj2[u]) {         if (!vis2[v]) {           vis2[v] = 1;           dist2[v] = dist2[u] + 1;           q.push(v);           if (v == n) return true;         }       }     }     return false;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long tt = 1;     for (long long tc = 1; tc <= tt; tc++) {       long long m, f = 0;       cin >> n >> m;       map<pair<long long, long long>, bool> trainase;       for (long long i = 0; i < m; i++) {         long long u, v;         cin >> u >> v;         adj[u].push_back(v);         adj[v].push_back(u);         trainase[{u, v}] = 1;         trainase[{v, u}] = 1;         if (u == n || v == n) f = 1;       }       if (!f)         cout << -1 <<   n ;       else {         for (long long i = 1; i <= n; i++) {           for (long long j = i + 1; j <= n; j++) {             if (!trainase[{i, j}]) {               adj2[i].push_back(j);               adj2[j].push_back(i);             }           }         }         if (!bfs2(1) || !bfs(1)) {           cout << -1 <<   n ;           return 0;         }         bfs(1);         bfs2(1);         cout << max(dist2[n], dist[n]) <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3fll;   const long long M = 1e9 + 7;   const long long maxn = 2e5 + 7;   const double eps = 0.00000001;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <typename T>   inline T abs(T a) {     return a > 0 ? a : -a;   }   void exgcd(long long a, long long b, long long &d, long long &x, long long &y) {     if (!b) {       d = a;       x = 1;       y = 0;     } else {       exgcd(b, a % b, d, y, x);       y -= a / b * x;     }   }   int n, m;   int i, j;   bool used[maxn];   vector<int> v[maxn];   int num[maxn], fa[maxn], mx;   int pp = 1;   void print(int mx) {     if (fa[mx]) print(fa[mx]);     long long a, b, t;     for (i = 0; i < v[mx].size(); i++) {       exgcd(pp, m, t, a, b);       printf( %I64d  , (v[mx][i] / t * a % m + m) % m);       pp = v[mx][i];     }   }   int main() {     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) scanf( %d , &j), used[j] = 1;     for (i = 1; i < m; i++)       if (!used[i]) v[gcd(i, m)].push_back(i);     for (i = 1; i < m; i++) {       if ((num[i] += v[i].size()) > num[mx]) mx = i;       for (j = i << 1; j < m; j += i)         if (num[j] < num[i]) num[j] = num[i], fa[j] = i;     }     printf( %d n , num[mx] + !used[0]);     print(mx);     if (!used[0])       puts( 0 );     else       puts(  );   }
#include <bits/stdc++.h>   using namespace std;   long long K, N;   string A, B;   bool valid[1001];   long long dp[100002][2];   int main() {     ios::sync_with_stdio(0);     cin >> A >> B >> K;     N = A.size();     dp[0][0] = 1, dp[0][1] = 0;     for (int i = 1; i <= K; ++i) {       dp[i][0] = (N - 1) * dp[i - 1][1];       dp[i][1] = dp[i - 1][0] + (N - 2) * dp[i - 1][1];       dp[i][0] %= 1000000007;       dp[i][1] %= 1000000007;     }     long long ans = 0;     for (int i = 0; i < N; ++i) {       valid[i] = true;       for (int j = 0; j < N; ++j)         if (A[j % N] != B[(i + j) % N]) valid[i] = false;       if (valid[i]) {         if (i == 0)           ans = (ans + dp[K][0]) % 1000000007;         else           ans = (ans + dp[K][1]) % 1000000007;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   int n, m;   using namespace std;   vector<int> used(5005, 0);   vector<int> used2(5005, 0);   int jlo1 = 3;   vector<int> a;   long long res = 0;   vector<vector<int>> graph(5005, a);   vector<int> b;   vector<vector<int>> graph1(5005, b);   int q = 0;   bool flag = false;   void dfs(int p) {     {       q++;       used[p] = 1;       for (int i = 0; i < graph[p].size(); i++) {         if (!used[graph[p][i]]) dfs(graph[p][i]);       }     }   }   void dfs2(int p) {     {       q++;       used2[p] = 1;       for (int i = 0; i < graph[p].size(); i++) {         if (!used2[graph[p][i]]) dfs2(graph[p][i]);       }     }   }   int main() {     int k, t, t1;     cin >> n >> m >> k;     for (int i = 0; i < m; i++) {       cin >> t >> t1;       graph[t].push_back(t1);     }     dfs(k);     vector<pair<int, int>> p_q;     for (int i = 1; i <= n; i++) {       if (!used[i]) {         used2.assign(5005, 0);         q = 0;         dfs2(i);         p_q.push_back(make_pair(q, i));       }     }     sort(p_q.rbegin(), p_q.rend());     long long res = 0;     for (int i = 0; i < p_q.size(); i++) {       if (!used[p_q[i].second]) {         res++;         dfs(p_q[i].second);       }     }     cout << res <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   vector<int> vec[N], fenw[N];   int n, k, x[N], r[N], f[N], id[N], rev[N];   void update(int who, int p, int v) {     while (p < fenw[who].size()) fenw[who][p] += v, p += p & -p;   }   int pref(int who, int p) {     int ret = 0;     while (p) ret += fenw[who][p], p -= p & -p;     return ret;   }   inline int get(int who, int l, int r) {     if (l > r) return 0;     return pref(who, r) - (l ? pref(who, l - 1) : 0);   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       scanf( %d %d %d , x + i, r + i, f + i);       id[i] = i, vec[f[i]].emplace_back(i);     }     for (int i = 0; i < N; ++i) {       if (vec[i].empty()) continue;       vec[i].emplace_back(0);       sort(vec[i].begin(), vec[i].end(),            [](int p, int q) { return x[p] < x[q]; });       fenw[i].resize(vec[i].size(), 0);       for (int j = 0; j < vec[i].size(); ++j) {         rev[vec[i][j]] = j, vec[i][j] = x[vec[i][j]];       }     }     sort(id + 1, id + n + 1, [](int i, int j) { return r[i] > r[j]; });     long long ans = 0;     for (int it = 1; it <= n; ++it) {       int i = id[it];       for (int oth = max(0, f[i] - k); oth <= f[i] + k; ++oth) {         if (vec[oth].empty()) continue;         int lt = lower_bound(vec[oth].begin(), vec[oth].end(), x[i] - r[i]) -                  vec[oth].begin();         int rt = upper_bound(vec[oth].begin(), vec[oth].end(), x[i] - 1) -                  vec[oth].begin() - 1;         ans += get(oth, lt, rt);         lt = lower_bound(vec[oth].begin(), vec[oth].end(), x[i] + 1) -              vec[oth].begin();         rt = upper_bound(vec[oth].begin(), vec[oth].end(), x[i] + r[i]) -              vec[oth].begin() - 1;         ans += get(oth, lt, rt);       }       update(f[i], rev[i], 1);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     for (long long i = 0; i < n; i++) cin >> a[i];     long long mx = 0;     vector<long long> ans(n);     for (long long i = 0; i < n; i++) {       long long cnt = a[i], mn = a[i];       vector<long long> tmp(n);       tmp[i] = a[i];       for (long long j = i + 1; j < n; j++) {         if (a[j] >= mn) {           tmp[j] = mn;           cnt += mn;         } else {           tmp[j] = a[j];           mn = a[j];           cnt += mn;         }       }       mn = a[i];       for (long long j = i - 1; j >= 0; j--) {         if (a[j] >= mn) {           tmp[j] = mn;           cnt += mn;         } else {           tmp[j] = a[j];           mn = a[j];           cnt += mn;         }       }       if (cnt > mx) {         mx = cnt;         for (long long j = 0; j < n; j++) ans[j] = tmp[j];       }     }     for (long long i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t;     t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<pair<int, int> > v;   vector<int> tail;   int getIdx(int l, int r, int key) {     while (l < r) {       int mid = (l + r) / 2;       if (tail[mid] < key)         r = mid;       else         l = mid + 1;     }     return r;   }   int LIS() {     int length = 1;     tail[0] = v[0].second;     for (int i = 1; i < n; i++) {       if (v[i].second > tail[0])         tail[0] = v[i].second;       else if (v[i].second < tail[length - 1])         tail[length++] = v[i].second;       else {         tail[getIdx(0, length - 1, v[i].second)] = v[i].second;       }     }     return length;   }   int main() {     int x, y;     scanf( %d , &n);     v = vector<pair<int, int> >(n);     for (int i = 0; i < n; i++) {       scanf( %d , &x);       x--;       v[x].first = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , &y);       y--;       v[y].second = i;     }     sort(v.begin(), v.end());     tail = vector<int>(n, 0);     cout << LIS();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast();   int main() {     fast();     int n, cookies[105] = {0};     cin >> n;     int sum = 0;     for (int i = 0; i < n; ++i) {       cin >> cookies[i];       sum += cookies[i];     }     int cnt = 0;     for (int i = 0; i < n; ++i) {       int cook = sum;       cook -= cookies[i];       if (cook % 2 == 0) ++cnt;     }     cout << cnt;     return 0;   }   void fast() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }
#include <bits/stdc++.h>   using namespace std;   struct st {     long long n, v;     bool operator<(const st &other) const { return v < other.v; }   };   template <typename T>   string ts(T val) {     std::ostringstream oss;     oss << val;     return oss.str();   }   int main() {     ios_base::sync_with_stdio(0);     long long n, a, b, a1, b1, a2, b2, k1, k2, k3;     cin >> n >> a >> b >> a1 >> b1 >> a2 >> b2;     k1 = a;     k2 = a1;     k3 = a2;     while (k1 + k2 + k3 < n && k1 < b) k1++;     while (k1 + k2 + k3 < n && k2 < b1) k2++;     while (k1 + k2 + k3 < n && k3 < b2) k3++;     cout << k1 <<     << k2 <<     << k3;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int K = 1048576;   int n;   long long t[2][2 * K];   vector<int> g[N];   int T[N];   long long h[N], x[N], dp[N];   long long total;   void build() {     for (int i = 0; i < 2 * K; i++) t[0][i] = t[1][i] = 0;   }   void upd(int id, long long X, int type) {     id += K - 1;     while (id > 0) {       t[type][id] += X;       id /= 2;     }   }   long long get(int L, int R, int type) {     if (R == 0)       return 0;     else if (type == 0 && R == K)       return 2e18;     L += K - 1;     R += K - 1;     long long res = 0;     while (L <= R) {       if (L % 2 == 1) res += t[type][L++];       if (R % 2 == 0) res += t[type][R--];       L /= 2;       R /= 2;     }     return res;   }   void dfs(int v) {     upd(T[v], x[v] * T[v], 0);     upd(T[v], x[v], 1);     int l = 1, r = K;     while (l + 1 < r) {       int mid = (l + r) / 2;       if (h[v] + h[v] + get(1, mid - 1, 0) <= total)         l = mid;       else         r = mid;     }     dp[v] = get(1, l - 1, 1);     long long residue = total - get(1, l - 1, 0) - h[v] - h[v];     dp[v] += min(t[0][l + K - 1], residue) / l;     for (int u : g[v]) {       h[u] += h[v];       dfs(u);     }     if (v == 1) {       for (int u : g[v]) dp[v] = max(dp[v], dp[u]);     } else {       long long max1 = 0, max2 = 0;       for (int u : g[v]) {         if (dp[u] > max1) {           max2 = max1;           max1 = dp[u];         } else if (dp[u] > max2) {           max2 = dp[u];         }       }       dp[v] = max(dp[v], max2);     }     upd(T[v], -x[v] * T[v], 0);     upd(T[v], -x[v], 1);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> total;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = 1; i <= n; i++) cin >> T[i];     for (int i = 2; i <= n; i++) {       int parent;       cin >> parent >> h[i];       g[parent].push_back(i);     }     build();     h[1] = 0;     dfs(1);     cout << dp[1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int z[1000005];   string s;   void z_function() {     int n = (int)s.length();     for (int i = 0; i < n; i++) z[i] = 0;     for (int i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }   }   long long power(long long a, long long b, long long m) {     long long x = 1;     a %= m;     while (b) {       if ((1 & b)) x = x * a % m;       a = a * a % m;       b >>= 1;     }     return x;   }   int y[1000005];   int main() {     int n, m;     scanf( %d , &n);     scanf( %d , &m);     cin >> s;     z_function();     int p = s.length();     for (int i = 1; i <= m; i++) {       scanf( %d , &y[i]);     }     y[m + 1] = n + 1;     int pos = 0;     pos += y[1] - 1;     for (int i = 2; i <= m + 1; i++) {       if (y[i] < y[i - 1] + p) {         if (z[y[i] - y[i - 1]] < p - y[i] + y[i - 1]) {           printf( 0 );           return 0;         }       } else         pos += y[i] - y[i - 1] - p;     }     printf( %lld n , power(26, pos, 1000000007));   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using lll = __int128_t;   const int N = 105;   int n;   vector<int> v[N];   void del(int x, int y) {     v[x].erase(find(v[x].begin(), v[x].end(), y));     v[y].erase(find(v[y].begin(), v[y].end(), x));   }   int f[N], rk[N];   lll dfs(int pos, int fa) {     f[pos] = fa;     vector<lll> vv;     for (auto &i : v[pos])       if (i != fa) vv.push_back(dfs(i, pos));     if (vv.empty()) return 0;     vector<int> ee(vv.size());     auto chk = [&](lll x) {       auto val = vv;       int mxid = -1;       lll mx;       for (int i = N - 1; i >= 0; --i)         if ((x >> i) & 1) {           mx = -(lll(1) << N);           for (int j = 0; j < int(vv.size()); j++)             if (val[j] > mx) mx = val[j], mxid = j;           ee[mxid] = i;           val[mxid] -= lll(1) << i;         }       for (int j = 0; j < int(vv.size()); j++)         if (val[j] >= 0) return 0;       return 1;     };     lll tt = (lll(1) << N) - 1;     for (int i = N - 1; i >= 0; --i)       if (chk(tt - (lll(1) << i))) tt -= lll(1) << i;     assert(chk(tt));     int idx = 0;     for (auto &i : v[pos])       if (i != fa) rk[i] = ee[idx++];     lll ret = 0;     for (int i = 0; i < int(vv.size()); i++)       ret |= vv[i] & (~((lll(1) << ee[i]) - 1)) | lll(1) << ee[i];     return ret;   }   int xx;   inline void upd(int x, int y) {     if (f[x] == y) swap(x, y);     if (!xx || rk[y] > rk[xx]) xx = y;   }   void gete(int pos, int fa) {     for (auto &i : v[pos])       if (i != fa) gete(i, pos), upd(pos, i);   }   int main() {     ios::sync_with_stdio(false);     cin >> n;     int t1, t2;     for (int i = 1; i < n; i++)       cin >> t1 >> t2, v[t1].push_back(t2), v[t2].push_back(t1);     dfs(1, 0);     int x = 1;     while (!v[x].empty()) {       xx = 0;       gete(x, 0);       del(xx, f[xx]);       cout <<  ?   << xx <<     << f[xx] << endl;       cin >> x;     }     cout <<  !   << x << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long x, n;     cin >> x >> n;     int pp = n % 4;     long long z;     if (pp == 0)       z = 0;     else if (pp == 1)       z = -n;     else if (pp == 2)       z = 1;     else       z = n + 1;     long long dre = x % 2 == 0 ? 1 : -1;     x += dre * z;     cout << x << endl;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)(1e5 + 123);   vector<int> gg[MAXN], gb[MAXN];   bool was[MAXN], been[MAXN];   int cnt = 0;   void dfs(int v) {     cnt++;     was[v] = been[v] = true;     for (auto to : gg[v]) {       if (was[to]) continue;       dfs(to);     }   }   int main() {     int n;     cin >> n;     int good;     cin >> good;     for (int i = 1; i <= good; i++) {       int a, b;       cin >> a >> b;       gg[a].push_back(b);       gg[b].push_back(a);     }     int bad;     cin >> bad;     for (int i = 1; i <= bad; i++) {       int a, b;       cin >> a >> b;       gb[a].push_back(b);       gb[b].push_back(a);     }     int ans = 0;     for (int i = 1; i <= n; i++) {       if (was[i]) continue;       cnt = 0;       dfs(i);       bool no = false;       for (int j = 1; j <= n; j++) {         if (been[j]) {           for (auto to : gb[j])             if (been[to]) {               no = true;               break;             }         }         if (no) break;       }       if (!no) ans = max(ans, cnt);       for (int j = 1; j <= n; j++) been[j] = false;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     string s;     cin >> s;     char arr[n + 10];     if (n % 2 == 1) {       int temp = n / 2;       int j = 0;       int k = 1;       for (int i = 0; i < (int)s.size(); i++) {         if (i % 2 == 0) {           arr[temp + j++] = s[i];         } else {           arr[temp - k++] = s[i];         }       }       string ans(arr, arr + n);       cout << ans << endl;     } else {       int temp = n / 2 - 1;       int j = 0;       int k = 1;       for (int i = 0; i < (int)s.size(); i++) {         if (i % 2 == 0) {           arr[temp - j++] = s[i];         } else {           arr[temp + k++] = s[i];         }       }       string ans(arr, arr + n);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   int n, a[N], pre[N], suf[N];   char ans[N];   struct Fenwick {     int n, c[N];     void init(int _n) {       n = _n;       memset(c, 0, sizeof(c[0]) * (n + 1));     }     void upd(int i, int v) {       while (i <= n) {         c[i] = max(c[i], v);         i += i & -i;       }     }     int qry(int i) {       int r = 0;       while (i > 0) {         r = max(r, c[i]);         i -= i & -i;       }       return r;     }   } fw;   void solve(int f[]) {     fw.init(*max_element(a, a + n));     for (int i = (0); i < (n); ++i) {       f[i] = fw.qry(a[i] - 1) + 1;       fw.upd(a[i], f[i]);     }   }   map<pair<int, int>, int> R;   int main() {     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , a + i);     solve(pre);     reverse(a, a + n);     int L = *max_element(a, a + n);     for (int i = (0); i < (n); ++i) a[i] = L - a[i] + 1;     solve(suf);     reverse(suf, suf + n);     L = *max_element(pre, pre + n);     for (int i = (0); i < (n); ++i)       if (pre[i] + suf[i] - 1 == L) {         ++R[make_pair(pre[i], suf[i])];       } else {         ans[i] =  1 ;       }     for (int i = (0); i < (n); ++i)       if (pre[i] + suf[i] - 1 == L)         ans[i] =  2  + (R[make_pair(pre[i], suf[i])] == 1);     ans[n] =   0 ;     puts(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct po {     int x, id, st;   } a[444444];   int n, m, i, j, x, y, t, k, ans[111111], id;   bool cmp(po a, po b) {     if (a.x == b.x) {       return a.st < b.st;     }     return a.x < b.x;   }   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) {       scanf( %d%d , &x, &y);       a[++t].x = k + 1, a[t].id = i, a[t].st = 0;       k += x * y;     }     for (i = 1; i <= m; i++) {       scanf( %d , &x);       a[++t].x = x, a[t].id = i, a[t].st = 1;     }     sort(a + 1, a + t + 1, &cmp);     for (i = 1; i <= t; i++) {       if (!a[i].st) {         id = a[i].id;       } else {         ans[a[i].id] = id;       }     }     for (i = 1; i <= m; i++) {       printf( %d n , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> fac;   void solve() {     long long int n, s, c = 0;     cin >> n;     vector<long long int> a, o;     for (long long int i = 0; i < n; i++) {       cin >> s;       a.push_back(s);     }     for (long long int i = 0; i < n; i++) {       cin >> s;       o.push_back(s);     }     int a1 = *min_element(a.begin(), a.end());     int o1 = *min_element(o.begin(), o.end());     for (long long int i = 0; i < n; i++) {       long long int e = a[i] - a1;       long long int f = o[i] - o1;       c += max(e, f);     }     cout << c << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<vector<int> > adj(n, vector<int>(n, 0));     set<int> s;     int x;     for (int i = 2; i < n + 1; i++) {       cin >> x;       adj[x - 1][i - 1] = 1;       s.insert(x - 1);     }     stack<int> st;     int i = 0;     int j;     int count = 0;     while (i < n) {       if (s.find(i) == s.end()) {         i++;         continue;       }       for (j = 0; j < n; j++) {         if (adj[i][j] == 1 && (s.find(j) == s.end())) {           count++;         }       }       if (count < 3) {         cout <<  No  << endl;         return 0;       }       count = 0;       i++;     }     cout <<  Yes  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long b, d, s, res = 0;     cin >> b;     cin >> d;     cin >> s;     long long val = max(b, max(d, s)) - 1;     if (val > b) res += val - b;     if (val > d) res += val - d;     if (val > s) res += val - s;     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   long long ans = 0;   int n, m, x, y;   int main() {     while (scanf( %d%d%d%d , &n, &x, &m, &y) == 4) {       if (x > y) {         n ^= m ^= n ^= m;         x ^= y ^= x ^= y;       }       ans = n + 1;       int l, r;       for (int i = 1; i <= m; ++i) {         l = y - i;         r = y + i;         if (l <= x - n || l >= x + n)           ++ans;         else {           r = min(r - 1, n + x);           if (l >= x)             ans += ((r - l) << 1);           else             ans += ((r - x - (x - l)) << 1) + 1;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long paw[30];   void pw() {     paw[0] = 1;     for (int i = 1; i < 20; i++) paw[i] = 10 * paw[i - 1];   }   long long rev(long long a) {     long long ret = 0;     vector<int> v;     while (a > 0) {       v.push_back(a % 10);       a /= 10;     }     for (int i = 0; i < v.size(); i++) ret += (v[i] * paw[v.size() - i - 1]);     return ret;   }   int main() {     long long a1, a2;     cin >> a1 >> a2;     pw();     cout << a1 + rev(a2) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int count = 0, k = 0, res = 0;       string s;       cin >> s;       for (int i = 0; i < s.length(); i++) {         count = count + (s[i] -  0 );       }       for (int i = 0; i < s.length(); i++) {         if (s[i] ==  1 ) {           k = 1;           count--;         }         if (s[i] ==  0  && k == 1 && count > 0) {           res++;         }       }       cout << res << endl;     }   }