malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long INF = 9e18;   const int inf = 2147483647;   long long phi(long long n) {     long long ans = n;     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) {         ans = ans / i * (i - 1);         while (n % i == 0) n /= i;       }     }     if (n > 1) ans = ans / n * (n - 1);     return ans;   }   long long qpow(long long a, long long b, long long mod) {     long long r = 1;     for (; b; b >>= 1) {       if (b & 1) r = (r * a) % mod;       a = (a * a) % mod;     }     return r;   }   long long C(int n, int m) {     if (m < n - m) m = n - m;     long long ans = 1;     for (int i = m + 1; i <= n; i++) ans *= i;     for (int i = 1; i <= n - m; i++) ans /= i;     return ans;   }   const int N = 2e5 + 5;   int look(int a, int x) {     int q = sqrt(x + 0.5);     int ans = inf;     for (int i = 2; i <= q; i++) {       if (x % i == 0) {         int j = x / i;         if (abs(i - a) < abs(j - a)) {           if (abs(ans - a) > abs(i - a)) {             ans = i;           }         } else {           if (abs(ans - a) > abs(j - a)) {             ans = j;           }         }       }     }     if (ans >= inf) {       if (abs(1 - a) < abs(x - a)) {         ans = 1;       } else {         ans = x;       }     } else {       if (abs(ans - a) > abs(1 - a)) {         ans = 1;       }       if (abs(ans - a) > abs(x - a)) {         ans = x;       }     }     return ans;   }   void work() {     int t;     scanf( %d , &t);     while (t--) {       int a, b, c;       scanf( %d%d%d , &a, &b, &c);       int ta, tc;       int ans = inf;       int as[5];       for (int i = 1; i <= (int)2e4; i++) {         int tb = i;         if (tb > a) {           ta = look(a, tb);         } else {           ta = tb;         }         if (c > tb) {           int t1 = c / tb;           int xc = t1 * tb, dc = (t1 + 1) * tb;           if (abs(c - xc) < abs(c - dc)) {             tc = xc;           } else {             tc = dc;           }         } else {           tc = tb;         }         int cnt1 = abs(a - ta), cnt2 = abs(b - tb), cnt3 = abs(c - tc);         if (cnt1 + cnt2 + cnt3 < ans) {           ans = cnt1 + cnt2 + cnt3;           as[0] = ta, as[1] = tb, as[2] = tc;         }       }       printf( %d n , ans);       for (int i = 0; i < 3; ++i) {         printf( %d  , as[i]);       }       puts(  );     }   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 5;   vector<int> adj[MAXN];   vector<pair<int, int>> q[MAXN];   int n, m;   long long ans[MAXN], depval[MAXN];   void dfs(int u, int dep, int pre, long long cur) {     for (auto pr : q[u]) {       depval[dep] += pr.second;       if (dep + pr.first + 1 < MAXN) depval[dep + pr.first + 1] -= pr.second;     }     long long curr = cur + depval[dep];     ans[u] = curr;     for (auto v : adj[u])       if (v != pre) dfs(v, dep + 1, u, curr);     for (auto pr : q[u]) {       depval[dep] -= pr.second;       if (dep + pr.first + 1 < MAXN) depval[dep + pr.first + 1] += pr.second;     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int u, v;       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int v, d, x;       scanf( %d%d%d , &v, &d, &x);       q[v].emplace_back(d, x);     }     dfs(1, 0, 1, 0);     for (int i = 1; i <= n; i++) printf( %lld  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300 + 5;   const int MBIT = 15 + 5;   const int INF = 0x3f3f3f3f;   int n, m, MT, dp[MBIT][MAXN][MAXN];   int ans[2][MAXN][MAXN];   inline void umax(int& a, const int& b) { a = max(a, b); }   void init() {     MT = (int)floor(log2((long double)n));     for (int s = 0; s <= MT; s++) {       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dp[s][i][j] = -INF;         }         dp[s][i][i] = 0;       }     }   }   void clr(int z) {     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         ans[z][i][j] = -INF;       }       ans[z][i][i] = 0;     }   }   bool check(int step) {     int z = 0;     clr(z);     for (int s = 0; s <= MT; s++) {       if (((step >> s) & 1) == 0) continue;       z ^= 1;       clr(z);       for (int k = 1; k <= n; k++) {         for (int i = 1; i <= n; i++) {           for (int j = 1; j <= n; j++) {             umax(ans[z][i][j], ans[z ^ 1][i][k] + dp[s][k][j]);           }         }       }     }     for (int i = 1; i <= n; i++) {       if (ans[z][i][i] > 0) return true;     }     return false;   }   int main() {     int u, v, a, b;     while (~scanf( %d %d , &n, &m)) {       init();       for (int i = 1; i <= m; i++) {         scanf( %d %d %d %d , &u, &v, &a, &b);         dp[0][u][v] = a, dp[0][v][u] = b;       }       for (int s = 1; s <= MT; s++) {         for (int k = 1; k <= n; k++) {           for (int i = 1; i <= n; i++) {             if (dp[s - 1][i][k] == -INF) continue;             for (int j = 1; j <= n; j++) {               umax(dp[s][i][j], dp[s - 1][i][k] + dp[s - 1][k][j]);             }           }         }       }       int lb = 2, ub = n + 1, mid;       while (lb <= ub) {         mid = (lb + ub) >> 1;         if (check(mid))           ub = mid - 1;         else           lb = mid + 1;       }       if (lb >= n + 1) lb = 0;       printf( %d n , lb);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool matrix[2005][2005];   int main() {     ios::sync_with_stdio(false);     int n, m, k;     cin >> n >> m >> k;     string s;     getline(cin, s);     for (int y = 0; y < n; y++) {       getline(cin, s);       for (int x = 0; x < m; x++) matrix[x][y] = s[x] ==  . ;     }     int result = 0;     for (int x = 0; x < m; x++) {       int cnt = 0;       for (int y = 0; y < n; y++) {         if (matrix[x][y])           cnt++;         else {           result += max(0, cnt - k + 1);           cnt = 0;         }       }       result += max(0, cnt - k + 1);     }     if (k != 1) {       for (int y = 0; y < n; y++) {         int cnt = 0;         for (int x = 0; x < m; x++) {           if (matrix[x][y])             cnt++;           else {             result += max(0, cnt - k + 1);             cnt = 0;           }         }         result += max(0, cnt - k + 1);       }     }     cout << result << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18;   const long long Mod = 1e9 + 7;   const long double Pi = acos(-1);   long long n, m, k;   struct Weapon {     long long Pow, Val;   } a[200009], b[200009];   struct Monster {     long long Att, Def, Val;   } c[200009];   bool Cmp1(Weapon x, Weapon y) { return x.Pow < y.Pow; }   bool Cmp2(Monster x, Monster y) { return x.Att < y.Att; }   long long SufMin[200009];   long long Tree[800009], Lzy[800009];   void Merge(long long Node) {     Tree[Node] = max(Tree[Node * 2], Tree[Node * 2 + 1]);   }   void Build(long long Node, long long l, long long r) {     if (l == r) {       Tree[Node] = -a[l].Val;       return;     }     Build(Node * 2, l, (l + r) / 2);     Build(Node * 2 + 1, (l + r) / 2 + 1, r);     Merge(Node);   }   void LzyUpd(long long Node, long long l, long long r) {     Tree[Node] += Lzy[Node];     if (l != r) {       Lzy[Node * 2] += Lzy[Node];       Lzy[Node * 2 + 1] += Lzy[Node];     }     Lzy[Node] = 0;   }   void Upd(long long Node, long long l, long long r, long long s, long long e,            long long x) {     if (l > r || s > e) return;     LzyUpd(Node, l, r);     if (s > r || e < l) return;     if (s <= l && e >= r) {       Lzy[Node] += x;       LzyUpd(Node, l, r);       return;     }     Upd(Node * 2, l, (l + r) / 2, s, e, x);     Upd(Node * 2 + 1, (l + r) / 2 + 1, r, s, e, x);     Merge(Node);   }   long long Query(long long Node, long long l, long long r) {     LzyUpd(Node, l, r);     return Tree[Node];   }   long long Bin1(long long X) {     long long l = -1, r = n;     while (r - l > 1) {       if (a[(l + r) / 2].Pow > X)         r = (l + r) / 2;       else         l = (l + r) / 2;     }     return r;   }   long long Bin2(long long X) {     long long l = -1, r = m;     while (r - l > 1) {       if (b[(l + r) / 2].Pow > X)         r = (l + r) / 2;       else         l = (l + r) / 2;     }     return (r == m ? inf : SufMin[r]);   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i < n; i++) {       cin >> a[i].Pow >> a[i].Val;     }     for (int i = 0; i < m; i++) {       cin >> b[i].Pow >> b[i].Val;     }     for (int i = 0; i < k; i++) {       cin >> c[i].Def >> c[i].Att >> c[i].Val;     }     sort(a, a + n, Cmp1);     sort(b, b + m, Cmp1);     sort(c, c + k, Cmp2);     for (int i = m - 1; i >= 0; i--) {       SufMin[i] = b[i].Val;       SufMin[i] = min(SufMin[i], (long long)(i == m - 1 ? inf : SufMin[i + 1]));     }     Build(1, 0, n - 1);     long long Ans = -Bin2(0) + Query(1, 0, n - 1);     for (int i = 0; i < k; i++) {       long long Id = Bin1(c[i].Def);       Upd(1, 0, n - 1, Id, n - 1, c[i].Val);       long long Best1 = Bin2(c[i].Att);       long long Best2 = Query(1, 0, n - 1);       Ans = max(Ans, -Best1 + Best2);     }     cout << Ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, q = 524288, p, ans = 1, lz;   int s[1048576], r[1048576];   int getsum(int t) {     if (t >= q) {       if (r[t] > lz - q) {         return 0;       } else {         return s[t];       }     }     if (r[t] <= lz - q) {       return s[t];     } else if (r[t * 2] <= lz - q) {       return s[t * 2] + getsum(t * 2 + 1);     } else {       return getsum(t * 2);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     cin >> n;     cout << 1 << endl;     lz = n - 1 + q;     for (int i = q; i < 2 * q; i++) {       r[i] = i - q;     }     for (int i = q - 1; i > 0; i--) {       r[i] = r[i * 2 + 1];     }     for (int i = 0; i < n; i++) {       cin >> p;       p--;       p += q;       while (p > 0) {         s[p] += 1;         p /= 2;       }       while (s[lz]) lz--;       cout << getsum(1) + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> mp;   int n, m;   int a[110], b[110];   int main() {     while (~scanf( %d%d , &n, &m)) {       mp.clear();       for (int i = 0; i < (n); ++i) scanf( %d , a + i);       for (int i = 0; i < (m); ++i) {         string s;         cin >> s;         mp[s]++;       }       int tot = 0;       for (map<string, int>::iterator it = mp.begin(); it != mp.end(); ++it)         b[tot++] = it->second;       sort(a, a + n);       sort(b, b + tot);       int mint = 0, maxt = 0;       for (int i = 0; i < (tot); ++i)         mint += a[i] * b[tot - 1 - i], maxt += a[n - tot + i] * b[i];       printf( %d %d n , mint, maxt);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 250000 + 5;   long long dp[maxn];   int main() {     long long n, m;     scanf( %lld %lld , &n, &m);     dp[0] = dp[1] = 1;     for (long long i = 2; i <= n; i++) {       dp[i] = ((dp[i - 1] % m) * (i % m)) % m;     }     long long sum = 0;     for (long long i = 1; i <= n; i++) {       sum += (((dp[i] % m) * (dp[n - i + 1] % m) % m) * ((n - i + 1) % m)) % m;     }     printf( %lld n , sum % m);   }
#include <bits/stdc++.h>   using namespace std;   long n;   vector<long> prec;   int main() {     ios_base::sync_with_stdio(0);     prec.push_back(2);     prec.push_back(7);     prec.push_back(2);     prec.push_back(3);     prec.push_back(3);     prec.push_back(4);     prec.push_back(2);     prec.push_back(5);     prec.push_back(1);     prec.push_back(2);     cin >> n;     cout << prec[n / 10] * prec[n % 10] << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     string s;     cin >> s;     int a[s.length()];     int n = s.length();     int ans = 0;     for (int i = 0; i < n; i++) {       int x = s[i] -  0 ;       a[i] = x % 3;       if (a[i] == 0) {         ans++;       }     }     for (int i = 0; i < n; i++) {       if (a[i] == 1) {         if (i < n - 1) {           if (a[i + 1] == 2) {             ans++;             a[i] = 0;             a[i + 1] = 0;             continue;           }         }         if (i < n - 2) {           if (a[i + 1] == 1 and a[i + 2] == 1) {             ans++;             a[i] = 0;             a[i + 1] = 0;             a[i + 2] = 0;             continue;           }         }       }       if (a[i] == 2) {         if (i < n - 1) {           if (a[i + 1] == 1) {             ans++;             a[i] = 0;             a[i + 1] = 0;             continue;           }         }         if (i < n - 2) {           if (a[i + 1] == 2 and a[i + 2] == 2) {             ans++;             a[i] = a[i + 1] = a[i + 2] = 0;             continue;           }         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[1005];   vector<long long int> csum;   string str;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     int m;     cin >> n >> m;     long long int x;     cin >> x;     csum.push_back(x);     for (int i = 1; i < n; i++) {       cin >> x;       long long int y = x + csum[i - 1];       csum.push_back(y);     }     for (int i = 0; i < m; i++) {       long long int y;       cin >> y;       int lo = lower_bound(csum.begin(), csum.end(), y) - csum.begin();       if (lo + 1 == 1) {         cout << lo + 1 <<     << y << endl;         continue;       }       cout << lo + 1 <<     << y - csum[lo - 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, n;     cin >> a >> b >> c >> n;     int d = n - (a + b - c);     if ((a - c) >= 0 && (b - c) >= 0 && c >= 0 && d > 0) {       cout << d << endl;     } else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   const int inf = 0x3f3f3f3f;   int b[maxn];   int a[maxn];   int ma[maxn];   int pre[maxn * 10];   int _find(int x) { return x == pre[x] ? x : pre[x] = _find(pre[x]); }   void _union(int x, int y) {     x = _find(x), y = _find(y);     if (x < y)       pre[x] = y;     else       pre[y] = x;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < maxn * 10; ++i) pre[i] = i;     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);       ma[i] = max(ma[i - 1], a[i]);     }     bool flag = true;     int x = 0;     for (int i = n; i > 0; --i) {       if (a[i] > ma[i - 1])         b[i] = ma[i - 1];       else         b[i] = a[i] + 1;       b[i] = _find(b[i]);       _union(b[i], b[i] + 1);       _union(a[i], a[i] + 1);       x = max(x, a[i]);     }     if (!flag)       puts( -1 );     else {       for (int i = 1; i <= n; ++i) printf( %d%c , b[i], i == n ?   n  :    );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1e9 + 7, N = 1e6 + 5;   char a[51][51];   int n, m;   int vis[51][51];   void dfs(int i, int j) {     vis[i][j] = 1;     if (i - 1 >= 0 and a[i - 1][j] ==  #  and vis[i - 1][j] == 0) dfs(i - 1, j);     if (i + 1 < n and a[i + 1][j] ==  #  and vis[i + 1][j] == 0) dfs(i + 1, j);     if (j - 1 >= 0 and a[i][j - 1] ==  #  and vis[i][j - 1] == 0) dfs(i, j - 1);     if (j + 1 < m and a[i][j + 1] ==  #  and vis[i][j + 1] == 0) dfs(i, j + 1);   }   int func() {     for (int i = 0; i < 51; i++)       for (int j = 0; j < 51; j++) vis[i][j] = 0;     int check = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  # ) check = 1, dfs(i, j);         if (check) break;       }       if (check) break;     }     check = 1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  #  and vis[i][j] == 0) {           check = 0;           break;         }       }     }     return check;   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     cin >> n >> m;     int cnt = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  # ) cnt++;       }     }     if (cnt <= 2) cout << -1, exit(0);     int ans = 2;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  # ) {           a[i][j] =  . ;           if (func() == 0) {             ans = 1;             break;           }           a[i][j] =  # ;         }       }       if (ans == 1) break;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   struct Tree {     long long maxv[80005];     void pushup(int x) { maxv[x] = max(maxv[x << 1], maxv[x << 1 | 1]); }     void update(int x, int l, int r, int p, long long v) {       if (l == r) {         maxv[x] = v;         return;       }       if (p <= ((l + r) >> 1))         update(x << 1, l, ((l + r) >> 1), p, v);       else         update(x << 1 | 1, ((l + r) >> 1) + 1, r, p, v);       pushup(x);     }     long long ask(int x, int l, int r, int from, int to) {       if (from > to) return -1e12;       if (l >= from && r <= to) return maxv[x];       long long ans = -1e12;       if (from <= ((l + r) >> 1))         ans = max(ans, ask(x << 1, l, ((l + r) >> 1), from, to));       if (to > ((l + r) >> 1))         ans = max(ans, ask(x << 1 | 1, ((l + r) >> 1) + 1, r, from, to));       return ans;     }   };   Tree t1, t2, t3;   int n, m, l;   long long a[55][20005], s[55][20005], f[20005];   int main() {     scanf( %d%d%d , &n, &m, &l);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) scanf( %lld , &a[i][j]);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) s[i][j] = s[i][j - 1] + a[i][j];     for (int i = 1; i <= 80000; i++) t1.maxv[i] = t2.maxv[i] = t3.maxv[i] = -1e12;     for (int i = 1; i <= n; i++) {       for (int j = 1; j + l - 1 <= m; j++) {         f[j] = max(t1.ask(1, 1, m, 1, j - l), t1.ask(1, 1, m, j + l, m));         f[j] = max(f[j], t2.ask(1, 1, m, j - l + 1, j) + s[i][j - 1]);         f[j] = max(f[j], t3.ask(1, 1, m, j + 1, j + l) - s[i][j + l - 1]);         f[j] = max(f[j], 0ll);       }       for (int j = 1; j + l - 1 <= m; j++) {         f[j] = f[j] + s[i][j + l - 1] - s[i][j - 1] + s[i + 1][j + l - 1] -                s[i + 1][j - 1];         t1.update(1, 1, m, j, f[j]);         t2.update(1, 1, m, j, f[j] - s[i + 1][j + l - 1]);         t3.update(1, 1, m, j, f[j] + s[i + 1][j - 1]);       }     }     printf( %lld n , t1.ask(1, 1, n, 1, n));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, oo = 0x3f3f3f3f;   const long long M = 1e12 + 105;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, -1, 0, 1};   int main() {     int c, r, ans = 0;     scanf( %d %d , &r, &c);     char second[r][c];     for (int i = 0; i < r; i++) scanf( %s , second[i]);     for (int i = 0; i < r; i++) {       int cc = 0;       for (int j = 0; j < c; j++)         if (second[i][j] ==  S )           break;         else if (second[i][j] ==  . )           cc++;       if (cc == c) {         ans += cc;         for (int j = 0; j < c; j++) second[i][j] =  X ;       }     }     for (int i = 0; i < c; i++) {       bool ff = false;       int cc = 0;       for (int j = 0; j < r; j++)         if (second[j][i] ==  S ) {           ff = true;           break;         } else if (second[j][i] ==  . )           cc++, second[j][i] =  X ;       if (!ff) ans += cc;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 300005;   int sum;   int main() {     int n, k;     scanf( %d%d , &n, &k);     for (int i = 0, x; i < n; ++i) scanf( %d , &x), sum += x;     for (int i = 0;; ++i) {       if (2 * sum >= (2 * k - 1) * (n + i)) {         printf( %d n , i);         break;       }       sum += k;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int64_t pre[200001];   int64_t dp[200001];   int n;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> pre[i];       pre[i] += pre[i - 1];     }     int64_t mx = -1e15;     for (int i = n - 1; i >= 1; --i) {       dp[i] = max(pre[n], mx);       mx = max(mx, pre[i] - dp[i]);     }     cout << dp[1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s[3];   int l[3];   int a[101][101][101];   int d[101][101][101];   int e[101][26];   int go(int x, int y, int z) {     if (a[x][y][z] != -1) return a[x][y][z];     if (z == l[2]) return -1e9;     if (x == l[0] || y == l[1]) return 0;     int &r = a[x][y][z];     r = 0;     if (go(x + 1, y, z) > r) {       r = go(x + 1, y, z);       d[x][y][z] = 1;     }     if (go(x, y + 1, z) > r) {       r = go(x, y + 1, z);       d[x][y][z] = 2;     }     if (s[0][x] == s[1][y]) {       int c = e[z][s[0][x] -  A ];       if (go(x + 1, y + 1, c) + 1 > r) {         r = go(x + 1, y + 1, c) + 1;         d[x][y][z] = 200 + c;       }     }     return r;   }   void go1(int x, int y, int z) {     if (x == l[0] || y == l[1] || z == l[2] || a[x][y][z] == -1) return;     if (d[x][y][z] == 1)       go1(x + 1, y, z);     else if (d[x][y][z] == 2)       go1(x, y + 1, z);     else if (d[x][y][z] >= 200) {       printf( %c , s[0][x]);       go1(x + 1, y + 1, d[x][y][z] - 200);     }   }   int main() {     for (int i = 0; i < 3; i++) {       getline(cin, s[i]);       l[i] = s[i].length();     }     for (int i = 0; i < l[2]; i++) {       for (int j = 0; j < 26; j++) {         string b = s[2].substr(0, i) + string(1,  A  + j);         int c = 0;         for (int k = 1; k <= b.length(); k++) {           if (b.substr(b.length() - k, k) == s[2].substr(0, k)) c = k;         }         e[i][j] = c;       }     }     memset(a, -1, sizeof(a));     go(0, 0, 0);     if (a[0][0][0] == 0) {       printf( 0 n );       return 0;     }     go1(0, 0, 0);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int m = 1000000007;   int size = 1000004;   bool mo(long long int n) {     int t = 0;     while (n) {       if (n % 10 == 3) t++;       n = n / 10;     }     if (t >= 3)       return true;     else       return false;   }   int main() {     long long int n;     cin >> n;     if (n == 1) {       cout << -1 << endl;       return 0;     }     cout << n <<     << n + 1 <<     << n * (n + 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 16;   int n, xa, xb, a[20], b[20], ca[N], cb[N], f[N][140], ans = 0x7fffffff;   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     char c;     for (int i = 1; i <= n; i++) {       cin >> c >> a[i] >> b[i];       xa += a[i], xb += b[i];       for (int j = 0; j < (1 << n); j++)         if (j & (1 << i - 1)) {           if (c ==  R )             ca[j]++;           else             cb[j]++;         }     }     memset(f, -1, sizeof(f));     f[0][0] = 0;     for (int i = 0; i < (1 << n); i++)       for (int j = 0; j <= 130; j++)         if (f[i][j] != -1)           for (int k = 1; k <= n; k++)             if (!(i & (1 << k - 1))) {               int ti = i | (1 << (k - 1)), sa = min(a[k], ca[i]),                   sb = min(b[k], cb[i]);               f[ti][j + sa] = max(f[ti][j + sa], f[i][j] + sb);             }     for (int i = 0; i <= 130; i++)       if (f[(1 << n) - 1][i] != -1)         ans = min(ans, max(xa - i, xb - f[(1 << n) - 1][i]));     cout << ans + n;     return 0;   }