malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 5e5 + 100;   int f[N];   struct node {     int u, v, w;     bool operator<(const node& a) const { return w < a.w; }   };   struct qq {     int id, u, v, w;     bool operator<(const qq& a) const {       if (a.w == w) return id < a.id;       return w < a.w;     }   };   vector<pair<int, int> > v;   qq q[N];   node pt[N];   bool vis[N];   int Find(int x, bool tmp) {     if (tmp) v.push_back({x, f[x]});     return x == f[x] ? x : f[x] = Find(f[x], tmp);   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       scanf( %d %d %d , &pt[i].u, &pt[i].v, &pt[i].w);     }     int qs;     cin >> qs;     int tot = 0;     for (int i = 1; i <= qs; i++) {       int k;       scanf( %d , &k);       for (int j = 1; j <= k; j++) {         q[tot].id = i;         int now;         scanf( %d , &now);         q[tot].u = pt[now].u;         q[tot].v = pt[now].v;         q[tot].w = pt[now].w;         tot++;       }     }     sort(q, q + tot);     sort(pt + 1, pt + 1 + m);     int cnt = 0;     for (int i = 1; i <= n; i++) f[i] = i;     for (int i = 1; i <= m; i++) {       while (cnt < tot && q[cnt].w == pt[i].w) {         queue<qq> que;         que.push(q[cnt]);         int tmp = q[cnt].id;         for (int j = cnt + 1; j <= tot; j++) {           if (q[j].w == q[j - 1].w && q[j].id == q[j - 1].id)             que.push(q[j]);           else {             cnt = j;             break;           }         }         bool res = true;         while (!que.empty()) {           qq now = que.front();           que.pop();           int f1 = Find(now.u, true);           int f2 = Find(now.v, true);           if (f1 == f2) {             res = false;             break;           }           f[f1] = f2;           v.push_back({f1, f1});         }         if (res == false) vis[tmp] = true;         for (int i = v.size() - 1; i >= 0; i--) {           f[v[i].first] = v[i].second;         }         v.clear();       }       int f1 = Find(pt[i].u, false);       int f2 = Find(pt[i].v, false);       if (f1 == f2) continue;       f[f1] = f2;     }     int cns = 0;     for (int i = 1; i <= n; i++)       if (Find(i, false) == i) cns++;     if (cns >= 2) {       for (int i = 1; i <= qs; i++) {         puts( NO );       }     } else {       for (int i = 1; i <= qs; i++) {         if (vis[i])           puts( NO );         else           puts( YES );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000005], n;   long long ans = 0;   long long now = 0;   long long solve(long long p) {     ans = 0;     now = 0;     for (int i = 1; i <= n; i++) {       now += a[i];       now %= p;       ans += min(now, p - now);     }     return ans;   }   int main() {     cin >> n;     long long sum = 0;     for (int i = 1; i <= n; i++) {       scanf( %d , a + i);       sum = sum + a[i];     }     if (sum == 1) {       cout <<  -1  << endl;     } else {       long long ans0 = (1ll << 62);       for (int p = 2; p <= 1e6; p++) {         if (sum % p == 0) {           ans0 = min(ans0, solve(p));           while (sum % p == 0) sum /= p;         }       }       if (sum != 1) ans0 = min(ans0, solve(sum));       cout << ans0 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     scanf( %d %d , &n, &k);     vector<long long int> v;     vector<long long int>::iterator it;     long long int a[k], i, j, c, t, x;     for (i = 0; i < k; i++) scanf( %lld , &a[i]);     for (i = 1; i <= n; i++) v.push_back(i);     c = 0;     for (i = 0; i < k; i++) {       c = (c + a[i]) % (n);       cout << v[c] <<    ;       v.erase(v.begin() + c);       n--;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[5005], dp[5005][5005][2];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &c[i]);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         if (i == j)           dp[i][j][0] = dp[i][j][1] = 0;         else           dp[i][j][0] = dp[i][j][1] = 0x3f3f3f3f;       }     }     for (int len = 2; len <= n; len++) {       for (int i = 1; i <= n; i++) {         int j = len - 1 + i;         if (j > n) break;         dp[i][j][0] = min(dp[i][j][0], dp[i + 1][j][0] + (c[i] != c[i + 1]));         dp[i][j][0] = min(dp[i][j][0], dp[i + 1][j][1] + (c[j] != c[i]));         dp[i][j][1] = min(dp[i][j][1], dp[i][j - 1][0] + (c[i] != c[j]));         dp[i][j][1] = min(dp[i][j][1], dp[i][j - 1][1] + (c[j - 1] != c[j]));       }     }     cout << min(dp[1][n][0], dp[1][n][1]) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline string toString(T a) {     ostringstream os(  );     os << a;     return os.str();   }   template <typename T>   inline long long toLong(T a) {     long long res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline int toInt(T a) {     int res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline double toDouble(T a) {     double res;     istringstream os(a);     os >> res;     return res;   }   template <typename T>   inline T SQ(T a) {     return a * a;   }   template <typename T>   inline T GCD(T a, T b) {     if (b == 0)       return a;     else       return GCD(b, a % b);   }   template <typename T>   inline T LCM(T a, T b) {     long long res = a * b;     res /= GCD(a, b);     return res;   }   template <typename T>   inline unsigned long long BIGMOD(T a, T b, T m) {     if (b == 0)       return 1;     else if (b % 2 == 0)       return SQ(BIGMOD(a, b / 2, m)) % m;     else       return (a % m * BIGMOD(a, b - 1, m)) % m;   }   template <typename T>   inline vector<string> PARSE(T str) {     vector<string> res;     string s;     istringstream os(str);     while (os >> s) res.push_back(s);     return res;   }   template <typename T>   inline unsigned long long DIST(T A, T B) {     unsigned long long res =         (A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y);     return res;   }   template <typename T>   inline long long CROSS(T A, T B, T C) {     return (B.x - A.x) * (C.y - A.y) - (C.x - A.x) * (B.y - A.y);   }   template <typename T>   inline double cosAngle(T a, T b, T c) {     double res = a * a + b * b - c * c;     res = res / (2 * a * b);     res = acos(res);     return res;   }   template <typename T>   inline T POWER(T base, int po) {     T res = 1;     if (base == 0) return 0;     for (int i = (0); i < (po); i++) res *= base;     return res;   }   template <typename T>   inline bool IS_ON(T mask, T pos) {     return mask & (1 << pos);   }   template <typename T>   inline int OFF(T mask, T pos) {     return mask ^ (1 << pos);   }   template <typename T>   inline int ON(T mask, T pos) {     return mask | (1 << pos);   }   template <typename T>   inline bool INSIDE_GRID(int R, int C, int ro, int clm) {     if (R >= 0 && C >= 0 && R < ro && C < clm) return 1;     return 0;   }   template <typename T>   inline void PRINT_GRID(T GRID, int ro, int clm) {     cout <<  GRID           <<  :   << GRID << endl;     for (int i = (0); i < (ro); i++) {       for (int j = (0); j < (clm); j++) cout << GRID[i][j] <<    ;       puts(  );     }   }   long long arr[500005];   vector<pair<long long, int> > inp;   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     ;     int n;     cin >> n;     for (int i = (0); i < (n); i++) {       cin >> arr[i];       inp.push_back(make_pair(arr[i], i));     }     sort((inp).begin(), (inp).end());     long long hell = 0;     for (int i = (0); i < (n); i++) {       hell = max(inp[i].first, hell + 1);       arr[inp[i].second] = hell;     }     for (int i = (0); i < (n); i++) cout << arr[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     pair<int, int> u, v;     int n, ans = 0;     long long a, b, c, p, q;     scanf( %d%d%d%d , &u.first, &u.second, &v.first, &v.second);     scanf( %d , &n);     while (n--) {       scanf( %lld%lld%lld , &a, &b, &c);       p = a * u.first + b * u.second + c;       q = a * v.first + b * v.second + c;       if ((p > 0 && q < 0) || (p < 0 && q > 0)) ++ans;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, i;     cin >> n;     long long int a[n], p, b[100000], sum = 0, r = 0, c[n];     for (i = 0; i < n; i = i + 1) {       cin >> a[i];       p = a[i];       b[p] = 0;       c[i] = 1;     }     for (i = 0; i < n; i = i + 1) {       p = a[i];       b[p] = b[p] + 1;       if (b[p] > 1) {         c[i] = 0;       } else {         r = r + 1;       }     }     for (i = 0; i < n; i = i + 1) {       p = a[i];       if (c[i] != 0) {         p = a[i];         if (b[p] > 1) {           sum = sum + r;           b[p] = b[p] - 1;         } else if (b[p] > 0) {           r = r - 1;           sum = sum + r;           b[p] = b[p] - 1;         }       } else {         b[p] = b[p] - 1;         if (b[p] == 0) {           r = r - 1;         }       }     }     printf( %lld n , sum);   }
#include <bits/stdc++.h>   using namespace std;   int dp, p[201000], tt[201000], pre[201000], l[201000], vis[201000];   int n, m, i, j, a[1010][1010], g[201000], now[201000], s, t, dis[201000],       z[201000], ans;   void link(int x, int y, int z) {     dp++;     pre[dp] = p[x];     p[x] = dp;     tt[dp] = y;     g[dp] = z;   }   int dfs(int x) {     int i;     i = p[x];     while (i) {       if (vis[tt[i]] == 0) {         vis[tt[i]] = 1;         if ((l[tt[i]] == 0) || (dfs(l[tt[i]]))) {           l[tt[i]] = x;           return 1;         }       }       i = pre[i];     }     return 0;   }   int bfs() {     int i, head, tail;     memcpy(now, p, sizeof(p));     memset(vis, 0, sizeof(vis));     head = 0;     tail = 1;     vis[s] = 1;     dis[s] = 0;     z[tail] = s;     do {       head++;       i = p[z[head]];       while (i) {         if ((vis[tt[i]] == 0) && (g[i] > 0)) {           vis[tt[i]] = 1;           dis[tt[i]] = dis[z[head]] + 1;           tail++;           z[tail] = tt[i];         }         i = pre[i];       }     } while (head != tail);     return vis[t];   }   int dfs(int u, int flow) {     int ans, tmp, i;     if (u == t) return flow;     i = now[u];     ans = 0;     while (i) {       if ((dis[u] + 1 == dis[tt[i]]) && (g[i] > 0)) {         tmp = dfs(tt[i], min(flow - ans, g[i]));         ans += tmp;         g[i] -= tmp;         if (i % 2 == 1)           g[i + 1] += tmp;         else           g[i - 1] += tmp;         if (flow == ans) return flow;       }       i = pre[i];       now[u] = i;     }     if (flow > ans) dis[u] = 1;     return ans;   }   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i][0];       for (j = 1; j <= a[i][0]; j++) {         cin >> a[i][j];         link(n + i, a[i][j], 0);       }     }     for (i = n + 1; i <= 2 * n; i++) {       memset(vis, 0, sizeof(vis));       dfs(i);     }     dp = 0;     memset(p, 0, sizeof(p));     s = 0;     t = n + 1;     for (i = 1; i <= n; i++) {       cin >> m;       if (m > 0) {         link(s, i, m);         link(i, s, 0);       } else {         ans += m;         link(i, t, -m);         link(t, i, 0);       }     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= a[i][0]; j++)         if (l[a[i][j]] - n != i) {           link(l[a[i][j]] - n, i, 0x37373737);           link(i, l[a[i][j]] - n, 0);         }     }     while (bfs()) ans += dfs(s, 0x37373737);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s;   bool ok1 = 1, ok2 = 1;   int a[220], b[220], l[110], r[110];   void qs(int u[], int L, int R) {     int i = L;     int j = R;     int m = u[(L + R) >> 1];     while (i < j) {       while (u[i] < m) i++;       while (u[j] > m) j--;       if (i <= j) {         swap(u[i], u[j]);         i++;         j--;       }     }     if (L < j) qs(u, L, j);     if (i < R) qs(u, i, R);   }   int main() {     cin >> n;     cin >> s;     for (size_t i = 0; (int)i < s.size(); ++i) a[i] = s[i] -  0 ;     for (int i = 0; i < n; i++) {       l[i] = a[i];     }     for (int i = 0; i < n; i++) {       r[i] = a[i + n];     }     qs(r, 0, n - 1);     qs(l, 0, n - 1);     for (size_t i = 0; (int)i < n; ++i) {       if (!(l[i] > r[i])) {         ok1 = 0;       }       if (!(l[i] < r[i])) {         ok2 = 0;       }     }     if (ok1 || ok2) {       printf( YES );       return 0;     }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int arr[1000008];   int l[1000008];   int mx[1000008 << 2], lazy[1000008 << 2];   void pushup(int rt) { mx[rt] = max(mx[rt << 1], mx[rt << 1 | 1]); }   void build(int rt, int l, int r) {     if (l > r) return;     if (l == r) {       mx[l] = arr[l];       return;     }     int mid = (l + r) >> 1;     build(rt << 1, l, mid);     build(rt << 1 | 1, mid + 1, r);     pushup(rt);   }   void pushdown(int rt) {     mx[rt << 1] += lazy[rt];     mx[rt << 1 | 1] += lazy[rt];     lazy[rt << 1] += lazy[rt];     lazy[rt << 1 | 1] += lazy[rt];     lazy[rt] = 0;   }   void update(int rt, int l, int r, int L, int R, int C) {     if (L <= l && r <= R) {       lazy[rt] += C;       mx[rt] += C;       return;     }     pushdown(rt);     int mid = (l + r) >> 1;     if (L <= mid) update(rt << 1, l, mid, L, R, C);     if (mid < R) update(rt << 1 | 1, mid + 1, r, L, R, C);     pushup(rt);   }   int query(int rt, int l, int r, int L, int R) {     if (L <= l && r <= R) return mx[rt];     int mid = (l + r) >> 1;     pushdown(rt);     int ret = -1;     if (L <= mid) ret = max(ret, query(rt << 1, l, mid, L, R));     if (mid < R) ret = max(ret, query(rt << 1 | 1, mid + 1, r, L, R));     return ret;   }   stack<int> sta;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %d , &arr[i]);     for (int i = n; i >= 1; --i) {       while (!sta.empty() && arr[sta.top()] <= arr[i]) {         l[sta.top()] = i + 1;         sta.pop();       }       sta.push(i);     }     while (!sta.empty()) {       l[sta.top()] = 1;       sta.pop();     }     for (int i = 1; i <= n; ++i) {       update(1, 1, n, l[i], i, 1);       if (i >= k) {         printf( %d  , query(1, 1, n, i - k + 1, i));         update(1, 1, n, l[i - k + 1], i - k + 1, -1);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[100005], n, m;   map<int, int> f;   int lowbit(int x) { return x & (-x); }   void add(int x, int j) {     while (x < 100005) {       c[x] += j;       x += lowbit(x);     }   }   int sum(int x) {     int s = 0;     while (x > 0) {       s += c[x];       x -= lowbit(x);     }     return s;   }   struct node {     int id;     int num;   } a[100005];   bool cmp_id(node A, node B) { return A.id < B.id; }   bool cmp_num(node A, node B) { return A.num < B.num; }   int main() {     int i, j, k, m, cnt, ans, tem;     while (scanf( %d , &n) != EOF) {       f.clear();       cnt = 1;       ans = 0;       for (i = 1; i <= n; i++) {         scanf( %d , &a[i].num);         a[i].id = i;       }       sort(a + 1, a + 1 + n, cmp_num);       for (i = 1; i <= n; i++)         if (f[a[i].num] == 0) f[a[i].num] = cnt++;       sort(a + 1, a + 1 + n, cmp_id);       for (i = 1; i <= n; i++) a[i].num = f[a[i].num];       for (i = 1; i <= n; i++) add(a[i].num, 1);       for (i = n; i >= 1; i--) {         tem = sum(a[i].num);         add(a[i].num, -1);         if (tem == i)           ans++;         else {           int ant = a[i].num;           while (i--) {             ant = min(a[i].num, ant);             int tp = sum(ant);             add(a[i].num, -1);             if (sum(ant) == i - 1) break;           }           ans++;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(nullptr);     ios::sync_with_stdio(false);     int n, q;     cin >> n >> q;     deque<int> deq;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       deq.push_back(a);     }     vector<pair<int, int>> ans;     for (int i = 0; i < 2 * n + 7; i++) {       int a = deq.front();       deq.pop_front();       int b = deq.front();       deq.pop_front();       ans.push_back(make_pair(a, b));       if (b > a) {         swap(b, a);       }       deq.push_front(a);       deq.push_back(b);     }     while (q--) {       long long int x;       cin >> x;       x--;       if (x < 2 * n) {         cout << ans[x].first <<     << ans[x].second << endl;       } else {         x -= n;         x %= (n - 1);         x += n;         cout << ans[x].first <<     << ans[x].second << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct BIT {     int N;     vector<int> B;     BIT(int n = 0) {       N = n;       B.resize(n + 2, 0);     }     void add(int x, int v) {       x++;       while (x <= N) {         B[x] += v;         x += x & -x;       }     }     int sum(int x) {       int s = 0;       x++;       while (x > 0) {         s += B[x];         x -= x & -x;       }       return s;     }     int sum(int a, int b) { return sum(b) - sum(a - 1); }   };   int main() {     int h, m, n;     scanf( %d%d%d , &h, &m, &n);     long long sol = 0;     map<int, pair<int, int> > pos;     vector<BIT> X;     vector<bool> visited(h, false);     vector<int> ai(h), bi(h);     for (int i = 0; i < h; ++i) {       if (!visited[i]) {         int cnt = 0;         for (int j = i; !visited[j]; j = (j + m) % h) {           visited[j] = true;           ai[j] = X.size();           bi[j] = cnt;           cnt++;         }         X.push_back(BIT(cnt));       }     }     for (int i = 0; i < n; ++i) {       char op[8];       scanf( %s , op);       int id, hs;       if (op[0] ==  - ) {         scanf( %d , &id);         X[pos[id].first].add(pos[id].second, -1);       } else {         scanf( %d%d , &id, &hs);         int xi = ai[hs], ti = bi[hs];         assert(X[xi].sum(0, X[xi].N - 1) < X[xi].N);         if (X[xi].sum(ti, X[xi].N - 1) == X[xi].N - ti) {           int lo = -1, hi = ti - 1;           sol += X[xi].N - ti;           while (hi - lo > 1) {             int mid = (hi + lo) / 2;             if (X[xi].sum(0, mid) == mid + 1)               lo = mid;             else               hi = mid;           }           sol += hi;           X[xi].add(hi, 1);           pos[id] = make_pair(xi, hi);         } else {           int lo = ti - 1, hi = X[xi].N - 1;           while (hi - lo > 1) {             int mid = (hi + lo) / 2;             if (X[xi].sum(ti, mid) == mid - ti + 1)               lo = mid;             else               hi = mid;           }           sol += hi - ti;           X[xi].add(hi, 1);           pos[id] = make_pair(xi, hi);         }       }     }     printf( %I64d n , sol);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int const N = 70;   int dx[] = {0, 0, 1, -1};   int dy[] = {1, -1, 0, 0};   char s[N][N];   int vis[N][N];   int n, m;   int dfs(int x, int y) {     if (s[x][y] !=  #  || vis[x][y]) return 0;     vis[x][y] = 1;     for (int i = 0; i < (4); i++) dfs(x + dx[i], y + dy[i]);     return 1;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < (n); i++) scanf( %s , s[i]);     int cnt = 0;     for (int i = 0; i < (n); i++)       for (int j = 0; j < (m); j++) {         if (s[i][j] ==  . ) continue;         cnt++;         s[i][j] =  . ;         int k = 0;         memset(vis, 0, sizeof(vis));         for (int d = 0; d < (4); d++) k += dfs(i + dx[d], j + dy[d]);         if (k > 1) {           puts( 1 );           return 0;         }         s[i][j] =  # ;       }     printf( %d n , cnt > 2 ? 2 : -1);   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-10;   const long long mod = 1e6 + 3;   const int INF = 1e9 + 1;   const int N = 105;   long long H[N], c, h, w;   struct Matrix {     long long arr[N][N];     Matrix() { memset(arr, 0, sizeof arr); }     Matrix(int x) {       memset(arr, 0, sizeof arr);       for (int i = 0; i < w + 1; i++) arr[i][i] = x;     }     Matrix operator*(Matrix a) {       Matrix ret;       for (int i = 0; i < w + 1; i++) {         for (int j = 0; j < w + 1; j++) {           for (int k = 0; k < w + 1; k++) {             ret.arr[i][j] += this->arr[i][k] * a.arr[k][j];             ret.arr[i][j] %= mod;           }         }       }       return ret;     }   };   Matrix poww(Matrix a, int p) {     if (!p) return Matrix(1);     Matrix ret = poww(a, p >> 1);     ret = ret * ret;     if (p & 1) ret = ret * a;     return ret;   }   void print(Matrix a) {     for (int i = 0; i < w + 1; i++) {       for (int j = 0; j < w + 1; j++) {         cout << a.arr[i][j] <<    ;       }       cout <<   n ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     H[0] = 1;     cin >> c >> w >> h;     for (int i = 1; i < N; i++) H[i] = (H[i - 1] * h) % mod;     Matrix A = Matrix(), B = Matrix();     for (int i = 0; i < w + 1; i++) {       B.arr[i][0] = H[i];     }     for (int i = 0; i < w; i++) {       B.arr[i][i + 1] = 1;     }     A.arr[0][0] = A.arr[0][1] = 1;     B = poww(B, c + 1);     cout << B.arr[0][0];   }
#include <bits/stdc++.h>   using namespace std;   template <class T1>   void deb(T1 e) {     cout << e << endl;   }   template <class T1, class T2>   void deb(T1 e1, T2 e2) {     cout << e1 <<     << e2 << endl;   }   template <class T1, class T2, class T3>   void deb(T1 e1, T2 e2, T3 e3) {     cout << e1 <<     << e2 <<     << e3 << endl;   }   template <class T1, class T2, class T3, class T4>   void deb(T1 e1, T2 e2, T3 e3, T4 e4) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 << endl;   }   template <class T1, class T2, class T3, class T4, class T5>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 << endl;   }   template <class T1, class T2, class T3, class T4, class T5, class T6>   void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {     cout << e1 <<     << e2 <<     << e3 <<     << e4 <<     << e5 <<     << e6          << endl;   }   long long sqr(long long n) { return n * n; }   double LOG(long long a, long long b) { return (log(a) / log(b)); }   long long GCD(long long a, long long b) {     if (a < 0) return GCD(-a, b);     if (b < 0) return GCD(a, -b);     return (!b) ? a : GCD(b, a % b);   }   long long LCM(long long a, long long b) {     if (a < 0) return LCM(-a, b);     if (b < 0) return LCM(a, -b);     return (a * (b / GCD(a, b)));   }   long long BigMod(long long B, long long P, long long M) {     if (!P) return 1;     if (!(P % 2)) return sqr(BigMod(B, P / 2, M)) % M;     return (B % M) * (BigMod(B, P - 1, M)) % M;   }   int par[205];   int dp[105][105][105];   string s1, s2, vir;   string ans;   int rec(int x, int y, int z) {     if (z == (int)vir.size()) return -(1 << 30);     if (x == (int)s1.size() || y == (int)s2.size()) return 0;     int &ret = dp[x][y][z];     if (ret != -1) return ret;     ret = rec(x + 1, y, z);     ret = max(ret, rec(x, y + 1, z));     if (s1[x] == s2[y]) {       int k = z;       while (k > 0 && s1[x] != vir[k]) k = par[k - 1];       if (s1[x] == vir[k]) k++;       ret = max(ret, rec(x + 1, y + 1, k) + 1);     }     return ret;   }   void prec(int x, int y, int z) {     if (z == (int)vir.size()) return;     if (x == (int)s1.size() || y == (int)s2.size()) return;     int &ret = dp[x][y][z];     if (ret == rec(x + 1, y, z)) return prec(x + 1, y, z);     if (ret == rec(x, y + 1, z)) return prec(x, y + 1, z);     if (s1[x] == s2[y]) {       int k = z;       while (k > 0 && s1[x] != vir[k]) k = par[k - 1];       if (s1[x] == vir[k]) k++;       if (ret == rec(x + 1, y + 1, k) + 1) {         ans += s1[x];         return prec(x + 1, y + 1, k);       }     }     return;   }   int main(void) {     cin >> s1 >> s2 >> vir;     memset(par, 0, sizeof(par));     int k = 0;     string cur = vir;     for (int i = 1; i < (int)cur.size(); i++) {       while (k > 0 && cur[i] != cur[k]) k = par[k - 1];       if (cur[i] == cur[k]) k++;       par[i] = k;     }     memset(dp, -1, sizeof(dp));     int res = rec(0, 0, 0);     if (!res) {       deb(res);       return 0;     }     ans =   ;     prec(0, 0, 0);     deb(ans);     return 0;   }