malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int MOD2 = 1e9 + 9;   const int PR = 727;   const int INF = INT_MAX;   const long long LINF = LLONG_MAX;   const int N = 1e5 + 20;   vector<int> G[N], p;   int n, m, k, f[N], tmp;   bool visited[N];   int main() {     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);     cin >> n >> m >> k;     for (int i = 0, v, u; i < m; i++) {       cin >> v >> u;       G[v].push_back(u);       G[u].push_back(v);     }     int v = 1;     while (1) {       visited[v] = 1;       f[v] = tmp++;       p.push_back(v);       for (int u : G[v])         if (!visited[u]) v = u;       if (visited[v]) break;     }     int idx = INF;     for (int v : G[p.back()]) idx = min(idx, f[v]);     cout << p.size() - idx << endl;     for (int i = idx; i < p.size(); i++) cout << p[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 500000;   int a[MAX], last[MAX], prv[MAX], inSet[MAX], current[MAX];   int n, k;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     memset(last, -1, sizeof(last));     memset(prv, -1, sizeof(prv));     for (int i = 0; i < n; i++) {       cin >> a[i];       prv[i] = last[a[i]];       last[a[i]] = i;     }     set<pair<int, int> > s;     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       int cur = a[i];       if (inSet[cur]) {         s.erase(s.find(make_pair(current[cur], cur)));         s.insert(make_pair(prv[i], cur));         current[cur] = prv[i];         continue;       }       ans++;       if (s.size() < k) {         inSet[cur] = true;         s.insert(make_pair(prv[i], cur));         current[cur] = prv[i];       } else {         pair<int, int> fr = (*s.begin());         inSet[cur] = true;         inSet[fr.second] = false;         s.erase(s.begin());         s.insert(make_pair(prv[i], cur));         current[cur] = prv[i];       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, k;     cin >> n >> k;     vector<int> v(n + 1, 0);     for (int i = 1; i <= n; i++) {       cin >> v[i];     }     sort(v.begin() + 1, v.end());     v[0] = v[1];     auto get = [&](int x) {       vector<int> p;       p.emplace_back(0);       for (int i = 1; i <= n; i++) {         int left = lower_bound(v.begin(), v.end(), v[i] - x) - v.begin() - 1;         int right = i - k;         auto it = lower_bound(p.begin(), p.end(), left);         if (it != p.end() and *it <= right) {           p.emplace_back(i);         }       }       return (find(p.begin(), p.end(), n) != p.end());     };     int lo = 0, hi = (v[n] - v[1]), ans = 1e9;     while (lo <= hi) {       int md = (lo + hi) / 2;       if (get(md))         ans = md, hi = md - 1;       else         lo = md + 1;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     if (k > n)       cout << -1 <<   n ;     else if (n != 1 && k == 1)       cout << -1 <<   n ;     else if (k == n) {       char x =  a ;       for (long long int i = 1; i <= (long long int)n; i++) {         cout << x;         x++;       }     } else if (k < n) {       long long int t = n - (k - 2);       for (long long int i = 1; i <= (long long int)t; i++) {         if (i % 2 != 0)           cout <<  a ;         else           cout <<  b ;       }       long long int q = n - t;       char y =  c ;       if (q > 0) {         for (long long int i = 1; i <= (long long int)q; i++) {           cout << y;           y++;         }       }     }   }   int main() {     std::ios::sync_with_stdio(false);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n, s, k, a[55], dp[55][2505];     cin >> n >> s >> k;     for (int i = 0; i < n; i++) cin >> a[i];     string s1;     cin >> s1;     priority_queue<pair<int, pair<int, int> > > q;     s--;     for (int i = 0; i < 55; i++)       for (int j = 0; j < 2505; j++) dp[i][j] = 1e7 + 7;     for (int i = 0; i < n; i++) {       dp[i][a[i]] = abs(i - s);       q.push(make_pair(abs(i - s), make_pair(i, a[i])));     }     while (!q.empty()) {       pair<int, pair<int, int> > p = q.top();       q.pop();       int dd = p.first;       int at = p.second.first;       int choc = p.second.second;       for (int i = 0; i < n; i++) {         if (a[i] > a[at] && s1[i] != s1[at]) {           int dis = abs(i - at);           if (dp[at][choc] + dis < dp[i][choc + a[i]]) {             dp[i][choc + a[i]] = dp[at][choc] + dis;             q.push(make_pair(-dp[i][choc + a[i]], make_pair(i, choc + a[i])));           }         }       }     }     int ans = 1e7 + 7;     for (int i = 0; i < n; i++)       for (int j = k; j <= 2505; j++) ans = min(ans, dp[i][j]);     if (ans > 1e6)       cout <<  -1 ;     else       cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, cnt = 0;     cin >> x;     int arr1[x], arr2[x];     for (int i = 0; i < x; i++) {       cin >> arr1[i] >> arr2[i];     }     for (int i = 0; i < x; i++) {       for (int j = 0; j < x; j++) {         if (i == j) {           continue;         }         if (arr1[i] == arr2[j]) {           cnt++;         }       }     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   void IO() {     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   int main() {     IO();     int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int sum = 0;       vector<long long int> arr(n + 1);       for (__typeof(n + 1) i = (1) - ((1) > (n + 1));            i != (n + 1) - ((1) > (n + 1)); i += 1 - 2 * ((1) > (n + 1))) {         cin >> arr[i];         sum += arr[i];       }       long long int rem = sum % n;       if (rem)         cout << -1 <<   n ;       else {         long long int want = sum / n;         vector<pair<pair<long long int, long long int>, long long int> > ans;         for (__typeof(n + 1) i = (2) - ((2) > (n + 1));              i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {           long long int rem = arr[i] % i;           arr[1] += arr[i];           if (rem) {             long long int more = i - rem;             ans.push_back(make_pair(make_pair(1, i), more));           }           ans.push_back(make_pair(make_pair(i, 1), (arr[i] + i - 1) / i));         }         for (__typeof(n + 1) i = (2) - ((2) > (n + 1));              i != (n + 1) - ((2) > (n + 1)); i += 1 - 2 * ((2) > (n + 1))) {           ans.push_back(make_pair(make_pair(1, i), want));         }         long long int a = (int)(ans.size());         cout << a <<   n ;         for (__typeof(a) i = (0) - ((0) > (a)); i != (a) - ((0) > (a));              i += 1 - 2 * ((0) > (a))) {           cout << ans[i].first.first <<     << ans[i].first.second <<                    << ans[i].second <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char** argv) {     long long r, x1, y1, x2, y2;     while (cin >> r >> x1 >> y1 >> x2 >> y2) {       double dis = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) + 0.0);       cout << ceil(dis / 2 / r) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   const int N = 400005;   const int mod = 998244353;   int n, m;   int fact[N], infact[N];   int qmi(int a, int k, int p) {     int res = 1;     while (k) {       if (k & 1) res = (LL)res * a % p;       a = (LL)a * a % p;       k >>= 1;     }     return res;   }   int C(int a, int b) {     return (LL)fact[a] * infact[a - b] % mod * infact[b] % mod;   }   int main() {     scanf( %d%d , &n, &m);     fact[0] = infact[0] = 1;     for (int i = 1; i < N; ++i) {       fact[i] = (LL)fact[i - 1] * i % mod;       infact[i] = (LL)infact[i - 1] * qmi(i, mod - 2, mod) % mod;     }     if (n == 2) {       printf( %d n , 0);       return 0;     }     int res = (LL)C(m, n - 1) * (n - 2) % mod;     int p = qmi(2, n - 3, mod) % mod;     printf( %d n , (LL)res * p % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     const int maxn = 1005;     char a[2 * maxn], b[maxn];     scanf( %s , a);     scanf( %s , b);     int lenA = strlen(a);     int lenB = strlen(b);     int cntA = 0, cntB = 0;     int i;     for (i = 0; i < lenA; i++)       if (a[i] ==  1 ) cntA++;     for (i = 0; i < lenB; i++)       if (b[i] ==  1 ) cntB++;     if (cntA % 2 == 0) {       if (cntA < cntB) {         puts( NO );       } else {         puts( YES );       }     } else {       if (cntB - cntA > 1) {         puts( NO );       } else {         puts( YES );       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int H = 1000000;   template <typename Key, typename Val>   struct Hash {     char *used;     Key *key;     Val *val;     Hash() {       used = new char[H];       key = new Key[H];       val = new Val[H];       memset(used, 0, sizeof(used));     }     int hash_func(const Key &k) { return k % H; }     pair<bool, int> find(const Key &k) {       int h = hash_func(k);       for (;; h++, h = (h == H) ? 0 : h) {         if (not used[h]) return make_pair(false, h);         if (key[h] == k) return make_pair(true, h);       }     }     void insert(const Key &k, const Val &v) {       int h = find(k).second;       used[h] = 1;       key[h] = k;       val[h] = v;     }     Val &get(const Key &k) {       pair<bool, int> f = find(k);       if (!f.first) assert(false);       return val[f.second];     }   };   int mod;   long long find(const long long &n, long long l, long long r, long long u,                  long long v, long long &num) {     num = 0;     if (l > r or u > v) return 0;     if (v < 1 or n < u) return 0;     if (r < 1 or n < l) return 0;     if (n == 1) {       if (l <= 1 and 1 <= r and u <= 1 and 1 <= v) {         num = 1;         return 1;       } else {         num = 0;         return 0;       }     }     l = max(1ll, l);     r = min(n, r);     u = max(1ll, u);     v = min(n, v);     if (l == 1 and r == n) {       num = v - u + 1;       long long c1 = v + u, c2 = (v - u + 1);       if (c1 % 2 == 0)         c1 /= 2;       else         c2 /= 2;       c1 %= mod;       c2 %= mod;       return c1 * c2 % mod;       ;     }     num = 0;     const long long n1 = (n + 1) / 2, n2 = n / 2;     long long ans = 0;     if (l <= n1) {       long long u1 = u, v1 = v, nn;       if (u1 % 2 == 0) u1++;       if (v1 % 2 == 0) v1--;       ans += find(n1, l, min(r, n1), (u1 + 1) / 2, (v1 + 1) / 2, nn) * 2;       num += nn;       ans -= nn;     }     if (n1 + 1 <= r) {       long long u1 = u, v1 = v, nn;       if (u1 % 2 == 1) u1++;       if (v1 % 2 == 1) v1--;       ans += find(n2, max(l, n1 + 1) - n1, r - n1, u1 / 2, v1 / 2, nn) * 2;       num += nn;     }     ans = (ans % mod + mod) % mod;     return ans;   }   long long n;   int m;   long long l, r, u, v;   int main() {     scanf( %I64d%d%d , &n, &m, &mod);     for (int i = 0; i < (int)(m); ++i) {       scanf( %I64d%I64d%I64d%I64d , &l, &r, &u, &v);       long long n1;       printf( %lld n , find(n, l, r, u, v, n1));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortmd(pair<long long, long long> &a, pair<long long, long long> &b) {     if (a.first != b.first)       return a.first < b.first;     else       return a.second < b.second;   }   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     srand(time(NULL));     long long t, i, j, a, b;     cin >> t;     while (t--) {       cin >> a >> b;       if (a == b) {         cout << 0 << endl;       } else if (a < b) {         j = b - a;         if (j % 2 == 0)           cout << 2 << endl;         else           cout << 1 << endl;       } else {         j = a - b;         if (j % 2 == 0)           cout << 1 << endl;         else           cout << 2 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   const int MAX = (int)1e5 + 5;   int a[MAX], b[MAX], n, m, c;   int main() {     scanf( %d%d%d , &n, &m, &c);     for (int i = 1; i <= n; i++) scanf( %d , a + i);     for (int i = 1; i <= m; i++) {       scanf( %d , b + i);       b[i] = (b[i] + b[i - 1]) % c;     }     for (int i = 1; i <= n; i++) {       a[i] = (i <= n - m + 1                   ? (a[i] + (i >= m ? b[m] : b[i])) % c                   : (a[i] + c + b[(i >= m) ? m : i] - b[m - 1 - (n - i)]) % c);       printf( %d  , a[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0;     bool f = 0;     for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return x;   }   int mod;   struct modint {     int x;     modint(int o = 0) { x = o; }     modint &operator=(int o) { return x = o, *this; }     modint &operator+=(modint o) {       return x = x + o.x >= mod ? x + o.x - mod : x + o.x, *this;     }     modint &operator-=(modint o) {       return x = x - o.x < 0 ? x - o.x + mod : x - o.x, *this;     }     modint &operator*=(modint o) { return x = 1ll * x * o.x % mod, *this; }     modint &operator^=(int b) {       modint a = *this, c = 1;       for (; b; b >>= 1, a *= a)         if (b & 1) c *= a;       return x = c.x, *this;     }     modint &operator/=(modint o) { return *this *= o ^= mod - 2; }     modint &operator+=(int o) {       return x = x + o >= mod ? x + o - mod : x + o, *this;     }     modint &operator-=(int o) {       return x = x - o < 0 ? x - o + mod : x - o, *this;     }     modint &operator*=(int o) { return x = 1ll * x * o % mod, *this; }     modint &operator/=(int o) { return *this *= ((modint(o)) ^= mod - 2); }     template <class I>     friend modint operator+(modint a, I b) {       return a += b;     }     template <class I>     friend modint operator-(modint a, I b) {       return a -= b;     }     template <class I>     friend modint operator*(modint a, I b) {       return a *= b;     }     template <class I>     friend modint operator/(modint a, I b) {       return a /= b;     }     friend modint operator^(modint a, int b) { return a ^= b; }     friend bool operator==(modint a, int b) { return a.x == b; }     friend bool operator!=(modint a, int b) { return a.x != b; }     bool operator!() { return !x; }     modint operator-() { return x ? mod - x : 0; }   };   inline modint qpow(modint a, int b) { return a ^ b; }   int n, k;   map<int, int> mp;   modint iv[100005], sum[100005];   void div(int l, int r, int k) {     if (k <= 1 || l == r) return mp[r - l + 1]++, void();     int mid = l + r >> 1;     div(l, mid, k - 1), div(mid + 1, r, k - 1);   }   modint getprob(int x, int y) {     modint res = modint(x) * y;     for (register int i = (1); i <= (x); ++i) res -= 2 * (sum[i + y] - sum[i]);     return res;   }   signed main() {     n = read(), k = read(), mod = read();     iv[1] = 1;     for (register int i = (2); i <= (max(4, n)); ++i)       iv[i] = iv[mod % i] * (mod - mod / i);     for (register int i = (1); i <= (n); ++i) sum[i] = sum[i - 1] + iv[i];     div(1, n, k);     modint res = 0;     for (auto it1 : mp)       for (auto it2 : mp) {         if (it1.first == it2.first) {           int cnt = it1.second, len = it1.first;           res += iv[2] * len * (len - 1) * cnt;           res += modint(cnt) * (cnt - 1) * iv[2] * getprob(len, len);         } else if (it1.first < it2.first) {           int l1 = it1.first, l2 = it2.first, c1 = it1.second, c2 = it2.second;           res += getprob(l1, l2) * c1 * c2;         }       }     res *= iv[2];     cout << res.x;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   int n, l, m;   const int MAXN = 1e6 + 5;   long long cini[MAXN], cfin[MAXN];   vector<vector<long long>> owo;   vector<vector<long long>> mul(vector<vector<long long>> A,                                 vector<vector<long long>> B) {     int n = A.size();     vector<vector<long long>> res(n, vector<long long>(n));     for (int k = 0; k < n; k++)       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++)           res[i][j] = (res[i][j] + A[i][k] * B[k][j]) % MOD;     return res;   }   vector<vector<long long>> mexp(vector<vector<long long>> M, long long e) {     int n = M.size();     vector<vector<long long>> res(n, vector<long long>(n));     for (int i = 0; i < n; i++) res[i][i] = 1;     for (long long k = 1; k <= e; k *= 2) {       if (k & e) res = mul(res, M);       M = mul(M, M);     }     return res;   }   int cost[MAXN];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> l >> m;     for (int i = 0; i < n; i++) {       int x;       cin >> x;       cini[x % m]++;     }     owo.assign(m, vector<long long>(m));     for (int i = 0; i < n; i++) {       int x;       cin >> x;       cost[i] = x;       for (int i = 0; i < m; i++) {         owo[i][(x + i) % m]++;       }     }     for (int i = 0; i < n; i++) {       int x;       cin >> x;       cfin[(x + cost[i]) % m]++;     }     vector<vector<long long>> res = mexp(owo, l - 2);     long long ans = 0;     for (int a = 0; a < m; a++) {       for (int b = 0; b < m; b++) {         int rem = (a + b) % m;         if (rem > 0) rem = m - rem;         long long te = ((long long)cini[a] * cfin[b]) % MOD;         ans = (ans + te * res[0][rem]) % MOD;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const int INF = 1034567890;   const long long LL_INF = 1234567890123456789ll;   const double PI = acos(-1);   const long double ERR = 1E-10;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int cnt = 1;       int place{};       int ph;       for (auto i{0}; i < 9; i++) {         if (n >= cnt) {           place = cnt;         }         cnt *= 3;       }       place *= 3;       ph = place;       int res = 0;       if (n > place / 2) {         res = place;       } else {         place /= 3;         res += place;         n -= place;         while (n && place) {           place /= 3;           if (n > place / 2) {             n -= place;             res += place;           }         }       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, sum = 0;     vector<int> ans;     cin >> n;     cout << (n * (n + 1) / 2) % 2 <<   n ;     sum = n * (n + 1) / 4;     while (sum) {       if (n <= sum) {         sum -= n;         ans.emplace_back(n);       }       n--;     }     cout << ans.size() <<    ;     for (int i = 0; i < ans.size(); i++) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<long long> s(n);     for (int(i) = (int)(0); (i) < (int)(n); ++(i)) cin >> s[i];     long long a, b, c, d, e;     cin >> a >> b >> c >> d >> e;     long long r = 0;     vector<long long> t(5, 0);     for (int(i) = (int)(0); (i) < (int)(n); ++(i)) {       r += s[i];       if (r >= e) t[4] += r / e, r -= (r / e) * e;       if (r >= d) t[3] += r / d, r -= (r / d) * d;       if (r >= c) t[2] += r / c, r -= (r / c) * c;       if (r >= b) t[1] += r / b, r -= (r / b) * b;       if (r >= a) t[0] += r / a, r -= (r / a) * a;     }     for (int(i) = (int)(0); (i) < (int)(5); ++(i)) cout << t[i] <<    ;     cout << endl;     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 5;   vector<int> g[maxn];   bool used[maxn][maxn];   int v[maxn], stk[maxn];   void dfs(int z, int m, int x, bool eq) {     stk[z] = x;     if (z == m) {       if (eq) return;       for (int i = 0; i < m + 1; ++i) printf( %d  , stk[i] + 1);       puts(  );       exit(0);     }     for (int i = 0; i < (int)g[x].size(); ++i) {       if (!used[x][g[x][i]] && !used[g[x][i]][x]) {         if (!eq || g[x][i] >= v[z + 1]) {           used[x][g[x][i]] = true;           dfs(z + 1, m, g[x][i], g[x][i] > v[z + 1] ? false : eq);           used[x][g[x][i]] = false;         }       }     }   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < m + 1; ++i) {       scanf( %d , &v[i]);       --v[i];     }     for (int i = 0; i < m; ++i) {       g[v[i]].push_back(v[i + 1]);       g[v[i + 1]].push_back(v[i]);     }     for (int i = 0; i < n; ++i) {       sort(g[i].begin(), g[i].end());     }     dfs(0, m, v[0], true);     puts( No solution );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     map<int, vector<int> > m;     int e;     for (int i = 2; i <= n; i++) {       cin >> e;       m[e].push_back(i);     }     vector<bool> leaf(n + 1, true);     leaf[1] = false;     for (int i = 1; i <= n; i++) {       if (m.count(i) > 0) {         int c = 0;         for (auto it = m[i].begin(); it != m[i].end(); it++) {           if (m.count(*it) != 1) c++;         }         if (c < 3) {           cout <<  No n ;           return 0;         }       }     }     cout <<  Yes n ;   }
#include <bits/stdc++.h>   using namespace std;   double dp[2005][2005];   int main() {     ios::sync_with_stdio(0);   a:     int n, t;     double p;     cin >> n >> p >> t;     dp[0][0] = 1.0;     for (int i = 1; i <= t; i++) dp[i][0] = dp[i - 1][0] * (1.0 - p);     for (int j = 1; j <= n; j++) dp[0][j] = 0.0;     for (int i = 1; i <= t; i++) {       for (int j = 1; j <= n; j++) {         if (j == n)           dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j];         else           dp[i][j] = dp[i - 1][j - 1] * p + dp[i - 1][j] * (1.0 - p);       }     }     double res = 0.0;     for (int i = 0; i <= n; i++) res += (dp[t][i] * ((double)i));     printf( %.10f n , (double)res);   }
#include <bits/stdc++.h>   using namespace std;   int arr[1100];   int main() {     int n, a, b, c, t, ans = 0, sum = 0;     cin >> n >> a >> b >> c >> t;     for (int i = 0; i < n; i++) {       cin >> arr[i];       sum += t - arr[i];     }     ans = n * a;     if (b >= c) {       cout << ans << endl;     } else {       cout << ans + sum * (c - b) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4005;   int f[maxn][maxn], prea[maxn][26], preb[maxn][26];   char a[maxn], b[maxn];   int n, m, ti, td, tr, te;   int main() {     int i, j, x, y;     scanf( %d%d%d%d , &ti, &td, &tr, &te);     scanf( %s%s , a + 1, b + 1);     n = strlen(a + 1);     m = strlen(b + 1);     for (i = 1; i <= n; ++i) {       memcpy(prea[i], prea[i - 1], sizeof prea[0]);       prea[i][a[i] -  a ] = i;       f[i][0] = i * td;     }     for (i = 1; i <= m; ++i) {       memcpy(preb[i], preb[i - 1], sizeof preb[0]);       preb[i][b[i] -  a ] = i;       f[0][i] = i * ti;     }     for (i = 1; i <= n; ++i)       for (j = 1; j <= m; ++j) {         f[i][j] = min(f[i - 1][j] + td, f[i][j - 1] + ti);         f[i][j] = min(f[i][j], f[i - 1][j - 1] + (a[i] != b[j] ? tr : 0));         x = prea[i - 1][b[j] -  a ];         y = preb[j - 1][a[i] -  a ];         if (x && y)           f[i][j] = min(f[i][j], f[x - 1][y - 1] + te + (i - x - 1) * td +                                      (j - y - 1) * ti);       }     printf( %d n , f[n][m]);     return 0;   }