malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void ckmax(T& x, T y) {     x = (y > x ? y : x);   }   template <typename T>   inline void ckmin(T& x, T y) {     x = (y < x ? y : x);   }   const int MAXN = 80;   const int INF = 0x3f3f3f3f;   int n, a[MAXN + 5], cnt[2], pos[MAXN + 5], cnt_pos,       ans[MAXN * (MAXN - 1) / 2 + 5];   int total, max_op;   int dp[MAXN + 5][MAXN * (MAXN - 1) / 2 + 5][MAXN + 5];   int calc(int len) { return len * (len - 1) / 2; }   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       cnt[a[i]]++;       if (a[i] == 1) {         pos[++cnt_pos] = i;       }     }     total = calc(cnt[0]);     max_op = calc(n);     if (!cnt[1]) {       for (int i = 0; i <= max_op; ++i) {         cout << 0 <<    ;       }       cout << endl;       return 0;     }     memset(dp, 0x3f, sizeof(dp));     for (int i = 1; i < n; ++i) {       dp[i][abs(pos[1] - i)][1] = calc(i - 1);       for (int j = 0; j <= max_op; ++j) {         for (int k = 1; k <= i && k < cnt[1]; ++k)           if (dp[i][j][k] != INF) {             int rest = cnt[1] - k;             for (int l = i + 1; l <= n - rest + 1; ++l) {               int newj = j + abs(pos[k + 1] - l);               if (newj <= max_op)                 ckmin(dp[l][newj][k + 1], dp[i][j][k] + calc(l - i - 1));             }           }       }     }     for (int i = 0; i <= max_op; ++i) ans[i] = total;     for (int i = cnt[1]; i <= n; ++i) {       for (int j = 0; j <= max_op; ++j) {         ckmin(ans[j], dp[i][j][cnt[1]] + calc(n - i));       }     }     for (int i = 0; i <= max_op; ++i) {       if (i) ckmin(ans[i], ans[i - 1]);       cout << total - ans[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   template <class T>   inline void read(T &x) {     T f = 1;     x = 0;     char s = getchar();     while (s <  0  || s >  9 ) {       if (s ==  - ) f = -1;       s = getchar();     }     while (s >=  0  && s <=  9 ) {       x = x * 10 + s -  0 ;       s = getchar();     }     x *= f;   }   const int p = 1e9 + 7;   struct Edge {     int u, v;   } e[201];   int head[101], ecnt;   inline void addedge(int u, int v) {     e[++ecnt].v = v;     e[ecnt].u = head[u];     head[u] = ecnt;   }   inline void add(int u, int v) {     addedge(u, v);     addedge(v, u);   }   int f[101][41], a, b, ans, n, k, g[101];   inline void dfs(int x, int fa) {     f[x][0] = 1;     f[x][k + 1] = 1;     for (int yny = head[x], v; yny && (v = e[yny].v); yny = e[yny].u) {       if (v == fa) continue;       dfs(v, x);       memset(g, 0, sizeof(g));       for (int i = 0; i <= 2 * k; i++)         for (int j = 0; j <= 2 * k; j++) {           if ((i + j) > (2 * k))             (g[std::max(i, j + 1)] += 1ll * f[x][i] * f[v][j] % p) %= p;           else             (g[std::min(i, j + 1)] += 1ll * f[x][i] * f[v][j] % p) %= p;         }       for (int i = 0; i <= 2 * k; i++) f[x][i] = g[i];     }   }   inline void solve() {     read(n);     read(k);     for (int i = 1; i <= n - 1; i++) read(a), read(b), add(a, b);     dfs(1, 0);     for (int i = 0; i <= k; i++) (ans += f[1][i]) %= p;     printf( %d n , ans);   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const long long N = 10000000;   long long n, a, b;   long long dp[N + 1];   signed main() {     cin >> n >> a >> b;     dp[0] = 0;     for (long long i = 1; i <= n; i++)       if (i & 1)         dp[i] = min(dp[i - 1] + a, dp[i + 1 >> 1] + a + b);       else         dp[i] = min(dp[i - 1] + a, dp[i >> 1] + b);     cout << dp[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string stringg;     string test =  new string for test ;     cin >> stringg;     int a = 5, b = 20;     int length = stringg.size();     int lower = 5 * 20;     for (int i = 1; i <= 5; i++)       for (int j = 1; j <= 20; j++) {         if (length <= i * j && i * j <= lower && i <= a) {           lower = i * j;           a = i;           b = j;         }       }     vector<vector<char> > mat(a, vector<char>(b));     for (int i = 0; i < 1000; i++) {       test +=  a ;     }     int currentcount = 0;     int zv = (lower - length) / a;     int zv2asdasd = (lower - length) % a;     bool k = 1;     cout << a <<     << b << endl;     for (int i = 0; i < 1000; i++) {       test +=  aa ;     }     for (int i = 0; i < a; i++) {       k = 1;       for (int j = 0; j < b; j++) {         if (j + 1 <= zv)           mat[i][j] =  * ;         else if (zv2asdasd != 0 && k) {           mat[i][j] =  * ;           zv2asdasd--;           k = 0;         } else {           mat[i][j] = stringg[currentcount];           currentcount++;         }         cout << mat[i][j];       }       cout << endl;     }     for (int i = 0; i < 1000; i++) {       test +=  aa ;     }     cin >> k;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b);   long long int gcd(long long int a, long long int b);   int prime(int n);   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     cin >> t;     while (t--) {       string a;       cin >> a;       long long int n = a.size();       long long int k = 0;       for (int i = 0; i < n; i++) {         if (a[i] !=  0 ) k++;       }       cout << k << endl;       for (int i = 0; i < n; i++) {         if (a[i] !=  0 ) {           cout << a[i];           for (int j = i + 1; j < n; j++) cout <<  0 ;           cout <<    ;         }       }       cout << endl;     }   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   long long int gcd(long long int a, long long int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int prime(int n) {     int flag = 1;     for (int i = 2; i <= sqrt(n); i++) {       if (n % i == 0) {         flag = 0;         break;       }     }     return flag;   }
#include <bits/stdc++.h>   inline long long gi() {     long long x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) f ^= ch ==  - , ch = getchar();     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f ? x : -x;   }   inline int pow(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = 1ll * ret * x % 1000000007;       x = 1ll * x * x % 1000000007;       y >>= 1;     }     return ret;   }   int f[1000010], S[1000010], fact[1000010], ifact[1000010];   int main() {     int n = gi(), k = gi();     fact[0] = 1;     for (int i = 1; i <= n; ++i) fact[i] = 1ll * fact[i - 1] * i % 1000000007;     ifact[n] = pow(fact[n], 1000000007 - 2);     for (int i = n; i; --i) ifact[i - 1] = 1ll * ifact[i] * i % 1000000007;     for (int i = k + 2; i <= n; ++i)       f[i] = 1ll * fact[i - 2] *              (0ll + i - k - 1 + S[i - 1] - S[i - k - 1] + 1000000007) %              1000000007,       S[i] = (S[i - 1] + 1ll * f[i] * ifact[i - 1]) % 1000000007;     printf( %d n , 1ll * fact[n - 1] * S[n] % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mat[1005][1005];   long long cols[1000005];   long long rows[1000005];   priority_queue<long long> pq;   int main() {     int n, m;     long long k, p;     scanf( %d %d %lld %lld , &n, &m, &k, &p);     for (int i = 0; i < n; i++) {       long long sum = 0;       for (int j = 0; j < m; j++) {         scanf( %d , &mat[i][j]);         sum += mat[i][j];       }       pq.push(sum);     }     for (int i = 1; i <= k; i++) {       long long val = pq.top();       pq.pop();       pq.push(val - p * m);       rows[i] = rows[i - 1] + val;     }     while (pq.size()) pq.pop();     for (int i = 0; i < m; i++) {       long long sum = 0;       for (int j = 0; j < n; j++) {         sum += mat[j][i];       }       pq.push(sum);     }     for (int i = 1; i <= k; i++) {       long long val = pq.top();       pq.pop();       pq.push(val - p * n);       cols[i] = cols[i - 1] + val;     }     long long ans = -1e18;     for (long long i = 0; i <= k; i++) {       ans = max(ans, rows[i] + cols[k - i] - i * (k - i) * p);     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int Maxn = 2e5 + 5, N = 4e5 + 5, Mod = 1e9 + 7, Inf = 1e18,                       Log = 22;   int n, h[Maxn], r, mx;   vector<int> adj[Maxn];   bool mrk[Maxn];   bool flg[2];   void Dfs(int v, int p) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (u == p) continue;       h[u] = h[v] + 1;       if (adj[u].size() == 1) {         if (h[u] & 1) {           flg[0] = 1;         } else {           flg[1] = 1;         }       }       Dfs(u, v);     }     return;   }   void DFs(int v, int p) {     for (int i = 0; i < adj[v].size(); i++) {       int u = adj[v][i];       if (u == p) continue;       if (adj[u].size() == 1) {         mrk[v] = 1;         mx--;         continue;       }       DFs(u, v);     }     mx += mrk[v];     return;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);       if (1 < adj[v].size())         r = v;       else if (1 < adj[u].size())         r = u;     }     Dfs(r, -1);     if (flg[0] && flg[1])       cout << 3 <<    ;     else       cout << 1 <<    ;     DFs(r, -1);     cout << n - 1 + mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[5000007], b[5000007];   long long mod = 1e9 + 7;   unsigned long long power(unsigned long long x, long long y, long long p) {     unsigned long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   unsigned long long modInverse(unsigned long long n, long long p) {     return power(n, p - 2, p);   }   unsigned long long nCrModPFermat(unsigned long long n, long long r,                                    long long p) {     if (n < r) return 0;     if (r == 0) return 1;     unsigned long long fac[n + 1];     fac[0] = 1;     for (long long i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;     return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %            p;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     while (t--) {       long long i, j, k, l, ans = 0, count = 0, n, m, x, y;       bool flag = 0;       string s;       long long maxa = -1000000000000000, mina = 1000000000000000;       cin >> n;       for (i = 0; i < 2 * n; i++) cin >> a[i];       sort(a, a + 2 * n);       for (i = 0; i < n; i++) ans -= a[i];       for (i = n; i < 2 * n; i++) ans += a[i];       cout << ((ans % 998244353) * (nCrModPFermat(2 * n, n, 998244353))) %                   998244353            <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   void albus() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool asec(long long a, long long b) { return a < b; }   bool desc(long long a, long long b) { return a > b; }   bool Asec_and_desc(pair<long long, pair<long long, long long>> a,                      pair<long long, pair<long long, long long>> b) {     if (a.first == b.first) {       if (a.second.first == b.second.first) {         return a.second.second < b.second.second;       }       return a.second.first < b.second.first;     }     return a.first > b.first;   }   bool compare(pair<long long, long long> a, pair<long long, long long> b) {     return a.second < b.second;   }   typedef struct data {     data *bit[2];     long long cnt = 0;   } trie;   trie *head;   void insert(long long x) {     trie *node = head;     for (long long i = 30; i >= 0; i--) {       long long cur = (x >> i) & 1;       if (node->bit[cur] == NULL) {         node->bit[cur] = new trie();       }       node = node->bit[cur];       node->cnt++;     }   }   long long countXor(long long x, long long q) {     trie *node = head;     long long ans = 0, sum = 0;     for (long long i = 30; i >= 0; i--) {       long long cur = (x >> i) & 1;       long long cur2 = (q >> i) & 1;       if (cur2 == 0) {         if (node->bit[!cur] != NULL) ans += node->bit[!cur]->cnt;         if (node->bit[cur] != NULL) {           node = node->bit[cur];         } else           return ans;       } else if (cur2 == 1) {         if (node->bit[!cur] != NULL)           node = node->bit[!cur];         else           return ans;       }     }     ans += node->cnt;     return ans;   }   int32_t main() {     albus();     head = new trie();     insert(0);     long long n, q;     cin >> n >> q;     vector<long long> A;     for (long long i = 1; i <= n; i++) {       long long a;       cin >> a;       A.push_back(a);     }     long long xo = 0, final = 0;     for (long long i = 0; i < A.size(); i++) {       xo ^= A[i];       final += countXor(xo, q);       insert(xo);     }     cout << final << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m = 0, b, c = 0;     cin >> n;     int a[1001];     for (int i = 0; i < n; i++) {       cin >> b;       if (b == 1) {         a[m] = c;         m += 1;       }       c = b;     }     a[m] = c;     cout << m << endl;     for (int i = 1; i < m + 1; i++) {       cout << a[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 10;   long long ans[MAXN];   int vis[MAXN], in[MAXN], worst[MAXN];   vector<int> adj[MAXN], idx[MAXN], path;   vector<pair<int, int> > bad, qs[MAXN];   struct BIT {     long long b[MAXN];     BIT() { fill(b, b + MAXN, 0); }     void upd(int p, long long v) {       for (; p < MAXN; p += (p & -p)) b[p] += v;     }     long long sum(int p) {       long long res = 0;       for (; p; p -= (p & -p)) res += b[p];       return res;     }     long long qry(int l, int r) { return sum(r) - sum(l - 1); }   };   BIT wo, cn;   void dfs(int s, int p = 0) {     vis[s] = 1;     in[s] = 1;     path.push_back(s);     for (auto v : adj[s]) {       if (v == p) continue;       if (!vis[v])         dfs(v, s);       else if (in[v]) {         int u, mi = MAXN, ma = -MAXN;         do {           u = path.back();           path.pop_back();           in[u] = 0;           ma = max(ma, u);           mi = min(mi, u);         } while (u != v);         worst[ma] = max(worst[ma], mi);       }     }   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int u = 1; u <= n; u++)       if (!vis[u]) dfs(u);     int cur = 0;     for (int i = 1; i <= n; i++) {       worst[i] = max(worst[i], cur);       cur = worst[i];       wo.upd(i, worst[i]);       idx[cur].push_back(i);     }     int q;     cin >> q;     for (int i = 0; i < q; i++) {       int l, r;       cin >> l >> r;       qs[l].push_back({r, i});     }     for (int l = 1; l <= n; l++) {       for (auto i : idx[l - 1]) {         wo.upd(i, -worst[i]);         cn.upd(i, 1);       }       for (auto p : qs[l]) {         int r = p.first;         long long d = r - l + 1;         long long tot = (long long)r * (r + 1) / 2 - (long long)l * (l - 1) / 2;         tot -= wo.qry(l, r);         tot -= cn.qry(l, r) * (l - 1);         ans[p.second] = tot;       }     }     for (int i = 0; i < q; i++) cout << ans[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int n, pos, l, r, ind, ans = 0, ans1 = 0, ans2 = 0;   int main(void) {     ios ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> pos >> l >> r;     if (pos < l) {       ans += l - pos + 1;       if (n - r > 0) {         ans += r - l + 1;       }     } else if (pos > r) {       ans += pos - r + 1;       if (l - 1 > 0) {         ans += r - l + 1;       }     } else {       ind = pos;       if (l - 1 > 0) {         ans1 += ind - l + 1;         ind = l;       }       if (n - r > 0) {         ans1 += r - ind + 1;       }       ind = pos;       if (n - r > 0) {         ans2 += r - ind + 1;         ind = r;       }       if (l - 1 > 0) {         ans2 += ind - l + 1;       }       ans = min(ans1, ans2);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n = 0, x, y, s = 0;     cin >> m;     vector<int> c(m);     for (int i = 0; i < (int)(m); ++i) {       cin >> c[i];       n += c[i];     }     cin >> x >> y;     for (int i = 0; i < (int)(m); ++i) {       s += c[i];       if (s <= y && s >= x && n - s <= y && n - s >= x) {         cout << i + 2 << endl;         return 0;       }     }     cout << 0 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 100000 + 100;   const int N = 100 + 100;   const int Mod = 1000000007;   int n, m;   int C[M][N], B[M][N], A[M];   int cnt[N];   inline void Pre() {     C[0][0] = 1;     for (int i = 1; i <= 100000; ++i) {       C[i][0] = 1;       for (int j = 1; j <= 100; ++j)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;     }   }   int main() {     Pre();     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &A[i]);     for (int i = 1; i <= m; ++i) {       int L, R, k;       scanf( %d%d%d , &L, &R, &k);       for (int j = 0; j <= k; ++j) B[L][j] = (B[L][j] + C[k][k - j]) % Mod;       for (int j = 0; j <= k; ++j)         B[R + 1][j] = (B[R + 1][j] - C[R + 1 - L + k][k - j]) % Mod;     }     for (int i = 1; i <= n; ++i) {       for (int j = 0; j <= 100; ++j) cnt[j] = (cnt[j] + B[i][j]) % Mod;       A[i] = (A[i] + cnt[0]) % Mod;       for (int j = 0; j <= 100; ++j) cnt[j] = (cnt[j] + cnt[j + 1]) % Mod;     }     for (int i = 1; i <= n; ++i) printf( %d  , (A[i] + Mod) % Mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b, k;   const int MOD = 1000000007;   int dp[5005][5005], sum[5005];   int main() {     scanf( %d%d%d%d , &n, &b, &a, &k);     for (int i = b; i <= n; i++) sum[i] = 1;     dp[0][b] = 1;     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         if (j == a) continue;         if (j > a)           dp[i][j] =               ((sum[n] - sum[(a + j) / 2] + MOD) % MOD - dp[i - 1][j] + MOD) %               MOD;         else           dp[i][j] = (sum[(a - 1 + j) / 2] - dp[i - 1][j] + MOD) % MOD;       }       sum[0] = 0;       for (int j = 1; j <= n; j++) sum[j] = (sum[j - 1] + dp[i][j]) % MOD;     }     printf( %d n , sum[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   istream& operator>>(istream& in, pair<T1, T2>& p) {     in >> p.first >> p.second;     return in;   }   template <typename T1, typename T2>   ostream& operator<<(ostream& out, pair<T1, T2> p) {     out <<  {  << p.first <<  ,   << p.second <<  } ;     return out;   }   template <typename T>   istream& operator>>(istream& in, vector<T>& arr) {     for (auto& i : arr) {       in >> i;     }     return in;   }   template <typename T>   ostream& operator<<(ostream& out, vector<T> arr) {     for (int64_t i = 0; i < (int64_t)arr.size() - 1; ++i) out << arr[i] <<    ;     if (arr.size()) out << arr.back();     out <<   n ;     return out;   }   int64_t get(int64_t n, int64_t k) {     if (n >= 0) {       return -n / k;     } else {       return abs(n) / k + (n % k != 0) * 1;     }   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int64_t p, k;     cin >> p >> k;     if (p < k) {       cout << 1 <<   n ;       cout << p <<   n ;       return 0;     }     vector<int64_t> ans(500000);     ans[0] = -p / k;     for (int64_t i = 1; i < 500000; ++i) {       ans[i] = get(ans[i - 1], k);     }     if (ans.back() != 0) {       cout << -1 <<   n ;       return 0;     }     while (ans.back() == 0) ans.pop_back();     vector<int64_t> ans2(ans.size() + 1);     ans2[0] = ans[0] * k + p;     for (int64_t i = 1; i < ans.size(); ++i) {       ans2[i] = ans[i] * k + ans[i - 1];     }     ans2[ans.size()] = ans.back();     cout << ans2.size() <<   n ;     cout << ans2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, a[N], ans;   bool vis[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     int now = 1, dir = 0, tot = 0;     while (tot < n) {       if (dir == 0) {         for (int i = now; i <= n; i++)           if (!vis[i] && tot >= a[i]) {             vis[i] = 1;             tot++;           }         now = n;         dir = 1;         if (tot < n) ans++;       } else {         for (int i = now; i >= 1; i--)           if (!vis[i] && tot >= a[i]) {             vis[i] = 1;             tot++;           }         now = 1;         dir = 0;         if (tot < n) ans++;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mxn = 5e3 + 100;   long long dp[25][mxn];   long long arr[mxn];   long long n, k;   bool Check(long long id, long long lo, long long hi, long long rtk) {     while (lo <= hi) {       long long mid = (lo + hi) / 2;       if (dp[id][mid] > rtk)         hi = mid - 1;       else if (dp[id][mid] < rtk)         lo = mid + 1;       else         return true;     }     return false;   }   int main() {     scanf( %lld%lld , &n, &k);     for (int i = 1; i <= n; i++) scanf( %lld , &arr[i]);     sort(arr + 1, arr + n + 1);     for (int i = 1; i <= n; i++) dp[1][i] = arr[i];     for (int i = 2; i <= k; i++) {       for (long long j = 1; j <= n; j++) dp[i][j] = arr[j] * i;     }     long long q;     scanf( %lld , &q);     while (q--) {       long long tk;       scanf( %lld , &tk);       long long mn = 1e9;       long long ans = 0;       for (int i = 1; i <= k; i++) {         for (int j = 1; j <= n; j++) {           long long tmp = dp[i][j];           if (tmp > tk) break;           long long ans = i;           long long rem = k - i;           if (tmp == tk)             mn = min(ans, mn);           else {             for (int jj = 1; jj <= rem; jj++) {               if (Check(jj, j + 1, n, tk - tmp)) {                 mn = min(ans + jj, mn);                 break;               }             }           }         }       }       if (mn == 1e9) mn = -1;       printf( %lld n , mn);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, s[100010][200], ans = 0x3f3f3f3f, vis[200], sub, cunt;   char a[100010];   bool check(int l, int r) {     int cnt = 0;     for (int i = 65; i <= 122; i++)       if (s[r][i] - s[l - 1][i]) cnt++;     return (cnt == cunt);   }   int find(int pos) {     int l = pos, r = n;     while (l < r) {       int mid = (l + r) >> 1;       if (check(pos, mid))         r = mid;       else         l = mid + 1;     }     if (check(pos, r))       return r;     else       return 0x3f3f3f3f;   }   int main() {     scanf( %d%s , &n, a + 1);     for (int i = 1; i <= n; i++) {       for (int j = 65; j <= 122; j++) s[i][j] = s[i - 1][j];       s[i][a[i]]++;       if (!vis[a[i]]) cunt++, vis[a[i]] = 1;     }     for (int i = 1; i <= n; i++) {       ans = min(ans, find(i) - i + 1);       if (--vis[a[i]] == 0) sub++;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> a;   char op[3];   long long res;   void Gao(vector<long long> a) {     if (a.size() == 1) {       if (res == -1)         res = a[0];       else         res = min(res, a[0]);       return;     }     vector<long long> tmp;     for (int i = 0; i < a.size(); i++)       for (int j = i + 1; j < a.size(); j++) {         tmp.clear();         for (int k = 0; k < a.size(); k++)           if (k != i && k != j) tmp.push_back(a[k]);         if (op[4 - a.size()] ==  + )           tmp.push_back(a[i] + a[j]);         else           tmp.push_back(a[i] * a[j]);         Gao(tmp);       }   }   int main() {     a.resize(4);     for (int i = 0; i < 4; i++) cin >> a[i];     for (int i = 0; i < 3; i++) scanf(  %c , &op[i]);     res = -1;     Gao(a);     cout << res << endl;     return 0;   }