malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100001;   vector<int> v, w;   char s[1000001];   int main() {     scanf( %s , &s);     int len = strlen(s);     for (int i = (0); i < (len); i++) {       if (s[i] ==  @ ) v.push_back(i);       if (s[i] ==  . ) w.push_back(i);     }     int t = 0, tmp = 0;     long long ans = 0;     while (t < v.size() && tmp < w.size()) {       long long first = 0, mid = 1, last = 0;       if (t == v.size()) break;       while (v[t] > w[tmp] && tmp < w.size()) tmp++;       if (tmp == w.size()) break;       if (v[t] + 1 == w[tmp]) mid = 0;       for (int i = v[t] + 1; i < w[tmp]; i++) {         if ((s[i] >  9  || s[i] <  0 ) && (s[i] >  z  || s[i] <  a )) {           mid = 0;           break;         }       }       if (!mid) {         t++;         continue;       }       if (v[t] > 0)         for (int i = v[t] - 1; i >= 0; i--) {           if ((s[i] >=  a  && s[i] <=  z ) || (s[i] >=  0  && s[i] <=  9 ) ||               s[i] ==  _ ) {             if (s[i] >=  a  && s[i] <=  z ) first++;           } else             break;         }       if (w[tmp] + 1 < len)         for (int i = w[tmp] + 1; i < len; i++) {           if (s[i] >=  a  && s[i] <=  z )             last++;           else             break;         }       ans += first * last;       t++;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, c;   int ans[1001];   int zero;   inline void send(int x, int p) {     if (ans[x] == 0) --zero;     ans[x] = p;     printf( %d n , x);     fflush(stdout);   }   int main() {     scanf( %d %d %d , &n, &m, &c);     int mid = (c + 1) / 2;     zero = n;     for (int round = 1; zero && round <= m; ++round) {       int p;       scanf( %d , &p);       if (p <= mid) {         int i;         for (i = 1; i < n; ++i)           if (ans[i] == 0 || ans[i] > p) {             break;           }         send(i, p);       } else {         int i;         for (i = n; i > 1; --i)           if (ans[i] == 0 || ans[i] < p) {             break;           }         send(i, p);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   const int INF = 1000000000;   const int MOD = 1073741824;   const int M = INF;   const double RRR = 180.0 / PI;   vector<vector<int> > g;   vector<bool> used;   void dfs(int v) {     used[v] = 1;     for (vector<int>::iterator it = g[v].begin(); it != g[v].end(); ++it) {       if (!used[*it]) {         dfs(*it);       }     }   }   int main() {     int x, y;     cin >> x >> y;     int d1 = 1, d2 = 0;     int e = 1;     int f = 0;     int a = 0, b = 0;     int r = 0;     int ans = 0;     if (a == x && b == y) {       cout << 0;       return 0;     }     while (1) {       a += d1;       b += d2;       r++;       if (a == x && b == y) {         cout << ans;         return 0;       }       if (r == e) {         ans++;         if (f == 0) {           f = 1;           d1 = 0;           d2 = 1;           r = 0;         } else {           if (f == 1) {             f = 2;             e++;             r = 0;             d1 = -1;             d2 = 0;           } else {             if (f == 2) {               f = 3;               r = 0;               d1 = 0;               d2 = -1;             } else {               f = 0;               e++;               r = 0;               d1 = 1;               d2 = 0;             }           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mcd(long long a, long long b) {     if (b > a) swap(a, b);     if (b == 0)       return a;     else       return mcd(b, a % b);   }   long long i, j, n, m, q, a, l, r, b;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> q;     while (q--) {       cin >> n;       if (n == 1)         cout << 3;       else if (n == 2)         cout << 2;       else if (n & 1)         cout << 1;       else         cout << 0;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long modulo = 998244353;   const long long p = modulo;   vector<int> edges[300005];   int father[300005];   long long rCount[300005];   long long oCount[300005];   long long eCount[300005];   pair<int, int> gcd(long long a, long long b) {     if (b == 0ll) return {1ll, 0ll};     pair<int, int> q = gcd(b, a % b);     return {q.second, q.first - q.second * (a / b)};   }   long long inv(long long a) {     long long aa = gcd(a, p).first;     aa %= p;     if (aa < 0) aa += p;     return aa;   }   void trace(int index) {     for (int j = 0; j < edges[index].size(); ++j) {       int v = edges[index][j];       if (v == father[index]) {         edges[index].erase(edges[index].begin() + j);         --j;         continue;       }       father[v] = index;       trace(v);     }   }   void dfs(int index) {     if (edges[index].empty()) {       rCount[index] = 1;       oCount[index] = 1;       eCount[index] = 0;       return;     }     long long totalR = 1;     long long total = 1;     for (int j = 0; j < edges[index].size(); ++j) {       int v = edges[index][j];       dfs(v);       totalR *= rCount[v];       totalR %= modulo;       total *= rCount[v] + eCount[v];       total %= modulo;     }     rCount[index] = totalR;     oCount[index] = 1;     eCount[index] = 0;     for (int j = 0; j < edges[index].size(); ++j) {       int v = edges[index][j];       long long temp = oCount[v] * total;       temp %= modulo;       temp *= inv(rCount[v] + eCount[v]);       temp %= modulo;       rCount[index] += temp;       rCount[index] %= modulo;       oCount[index] *= (rCount[v] + eCount[v]);       oCount[index] %= modulo;       eCount[index] += temp;       eCount[index] %= modulo;     }   }   int main() {     int n;     cin >> n;     if (n == 1) {       cout << 1 << endl;       return 0;     }     int u, v;     for (int i = 0; i < n - 1; ++i) {       scanf( %i%i , &u, &v);       --u;       --v;       edges[u].push_back(v);       edges[v].push_back(u);     }     for (int i = 0; i < n; ++i) {       father[i] = -1;       rCount[i] = 0;       oCount[i] = 0;       eCount[i] = 0;     }     father[0] = -1;     trace(0);     dfs(0);     long long result = rCount[0];     while (result < 0) {       result += modulo;     }     result %= modulo;     cout << result << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = (int)1e2, maxM = (int)1e2, intMax = INT_MAX, maxValue = 44721;   const long long llmax = LLONG_MAX, INF = (long long)1e9 + 1, mod = 998244353;   long long nod(long long a, long long b) {     while (a != 0 && b != 0) {       if (a < b)         b %= a;       else         a %= b;     }     return a + b;   }   int nod(int a, int b) {     while (a != 0 && b != 0) {       if (a < b)         b %= a;       else         a %= b;     }     return a + b;   }   long long nok(long long a, long long b) { return a * b / nod(a, b); }   int nok(int a, int b) { return a * b / nod(a, b); }   long long modPlus(long long a, long long b) {     a %= mod;     b %= mod;     return a + b;   }   long long modPlus(int a, int b) {     a %= mod;     b %= mod;     return (a + b) % mod;   }   long long binPow(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2 == 1) {         res *= a;         res %= mod;       }       a = a * a;       a %= mod;       b >>= 1;     }     return res;   }   int n, s, a, b, emaxx = -1;   int main() {     scanf( %d%d , &n, &s);     s *= 100;     for (int i = 0; i < n; i++) {       scanf( %d%d , &a, &b);       b += a * 100;       if (s >= b) emaxx = max((100 - (b % 100)) % 100, emaxx);     }     printf( %d n , emaxx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       int diff = INT_MAX;       int a1, b1, c1;       for (int i = 1; i <= 10000; i++) {         for (int j = i; j <= 20000; j += i) {           for (int k = j; k <= 50000; k += j) {             int dif = abs(a - i) + abs(b - j) + abs(c - k);             if (dif < diff) {               diff = dif;               a1 = i;               b1 = j;               c1 = k;             }           }         }       }       cout << diff << endl << a1 <<     << b1 <<     << c1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, k, q;   int it[35][800005];   struct point {     int a[10];     point(){};     int &operator[](int x) { return a[x]; }   };   point p[200005];   int sign(point &p, int bit) {     int ans = 0;     for (int i = 0; i < k; i++) {       if (bit & 1 == 1) {         ans += p[i];       } else {         ans -= p[i];       }       bit >>= 1;     }     return ans;   }   void build(int id, int l, int r) {     if (l == r - 1) {       for (int i = 0; i < (1 << k); i++) {         it[i][id] = sign(p[l], i);       }       return;     }     int mid = (l + r) / 2;     build(id * 2, l, mid);     build(id * 2 + 1, mid, r);     for (int i = 0; i < (1 << k); i++) {       it[i][id] = min(it[i][id * 2], it[i][id * 2 + 1]);     }   }   void update(int id, int l, int r, int pos, point &val) {     if (l == r - 1) {       for (int i = 0; i < (1 << k); i++) {         it[i][id] = sign(val, i);       }       return;     }     int mid = (l + r) / 2;     if (pos < mid) {       update(id * 2, l, mid, pos, val);     } else {       update(id * 2 + 1, mid, r, pos, val);     }     for (int i = 0; i < (1 << k); i++) {       it[i][id] = min(it[i][id * 2], it[i][id * 2 + 1]);     }   }   int chosen[35];   void get(int id, int l, int r, int a, int b) {     if (a >= b) return;     if (l == a && r == b) {       for (int i = 0; i < (1 << k); i++) {         chosen[i] = min(chosen[i], it[i][id]);       }       return;     }     int mid = (l + r) / 2;     get(id * 2, l, mid, a, min(mid, b));     get(id * 2 + 1, mid, r, max(mid, a), b);   }   int main() {     cin >> n >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < k; j++) {         cin >> p[i][j];       }     }     build(1, 0, n);     cin >> q;     while (q--) {       int t;       cin >> t;       if (t == 1) {         int x;         cin >> x;         x--;         point cnt;         for (int i = 0; i < k; i++) {           cin >> cnt[i];         }         update(1, 0, n, x, cnt);       }       if (t == 2) {         int l, r;         cin >> l >> r;         l--;         for (int i = 0; i < (1 << k); i++) {           chosen[i] = 1e9;         }         get(1, 0, n, l, r);         int res = 0;         for (int i = 0; i < (1 << k); i++) {           res = max(res, abs(chosen[(1 << k) - i - 1] + chosen[i]));         }         cout << res << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   int N;   int X[206], Y[206];   int D[202][202];   long long area(int i1, int i2, int i3) {     return 1LL * X[i1] * Y[i2] + 1LL * X[i2] * Y[i3] + 1LL * X[i3] * Y[i1] -            1LL * Y[i1] * X[i2] - 1LL * Y[i2] * X[i3] - 1LL * Y[i3] * X[i1];   }   int sign(int i1, int i2, int i3) {     long long val = area(i1, i2, i3);     if (val < 0) return -1;     if (val > 0) return 1;     return 0;   }   bool inpoly(int x, int y) {     int pnx = 1e9 + 7, pny = 1e9 + 9;     X[N + 2] = x;     Y[N + 2] = y;     X[N + 3] = pnx;     Y[N + 3] = pny;     for (int i = 1; i <= N + 1; ++i) {       X[i] *= 2;       Y[i] *= 2;     }     int nn = 0;     for (int i = 1; i <= N; ++i)       if (sign(N + 2, N + 3, i) * sign(N + 2, N + 3, i + 1) == -1 &&           sign(i, i + 1, N + 2) * sign(i, i + 1, N + 3) == -1)         ++nn;     for (int i = 1; i <= N + 1; ++i) {       X[i] /= 2;       Y[i] /= 2;     }     return (nn % 2);   }   bool isok(int i1, int i2) {     if (i1 + 1 == i2 || (i2 == N && i1 == 1)) return true;     for (int i = 1; i <= N; ++i)       if (i != i1 && i != i2) {         if (X[i] < min(X[i1], X[i2]) || X[i] > max(X[i1], X[i2])) continue;         if (Y[i] < min(Y[i1], Y[i2]) || Y[i] > max(Y[i1], Y[i2])) continue;         if (1LL * (Y[i] - Y[i1]) * (X[i2] - X[i]) ==             1LL * (Y[i2] - Y[i]) * (X[i] - X[i1]))           return false;       }     for (int i = 1; i <= N; ++i)       if (i != i1 && i + 1 != i1 && (i + 1) % N != i1)         if (i != i2 && i + 1 != i2 && (i + 1) % N != i2) {           int p1 = i, p2 = i + 1;           if (sign(i1, i2, p1) * sign(i1, i2, p2) == -1 &&               sign(p1, p2, i1) * sign(p1, p2, i2) == -1)             return false;         }     int xn = X[i1] + X[i2];     int yn = Y[i1] + Y[i2];     if (!inpoly(xn, yn)) return false;     return true;   }   int ways(int i1, int i2) {     if (D[i1][i2] != -1) return D[i1][i2];     if (i1 + 1 == i2) return 1;     int& now = D[i1][i2];     now = 0;     if (!isok(i1, i2)) return now;     for (int k = i1 + 1; k <= i2 - 1; ++k)       now = (now + 1LL * ways(i1, k) * ways(k, i2)) % MOD;     return now;   }   int main() {     cin.sync_with_stdio(false);     cin >> N;     for (int i = 1; i <= N; ++i) cin >> X[i] >> Y[i];     X[N + 1] = X[1];     Y[N + 1] = Y[1];     memset(D, -1, sizeof(D));     cout << ways(1, N) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   struct Node {     int a, b, d;   } p[MAXN];   int n, k;   bool cmp(Node aa, Node bb) { return aa.d < bb.d; }   bool cmp2(Node aa, Node bb) { return aa.d > bb.d; }   int main() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &p[i].a);     for (int i = 1; i <= n; i++) {       scanf( %d , &p[i].b);       p[i].d = p[i].a - p[i].b;     }     long long ans = 0;     sort(p + 1, p + 1 + n, cmp);     if (p[1].d >= 0) {       for (int i = 1; i <= k; i++) ans += (long long)p[i].a;       for (int i = k + 1; i <= n; i++) ans += (long long)p[i].b;     } else if (p[n].d <= 0) {       sort(p + 1, p + 1 + n, cmp2);       for (int i = 1; i <= n; i++) {         ans += (long long)p[i].a;       }     } else {       if (p[k].d <= 0) {         for (int i = 1; i <= n; i++) {           if (p[i].d <= 0)             ans += (long long)p[i].a;           else             ans += (long long)p[i].b;         }       } else {         int tmp = 0;         for (int i = 1; i <= n; i++) {           if (p[i].d <= 0) {             ans += (long long)p[i].a;           } else {             tmp = i;             break;           }         }         sort(p + tmp, p + 1 + k, cmp2);         for (int i = tmp; i <= k; i++) {           ans += (long long)p[i].a;         }         for (int i = k + 1; i <= n; i++) {           ans += (long long)p[i].b;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> dp;     dp.push_back(0);     dp.push_back(1);     while (dp.back() <= n - 1) {       dp.push_back(dp[dp.size() - 1] + dp[dp.size() - 2] + 1);     }     cout << dp.size() - 2 << endl;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast ,  unroll-loops )   using namespace std;   const int inf = numeric_limits<int>::max() / 2;   const long double eps = 1e-9;   const long double pi = acos(-1);   inline void solve(), read();   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read();     solve();     return 0;   }   pair<int, int> operator+(pair<int, int> p1, pair<int, int> p2) {     return {p1.first + p2.first, p1.second + p2.second};   }   int q;   map<pair<int, int>, int> l, s;   map<int, set<pair<int, int>>> qs;   int n = 0;   int gcd(int a, int b) {     while (b != 0) {       a %= b;       swap(a, b);     }     return a;   }   pair<int, int> getp(pair<int, int> p) {     int g = gcd(p.first, p.second);     return {p.first / g, p.second / g};   }   void add(pair<int, int> p) {     ++n;     pair<int, int> t = getp(p);     ++l[t];     int d = p.first * p.first + p.second * p.second;     for (pair<int, int> q : qs[d]) {       pair<int, int> u = getp(p + q);       ++s[u];     }     qs[d].insert(p);   }   void del(pair<int, int> p) {     --n;     pair<int, int> t = getp(p);     --l[t];     int d = p.first * p.first + p.second * p.second;     qs[d].erase(p);     for (pair<int, int> q : qs[d]) {       pair<int, int> u = getp(p + q);       --s[u];     }   }   int get(pair<int, int> p) {     pair<int, int> t = getp(p);     return n - l[t] - 2 * s[t];   }   inline void solve() {     for (int i = 0; i < q; i++) {       int t;       pair<int, int> p;       cin >> t >> p.first >> p.second;       if (t == 1) {         add(p);       } else if (t == 2) {         del(p);       } else if (t == 3) {         int ans = get(p);         cout << ans <<   n ;       }     }   }   inline void read() { cin >> q; }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j, k;     double maxm, sum, r;     cin >> n;     double A[n];     for (i = 0; i < n; i++) cin >> A[i];     sort(A, A + n);     maxm = A[n - 1];     for (i = n - 1; i >= 0; i--) {       sum = 0;       for (j = n - 1; j >= i; j--) {         r = A[j];         for (k = n - 1; k >= i; k--) {           if (k != j) r = r * (double(1.0) - A[k]);         }         sum += r;       }       if (sum > maxm) maxm = sum;     }     cout << setprecision(10) << maxm << endl;   }
#include <bits/stdc++.h>   void fre() {     freopen( c://test//input.in ,  r , stdin);     freopen( c://test//output.out ,  w , stdout);   }   template <class T>   inline void gmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline void gmin(T &a, T b) {     if (b < a) a = b;   }   using namespace std;   const int N = 1e5 + 10, M = 0, Z = 1e9 + 7, maxint = 2147483647,             ms31 = 522133279, ms63 = 1061109567, ms127 = 2139062143;   const double eps = 1e-8, PI = acos(-1.0);   int n, m;   int x, y;   int ind[N], s[N], num, top;   vector<int> a[N], b[N];   bool e[N];   void dfs(int x) {     e[x] = 1;     num++;     if (ind[x] == 0) s[++top] = x;     for (int i = a[x].size() - 1; i >= 0; i--) {       int y = a[x][i];       if (!e[y]) dfs(y);     }   }   int main() {     while (~scanf( %d%d , &n, &m)) {       memset(ind, 0, sizeof(ind));       for (int i = 1; i <= n; i++) a[i].clear(), b[i].clear();       for (int i = 1; i <= m; i++) {         scanf( %d%d , &x, &y);         ind[y]++;         a[x].push_back(y);         a[y].push_back(x);         b[x].push_back(y);       }       int ans = 0;       memset(e, 0, sizeof(e));       for (int i = 1; i <= n; i++)         if (!e[i]) {           num = top = 0;           dfs(i);           int sum = top;           while (top) {             int x = s[top--];             for (int j = b[x].size() - 1; j >= 0; j--) {               int y = b[x][j];               ind[y]--;               if (ind[y] == 0) {                 s[++top] = y;                 sum++;               }             }           }           if (sum == num)             ans += (num - 1);           else             ans += num;         }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int a, b, c;       cin >> a >> b >> c;       if (a > b) swap(a, b);       int mx = (b - a) * 2;       if (a > mx || b > mx || c > mx)         cout <<  -1 n ;       else {         if (c > mx / 2)           cout << c - mx / 2 <<   n ;         else           cout << c + mx / 2 <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[50100];   long long m, ans;   struct node {     int s, cnt[30];     node *ch[2];     node();   } * tp, *nul, *root[50100];   int getint() {     char ch;     while (!isdigit(ch = getchar()))       ;     int x = ch -  0 ;     for (; isdigit(ch = getchar()); x = x * 10 + ch -  0 )       ;     return x;   }   node::node() { ch[0] = tp, tp = this; }   node *newnode(node *x) {     if (!tp) new node[50000];     node *t = tp;     tp = t->ch[0], *t = *x;     return t;   }   void insert(node *&x, node *y, int w) {     node *ret = newnode(y);     ++(x = ret)->s;     for (int i = 29; i >= 0; --i) {       for (int j = 0; j <= i; ++j) x->cnt[j] += (w >> j) & 1;       int t = (w >> i) & 1;       x->ch[t] = newnode(y = y->ch[t]), ++(x = x->ch[t])->s;     }     x = ret;   }   int main() {     scanf( %d%I64d , &n, &m);     nul = new node, tp = 0;     memset(nul, 0, sizeof(node));     root[1] = nul->ch[0] = nul->ch[1] = nul;     for (int i = 1; i <= n; ++i) insert(root[i + 1], root[i], a[i] = getint());     for (int i = 29; i >= 0; --i) {       long long sum = 0;       for (int j = 2; j <= n; ++j) sum += root[j]->ch[1 ^ ((a[j] >> i) & 1)]->s;       if (sum < m) {         m -= sum, ans += (1LL << i) * sum;         for (int j = 2; j <= n; ++j) {           node *x = root[j]->ch[1 ^ ((a[j] >> i) & 1)];           for (int k = 0; k <= i - 1; ++k)             ans +=                 (1LL << k) * (((a[j] >> k) & 1) ? x->s - x->cnt[k] : x->cnt[k]);           root[j] = root[j]->ch[(a[j] >> i) & 1];         }       } else {         ans += (1LL << i) * m;         for (int j = 2; j <= n; ++j) root[j] = root[j]->ch[1 ^ ((a[j] >> i) & 1)];       }     }     printf( %d n , ans % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline void read(T& x) {     x = 0;     char s = (char)getchar();     bool f = false;     while (!(s >=  0  && s <=  9 )) {       if (s ==  - ) f = true;       s = (char)getchar();     }     while (s >=  0  && s <=  9 ) {       x = (x << 1) + (x << 3) + s -  0 ;       s = (char)getchar();     }     if (f) x = (~x) + 1;   }   const long long N = 2e6 + 5, mod = 998244353, MAX = 2e6;   long long power[N], fac[N], inv[N];   inline long long quickpow(long long a, long long b, long long p = mod) {     long long res = 1;     while (b) {       if (b & 1) res = res * a % p;       a = a * a % p;       b >>= 1;     }     return res;   }   inline long long C(long long n, long long m) {     if (n < m) return 0;     return fac[n] * inv[m] % mod * inv[n - m] % mod;   }   long long n;   long long ans[N];   void init() {     long long limit = 2e5;     long long x = 810;     ans[1] = 10;     ans[2] = 180;     for (register long long i = 3; i <= limit; ++i) {       ans[i] = ans[i - 1] * 10 + x;       x *= 10;       ans[i] %= mod, x %= mod;     }   }   signed main() {     init();     long long n;     cin >> n;     for (register long long i = n; i >= 1; --i) cout << ans[i] <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int kN = 100 + 1;   const int kA = 256;   bool dp[kN][kN][kA];   bool used[kN][kN][kA];   vector<pair<int, int> > g[kN];   bool Dp(int u, int v, int mark) {     if (!used[u][v][mark]) {       used[u][v][mark] = true;       dp[u][v][mark] = false;       for (const auto& edge : g[u]) {         if (edge.second < mark) {           continue;         }         dp[u][v][mark] = dp[u][v][mark] || !Dp(v, edge.first, edge.second);       }     }     return dp[u][v][mark];   }   void Solve() {     int n, m;     cin >> n >> m;     for (int i = 0; i < m; ++i) {       int u, v;       char ch;       cin >> u >> v >> ch;       g[u - 1].emplace_back(v - 1, int(ch));     }     for (int u = 0; u < n; ++u) {       for (int v = 0; v < n; ++v) {         cout << (Dp(u, v, 0) ?  A  :  B );       }       cout <<   n ;     }   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(NULL);     int tests_count = 1;     for (int test_index = 0; test_index < tests_count; ++test_index) {       Solve();     }     return 0;   }