malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   #define ll long long   #define deb(x) cout << #x <<  =  << x << endl   #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl   #define nl   n    void solve()   {       int n;       cin >> n;       int arr[n][n];       int x = 1;       for(int i=0;i<n;i++){           for(int j=0;j<n;j++){               if(i==j){                   arr[i][j]=x;                   x++;               }           }       }       for (int k = 1; k <= 2 * n - 2; k++)       {           for (int i = 0; i < n; i++)           {               for (int j = 0; j < n; j++)               {                   if(i!=j){                       if (i + j == k)                   {                       arr[i][j] = x;                       x++;                   }                   }               }           }       }       if (n == 1)       {           cout << 1 <<   n ;           return;       }       else if (n == 2)       {           cout << -1 <<   n ;       }       else       {           for (int i = 0; i < n; i++)           {               for (int j = 0; j < n; j++)               {                   cout << arr[i][j] <<    ;               }               cout <<   n ;           }       }   }   int main()   {       ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);       srand(chrono::high_resolution_clock::now().time_since_epoch().count());       int t;       cin >> t;       while (t--)       {           solve();       }       return 0;   }
#include <bits/stdc++.h>   const int MOD = 1e9 + 7;   int primes[100000];   using namespace std;   bool cmp(const pair<int, int>& a, const pair<int, int>& b) {     return a.first > b.first;   }   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, k;     cin >> n >> k;     int a[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long sum = 0;     long long ans = 0;     for (int i = 0; i < n; i++) {       sum += a[i];       long long p = sum / k;       cout << abs(p - ans) <<    ;       ans = p;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(int num) {     for (int i = 2; i <= sqrt(num) + 1; ++i) {       if (num % i == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     if (n < 9) {       cout << 1 << endl;       cout << n << endl;     } else if (n == 9) {       cout << 3 << endl;       cout << 3 <<     << 3 <<     << 3 << endl;     } else if (n == 11) {       cout << 3 << endl;       cout << 3 <<     << 3 <<     << 5 << endl;     } else {       cout << 3 << endl;       n -= 3;       for (int i = 3; i <= n / 2; ++i) {         if (isPrime(i) && isPrime(n - i)) {           cout << 3 <<     << i <<     << n - i << endl;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool yes(int x1, int x2, int x3, int x4) {     int num1 = (x1 + x2 + x3 + x4) / 4, num2 = (x2 + x3) / 2, num3 = x4 - x1;     if (((x1 + x2 + x3 + x4) % 4 != 0) || ((x2 + x3) % 2 != 0) || num1 != num2 ||         num1 != num3 || x1 == -1 || x2 == -1 || x3 == -1 || x4 == -1)       return false;     if (x1 <= x2 && x2 <= x3 && x3 <= x4) return true;     return false;   }   bool fun(int x1, int x2, int x3, int x4, vector<int> sol) {     for (int i = 1; i <= 2000; i++) {       vector<int> Sol = sol;       int X1 = x1, X2 = x2, X3 = x3, X4 = x4;       x1 = i;       x4 = i * 3;       if (x2 == -1 && x3 != -1)         x2 = x4 + x1 - x3, sol.push_back(x2);       else if (x2 != -1 && x3 == -1)         x3 = x4 + x1 - x2, sol.push_back(x3);       else if (x2 != -1 && x3 != -1 && x2 + x3 != x1 + x4)         continue;       if (yes(x1, x2, x3, x4)) {         cout <<  YES n ;         for (int i = 0; i < (int)sol.size(); i++) cout << sol[i] <<   n ;         return true;       }       x1 = X1, x2 = X2, x3 = X3, x4 = X4, sol = Sol;     }     return false;   }   bool Fun(int x1, int x2, int x3, int x4, vector<int> sol) {     for (int i = 1; i <= 2000; i++) {       x2 = i;       x3 = x4 + x1 - x2;       vector<int> Sol = sol;       sol.push_back(x2);       sol.push_back(x3);       if (yes(x1, x2, x3, x4)) {         cout <<  YES n ;         for (int I = 0; I < (int)sol.size(); I++) cout << sol[I] << endl;         return true;       }       sol = Sol;     }     return false;   }   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     int ar[4];     memset(ar, -1, sizeof(ar));     for (int i = 0; i < n; i++) cin >> ar[i];     if (n == 0) {       cout <<  YES n1 n1 n3 n3 ;       goto ss;     }     for (int i = 0; i < 4; i++)       for (int i1 = 0; i1 < 4; i1++)         for (int i2 = 0; i2 < 4; i2++)           for (int i3 = 0; i3 < 4; i3++) {             if (i == i1 || i == i2 || i == i3 || i1 == i2 || i1 == i3 || i2 == i3)               continue;             vector<int> sol;             int x1 = ar[i], x2 = ar[i1], x3 = ar[i2], x4 = ar[i3];             if (x1 != -1 && x4 != -1) {               if (x1 * 3 != x4) continue;             } else if (x1 == -1 && x4 != -1) {               x1 = x4 / 3;               if (x4 % 3 != 0) continue;               sol.push_back(x1);             } else if (x1 != -1 && x4 == -1) {               x4 = x1 * 3;               sol.push_back(x4);             } else if (x1 == -1 && x4 == -1)               if (fun(x1, x2, x3, x4, sol)) goto ss;             if (x2 == -1 && x3 == -1) {               if (Fun(x1, x2, x3, x4, sol)) goto ss;             } else if (x2 == -1) {               x2 = x4 + x1 - x3;               sol.push_back(x2);             } else if (x3 == -1) {               x3 = x4 + x1 - x2;               sol.push_back(x3);             }             if (yes(x1, x2, x3, x4)) {               cout <<  YES n ;               for (int I = 0; I < (int)sol.size(); I++) cout << sol[I] <<   n ;               goto ss;             }           }     cout <<  NO ;   ss:     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int a[120000];   int main() {     cin >> n >> k;     for (int i = 0; i < n * 2; i++) a[i] = i;     for (int i = 0; i < k; i++) {       int now = i * 2;       swap(a[now], a[now + 1]);     }     k = n - k;     for (int i = 0; i < n * 2; i++) {       printf( %d  , a[i] + 1);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     if (n % 2 == 0) {       n = n / 2;       if (n % 2 == 0)         cout << 0;       else         cout << 1;     } else {       n = (n + 1) / 2;       if (n % 2 == 0)         cout << 0;       else         cout << 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _dbg(const char* _s, T _h) {     cerr << _s <<   =   << _h <<   n ;   }   template <typename T, typename... Ts>   void _dbg(const char* _s, T _h, Ts... _t) {     int _b = 0;     while (((_b += *_s ==  ( ) -= *_s ==  ) ) != 0 || *_s !=  , ) cerr << *_s++;     cerr <<   =   << _h <<  , ;     _dbg(_s + 1, _t...);   }   const int64_t INF = static_cast<int64_t>(1e9) + 7;   const int64_t LINF = INF * INF;   const int MAXN = static_cast<int>(1e6) + 17;   void solve() {     int n;     int64_t second;     cin >> n >> second;     vector<int> v(n);     int64_t sum = 0;     int right = INF;     for (auto& el : (v)) {       cin >> el;       sum += el;       right = min(right, el);     }     if (sum < second) {       cout <<  -1 n ;       return;     }     ++right;     int left = 0;     while (right - left > 1) {       int mid = (left + right) / 2;       int64_t amount = 0;       for (int i = 0; i < n; ++i) {         amount += v[i] - mid;       }       if (amount >= second) {         left = mid;       } else {         right = mid;       }     }     cout << left;   }   int main() {     cin.tie(nullptr);     cout.tie(nullptr);     ios_base::sync_with_stdio(false);     int q = 1;     for (int i = 0; i < q; ++i) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100005], top, s[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie();     cout.tie();     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     top = -1;     for (int i = n - 1; i >= 0; --i) {       s[++top] = a[i];       while (top > 0 && s[top] == s[top - 1]) ++s[--top];     }     cout << s[0] - top;     return 0;   }
#include <bits/stdc++.h>   const int MaxN = 100111;   const int mod = 1000000009;   int f[MaxN];   int getFather(int x) {     if (f[x] == x) return f[x];     return f[x] = getFather(f[x]);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) f[i] = i;     int ans = 0;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       if (getFather(x) == getFather(y))         ans = ((ans * 2) % mod + 1) % mod;       else         f[getFather(y)] = getFather(x);       printf( %d n , ans % mod);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const double eps = 1e-12;   const int INF = (1 << 31) - 1;   const long long LLINF = ((long long)1 << 62) - 1;   const int maxn = 1000 * 100 + 10;   int a[maxn], sum[maxn], sum2[maxn];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (i)         sum[i] = sum[i - 1] + a[i];       else         sum[i] = a[i];     }     string s;     getline(cin, s);     getline(cin, s);     for (int i = (int)s.size() - 1; i >= 0; i--) {       if (i != (int)s.size() - 1) {         sum2[i] = sum2[i + 1] + (s[i] -  0 ) * a[i];       } else {         sum2[i] = (s[i] -  0 ) * a[i];       }     }     long long maxx = 0LL;     for (int i = (int)s.size() - 1; i >= 0; i--) {       if (s[i] ==  1 ) {         long long cur = 0LL;         cur = sum[i - 1];         cur += sum2[i + 1];         maxx = max(maxx, cur);       }     }     printf( %lld , max(maxx, (long long)sum2[0]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename... T>   inline void inp(T &...args) {     ((cin >> args), ...);   }   template <typename T>   inline istream &operator>>(istream &in, vector<T> &a) {     for (auto &x : a) in >> x;     return in;   }   template <typename T, typename U>   inline istream &operator>>(istream &in, pair<T, U> &a) {     in >> a.first >> a.second;     return in;   }   void solve(int &T) {     long long int n, k;     cin >> n >> k;     vector<long long int> a(n);     cin >> a;     map<long long int, long long int> m;     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       m[a[i]]++;     }     set<long long int> s;     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       if (a[i] <= k) {         long long int x = a[i];         long long int y = k - a[i];         if (m.count(y) and !s.count(min(x, y))) {           if (x == y and m[y] >= 2) {             s.insert(min(x, y));           } else             s.insert(min(x, y));         }       }     }     11;     int ok = 1;     vector<long long int> ans(n, 0);     for (long long int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {       if (s.count(a[i])) {         ans[i] = 1;         if (k % 2 == 0 and a[i] == k / 2) {           ans[i] = ok;           ok ^= 1;         }       }     }     for (auto &X : ans) {       cout << X <<    ;     }     cout <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t = 1;     cin >> t;     for (int i = 1; i <= t; i++) {       if (0) cerr <<  Case #  << i <<   n ;       solve(i);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool debug = false;   int n, m, k;   int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   long long ln, lk, lm;   int a[10];   bool v[9], vv[9];   bool walk(int x) {     v[x] = 1;     if (a[x] == 1 || vv[a[x]]) return vv[x] = 1;     if (v[a[x]]) return 0;     return vv[x] = walk(a[x]);   }   bool ck() {     for (int i = 2; i <= k; i++) {       v[i] = 0;       vv[i] = 0;     }     for (int i = 2; i <= k; i++)       if (!v[i]) {         if (!walk(i)) {           return 0;         }       }     return 1;   }   long long tmp;   void dfs(int x) {     if (x == k + 1) {       if (ck()) tmp++;       return;     }     for (int(i) = 1; (i) <= (int)(k); (i)++)       if (i != x) {         a[x] = i;         dfs(x + 1);       }   }   int main() {     scanf( %d%d , &n, &k);     long long ans = k;     dfs(2);     (ans *= tmp) %= 1000000007;     m = n - k;     for (int i = k + 1; i <= n; i++) {       (ans *= m) %= 1000000007;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   const int MAXN = 1e5 + 5;   long long ans[MAXN], b[MAXN];   int n, first[65], cnt_ans;   bool selected[MAXN];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lld , &b[i]);     std::sort(b, b + n);     memset(first, 0xff, sizeof(first));     for (int i = 0; i < n; i++) {       for (int j = 60; j >= 0; j--) {         if (b[i] >> j & 1) {           if (first[j] == -1) first[j] = i;           break;         }       }     }     long long cur = 0;     bool flag = true;     for (int i = 0; i < n; i++) {       int j;       for (j = 0; j <= 60; j++)         if (!(cur >> j & 1)) {           if (first[j] != -1 && !selected[first[j]]) {             selected[first[j]] = true;             cur ^= b[first[j]];             ans[cnt_ans++] = b[first[j]++];             if (!(b[first[j]] >> j)) first[j] = -1;             break;           }         }       if (j == 61) {         flag = false;         break;       }     }     if (flag) {       printf( Yes n );       for (int i = 0; i < n; i++) printf( %lld  , ans[i]);       printf(  n );     } else {       printf( No n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, K;   char c[10];   int vl(int x, int y) {     printf( 1 %d %d n , x, y), fflush(stdout);     return scanf( %s , c), c[0] ==  T ;   }   int ef(int L, int R) {     for (; L < R;)       vl((L + R >> 1), (L + R >> 1) + 1) ? R = (L + R >> 1)                                          : L = (L + R >> 1) + 1;     return L;   }   int main() {     scanf( %d%d , &N, &K);     int Ans1 = ef(1, N), Ans2 = ef(1, Ans1 - 1);     if (Ans1 == Ans2 || !vl(Ans2, Ans1)) Ans2 = ef(Ans1 + 1, N);     printf( 2 %d %d n , Ans1, Ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int b, f, p, h, c, money = 0;       scanf( %d %d %d %d %d , &b, &p, &f, &h, &c);       b /= 2;       if (h > c) {         money = min(b, p) * h;         b -= min(b, p);         money += min(b, f) * c;       } else {         money = min(b, f) * c;         b -= min(b, f);         money += min(b, p) * h;       }       printf( %d n , money);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     {       int n, m;       cin >> n >> m;       vector<int> a(n + 2);       for (int i = 1; i <= n; i++) cin >> a[i];       a[0] = 0, a[n + 1] = m;       vector<int> light(n + 2, 0), dark(n + 2, 0);       for (int i = 1; i <= n + 1; i++) {         light[i] = light[i - 1], dark[i] = dark[i - 1];         if (i % 2)           light[i] += a[i] - a[i - 1];         else           dark[i] += a[i] - a[i - 1];       }       int ans = light[n + 1];       for (int i = 1; i <= n + 1; i++) {         ans =             max(ans, light[i - 1] + dark[n + 1] - dark[i] + a[i] - a[i - 1] - 1);       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1 << 23;   bool a[maxn];   bool vis[maxn];   int n, m, x;   void dfs(int x) {     if (vis[x]) return;     vis[x] = true;     for (int i = 0; i <= n; i++)       if (x & (1 << i)) dfs(x ^ (1 << i));     if (a[x]) dfs((1 << n) - 1 - x);   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) scanf( %d , &x), a[x] = true;     int ans = 0;     for (int i = 0; i < (1 << n); i++)       if (!vis[i] && a[i]) dfs(i), ans++;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, pos, lpos;     int q;     cin >> n >> q;     for (int i = 0; i < q; i++) {       cin >> pos;       while (pos % 2 == 0) {         lpos = pos / 2 + 1;         pos += n - lpos + 1;       }       cout << pos / 2 + 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9;   const long long N = 1e5 + 10;   const long long bits = 30;   const long long mod = 1e9 + 7;   const long double pi = 3.14159265358979323846;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     std::cout << std::fixed << std::setprecision(20);     ;     long double n;     cin >> n;     long double ans = 0;     for (long double i = 1; i <= n; i++) {       ans += (long double)1.0 / i;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int nx[10000][26], al[26], l1, l2;   string s1, s2;   int main() {     cin >> s1 >> s2;     l1 = s1.size();     l2 = s2.size();     for (int i = 0; i < l1; i++) fill(nx[i], nx[i] + 26, -1);     fill(al, al + 26, -1);     for (int i = l1 - 1; i >= 0; i--) al[s1[i] -  a ] = i;     for (int i = l1 - 1; i >= 0; i--) {       for (int j = 0; j < 26; j++) nx[i][j] = al[j];       al[s1[i] -  a ] = i;     }     int cur = l1 - 1, ans = 0;     for (int i = 0; i < l2; i++) {       if (nx[cur][s2[i] -  a ] == -1) {         cout << -1 << endl;         return 0;       }       if (nx[cur][s2[i] -  a ] <= cur) ans++;       cur = nx[cur][s2[i] -  a ];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline long long Getint() {     char ch = getchar();     long long x = 0, fh = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fh = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       (x *= 10) += ch ^ 48;       ch = getchar();     }     return fh * x;   }   const int N = 200005;   int n, h;   long long mod, fc[N], fiv[N], inv[N], sm[N];   int su[N];   struct nod {     int a, l;     nod(int x = 0, int y = 0) {       a = x;       l = y;     }   };   vector<nod> a;   inline long long Solve(int l1, int l2) {     long long Ans = 1ll * l1 * l2 % mod * inv[2] % mod;     for (int i = 1; i <= l1; i++) (Ans += sm[i] - sm[i + l2] + mod) %= mod;     return (Ans % mod + mod) % mod;   }   void Build(int l, int r, int h) {     if (h == 1) {       su[r - l + 1]++;       return;     }     if (l == r) {       su[1]++;       return;     }     int mid = l + r >> 1;     Build(l, mid, h - 1);     Build(mid + 1, r, h - 1);   }   int main() {     n = Getint();     h = Getint();     mod = Getint();     fc[0] = fc[1] = fiv[0] = fiv[1] = inv[0] = inv[1] = 1;     for (int i = 2; i <= N - 1; i++) {       fc[i] = fc[i - 1] * i % mod;       inv[i] = (mod - mod / i) * inv[mod % i] % mod;       fiv[i] = fiv[i - 1] * inv[i] % mod;     }     for (int i = 1; i <= N - 1; i++) {       sm[i] = (sm[i - 1] + inv[i]) % mod;     }     Build(1, n, h);     long long Ans = 0;     for (int i = 1; i <= n; i++) {       if (!su[i]) continue;       a.push_back(nod(su[i], i));       (Ans += 1ll * su[i] * i % mod * (i - 1) % mod * inv[4]) %= mod;     }     for (int i = 0; i <= int(a.size()) - 1; i++) {       (Ans += 1ll * a[i].a * (a[i].a - 1) % mod * inv[2] % mod *               Solve(a[i].l, a[i].l)) %= mod;       for (int j = i + 1; j <= int(a.size()) - 1; j++) {         (Ans += 1ll * a[i].a * a[j].a % mod * Solve(a[i].l, a[j].l)) %= mod;       }     }     cout << Ans % mod <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int G = 2520;   const int B = 41;   const int MAXN = B * G;   unsigned char S[G][B], ps[B + 1][G][4], mp[256];   string e;   void Pre() {     mp[ A ] = 0;     mp[ G ] = 1;     mp[ T ] = 2;     mp[ C ] = 3;   }   void build(int g) {     for (int i = 0; i < 4; i++) {       ps[0][g][i] = 0;       for (int j = 0; j < B; j++) ps[j + 1][g][i] = ps[j][g][i] + (S[g][j] == i);     }   }   void chng(int p, char c) {     S[p % G][p / G] = c;     build(p % G);   }   inline int nxt(int x, int y) {     if (x % G <= y)       return (x + (y - x % G)) / G;     else       return (x + (G + y - x % G)) / G;   }   inline int get(int g, int l, int r, int x) { return ps[r][g][x] - ps[l][g][x]; }   int t(int i) { return e[i % e.size()]; }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     Pre();     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) S[i % G][i / G] = mp[s[i]];     for (int i = 0; i < G; i++) build(i);     int q;     cin >> q;     while (q--) {       int type;       cin >> type;       if (type == 1) {         int x;         char c;         cin >> x >> c;         x--;         chng(x, mp[c]);       } else {         int l, r;         cin >> l >> r >> e;         l--;         int ans = 0;         for (int i = 0; i < G; i++) {           ans += get(i, nxt(l, i), nxt(r, i), mp[t((i - l % G + G) % G)]);         }         cout << ans << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 9e4;   const int INF = 1 << 30;   const long long mod = 1e9 + 7;   const double eps = 1e-8;   int main() {     long long a[100] = {0,   4,   10,  20,  35,  56,  83, 116,                         155, 198, 244, 292, 341, 390, 439};     long long n;     while (cin >> n)       if (n <= 14)         cout << a[n] << endl;       else         cout << a[14] + (long long)49 * (n - 14) << endl;   }
#include <bits/stdc++.h>   int main() {     int tab[2000], i, max = 0, posmax = 0, index = -1, n;     scanf( %d , &n);     for (i = 0; i < n; i++) {       scanf( %d , &tab[i]);       if (tab[i] > max) {         max = tab[i];         posmax = i + 1;       }     }     while (max-- && index == -1)       for (i = 0; i < n; i++)         if (tab[i] == max) {           index = i;           break;         }     printf( %d %d , posmax, tab[index]);     return 0;   }
#include <bits/stdc++.h>   char bar[1000002];   int main() {     scanf( %s , bar);     int n = strlen(bar);     long long int left = 0, mid = 0, right = 0;     for (int i = 0; bar[i] !=  ^ ; i++) mid = i + 1;     for (int i = 0; bar[i] !=  ^ ; i++)       if (bar[i] !=  = ) left += (mid - i) * (bar[i] -  0 );     for (int i = n - 1; bar[i] !=  ^ ; i--)       if (bar[i] !=  = ) right += (i - mid) * (bar[i] -  0 );     if (left < right) puts( right );     if (right < left) puts( left );     if (right == left) puts( balance );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<pair<int, char> > > adj(201);   int dp[101][101][26][2];   bool solve(int i, int j, char round, bool turn) {     if (dp[i][j][(int)(round -  a )][turn] != -1)       return dp[i][j][(int)(round -  a )][turn];     int ret = 0;     if (!turn) {       for (int k = 0; k < adj[i].size(); k++) {         if (adj[i][k].second >= round)           if (!solve(adj[i][k].first, j, adj[i][k].second, !turn)) ret = 1;       }     } else {       for (int k = 0; k < adj[j].size(); k++) {         if (adj[j][k].second >= round)           if (!solve(i, adj[j][k].first, adj[j][k].second, !turn)) ret = 1;       }     }     return dp[i][j][(int)(round -  a )][turn] = ret;   }   int main() {     memset(dp, -1, sizeof dp);     int n, m;     cin >> n >> m;     for (int i = 0; i < m; i++) {       int x, y;       char z;       cin >> x >> y >> z;       adj[x].push_back({y, z});     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         int h = solve(i, j,  a , 0);         if (h == 1)           cout <<  A ;         else           cout <<  B ;       }       cout << endl;     }     return 0;   }