malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct node {     bool visited;     short prex;     short prey;     short val;     node() { visited = false; }     void print() {       cout << visited <<   (  << prex <<  ,   << prey <<  )   << val << endl;     }   };   struct coord {     int x, y;     coord(int x, int y) {       this->x = x;       this->y = y;     }   };   class SpecialNum {    public:     SpecialNum(int d, int s) {       this->d = d;       this->s = s;       init();     }     bool get() { return get(0, s); }     bool get(int x, int y);       private:     int d, s;     node** table = 0;     void init() {       table = new node*[d];       for (int i = 0; i < d; i++) table[i] = new node[s + 1];       bfs();     }     void bfs();   };   void SpecialNum::bfs() {     queue<coord> que;     int nextx = 0, nexty = 0;     que.push(coord(0, 0));     while (!que.empty()) {       coord cur = que.front();       que.pop();       for (int i = 0; i < 10; i++) {         nextx = (10 * cur.x + i) % d;         nexty = cur.y + i;         if (table[nextx][nexty].visited || nexty > s) continue;         table[nextx][nexty].visited = true;         table[nextx][nexty].prex = cur.x;         table[nextx][nexty].prey = cur.y;         table[nextx][nexty].val = i;         que.push(coord(nextx, nexty));       }     }   }   bool SpecialNum::get(int x, int y) {     if (!table[x][y].visited || (x == 0 && y == 0)) return false;     get(table[x][y].prex, table[x][y].prey);     cout << table[x][y].val;     return true;   }   int main() {     int d, s;     cin >> d >> s;     SpecialNum* sn = new SpecialNum(d, s);     if (!sn->get()) cout << -1;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n;   void chis(int x) {     switch (x) {       case 0:         cout <<  zero  << endl;         break;       case 1:         cout <<  one  << endl;         break;       case 2:         cout <<  two  << endl;         break;       case 3:         cout <<  three  << endl;         break;       case 4:         cout <<  four  << endl;         break;       case 5:         cout <<  five  << endl;         break;       case 6:         cout <<  six  << endl;         break;       case 7:         cout <<  seven  << endl;         break;       case 8:         cout <<  eight  << endl;         break;       case 9:         cout <<  nine  << endl;         break;     }   }   void chis2(int x) {     switch (x) {       case 2:         cout <<  twenty ;         break;       case 3:         cout <<  thirty ;         break;       case 4:         cout <<  forty ;         break;       case 5:         cout <<  fifty ;         break;       case 6:         cout <<  sixty ;         break;       case 7:         cout <<  seventy ;         break;       case 8:         cout <<  eighty ;         break;       case 9:         cout <<  ninety ;         break;     }   }   void chis3(int x) {     switch (x) {       case 10:         cout <<  ten  << endl;         break;       case 11:         cout <<  eleven  << endl;         break;       case 12:         cout <<  twelve  << endl;         break;       case 13:         cout <<  thirteen  << endl;         break;       case 14:         cout <<  fourteen  << endl;         break;       case 15:         cout <<  fifteen  << endl;         break;       case 16:         cout <<  sixteen  << endl;         break;       case 17:         cout <<  seventeen  << endl;         break;       case 18:         cout <<  eighteen  << endl;         break;       case 19:         cout <<  nineteen  << endl;         break;     }   }   void read() {     cin >> n;     if (n <= 9)       chis(n);     else {       int des = n / 10;       if (des == 1)         chis3(n);       else {         chis2(des);         int ost = n % 10;         if (ost == 0)           cout << endl;         else {           cout <<  - ;           chis(ost);         }       }     }   }   int main() {     read();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     if (n == 1)       cout <<  1 ;     else if (n <= 5 && n != 3)       cout <<  3 ;     else if (n <= 13)       cout <<  5 ;     else if (n <= 25)       cout <<  7 ;     else if (n <= 41)       cout <<  9 ;     else if (n <= 61)       cout <<  11 ;     else if (n <= 85)       cout <<  13 ;     else       cout <<  15 ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x, y, a, b;     cout <<  YES n ;     cin >> n;     while (n--) {       cin >> x >> y >> a >> b;       cout << (abs(2 * (x % 2)) + abs(y % 2)) + 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a, b, ms[111][111], d[111], w[111], dd[111];   double f[111], ff[111], ans;   int main() {     cin >> n >> m;     memset(ms, 63, sizeof(ms));     for (int i = 0; i < m; i++) {       cin >> a >> b;       a--;       b--;       ms[a][b] = ms[b][a] = 1;     }     memset(d, 63, sizeof(d));     d[0] = 0;     f[0] = 1;     memset(w, 0, sizeof(w));     for (int i = 0; i < n; i++) {       int o = 1e9, l;       for (int i = 0; i < n; i++)         if (!w[i] && d[i] < o) o = d[i], l = i;       w[l] = 1;       for (int i = 0; i < n; i++)         if (o + ms[l][i] < d[i]) {           d[i] = o + ms[l][i];           f[i] = f[l];         } else if (o + ms[l][i] == d[i])           f[i] += f[l];     }     memset(dd, 63, sizeof(dd));     dd[n - 1] = 0;     ff[n - 1] = 1;     memset(w, 0, sizeof(w));     for (int i = 0; i < n; i++) {       int o = 1e9, l;       for (int i = 0; i < n; i++)         if (!w[i] && dd[i] < o) o = dd[i], l = i;       w[l] = 1;       for (int i = 0; i < n; i++)         if (o + ms[l][i] < dd[i]) {           dd[i] = o + ms[l][i];           ff[i] = ff[l];         } else if (o + ms[l][i] == dd[i])           ff[i] += ff[l];     }     for (int i = 0; i < n; i++) {       double o = 0;       for (int j = 0; j < n; j++)         if (ms[i][j] == 1) {           if (d[i] + 1 + dd[j] == d[n - 1]) o += f[i] * ff[j];           if (dd[i] + 1 + d[j] == d[n - 1]) o += ff[i] * f[j];         }       ans = max(ans, o);     }     printf( %.10lf n , ans / f[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e3;   int a[N];   int main() {     int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + 1 + n);     cout << a[n - k + 1];   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 77, Mod = 1e9 + 7;   int n, d1[N], d2[N], P1, P2, Mx, deg[N], p1[N], p2[N];   long long A;   vector<pair<int, pair<int, int> > > R;   vector<int> a[N];   void dfs(int v, int prev, bool t) {     for (int u : a[v]) {       if (u == prev) {         continue;       }       if (t) {         d1[u] = d1[v] + 1;         p1[u] = v;       } else {         d2[u] = d2[v] + 1;         p2[u] = v;       }       dfs(u, v, t);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; i++) {       int v, u;       scanf( %d %d , &v, &u);       deg[v]++;       deg[u]++;       a[v].push_back(u);       a[u].push_back(v);     }     dfs(1, 1, 1);     for (int i = 1; i <= n; i++) {       if (d1[i] > Mx) {         Mx = d1[i];         P1 = i;       }     }     d1[P1] = 0;     dfs(P1, P1, 1);     Mx = 0;     for (int i = 1; i <= n; i++) {       if (d1[i] > Mx) {         Mx = d1[i];         P2 = i;       }     }     dfs(P2, P2, 0);     vector<int> Leaves;     for (int i = 1; i <= n; i++) {       if (i == P1 || i == P2 || deg[i] > 1) continue;       Leaves.push_back(i);     }     while (Leaves.size()) {       int v = Leaves.back();       Leaves.pop_back();       if (d1[v] >= d2[v]) {         A += d1[v];         R.push_back(make_pair(v, make_pair(P1, v)));       } else {         A += d2[v];         R.push_back(make_pair(v, make_pair(P2, v)));       }       deg[v]--;       for (int u : a[v]) {         deg[u]--;         if (deg[u] == 1) Leaves.push_back(u);       }     }     while (p2[P1]) {       R.push_back(make_pair(P1, make_pair(P2, P1)));       A += d2[P1];       P1 = p2[P1];     }     printf( %I64d n , A);     for (auto x : R)       printf( %d %d %d n , x.first, x.second.first, x.second.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int a, b, c;     cin >> a >> b >> c;     long int temp = b - a;     if (c == 0 || b == a) {       if (b == a)         cout <<  YES ;       else         cout <<  NO ;     } else if (temp % c == 0) {       if ((temp < 0 && c < 0) || (temp > 0 && c > 0))         cout <<  YES ;       else         cout <<  NO ;     } else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long i, j, k, m, n, t, x;   string s, u;   int main() {     for (scanf( %lld , &t); t--;) {       i = 1;       cin >> x >> s;       for (; s.size() < x; i++) {         if (s[i - 1] > 49) {           u = s.substr(i);           for (k = s[i - 1] - 48; --k;) s += u;         }       }       m = s.size();       for (; i <= x; i++)         m = (m + (s[i - 1] - 49) * (m - i + 1000000007)) % 1000000007;       cout << m << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = acos(-1.0);   template <typename T>   T abs(T x) {     return x > 0 ? x : -x;   }   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   bool chmin(T &x, T y) {     if (x > y) {       x = y;       return true;     }     return false;   }   template <typename T>   bool chmax(T &x, T y) {     if (x < y) {       x = y;       return true;     }     return false;   }   template <typename U, typename V>   ostream &operator<<(ostream &s, const pair<U, V> &x) {     s <<  (  << x.fst <<  ,   << x.snd <<  ) ;     return s;   }   template <typename U>   ostream &operator<<(ostream &s, const vector<U> &x) {     s <<  [ ;     bool was = false;     for (auto it : x) {       if (was) {         s <<  ,  ;       }       was = true;       s << it;     }     s <<  ] ;     return s;   }   template <typename U>   ostream &operator<<(ostream &s, const set<U> &x) {     s <<  { ;     bool was = false;     for (auto it : x) {       if (was) {         s <<  ,  ;       }       was = true;       s << it;     }     s <<  } ;     return s;   }   template <int sz>   ostream &operator<<(ostream &s, const bitset<sz> &x) {     for (int i = 0; i < sz; i++) {       s << x[i];     }     return s;   }   int main() {     srand(time(0));     int k;     cin >> k;     int maxi = 25;     while (k--) {       int p;       cin >> p;       chmax(maxi, p);     }     cout << maxi - 25 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, A, cf, cm, m;   long long L, ans[100005], f, ansA, ansL;   long long s[100005];   struct data {     long long id, v;   } a[100005];   bool cmp(data a, data b) { return a.v < b.v || a.v == b.v && a.id < b.id; }   long long findL(long long m, long long R) {     long long l = 0, r = A, ans = 0;     while (l <= r) {       long long mid = (l + r) >> 1;       int p = lower_bound(a + 1, a + n + 1, (data){0, mid}, cmp) - a - 1;       if (p > R) p = R;       if (p * mid - s[p] <= m) {         ans = mid;         l = mid + 1;       } else         r = mid - 1;     }     return ans;   }   void init() {     cin >> n >> A >> cf >> cm >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i].v;       a[i].id = i;     }     sort(a + 1, a + n + 1, cmp);     for (int i = 1; i <= n; i++) {       s[i] = s[i - 1] + a[i].v;     }     for (int i = 0; i <= n; i++) {       long long p = A * i - s[n] + s[n - i];       if (p <= m) {         L = findL(m - p, n - i);         if (cm * L + cf * i > f) {           f = cm * L + cf * i;           ansA = i;           ansL = L;         }       }     }     cout << f << endl;     for (int j = 1; j <= n; j++) {       if (j > n - ansA) {         ans[a[j].id] = A;       } else if (a[j].v <= ansL) {         ans[a[j].id] = ansL;       } else         ans[a[j].id] = a[j].v;     }     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }   }   int main() {     init();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3E5 + 7, mod = 998244353;   long long n, a[N], inv[N], ans;   signed main() {     scanf( %lld , &n);     for (long long i = 1; i <= n << 1; i++) scanf( %lld , &a[i]);     sort(a + 1, a + 2 * n + 1);     for (long long i = 1; i <= n; i++) ans = (ans - a[i] + mod) % mod;     for (long long i = n + 1; i <= n << 1; i++) ans = (ans + a[i]) % mod;     for (long long i = n << 1; i >= n + 1; i--) ans = ans * i % mod;     inv[1] = 1;     for (long long i = 2; i <= n; i++) {       inv[i] = 1ll * inv[mod % i] * (mod - mod / i) % mod;       ans = 1ll * ans * inv[i] % mod;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long int n;     cin >> n;     int a[n], b[n], i;     for (i = 0; i < n; ++i) cin >> a[i] >> b[i];     for (i = 0; i < n; ++i) {       if (a[i] != b[i]) break;     }     if (i == n) {       for (i = 1; i < n; ++i) {         if (a[i] <= a[i - 1])           continue;         else           break;       }       if (i == n)         cout <<  maybe ;       else         cout <<  unrated ;     } else       cout <<  rated ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n;     char a[1000][10];     cin >> n;     cin >> a[0];     for (i = 1; i <= n; i++) {       cin >> a[i];     }     if (n % 2 == 0)       cout <<  home ;     else       cout <<  contest ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> v[1010];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int aux, aux2;       scanf( %d , &aux);       for (int j = 0; j < aux; ++j) {         scanf( %d , &aux2);         v[i].push_back(aux2);       }       sort(v[i].begin(), v[i].end());     }     int r = 0;     for (int i = 0; i < n; ++i) {       int pnt1 = 0, pnt2 = 0;       int pr = (i - 1 + n) % n, ne = (i + 1) % n;       for (int j = 0; j < v[i].size() - 1; ++j) {         int q1 = 0, q2 = 0;         while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j]) pnt1++;         while (pnt1 < v[pr].size() && v[pr][pnt1] < v[i][j + 1]) pnt1++, q1++;         while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j]) pnt2++;         while (pnt2 < v[ne].size() && v[ne][pnt2] < v[i][j + 1]) pnt2++, q2++;         if (q1 != q2) r++;       }     }     printf( %d n , r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[110];   double f[110][110][110], C[110][110];   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) scanf( %d , &a[i]);     C[0][0] = 1;     for (int i = 1; i <= 55; i++) {       C[i][0] = 1;       for (int j = 1; j <= i; j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];     }     for (int i = 0; i <= n; i++) f[0][0][i] = i;     for (int i = 1; i <= m; i++)       for (int j = 0; j <= n; j++)         for (int k = 0; k <= n; k++)           for (int c = 0; c <= j; c++) {             int _max = max(k, (c % a[i] == 0) ? (c / a[i]) : (c / a[i] + 1));             f[i][j][k] +=                 f[i - 1][j - c][_max] * pow(i - 1, j - c) / pow(i, j) * C[j][c];           }     printf( %.10f n , f[m][n][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int b[111111], n;   int check(int k) {     int l = n / k;     for (int i = 0; i < l; i++) {       int ok = 1;       int cur = i;       for (int j = 0; ok && j < k; j++) {         if (!b[cur]) ok = 0;         cur += l;         cur %= n;       }       if (ok) return 1;     }     return 0;   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) cin >> b[i];     int flag = 0;     for (int i = 3; i <= n; i++) {       if (n % i == 0) {         if (check(i)) flag = 1;       }     }     printf(flag ?  YES n  :  NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int a, b, t, p;   int Pow(int x, int a) {     int ret = 1;     while (a) {       if (a & 1) ret = ret * 1ll * x % 1000000007;       a >>= 1, x = x * 1ll * x % 1000000007;     }     return ret;   }   int pr[200006];   int J[200006], iJ[200006];   int C(int a, int b) {     if (b > a) return 0;     return J[a] * 1ll * iJ[b] % 1000000007 * iJ[a - b] % 1000000007;   }   int sdp[1506][1506], pdp[1506][1506], g[1506][1506];   int sp[200006];   void solve() {     cin >> n >> m >> a >> b >> t;     J[0] = iJ[0] = 1;     for (int i = (1), iend = (t); i <= iend; ++i)       J[i] = J[i - 1] * 1ll * i % 1000000007, iJ[i] = Pow(J[i], 1000000007 - 2);     p = a * 1ll * Pow(b, 1000000007 - 2) % 1000000007;     pr[0] = C(t, 0) * 1ll * Pow(p, 0) % 1000000007 * Pow(1 + 1000000007 - p, t) %             1000000007;     for (int i = (1), iend = (m); i <= iend; ++i) {       if (i <= t)         pr[i] = C(t, i) * 1ll * Pow(p, i) % 1000000007 *                 Pow(1 + 1000000007 - p, t - i) % 1000000007;       sp[i] = (sp[i - 1] + pr[i - 1]) % 1000000007;     }     pdp[0][m] = 1, sdp[0][m] = 1;     for (int i = (1), iend = (n); i <= iend; ++i)       for (int j = (1), jend = (m); j <= jend; ++j) {         pdp[i][j] = pr[m - j] * 1ll *                     ((sdp[i - 1][m] - sdp[i - 1][m - j] + 1000000007) %                          1000000007 * 1ll * sp[j] % 1000000007 -                      g[i - 1][j] + 1000000007) %                     1000000007;         sdp[i][j] = (sdp[i][j - 1] + pdp[i][j]) % 1000000007;         g[i][j] = (g[i][j - 1] + pr[j - 1] * 1ll * sdp[i][j - 1] % 1000000007) %                   1000000007;       }     cout << sdp[n][m] << endl;   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     int a[3];     int s = 0;     int count = 0;     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 3; j++) {         cin >> a[j];         if (a[j] == 1) count++;       }       if (count >= 2) s++;       count = 0;     }     cout << s << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void amin(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void amax(T &a, const T &b) {     if (a < b) a = b;   }   struct Data {     int sx, sy;     int le, ri, to, bo;     bool operator<(const Data &y) const { return sx < y.sx; }   };   int N, Q;   int main() {     scanf( %d%d , &N, &Q);     set<Data> S;     S.insert((Data){1, 1, 1, N, 1, N});     Data seek;     for (int $ = 0, $_len = (Q); $ < $_len; ++$) {       int col, row;       char buf[8], dir;       scanf( %d%d%s , &col, &row, buf);       dir = buf[0];       int ans = 0;       seek.sx = col;       set<Data>::iterator it = S.upper_bound(seek);       if (it != S.begin()) {         it--;         if (it->sx <= col && col <= it->ri) {           Data D = *it;           S.erase(it);           if (dir ==  U ) {             ans = row - D.to + 1;             if (D.sx < col)               S.insert((Data){D.sx, row + 1, D.le, col - 1, D.to, D.bo});             if (col < D.ri)               S.insert((Data){col + 1, D.sy, col + 1, D.ri, D.to, row - 1});           } else {             ans = col - D.le + 1;             if (D.sy < row)               S.insert((Data){col + 1, D.sy, D.le, D.ri, D.to, row - 1});             if (row < D.bo)               S.insert((Data){D.sx, row + 1, D.le, col - 1, row + 1, D.bo});           }         } else {           ans = 0;         }       } else {         ans = 0;       }       printf( %d n , ans);     }     return 0;   }
#include<cstdio>   #include<cstring>   #include<vector>   typedef long long ll;   int main()   {       int t,a[120];       scanf( %d ,&t);       while(t--)       {           int n,u,v;           scanf( %d%d%d ,&n,&u,&v);              for(int i=1;i<=n;i++)           {              scanf( %d ,&a[i]);           }           int j,b=0;           for(j=2;j<=n;j++)           {               if(a[j]==a[j-1]+1||a[j]==a[j-1]-1)                   {b=1;}               if(a[j]>a[j-1]+1||a[j]<a[j-1]-1)               {                   b=2;break;               }           }           if(b==0)              {                  if(u<v)           printf( %d n ,u+v);           else               printf( %d n ,2*v);              }           else if(b==2)           {               printf( 0 n );           }           else           {               if(u>v)printf( %d n ,v);               else printf( %d n ,u);           }       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string one, two;     map<string, string> m;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> one >> two;       bool found = false;       for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {         if (it->second == one) {           it->second = two;           found = true;         }       }       if (!found) {         m.insert(pair<string, string>(one, two));       }     }     cout << m.size() <<   n ;     for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {       cout << it->first <<     << it->second <<   n ;     }     cout << flush;     return 0;   }
// Author:  HolyK   // Created: Thu Jul  8 09:48:07 2021   #include <bits/stdc++.h>   #define dbg(a...) fprintf(stderr, a)   template <class T, class U>   inline bool smin(T &x, const U &y) {     return y < x ? x = y, 1 : 0;   }   template <class T, class U>   inline bool smax(T &x, const U &y) {     return x < y ? x = y, 1 : 0;   }      using LL = long long;   using PII = std::pair<int, int>;      int ask(int x) {     std::cout << x << std::endl;     int r;     std::cin >> r;     return r;   }   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(nullptr);     int t;     std::cin >> t;     while (t--) {       int n, k;       std::cin >> n >> k;       if (ask(0)) continue;       for (int i = 1; i < n; i++) {         int x = 0;         for (int j = 1; j <= i; j *= k) {    int u = (i / j - (i - 1) / j) % k;    if (i & 1) u = (k - u) % k;    x += u * j;         }         if (ask(x)) break;       }     }     return 0;   }   /*   0    */
#include <bits/stdc++.h>   using namespace std;   void computeLcp(string &s1, string &s2, int LCP[][5005]) {     for (int i = ((int)s1.size()) - 1; i >= 0; i--) {       for (int j = ((int)s2.size()) - 1; j >= 0; j--) {         if (s1[i] == s2[j]) {           LCP[i][j] = 1 + LCP[i + 1][j + 1];         } else {           LCP[i][j] = 0;         }       }     }   }   int lcp[5005][5005];   int mUA[5005];   int mUB[5005];   int main() {     ios_base::sync_with_stdio(0);     string A, B;     cin >> A >> B;     memset((lcp), (0), sizeof(lcp));     ;     computeLcp(A, A, lcp);     int ans = (1 << 30);     for (int i = 0; i < ((int)A.size()); i++) {       int minUniqueLength = 0;       for (int j = 0; j < ((int)A.size()); j++) {         if (i == j) continue;         minUniqueLength = max(minUniqueLength, lcp[i][j]);       }       minUniqueLength++;       mUA[i] = minUniqueLength;     }     memset((lcp), (0), sizeof(lcp));     ;     computeLcp(B, B, lcp);     for (int i = 0; i < ((int)B.size()); i++) {       int minUniqueLength = 0;       for (int j = 0; j < ((int)B.size()); j++) {         if (i == j) continue;         minUniqueLength = max(minUniqueLength, lcp[i][j]);       }       minUniqueLength++;       mUB[i] = minUniqueLength;     }     memset((lcp), (0), sizeof(lcp));     ;     computeLcp(A, B, lcp);     for (int i = 0; i < ((int)A.size()); i++) {       for (int j = 0; j < ((int)B.size()); j++) {         if (lcp[i][j] >= max(mUA[i], mUB[j])) {           ans = min(ans, max(mUA[i], mUB[j]));         }       }     }     if (ans >= (1 << 30)) ans = -1;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, x;   void solve() {     cin >> n >> x;     int left = x - 1;     int right = n - x;     if (left >= right)       cout << (x - 1 == 0 ? 1 : x - 1) << endl;     else       cout << (x + 1 > n ? n : x + 1) << endl;   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);     ;     int tt;     tt = 1;     for (int i = 1; i <= tt; ++i) {       solve();     }     return 0;   }