malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int c[25];   bool vis[25];   int n, m;   bool dfs(int p, int s, int k) {     if (p > n) return m == n - 1;     if (!k) return dfs(p + 1, p, c[p + 1]);     for (; s; s--)       if (!vis[s] && c[s] + 1 < c[p] && c[s] + 1 <= k) {         vis[s] = true;         k -= c[s] + 1;         m++;         if (dfs(p, s - 1, k)) return true;         vis[s] = false;         k += c[s] + 1;         m--;       }     return false;   }   int main() {     while (~scanf( %d , &n)) {       for (int i = 1; i <= n; ++i) {         scanf( %d , &c[i]);         c[i]--;       }       sort(c + 1, c + 1 + n);       memset(vis, false, sizeof(vis));       m = 0;       puts(dfs(1, 0, c[1]) ?  YES  :  NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     getline(cin, s);     for (int i = 0; i < n; i++) {       getline(cin, s);       if (s.length() >= 5) {         if ((s.substr(0, 5) ==  miao. ) &&             (s.substr(s.length() - 5, 5) !=  lala. ))           cout <<  Rainbow s  << endl;         else if ((s.substr(0, 5) !=  miao. ) &&                  (s.substr(s.length() - 5, 5) ==  lala. ))           cout <<  Freda s  << endl;         else           cout <<  OMG>.< I don t know!  << endl;       } else         cout <<  OMG>.< I don t know!  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1010;   char mtr[MAXN][MAXN];   int main() {     int n, m;     cin >> n >> m;     set<int> s;     bool ok = true;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> mtr[i][j];       }     }     for (int i = 1; i <= n; i++) {       int gnomo, doce;       for (int j = 1; j <= m; j++) {         if (mtr[i][j] ==  G ) gnomo = j;         if (mtr[i][j] ==  S ) doce = j;       }       int r = doce - gnomo;       if (r > 0)         s.insert(r);       else         ok = false;     }     if (ok == false) {       cout <<  -1  << endl;       return 0;     }     cout << s.size() << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     int count = 0, c = 0;     cin >> a;     count = a.size();     for (int i = 0; a[i] !=   0 ; i++) {       if (a[i] >=  A  && a[i] <=  Z ) c++;     }     if ((c == count) || ((c == count - 1) && (a[0] >=  a  && a[0] <=  z ))) {       for (int i = 0; a[i] !=   0 ; i++) {         if (a[i] >=  A  && a[i] <=  Z )           a[i] = a[i] + 32;         else           a[i] = a[i] - 32;       }     }     for (int i = 0; a[i] !=   0 ; i++) {       cout << a[i];     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chmin(T &x, const T &y) {     if (x > y) x = y;   }   template <typename T>   void chmax(T &x, const T &y) {     if (x < y) x = y;   }   char readc() {     char c;     while ((c = getchar()) <  - )       ;     return c;   }   int read() {     char c;     while ((c = getchar()) <  - )       ;     if (c ==  - ) {       int x = (c = getchar()) -  0 ;       while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ;       return -x;     }     int x = c -  0 ;     while ((c = getchar()) >=  0 ) x = x * 10 + c -  0 ;     return x;   }   const int N = 2e5 + 5;   pair<int, int> p[N];   long long s[N];   int main() {     int n, a, b;     cin >> n >> a >> b;     for (int i = 1; i <= n; ++i) {       p[i].first = read();       p[i].second = read();       p[i].first -= p[i].second;     }     sort(p + 1, p + n + 1, greater<pair<int, int> >());     for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + max(0, p[i].first);     for (int i = n + 1; i <= b; ++i) s[i] = s[i - 1];     long long ans = s[b];     if (b)       for (int i = 1; i <= n; ++i)         chmax(ans, ((i < b) ? s[b] - max(0, p[i].first) : s[b - 1]) +                        ((long long)(p[i].first + p[i].second) << a) -                        p[i].second);     for (int i = 1; i <= n; ++i) ans += p[i].second;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 150000 + 10;   int len, n, h;   int a[MAXN], b[MAXN];   int dp[1 << 20], all[1 << 20];   inline void go(int root, int lo, int hi, int s, int e, int key) {     if (hi < s || e < lo) return;     if (s <= lo && hi <= e) {       all[root] += key;       dp[root] += key;       return;     }     int mid = (lo + hi) / 2;     go(root * 2, lo, mid, s, e, key);     go(root * 2 + 1, mid + 1, hi, s, e, key);     dp[root] = min(dp[root * 2], dp[root * 2 + 1]) + all[root];   }   inline void build(int root, int lo, int hi) {     if (lo == hi) {       dp[root] = -lo;       return;     }     int mid = (lo + hi) / 2;     build(root * 2, lo, mid);     build(root * 2 + 1, mid + 1, hi);     dp[root] = -hi;   }   int main() {     cin >> n >> len >> h;     for (int i = 0; i < len; i++) cin >> b[i];     for (int i = 0; i < n; i++) cin >> a[i];     sort(b, b + len);     int ret = 0;     build(1, 0, len - 1);     for (int i = 0; i < n; i++) {       int poi = lower_bound(b, b + len, h - a[i]) - b;       go(1, 0, len - 1, poi, len - 1, 1);       if (len <= i + 1) {         ret += (dp[1] > 0);         poi = lower_bound(b, b + len, h - a[i - len + 1]) - b;         go(1, 0, len - 1, poi, len - 1, -1);       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, q, ans, top[200005 << 1];   int find(int u) {     if (top[u] == u) return u;     return top[u] = find(top[u]);   }   inline void work() {     scanf( %d %d %d , &n, &m, &q);     for (int i = 1; i <= n + m; i++) top[i] = i;     for (int i = 1, u, v; i <= q; i++) {       scanf( %d %d , &u, &v);       v = v + n;       int fu = find(u), fv = find(v);       if (fu == fv) continue;       top[fu] = fv;     }     for (int i = 1; i <= n + m; i++)       if (top[i] == i) ans++;     printf( %d , ans - 1);   }   int main() {     work();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int getMin(int l, int r, char a[], char ch) {     int count = 0;     for (int i = l; i <= r; i++) {       if (a[i] != ch) {         count++;       }     }     return count;   }   int findans(int l, int r, char a[], char ch) {     if (l == r) {       if (a[l] == ch) {         return 0;       } else {         return 1;       }     }     int mid = (l + r) / 2;     return min(getMin(l, mid, a, ch) + findans(mid + 1, r, a, ch + 1),                getMin(mid + 1, r, a, ch) + findans(l, mid, a, ch + 1));   }   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       char a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       int ans = findans(0, n - 1, a,  a );       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void MAIN();   int main() {     MAIN();     return 0;   }   const long long N = 5e3 + 1, mod = 1e9 + 7;   int n, m, best[N][N], len[N][N];   char s[N][N];   void MAIN() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %s , s[i] + 1);       for (int j = 1; j <= m; ++j) {         if (s[i][j] ==  1 ) {           len[i][j] = len[i][j - 1] + 1;         }         ++best[j][len[i][j]];       }     }     for (int i = m - 1; i >= 1; --i) {       for (int j = 1; j <= m; ++j) {         best[j][i] += best[j][i + 1];       }     }     int ans = 0;     for (int i = 1; i <= m; ++i) {       for (int len = 1; len <= m; ++len) {         ans = max(ans, len * best[i][len]);       }     }     printf( %d , ans);   }
#include <bits/stdc++.h>   using namespace std;   vector<int> parent;   vector<string> names;   void parse(int par) {     string str;     char c;     while (isalpha(cin.peek())) {       cin >> c;       str += c;     }     names.push_back(str);     parent.push_back(par);     int id = names.size() - 1;     while (cin.peek() ==  ,  || cin.peek() ==  : ) {       cin >> c;       parse(id);     }     cin >> c;   }   int main() {     int ans = 0;     parse(-1);     for (int i = 0; i < names.size(); i++) {       int j = parent[i];       while (j != -1) {         ans += (names[j] == names[i]);         j = parent[j];       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long sz = 1e5 + 10;   long long ara[sz], n, p;   ;   bool isValid(long long now) {     long long ptr = 1;     for (long long i = 1; i <= n; ++i) {       while (ptr <= n && ara[ptr] <= now) ptr++;       if (ptr - i >= p) return 0;       now++;     }     return 1;   }   int main() {     cin >> n >> p;     for (long long i = 1; i <= n; ++i) scanf( %lld , &ara[i]);     sort(ara + 1, ara + n + 1);     long long start = 1, now = start;     for (long long i = 1; i <= n; ++i) {       if (now < ara[i]) {         long long diff = ara[i] - now;         now += diff, start += diff;       }       now++;     }     long long lo = start, hi = 1e9, stop = -1;     while (lo <= hi) {       long long mid = lo + hi >> 1;       if (isValid(mid)) {         stop = mid;         lo = mid + 1;       } else         hi = mid - 1;     }     cout << max(0LL, stop - start + 1) <<   n ;     for (long long i = start; i <= stop; i += 1) {       if (i != start) printf(   );       printf( %lld , i);     }     if (stop != -1) printf(  n );     return 0;   }
#include <bits/stdc++.h>   struct state {     int n : 24;     int c : 8;     state const *prev;   };   state b[128][128][128] = {};   void print(state const &s) {     if (s.n) {       state const &p = *s.prev;       print(p);       if (p.n < s.n) printf( %c , s.c);     }   }   int main() {     char s1[128];     char s2[128];     char sv[128];     scanf( %s%s%s , s1, s2, sv);     unsigned int n1 = strlen(s1);     unsigned int n2 = strlen(s2);     unsigned int nv = strlen(sv);     unsigned int fail[128] = {};     for (unsigned int i = 1, j = 0; i < nv;)       if (sv[i] == sv[j])         fail[i++] = 1 + j++;       else if (0 < j)         j = fail[j - 1];       else         fail[i++] = 0;     b[0][0][0].n = 0;     for (unsigned int i = 1; i <= nv; ++i) b[0][0][i].n = -4200;     for (unsigned int i = 1; i <= n1; ++i) {       for (unsigned int j = 1; j <= n2; ++j) {         for (unsigned int k = 0; k < nv; ++k) {           b[i][j][k] = b[i - 1][j][k];           if (b[i][j][k].n < b[i][j - 1][k].n) b[i][j][k] = b[i][j - 1][k];         }         if (s1[i - 1] == s2[j - 1]) {           for (unsigned int k = 0; k < nv; ++k) {             unsigned int v = k;             while (1) {               if (s1[i - 1] == sv[v]) {                 ++v;                 break;               }               if (0 < v)                 v = fail[v - 1];               else                 break;             }             if (b[i][j][v].n < b[i - 1][j - 1][k].n + 1) {               b[i][j][v].n = b[i - 1][j - 1][k].n + 1;               b[i][j][v].c = s1[i - 1];               b[i][j][v].prev = &b[i - 1][j - 1][k];             }           }         }       }     }     unsigned int v = 0;     for (unsigned int i = 1; i < nv; ++i)       if (b[n1][n2][v].n < b[n1][n2][i].n) v = i;     if (0 < b[n1][n2][v].n) {       print(b[n1][n2][v]);       printf(  n );     } else       printf( 0 n );   }
#include <bits/stdc++.h>   using namespace std;   set<pair<string, string> > m;   int n, z[2000], d, k, ans;   string a[2000], b[2000], zx[2000][5];   int main() {     cin >> n >> d;     for (int i = 0; i < n; i++) {       cin >> a[i];       cin >> b[i];       cin >> z[i];     }     for (int i = 0; i < n; i++)       for (int j = i + 1; j < n; j++)         if (z[j] - z[i] <= d) {           if (a[i] == b[j] && a[j] == b[i] && z[i] != z[j])             m.insert(make_pair(min(a[i], b[i]), max(a[i], b[i])));         } else           break;     cout << m.size() << endl;     for (set<pair<string, string> >::iterator i = m.begin(); i != m.end(); i++)       cout << i->first <<     << i->second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int x[100111];   int num[100111], numl;   int ans[100111];   map<int, int> HASH;   int main() {     int i, temp;     scanf( %d , &n);     memset(num, 0, sizeof(num));     numl = 0;     for (i = 0; i < n; i++) {       scanf( %d , &temp);       if (HASH.count(temp) == 0) {         HASH[temp] = numl;         x[numl] = temp;         numl++;       }       num[HASH[temp]]++;     }     sort(x, x + numl);     ans[0] = num[HASH[x[0]]];     for (i = 1; i < numl; i++) {       ans[i] = ans[i - 1] + num[HASH[x[i]]];     }     int m, q;     int left, right, mid;     scanf( %d , &q);     for (i = 0; i < q; i++) {       scanf( %d , &m);       left = 0;       right = numl - 1;       while (left <= right) {         mid = (left + right) / 2;         if (x[mid] == m ||             (x[mid - 1] < m && x[mid + 1] > m && mid + 1 < numl && mid - 1 >= 0))           break;         if (x[mid] > m)           right = mid - 1;         else           left = mid + 1;       }       while (x[mid] > m && mid >= 0) mid--;       while (x[mid + 1] <= m && mid + 1 < numl) mid++;       if (mid >= 0 && mid < numl) printf( %d n , ans[mid]);       if (mid < 0) printf( 0 n );       if (mid >= numl) printf( %d n , n);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void debug(int n) { printf( %d n ); }   bool cmp(pair<int, pair<int, int> > &a, pair<int, pair<int, int> > &b) {     if (a.second.first == b.second.first) {       return a.first < b.first;     }     return a.second.first < b.second.first;   }   int main() {     int n, u, v, kase;     scanf( %d , &kase);     while (kase--) {       scanf( %d , &n);       vector<pair<int, pair<int, int> > > q;       for (int i = 0; i < n; i++) {         scanf( %d%d , &u, &v);         q.push_back(make_pair(i, make_pair(u, v)));       }       sort(q.begin(), q.end(), cmp);       vector<int> idx;       int time = 0;       for (int i = 0; i < n; i++) {         time = max(time, q[i].second.first);         if (time > q[i].second.second) {           idx.push_back(0);         } else {           idx.push_back(time);           time++;         }       }       for (auto i : idx) printf( %d  , i);       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   const int INF = 2e9;   const long long INFLL = 1e18;   const int MAX_N = 100000;   vector<int> gp[MAX_N + 1];   int N;   int p[MAX_N + 1];   int cnt[MAX_N + 1];   int lv[MAX_N + 1];   void dfs(int x) {     cnt[lv[x]]++;     for (int i : gp[x]) {       lv[i] = lv[x] + 1;       dfs(i);     }   }   int main() {     scanf( %d , &N);     for (int i = 2; i <= N; i++) {       scanf( %d , &p[i]);       gp[p[i]].push_back(i);     }     lv[1] = 1;     dfs(1);     int ans = 0;     for (int i = 1; i <= N; i++) {       ans += (cnt[i] % 2);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100002;   const int logN = 22;   vector<int> c;   map<int, int> m;   void solve() {     int n;     cin >> n;     while (n--) {       int x;       cin >> x;       m[x]++;     }     int ans = 0;     for (const pair<int, int> &x : m) {       bool f = false;       for (const int &y : c) {         if (y == x.first) {           if (x.second >= 2) {             f = true;             break;           }           continue;         }         if (y != 2 * x.first && m.find(y - x.first) != m.end()) {           f = true;           break;         }       }       if (!f) {         ans += x.second;       }     }     cout << ans << endl;   }   int main() {     int t = 1;     for (int i = 0; i <= 31; i++) {       c.push_back(1 << i);     }     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000050;   int go[N][2], a[N], b[N], n, i, j, p, sz[N], tsz;   long long k, x[N];   int main() {     scanf( %i %lld , &n, &k);     for (i = 2; i <= n; i++) scanf( %i %lld , &p, &x[i]), x[i] ^= x[p];     for (i = 1; i <= n; i++) a[i] = b[i] = 1;     long long ans = 0;     for (j = 61; ~j; j--) {       for (i = 1; i <= tsz; i++) go[i][0] = go[i][1] = sz[i] = 0;       tsz = 0;       for (i = 1; i <= n; i++) {         int g = (x[i] >> j) & 1;         if (!go[a[i]][g]) go[a[i]][g] = ++tsz;         sz[a[i] = go[a[i]][g]]++;       }       long long sum = 0;       for (i = 1; i <= n; i++) {         int g = (x[i] >> j) & 1;         sum += sz[go[b[i]][g]];       }       if (sum < k) {         ans += (long long)1 << j;         k -= sum;         for (i = 1; i <= n; i++) {           int g = (x[i] >> j) & 1;           b[i] = go[b[i]][g ^ 1];         }       } else {         for (i = 1; i <= n; i++) {           int g = (x[i] >> j) & 1;           b[i] = go[b[i]][g];         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, p;   long long A[5001];   long long a[5001];   long long l[1000005];   long long dp[2][5001];   long long s[5001][5001];   void work(long long *prev, long long *nxt) {     long long total = 0, prev_total = 1;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= min(l[i], m); j++) {         nxt[j] = (s[l[i]][j] * A[j] % p) * prev_total % p;         if (j <= l[i - 1])           nxt[j] = (nxt[j] - ((prev[j] * a[j] % p) * s[l[i]][j]) % p + p) % p;         total = (total + nxt[j]) % p;       }       swap(nxt, prev);       memset(nxt, 0, sizeof(long long) * 5000);       prev_total = total;       total = 0;     }     printf( %I64d n , prev_total);   }   int main() {     scanf( %I64d %I64d %I64d , &n, &m, &p);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &l[i]);     }     a[0] = 1;     A[0] = 1;     for (int i = 1; i <= 5000; i++) {       A[i] = A[i - 1] * (m - i + 1) % p;       a[i] = a[i - 1] * i % p;     }     s[0][0] = 1;     for (int i = 1; i <= 5000; i++)       for (int j = 1; j <= i; j++) {         s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * (j - 1) % p) % p;       }     work(dp[0], dp[1]);   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 100005, LOG = 25;   long long n, f[N][LOG + 5], cnt = 0, head[N], dep[N];   long long size[N];   struct CLANNAD {     long long to, nxt;   } a[N << 1];   inline void add(long long u, long long v) {     a[++cnt].to = v;     a[cnt].nxt = head[u];     head[u] = cnt;   }   inline long long getnode(long long x, long long deep) {     for (long long i = LOG; i >= 0; i--)       if (dep[f[x][i]] >= deep) x = f[x][i];     return x;   }   inline long long LCA(long long x, long long y) {     if (dep[x] < dep[y]) swap(x, y);     long long ox = x, oy = y;     for (long long i = LOG; i >= 0; i--)       if (dep[f[x][i]] >= dep[y]) x = f[x][i];     long long lca;     if (x == y)       lca = x;     else {       for (long long i = LOG; i >= 0; i--)         if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];       lca = f[x][0];     }     long long dis = dep[ox] + dep[oy] - dep[lca] * 2;     if (dis & 1)       return 0;     else if (oy == lca) {       long long mid = (dep[ox] + dep[oy]) >> 1;       return size[getnode(ox, mid)] - size[getnode(ox, mid + 1)];     } else if (dep[ox] != dep[oy]) {       long long mid = dep[ox] - dis / 2;       return size[getnode(ox, mid)] - size[getnode(ox, mid + 1)];     } else       return n - size[getnode(ox, dep[lca] + 1)] -              size[getnode(oy, dep[lca] + 1)];   }   void dfs(long long x, long long fx) {     size[x] = 1;     dep[x] = dep[fx] + 1;     f[x][0] = fx;     for (long long i = 1; i <= LOG; i++) f[x][i] = f[f[x][i - 1]][i - 1];     for (long long i = head[x]; i; i = a[i].nxt)       if (a[i].to != fx) dfs(a[i].to, x), size[x] += size[a[i].to];   }   signed main() {     cin >> n;     long long u, v;     for (long long i = 1; i <= n - 1; i++)       scanf( %lld%lld , &u, &v), add(u, v), add(v, u);     dfs(1, 0);     long long T, x, y;     cin >> T;     while (T--) {       scanf( %lld%lld , &x, &y);       if (x == y)         printf( %lld n , n);       else         printf( %lld n , LCA(x, y));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long A[5 * 1000 + 3][5 * 1000 + 3];   long long sum[5 * 1000 + 3];   int main() {     int n, a, b, k;     cin >> n >> a >> b >> k;     if (a > b) {       a = n - a + 1;       b = n - b + 1;     }     for (int j = 1; j <= b / 2; j++) A[j][1] = b - 2;     A[b - 1][1] = 0;     for (int j = b - 2; j > b / 2; j--) A[j][1] = A[j + 1][1] + 2;     for (int i = 2; i <= k; i++) {       sum[b] = 0;       A[b - 1][i] = 0;       for (int j = b - 1; j > 0; j--)         sum[j] = (sum[j + 1] + A[j][i - 1]) % (1000 * 1000 * 1000 + 7);       for (int j = b - 1; j > b / 2; j--)         A[j][i] = (sum[2 * j - b + 1] - A[j][i - 1] + (1000 * 1000 * 1000 + 7)) %                   (1000 * 1000 * 1000 + 7);       for (int j = 1; j <= b / 2; j++)         A[j][i] = (sum[1] - A[j][i - 1] + (1000 * 1000 * 1000 + 7)) %                   (1000 * 1000 * 1000 + 7);     }     cout << A[a][k];     return 0;   }
#include <bits/stdc++.h>   const int N = 50005;   char s[N];   int main() {     scanf( %s , s);     int i, j, n = strlen(s);     for (j = 1; j <= n / 2; j++) {       int t = 0, cnt = 0;       for (i = 0; i + j < n; i++) {         s[t++] = s[i];         if (s[i] == s[i + j])           cnt++;         else           cnt = 0;         if (cnt == j) {           t -= j;           cnt = 0;         }       }       for (; i < n; i++) s[t++] = s[i];       n = t;     }     s[n] = 0;     puts(s);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int r;   int done = 1;   pair<int, int> tempo(int x, int y) {     if (x >= y) {       if (x % y == 0) {         if (y == 1)           return make_pair(x, x - 1);         else           return make_pair(1000000100, 1000000100);       }       pair<int, int> next = tempo(x % y, y);       int num = x / y;       next.first += num;       next.second += num - 1;       return next;     }     if (y % x == 0) {       if (x == 1) {         return make_pair(y, y - 2);       } else         return make_pair(1000000100, 1000000100);     }     pair<int, int> next = tempo(x, y % x);     int num = y / x;     next.first += num;     next.second += num - 1;     return next;   }   int main() {     cin >> n >> r;     if (r == 1) {       if (n == 1)         cout <<  0 nT ;       else         cout <<  IMPOSSIBLE ;       return 0;     }     int minimo = 1000000100;     int chos = 0;     for (int i = 1; i < r; i++) {       pair<int, int> ris = tempo(i, r - i);       if (ris.first == n - 1 and ris.second < minimo) {         minimo = ris.second;         chos = i;       }     }     if (chos == 0) {       cout <<  IMPOSSIBLE ;       return 0;     }     cout << minimo;     cout << endl;     vector<char> roba;     int x = chos;     int y = r - chos;     while (x > 0) {       if (x == 1 and y == 1) {         x = 0;         roba.push_back( T );       } else if (x > y) {         roba.push_back( T );         x -= y;       } else if (x < y) {         roba.push_back( B );         y -= x;       }     }     for (int i = int(roba.size()) - 1; i >= 0; i--) cout << roba[i];     if (roba[0] ==  T )       cout <<  B ;     else       cout <<  T ;   }