malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   void print(int n) {     if (n == 4) {       printf( 1 * 2 = 2 n );       printf( 3 * 4 = 12 n );       printf( 2 * 12 = 24 n );     } else if (n == 5) {       printf( 5 * 4 = 20 n );       printf( 3 + 2 = 5 n );       printf( 5 - 1 = 4 n );       printf( 20 + 4 = 24 n );     }   }   int main() {     int n;     while (~scanf( %d , &n)) {       if (n <= 3) {         printf( NO n );         continue;       }       printf( YES n );       if (n == 4)         print(4);       else if (n == 5)         print(5);       else if (n % 2) {         print(5);         for (int i = n; i > 5; i = i - 2) {           printf( %d - %d = 1 n , i, i - 1);           printf( 24 * 1 = 24 n );         }       } else {         print(4);         for (int i = n; i > 4; i = i - 2) {           printf( %d - %d = 1 n , i, i - 1);           printf( 24 * 1 = 24 n );         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 666;   const int inf = 1e9;   struct edge {     int pr;     int to;     int cap;   } e[111111];   int tot = 1, la[N];   void clr() {     tot = 1;     memset(la, 0, sizeof(la));   }   void adde(int x, int y, int z) {     e[++tot].pr = la[x];     la[x] = tot;     e[tot].to = y;     e[tot].cap = z;   }   void addf(int x, int y, int z = inf) {     adde(x, y, z);     adde(y, x, 0);   }   int d[N];   int bfs(int s, int t) {     queue<int> Q;     int i, x, y;     memset(d, 0, sizeof(d));     d[s] = 1;     Q.push(s);     while (!Q.empty()) {       x = Q.front();       Q.pop();       for (i = la[x]; i; i = e[i].pr) {         if (!e[i].cap) continue;         y = e[i].to;         if (!d[y]) {           d[y] = d[x] + 1;           Q.push(y);         }       }     }     return d[t];   }   int dfs(int s, int t, int f) {     if (s == t) return f;     int i, x, y, r = 0;     for (i = la[s]; i; i = e[i].pr) {       if (!e[i].cap || !f) continue;       y = e[i].to;       if (d[y] != d[s] + 1) continue;       x = dfs(y, t, min(f, e[i].cap));       if (x) {         f -= x;         r += x;         e[i].cap -= x;         e[i ^ 1].cap += x;       }     }     if (!r) d[s] = 0;     return r;   }   int maxflow(int s, int t) {     int x, r = 0;     while (bfs(s, t)) {       x = dfs(s, t, inf);       if (x)         r += x;       else         break;     }     return r;   }   int vis[N], w[N];   bool hungary(int x) {     int i, y;     for (i = la[x]; i; i = e[i].pr) {       y = e[i].to;       if (!vis[y]) {         vis[y] = 1;         if (!w[y] || hungary(w[y])) {           w[y] = x;           return true;         }       }     }     return false;   }   int n, a[N][N];   int main() {     int i, j, o, s, t, ans;     scanf( %d , &n);     clr();     for (i = 1; i <= n; i = i + 1) {       scanf( %d , &o);       while (o--) {         scanf( %d , &j);         a[i][j] = 1;         adde(i, j, 0);       }     }     for (i = 1; i <= n; i = i + 1) {       memset(vis, 0, sizeof(vis));       hungary(i);     }     clr();     s = 0, t = n + 1;     for (i = 1; i <= n; i = i + 1)       for (j = 1; j <= n; j = j + 1)         if (a[i][j]) addf(i, w[j]);     ans = 0;     for (i = 1; i <= n; i = i + 1) {       scanf( %d , &o);       if (o > 0)         addf(i, t, o);       else {         ans += o;         addf(s, i, -o);       }     }     printf( %d , ans + maxflow(s, t));     return 0;   }
#include <bits/stdc++.h>   int main() {     int x, h, m, hh, mm;     scanf( %d , &x);     scanf( %d%d , &h, &m);     hh = h, mm = m;     for (int i = 0; i <= 24 * 60; i++) {       int tmp = x * i;       h = hh, m = mm;       while (m < tmp) {         m += 60;         h--;         if (h == -1) h = 23;       }       m -= tmp;       if (m % 10 == 7 || m / 10 == 7 || h % 10 == 7 || h / 10 == 7) {         printf( %d n , i);         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   template <class T>   T my_pow(T n, T p) {     if (p == 0) return 1;     T x = my_pow(n, p / 2);     x = (x * x);     if (p & 1) x = (x * n);     return x;   }   template <class T>   T big_mod(T n, T p, T m) {     if (p == 0) return (T)1;     T x = big_mod(n, p / 2, m);     x = (x * x) % m;     if (p & 1) x = (x * n) % m;     return x;   }   template <class T>   inline T Mod(T n, T m) {     return (n % m + m) % m;   }   template <class T>   T extract(string s, T ret) {     stringstream ss(s);     ss >> ret;     return ret;   }   template <class T>   string itos(T n) {     ostringstream ost;     ost << n;     ost.flush();     return ost.str();   }   long long stoi(string s) {     long long r = 0;     istringstream sin(s);     sin >> r;     return r;   }   double toDouble(string s) {     double r = 0;     istringstream sin(s);     sin >> r;     return r;   }   long long ar[2000005], ar1[200005];   long long a = 0, b = 0, c = 0, r = 0, rr = 0, res = 0, n, m;   string s, ss;   long long fun(long long val) {     r = 0;     for (__typeof(n) i = 0; i < (n); i++) {       if (val < ar[i]) return false;       r += (val - ar[i]);     }     if (r >= val)       return true;     else       return false;   }   int main() {     cin >> n;     for (__typeof(n) i = 0; i < (n); i++) {       cin >> ar[i];     }     long long lo = 0, hi = 10000000000ll;     while (hi - lo > 1) {       long long mid = (lo + hi) >> 1;       if (fun(mid))         hi = mid;       else         lo = mid;     }     cout << hi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x, i, a[100100], b[100100];   priority_queue<pair<long long, int>> q;   long long m, mx, mn, cur, cnt, le, ri, h;   int fnd(int i, long long v) {     int lft = 0, rgh = a[i];     while (lft < rgh) {       int mid = (lft + rgh) / 2 + 1;       cur = a[i] - 3LL * mid * (mid + 1LL) - 1LL;       if (cur < v)         rgh = mid - 1;       else         lft = mid;     }     return rgh;   }   int main() {     scanf( %d%I64d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       q.push({a[i] - 1LL, i});       cur = a[i] - 3LL * a[i] * (a[i] + 1LL) - 1LL;       if (i) {         mn = min(mn, cur);         mx = max(mx, a[i] - 1LL);       } else {         mn = cur;         mx = a[i] - 1LL;       }     }     le = 0;     ri = mx - mn;     while (le < ri) {       h = (le + ri) / 2;       for (cnt = i = 0; i < n; i++) cnt += fnd(i, mx - h);       if (cnt < m)         le = h + 1;       else         ri = h;     }     for (i = 0; i < n; i++) {       b[i] = fnd(i, mx - ri + 1);       m -= b[i];     }     for (i = 0; i < n && m > 0; i++) {       x = min(1LL * fnd(i, mx - ri) - b[i], m);       b[i] += x;       m -= x;     }     for (i = 0; i < n; i++) printf( %d  , b[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n, m, arr[303][303];       scanf( %d %d , &n, &m);       bool can = true;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           scanf( %d , &arr[i][j]);           if (i == 0 || i == n - 1) {             if (j > 0 && j < m - 1) {               if (arr[i][j] > 3) can = false;               arr[i][j] = 3;             } else {               if (arr[i][j] > 2) can = false;               arr[i][j] = 2;             }           } else if (j == 0 || j == m - 1) {             if (i > 0 && i < n - 1) {               if (arr[i][j] > 3) can = false;               arr[i][j] = 3;             } else {               if (arr[i][j] > 2) can = false;               arr[i][j] = 2;             }           } else {             if (arr[i][j] > 4) can = false;             arr[i][j] = 4;           }         }       }       if (!can) {         printf( NO n );         continue;       }       printf( YES n );       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           printf( %d%c , arr[i][j], j >= m - 1 ?   n  :    );         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int>> g, sg;   vector<bool> vis;   void dfs(int u) {     vis[u] = 1;     for (int v : g[u]) {       if (!vis[v]) {         sg[u].push_back(v);         sg[v].push_back(u);         dfs(v);       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     g.resize(n);     sg.resize(n);     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       g[u].push_back(v);       g[v].push_back(u);     }     vis.assign(n, 0);     dfs(0);     auto find_path = [&](int u, int v) {       swap(u, v);       queue<int> qu;       vector<int> p(n, -1);       vis.assign(n, 0);       vis[u] = 1;       qu.push(u);       while (!qu.empty()) {         int x = qu.front();         qu.pop();         for (int y : sg[x]) {           if (!vis[y]) {             vis[y] = 1;             qu.push(y);             p[y] = x;           }         }       }       vector<int> ret;       for (int x = v; x != u; x = p[x]) {         ret.push_back(x);       }       ret.push_back(u);       return ret;     };     int q;     cin >> q;     vector<pair<int, int>> queries(q);     vector<int> deg(n, 0);     vector<vector<int>> ans(q);     for (int i = 0; i < q; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       deg[u]++;       deg[v]++;       queries[i] = {u, v};       ans[i] = find_path(u, v);     }     int cnt_odd = 0;     for (int u = 0; u < n; u++) cnt_odd += deg[u] % 2;     if (cnt_odd) {       cout <<  NO n  << cnt_odd / 2 <<   n ;     } else {       cout <<  YES n ;       for (auto v : ans) {         cout << v.size() <<   n ;         for (int x : v) cout << x + 1 <<    ;         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<set<int> > graph;   vector<int> eliminar;   set<int>::iterator ite;   void elim(int N) {     eliminar.clear();     for (int i = 1; i <= N; i++)       if (graph[i].size() == 1) eliminar.push_back(i);   }   int main() {     int n, m, n1, n2, temp, contador;     cin >> n >> m;     contador = 0;     graph.resize(n + 10);     while (m--) {       cin >> n1 >> n2;       graph[n1].insert(n2);       graph[n2].insert(n1);     }     elim(n);     while (!eliminar.empty()) {       for (int i = 0; i < eliminar.size(); i++) {         graph[eliminar[i]].clear();         for (int j = 1; j <= n; j++)           if (graph[j].find(eliminar[i]) != graph[j].end())             graph[j].erase(eliminar[i]);       }       contador++;       elim(n);     }     cout << contador << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, c, f = 0;   int main() {     cin >> n >> a >> b >> c;     for (int i = 0; i <= c; i++) {       for (int j = 0; j <= b; j++) {         if (n - j - 2 * i >= 0 && n - j - 2 * i <= a / 2) {           f++;         }       }     }     cout << f;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, flag = 0;     cin >> n;     int a[n];     for (i = 0; i < n; i++) {       cin >> a[i];       if (a[i] == 1) flag = 1;     }     if (flag)       cout <<  -1  << endl;     else       cout <<  1  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   int a[MAXN];   int main() {     int n, tot = 0, flag = -1, num = 0;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     sort(a, a + n);     for (int i = 0; i < n - 1; ++i) {       if (i != 0 && a[i] == a[i + 1] && a[i - 1] == a[i] - 1) flag = 1;       if (a[i] == a[i + 1]) num++;       tot += a[i] - i;     }     tot += a[n - 1] - (n - 1);     if (num >= 2) flag = 1;     if (a[0] == 0 && a[1] == 0) flag = 1;     if (flag == -1) {       if (tot % 2 == 0)         flag = 1;       else         flag = 0;     }     if (flag)       printf( cslnb );     else       printf( sjfnb );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename S, typename T>   ostream& operator<<(ostream& out, pair<S, T> const& p) {     out <<  (  << p.first <<  ,   << p.second <<  ) ;     return out;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> const& v) {     int l = v.size();     for (int i = 0; i < l - 1; i++) out << v[i] <<    ;     if (l > 0) out << v[l - 1];     return out;   }   long long n;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     if (n == 0) {       cout <<  0 0  << endl;       return 0;     }     long long lo = 0, hi = 600000000, mid;     while (lo + 1 < hi) {       mid = (lo + hi) / 2;       if (1 + (mid * (mid + 1)) * 3 <= n + 1)         lo = mid;       else         hi = mid;     }     long long x, y;     if (lo == 0) {       x = 2, y = 0;       lo++;     } else {       n -= (lo * (lo + 1) * 3);       lo++;       x = 2 * (lo), y = 0;     }     if (n == 0) {       x -= 2;     }     for (int i = 0; i < 6 and n > 0; i++) {       if (lo <= n) {         if (i == 0) {           x -= lo;           y += 2 * lo;         } else if (i == 1) {           x -= 2 * lo;         } else if (i == 2) {           x -= lo;           y -= 2 * lo;         } else if (i == 3) {           x += lo;           y -= 2 * lo;         } else if (i == 4) {           x += 2 * lo;         } else if (i == 5) {           x += lo;           y += 2 * lo;         }         n -= lo;       } else {         lo = n;         if (i == 0) {           x -= lo;           y += 2 * lo;         } else if (i == 1) {           x -= 2 * lo;         } else if (i == 2) {           x -= lo;           y -= 2 * lo;         } else if (i == 3) {           x += lo;           y -= 2 * lo;         } else if (i == 4) {           x += 2 * lo;         } else if (i == 5) {           x += lo;           y += 2 * lo;         }         break;       }     }     cout << x <<     << y << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, h[100005], p[100005], f[100005];   bool check(long long x) {     int now = 1;     for (int i = 1; i <= n; i++) {       long long rest = x - abs(h[i] - p[now]);       if (rest < 0) continue;       long long nowp = p[now];       while ((p[now] <= h[i] || p[now] - nowp <= rest ||               2 * (p[now] - h[i]) <= rest) &&              now <= m)         now++;       if (now == m + 1) return 1;     }     return now == m + 1;   }   int main() {     scanf( %I64d%I64d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %I64d , &h[i]);     for (int i = 1; i <= m; i++) scanf( %I64d , &p[i]);     long long l = 0, r = 100000000000;     while (l <= r) {       long long mid = l + r >> 1;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     printf( %I64d n , l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[3][3], t[3][3];   vector<char> vs, vt;   int main() {     scanf( %s%s%s%s , s[0], s[1], t[0], t[1]);     if (s[0][0] !=  X ) vs.push_back(s[0][0]);     if (s[0][1] !=  X ) vs.push_back(s[0][1]);     if (s[1][1] !=  X ) vs.push_back(s[1][1]);     if (s[1][0] !=  X ) vs.push_back(s[1][0]);     if (t[0][0] !=  X ) vt.push_back(t[0][0]);     if (t[0][1] !=  X ) vt.push_back(t[0][1]);     if (t[1][1] !=  X ) vt.push_back(t[1][1]);     if (t[1][0] !=  X ) vt.push_back(t[1][0]);     for (int i = 0; i < 3; i++) vs.push_back(vs[i]);     for (int i = 0; i < 3; i++) {       if (vs[i] == vt[0]) {         bool ok = 1;         for (int j = 0; j < 3; j++) {           if (vs[i + j] != vt[j]) {             ok = 0;           }         }         printf( %s n , ok ?  YES  :  NO );         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF32 = 0x3f3f3f3f;   const long long INF64 = 0x3f3f3f3f3f3f3f3f;   const int mod2 = 1e9 + 9;   const int mod = 1e9 + 7;   const int N = 2e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int n, k, m;     long long sum = 0;     cin >> n >> k >> m;     vector<int> cost(k + 1);     for (int i = 1; i <= k; ++i) {       cin >> cost[i];       sum += cost[i];     }     sort(cost.begin(), cost.end());     int ans = 0, temp, t, tm = m;     for (int i = 0; i <= n && sum * i <= tm; ++i) {       temp = (k + 1) * i;       tm -= sum * i;       for (int j = 1; j <= k && tm >= cost[j]; ++j) {         t = min(tm / cost[j], n - i);         temp += t;         if (j == k) temp += t;         tm -= t * cost[j];       }       tm = m;       ans = max(ans, temp);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int n, m, r;   int mat[61][61], opt[61][61][61];   int main() {     scanf( %d%d%d , &n, &m, &r);     for (int i = (0); i < (n); i++)       for (int j = (0); j < (n); j++)         for (int k = (0); k < (n); k++) opt[i][j][k] = 1000000000;     for (int k = (0); k < (m); k++) {       for (int i = (0); i < (n); i++)         for (int j = (0); j < (n); j++) scanf( %d , &mat[i][j]);       for (int k = (0); k < (n); k++)         for (int i = (0); i < (n); i++)           for (int j = (0); j < (n); j++)             mat[i][j] = (((mat[i][j]) < (mat[i][k] + mat[k][j]))                              ? (mat[i][j])                              : (mat[i][k] + mat[k][j]));       for (int i = (0); i < (n); i++)         for (int j = (0); j < (n); j++)           opt[i][j][0] =               (((opt[i][j][0]) < (mat[i][j])) ? (opt[i][j][0]) : (mat[i][j]));     }     for (int p = (1); p < (n); p++)       for (int i = (0); i < (n); i++)         for (int j = (0); j < (n); j++)           for (int k = (0); k < (n); k++)             opt[i][j][p] = (((opt[i][j][p]) < (opt[i][k][p - 1] + opt[k][j][0]))                                 ? (opt[i][j][p])                                 : (opt[i][k][p - 1] + opt[k][j][0]));     while (r--) {       int u, v, k;       scanf( %d%d%d , &u, &v, &k);       printf( %d n , opt[u - 1][v - 1][(((k) < (n - 1)) ? (k) : (n - 1))]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, u, i1, i2, s;   long long f[60][60][2], C[60][60];   inline void M(int j, int k, long long A) {     A %= 1000000007;     f[i][j][k] = (f[i][j][k] + A) % 1000000007;   }   inline long long pow(long long x, long long y) {     long long an = 1;     for (; y; y >>= 1) {       if (y & 1) an = an * x % 1000000007;       x = x * x % 1000000007;     }     return an;   }   int main() {     scanf( %d%d , &n, &m);     for (i = 0; i <= n; i++) {       C[i][0] = 1;       for (j = 1; j <= i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007;     }     f[1][0][0] = 1;     long long P = pow(2, 1000000007 - 2);     for (i = 2; i <= n; i++) {       s = i == n ? 1 : i;       for (j = 0; j <= i - 1; j++) {         M(j + 1, 1, s * f[i - 1][j][0]);         M(j, 0, s * f[i - 1][j][1]);       }       for (j = 1; j + 1 < i; j++)         for (k = 0; k <= j; k++)           for (i1 = 0; i1 <= 1; i1++) {             int A = i - 1 - j;             for (u = 0; u <= A; u++)               for (i2 = 0; i2 <= 1; i2++) {                 long long B = f[j][k][i1] * C[i - 1][j] % 1000000007 *                               f[A][u][i2] % 1000000007 * s % 1000000007 * P %                               1000000007;                 int C = k + u + (!i1 || !i2), D = !(i1 && i2);                 M(C, D, B);               }           }     }     printf( %I64d n , (f[n][m][0] + f[n][m][1]) % 1000000007);     return 0;   }
#include <bits/stdc++.h>   const int MAXINT = 2147483640;   const long long MAXLL = 9223372036854775800LL;   const long long MAXN = 1123456;   const long long MOD = 1123456769;   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     srand(time(0));     vector<int> v;     int n, m, i, h;     char c;     cin >> n;     for (i = 1; i <= n; i++) {       cin >> h >> c >> m;       v.push_back(h * 60 + m);     }     sort(v.begin(), v.end());     v.push_back(24 * 60 + v[0]);     int mx = 0;     for (i = 1; i < v.size(); i++) {       mx = max(mx, v[i] - v[i - 1] - 1);     }     h = mx / 60;     m = mx % 60;     if (h < 10) cout << 0;     cout << h <<  : ;     if (m < 10) cout << 0;     cout << m <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000100;   int N;   long long arr[MAXN];   long long csum;   long long nv[MAXN];   long long dp[MAXN][2];   long long gogo(long long x) {     nv[0] = 0;     for (int i = 0; i < N; i++) {       nv[i + 1] = (nv[i] + arr[i]) % x;     }     for (int i = 0; i <= N; i++) {       dp[i][0] = dp[i][1] = 3e18;     }     dp[0][0] = nv[1];     dp[0][1] = (x - nv[1]);     for (int i = 1; i < N; i++) {       if ((x - nv[i]) + nv[i + 1] <= arr[i])         dp[i][0] = min(dp[i][0], dp[i - 1][1] + nv[i + 1]);       if (nv[i + 1] - nv[i] <= arr[i])         dp[i][0] = min(dp[i][0], dp[i - 1][0] + nv[i + 1]);       if ((x - nv[i]) + (nv[i + 1] - x) <= arr[i])         dp[i][1] = min(dp[i][1], dp[i - 1][1] + (x - nv[i + 1]));       dp[i][1] = min(dp[i][1], dp[i - 1][0] + (x - nv[i + 1]));     }     return min(dp[N - 1][1], dp[N - 1][0]);   }   int main() {     ios_base::sync_with_stdio(0);     csum = 0;     cin >> N;     for (int i = 0; i < N; i++) {       cin >> arr[i];       csum += arr[i];     }     vector<long long> v;     for (long long i = 2; i < MAXN; i++) {       if (csum % i == 0) {         v.push_back(i);         while (csum % i == 0) csum /= i;       }     }     if (csum > 1) v.push_back(csum);     long long ans = 3e18;     for (long long f : v) ans = min(ans, gogo(f));     if (ans > 2e18)       cout <<  -1 n ;     else       cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200033;   int n;   bool col[MAXN];   struct edge {     int t, nx;   } E[MAXN << 1], E_[MAXN << 1];   int first[MAXN], edges_nums = 0;   inline void add(int f, int t) {     E[++edges_nums].t = t;     E[edges_nums].nx = first[f];     first[f] = edges_nums;   }   int first_[MAXN], edges_nums_ = 0;   inline void add_(int f, int t) {     E_[++edges_nums_].t = t;     E_[edges_nums_].nx = first_[f];     first_[f] = edges_nums_;   }   bool check[MAXN];   int nums_of_gp, bel[MAXN];   void uni(int e, int c, int fa) {     int t;     for (int i = first[e]; i; i = E[i].nx) {       t = E[i].t;       if (col[t] == c && !check[t] && t != fa) {         check[t] = 1;         bel[t] = nums_of_gp;         uni(t, c, e);       }     }   }   int fa[MAXN];   int find(int e) { return fa[e] == e ? e : fa[e] = find(fa[e]); }   void union_(int a, int b) {     int e1 = find(a);     int e2 = find(b);     if (e1 != e2) fa[e1] = e2;   }   int MX, S;   void dfs(int sum, int e, int fa) {     if (sum > MX) {       MX = sum;       S = e;     }     int t;     for (int i = first_[e]; i; i = E_[i].nx) {       t = E_[i].t;       if (t != fa) dfs(sum + 1, t, e);     }   }   int main() {     int a, b;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &col[i]);     for (int i = 1; i < n; i++) {       scanf( %d%d , &a, &b);       add(a, b);       add(b, a);     }     for (int i = 1; i <= n; i++) {       fa[i] = i;       if (!check[i]) {         nums_of_gp++;         bel[i] = nums_of_gp;         uni(i, col[i], 0);       }     }     for (int i = 1; i <= n; i++) {       for (int j = first[i]; j; j = E[j].nx) {         int f = bel[i];         int t = bel[E[j].t];         if (find(f) != find(t)) {           union_(f, t);           add_(f, t);           add_(t, f);         }       }     }     dfs(0, 1, 0);     MX = 0;     dfs(0, S, 0);     if (nums_of_gp > 1)       printf( %d , (MX + 1) >> 1);     else       printf( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char str[100030];   int main() {     while (gets(str) != NULL) {       int len = strlen(str), m, n1 = 0, n2 = 0;       for (int i = 0; i < len; i++)         if (str[i] >=  a  && str[i] <=  z )           n2++;         else           n1++;       int m1 = 0, m2 = 0;       m = n1;       for (int i = 1; i <= len; i++) {         int k = 0;         if (str[i - 1] >=  a  && str[i - 1] <=  z )           m2++;         else           m1++;         k += n1 - m1;         k += m2;         if (k < m) m = k;       }       printf( %d n , m);     }     return 0;   }