malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long modpow(long long a, long long p, long long mod) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a) % mod;       a = (a * a) % mod;       p /= 2;     }     return ret;   }   long long power(long long a, long long p) {     long long ret = 1;     while (p) {       if (p & 1) ret = (ret * a);       a = (a * a);       p /= 2;     }     return ret;   }   int n, m;   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   bool check(int i, int j) {     if (i >= 0 && j >= 0 && i < n && j < m) return 1;     return 0;   }   int v[2015][2015] = {0}, deg[2015][2015] = {0};   string mat[2015];   queue<pair<int, int> > q;   pair<int, int> p;   int main() {     int i, j, tmp;     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cin >> n >> m;     int x, y, xx, yy;     for (i = 0; i < n; i++) cin >> mat[i];     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if (mat[i][j] ==  . )           for (x = 0; x < 4; x++) {             y = x;             if (check(i + dx[x], j + dy[y]) && mat[i + dx[x]][j + dy[y]] ==  . )               deg[i][j]++;           }         if (deg[i][j] == 1) q.push(make_pair(i, j));       }     }     while (!q.empty()) {       pair<int, int> p;       p = q.front();       q.pop();       i = p.first;       j = p.second;       for (x = 0; x < 4; x++) {         y = x;         if (check(i + dx[x], j + dy[y]) && mat[i + dx[x]][j + dy[y]] ==  . ) {           if (dx[x] == 1) {             mat[i][j] =  ^ ;             mat[i + dx[x]][j + dy[y]] =  v ;           } else if (dx[x] == -1) {             mat[i][j] =  v ;             mat[i + dx[x]][j + dy[y]] =  ^ ;           } else if (dy[y] == 1) {             mat[i][j] =  < ;             mat[i + dx[x]][j + dy[y]] =  > ;           } else if (dy[y] == -1) {             mat[i][j] =  > ;             mat[i + dx[x]][j + dy[y]] =  < ;           }           for (xx = 0; xx < 4; xx++) {             yy = xx;             if (check(i + dx[xx], j + dy[yy])) {               deg[i + dx[xx]][j + dy[yy]]--;               if (mat[i + dx[xx]][j + dy[yy]] ==  .  &&                   deg[i + dx[xx]][j + dy[yy]] == 1)                 q.push(make_pair(i + dx[xx], j + dy[yy]));             }             if (check(i + dx[x] + dx[xx], j + dy[y] + dy[yy])) {               deg[i + dx[x] + dx[xx]][j + dy[y] + dy[yy]]--;               if (mat[i + dx[x] + dx[xx]][j + dy[y] + dy[yy]] ==  .  &&                   deg[i + dx[x] + dx[xx]][j + dy[y] + dy[yy]] == 1)                 q.push(make_pair(i + dx[x] + dx[xx], j + dy[y] + dy[yy]));             }           }           break;         }       }     }     int f = 1;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++)         if (mat[i][j] ==  . ) f = 0;     if (f) {       for (i = 0; i < n; i++) {         for (j = 0; j < m; j++) cout << mat[i][j];         cout << endl;       }     } else       cout <<  Not unique n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first == b.first && a.second < b.second) return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, d;     cin >> n >> m >> d;     long long int a[n * m];     for (long long int i = 0; i < n * m; i++) cin >> a[i];     long long int ans = 0;     sort(a, a + (n * m));     for (long long int i = 0; i < n * m; i++) ans += abs(a[i] - a[n * m / 2]);     if (ans % d == 0)       cout << ans / d <<   n ;     else       cout <<  -1 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 10010;   vector<pair<short int, short int> > G[MAXN];   vector<short int> cul[MAXN], row[MAXN];   pair<short int, short int> p[MAXN];   void add_edge(int u, int v, int d) { G[u].push_back(make_pair(v, d)); }   void init(int n) {     for (int i = 1; i <= n; i++) {       G[i].clear();     }   }   bool vis[MAXN];   int dis[MAXN];   void dijkstra(int s, int n) {     for (int i = 1; i <= n; i++) vis[i] = 0;     for (int i = 1; i <= n; i++) dis[i] = (i == s ? 0 : 0x3FFFFFFF);     priority_queue<pair<short int, short int>,                    vector<pair<short int, short int> >,                    greater<pair<short int, short int> > >         q;     q.push(make_pair(dis[s], s));     while (!q.empty()) {       pair<short int, short int> p = q.top();       int x = p.second;       q.pop();       if (vis[x]) continue;       vis[x] = 1;       for (int i = 0; i < G[x].size(); i++) {         int y = G[x][i].first;         int d = G[x][i].second;         if (!vis[y] && dis[x] + d < dis[y]) {           dis[y] = dis[x] + d;           q.push(make_pair(dis[y], y));         }       }     }   }   map<pair<short int, short int>, short int> mp;   int main() {     int n, m, k, a, b;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= k; i++) {       scanf( %d%d , &a, &b);       p[i].first = a;       p[i].second = b;       mp[p[i]] = i;       cul[p[i].second].push_back(p[i].first);       row[p[i].first].push_back(p[i].second);     }     init(k);     for (int i = 1; i <= k; i++) {       short int x = p[i].first, y = p[i].second;       for (int j = 0; j < row[x].size(); j++)         if (row[x][j] != y)           add_edge(i, mp[make_pair(x, row[x][j])],                    row[x][j] - 1 != y && row[x][j] + 1 != y);       for (int j = 0; j < cul[y].size(); j++)         if (cul[y][j] != x)           add_edge(i, mp[make_pair(cul[y][j], y)],                    cul[y][j] - 1 != x && cul[y][j] + 1 != x);       for (int l = -1; l <= 1; l += 2) {         for (int j = 0; j < row[x + l].size(); j++)           if (row[x + l][j] != y)             add_edge(i, mp[make_pair(x + l, row[x + l][j])], 1);         for (int j = 0; j < cul[y + l].size(); j++)           if (cul[y + l][j] != x)             add_edge(i, mp[make_pair(cul[y + l][j], y + l)], 1);       }       for (int l = -2; l <= 2; l = l + 4) {         if (x + l > 0 && x + l <= m + 1)           for (int j = 0; j < row[x + l].size(); j++)             add_edge(i, mp[make_pair(x + l, row[x + l][j])], 1);         if (y + l > 0 && y + l <= n + 1)           for (int j = 0; j < cul[y + l].size(); j++)             add_edge(i, mp[make_pair(cul[y + l][j], y + l)], 1);       }     }     dijkstra(1, k);     int ans = 0x3FFFFFFF;     for (int i = 1; i <= k; i++) {       if (dis[i] == 0x3FFFFFFF || dis[i] > ans) continue;       if (n - p[i].first + m - p[i].second <= 1)         ans = min(ans, dis[i] + (mp[make_pair(n, m)] == 0));       else if (n - p[i].first <= 1 || m - p[i].second <= 1)         ans = min(ans, dis[i] + 1);     }     if (ans == 0x3FFFFFFF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #define maxn 10      using namespace std;      int n, m;   map<vector<int>, int> f, g;   int a[maxn], b[maxn], c[maxn][maxn];      int main(){    scanf( %d%d , &n, &m);    vector<int> v;    for(int i = 1;i <= n;i++) scanf( %d , &a[i]);    for(int i = 1;i <= m;i++) scanf( %d , &b[i]);    for(int i = 1;i <= n;i++) for(int j = 1;j <= m;j++) scanf( %d , &c[i][j]);    f[vector<int>(n + 1)] = 0;    for(int j = 1;j <= m;j++){     for(map<vector<int>, int>::iterator it = f.begin();it != f.end();++it){      vector<int> v = it->first;      v[n] = 0;      if(g.find(v) == g.end()) g[v] = it->second;      else g[v] = min(g[v], it->second);     }     swap(f, g), g.clear();     for(int i = 1;i <= n;i++){      for(map<vector<int>, int>::iterator it = f.begin();it != f.end();++it){       vector<int> v = it->first;        for(int k = 0;k <= min(a[i] - v[i - 1], b[j] - v[n]);k++){        vector<int> w = v;        w[i - 1] += k, w[n] += k;         if(g.find(w) == g.end()) g[w] = it->second + (k ? c[i][j] : 0);        else g[w] = min(g[w], it->second + (k ? c[i][j] : 0));          }      }      swap(f, g), g.clear();     }    }    int ans = 1e9;    for(map<vector<int>, int>::iterator it = f.begin();it != f.end();++it){     vector<int> v = it->first;      bool tag = false;     for(int i = 0;i < n;i++){      if(v[i] < a[i + 1]){       tag = true;       break;      }     }     if(!tag) ans = min(ans, it->second);    }    printf( %d , ans == 1e9 ? -1 : ans);   }
#include <bits/stdc++.h>   using namespace std;   struct cell {     long long root_vertix, com_len;     cell() {}     cell(long long x, long long y) {       root_vertix = x;       com_len = y;     }     bool operator<(const cell &x) const { return com_len < x.com_len; }   };   long long root[100002];   long long n, m, p, q;   long long find_root(long long x) {     if (root[x] <= 0) return x;     return root[x] = find_root(root[x]);   }   bool merge(long long x, long long y, long long len) {     x = find_root(x);     y = find_root(y);     if (x == y) {       root[x] -= len;       return false;     } else {       root[x] = root[x] - len + root[y];       root[y] = x;       return 1;     }   }   int main() {     cin >> n >> m >> p >> q;     long long components = n;     fill(root, root + n + 1, 0);     for (int i = 0; i < m; i++) {       long long x, y, z;       cin >> x >> y >> z;       if (merge(x, y, z)) components--;     }     if (components < q || p < (components - q) ||         (components == n && q == n && p > 0)) {       cout <<  NO  << endl;       return 0;     } else       cout <<  YES  << endl;     priority_queue<cell> qq;     for (int i = 1; i <= n; i++)       if (root[i] <= 0) qq.push(cell(i, root[i]));     long long diff = components - q;     long long same = p - diff;     while (diff--) {       cell x, y;       x = qq.top();       qq.pop();       y = qq.top();       qq.pop();       long long len = min((long long)1000000000, -x.com_len - y.com_len + 1);       cout << x.root_vertix <<     << y.root_vertix << endl;       merge(x.root_vertix, y.root_vertix, len);       x.com_len = root[x.root_vertix];       qq.push(x);     }     long long vertix;     for (int i = 1; i <= n; i++)       if (root[i] > 0) {         vertix = i;         break;       }     while (same--) cout << vertix <<     << root[vertix] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool tu[305][305];   long long pri[305];   int d[305];   int n, m, t;   int bg[1100000];   int top[110000];   int main() {     scanf( %d%d%d , &n, &m, &t);     for (int i = 1; i <= n; i++) scanf( %I64d , &pri[i]);     for (int i = 1; i <= m; i++) {       int b, c;       scanf( %d%d , &b, &c);       tu[b][c] = 1;       d[c]++;     }     for (int kk = 1; kk <= n; kk++) {       int now = 0;       for (int i = 1; i <= n; i++)         if (d[i] == 0) now = i;       if (!now) {         printf( 0 n );         return 0;       }       d[now] = -1;       for (int i = 1; i <= n; i++)         if (tu[now][i]) d[i]--;       top[++top[0]] = now;     }     for (int i = 1; i <= top[0]; i++) {       int x = top[i];       for (int j = 1; j <= n; j++) {         if (tu[x][j]) pri[j] += pri[x], t -= pri[x];         if (t < 0) {           printf( 0 n );           return 0;         }       }     }     if (t < 0) {       printf( 0 n );       return 0;     }     bg[0] = 1;     for (int i = 1; i <= n; i++)       for (long long j = pri[i]; j <= t; j++)         bg[j] = (bg[j] + bg[j - pri[i]]) % 1000000007;     printf( %d n , t >= 0 ? bg[t] : 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main()   {       long long tests, a, b, c, i,sum;       cin >> tests;       while (tests--)       {           cin >> a >> b >> c;           if (c / b + 1 >= a)               printf( %lld n ,(a*a-a)/2);           else               printf( %lld n ,(c/b)*(c/b+1)/2+(a-c/b-1)*(c/b));       }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   char s[maxn], t[maxn];   int pr, mod;   const int prs[60] = {       73,  79,  83,  89,  97,  101, 103, 107, 109, 113, 127, 131, 137, 139, 149,       151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,       233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,       317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409};   const int mods[100] = {       998244521, 998244523, 998244529, 998244601, 998244617, 998244619, 998244631,       998244649, 998244673, 998244677, 998244679, 998244707, 998244713, 998244749,       998244761, 998244787, 998244799, 998244803, 998244839, 998244853, 998244889,       998244893, 998244899, 998244911, 998244943, 998244967, 998244991, 998245037,       998245063, 998245091, 998245097, 998245099, 998245109, 998245111, 998245141,       998245147, 998245153, 998245159, 998245169, 998245177, 998245189, 998245207,       998245211, 998245223, 998245247, 998245331, 998245349, 998245373, 998245403,       998245463, 998245481, 998245483, 998245487, 998245489, 998245531, 998245543,       998245553, 998245571, 998245613, 998245631, 998245639, 998245687, 998245697,       998245709, 998245711, 998245733, 998245739, 998245757, 998245777, 998245799,       998245837, 998245867, 998245877, 998245909, 998245943, 998245949, 998245981,       998246021, 998246047, 998246071, 998246077, 998246101, 998246129, 998246143,       998246177, 998246189, 998246191, 998246237, 998246251, 998246257, 998246261,       998246267, 998246279, 998246317, 998246363, 998246369, 998246371, 998246387,       998246399, 998246401};   int ht[maxn], pw[maxn];   vector<int> pos[2];   int hash_t(int l, int r) {     if (l == 0) return ht[r];     return (ht[r] - pw[r - l + 1] * 1ll * ht[l - 1] % mod + mod) % mod;   }   int main() {     srand(time(0) + clock());     pr = prs[rand() % 60], mod = mods[rand() % 100];     scanf( %s , s);     scanf( %s , t);     int n = strlen(s), m = strlen(t), c0 = 0, c1 = 0;     if (s[0] ==  1 ) {       for (int i = 0; i < n; ++i) {         if (s[i] ==  0 )           s[i] =  1 ;         else           s[i] =  0 ;       }     }     for (int i = 0; i < n; ++i) {       if (s[i] ==  0 ) ++c0;       if (s[i] ==  1 ) ++c1;       pos[s[i] -  0 ].push_back(i);     }     if (pos[0].size() == 0 || pos[1].size() == 0) {       puts( 0 );       return 0;     }     ht[0] = t[0];     for (int i = 1; i < m; ++i) ht[i] = (1ll * ht[i - 1] * pr + t[i]) % mod;     pw[0] = 1;     int ans = 0;     for (int i = 1; i < maxn; ++i) pw[i] = pw[i - 1] * 1ll * pr % mod;     for (int x = 1; x * c0 < m; ++x) {       if ((m - x * c0) % c1 != 0) continue;       int y = (m - x * c0) / c1;       int hx = hash_t(0, x - 1);       int hy = hash_t(pos[1][0] * x, pos[1][0] * x + y - 1);       int real_t = 0;       if (hx == hy) continue;       for (int j = 0; j < n; ++j) {         if (s[j] ==  0 )           real_t = (real_t * 1ll * pw[x] + hx) % mod;         else           real_t = (real_t * 1ll * pw[y] + hy) % mod;       }       if (real_t == ht[m - 1]) ++ans;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int Maxn = 100020;   char s[Maxn];   int a[Maxn];   int k, n;   bool check(int m) {     for (int i = 1; i <= n; i++) {       if (s[i] ==  1 ) continue;       if (a[i - 1] - a[max(0, i - m - 1)] + a[min(n, i + m)] - a[i] >= k)         return 1;     }     return 0;   }   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) a[i] = a[i - 1] + (s[i] ==  0 );     int l = 1, r = n;     while (l <= r) {       int mid = (l + r) >> 1;       if (check(mid))         r = mid - 1;       else         l = mid + 1;     }     printf( %d n , l);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string x, y, z;     cin >> x;     y += tolower(x[0]);     z += toupper(x[0]);     for (int i = 1; i < x.size(); i++) {       y += toupper(x[i]);       z += toupper(x[i]);     }     if (x == y || x == z || x.size() == 1) {       for (int i = 0; i < x.size(); i++) {         if (x[i] == toupper(x[i]))           x[i] = tolower(x[i]);         else           x[i] = toupper(x[i]);       }     }     cout << x << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     int flag = 0;     while (flag == 0) {       if (a == b) {         flag = 1;         break;       }       if (a == x) {         break;       }       if (b == y) {         break;       }       a++;       b--;       if (a == n + 1) {         a = 1;       }       if (b == 0) {         b = n;       }     }     if (flag == 1) {       cout <<  YES             <<   n ;     } else if (flag == 0) {       cout <<  NO             <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optmize(2)   using namespace std;   inline int read() {     int X = 0, w = 0;     char ch = 0;     while (!isdigit(ch)) w |= ch ==  - , ch = getchar();     while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();     return w ? -X : X;   }   int f[1000010];   vector<int> G[1000010];   int vis[1000010];   int tot, s, cnt;   int dfs(int i) {     int res = 1;     vis[i] = 1;     for (int j = 0; j < G[i].size(); j++) {       if (!vis[G[i][j]]) res += dfs(G[i][j]);     }     return res;   }   multiset<int> ss;   int n = read(), m = read(), k = read();   int main() {     for (int i = 1; i <= m; i++) {       int x = read(), y = read();       G[x].push_back(y), G[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (!vis[i]) f[++tot] = dfs(i);     sort(f + 1, f + tot + 1);     reverse(f + 1, f + tot + 1);     int total = 0;     for (int i = 1; i <= tot; i++) {       f[i] = min(f[i], k);       total += f[i];       ss.insert(f[i]);     }     for (int i = 0;; i++) {       if (total >= 2 * ((int)ss.size() - 1)) {         cout << i << endl;         return 0;       }       int a = *ss.begin();       ss.erase(ss.begin());       int b = *ss.begin();       ss.erase(ss.begin());       total = total - a - b + min(a + b, k);       ss.insert(min(a + b, k));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int m = 10;   int a[10], b[10], ap[10], bp[10];   int n;   int main() {     memset(a, 0, sizeof(a));     memset(b, 0, sizeof(b));     string s;     cin >> s;     n = int(s.size());     for (int i = 0; i < n; ++i) {       int num = s[i] -  0 ;       ++ap[num];       ++bp[num];     }     int ans = 0;     int ln = -1;     for (int i = 0; i < m; ++i) {       for (int j = 0; j < m; ++j) {         a[j] = ap[j];         b[j] = bp[j];       }       int p = 0;       int pans = 0;       if (i == 0 && a[0] > 0 && b[0] > 0) {         --a[0];         --b[0];         ++pans;       } else {         if (i != 0 && a[i] > 0 && b[m - i] > 0) {           --a[i];           --b[m - i];           p = 1;           ++pans;         } else           continue;       }       for (int j = 0; j < n; ++j) {         for (int k = 0; k < m; ++k) {           if (k == 0 && p == 0 && a[0] > 0 && b[0] > 0) {             --a[0];             --b[0];             ++pans;             break;           }           if (a[k] > 0 && b[m - p - k] > 0) {             --a[k];             --b[m - p - k];             ++pans;             p = 1;             break;           }         }       }       pans += min(a[0], b[0]);       if (pans > ans) {         ans = pans;         ln = i;       }     }     for (int j = 0; j < m; ++j) {       a[j] = ap[j];       b[j] = bp[j];     }     string sa, sb;     {       int p = 0;       int i = ln;       if (i == 0 && a[0] > 0 && b[0] > 0) {         --a[0];         --b[0];         sa +=  0 ;         sb +=  0 ;       } else {         if (i != 0 && a[i] > 0 && b[m - i] > 0) {           --a[i];           --b[m - i];           p = 1;           sa += char(i +  0 );           sb += char(m - i +  0 );         } else {           cout << s << endl << s << endl;           return 0;         }       }       for (int j = 0; j < n; ++j) {         for (int k = 0; k < m; ++k) {           if (k == 0 && p == 0 && a[0] > 0 && b[0] > 0) {             --a[0];             --b[0];             sa +=  0 ;             sb +=  0 ;             break;           }           if (a[k] > 0 && b[m - p - k] > 0) {             --a[k];             --b[m - p - k];             sa += char(k +  0 );             sb += char(m - p - k +  0 );             p = 1;             break;           }         }       }     }     int T = min(a[0], b[0]);     a[0] -= T;     b[0] -= T;     for (int i = 0; i < m; ++i) {       while (a[i] > 0) {         --a[i];         sa += i +  0 ;       }     }     for (int i = 0; i < m; ++i) {       while (b[i] > 0) {         --b[i];         sb += i +  0 ;       }     }     reverse(sa.begin(), sa.end());     reverse(sb.begin(), sb.end());     cout << sa;     for (int i = 0; i < T; ++i) printf( 0 );     cout << endl;     cout << sb;     for (int i = 0; i < T; ++i) printf( 0 );     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, x, y;     cin >> n >> x >> y;     char c;     long long s = 0;     bool b = 0;     for (int i = 0; i < n; i++) {       cin >> c;       if (b == 1 && c ==  1 ) {         b = 0;         s++;       } else if (b == 0 && c ==  0 ) {         b = 1;       }     }     if (c ==  0 ) s++;     if (s > 0 && x < y) {       cout << (s - 1) * x + y;     } else       cout << s * y;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     string s;     cin >> s;     vector<long long int> ind;     long long int t = 0;     ind.push_back(0);     for (long long int i = 1; i < n; i++) {       if (s[i] != s[ind[t]]) {         t++;         ind.push_back(i);       }     }     long long int f = 0;     long long int last = 0;     for (long long int i = 1; i <= t; i++) {       if (ind[i] - ind[i - 1] - 1 >= 2) {         f = 1;         break;       }       if (ind[i] - ind[i - 1] - 1 >= 1) {         last++;       }     }     if (n - ind[t] - 1 >= 2) f = 1;     if (n - ind[t] - 1 >= 1) last++;     if (last >= 2) f = 1;     if (f == 1) {       cout << ind.size() + 2 <<   n ;     } else if (last >= 1) {       cout << ind.size() + 1 <<   n ;     } else {       cout << ind.size() <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int d[100][110];   int grad[110];   int dp[1 << 16];   int main() {     int n, m, a, b, c, sum(0);     ios_base ::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i(0); i < n; i++)       for (int j(0); j < n; j++)         if (i != j) d[i][j] = 1e9;     while (m--) {       cin >> a >> b >> c;       a--;       b--;       sum += c;       grad[a]++, grad[b]++;       d[a][b] = d[b][a] = min(d[a][b], c);     }     for (int k(0); k < n; k++)       for (int i(0); i < n; i++)         for (int j(0); j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);     for (int i(0); i < n; i++) {       if (grad[i] && d[0][i] >= 1e9) {         cout << -1;         return 0;       }     }     int mask(0);     for (int i(0); i < n; i++)       if (grad[i] & 1) mask |= (1 << i);     for (int i(0); i <= mask; i++) dp[i] = 1e9;     dp[mask] = 0;     while (mask) {       for (int i(0); i < n; i++) {         if (!(mask & (1 << i))) continue;         for (int j(i + 1); j < n; j++)           if (mask & (1 << j))             dp[mask ^ (1 << i) ^ (1 << j)] =                 min(dp[mask ^ (1 << i) ^ (1 << j)], dp[mask] + d[i][j]);       }       mask--;     }     cout << dp[0] + sum <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[10] = {0};     char S[100001];     cin >> S;     for (int i = 0; S[i]; i++) {       int j = 0;       if (S[i] ==  L ) {         while (arr[j] == 1) j++;         arr[j] = 1;       }       j = 10 - 1;       if (S[i] ==  R ) {         while (arr[j] == 1) j--;         arr[j] = 1;       }       if (S[i] >= 48 && S[i] <= 57) {         arr[S[i] - 48] = 0;       }     }     for (int i = 0; i < 10; i++) cout << arr[i];     cout << endl;   }