malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, x;   long long f[1510], g[1510];   long long sum[1510];   int main() {     memset(f, 0, sizeof(f));     scanf( %d%d , &n, &m);     for (int i = 0; i < n; ++i) {       scanf( %d , &x);       sum[0] = x;       for (int j = 1; j < m; ++j) {         scanf( %d , &x);         sum[j] = sum[j - 1] + x;       }       if (i == 0) {         for (int j = 0; j < m; ++j) f[j] = sum[j];       } else if ((i & 1) == 1) {         long long cm = f[m - 1];         for (int j = m - 2; j >= 0; --j) {           g[j] = sum[j] + cm;           cm = max(cm, f[j]);         }         for (int j = 0; j < m - 1; ++j) f[j] = g[j];       } else {         long long cm = f[0];         for (int j = 1; j < m; ++j) {           g[j] = sum[j] + cm;           cm = max(cm, f[j]);         }         for (int j = 1; j < m; ++j) f[j] = g[j];       }     }     long long ans = -9999999999999999ll;     if ((n & 1) == 0) {       for (int i = 0; i < m - 1; ++i) ans = max(f[i], ans);     } else {       for (int i = 1; i < m; ++i) ans = max(f[i], ans);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool yes(int a, int b, bool vis[10]) {     long long int temp = a;     while (temp > 0) {       int r = temp % 10;       if (vis[r] == true) {         return true;       }       temp /= 10;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int n;     cin >> n;     bool vis[10];     for (int i = 0; i <= 9; i++) {       vis[i] = false;     }     long long int temp = n;     while (n > 0) {       int r = n % 10;       vis[r] = true;       n /= 10;     }     n = temp;     long long int cnt = 0;     for (long long int i = 1; i * i <= n; i++) {       if (n % i == 0) {         if (yes(i, n, vis)) {           cnt++;         }         if (i * i != n) {           if (yes(n / i, n, vis)) {             cnt++;           }         }       }     }     cout << cnt <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 14, M = 1 << N;   int n, p[M];   char s[N][N];   vector<long long> f[M][N];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %s , s[i]);     for (int i = 1; i < 1 << n; ++i) {       p[i] = p[i >> 1] + (i & 1);       for (int j = 0; j < n; ++j)         if (i >> j & 1) f[i][j].resize(1 << (p[i] - 1));     }     for (int i = 0; i < n; ++i) f[1 << i][i][0] = 1;     for (int i = 1; i < 1 << n; ++i)       for (int j = 0; j < n; ++j)         if (i >> j & 1)           for (int k = 0; k < n; ++k)             if (!(i >> k & 1)) {               int x = s[j][k] ==  1 , y = i | (1 << k), z = x << p[i] >> 1;               for (int t = 0; t < 1 << (p[i] - 1); ++t)                 f[y][k][t | z] += f[i][j][t];             }     for (int i = 0; i < 1 << n >> 1; ++i) {       long long x = 0;       for (int j = 0; j < n; ++j) x += f[(1 << n) - 1][j][i];       printf( %lld  , x);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   queue<int> que;   int n, k;   int main() {     while (cin >> n >> k) {       if (k == 0) {         cout << 1;         for (int i = 2; i < 2 * n + 1; i++) cout <<     << i;         cout << endl;         continue;       }       cout << k + 1;       for (int i = 1; i < 2 * n + 1; i++)         if (i != k + 1) que.push(i);       while (!que.empty()) {         cout <<     << que.front();         que.pop();       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int brr[100000];   int crr[100000];   int main() {     int n, l;     cin >> n >> l;     int flag = 0;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int j = 0; j < n; j++) cin >> brr[j];     for (int i = 0; i < n; i++) {       crr[arr[i]] = 1;     }     int s = arr[0];     int x;     int fans = 1;     int z = 1;     if ((l - arr[n - 1] - 1) + (arr[0] - 0 + 1) == brr[1] - brr[0]) {       s = arr[n - 1];       for (int i = 1; i < n; i++) {         int diff = brr[i] - brr[i - 1];         s = (diff + s) % l;         if (crr[s] == 0) {           fans = 0;           break;         }       }       if (fans == 1) flag = 1;     }     z = 1;     while (z < n && flag == 0) {       int f2 = 1;       int f3 = 1;       while (z < n) {         if (arr[z] - arr[z - 1] == brr[1] - brr[0]) {           f2 = 0;           break;         }         z++;       }       if (f2 == 0) {         s = arr[z - 1];         for (int i = 1; i < n && f3; i++) {           int diff = brr[i] - brr[i - 1];           s = (diff + s) % l;           if (crr[s] == 0) {             f3 = 0;             break;           }         }         if (f3) {           z = n;           flag = 1;         }       }       z++;     }     if (n == 1)       cout <<  YES ;     else if (flag == 1)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   int lcm(int a, int b) { return a * (b / gcd(a, b)); }   int cx[] = {-1, 1, 0, 0, 1, 1, -1, -1};   int cy[] = {0, 0, -1, 1, -1, 1, -1, 1};   bool is_possible(long long left, long long rigth) {     if (left <= rigth) return true;     return false;   }   int main() {     ios::sync_with_stdio(0);     int n;     long long l = -2 * 1000000000, number, r = 2 * 1000000000;     string option, answer;     cin >> n;     for (int i = (0), _b = ((n)-1); i <= _b; i++) {       cin >> option >> number >> answer;       if (option ==  >= ) {         if (answer ==  Y )           l = max(l, number);         else           r = min(r, number - 1);       } else if (option ==  <= ) {         if (answer ==  Y )           r = min(r, number);         else           l = max(l, number + 1);       } else if (option ==  > ) {         if (answer ==  Y )           l = max(l, number + 1);         else           r = min(r, number);       } else {         if (answer ==  Y )           r = min(r, number - 1);         else           l = max(l, number);       }       if (!is_possible(l, r)) {         cout <<  Impossible  << endl;         return 0;       }     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const long long INF = 0x3f3f3f3f3f3f3f3f;   const long long llinf = LLONG_MAX;   const int inf = INT_MAX;   const int nmax = 1e6 + 5;   const int mod = 1e9 + 7;   using namespace std;   int i, ans, x;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cerr.tie(0);     cout.tie(0);     cin >> s;     for (i = 0; i < s.size(); i++) {       if (s[i] ==  M )         x++;       else if (x)         ans = max(ans + 1, x);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100100];   bool c;   int main() {     cin >> n;     if (n == 1 || n == 2) {       cout << 0;       return 0;     }     for (int i = 1; i <= n; i++) cin >> a[i];     vector<int> cch;     vector<int> chh;     vector<int> aas;     aas.push_back(a[1]);     aas.push_back(a[2]);     aas.push_back(a[3]);     cch = aas;     sort(cch.begin(), cch.end());     chh = cch;     reverse(chh.begin(), chh.end());     if ((aas != cch) && (aas != chh)) {       cout << 3 << endl;       cout << 1 <<     << 2 <<     << 3;       return 0;     }     if (a[1] < a[2] || a[2] < a[3]) c = true;     if (a[1] == a[2] && a[2] == a[3]) {       int q = 4;       while (a[q] == a[3]) q++;       if (q == n) {         cout << 0;         return 0;       }       if (a[3] < a[q]) c = true;     }     for (int i = 4; i <= n; i++) {       if (((a[i] < a[i - 1]) && c) || ((a[i] > a[i - 1]) && (!c))) {         cout << 3 << endl << 1 <<     << i - 1 <<     << i;         return 0;       }     }     cout << 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, lst[3], mx[2];   long long ans, pos[300005];   char color;   inline char get() {     char in = getchar();     while (in !=  R  && in !=  G  && in !=  B ) {       in = getchar();     }     return in;   }   inline void did(int opt, int nowpos) {     if (lst[opt] != 0) {       ans += pos[nowpos] - pos[lst[opt]];       mx[opt] =           (mx[opt] > pos[nowpos] - pos[lst[opt]] ? mx[opt]                                                  : pos[nowpos] - pos[lst[opt]]);     }     lst[opt] = nowpos;   }   inline void did2(int nowpos) {     if (lst[2] != 0) {       ans += (0 < pos[nowpos] - pos[lst[2]] - mx[0] - mx[1]                   ? 0                   : pos[nowpos] - pos[lst[2]] - mx[0] - mx[1]);     }     lst[2] = nowpos;     mx[0] = 0;     mx[1] = 0;   }   int main() {     scanf( %d , &n);     for (register int i = 1; i <= n; i++) {       scanf( %d , &pos[i]);       color = get();       switch (color) {         case  R :           did(0, i);           break;         case  B :           did(1, i);           break;         case  G :           did(0, i);           did(1, i);           did2(i);           break;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   string s[6], S;   bool F;   int main() {     cin >> S;     for (int i = 1; i <= 5; ++i) cin >> s[i];     for (int i = 1; i <= 5; ++i)       if (s[i][0] == S[0] || s[i][1] == S[1]) F = 1;     puts(F ?  YES  :  NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX_A = 1e7;   const int N = 500000;   bool sieve[MX_A + 1];   pair<int, int> pr[MX_A + 1];   int a1[N], a2[N], arr[N];   void handleven(int i) {     int num = arr[i];     while (num % 2 == 0) num /= 2;     if (num != 1) {       a1[i] = 2;       a2[i] = num;     } else {       a1[i] = a2[i] = -1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     for (int i = 2; i <= MX_A; i++) {       if (sieve[i]) continue;       for (int j = i; j <= MX_A; j += i) {         if (!pr[j].second) {           if (!pr[j].first) {             pr[j].first = i;           } else {             pr[j].second = i;           }         }         sieve[j] = true;       }     }     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       int num = arr[i];       if (arr[i] % 2 == 0) {         while (num % 2 == 0) num /= 2;         if (num != 1) {           a1[i] = 2;           a2[i] = num;         } else {           a1[i] = a2[i] = -1;         }       } else if (pr[arr[i]].second) {         a1[i] = pr[arr[i]].first;         a2[i] = pr[arr[i]].second;       } else {         a1[i] = a2[i] = -1;       }     }     for (int i = 0; i < n; i++) {       cout << a1[i] <<    ;     }     cout <<   n ;     for (int i = 0; i < n; i++) {       cout << a2[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 2e9;   const int MOD = 1e9 + 7;   const double Pi = 3.141592653589793;   const int N = 3e5 + 5;   long long c[N], v[N], g[N], a[N], n, k, s, t, m = 0, mx = 0, mn = -1, res = OO;   bool check(long long cap) {     long long time = 0;     for (int i = (int)1; i <= (int)m; i++) {       if (a[i] > cap) return false;       long long y = max(0LL, min(a[i], cap - a[i])), x = a[i] - y;       time += 2LL * x + y;     }     return (time <= t);   }   int main() {     cin >> n >> k >> s >> t;     if (s > t) {       cout << -1;       return 0;     }     for (int i = (int)1; i <= (int)n; i++) scanf( %i%i , &v[i], &c[i]);     for (int i = (int)1; i <= (int)k; i++) scanf( %i , &g[i]);     g[++k] = s;     g[++k] = 0;     sort(g + 1, g + k + 1);     for (int i = (int)2; i <= (int)k; i++)       a[++m] = g[i] - g[i - 1], mx = max(mx, a[m]);     long long l = mx, r = s * 2, mid;     while (l <= r) {       mid = (l + r) >> 1;       if (check(mid))         mn = mid, r = mid - 1;       else         l = mid + 1;     }     for (int i = (int)1; i <= (int)n; i++)       if (c[i] >= mn) res = min(res, v[i]);     if (res == OO)       cout << -1;     else       cout << res;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   bool chkmax(T &x, T y) {     return x < y ? x = y, true : false;   }   template <typename T>   bool chkmin(T &x, T y) {     return x > y ? x = y, true : false;   }   int readint() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   const int cys = 998244353;   int n, k;   long long mod(long long x) { return x >= cys ? x - cys : x; }   namespace task1 {   long long d[2025][2025];   void work() {     d[0][0] = 1;     for (int i = 1; i <= n; i++) {       for (int j = 0; j <= n; j++) {         d[i][j] = d[i - 1][j];         if (j >= i) d[i][j] = mod(d[i][j] + d[i][j - i]);       }     }     long long ans = 0;     for (int i = 1; i <= n; i++) ans = mod(ans + d[n][i]);     printf( %lld n , ans);   }   }  // namespace task1   namespace task2 {   long long d[2025][2025], f[2025][2025];   void work() {     d[0][0] = 1;     for (int i = n; i >= 1; i--)       for (int j = 0; j <= n / i; j++)         for (int k = 0; k <= n; k++)           if (j && k >= i * j) d[j][k] = mod(d[j][k] + d[j - 1][k - i * j]);     long long ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= n; j++) ans = mod(ans + d[i][j]);     printf( %lld n , ans);   }   }  // namespace task2   namespace taskg3 {   vector<int> a;   map<vector<int>, bool> bk;   int ans;   bool check(vector<int> x) {     vector<int> tmp(0);     for (int i = 0; i < x.size(); i++)       for (int j = 0; j < x[i]; j++) tmp.push_back(i + 1);     int sum = 0;     for (int i = 0; i < tmp.size(); i++) sum += tmp[i] * (tmp.size() - i);     return sum <= n;   }   vector<int> getans(vector<int> x) {     sort(x.begin(), x.end());     int lst = 0;     vector<int> ret(0);     for (int i = 1; i < x.size(); i++)       if (x[i] != x[i - 1]) ret.push_back(i - lst), lst = i;     ret.push_back(x.size() - lst);     return ret;   }   bool dfs(int now, int sum) {     if (now >= 1) {       if (!check(a)) return 0;       vector<int> tmp = a;       for (int i = 1; i <= k - 3; i++) tmp = getans(tmp);       sort(tmp.begin(), tmp.end());       if (!bk.count(tmp)) bk[tmp] = 1, ans++;     }     int g = now ? a[now - 1] : 64;     for (int i = 1; i <= g && i <= 64 - sum; i++) {       a.push_back(i);       if (!dfs(now + 1, sum + i)) {         a.pop_back();         break;       }       a.pop_back();     }     return 1;   }   void work() {     ans = 0;     dfs(0, 0);     printf( %d n , ans);   }   }  // namespace taskg3   int main() {     n = readint();     k = readint();     if (k >= 20)       printf( 1 n );     else if (k == 1)       task1::work();     else if (k == 2)       task2::work();     else       taskg3::work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = INT_MAX;   void solve() {     long long n;     cin >> n;     vector<long long> a(n);     vector<long long> first(n, INF);     vector<long long> last(n, -INF);     for (long long i = 0; i < n; ++i) {       cin >> a[i];       --a[i];       first[a[i]] = min(first[a[i]], i);       last[a[i]] = max(last[a[i]], i);     }     sort(a.begin(), a.end());     a.erase(unique(a.begin(), a.end()), a.end());     long long now = 0;     long long mx = 0;     long long ans = 0;     n = a.size();     for (long long i = 0; i < n; ++i) {       if (i) {         if (first[a[i]] > mx)           ++now;         else           now = 1;         mx = last[a[i]];         ans = max(ans, now);       } else {         now = 1;         mx = max(mx, last[a[i]]);         ans = max(ans, now);       }     }     cout << a.size() - ans <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long q;     cin >> q;     while (q--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   int inf = 1e9;   int mod = 1e9 + 7;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     int L[n], R[n];     for (int i = 0; i < n; i++) cin >> L[i] >> R[i];     map<int, vector<int>> start, end;     set<int> line;     for (int i = 0; i < n; i++) {       start[L[i]].push_back(i);       end[R[i]].push_back(i);       line.insert(L[i]);       line.insert(R[i]);     }     set<int> s;     int prev = 0;     int dp[1 << 8];     map<int, int> order[2 * n + 1];     int cnt = 0;     int ans = 0;     memset(dp, 0, sizeof(dp));     for (int cur : line) {       for (int u : start[cur]) s.insert(u);       cnt++;       vector<int> val;       int e = 0;       for (int u : s) {         order[cnt][u] = e++;         val.push_back(u);       }       vector<int> temp(1 << 8, 0);       for (int i = 0; i < (1 << (int)val.size()); i++) {         int bit = 0;         int y = 0, z = 0;         for (int j = 0; j < (int)val.size(); j++) {           if ((i >> j) & 1) {             int x = val[j];             if (order[cnt - 1].find(x) != order[cnt - 1].end()) {               bit |= (1 << order[cnt - 1][x]);               y ^= 1;             }             z ^= 1;           }         }         temp[i] = dp[bit];         temp[i] += y * (cur - prev - 1);         temp[i] += z;         ans = max(ans, temp[i]);       }       vector<int> f, b;       for (int u : end[cur]) {         b.push_back(u);         s.erase(s.find(u));       }       for (int u : s) {         f.push_back(u);       }       memset(dp, 0, sizeof(dp));       for (int i = 0; i < (1 << (int)f.size()); i++) {         int bit = 0;         for (int k = 0; k < (int)f.size(); k++) {           if ((i >> k) & 1) {             bit |= (1 << order[cnt][f[k]]);           }         }         int x = bit;         for (int j = 0; j < (1 << (int)b.size()); j++) {           bit = x;           for (int k = 0; k < (int)b.size(); k++) {             if ((j >> k) & 1) {               bit |= (1 << order[cnt][b[k]]);             }           }           dp[x] = max(dp[x], temp[bit]);         }       }       prev = cur;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, len;   char p[1000];   int done[1000];   long long ans = 0;   long long p2[1000];   int main() {     int i, j;     scanf( %s , p);     p2[0] = 1;     for (i = 1; i <= 200; ++i) p2[i] = (p2[i - 1] * 2) % 1000000007;     len = strlen(p);     for (i = 0; i < len; ++i) done[i] = p[len - i - 1] -  0 ;     for (i = 0; i < len; ++i) {       ans = (ans * 2) % 1000000007;       if (done[i] == 1) ans = (ans + p2[i] * p2[i]) % 1000000007;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortbysec(const pair<int, bool> &a, const pair<int, bool> &b) {     return (a.first < b.first || (a.first == b.first && a.second < b.second));   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n;     cin >> n;     int res = n;     vector<pair<int, bool> > a(n);     for (int i = 0; i < n; i++) {       cin >> a[i].first;       a[i].second = 0;     }     sort(a.begin(), a.end());     vector<pair<int, bool> >::iterator it = a.begin();     for (int i = 0; i < a.size() - 1; i++) {       for (int j = i + 1; j < a.size(); j++) {         if (a[i].first < a[j].first && !a[j].second) {           a[j].second = 1;           res--;           break;         }       }     }     cout << res <<   n ;     return EXIT_SUCCESS;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<int> lott;   int main() {     long long int xm, find = 0;     cin >> xm;     lott.push(100);     lott.push(20);     lott.push(10);     lott.push(5);     lott.push(1);     while (xm) {       while (lott.top() <= xm) {         find++;         xm -= lott.top();       }       lott.pop();     }     cout << find << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long m[4], x, y, a;   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL), cout.tie(NULL);     for (long long i = 0; i < 10; ++i) {       cout << i << i << i << i << endl;       cin >> x >> y;       if (x == 1) m[a++] = i;     }     for (long long i = 0; i < 24; ++i) {       next_permutation(m, m + 4);       for (long long i = 0; i < 4; ++i) cout << m[i];       cout << endl;       cin >> x >> y;       if (x == 4) return cout << endl, 0;     }   }
#include <bits/stdc++.h>   using namespace std;   char str[200010];   int tim[200010];   int main() {     memset(tim, 0x3f, sizeof(tim));     int n, k;     scanf( %d %d , &n, &k);     scanf( %s , str);     for (int i = 0; i < n; i++)       if (str[i] == str[(i + 1) % n] || str[i] == str[(i - 1 + n) % n])         tim[i] = 0;     for (int i = 0; i < 2 * n; i++)       tim[i % n] = min(tim[i % n], tim[(i - 1 + n) % n] + 1);     for (int i = 2 * n - 1; i >= 0; i--)       tim[i % n] = min(tim[i % n], tim[(i + 1) % n] + 1);     for (int i = 0; i < n; i++)       if (min(tim[i], k) & 1)         printf( %c ,  W  +  B  - str[i]);       else         printf( %c , str[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s1, s2, virus;   pair<int, int> dp[105][105][105];   int l1, l2, lvirus;   string ans =   ;   int pi[105];   void pf(string s) {     memset(pi, 0, sizeof(pi));     int n = (int)s.length();     for (int i = 1; i < n; ++i) {       int j = pi[i - 1];       while (j > 0 && s[i] != s[j]) j = pi[j - 1];       if (s[i] == s[j]) ++j;       pi[i] = j;     }   }   int main() {     cin >> s1 >> s2 >> virus;     l1 = s1.length();     l2 = s2.length();     lvirus = virus.length();     int i, j, k;     for (i = 1; i <= l1; i++) {       for (j = 1; j <= l2; j++) {         for (k = 0; k < lvirus; k++) {           if (dp[i][j][k].first <= dp[i - 1][j][k].first) {             dp[i][j][k].first = dp[i - 1][j][k].first;             dp[i][j][k].second = 1;           }           if (dp[i][j][k].first <= dp[i][j - 1][k].first) {             dp[i][j][k].first = dp[i][j - 1][k].first;             dp[i][j][k].second = 2;           }           if (s1[i - 1] == s2[j - 1]) {             if (k != 0 && s1[i - 1] == virus[k - 1]) {               if (dp[i][j][k].first < dp[i - 1][j - 1][k - 1].first + 1) {                 dp[i][j][k].first = dp[i - 1][j - 1][k - 1].first + 1;                 dp[i][j][k].second = 3;               }             }             int z = k;             if (s1[i - 1] != virus[z]) {               char c = virus[z];               virus[z] = s1[i - 1];               pf(virus);               int v = pi[z];               if (dp[i][j][v].first < dp[i - 1][j - 1][z].first + 1) {                 dp[i][j][v].first = dp[i - 1][j - 1][z].first + 1;                 dp[i][j][v].second = 10 + z;               }               virus[z] = c;             }           }         }       }     }     int mx = 0, cur = -1;     for (i = 0; i < lvirus; i++) {       if (mx <= dp[l1][l2][i].first) {         cur = i;         mx = dp[l1][l2][i].first;       }     }     if (mx == 0) {       cout << 0;       return 0;     }     i = l1;     j = l2;     while (i != 0 && j != 0) {       if (dp[i][j][cur].second == 1) {         i--;         continue;       }       if (dp[i][j][cur].second == 2) {         j--;         continue;       }       if (dp[i][j][cur].second == 3) {         ans = s1[i - 1] + ans;         i--;         j--;         cur--;         continue;       }       ans = s1[i - 1] + ans;       cur = dp[i][j][cur].second - 10;       i--;       j--;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, i;     cin >> n >> k;     if (k == 1 || k == n) {       cout << 3 * n << endl;       return 0;     } else {       int sum = 0;       if (k & 1) {         if (k >= n / 2 + 1) {           k = n - k + 1;         }       } else {         if (k > n / 2) {           k = n - k + 1;         }       }       int cnt = 0;       for (i = k; i >= 1; i--) {         if (cnt == 1) {           sum += 4;         } else {           sum += 3;         }         cnt++;       }       sum--;       sum += k;       for (i = k + 1; i <= n; i++) {         sum += 3;       }       sum--;       cout << sum << endl;     }     return 0;   }