malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct city_t : array<bitset<99>, 4> {     int n, k, m, p;     city_t() { cin >> n >> k, m = n / 2, p = n - 2; }     void hotel(int i, int j) {       if (!(*this)[i][j] && k > 0) (*this)[i][j] = true, k--;     }     void solve() {       if (k % 2) hotel(1, m);       for (int i = 1; i < 3 && k > 0; i++)         for (int u = 1, v = p; v > u && k > 0; u++, v--) hotel(i, u), hotel(i, v);       hotel(1, m), hotel(2, m);     }     void write() {       cout <<  YES ;       for (int i = 0; i < 4; i++) {         cout <<   n ;         for (int j = 0; j < n; j++)           if ((*this)[i][j])             cout <<  # ;           else             cout <<  . ;       }     }   };   int main() {     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     city_t city;     city.solve(), city.write();   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k, x, y, z;   int main() {     cin >> n >> k >> m;     if (m <= k)       cout << m << endl;     else if (m <= n)       cout << k << endl;     else {       long long tmp = n + k;       cout << tmp - m << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> E[3010];   int mark[3010];   int c, f;   bool find(int i, int p) {     if (mark[i] == 1) {       c = i;       f = 1;       return true;     }     mark[i] = 1;     for (vector<int>::iterator to = E[i].begin(); to < E[i].end(); to++) {       if (*to != p && find(*to, i)) {         if (f) mark[i] = 2;         if (i == c) f = 0;         return true;       }     }     return false;   }   int ans[3010];   void bfs(int i) {     queue<int> v;     v.push(i);     while (!v.empty()) {       int to = v.front();       v.pop();       for (vector<int>::iterator at = E[to].begin(); at < E[to].end(); at++) {         if (ans[*at] > ans[to] + 1) {           ans[*at] = ans[to] + 1;           v.push(*at);         }       }     }   }   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       E[a].push_back(b);       E[b].push_back(a);     }     find(0, -1);     for (int i = 0; i < 3010; i++) ans[i] = 10000000;     for (int i = 0; i < n; i++)       if (mark[i] == 2) {         ans[i] = 0;         bfs(i);       }     for (int i = 0; i < n; i++) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int n, k;     std::cin >> n >> k;     int64_t s1 = 0;     int s2 = 0;     for (int i = 0; i < k; ++i) {       int a, b;       std::cin >> a >> b;       s1 += b;       s2 = (s2 + 1ll * a * b) % n;     }     if (s1 > n) {       std::cout << -1 <<   n ;     } else if (s1 < n) {       std::cout << 1 <<   n ;     } else if (1ll * n * (n - 1) / 2 % n == s2) {       std::cout << 1 <<   n ;     } else {       std::cout << -1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> a(26), a2(26), a3(26);     string s1, s2, s3;     char ss1[100001], ss2[100001], ss3[100001];     scanf( %s%s%s , ss1, ss2, ss3);     s1 = ss1;     s2 = ss2;     s3 = ss3;     for (int i = 0; i < s1.size(); i++) a[s1[i] -  a ]++;     for (int i = 0; i < s2.size(); i++) a2[s2[i] -  a ]++;     for (int i = 0; i < s3.size(); i++) a3[s3[i] -  a ]++;     int max1 = 0, max2 = 0;     int ma2 = 100000;     for (int i = 0; i < 26; i++)       if (a2[i]) ma2 = min(ma2, a[i] / a2[i]);     for (int i = 0; i <= ma2; i++) {       int r = 100000;       for (int j = 0; j < 26; j++)         if (a3[j]) r = min(r, (a[j] - i * a2[j]) / a3[j]);       if (r + i > max1 + max2) max1 = i, max2 = r;     }     for (int i = 0; i < max1; i++) printf( %s , ss2);     for (int i = 0; i < max2; i++) printf( %s , ss3);     for (int i = 0; i < 26; i++) a[i] -= (a2[i] * max1 + a3[i] * max2);     for (int i = 0; i < 26; i++) {       while (a[i] > 0) {         printf( %c , i +  a );         a[i]--;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 501;   int dp[N][N][2];   char a[N][N];   const int MOD = 1e9 + 7;   void add(int &a, int b) {     a += b;     if (a >= MOD) a -= MOD;     if (a < 0) a += MOD;   }   int mul(int a, int b) { return (long long)a * b % MOD; }   int power(int a, int b) {     int ans = 1;     while (b > 0) {       if (b & 1) ans = mul(ans, a);       a = mul(a, a);       b >>= 1;     }     return ans;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> (a[i] + 1);     }     for (int x2 = 1; x2 <= n; x2++) {       for (int x1 = n; x1 >= 1; x1--) {         for (int y1 = m; y1 >= 1; y1--) {           int x2cc = x2 % 2;           int y2 = n + m - x2 - x1 - y1 + 2;           dp[x1][y1][x2cc] = 0;           if (x1 > x2 || y1 > y2) continue;           if (y2 < 1 || y2 > m) continue;           if (x1 == x2 && y1 == y2) {             dp[x1][y1][x2cc] = 1;             continue;           }           if ((x2 == x1 + 1 && y1 == y2) || (x1 == x2 && y2 == y1 + 1))             if (a[x1][y1] == a[x2][y2]) {               dp[x1][y1][x2cc] = 1;               continue;             }           if (x1 < n) {             if (x2 > 1)               if (a[x1 + 1][y1] == a[x2 - 1][y2])                 add(dp[x1][y1][x2cc], dp[x1 + 1][y1][!x2cc]);             if (y2 > 1)               if (a[x1 + 1][y1] == a[x2][y2 - 1])                 add(dp[x1][y1][x2cc], dp[x1 + 1][y1][x2cc]);           }           if (y1 < m) {             if (x2 > 1)               if (a[x1][y1 + 1] == a[x2 - 1][y2])                 add(dp[x1][y1][x2cc], dp[x1][y1 + 1][!x2cc]);             if (y2 > 1)               if (a[x1][y1 + 1] == a[x2][y2 - 1])                 add(dp[x1][y1][x2cc], dp[x1][y1 + 1][x2cc]);           }         }       }     }     if (a[1][1] != a[n][m]) dp[1][1][n % 2] = 0;     cout << dp[1][1][n % 2] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, x, y, good, bad;     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &n, &x, &y);       bad = min(n, x + y - 1);       if (x + y <= n)         good = 1;       else         good = min(n, x + y - n + 1);       printf( %d %d n , good, bad);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int gcd(long long int a, long long int b) {     return b ? gcd(b, a % b) : a;   }   long long int lcm(long long int a, long long int b) {     return a * b / gcd(a, b);   }   int n, m, cnt[11][11], a[22], b[22], tr[11], mx;   void bktk(int i) {     if (i == n + 1) {       int ans = 0;       memset(cnt, 0, sizeof(cnt));       for (int j = 1; j <= m; j++)         cnt[min(tr[a[j]], tr[b[j]])][max(tr[b[j]], tr[a[j]])]++;       for (int j = 1; j <= 6; j++)         for (int k = 1; k <= 6; k++)           if (cnt[j][k]) ans++;       mx = max(ans, mx);       return;     }     for (int j = 1; j <= 6; j++) {       tr[i] = j;       bktk(i + 1);     }   }   int main() {     cin >> n >> m;     if (n < 7) {       cout << m << endl;       return 0;     }     for (int i = 1; i <= m; i++) cin >> a[i] >> b[i];     bktk(1);     cout << mx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long q;     cin >> q;     if (q == 1) {       cout <<  1 n0 n ;       return 0;     }     long long a = -1, b = -1;     for (long long d = 2; d * d <= q; d++) {       if (q % d) continue;       a = d;       b = q / d;       break;     }     if (a == -1) {       cout <<  1 n0 n ;       return 0;     }     for (long long d = 2; d * d <= b; d++) {       if (b % d) continue;       cout <<  1 n  << a * d <<   n ;       return 0;     }     cout <<  2 n ;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 5e5 + 10;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000000006;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 2000;   long long n, k, ans;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     ans = 1;     for (int i = 2; i <= k; ++i) ans = (ans * k) % MOD;     n -= k;     for (int i = 1; i <= n; ++i) ans = (ans * n) % MOD;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void main0();   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     main0();     return 0;   }   const int dx[8] = {0, 1, -1, 0, 1, 1, -1, -1};   const int dy[8] = {1, 0, 0, -1, 1, -1, -1, 1};   const int N = 2e3 + 1;   const int INF = 0x3f3f3f3f;   const long long INFF = 0x3f3f3f3f3f3f3f3f;   const int mod = 998244353;   const double eps = 1e-6;   const double Pi = acos(-1.0);   mt19937 rnd(       (unsigned int)chrono::steady_clock::now().time_since_epoch().count());   int n, m;   char a[N][N];   int ans[N][N];   int vis[N][N], step;   int incyc, cyclen;   pair<int, int> cycp;   void dfs(int x, int y) {     vis[x][y] = ++step;     int xt = x;     int yt = y;     if (a[x][y] ==  U )       xt--;     else if (a[x][y] ==  D )       xt++;     else if (a[x][y] ==  L )       yt--;     else       yt++;     if ((1 > xt) || (xt > n) || (1 > yt) || (yt > m)) {       vis[x][y] = 0;       ans[x][y] = 1;       return;     }     if (vis[xt][yt]) {       incyc = 1;       cyclen = vis[x][y] - vis[xt][yt] + 1;       vis[xt][yt] = 0;       vis[x][y] = 0;       ans[x][y] = cyclen;       return;     }     if (ans[xt][yt] == 0) {       dfs(xt, yt);     }     if (incyc)       ans[x][y] = cyclen;     else       ans[x][y] = ans[xt][yt] + 1;     if (vis[x][y] == 0) incyc = 0;     vis[x][y] = 0;   }   void main0() {     int T;     cin >> T;     while (T--) {       cin >> n >> m;       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           ans[i][j] = vis[i][j] = 0;         }       }       for (int i = 1; i <= n; ++i) {         cin >> a[i] + 1;       }       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           if (ans[i][j]) continue;           step = 0;           dfs(i, j);         }       }       pair<int, int> pos = {1, 1};       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           if (ans[i][j] > ans[pos.first][pos.second]) pos = {i, j};         }       }       cout << pos.first <<     << pos.second <<     << ans[pos.first][pos.second]            << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = int(1e5 + 5);   vector<int> g[N];   int cnt[N];   void dfs(int v, int depth = 0) {     cnt[depth]++;     for (int to : g[v]) {       dfs(to, depth + 1);     }   }   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     for (int i = 2; i <= n; i++) {       int p;       cin >> p;       g[p].push_back(i);     }     dfs(1);     int res = 0;     for (int i = 0; i <= n; i++) {       res += cnt[i] % 2;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[110000], add[110000];   int n, m, a, cnt, me;   char temp[3];   int main() {     while (~scanf( %d%d , &n, &m)) {       for (int i = 1; i <= n; i++) ans[i] = 1, add[i] = 0;       ;       cnt = 0;       me = 0;       for (int i = 1; i <= m; i++) {         scanf( %s%d , temp, &a);         if (*temp ==  + ) {           if (!me || (me == a))             me = a;           else             ans[a] = 0;           add[a] = 1;           if (a != me && !add[me]) ans[me] = 0;           cnt++;         } else {           if (!me) me = a;           if (a != me && add[a] == 0) {             ans[me] = 0;             me = a;           }           if (add[a]) {             add[a] = 0;             cnt--;           }           if (cnt) ans[a] = 0;         }       }       int tt = 0;       bool fi = true;       for (int i = 1; i <= n; i++)         if (ans[i]) tt++;       printf( %d n , tt);       for (int i = 1; i <= n; i++) {         if (ans[i]) {           if (!fi) printf(   );           printf( %d , i);           if (fi) fi = false;         }       }       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string str[1009];     int n, m;     while (cin >> n >> m) {       for (int i = 0; i < n; i++) cin >> str[i];       int ret = 0, cury = 0;       for (int i = 0; i < n; i++) {         int right = cury;         if (i % 2 == 0) {           for (int j = 0; j < m; j++)             if (str[i][j] ==  W ) right = j;           int right1 = cury;           if (i < n - 1)             for (int j = 0; j < m; j++)               if (str[i + 1][j] ==  W ) right1 = j;           right = max(right, right1);           ret += (right - cury);           cury = right;         } else {           int left = cury, left1 = cury;           for (int j = m - 1; j >= 0; j--)             if (str[i][j] ==  W ) left = j;           if (i < n - 1)             for (int j = m - 1; j >= 0; j--)               if (str[i + 1][j] ==  W ) left1 = j;           left = min(left, left1);           ret += (cury - left);           cury = left;         }       }       int row = 0;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++)           if (str[i][j] ==  W ) row = i;       ret += row;       cout << ret << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dis[3];   int n;   int main() {     scanf( %d , &n);     scanf( %d %d %d , &dis[0], &dis[1], &dis[2]);     int ans = 0;     n--;     int idx = 0;     while (n--) {       if (dis[idx] < dis[(idx + 1) % 3]) {         ans += dis[idx];         idx = (idx + 2) % 3;       } else {         ans += dis[(idx + 1) % 3];         idx = (idx + 1) % 3;       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int maxl = 1000 * 100 + 5;   int n, k;   string s;   int dis[30][maxl];   int main() {     cin >> n >> k >> s;     memset(dis, -1, sizeof dis);     for (int i = 0; i < 27; i++) {       queue<int> q;       for (int j = 0; j < k; j++)         if (s[j] == (char)(i +  a )) {           q.push(j);           dis[i][j] = 0;         }       while (!q.empty()) {         int index = q.front();         q.pop();         if (index != 0)           if (dis[i][index - 1] == -1) {             dis[i][index - 1] = dis[i][index] + 1;             q.push(index - 1);           }         if (index != maxl - 1)           if (dis[i][index + 1] == -1) {             dis[i][index + 1] = dis[i][index] + 1;             q.push(index + 1);           }       }     }     for (int j = 0; j < n; j++) {       string tmp;       cin >> tmp;       long long int ans = 0;       for (int i = 0; i < tmp.size(); i++)         ans += (dis[tmp[i] -  a ][i] == -1 ? tmp.size() : dis[tmp[i] -  a ][i]);       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       string s(200,  a );       cout << s << endl;       for (int i = 0; i < n; i++) {         int u;         cin >> u;         s[u] = s[u] ==  a  ?  b  :  a ;         cout << s << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<long long>> gr;   vector<bool> used;   vector<long long> tin, up;   const long long Nmax = 400000;   long long p[Nmax];   long long sz[Nmax];   long long timer = 0;   long long diametr(long long u, vector<vector<long long>> gr) {     queue<long long> q;     long long n = (long long)(gr.size());     vector<long long> h(n + 1, -1);     q.push(u);     h[u] = 0;     long long ml = u;     while (!q.empty()) {       long long v = q.front();       q.pop();       for (long long x : gr[v]) {         if (h[x] == -1) {           h[x] = h[v] + 1;           if (h[x] > h[ml]) ml = x;           q.push(x);         }       }     }     vector<long long> prev(n + 1, -1);     h.assign(n + 1, -1);     q.push(ml);     h[ml] = 0;     long long ms = ml;     prev[ml] = ml;     while (!q.empty()) {       long long v = q.front();       q.pop();       for (long long x : gr[v]) {         if (prev[x] == -1) {           h[x] = h[v] + 1;           prev[x] = v;           if (h[x] > h[ms]) ms = x;           q.push(x);         }       }     }     vector<long long> res;     while (prev[ms] != ms) {       res.push_back(ms);       ms = prev[ms];     }     res.push_back(ms);     reverse((res).begin(), (res).end());     return (long long)(res.size()) - 1;   }   long long find(long long x) {     if (p[x] != x) {       p[x] = find(p[x]);     }     return p[x];   }   void merge(long long x, long long y) {     x = find(x);     y = find(y);     p[y] = x;   }   void restart(long long N) {     for (long long i = 0; i < N; ++i) {       sz[i] = 1;       p[i] = i;     }   }   vector<pair<long long, long long>> most;   void dfs(long long u, long long p) {     used[u] = true;     tin[u] = timer++;     up[u] = tin[u];     for (long long v : gr[u]) {       if (used[v] && v != p) up[u] = min(up[u], tin[v]);       if (!used[v]) {         dfs(v, u);         up[u] = min(up[u], up[v]);         if (tin[u] < up[v]) {           most.emplace_back(u, v);         } else {           merge(u, v);         }       }     }   }   void solve() {     long long n, m;     cin >> n >> m;     gr.resize(n);     tin.assign(n, 0);     up.assign(n, 0);     used.assign(n, 0);     restart(n);     for (long long i = (0); i < (m); ++i) {       long long u, v;       cin >> u >> v;       u--;       --v;       gr[u].push_back(v);       gr[v].push_back(u);     }     dfs(0, -1);     vector<vector<long long>> gr2(n);     if (most.empty()) {       cout << 0;       return;     }     for (long long i = (0); i < ((long long)(most.size())); ++i) {       long long u = most[i].first, v = most[i].second;       u = find(u);       v = find(v);       gr2[u].push_back(v);       gr2[v].push_back(u);     }     long long v = most[0].first;     v = find(v);     cout << diametr(v, gr2);   }   signed main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   using ll = long long;   using vi = vector<int>;   using pii = pair<int, int>;   const int MX = 1e5 + 10;   template <typename T>   istream &operator>>(istream &is, vector<T> &v) {     for (auto i = begin(v); i != end(v); i++) is >> *i;     return is;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     for (auto i = begin(v); i != end(v); i++)       os << *i << (i == end(v) - 1 ?   n  :    );     return os;   }   template <typename T>   inline void rd(T &s) {     s = 0;     T t = 1, k = getchar();     for (; k <  0  || k >  9 ; k = getchar())       if (k ==  - ) t = -1;     for (; k >=  0  && k <=  9 ; k = getchar())       s = (s << 1) + (s << 3) + (k ^ 48);     s *= t;   }   ll n, m, t;   char a[1111][1111];   ll b[1111][1111];   ll dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};   void solve() {     cin >> n >> m >> t;     for (register ll i = 1, ilen = (ll)(n); i <= ilen; ++i) cin >> (a[i] + 1);     queue<pii> q;     for (register ll i = 1, ilen = (ll)(n); i <= ilen; ++i)       for (register ll j = 1, jlen = (ll)(m); j <= jlen; ++j) {         if (a[i][j] == a[i + 1][j] || a[i][j] == a[i - 1][j] ||             a[i][j] == a[i][j + 1] || a[i][j] == a[i][j - 1])           b[i][j] = 1, q.push(make_pair(i, j));         else           b[i][j] = 2e18;       }     while (q.size()) {       ll x = q.front().first, y = q.front().second;       q.pop();       for (register ll i = 0, ilen = (ll)(4); i < ilen; ++i) {         ll nx = x + dx[i], ny = y + dy[i];         if (nx >= 1 && nx <= n && ny >= 1 && ny <= m) {           if (b[x][y] + 1 < b[nx][ny]) q.push(make_pair(nx, ny));           b[nx][ny] = min(b[nx][ny], b[x][y] + 1);         }       }     }     while (t--) {       ll x, y, p;       cin >> x >> y >> p;       if (p >= b[x][y] && (p - b[x][y]) % 2 == 0) {         if (a[x][y] ==  1 )           cout <<  0  <<   n ;         else           cout <<  1  <<   n ;       } else         cout << a[x][y] <<   n ;     }   }   signed main() {     ll T = 1;     while (T--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = (int)1e6 + 5;   void compute() {     int n, m;     scanf( %d %d , &n, &m);     vector<int> v(n);     for (int i = 0; i < n; ++i) scanf( %d , &v[i]);     vector<pair<int, int> > seg(m);     vector<vector<int> > lf(n), rg(n);     for (int i = 0; i < m; ++i) {       scanf( %d%d , &seg[i].first, &seg[i].second);       --seg[i].first;       --seg[i].second;       lf[seg[i].second].push_back(seg[i].first);       rg[seg[i].first].push_back(seg[i].second);     }     vector<int> add(n, 0);     vector<int> ansv(n, -inf);     int mn = v[0];     for (int i = 0; i < n; ++i) {       ansv[i] = max(ansv[i], v[i] - mn);       for (auto l : lf[i]) {         for (int j = l; j <= i; ++j) {           --add[j];           mn = min(mn, v[j] + add[j]);         }       }       mn = min(mn, v[i] + add[i]);     }     add = vector<int>(n, 0);     mn = v[n - 1];     for (int i = n - 1; i >= 0; --i) {       ansv[i] = max(ansv[i], v[i] - mn);       for (auto r : rg[i]) {         for (int j = i; j <= r; ++j) {           --add[j];           mn = min(mn, v[j] + add[j]);         }       }       mn = min(mn, v[i] + add[i]);     }     int res = *max_element(ansv.begin(), ansv.end());     vector<int> res2;     for (int i = 0; i < n; ++i) {       if (ansv[i] == res) {         for (int j = 0; j < m; ++j) {           if (!(seg[j].first <= i && seg[j].second >= i)) res2.push_back(j + 1);         }         break;       }     }     printf( %d n%d n , res, (int)res2.size());     for (auto i : res2) printf( %d  , i);     printf(  n );   }   int main() {     compute();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k;     bool odd = false, even = false;     cin >> n >> k;     if (n & 1) {       if (k > (n / 2 + 1)) {         even = true;         k -= (n / 2 + 1);       } else         odd = true;     } else {       if (k > n / 2) {         even = true;         k -= (n / 2);       } else         odd = true;     }     if (odd)       cout << 2 * k - 1 << endl;     else       cout << 2 * k << endl;     return 0;   }