malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int A[10010];   int B[10010];   bool check(int st, int ed) {     int mx = st;     for (int i = st; i <= ed; i++) {       if (A[i] > A[mx]) {         mx = i;       }       if (A[i] == A[mx]) {         if (st <= i - 1 && A[i - 1] < A[i]) mx = i;         if (i + 1 <= ed && A[i + 1] < A[i]) mx = i;       }     }     bool can = false;     if (st <= mx - 1 && A[mx - 1] < A[mx]) can = true;     if (mx + 1 <= ed && A[mx + 1] < A[mx]) can = true;     return can || (st == ed);   }   void consume(int st, int ed) {     int mx = st;     for (int i = st; i <= ed; i++) {       if (A[i] > A[mx]) {         mx = i;       }       if (A[i] == A[mx]) {         if (st <= i - 1 && A[i - 1] < A[i]) mx = i;         if (i + 1 <= ed && A[i + 1] < A[i]) mx = i;       }     }     if (mx + 1 <= ed && A[mx + 1] < A[mx]) {       for (int i = mx + 1; i <= ed; i++) {         printf( %d R n , mx + 1);       }       for (int j = mx - 1; j >= st; j--) {         printf( %d L n , j + 1 + 1);       }     } else if (st <= mx - 1 && A[mx - 1] < A[mx]) {       for (int j = mx - 1; j >= st; j--) {         printf( %d L n , j + 1 + 1);       }       for (int i = mx + 1; i <= ed; i++) {         printf( %d R n , st + 1);       }     }   }   int main() {     for (;;) {       int N;       if (scanf( %d , &N) == EOF) break;       for (int i = 0; i < N; i++) {         scanf( %d , &A[i]);       }       int M;       scanf( %d , &M);       for (int i = 0; i < M; i++) {         scanf( %d , &B[i]);       }       int j = 0;       int sum = 0;       bool possible = true;       vector<int> part;       part.push_back(-1);       for (int i = 0; i < N; i++) {         sum += A[i];         if (j < M && sum == B[j]) {           possible &= check(part.back() + 1, i);           part.push_back(i);           if (!possible) break;           sum = 0;           j += 1;         }       }       if (sum > 0 || j < M) possible = false;       if (possible) {         printf( YES n );         for (int i = part.size() - 2; i >= 0; i--) {           consume(part[i] + 1, part[i + 1]);         }       } else {         printf( NO n );       }     }   }
#include <bits/stdc++.h>   using namespace std;   string s[505];   int n, par[505][505], a[505 * 505] = {0}, v[505 * 505] = {0}, p[505 * 505];   bool b[505 * 505] = {0};   int dfs(int x, int y, int k) {     par[x][y] = k;     int ret = 1;     if (x > 0 && par[x - 1][y] == -1 && s[x - 1][y] ==  . )       ret += dfs(x - 1, y, k);     if (x + 1 < n && par[x + 1][y] == -1 && s[x + 1][y] ==  . )       ret += dfs(x + 1, y, k);     if (y > 0 && par[x][y - 1] == -1 && s[x][y - 1] ==  . )       ret += dfs(x, y - 1, k);     if (y + 1 < n && par[x][y + 1] == -1 && s[x][y + 1] ==  . )       ret += dfs(x, y + 1, k);     return ret;   }   void reset(int bx, int ex, int by, int ey) {     int i, j;     for (i = bx; i <= ex; i++) {       for (j = by; j <= ey; j++) b[par[i][j]] = 0;     }   }   int get_sum(int bx, int ex, int by, int ey) {     int i, j, ret = 0, u;     for (i = bx; i <= ex; i++) {       for (j = by; j <= ey; j++) {         if (s[i][j] ==  X ) continue;         u = par[i][j];         if (v[u] == 0 && b[u] == 0) ret += a[u];         b[u] = 1;       }     }     return ret;   }   int main() {     std::ios_base::sync_with_stdio(0);     int cases, caseno = 0, i, j, k, t, u, mx, sum, temp, sz = 0;     cin >> n >> k;     for (i = 0; i <= n - 1; i++) cin >> s[i];     memset(par, -1, sizeof(par));     for (i = 0; i <= n - 1; i++) {       for (j = 0; j <= n - 1; j++) {         if (s[i][j] ==  X ) {           par[i][j] = sz;           a[sz++] = 1;         } else if (par[i][j] == -1) {           a[sz] = dfs(i, j, sz);           sz++;         }       }     }     mx = 0;     for (i = 0; i <= n - k; i++) {       sum = 0;       memset(v, 0, sizeof(v));       for (t = i; t <= i + k - 1; t++) {         for (j = 0; j <= k - 1; j++) {           v[par[t][j]]++;           if (v[par[t][j]] == 1) sum += a[par[t][j]];         }       }       for (j = 0; j <= n - k; j++) {         temp = 0;         if (j > 0) {           for (t = i; t <= i + k - 1; t++) {             u = par[t][j - 1];             v[u]--;             if (v[u] == 0) sum -= a[u];           }           for (t = i; t <= i + k - 1; t++) {             u = par[t][j + k - 1];             v[u]++;             if (v[u] == 1) sum += a[u];           }         }         if (i > 0) reset(i - 1, i - 1, j, j + k - 1);         if (i + k < n) reset(i + k, i + k, j, j + k - 1);         if (j > 0) reset(i, i + k - 1, j - 1, j - 1);         if (j + k < n) reset(i, i + k - 1, j + k, j + k);         if (i > 0) temp += get_sum(i - 1, i - 1, j, j + k - 1);         if (i + k < n) temp += get_sum(i + k, i + k, j, j + k - 1);         if (j > 0) temp += get_sum(i, i + k - 1, j - 1, j - 1);         if (j + k < n) temp += get_sum(i, i + k - 1, j + k, j + k);         mx = max(mx, sum + temp);       }     }     cout << mx <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[16], d[40000], vis[40000];   int main() {     ios::sync_with_stdio(0);     int n, x, i, j, k, l0, m, m0, m1, c;     long long l, r, v, ans = 0;     cin >> n >> l >> r >> x;     for (i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + n + 1);     for (i = 1, m = 1; i <= n; i++) {       m0 = m;       for (j = 0; j < m0; j++, m++) {         m1 = m;         c = 1;         while (!(m1 & 1)) c++, m1 = m1 >> 1;         d[m] = a[i] + d[j];         if (j && a[i] - a[c] >= x) vis[m] = 1;         if (vis[m] && d[m] >= l && d[m] <= r) ans++;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   inline int read(T &a) {     a = 0;     char c = getchar(), f = 1;     while (c >  9  || c <  0 ) {       if (c ==  - ) f = (~f) + 1;       if (c == -1) return -1;       c = getchar();     }     while (c <=  9  && c >=  0 )       a = (a << 1) + (a << 3) + (c ^ 48), c = getchar();     a *= f;     return 1;   }   template <typename T>   inline int write(T a) {     if (a < 0) putchar( - ), a = (~a) + 1;     if (a / 10) return write(a / 10) & putchar(a % 10 | 48);     return putchar(a | 48);   }   template <typename T>   inline int write(T a, char c) {     return write(a) + putchar(c);   }   int n, m;   int w[200001];   int x[200001], y[200001];   int need[200001];   bool used[200001];   vector<int> v[200001];   bool ok[200001];   queue<int> q;   int ans[200001], cnt;   int main() {     read(n), read(m);     for (int i = 1; i <= n; i++) read(w[i]);     for (int i = 1; i <= m; i++) {       read(x[i]), read(y[i]), need[x[i]]++, need[y[i]]++;       v[x[i]].push_back(i);       v[y[i]].push_back(i);     }     for (int i = 1; i <= n; i++)       if (need[i] <= w[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }     while (!q.empty()) {       int t = q.front();       q.pop();       ans[++cnt] = t;       need[x[t]]--, need[y[t]]--;       int i = y[t];       if (need[i] <= w[i] && !used[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }       i = x[t];       if (need[i] <= w[i] && !used[i]) {         used[i] = 1;         for (auto j : v[i])           if (!ok[j]) {             ok[j] = 1;             q.push(j);           }       }     }     if (cnt != m) return puts( DEAD ) & 0;     puts( ALIVE );     for (int i = cnt; i >= 1; i--) write(ans[i],    );     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int i, j, n, k, imp, c, h;     int f[200];     {       imp = 0;       memset(f, 0, sizeof(f));       cin >> k;       cin >> s;       n = ((int)s.size());       h = n % 2 + n / 2;       for (i = 0; i < n; i++)         if (isalpha(s[i])) f[s[i] -  a ]++;       for (i = h - 1; i > -1; i--) {         if (s[i] != s[n - i - 1]) {           if (isalpha(s[i]) && isalpha(s[n - i - 1])) {             imp = 1;             break;           } else if (isalpha(s[i]))             s[n - i - 1] = s[i];           else             s[i] = s[n - i - 1];         } else if (s[i] ==  ? ) {           c = 0;           for (j = k - 1; j > -1; j--)             if (f[j] == 0) {               c = j;               f[j]++;               break;             }           s[i] = s[n - i - 1] =  a  + c;         }       }       if (imp == 0) {         for (i = 0; i < k; i++)           if (!f[i]) {             imp = 1;             break;           }       }       if (!imp)         cout << s << endl;       else         cout <<  IMPOSSIBLE  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int N = 1e6 + 5;   int n, cnt[3], dp[N], sum = 1;   int add(int x, int y) { return (1ll * x + 1ll * y) % mod; }   int mul(int x, int y) { return (1ll * x * 1ll * y) % mod; }   int del(int x, int y) { return ((1ll * x - 1ll * y) % mod + mod) % mod; }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x;       scanf( %d , &x);       cnt[x]++;     }     dp[0] = 1;     dp[1] = 1;     for (int i = 2; i <= cnt[1]; i++)       dp[i] = add(dp[i - 1], mul(dp[i - 2], i - 1));     for (int i = 1; i <= cnt[2]; i++) sum = mul(sum, cnt[1] + i);     printf( %d , mul(sum, dp[cnt[1]]));   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   pair<long long, long long> a[N];   long long top, k, n, avr, mx;   int main() {     scanf( %d %d %d , &n, &mx, &avr);     for (int i = 1; i <= n; i++) {       int b, r;       scanf( %d %d , &b, &r);       a[i] = make_pair(r, b);       top += b;     }     sort(a + 1, a + 1 + n);     long long tmp = 0, i = 1;     while (top < avr * n) {       long long t = min(avr * n - top, mx - a[i].second);       top += t;       tmp += t * a[i].first;       i++;     }     cout << tmp << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ch[55][55];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) cin >> ch[i][j];     int ret = 0;     for (int i = 0; i < n - 1; i++)       for (int j = 0; j < m - 1; j++) {         bool f = 0, a = 0, c = 0, e = 0;         for (int h = i; h < i + 2; h++)           for (int k = j; k < j + 2; k++)             if (ch[h][k] ==  f )               f = 1;             else if (ch[h][k] ==  a )               a = 1;             else if (ch[h][k] ==  c )               c = 1;             else if (ch[h][k] ==  e )               e = 1;         if (f && a && c && e) ret++;       }     cout << ret << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (s.size() == 1) {         if (s[0] ==  ? )           printf( a n );         else           cout << s <<   n ;       } else {         int f = 0;         for (int i = 0; i < s.size(); i++) {           if (s[i] == s[i + 1] && s[i] !=  ? ) {             f = 1;             break;           }         }         if (f == 1)           printf( -1 n );         else {           char ch =  a ;           for (int i = 0; i < s.size() - 1; i++) {             if (s[i] ==  ?  && i == 0) {               for (char c =  a ; c <=  c ; c++) {                 if (s[i + 1] != c) {                   s[i] = c;                   break;                 }               }             } else if (s[i] ==  ? ) {               for (char c =  a ; c <=  c ; c++) {                 if (s[i + 1] != c && s[i - 1] != c) {                   s[i] = c;                   break;                 }               }             }           }           if (s[s.size() - 1] ==  ? ) {             for (char c =  a ; c <=  c ; c++) {               if (s[s.size() - 2] != c) {                 s[s.size() - 1] = c;                 break;               }             }           }           cout << s <<   n ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long tcc, n, m;   int main() {     scanf( %lld , &tcc);     while (tcc--) {       scanf( %lld %lld , &n, &m);       unsigned long long sum = 0, m2 = m, t = 10;       while (t-- && m2 <= n) {         sum += m2 % 10;         m2 += m;       }       m2 = m * 10;       t = n / m2;       sum *= t;       n -= m2 * t;       m2 = m;       while (m2 <= n) {         sum += m2 % 10;         m2 += m;       }       printf( %lld n , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long SIZE = 100000;   const int INF = 0x3f3f3f3f;   const long long ll_INF = 0x3f3f3f3f3f3f3f3f;   const long double PI = acos(-1);   const long long MAXN = numeric_limits<long long>::max();   const long long MAX = 2000000;   void solve() {     string s;     long long k, i = 1;     cin >> k;     while (((int)(s).size()) < k) {       s += to_string(i);       i++;     }     cout << s[k - 1];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long x[100002];   vector<int> P[2 * 100002];   void NoSol() {     printf( No n );     exit(0);   }   long long sqr(int x) { return 1LL * x * x; }   int bs(int x, long long val) {     int i = -1, sz = P[x].size(), p = 1;     while (p < sz) p <<= 1;     while (p) {       if (i + p < sz && sqr(P[x][i + p]) <= val) i += p;       p >>= 1;     }     return i + 1;   }   int main() {     int n;     long long Xmax = 0;     scanf( %d , &n);     for (int i = 0; i < n / 2; ++i) {       scanf( %lld , &x[i * 2 + 1]);       Xmax = max(Xmax, x[i * 2 + 1]);       if (x[i * 2 + 1] % 4 == 2) NoSol();     }     long long s = 0;     for (int a = 1; a < Xmax; ++a)       for (int b = a + 1; sqr(b) - sqr(a) <= Xmax; ++b)         P[sqr(b) - sqr(a)].push_back(a);     long long sum = 0;     for (int i = 0; i < n / 2; ++i) {       long long X = x[i * 2 + 1];       if (P[X].empty()) NoSol();       if (sqr(P[X].back()) <= sum) NoSol();       x[i * 2] = sqr(P[X][bs(X, sum)]) - sum;       sum = sum + x[i * 2] + X;     }     printf( Yes n );     s = 0;     for (int i = 0; i < n; ++i) {       printf( %lld  , x[i]);       s += x[i];       long long r = sqrt(s);       if (r * r != s)         while (1)           ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, k, m, a[100100], sum = 0;     priority_queue<pair<long long, long long>,                    vector<pair<long long, long long> >,                    greater<pair<long long, long long> > >         pq;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];       pq.push(make_pair(a[i], i));     }     if (sum < k) {       cout << -1 << endl;       return 0;     }     long long last = 0;     while (!pq.empty()) {       long long x = pq.top().first;       if ((x - last) * pq.size() <= k) {         k -= (x - last) * pq.size();         last = x;         while (!pq.empty()) {           if (pq.top().first == x)             pq.pop();           else             break;         }       } else         break;     }     long long temp = pq.size();     if (temp == 0) return 0;     m = k % temp;     long long o = k / temp;     for (int i = 1; i <= n; i++) a[i] -= (last + o);     deque<long long> dq;     m = k % temp;     for (int i = 1; i <= n; i++) {       if (a[i] > 0) dq.push_back(i);     }     for (int i = 0; i < m; i++) {       if (dq.empty()) return 0;       long long x = dq.front();       dq.pop_front();       if (a[x] > 0) dq.push_back(x);       a[x]--;     }     while (!dq.empty()) {       if (a[dq.front()] > 0) cout << dq.front() <<    ;       dq.pop_front();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, p, q;   unsigned int C[132];   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int a[132];   void Init() {     C[0] = 1;     for (int i = 1; i <= min(p, n - 1); ++i) {       a[0] = 0;       for (int j = 0; j < i; ++j) a[++a[0]] = n - j;       for (int k = 1; k <= i; ++k) {         int x = k;         for (int j = 1; j <= a[0] && k != 1; ++j) {           int Gcd = gcd(x, a[j]);           a[j] /= Gcd, x /= Gcd;         }       }       C[i] = 1;       for (int j = 1; j <= a[0]; ++j) C[i] = C[i] * a[j];     }   }   int main() {     scanf( %d%d%d , &n, &p, &q), Init();     unsigned int ans = 0;     for (int i = 1; i <= q; ++i) {       unsigned int tmp = 0, now = 1;       for (int j = 0; j <= min(p, n - 1); ++j, now = now * i) tmp += C[j] * now;       ans ^= tmp * i;     }     printf( %u n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sgn(T x) {     return x < 0 ? -1 : x != 0;   }   template <typename T>   T gcd(T a, T b) {     return a ? gcd(b % a, a) : b;   }   void reads(string& x) {     char kk[((long long)5e2 + 123)];     scanf( %s , kk);     x = kk;   }   long long n, m, ans;   long long v, r[((long long)5e2 + 123)], c[((long long)5e2 + 123)];   long long lp[(long long)1e6 + 1];   vector<long long> pr;   void sieve() {     for (long long i = 2; i <= 1e6; ++i) {       if (lp[i] == 0) {         lp[i] = i;         pr.push_back(i);       }       for (long long j = 0;            j < (long long)pr.size() && pr[j] <= lp[i] && i * pr[j] <= 1e6; ++j)         lp[i * pr[j]] = pr[j];     }   }   void solve() {     sieve();     scanf( %lld %lld , &n, &m);     for (long long i = 0; i < n; i++)       for (long long j = 0; j < m; j++) {         scanf(  %lld , &v);         v = (*lower_bound(pr.begin(), pr.end(), v) - v);         r[i] += v;         c[j] += v;       }     ans = 1e9;     for (long long i = 0; i < n; i++) ans = min(ans, r[i]);     for (long long i = 0; i < m; i++) ans = min(ans, c[i]);     printf( %lld n , ans);   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   vector<int> v[100005];   bool d[100005];   int s[100005];   void del(int i, int par) {     if (v[i].size() <= 2) {       d[i] = true;       for (int j : v[i])         if (j != par) del(j, i);     }   }   int main() {     int n;     cin >> n;     int a, b;     for (int i = 1; i < n; i++) {       cin >> a >> b;       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 1; i <= n; i++) {       if (v[i].size() == 1) del(i, 0);     }     for (int i = 1; i <= n; i++) {       for (int j : v[i])         if (d[j]) s[i] = min(s[i] + 1, 2);     }     for (int i = 1; i <= n; i++)       if (!d[i]) {         int cnt = 0;         for (int j : v[i])           if (!d[j] && v[j].size() - s[j] > 1) cnt++;         if (cnt > 2) {           cout <<  No n ;           return 0;         }       }     cout <<  Yes n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int INF = 1e18;   const int inf = 1e9;   const int MOD = 1e9 + 7;   const int nax = 1000000 + 10;   int main() {     ios::sync_with_stdio(0);     double a, b, m, t, dx, dz, mz, mx, vx, vy, vz, ansx, ansz;     int pz, px;     cin >> a >> b >> m;     cin >> vx >> vy >> vz;     t = m / abs(vy);     dz = t * vz;     pz = dz / b;     mz = dz - pz * b;     if ((int)pz % 2 == 0)       ansz = mz;     else       ansz = b - mz;     dx = abs(vx) * t;     if (dx <= a / 2)       ansx = a / 2 + dx;     else {       dx -= a / 2;       px = dx / a;       mx = dx - px * a;       if ((int)px % 2 == 0)         ansx = a - mx;       else         ansx = mx;     }     if (vx < 0) {       ansx = a - ansx;     }     cout << fixed << setprecision(8) << ansx << endl;     cout << ansz << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007LL;   long long large = 2000000000000000000LL;   vector<int> p;   int f(int x) { return p[x] == x ? x : p[x] = f(p[x]); }   vector<vector<pair<int, int> > > adj;   int main() {     int n, m, a, b;     cin >> n >> m >> a >> b;     p.assign(n, 0);     adj.assign(n, vector<pair<int, int> >());     for (int i = 0; i < n; i++) p[i] = i;     for (int i = 0; i < m; i++) {       int x, y, z;       cin >> x >> y >> z;       x--;       y--;       int t = 0;       if (z == b) t = 1;       adj[x].push_back(pair<int, int>(y, t));       adj[y].push_back(pair<int, int>(x, t));       if (t == 0) p[f(x)] = f(y);     }     map<int, int> comp;     int sz = 0;     for (int i = 0; i < n; i++) {       if (comp.find(f(i)) == comp.end()) comp[f(i)] = sz++;     }     vector<vector<int> > cc(sz, vector<int>());     for (int i = 0; i < n; i++) cc[comp[f(i)]].push_back(i);     sz = 0;     comp.clear();     for (int i = 0; i < (int)cc.size(); i++) {       if ((int)cc[i].size() > 3) comp[f(cc[i][0])] = sz++;     }     vector<vector<int> > dis(1 << sz, vector<int>(n, 1000000010));     dis[0][0] = 0;     priority_queue<pair<int, pair<int, int> >,                    vector<pair<int, pair<int, int> > >,                    greater<pair<int, pair<int, int> > > >         pq;     pq.push(pair<int, pair<int, int> >(0, pair<int, int>(0, 0)));     while (!pq.empty()) {       pair<int, pair<int, int> > front = pq.top();       pq.pop();       int mask = front.second.first;       int u = front.second.second;       if (front.first > dis[mask][u]) continue;       for (int j = 0; j < (int)adj[u].size(); j++) {         int v = adj[u][j].first;         int ty = adj[u][j].second;         if (ty == 0) {           int cost = dis[mask][u] + a;           if (dis[mask][v] > cost) {             dis[mask][v] = cost;             pq.push(pair<int, pair<int, int> >(dis[mask][v],                                                pair<int, int>(mask, v)));           }         } else {           int cost = dis[mask][u] + b;           if (f(u) != f(v)) {             int vmask = mask;             if (comp.find(f(v)) != comp.end()) {               if (mask & (1 << comp[f(v)])) continue;             }             if (comp.find(f(u)) != comp.end()) {               vmask |= (1 << comp[f(u)]);             }             if (dis[vmask][v] > cost) {               dis[vmask][v] = cost;               pq.push(pair<int, pair<int, int> >(dis[vmask][v],                                                  pair<int, int>(vmask, v)));             }           }         }       }     }     vector<int> dp(n, 1000000010);     for (int i = 0; i < n; i++) {       for (int j = 0; j < (1 << sz); j++) {         dp[i] = min(dp[i], dis[j][i]);       }     }     for (int i = 0; i < n; i++) cout << dp[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n;     string s;     cin >> n >> s;     if (count(s.begin(), s.end(), s[0]) == s.size() || s.size() == 1) {       cout <<  NO  << endl;     } else {       cout <<  YES  << endl;       for (int i = 0; i < s.size() - 1; i++) {         if (s[i] != s[i + 1]) {           cout << s[i] << s[i + 1];           exit(0);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int need, e;   int mat[128][128];   bool found;   int add;   int v;   int main() {     memset(mat, 0, sizeof mat);     cin >> need;     e = 0;     while (e < need) {       found = false;       for (int i = 1; i <= v && found == false; i++)         for (int j = i + 1; j <= v && found == false; j++) {           if (mat[i][j] == 1) continue;           add = 0;           for (int k = 1; k <= v; k++) {             if (k == i || k == j) continue;             if (mat[i][k] && mat[k][j]) add++;           }           if (e + add <= need) {             found = true;             e += add;             mat[i][j] = 1;             mat[j][i] = 1;           }         }       if (found == false) v++;     }     cout << v << endl;     for (int i = 1; i <= v; i++) {       for (int j = 1; j <= v; j++) cout << mat[i][j];       cout << endl;     }     return 0;   }