malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   struct Edge {     int to, cap, flow;   };   struct Graph {     int n;     vector<vector<int> > e;     vector<Edge> edges;     vector<int> d, c;     Graph() {}     Graph(int _n) {       n = _n;       e.resize(n);     }     void addEdge(int from, int to, int cap) {       e[from].push_back(edges.size());       edges.push_back(Edge({to, cap, 0}));       e[to].push_back(edges.size());       edges.push_back(Edge({from, 0, 0}));     }     bool bfs() {       d.assign(n, INF);       c.assign(n, 0);       vector<int> q(n);       int qL = 0, qR = 0;       d[0] = 0;       q[qR++] = 0;       while (qL < qR) {         int v = q[qL++];         for (int i = 0; i < (int)e[v].size(); i++) {           Edge cur = edges[e[v][i]];           if (d[cur.to] > d[v] + 1 && cur.flow < cur.cap) {             d[cur.to] = d[v] + 1;             q[qR++] = cur.to;           }         }       }       return d[n - 1] != INF;     }     int dfs(int v, int flow) {       if (v == n - 1) return flow;       if (flow == 0) return 0;       for (int &i = c[v]; i < (int)e[v].size(); i++) {         Edge cur = edges[e[v][i]];         if (d[cur.to] != d[v] + 1) continue;         int pushed = dfs(cur.to, min(flow, cur.cap - cur.flow));         if (pushed > 0) {           edges[e[v][i]].flow += pushed;           edges[e[v][i] ^ 1].flow -= pushed;           return pushed;         }       }       return 0;     }     long long flow() {       long long flow = 0;       while (bfs()) {         while (int pushed = dfs(0, INF)) {           flow += pushed;         }       }       return flow;     }   };   int main() {     int n, m, h;     while (cin >> n >> h >> m) {       vector<int> l(m), r(m), x(m), c(m);       for (int i = 0; i < m; i++) {         cin >> l[i] >> r[i] >> x[i] >> c[i];         x[i]++;         l[i]--;         r[i]--;       }       Graph gr(1 + n * (h + 1) + m + 1);       int sz = gr.n;       long long sum = 0;       for (int i = 0; i < n; i++) {         for (int j = 1; j <= h; j++) {           gr.addEdge(1 + i * (h + 1) + (j - 1), 1 + i * (h + 1) + j, INF);           gr.addEdge(1 + i * (h + 1) + j, sz - 1, 2 * j - 1);           sum += 2 * j - 1;         }       }       for (int i = 0; i < m; i++) {         if (x[i] > h) continue;         for (int t = l[i]; t <= r[i]; t++) {           gr.addEdge(1 + n * (h + 1) + i, 1 + t * (h + 1) + x[i], INF);         }         gr.addEdge(0, 1 + n * (h + 1) + i, c[i]);       }       cout << sum - gr.flow() << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   char s[4005], t[4005], ax[4005];   int main() {     scanf( %s%s , s, t);     int n = strlen(s), m = strlen(t), ret = m;     for (int i = n - 1; i >= 0; i--) s[i + m] = s[i], s[i] = 0;     n += m;     for (int i = 0; i < n; i++) {       int ct = 0;       for (int j = 0; j < m; j++) {         if (i + j >= n || s[i + j] != t[j]) ct++;       }       ret = min(ret, ct);       ct = 0;       for (int j = 0; j < m; j++) {         if (i - j < 0 || s[i - j] != t[m - 1 - j]) ct++;       }       ret = min(ret, ct);     }     printf( %d n , ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   const int MM = 998244353;   const long double PI = acos(-1);   const long long INF = 2e18;   template <typename T, typename T1>   void amax(T &a, T1 b) {     if (b > a) a = b;   }   template <typename T, typename T1>   void amin(T &a, T1 b) {     if (b < a) a = b;   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b, e / 2);     return power(b * b, e / 2);   }   long long power(long long b, long long e, long long m) {     if (e == 0) return 1;     if (e & 1) return b * power(b * b % m, e / 2, m) % m;     return power(b * b % m, e / 2, m);   }   long long modinv(long long a, long long m) { return power(a, m - 2, m); }   int TLE_TERROR() {     long long n, p, f = 0, zz = -1;     cin >> n >> p;     string s;     cin >> s;     if (p == 1) {       cout <<  NO ;       return 0;     }     if (p == 2) {       if (n > 2)         cout <<  NO ;       else if (n == 1) {         if (s[0] ==  a )           cout <<  b ;         else           cout <<  NO ;       } else {         if (s ==  ab )           cout <<  ba ;         else           cout <<  NO ;       }       return 0;     }     for (long long i = n - 1; i >= 0; i--) {       char z = s[i];       while ((z -  a  + 1) < p) {         z++;         if (i > 0 && z == s[i - 1]) continue;         if (i > 1 && z == s[i - 2]) continue;         long long q = n - i;         s[i] = z;         f = 1;         zz = i;         break;       }       if (f == 1) break;     }     if (f == 0)       cout <<  NO ;     else {       for (long long i = zz + 1; i < n; i++) {         if (i > 1) {           if (s[i - 1] !=  a  && s[i - 2] !=  a )             s[i] =  a ;           else if (s[i - 1] !=  b  && s[i - 2] !=  b )             s[i] =  b ;           else             s[i] =  c ;         } else {           if (s[i - 1] !=  a )             s[i] =  a ;           else if (s[i - 1] !=  b )             s[i] =  b ;           else             s[i] =  c ;         }       }       cout << s;     }     return 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long int TESTS = 1;     while (TESTS--) TLE_TERROR();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long bit[65], f[65][120][2];   inline long long dp(long long s, int tot, int h1, int h2) {     memset(f, 0, sizeof f);     f[0][0][0] = 1;     int ed = log2(s);     for (int i = 1; i <= ed; ++i) {       long long d = (s >> i) & 1;       int ed = i * 2 - 2;       for (int j = 0; j <= ed; ++j)         for (int k = 0; k <= 1; ++k)           for (int p1 = 0; p1 <= 1; ++p1)             for (int p2 = 0; p2 <= 1; ++p2)               if ((i < h1 || p1 == 0) && (i < h2 || p2 == 0) &&                   (p1 + p2 + k) % 2 == d)                 f[i][j + p1 + p2][(k + p1 + p2) / 2] += f[i - 1][j][k];     }     return f[ed][tot][0];   }   int main() {     long long x, s, res, ans = 0;     int ed = 0;     scanf( %lld , &s);     bit[0] = 1;     while (bit[ed] <= s) bit[++ed] = bit[ed - 1] << 1;     for (int i = 1; i <= ed; ++i) {       if (bit[i] - 1 > s) break;       x = s % (bit[i] - 1);       for (int j = i; j >= 1; --j)         if (x >= bit[j] - 1) x -= bit[j] - 1;       if (!x) ++ans;     }     for (int h1 = 1; h1 <= ed - 1; ++h1) {       for (int h2 = 1; bit[h2] - 1 <= s && h2 < ed; ++h2) {         x = (s - bit[h2] + 1) / (bit[h1 + 1] + bit[h2 + 1] - 3);         if (x > 0) {           res = (s - bit[h2] + 1) % (bit[h1 + 1] + bit[h2 + 1] - 3);           if (res == 0) {             ++ans;             continue;           }           if (h1 == 1 && h2 == 1) {             ans += (s == x * 5 + 1);             continue;           }           for (int i = 1; i <= h1 + h2; ++i)             if ((res + i) % 2 == 0) ans += dp(res + i, i, h1, h2);         }       }     }     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct point {     int x, y;     point() : x(0), y(0) {}     point(int x, int y) : x(x), y(y) {}     point operator-(const point& p) const { return point(x - p.x, y - p.y); }     int dot(const point& p) const { return x * p.x + y * p.y; }     int cross(const point& p) const { return x * p.y - y * p.x; }   };   istream& operator>>(istream& is, point& p) { return is >> p.x >> p.y; }   bool pointInSegment(const point& a, const point& b, const point& p) {     return (p - a).cross(b - a) == 0 && (a - p).dot(b - p) <= 0;   }   bool pointInPerimeter(const vector<point>& P, const point& p) {     int n = P.size();     for (int i = 0; i < n; i++) {       if (pointInSegment(P[i], P[(i + 1) % n], p)) {         return true;       }     }     return false;   }   bool crossesRay(const point& a, const point& b, const point& p) {     return ((b.y >= p.y) - (a.y >= p.y)) * (a - p).cross(b - p) >= 0;   }   bool pointInPolygon(const vector<point>& P, const point& p) {     if (pointInPerimeter(P, p)) {       return true;     }     int n = P.size();     int rays = 0;     for (int i = 0; i < n; i++) {       rays += crossesRay(P[i], P[(i + 1) % n], p);     }     return rays & 1;   }   int sgn(int x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   int intersectSegmentsInfo(const point& a, const point& b, const point& c,                             const point& d) {     point v1 = b - a, v2 = d - c;     int t = sgn(v1.cross(c - a)), u = sgn(v1.cross(d - a));     if (t == u) {       if (t == 0) {         if (pointInSegment(a, b, c) || pointInSegment(a, b, d) ||             pointInSegment(c, d, a) || pointInSegment(c, d, b)) {           return -1;         } else {           return 0;         }       } else {         return 0;       }     } else {       return sgn(v2.cross(a - c)) != sgn(v2.cross(b - c));     }   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     vector<point> a(4), b(4);     for (point& p : a) cin >> p;     for (point& p : b) cin >> p;     bool ans = false;     for (const point& p : a) {       ans = ans | pointInPolygon(b, p);     }     for (const point& p : b) {       ans = ans | pointInPolygon(a, p);     }     for (int i = 0; i < 4; ++i) {       for (int j = 0; j < 4; ++j) {         ans = ans | (intersectSegmentsInfo(a[i], a[(i + 1) % 4], b[j],                                            b[(j + 1) % 4]) != 0);       }     }     cout << (ans ?  YES  :  NO ) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     int flag = 0, f = 0;     cin >> s1 >> s2;     int l = s1.length();     for (int i = 0; i < l; i++) {       if (s1[i] <  a ) {         s1[i] += 32;       }       if (s2[i] <  a ) s2[i] += 32;       if (s1[i] != s2[i]) {         f = i;         flag = 1;         break;       }     }     if (flag == 0)       cout <<  0 ;     else {       if (s1[f] > s2[f])         cout <<  1 ;       else         cout <<  -1 ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, f[33];   double ans = 0;   vector<int> v[33];   string s;   template <class T>   ostream& operator<<(ostream& out, vector<T> v) {     out << v.size() <<   n ;     for (auto e : v) out << e <<    ;     return out;   }   double check(int k) {     double ans = 0, local;     for (int i = 0; i < n; i++) {       memset(f, 0, sizeof f);       for (auto j : v[k]) {         f[s[(j + i) % n] -  a ]++;       }       local = 0;       for (int i = 0; i <=  z  -  a ; i++)         if (f[i] == 1) local += (double)1. / v[k].size();       ans = max(ans, local);     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> s;     n = s.size();     for (int i = 0; i < s.size(); i++) v[s[i] -  a ].push_back(i);     for (int i = 0; i <=  z  -  a ; i++) {       ans += ((double)v[i].size() / n) * check(i);     }     cout << fixed << setprecision(13) << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, d, i, e, f, g, n, m, k, l, A[500005], B[500005], fix[500005],       root, ans, C[500005];   vector<long long> v[500005];   void dfs(long long x, long long y) {     for (long long i = 0; i < v[x].size(); i++) {       if (v[x][i] == y) continue;       dfs(v[x][i], x);       if (fix[v[x][i]] == 0) C[x]++;     }     if (C[x] == 0) return;     root = x;     fix[x] = 1;     for (long long i = 0; i < v[x].size(); i++) {       if (v[x][i] == y) continue;       if (fix[v[x][i]] == 1) continue;       fix[v[x][i]] = 1;       swap(A[B[root]], A[B[v[x][i]]]);       ans += 2;       a = B[root];       B[root] = B[v[x][i]];       B[v[x][i]] = a;       root = v[x][i];     }   }   int main() {     cin >> n;     for (long long i = 1; i <= n; i++) {       A[i] = i;       B[i] = i;     }     for (long long i = 1; i < n; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     dfs(1, 0);     if (fix[1] == 0) {       a = v[1][0];       swap(A[1], A[B[v[1][0]]]);       ans += 2;     }     cout << ans << endl;     for (long long i = 1; i <= n; i++) cout << A[i] <<    ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 101;   int n, m;   struct price {     int p;     int au;     bool operator<(const price &rhs) const {       if (au == rhs.au) return p > rhs.p;       return au < rhs.au;     }   } price[MAX_N];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d , &price[i].p);     }     for (int i = 0; i < m; ++i) {       int x;       scanf( %d , &x);       price[x].au = 1;     }     sort(price + 1, price + n + 1);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       if (price[i].au == 0) {         ans += price[i].p;       } else {         if (ans > price[i].p)           ans *= 2;         else           ans += price[i].p;       }     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 2e5 + 6;   int cnt[666], dp[777][777];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int _, n;     cin >> _;     while (_--) {       cin >> n;       for (int i = 0; i <= n - 1; i++) cin >> cnt[i];       for (int i = 0; i <= n; i++)         for (int j = 0; j <= n * 2; j++) dp[i][j] = 1e9;       sort(cnt, cnt + n);       int ans = 1e9;       dp[0][0] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n * 2; j++) {           for (int k = 0; k <= j - 1; k++) {             dp[i][j] = min(dp[i - 1][k] + abs(cnt[i - 1] - j), dp[i][j]);             if (n - i == 0) ans = min(ans, dp[i][j]);           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool calculate_digits(int a) {     int sum = 0;     while (a > 0) {       sum += (a % 10);       a = a / 10;     }     if (sum % 4 == 0) {       return true;     } else {       return false;     }   }   int main() {     int a;     cin >> a;     for (int i = a; i <= a + 10; i++) {       if (calculate_digits(i)) {         cout << i << endl;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, res = 0;     cin >> n >> k;     vector<int> arrAB;     vector<int> arrA;     vector<int> arrB;     for (int i = 0; i < n; i++) {       int time, a, b;       cin >> time >> a >> b;       if (a == 1 && b == 1) {         arrAB.push_back(time);       } else if (a == 1) {         arrA.push_back(time);       } else if (b == 1) {         arrB.push_back(time);       }     }     sort(arrA.begin(), arrA.end());     sort(arrB.begin(), arrB.end());     for (int i = 0; i < arrA.size() && i < arrB.size(); i++) {       arrAB.push_back(arrA[i] + arrB[i]);     }     sort(arrAB.begin(), arrAB.end());     if (arrAB.size() < k)       cout <<  -1  << endl;     else {       for (int i = 0; i < k; i++) res += arrAB[i];       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int max_n = 100000;   int n, k;   char s[max_n + 5];   void solve(void);   int main(void) {     int t;     scanf( %d , &t);     while (t--) solve();     return 0;   }   void solve(void) {     scanf( %d%d , &n, &k);     scanf( %s , s);     int i, j, t, ans = 0;     int lcnt = 0;     for (i = 0; i < n; i++) {       if (s[i] ==  W ) {         if (i > 0 && s[i - 1] ==  W )           ans += 2;         else           ans++;       } else         lcnt++;     }     if (lcnt == n) {       if (!k)         printf( 0 n );       else         printf( %d n , 2 * k - 1);       return;     }     i = 0;     vector<int> gap;     while (i < n) {       if (s[i] ==  L ) {         i++;         continue;       }       j = i;       while (j < n && s[j] ==  W ) j++;       t = j;       while (t < n && s[t] ==  L ) t++;       if (t >= n) break;       gap.push_back(t - j);       i = t;     }     sort(gap.begin(), gap.end());     for (i = 0; k && i < (int)gap.size(); i++) {       if (gap[i] <= k) {         k -= gap[i];         lcnt -= gap[i];         ans += 2 * gap[i] + 1;       } else {         lcnt -= k;         ans += 2 * k;         k = 0;       }     }     if (k) {       ans += min(k, lcnt) * 2;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     cin >> a;     string s;     cin >> s;     int x = 0;     for (int i = 0; i < a - 1; i++) {       if (s[i] > s[i + 1]) {         cout <<  YES  << endl;         cout << i + 1 <<     << i + 2;         return 0;       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, p, q, r;     cin >> n >> p >> q >> r;     long long int a[n], ans = LLONG_MIN;     for (long long int i = 0; i < n; i++) cin >> a[i];     long long int prefixMax[n], suffixMax[n];     prefixMax[0] = p * a[0];     suffixMax[n - 1] = r * a[n - 1];     for (long long int i = 1; i < n; i++)       prefixMax[i] = max(prefixMax[i - 1], p * a[i]);     for (long long int i = n - 2; i >= 0; i--)       suffixMax[i] = max(suffixMax[i + 1], r * a[i]);     for (long long int i = 0; i < n; i++) {       ans = max(ans, prefixMax[i] + suffixMax[i] + (q * a[i]));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void exgcd(int a, int b, int *x, int *y) {     if (b) {       exgcd(b, a % b, y, x);       (*y) = (*y) - (a / b) * (*x);     } else       *x = 1, *y = 0;   }   int main() {     std::ios::sync_with_stdio(false);     double r1, r2, c1, c2, d1, d2;     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     double a, b, c, d;     b = (r1 + c2 - d1) / 2.0;     a = r1 - b;     d = c2 - b;     c = d2 - b;     if ((int)a == a && (int)b == b && (int)c == c && (int)d == d && a + b == r1 &&         c + d == r2 && a + d == d1 && c + b == d2 && a + c == c1 && b + d == c2) {       set<int> temp;       temp.insert(a);       temp.insert(b);       temp.insert(c);       temp.insert(d);       if (temp.size() == 4 && *(temp.begin()) > 0 && *(temp.rbegin()) < 10) {         cout << (int)a <<     << (int)b << endl;         cout << (int)c <<     << (int)d << endl;       } else         cout << -1;     } else       cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int x, y, id;   };   bool operator<(const Node &s, const Node &t) {     if (s.x != t.x)       return s.x < t.x;     else       return s.y < t.y;   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     vector<Node> vn;     vector<int> ans;     set<int> se;     for (int i = 0; i < m; i++) {       Node no;       scanf( %d%d , &(no.x), &(no.y));       no.id = i + 1;       vn.push_back(no);     }     sort(vn.begin(), vn.end());     for (int i = 0; i < n; i++) se.insert(i);     for (int i = 0; i < m; i++) {       set<int>::iterator it = se.lower_bound(n - vn[i].y);       if (it == se.end()) continue;       if (*it < vn[i].x) {         se.erase(it);         ans.push_back(vn[i].id);       }     }     sort(ans.begin(), ans.end());     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   long long power(long long a, long long n, long long mod) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;         p %= mod;       }       n >>= 1;       a *= a;       a %= mod;     }     return p % mod;   }   using namespace std;   int a[100004], b[100004], c[100004];   vector<int> p;   void sieve() {     int i, j;     for (i = 2; i * i <= 100000; i++)       if (!b[i])         for (j = i * i; j <= 100000; j += i) b[j] = 1;     for (i = 2; i <= 100000; i++)       if (!b[i]) p.push_back(i);   }   int main() {     int i, j;     int n;     sieve();     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     int x, y;     for (i = 0; i < n; i++) {       x = a[i];       for (j = 0; p[j] * p[j] <= a[i]; j++) {         if (x % p[j] == 0) c[p[j]]++;         while (x % p[j] == 0) x = x / p[j];       }       if (x > 1) c[x]++;     }     x = 1;     for (i = 0; i < p.size(); i++) x = max(x, c[p[i]]);     printf( %d n , x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = unsigned long long;   ll a[5], b[5], c[5], d[5], fl, k, cnt, vis[10];   set<pair<ll, ll> > st;   map<pair<ll, ll>, ll> mp;   vector<ll> G[10];   set<ll> stt;   void dfs(ll u = 1, ll par = -1) {     vis[u] = 1;     cnt++;     for (ll v : G[u]) {       if (par == v) continue;       if (vis[v]) return;       dfs(v, u);     }   }   int main() {     while (cin >> a[0] >> b[0] >> c[0] >> d[0]) {       st.clear();       stt.clear();       for (int i = 1; i < 4; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];       fl = 1;       for (int i = 0; i < 4; i++) {         if (a[i] != c[i] && b[i] != d[i]) fl = 0;       }       k = 0;       for (int i = 0; i < 10; i++) G[i].clear();       for (int i = 0; i < 10; i++) vis[i] = 0;       for (int i = 0; i < 4; i++) {         if (mp.find({a[i], b[i]}) == mp.end()) {           mp[{a[i], b[i]}] = ++k;         }         if (mp.find({c[i], d[i]}) == mp.end()) {           mp[{c[i], d[i]}] = ++k;         }         st.insert({a[i], b[i]});         st.insert({c[i], d[i]});         G[mp[{a[i], b[i]}]].push_back(mp[{c[i], d[i]}]);         G[mp[{c[i], d[i]}]].push_back(mp[{a[i], b[i]}]);       }       if (st.size() != 4) fl = 0;       for (int i = 0; i < 4; i++) {         stt.insert((a[i] - c[i]) * (a[i] - c[i]) + (b[i] - d[i]) * (b[i] - d[i]));       }       if (stt.size() > 2) fl = 0;       cnt = 0;       dfs();       if (cnt != 4) fl = 0;       puts(fl ?  YES  :  NO );     }   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char const *argv[]) {     int d, n, c, ans, m;     string arr[105];     cin >> n >> d;     ans = 0;     m = 0;     for (int i = 0; i < d; i++) {       cin >> arr[i];       c = 0;       for (int j = 0; j < n; j++) {         if (arr[i][j] ==  1 ) c++;       }       if (c < n)         m++;       else         m = 0;       if (m > ans) ans = m;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[500005], cmd[500005];   int baam[500005], daan[500005], jora[500005];   int n, m, pos;   long long bit[500005];   void update(int l, int r) {     bit[l] += 1;     bit[r + 1] -= 1;   }   void moveLeft() {     if (baam[pos] > 0 && baam[pos] <= n) pos = baam[pos];     return;   }   void moveRight() {     if (daan[pos] > 0 && daan[pos] <= n) pos = daan[pos];     return;   }   void deleteNode() {     int nextPos, L, R;     L = min(pos, jora[pos]);     R = max(pos, jora[pos]);     if (daan[R] <= n)       pos = daan[R];     else       pos = baam[L];     daan[baam[L]] = daan[R];     baam[daan[R]] = baam[L];     update(L, R);     return;   }   int main() {     scanf( %d %d %d , &n, &m, &pos);     getchar();     for (int i = 1; i <= n; i++) scanf( %c , &str[i]);     getchar();     stack<int> st;     for (int i = 1; i <= n; i++) {       if (str[i] ==  ( )         st.push(i);       else {         jora[i] = st.top();         jora[st.top()] = i;         st.pop();       }     }     for (int i = 1; i <= n; i++) {       baam[i] = i - 1;       daan[i] = i + 1;     }     scanf( %s , cmd);     for (int i = 0; cmd[i]; i++) {       if (cmd[i] ==  L )         moveLeft();       else if (cmd[i] ==  R )         moveRight();       else         deleteNode();     }     for (int i = 1; i <= n; i++) bit[i] += bit[i - 1];     for (int i = 1; i <= n; i++) {       if (!bit[i]) printf( %c , str[i]);     }     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 2e5 + 10;   int n;   int d[maxn];   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       d[u]++;       d[v]++;     }     for (int i = 1; i <= n; i++) {       if (d[i] == 2) {         puts( NO );         return 0;       }     }     puts( YES );     return 0;   }