malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const int N = 1005;   int cnt[N];   bitset<N> dp;   int n, m;   int idx[N];   int par[N];   int xx[N];   bool vis[N];   int find(int x) {     if (par[x] == x) return x;     return par[x] = find(par[x]);   }   int main() {     for (int i = 0; i <= 1000; i += 1) cnt[i] = 0;     cin >> n >> m;     int ix = 1;     for (int i = 0; i <= n; i += 1) par[i] = i;     int id = -1, tmp, x;     bool flag = false;     for (int i = 1; i <= n; i += 1) {       cin >> xx[i];       if (xx[i] != 0) par[i] = find(par[xx[i]]);       if (xx[i] == 0) {         idx[i] = ix++;       }     }     for (int i = 1; i <= n; i += 1) {       if (find(par[i]) == find(par[m])) {         continue;       }       cnt[idx[find(par[i])]]++;     }     int now = m;     while (now != 0) {       cnt[idx[par[m]]]++;       now = xx[now];     }     dp[cnt[idx[par[m]]]] = 1;     for (int i = 1; i <= ix - 1; i += 1) {       if (i != idx[par[m]]) {         dp = (dp << cnt[i]) | dp;       }     }     for (int i = 0; i <= n; i += 1) {       if (dp[i] == 1) {         cout << i << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 33;   template <class T>   inline void relax(T &a, const T &b) {     if (b > a) a = b;   }   int main() {     int n;     static int a[MaxN][MaxN];     cin >> n;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) scanf( %d , &a[i][j]);     int l = (n + 1) / 2;     int res = INT_MIN;     for (int lastR = 0; lastR < (1 << l); lastR++) {       int cur = 0;       for (int r = 0; r < l; r++) {         int resR = INT_MIN;         for (int tv = 0; tv <= 1; tv++) {           int curR = 0;           for (int c = 0; c < l; c++) {             int resRC = INT_MIN;             for (int cv = 0; cv <= 1; cv++) {               if (r == l - 1 && cv != (lastR >> c & 1)) continue;               if (c == l - 1 && cv != tv) continue;               int curRC = 0;               curRC += cv == 0 ? a[r][c] : -a[r][c];               if (r + l < n)                 curRC +=                     (cv ^ (lastR >> c & 1)) == 0 ? a[r + l][c] : -a[r + l][c];               if (c + l < n) curRC += (cv ^ tv) == 0 ? a[r][c + l] : -a[r][c + l];               if (r + l < n && c + l < n)                 curRC +=                     (cv ^ (lastR >> c & 1) ^ tv ^ (lastR >> (l - 1) & 1)) == 0                         ? a[r + l][c + l]                         : -a[r + l][c + l];               relax(resRC, curRC);             }             if (resRC == INT_MIN) {               curR = INT_MIN;               break;             }             curR += resRC;           }           relax(resR, curR);         }         cur += resR;       }       relax(res, cur);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }   inline long long Set(long long n, long long pos) {     return n = n | (1LL << pos);   }   inline long long Reset(long long n, long long pos) {     return n = n & ~(1LL << pos);   }   inline bool Check(long long n, long long pos) {     return (bool)(n & (1LL << pos));   }   inline long long Count(long long n) { return __builtin_popcountll(n); }   long long const N = 3e5 + 5;   long long const MOD = 998244353;   long long color[N];   vector<long long> adj[N];   long long dp[N];   long long res[N];   long long dfs(long long node, long long p) {     long long col = 0;     for (auto c : adj[node]) {       if (p == c) continue;       long long temp = dfs(c, node);       col += max(temp, 0LL);     }     col += color[node];     return dp[node] = col;   }   void adfs(long long node, long long p, long long up) {     up = max(up, 0LL);     res[node] = dp[node] + up;     for (auto c : adj[node]) {       if (p == c) continue;       long long temp = dp[node] - max(dp[c], 0LL) + up;       adfs(c, node, temp);     }   }   void solve() {     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       cin >> color[i];       if (color[i] == 0) color[i] = -1;     }     for (long long i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(1, -1);     adfs(1, -1, 0);     for (long long i = 1; i <= n; i++) cout << res[i] <<    ;   }   int32_t main() {     fast();     solve();   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1LL << 60;   const long long N = 2e5 + 5;   long long a[N];   void solve() {     long long n;     cin >> n;     vector<long long> vect;     for (long long i = 1; i < n + 1; i++) {       cin >> a[i];       if (a[i] != i) {         vect.push_back(i);       }     }     if ((long long)vect.size() == 0) {       cout << 0;       return;     }     bool fl = true;     for (long long i = 1; i < (long long)vect.size(); i++) {       if (vect[i] - vect[i - 1] > 1) fl = false;     }     if (fl)       cout << 1;     else       cout << 2;   }   signed main() {     std::ios::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, l, c, d, p, nl, np;     cin >> n >> k >> l >> c >> d >> p >> nl >> np;     int mls = k * l;     int slices = c * d;     int drinks = min(mls / nl, min(p / np, slices)) / n;     cout << drinks << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[500010];   char s[500010], temp[500010];   int n;   long long Max = -1000, sum = 0;   void init() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> s[i];     }   }   void work() {     for (int i = 0; i < n; i++) {       if (s[i] ==  B ) sum += a[i];     }     Max = sum;     long long temp = sum;     for (int i = n - 1; i >= 0; i--) {       if (s[i] ==  A ) {         sum += a[i];         if (sum > Max) Max = sum;       } else {         sum -= a[i];       }     }     sum = temp;     for (int i = 0; i < n; i++) {       if (s[i] ==  A ) {         sum += a[i];         if (sum > Max) Max = sum;       } else {         sum -= a[i];       }     }   }   int main() {     init();     work();     cout << Max << endl;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   #pragma GCC optimize( unroll-loops )   using namespace std;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     int n, m, q, p;     cin >> n >> m >> q >> p;     queue<pair<pair<int, int>, int>> qu;     vector<vector<int>> g(n, vector<int>(m, 0));     vector<vector<char>> d(n, vector<char>(m));     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> d[i][j];         if (d[i][j] ==  * ) g[i][j] = -1;       }     int si[4]{0, 0, -1, 1};     int sj[4]{1, -1, 0, 0};     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (d[i][j] !=  .  && d[i][j] !=  * ) {           int cur = (int(d[i][j]) - int( A ) + 1) * q;           g[i][j] += cur;           qu.push({{i, j}, cur});           vector<vector<bool>> used(n, vector<bool>(m, false));           used[i][j] = true;           while (!qu.empty()) {             int x = qu.front().first.first;             int y = qu.front().first.second;             int qq = qu.front().second;             for (int c = 0; c < 4; c++) {               int tx = x + si[c];               int ty = y + sj[c];               if (tx > -1 && tx < n && ty > -1 && ty < m)                 if (!used[tx][ty] && g[tx][ty] != -1) {                   g[tx][ty] += qq / 2;                   used[tx][ty] = true;                   if (qq > 1) qu.push({{tx, ty}, qq / 2});                 }             }             qu.pop();           }         }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (g[i][j] > p) ans++;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, g, b;     cin >> r >> g >> b;     if (r % 2 == 0)       r = r / 2;     else       r = r / 2 + 1;     if (g % 2 == 0)       g = g / 2;     else       g = g / 2 + 1;     if (b % 2 == 0)       b = b / 2;     else       b = b / 2 + 1;     int tmp1 = 3 * (r - 1);     int tmp2 = 3 * (g - 1) + 1;     int tmp3 = 3 * (b - 1) + 2;     tmp1 = max(tmp1, tmp2);     tmp1 = max(tmp1, tmp3);     cout << tmp1 + 30;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 4e6 + 7;   const int inf = INT_MAX;   const long long inff = 1e18;   const long long mod = 1e9 + 7;   int d, s;   pair<int, int> dp[maxn];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cin >> d >> s;     for (int i = 0; i <= (d + 1) * (s + 1); i++) dp[i] = make_pair(-1, 0);     queue<int> q;     q.push(0);     while (!q.empty()) {       int now = q.front();       int sum = now / d, r = now % d;       q.pop();       for (int i = 0; i < 10; i++) {         if (sum + i <= s && (dp[(sum + i) * d + (r * 10 + i) % d].first == -1)) {           dp[(sum + i) * d + (r * 10 + i) % d] = make_pair(now, i);           q.push((sum + i) * d + (r * 10 + i) % d);         }       }     }     int now = s * d;     if (dp[now].first == -1)       return cout << -1 <<   n , 0;     else {       vector<int> v;       while (now) {         v.push_back(dp[now].second);         now = dp[now].first;       }       reverse((v).begin(), (v).end());       for (int i : v) cout << i;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N1[] = {1, -1}, NINF = (int)0x80808080u, MAXN = 30000, MAXK = 200;   long long int dp[MAXN][MAXK + 1][2][2], mdp[MAXN][MAXK + 1][2];   int arr[MAXN], cs[MAXN], n, k;   inline long long int max(long long int a, long long int b) {     return a > b ? a : b;   }   int main() {     scanf( %d%d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &arr[i]);       cs[i] = (i ? cs[i - 1] : 0) + arr[i];     }     memset(dp, NINF, sizeof dp);     memset(mdp, NINF, sizeof mdp);     mdp[0][0][0] = mdp[0][0][1] = 0;     for (int p = 0; p < 2; p++)       for (int q = 0; q < 2; q++) {         dp[0][1][p][q] = N1[q] * arr[0];         mdp[0][1][q] = max(mdp[0][1][q], dp[0][1][p][q]);       }     for (int i = 1; i < n; i++) {       mdp[i][0][0] = mdp[i][0][1] = 0;       mdp[i][1][0] = mdp[i - 1][1][0];       mdp[i][1][1] = mdp[i - 1][1][1];       for (int p = 0; p < 2; p++)         for (int q = 0; q < 2; q++) {           dp[i][1][p][q] =               max(dp[i - 1][1][p][q], mdp[i - 1][0][p]) + N1[q] * arr[i];           mdp[i][1][q] = max(mdp[i][1][q], dp[i][1][p][q]);         }       for (int j = 2; j <= k - 1; j++) {         mdp[i][j][0] = mdp[i - 1][j][0];         mdp[i][j][1] = mdp[i - 1][j][1];         for (int p = 0; p < 2; p++)           for (int q = 0; q < 2; q++) {             dp[i][j][p][q] = max(dp[i - 1][j][p][q], mdp[i - 1][j - 1][p]) +                              (N1[q] - N1[p]) * arr[i];             mdp[i][j][q] = max(mdp[i][j][q], dp[i][j][p][q]);           }       }       mdp[i][k][0] = mdp[i - 1][k][0];       for (int p = 0; p < 2; p++) {         dp[i][k][p][0] =             max(dp[i - 1][k][p][0], mdp[i - 1][k - 1][p]) - N1[p] * arr[i];         mdp[i][k][0] = max(mdp[i][k][0], dp[i][k][p][0]);       }     }     printf( %I64d n , mdp[n - 1][k][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, r, c, i, d, j = 0, a = 0, b = 0;     string s;     cin >> s;     n = s.size();     r = 1;     c = n;     while (c > 20) {       r++;       c = ceil((float)n / (float)r);     }     d = r * c - n;     cout << r <<     << c << endl;     while (j < r && d > 0) {       string s1(s, a, c - 1);       cout <<  *  << s1 << endl;       a = a + c - 1;       j++;       d--;     }     while (j < r) {       string s1(s, a, c);       cout << s1 << endl;       a = a + c;       j++;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, p, m;   vector<vector<int> > g;   vector<char> used;   vector<long long> c, vs, es;   pair<int, int> dfs(int v) {     used[v] = true;     pair<int, int> ans(1, (int)g[v].size());     for (int u : g[v]) {       if (used[u]) {         continue;       }       pair<int, int> a = dfs(u);       ans.first += a.first;       ans.second += a.second;     }     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> p;     g.resize(n);     used.resize(n);     c = vs = es = vector<long long>(p);     for (int k = 0; k < p; k++) {       cin >> c[k];       c[k]--;     }     for (int k = 0; k < m; k++) {       int v, u;       cin >> v >> u;       v--;       u--;       g[v].push_back(u);       g[u].push_back(v);     }     int i = -1;     for (int k = 0; k < p; k++) {       pair<int, int> ans = dfs(c[k]);       vs[k] = ans.first;       es[k] = ans.second / 2;       if (i == -1 || vs[k] > vs[i]) {         i = k;       }     }     int rem = 0;     for (int k = 0; k < n; k++) {       if (!used[k]) {         pair<int, int> ans = dfs(k);         vs[i] += ans.first;         es[i] += ans.second / 2;       }     }     long long ans = 0;     for (int k = 0; k < p; k++) {       ans += vs[k] * (vs[k] - 1) / 2 - es[k];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, max;   vector<int> a[100000];   bool visited[100000] = {0};   char col[100000] = { Z };   void f(int x) {     queue<int> q;     q.push(x);     visited[x] = 1;     char temp =  A ;     col[x] = temp;     while (!q.empty()) {       int p = q.front();       q.pop();       temp = col[p];       if (temp ==  A )         temp =  B ;       else         temp =  A ;       for (int i = 0; i < a[p].size(); i++) {         if (visited[a[p][i]] == false) {           q.push(a[p][i]);           visited[a[p][i]] = true;           col[a[p][i]] = temp;         } else if (col[a[p][i]] != temp) {           puts( -1 );           exit(0);         }       }     }   }   int main() {     cin >> n >> m;     int x, y;     for (int i = 0; i < m; i++) {       cin >> x >> y;       x--;       y--;       a[x].push_back(y);       a[y].push_back(x);     }     f(x);     for (int i = 0; i < 100000; i++) {       if (a[i].size() && visited[i] == 0) f(i);     }     int c1 = 0;     for (int i = 0; i < 100000; i++)       if (col[i] ==  B ) c1++;     cout << c1 <<   n ;     for (int i = 0; i < 100000; i++)       if (col[i] ==  B ) cout << i + 1 <<    ;     cout <<   n ;     c1 = 0;     for (int i = 0; i < 100000; i++)       if (col[i] ==  A ) c1++;     cout << c1 <<   n ;     for (int i = 0; i < 100000; i++)       if (col[i] ==  A ) cout << i + 1 <<    ;     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e6 + 1;   const long long inf = 1e9 + 1;   const long long mod = 1e9 + 7;   const long double eps = 1e-6;   mt19937 rnd(58);   struct point {     long double x, y;     bool operator==(const point &right);   };   bool point::operator==(const point &b) { return (x == b.x && y == b.y); }   long double dist(point a, point b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   long double mindist(point A1, point A2, point B1, point B2) {     long double x0 = A1.x - B1.x, y0 = A1.y - B1.y;     long double k = A2.x - A1.x - (B2.x - B1.x), s = A2.y - A1.y - (B2.y - B1.y);     if (A1 == A2 && B1 == B2) return dist(A1, B1);     long double v = -(x0 * k + y0 * s) / (k * k + s * s);     long double ans = min(dist(A1, B1), dist(A2, B2));     if (v > 0 && v < 1)       ans = min(ans, (k * k + s * s) * v * v + 2 * v * (x0 * k + y0 * s) +                          x0 * x0 + y0 * y0);     return ans;   }   point A[N], B[N];   void solve() {     long long i, j, k, n, d1, d2;     cin >> n >> d1 >> d2;     d1 = d1 * d1;     d2 = d2 * d2;     for (i = 0; i < n; ++i) {       cin >> A[i].x >> A[i].y >> B[i].x >> B[i].y;     }     long long ans = 0;     bool canHello = 1;     for (i = 0; i < n - 1; ++i) {       if (dist(A[i], B[i]) >= d2 + eps) canHello = 1;       if (canHello && mindist(A[i], A[i + 1], B[i], B[i + 1]) <= d1 + eps) {         ++ans;         canHello = 0;       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s1, s2;     int l;     vector<int> v;     cin >> s1 >> s2;     for (int i = 0; i < s2.length(); i++) {       if ((s2[i] -  0 ) > 0) v.push_back(s2[i] -  0 );     }     sort(v.begin(), v.end());     int k = v.size() - 1;     for (int i = 0; i < s1.length(); i++) {       for (int j = k; j >= 0; j--) {         if ((s1[i] -  0 ) < v[j]) {           k--;           s1[i] = char(v[j] +  0 );         }         break;       }     }     cout << s1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<long long int, int> mp;   map<long long int, int> mpp;   long long int a[100007];   long long int b[100007];   long long int bb[100007];   int main() {     int m, p;     scanf( %d %d , &m, &p);     int i, j;     for (i = 0; i < m; i++) scanf( %lld , a + i);     for (i = 0; i < p; i++) scanf( %lld , b + i);     sort(b, b + p);     long long int ans = 0;     long long int anss = 0;     long long int ansss;     bb[0] = 0;     mp[0] = 1;     mpp[0] = 1;     for (i = 1; i < m; i++) anss = anss + a[i], mp[anss]++, bb[i] = anss;     for (i = 0; i < m; i++) {       anss = bb[i];       if (mpp[b[0] - anss - a[0]]) continue;       mpp[b[0] - anss - a[0]] = 1;       ansss = 1;       j = 1;       while (j < p) {         anss = anss + b[j] - b[j - 1];         if (mp[anss]) {           if (!(b[j] - anss - a[0])) ansss = 0;         } else {           ansss = 0;           break;         }         j++;       }       ans = ans + ansss;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int inf = 1e9;   const int NINF = 0xc0c0c0c0;   const int maxn = 1e5 + 7;   const int bas = maxn / 2;   const int Maxn = 1e7 + 7;   const double eps = 1e-6;   const int mod = (1 << 31) - 1;   template <typename T>   void read(T &x) {     x = 0;     char c = getchar();     T flag = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     x = x * flag;   }   struct edge {     int v, next;   } e[maxn << 1];   int head[maxn], cnt;   void add(int a, int b) {     e[++cnt] = edge{b, head[a]};     head[a] = cnt;   }   int f[maxn][21], dep[maxn], tot, dp[maxn], treez = 0, root;   void dfs(int u, int fa) {     dep[u] = dep[fa] + 1;     f[u][0] = fa;     for (int i = 1; i <= 20; i++) {       f[u][i] = f[f[u][i - 1]][i - 1];     }     for (int i = head[u]; i; i = e[i].next) {       int v = e[i].v;       if (v == fa) continue;       dfs(v, u);       treez = max(treez, dp[u] + dp[v] + 1);       dp[u] = max(dp[u], dp[v] + 1);     }   }   int getlca(int a, int b) {     if (dep[a] < dep[b]) swap(a, b);     for (int i = 20; ~i; i--) {       int x = f[a][i];       if (dep[x] >= dep[b]) a = x;     }     if (a == b) return a;     for (int i = 20; ~i; i--) {       if (f[a][i] != f[b][i]) {         a = f[a][i];         b = f[b][i];       }     }     return f[a][0];   }   int k;   int work(int a, int lca) {     for (int i = 20; ~i; i--) {       if ((1 << i) <= k && dep[f[a][i]] >= dep[lca]) {         a = f[a][i];         k -= (1 << i);       }     }     return a;   }   void solve() {     int n, a, b, da, db;     cin >> n >> a >> b >> da >> db;     for (int i = 1; i <= n; i++) head[i] = 0, dp[i] = 0, dep[i] = 0;     cnt = 0;     treez = 0;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       add(u, v);       add(v, u);     }     if (da * 2 >= db) {       puts( Alice );       return;     }     dfs(1, 0);     int lca = getlca(a, b);     if (treez <= da * 2) {       puts( Alice );       return;     }     if (dep[a] + dep[b] - dep[lca] * 2 <= da) {       puts( Alice );       return;     }     puts( Bob );   }   signed main() {     int T = 1;     scanf( %d , &T);     while (T--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long n, l, r;   inline long long query(long long l, long long r) {     for (long long i = 62; i >= 1; i--) {       if ((1ll << i) - 1 >= l && (1ll << i) - 1 <= r) return (1ll << i) - 1;     }     for (long long i = 62; i >= 0; i--)       if (((1ll << i) & l) > 0 && ((1ll << i) & r) > 0)         return (1ll << i) + query(l - (1ll << i), r - (1ll << i));   }   int main() {     scanf( %lld , &n);     while (n--) {       scanf( %lld%lld , &l, &r);       if (l > r) {         long long t = l;         l = r;         r = t;       }       if (l == r) {         printf( %lld n , l);         continue;       }       printf( %lld n , query(l, r));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool nextper(int num[], int n) {     int i;     for (i = n - 1; i > 0; i--) {       if (num[i] > num[i - 1]) {         for (int j = n - 1; j >= i; j--) {           if (num[j] > num[i - 1]) {             int t = num[j];             num[j] = num[i - 1];             num[i - 1] = t;             for (int m = i, k = n - 1; m < k; m++, k--) {               t = num[m];               num[m] = num[k];               num[k] = t;             }             break;           }         }         break;       }     }     if (i > 0) {       return true;     } else       return false;   }   int order[8] = {0, 1, 2, 3, 4, 5, 6, 7};   char s[8][9];   int main() {     int n, k, i, j, min, max, num, ans = 2147483647;     scanf( %d %d , &n, &k);     for (i = 0; i < n; i++) scanf( %s , s[i]);     do {       min = 2147483647;       max = 0;       for (i = 0; i < n; i++) {         num = 0;         for (j = 0; j < k; j++) num = num * 10 + (s[i][order[j]] -  0 );         if (min > num) min = num;         if (max < num) max = num;       }       if (max - min < ans) ans = max - min;     } while (nextper(order, k));     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   long long bd(string n) {     string num = n;     long long dec_value = 0;     long long base = 1;     long long len = num.length();     for (long long i = len - 1; i >= 0; i--) {       if (num[i] ==  1 ) dec_value += base;       base = base * 2;     }     return dec_value;   }   long long db(long long n) {     for (long long i = 31; i >= 0; i--) {       long long k = n >> i;       if (k & 1)         cout <<  1 ;       else         cout <<  0 ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long l, r;     cin >> l >> r;     if (l < r) {       long long x = 64 - (__builtin_clzll(l ^ r));       long long y = 1;       long long ans = y << x;       ans--;       cout << ans;     } else       cout << 0;     return 0;   }