malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct masivs {     long long in;     long long out;     long long poz;   };   masivs mas[100005];   long long i, j, k, n, m, a, b, c;   vector<pair<pair<long long, long long>, long long> > ab;   int main() {     std::cin.sync_with_stdio(false);     std::cin.tie(0);     cin >> n >> m;     i = 0;     while (i < n) {       mas[i].poz = i;       i++;     }     i = 0;     while (i < m) {       cin >> a >> b >> c;       a--;       b--;       mas[a].in += c;       mas[b].out += c;       k = min(mas[a].in, mas[a].out);       mas[a].in -= k;       mas[a].out -= k;       k = min(mas[b].in, mas[b].out);       mas[b].in -= k;       mas[b].out -= k;       i++;     }     j = 0;     i = 0;     while (i < n) {       while (mas[i].in) {         while (mas[j].out == 0) {           j++;         }         k = min(mas[i].in, mas[j].out);         ab.push_back({{i + 1, j + 1}, k});         mas[i].in -= k;         mas[j].out -= k;       }       i++;     }     cout << ab.size() <<   n ;     for (j = 0; j < ab.size(); j++) {       cout << ab[j].first.first <<     << ab[j].first.second <<                << ab[j].second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const int MAX_N = 5e2 + 5;   int n, f[MAX_N][MAX_N], g[MAX_N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &f[i][i]);     for (int l = 1; l < n; ++l)       for (int i = 1; i + l <= n; ++i)         for (int j = i; j < i + l; ++j)           if (f[i][j] && f[i][j] == f[j + 1][i + l]) f[i][i + l] = f[i][j] + 1;     for (int i = 1; i <= n; ++i) {       g[i] = i;       for (int j = 1; j <= i; ++j)         if (f[j][i]) g[i] = std::min(g[i], g[j - 1] + 1);     }     printf( %d n , g[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 400005;   int n, m, h[N], p[N];   set<int> S;   set<int>::iterator it;   inline void read(int &i) {     i = 0;     char c = getchar();     bool j = 0;     for (; !isdigit(c); c = getchar())       if (c ==  - ) j = 1;     for (; isdigit(c); c = getchar()) i = (i << 1) + (i << 3) + c -  0 ;     i = j ? -i : i;   }   struct Segment_Tree {     int sz, mx[N << 2];     inline void mdf(int u, int l, int r, int x, int y) {       if (l == r) {         mx[u] = y;         return;       }       int mid = (l + r) >> 1;       if (x <= mid)         mdf(u << 1, l, mid, x, y);       else         mdf(u << 1 | 1, mid + 1, r, x, y);       mx[u] = max(mx[u << 1], mx[u << 1 | 1]);     }     inline int qry(int u, int l, int r, int L, int R) {       if (L <= l && r <= R) return mx[u];       int mid = (l + r) >> 1, as = 0;       if (L <= mid) as = max(as, qry(u << 1, l, mid, L, R));       if (mid < R) as = max(as, qry(u << 1 | 1, mid + 1, r, L, R));       return as;     }     inline void mdf(int x, int y) { mdf(1, 0, sz, x, y); }     inline int qry(int l, int r) { return qry(1, 0, sz, l, r); }   } A, B;   int main() {     read(n);     read(m);     A.sz = n + 100;     B.sz = m + 200;     int op, x, y;     for (int tim = 1; tim <= m; ++tim) {       read(op), read(x);       if (op == 1) {         x = n + 1 - x;         read(y);         y = tim + 10 - y;         p[y] = x;         h[x] = y;         S.insert(x);         for (int i = y + 1; i <= y + 9; ++i)           if (p[i]) A.mdf(p[i], 0);         for (int i = y; i <= y + 9; ++i)           if (p[i]) {             int f = A.qry(0, p[i] - 1) + 1;             A.mdf(p[i], f);             B.mdf(i, f);           }       } else {         it = S.end();         while (x--) it--, B.mdf(h[*it], 0);         int del = *it;         A.mdf(*it, 0);         it++;         for (; it != S.end(); it++) {           int f = B.qry(0, h[*it] - 1) + 1;           B.mdf(h[*it], f);           A.mdf(*it, f);         }         S.erase(del);         p[h[del]] = 0;         h[del] = 0;       }       printf( %d n , A.qry(1, n));     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   using namespace std;   const int maxn = 1e4 + 5;   set<string> st3;   int dp[maxn][4];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s1, sx, sy, sz;     cin >> s1;     int len = s1.size();     if (len <= 6)       cout << 0 << endl;     else {       if (len >= 7) {         dp[len - 2][2] = 1;         sx =   ;         sx = sx + s1[len - 2] + s1[len - 1];         st3.insert(sx);       }       if (len >= 8) {         dp[len - 3][3] = 1;         sx =   ;         sx = sx + s1[len - 3] + s1[len - 2] + s1[len - 1];         st3.insert(sx);       }       for (int i = len - 4; i >= 5; i--) {         sx =   ;         sy =   ;         sx = sx + s1[i] + s1[i + 1];         sy = sy + s1[i + 2] + s1[i + 3];         if ((sx != sy && dp[i + 2][2]) || dp[i + 2][3]) {           dp[i][2] = 1;           st3.insert(sx);         }         sx =   ;         sy =   ;         sx = sx + s1[i] + s1[i + 1] + s1[i + 2];         sy = sy + s1[i + 3] + s1[i + 4] + s1[i + 5];         if ((sx != sy && dp[i + 3][3]) || dp[i + 3][2]) {           dp[i][3] = 1;           st3.insert(sx);         }       }       cout << st3.size() << endl;       for (auto& it : st3) cout << it << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int k, c, fact[10010], refact[10010];   int POW(int a, int b) {     int res;     for (res = 1; b; (b & 1) && (res = 1LL * res * a % 1000000007),         a = 1LL * a * a % 1000000007, b >>= 1)       ;     return res;   }   int C(int n, int m) {     if (m > n) return 0;     return 1LL * fact[n] * refact[m] % 1000000007 * refact[n - m] % 1000000007;   }   void Init() {     fact[0] = refact[0] = 1;     for (int i = 1; i <= 1010; ++i) {       fact[i] = 1LL * fact[i - 1] * i % 1000000007;       refact[i] = POW(fact[i], 1000000007 - 2);     }   }   void Work() {     int i, cnt, ans = 1;     scanf( %d%d , &k, &cnt);     for (i = 2; i <= k; ++i) {       scanf( %d , &c);       ans = 1LL * ans * C(cnt + c - 1, cnt) % 1000000007;       cnt += c;     }     printf( %d n , ans);   }   int main() {     Init();     Work();     return 0;   }
#include <bits/stdc++.h>   const int MAXNUM = 255000;   int n;   int m;   int ecnt;   int a[MAXNUM];   int b[MAXNUM];   int inflow[MAXNUM];   int outflow[MAXNUM], direct[MAXNUM];   int head[MAXNUM], to[MAXNUM * 2], next[MAXNUM * 2], c[MAXNUM * 2],       from[MAXNUM * 2];   inline int readint() {     char c = getchar();     while (!isdigit(c)) c = getchar();     int x = 0;     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x;   }   inline void addEdge(int &u, int &v, int &i) {     int x = readint();     outflow[u] += x;     outflow[v] += x;     to[ecnt] = v;     c[ecnt] = x;     from[ecnt] = i;     next[ecnt] = head[u];     head[u] = ecnt++;     to[ecnt] = u;     c[ecnt] = x;     from[ecnt] = i;     next[ecnt] = head[v];     head[v] = ecnt++;   }   void makeDirect() {     std::stack<int> st;     st.push(1);     outflow[1] = 0;     while (!st.empty()) {       int u = st.top();       st.pop();       for (int p = head[u]; p; p = next[p]) {         int &v = to[p];         if (inflow[v] == outflow[v] && v != n) continue;         inflow[v] += c[p];         outflow[v] -= c[p];         if (inflow[v] == outflow[v] && v != n) st.push(v);         int x = from[p];         if (v == a[x]) direct[x] = 1;       }     }   }   int main() {     scanf( %d%d , &n, &m);     ecnt = 1;     for (int i = 0; i < m; ++i) {       a[i] = readint();       b[i] = readint();       addEdge(a[i], b[i], i);     }     makeDirect();     for (int i = 0; i < m; ++i) printf( %d n , direct[i]);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:100000000 )   using namespace std;   vector<vector<int> > g;   vector<int> cl;   int q = 0;   int n;   void dfs(int v) {     cl[v] = q;     if (cl[g[v][0]] == 0) dfs(g[v][0]);   }   void swap(int i, int j) {     g[i][0] = g[j][0] + g[i][0];     g[j][0] = g[i][0] - g[j][0];     g[i][0] = g[i][0] - g[j][0];   }   int calc() {     int ans = 0;     vector<int> t;     t.resize(q + 1, 0);     for (int i = 0; i < n; i++) t[cl[i]]++;     for (int i = 1; i <= q; i++) {       ans += t[i] - 1;     }     return ans;   }   int main() {     cin >> n;     g.resize(n);     cl.assign(n, 0);     int t;     for (int i = 0; i < n; i++) {       cin >> t;       g[i].push_back(t - 1);     }     int m;     cin >> m;     for (int i = 0; i < n; i++) {       if (cl[i] == 0) {         q++;         dfs(i);       }     }     int w = calc();     if (m == w) {       cout << 0;     }     if (m > w) {       cout << m - w <<   n ;       for (int i = 0; i < m - w; i++) {         int v1 = 0, v2 = 1;         while (cl[v1] == cl[v2]) v2++;         cout << v1 + 1 <<     << v2 + 1 <<    ;         swap(v1, v2);         q = 0;         cl.assign(n, 0);         for (int i = 0; i < n; i++) {           if (cl[i] == 0) {             q++;             dfs(i);           }         }       }     }     if (m < w) {       cout << w - m <<   n ;       for (int i = 0; i < w - m; i++) {         int v1 = 0, v2 = 0;         while (g[v1][0] == v1) v1++;         while (cl[v1] != cl[v2] || v1 == v2) v2++;         cout << v1 + 1 <<     << v2 + 1 <<    ;         swap(v1, v2);         q = 0;         cl.assign(n, 0);         for (int i = 0; i < n; i++) {           if (cl[i] == 0) {             q++;             dfs(i);           }         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   long long int ppow(long long int i, long long int j) {     if (i >= 998244353) i %= 998244353;     long long int res = 1LL;     while (j) {       if (j & 1LL) {         res *= i;         if (res >= 998244353) res %= 998244353;       }       i *= i;       if (i >= 998244353) i %= 998244353;       j >>= 1LL;     }     return res;   }   long long int k[1000002];   long long int r[1000002];   long long int C(int a, int b) {     long long int up = k[a];     long long int dw = r[a - b] * r[b];     if (dw >= 998244353) dw %= 998244353;     up *= dw;     if (up >= 998244353) up %= 998244353;     return up;   }   long long int p3[1000002];   int main() {     scanf( %lld , &n);     p3[0] = 1;     for (int i = 1; i < 1000002; i++) {       p3[i] = p3[i - 1];       p3[i] *= 3LL;       if (p3[i] >= 998244353) p3[i] %= 998244353;     }     k[0] = 1LL;     for (int i = 1; i < 1000002; i++) {       k[i] = k[i - 1];       k[i] *= (long long int)(i);       if (k[i] >= 998244353) k[i] %= 998244353;     }     r[1000002 - 1] = ppow(k[1000002 - 1], 998244353 - 2);     for (int i = 1000002 - 2; i >= 0; i--) {       r[i] = r[i + 1] * (long long int)(i + 1);       if (r[i] >= 998244353) r[i] %= 998244353;     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       long long int way = C(n, i) * ppow(3, i);       if (way >= 998244353) way %= 998244353;       way *= ppow(p3[n], n - i);       if (way >= 998244353) way %= 998244353;       if (i & 1) {         ans += way;       } else {         ans += 998244353 - way;       }       if (ans >= 998244353) ans %= 998244353;     }     for (int i = 1; i <= n; i++) {       {         long long int way = 3LL * C(n, i);         if (way >= 998244353) way %= 998244353;         long long int dif_col = ppow(p3[n - i] + 998244353 - 1LL, n);         way *= dif_col;         if (way >= 998244353) way %= 998244353;         if (i & 1) {           ans += way;         } else {           ans += 998244353 - way;         }         if (ans >= 998244353) ans %= 998244353;       }       {         long long int way = ((p3[i] + 998244353 - 3LL) % 998244353) * C(n, i);         if (way >= 998244353) way %= 998244353;         way *= ppow(p3[n - i], n);         if (way >= 998244353) way %= 998244353;         if (i & 1) {           ans += way;         } else {           ans += 998244353 - way;         }         if (ans >= 998244353) ans %= 998244353;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   void rep(const char *s, int x) {     for (int i = 1; i <= x; i++) printf( %s , s);   }   void leading0() {     putchar( 1 );     putchar( r );     rep( 0srt , 30);     rep( lst , 30);     putchar( l );     putchar( e );   }   int main() {     printf( r0l );     rep( l , 31);     leading0();     putchar( u );     leading0();     putchar( u );     putchar( u );     putchar( u );     rep( r1 , 31);     putchar( d );     putchar( d );     putchar( d );     rep( d , 3);     rep( 1l , 31);     putchar( u );     rep( re , 31);     rep( u , 3);     for (int j = 1; j <= 31; j++) {       printf( edsddduuutttt1d0uuudst0 );       putchar( u );       rep( ust , 3);       if (j > 1) {         printf( dddd10utu10rtdr10ltled1uuuu );         printf( edsddduuutttt1d0uuudst0 );         putchar( u );         rep( ust , 3);         printf( dddr01dtl1rt );         printf( uu );         putchar( l );       } else {         putchar( l );         putchar( d );       }     }     putchar( d );     putchar( r );   }
#include <bits/stdc++.h>   using namespace std;   int dp[255][105][105];   int c[255][255];   int cc[1005];   int N;   string s;   int f(char l, int i, int k) {     if (i == N) return 0;     if (dp[l][i][k] != -1) return dp[l][i][k];     int r = f(s[i], i + 1, k) + c[l][s[i]];     if (k) {       for (char x =  a ; x <=  z ; x++) r = max(r, f(x, i + 1, k - 1) + c[l][x]);     }     return dp[l][i][k] = r;   }   int main() {     int k, m;     char x, y;     int z;     cin >> s >> k >> m;     N = s.size();     for (int i = 0; i < m; i++) {       cin >> x >> y >> z;       c[x][y] = z;     }     memset(dp, -1, sizeof(dp));     cout << f( # , 0, k) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     long long n, m, k;     cin >> n >> m >> k;     long long l = 1, r = 1e9 + 1;     while (r - l > 1) {       long long mid = (l + r) / 2;       long long ans = mid;       if (k >= mid) ans += ((mid - 1) * mid) / 2;       if (k > mid) ans += k - mid;       if (k < mid)         ans += (((mid - 1) + (k - mid)) * ((mid - 1) - (k - mid) + 1)) / 2;       long long t = n - k + 1;       if (t >= mid) ans += ((mid - 1) * mid) / 2;       if (t > mid) ans += t - mid;       if (t < mid)         ans += (((mid - 1) + (t - mid)) * ((mid - 1) - (t - mid) + 1)) / 2;       if (ans > m)         r = mid;       else         l = mid;     }     cout << l << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 1e6 + 6;   vector<int> adj[MAX];   bool visited[MAX];   void dfs(int source, int &nodes, int &total) {     total += adj[source].size();     visited[source] = true;     nodes++;     for (auto &each : adj[source]) {       if (!visited[each]) {         dfs(each, nodes, total);       }     }   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = int(0); i < int(m); i++) {       int a, b;       scanf( %d %d , &a, &b);       adj[a].push_back(b);       adj[b].push_back(a);     }     for (int i = int(1); i < int(n + 1); i++) {       if (!visited[i]) {         int total = 0;         int nodes = 0;         dfs(i, nodes, total);         if (total != (1LL * nodes * (nodes - 1))) {           puts( NO );           return 0;         }       }     }     puts( YES );     return 0;   }
#include <bits/stdc++.h>   const double PI = 3.141592653589793238460;   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int max(long long int a, long long int b) {     if (a > b)       return a;     else       return b;   }   long long int min(long long int a, long long int b) {     if (a < b)       return a;     else       return b;   }   long long int power(long long int a, long long int b) {     long long int i, p = 1;     for (i = 0; i < b; i++) {       p *= a;     }     return p;   }   using namespace std;   int main() {     ios::sync_with_stdio(false);     long long int n, i;     cin >> n;     vector<pair<long long int, long long int> > p;     p.push_back({0, 0});     p.push_back({0, 1});     p.push_back({1, 1});     p.push_back({1, 0});     for (i = 0; i < n; i++) {       p.push_back({i + 2, i + 1});       p.push_back({i + 1, i + 2});       p.push_back({i + 2, i + 2});     }     cout << p.size() <<   n ;     for (i = 0; i < p.size(); i++) {       cout << p[i].first <<     << p[i].second <<   n ;     }     return 0;   }
#include <iostream>   #include <vector>   #include <queue>   #include <algorithm>      using ll = long long;   #define MIN(a, b) (((a) < (b)) ? (a) : (b))   #define MAX(a, b) (((a) < (b)) ? (b) : (a))      int const nmax = 400;   int const modulo = 998244353;      int d[1 + nmax][1 + nmax];   std::vector<int> g[1 + nmax];      int main() {     int n, m;     std::cin >> n >> m;     for(int i = 1; i <= m; i++) {       int a, b;       std::cin >> a >> b;       g[a].push_back(b);       g[b].push_back(a);     }     for(int i = 1;i <= n; i++) {       std::queue<int> q;       q.push(i);       for(int j = 1;j <= n; j++)         d[i][j] = -1;       d[i][i] = 0;       while(0 < q.size()) {         int node = q.front();         q.pop();         for(int h = 0; h < g[node].size(); h++) {           int to = g[node][h];           if(d[i][to] == -1) {             d[i][to] = d[i][node] + 1;             q.push(to);           }         }       }     }     for(int i = 1; i <= n; i++) {       for(int j = 1;j <= n; j++) {         int target = d[i][j], on_chain = 0, result = 1;         for(int to = 1; to <= n; to++)            if(d[i][to] + d[j][to] == target)             on_chain++;           else {             int p = 0;             for(int h = 0; h < g[to].size(); h++) {               int oth = g[to][h];               if(d[i][oth] + 1 == d[i][to] && d[j][oth] + 1 == d[j][to])                 p++;             }             result = 1LL * result * p % modulo;           }                  if(on_chain != target + 1)           result = 0;         std::cout << result <<    ;       }       std::cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return a % b ? gcd(b, a % b) : b; }   int main() {     int n;     while (cin >> n) {       int sum = 0;       for (int i = 2; i < n; i++) {         int t = n;         while (t) {           sum += t % i;           t /= i;         }       }       int g = gcd(sum, n - 2);       cout << sum / g <<  /  << (n - 2) / g << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     double arr[105];     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %lf , &arr[i]);     sort(arr, arr + n);     reverse(arr, arr + n);     double Max = 0;     double prev = 0, a = 0, b = 1;     for (int i = 0; i < n; i++) {       a = (a * (1 - arr[i])) + arr[i] * b;       b *= (1 - arr[i]);       Max = max(Max, a);     }     printf( %.10lf n , Max);     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1024000000,1024000000 )   using namespace std;   const long long inf = 0x3f3f3f3f3f3f3f3f;   const int maxn = 100005;   int main() {     int n;     long long r;     scanf( %d %lld , &n, &r);     n = 1 << n;     int c[n];     double sum = 0;     for (int i = 0; i < n; i++) scanf( %d , &c[i]), sum += c[i];     printf( %.6f n , sum / n);     for (int i = 0; i < r; i++) {       int z, g;       scanf( %d %d , &z, &g);       sum = sum - c[z] + g;       c[z] = g;       printf( %.6f n , sum / n);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   const int maxm = 5e3 + 110;   double dp[maxn][maxm];   struct node {     int f, s;     double p;   } a[maxn];   int main() {     int n, R;     scanf( %d %d , &n, &R);     for (int i = 1; i <= n; i++) {       scanf( %d %d %lf , &a[i].f, &a[i].s, &a[i].p);       a[i].p = a[i].p / 100.0;     }     double l = 0, r = 1e15, ans = 0;     for (int ii = 0; ii <= 100; ii++) {       double mid = (l + r) / 2.0;       for (int j = 0; j <= R; j++) dp[n + 1][j] = j;       for (int j = R + 1; j <= 5100; j++) dp[n + 1][j] = 0x3f3f3f3f;       for (int i = n; i >= 1; i--) {         for (int j = 5005; j >= 0; j--) {           dp[i][j] = dp[i + 1][j + a[i].f] * a[i].p +                      dp[i + 1][j + a[i].s] * (1 - a[i].p);           dp[i][j] =               min(dp[i][j], dp[i + 1][j + a[i].f] * a[i].p +                                 (1 - a[i].p) * (mid + (double)(j + a[i].s)));           dp[i][j] =               min(dp[i][j], a[i].p * ((double)(j + a[i].f) + mid) +                                 (1 - a[i].p) * ((double)(j + mid) + a[i].s));         }       }       if (dp[1][0] >= mid) {         ans = mid;         l = mid;       } else         r = mid;     }     printf( %.9f n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   int a[maxn];   int b[maxn];   int n;   vector<pair<int, int>> v;   void borrow(int pos, int val) {     if (val == 1) {       if (a[pos + 1] == 0) borrow(pos + 1, -1);       if (v.size() >= 100000) return;       v.push_back(make_pair(pos, -1));       a[pos + 1]--;       a[pos]--;     } else {       if (a[pos + 1] == 9) borrow(pos + 1, 1);       if (v.size() >= 100000) return;       v.push_back(make_pair(pos, 1));       a[pos + 1]++;       a[pos]++;     }   }   void solve() {     for (int i = 1; i <= n - 1; i++) {       while (a[i] != b[i]) {         if (a[i] < b[i]) {           if (a[i + 1] == 9) {             borrow(i + 1, 1);           }           if (v.size() >= 100000) return;           v.push_back(make_pair(i, 1));           a[i]++;           a[i + 1]++;         } else {           if (a[i + 1] == 0) {             borrow(i + 1, -1);           }           if (v.size() >= 100000) return;           v.push_back(make_pair(i, -1));           a[i]--;           a[i + 1]--;         }       }     }   }   int main() {     while (cin >> n) {       v.clear();       char c;       for (int i = 1; i <= n; i++) {         cin >> c;         a[i] = c -  0 ;       }       for (int i = 1; i <= n; i++) {         cin >> c;         b[i] = c -  0 ;       }       long long ans = 0;       int temp = a[1];       for (int i = 1; i <= n - 1; i++) {         ans += abs(b[i] - temp);         temp = a[i + 1] + b[i] - temp;       }       if (temp != b[n]) {         cout << -1 << endl;         continue;       }       cout << ans << endl;       solve();       for (int i = 0; i < v.size(); i++) {         cout << v[i].first <<     << v[i].second << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[110];   char s[2];   int n, m, x, y, f[110][110][27];   int dp(int x, int y, int k) {     if (f[x][y][k] != 0) return f[x][y][k];     int ret = 1;     for (auto e : g[x])       if (e.second >= k) ret = min(ret, dp(y, e.first, e.second));     f[x][y][k] = -ret;     return f[x][y][k];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%s , &x, &y, s);       g[x].push_back(pair<int, int>(y, s[0] -  a ));     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         for (int k = 0; k < 26; k++) f[i][j][k] = dp(i, j, k);         if (f[i][j][0] > 0)           cout <<  A ;         else           cout <<  B ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int d[2005];   queue<int> q;   int main() {     int n, k, i, a;     scanf( %d %d , &n, &k);     for (i = 0; i <= 2000; i++) d[i] = 999999;     for (i = 1; i <= k; i++) {       scanf( %d , &a);       d[a - n + 1000] = 1;     }     for (i = 0; i <= 2000; i++)       if (d[i] == 1) q.push(i);     while (q.size()) {       a = q.front();       q.pop();       for (i = 0; i <= 2000; i++)         if (d[i] == 1 && d[a + i - 1000] == 999999) {           q.push(a + i - 1000);           d[a + i - 1000] = d[a] + 1;         }     }     if (d[1000] == 999999)       cout << -1 << endl;     else       cout << d[1000] << endl;     return 0;   }