malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long lpow(long long a, long long n) {     long long c = 1ll;     while (n) {       if (n % 2) c = (c * a) % 1000000007ll;       a = (a * a) % 1000000007ll;       n /= 2;     }     return c;   }   long long c[104][105], C[105][105], a[10005];   int main() {     long long n, m, k, x;     int i, j;     cin >> n >> m >> k;     for (i = 0; i <= 100; i++) {       c[i][0] = 1ll;       c[i][1] = i;       for (j = 2; j <= i; j++)         c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % 1000000007ll;     }     for (i = 0; i < n; i++) {       x = m / n;       if (m % n > i) x++;       for (j = 0; j <= n; j++) C[i][j] = lpow(c[n][j], x);     }     a[0] = 1ll;     for (i = 0; i < n; i++) {       for (j = k; j >= 0; j--)         for (x = n; x >= 1; x--)           if (j >= x)             a[j] = (a[j] + (a[j - x] * C[i][x]) % 1000000007ll) % 1000000007ll;     }     cout << a[k] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[3010][3010], t[3010][3010], S[3010], T[3010];   int nxt[3010], len, pos, tl, tr, p[3010], pre[3010][3010], n, len_s[3010];   void change(int id) {     int n = strlen(s[id] + 1), j = 0;     for (int i = 1; i <= n; i++) {       while (j && S[j + 1] != s[id][i]) j = nxt[j];       if (S[j + 1] == s[id][i]) j++;       if (j == len) {         for (int k = 1; k <= len; k++) s[id][i - len + k] = T[k];         break;       }     }   }   void check(int id) {     int j = 0, diff = 0;     for (int i = 1; i <= len_s[id]; i++) {       while (j && S[j + 1] != s[id][i]) j = nxt[j];       if (S[j + 1] == s[id][i]) j++;       if (j == len && pre[id][i] - pre[id][i - len]) {         p[id] = i - len + 1;         break;       } else if (j == len)         j = nxt[j];     }   }   void get_S() {     int mx = 0;     for (int i = 1; i <= tl - 1; i++) {       int flag = 1;       for (int j = 1; j <= n; j++)         if (p[j] && (p[j] - i <= 0 || s[j][p[j] - i] != s[pos][tl - i])) {           flag = 0;           break;         }       if (flag)         mx++;       else         break;     }     tl -= mx;     mx = 0;     for (int i = 1; i <= n; i++)       if (p[i]) p[i] = p[i] + len - 1;     for (int i = 1; i <= len_s[pos] - tr; i++) {       int flag = 1;       for (int j = 1; j <= n; j++)         if (p[j] && (p[j] + i > len_s[j] || s[j][p[j] + i] != s[pos][tr + i])) {           flag = 0;           break;         }       if (flag)         mx++;       else         break;     }     tr += mx;     len = tr - tl + 1;     for (int i = 1; i <= len; i++) {       S[i] = s[pos][i + tl - 1];       T[i] = t[pos][i + tl - 1];     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %s , s[i] + 1);       len_s[i] = strlen(s[i] + 1);     }     for (int i = 1; i <= n; i++) scanf( %s , t[i] + 1);     for (int i = 1; i <= n; i++) {       int lef = len_s[i] + 1, righ = 0;       for (int j = 1; j <= len_s[i]; j++)         if (s[i][j] != t[i][j]) {           lef = min(lef, j);           righ = max(righ, j);           pre[i][j] = pre[i][j - 1] + 1;         } else           pre[i][j] = pre[i][j - 1];       if (righ - lef + 1 > len) {         len = righ - lef + 1;         for (int j = lef; j <= righ; j++) {           S[j - lef + 1] = s[i][j];           T[j - lef + 1] = t[i][j];         }         pos = i;         tl = lef;         tr = righ;       }     }     int j = 0;     for (int i = 2; i <= len; i++) {       while (j && S[j + 1] != S[i]) j = nxt[j];       if (S[j + 1] == S[i]) j++;       nxt[i] = j;     }     for (int i = 1; i <= n; i++) check(i);     get_S();     j = 0;     for (int i = 2; i <= len; i++) {       while (j && S[j + 1] != S[i]) j = nxt[j];       if (S[j + 1] == S[i]) j++;       nxt[i] = j;     }     for (int i = 1; i <= n; i++) {       change(i);       int len = strlen(s[i] + 1);       for (int j = 1; j <= len; j++)         if (s[i][j] != t[i][j]) {           puts( NO );           return 0;         }     }     puts( YES );     puts(S + 1);     puts(T + 1);     return 0;   }
#include<bits/stdc++.h>   #define int long long   #define reg register   using namespace std;   const int maxn=5e5+5;   const int mod=1e9+7;   const int INF=2e9;   inline int read()   {       int x=0,f=1;       char ch=getchar();       while(ch< 0  || ch> 9 )       {           if(ch== - )           f=-1;           ch=getchar();       }       while(ch>= 0  && ch<= 9 )       {           x=x*10+ch- 0 ;           ch=getchar();       }       return x*f;   }   int T;   int d;   int prime[maxn];   int tot=0;   int check[maxn];   void Pre(int maxx)   {    check[1]=1;    for(int i=2;i<=maxx;i++)    {     if(check[i]==0)     prime[++tot]=i;     for(int j=1;j<=tot && prime[j]*i<=maxx;j++)     {      check[i*prime[j]]=1;      if(i%prime[j]==0)      break;     }    }   }   signed main()   {     Pre(500000);    //for(int i=1;i<=20;i++)    //cout<<prime[i]<<   ;    T=read();    //cout<<tot<<endl;    while(T--)    {     d=read();    /* if(d==2)     {      printf( 15 n );      continue;     }     else     if(d==1)     {      printf( 6 n );      continue;     }*/     int l=1,r=tot;     while(l<r)     {      int mid=(l+r)>>1;      if(prime[mid]-1>=d)      r=mid;      else      l=mid+1;     }     int ans1=l;     //cout<<ans1<<endl;     l=ans1+1,r=tot;     while(l<r)     {      int mid=(l+r)>>1;      if(prime[mid]-prime[ans1]>=d)      r=mid;      else      l=mid+1;     }     int ans2=l;     printf( %lld n ,prime[ans1]*prime[ans2]);    }    return 0;   }   /*   4   3 3 2 1   6   3 4 5 1 6 2      0   */
#include <bits/stdc++.h>   using namespace std;   long long ans1, ans2;   int n;   char s[111111];   long long a[111111], pa[111111], b[111111], pb[111111];   inline long long get(long long x, int first) {     long long t = first, ans = 0;     while (t <= x) {       ans += (x + 1 - t);       t += 2;     }     return ans;   }   inline void solve(long long *a, long long *b, int n) {     long long sum1 = 0, sum2 = 0;     for (int i = 1; i <= n; i++) {       if (b[i] % 2 == 0) {         int r = b[i] + a[i] - 1;         if (r % 2 == 0)           sum1 += a[i] / 2, sum2 += a[i] / 2 + 1;         else if (r % 2 == 1)           sum1 += a[i] / 2, sum2 += a[i] / 2;       } else if (b[i] % 2 == 1) {         int r = b[i] + a[i] - 1;         if (r % 2 == 0)           sum1 += a[i] / 2, sum2 += a[i] / 2;         else if (r % 2 == 1)           sum1 += a[i] / 2 + 1, sum2 += a[i] / 2;       }     }     for (int i = 1; i <= n; i++) {       int r = b[i] + a[i] - 1;       if (b[i] % 2 == 0) {         if (r % 2 == 0)           sum1 -= a[i] / 2, sum2 -= a[i] / 2 + 1;         else if (r % 2 == 1)           sum1 -= a[i] / 2, sum2 -= a[i] / 2;       } else if (b[i] % 2 == 1) {         if (r % 2 == 0)           sum1 -= a[i] / 2, sum2 -= a[i] / 2;         else if (r % 2 == 1)           sum1 -= a[i] / 2 + 1, sum2 -= a[i] / 2;       }       if (b[i] % 2 == 0) {         if (r % 2 == 0)           ans2 += (a[i] / 2) * sum2, ans2 += (a[i] / 2 + 1) * sum1,               ans1 += (a[i] / 2) * sum1, ans1 += (a[i] / 2 + 1) * sum2;         else if (r % 2 == 1)           ans2 += (a[i] / 2) * sum2, ans2 += (a[i] / 2) * sum1,               ans1 += (a[i] / 2) * sum1, ans1 += (a[i] / 2) * sum2;       } else if (b[i] % 2 == 1) {         if (r % 2 == 0)           ans2 += (a[i] / 2) * sum2, ans2 += (a[i] / 2) * sum1,               ans1 += (a[i] / 2) * sum1, ans1 += (a[i] / 2) * sum2;         else if (r % 2 == 1)           ans2 += (a[i] / 2) * sum1, ans2 += (a[i] / 2 + 1) * sum2,               ans1 += (a[i] / 2) * sum2, ans1 += (a[i] / 2 + 1) * sum1;       }       ans1 += get(a[i], 1);       ans2 += get(a[i], 2);     }   }   int main() {     scanf( %s , s);     int len = strlen(s);     int t = 1;     a[1] = 1;     pa[1] = 0;     for (int i = 1; i < len; i++)       if (s[i - 1] == s[i])         a[t]++;       else         a[++t] = 1, pa[t] = i;     int t1 = 0;     for (int i = 1; i <= t; i++)       if (i % 2 == 1) b[++t1] = a[i], pb[t1] = pa[i];     ans1 = 0, ans2 = 0;     solve(b, pb, t1);     t1 = 0;     for (int i = 1; i <= t; i++)       if (i % 2 == 0) b[++t1] = a[i], pb[t1] = pa[i];     solve(b, pb, t1);     cout << ans2 <<     << ans1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n;       cin >> n;       long long int idx[2 * n + 1], chk = 2 * n;       vector<long long int> coin;       coin.push_back(0LL);       for (long long int i = 1; i <= 2 * n; i++) {         long long int x;         cin >> x;         idx[x] = i;       }       for (long long int i = 2 * n; i >= 1; i--) {         if (idx[i] <= chk) {           coin.push_back(chk - idx[i] + 1);           chk = idx[i] - 1;         }       }       long long int cost = n, coin_no = coin.size() - 1;       long long int dp[coin_no + 1][cost + 1];       memset(dp, 0, sizeof(dp));       for (long long int i = 0; i <= coin_no; i++) dp[i][0] = 1;       for (long long int i = 1; i <= coin_no; i++) {         for (long long int j = 1; j <= cost; j++) {           dp[i][j] = dp[i - 1][j];           if (coin[i] <= j) dp[i][j] |= dp[i - 1][j - coin[i]];         }       }       if (dp[coin_no][cost])         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, p[10];   map<long long, string> m;   set<long long> s[10];   template <class T>   string toString(T x) {     ostringstream os;     os << x;     return os.str();   }   int getlen(long long x) {     int ans = 0;     while (x) {       ans++;       x /= 10;     }     return max(ans, 1);   }   string get(long long x) {     if (m.count(x)) return m[x];     return toString(x);   }   void relaxPower(long long x, string str) {     if (x > n || str.length() >= getlen(x)) return;     if (m.count(x) && m[x].length() <= str.length()) return;     s[m[x].length()].erase(x);     m[x] = str;     s[str.length()].insert(x);   }   void getPowers() {     for (long long x = 2; x * x <= n; x++) {       long long rs = x * x;       int p = 2;       while (rs <= n) {         string tmp = toString(x) +  ^  + toString(p);         relaxPower(rs, tmp);         rs *= x;         p++;       }     }   }   void getPowerAndPower(int len) {     for (int i = 1; i <= len; i++)       for (int j = i; i + j + 1 <= len; j++)         for (auto x : s[i])           for (auto y : s[j]) relaxPower(x * y, get(x) +  *  + get(y));   }   void getSimpleAndPower(int len) {     for (int i = 1; i + 2 <= len; i++) {       for (long long x = 1; x < p[len - i - 1]; x++)         for (long long y : s[i]) relaxPower(x * y, toString(x) +  *  + get(y));     }   }   void precalc() {     getPowers();     getPowerAndPower(7);     getSimpleAndPower(7);   }   string ans;   void relaxAnswer(string str) {     if (str.length() < ans.length()) ans = str;   }   void checkAnswer() {     for (int i = 1; i * 2 + 1 < ans.length(); i++) {       for (long long x = 1; x <= p[i]; x++) {         relaxAnswer(get(n - x) +  +  + get(x));         if (n % x == 0) relaxAnswer(get(n / x) +  *  + get(x));       }       for (auto x : s[i]) {         relaxAnswer(get(n - x) +  +  + get(x));         if (n % x == 0) relaxAnswer(get(n / x) +  *  + get(x));       }     }   }   int main() {     p[0] = 1;     for (int i = 1; i < 10; i++) p[i] = p[i - 1] * 10;     cin >> n;     precalc();     ans = get(n);     checkAnswer();     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, v;     cin >> n >> v;     map<int, int> s;     for (int i = 1; i <= n; i++) {       long long a;       cin >> a;       for (int j = 0; j < a; j++) {         long long b;         cin >> b;         if (v > b) {           s[i] = 1;         }       }     }     cout << s.size() << endl;     for (map<int, int>::iterator it = s.begin(); it != s.end(); it++)       cout << it->first <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   enum { AABB, ABAB, ABBA, AAAA };   int n, k;   string s1, s2, s3, s4;   bool isvow(char c) {     return (c ==  a  || c ==  e  || c ==  i  || c ==  o  || c ==  u );   }   string suf(string s) {     static int sp = 0;     auto i = s.end(), beg = s.begin();     int tk = 0;     while (tk < k && i > beg) {       --i;       tk += isvow(*i);     }     string res(i, s.end());     if (tk < k) {       res = string(sp++,    );     }     return res;   }   void foo() {     cout <<  NO n ;     exit(0);   }   int main(void) {     int i;     cin >> n >> k;     int ans = AAAA;     for (i = 0; i < n; ++i) {       cin >> s1 >> s2 >> s3 >> s4;       auto suf1 = suf(s1), suf2 = suf(s2), suf3 = suf(s3), suf4 = suf(s4);       if (suf1 == suf2 && suf2 == suf3 && suf3 == suf4) {       } else if (suf1 == suf2 && suf3 == suf4) {         if (ans == AAAA || ans == AABB) {           ans = AABB;         } else {           foo();         }       } else if (suf1 == suf3 && suf2 == suf4) {         if (ans == AAAA || ans == ABAB) {           ans = ABAB;         } else {           foo();         }       } else if (suf1 == suf4 && suf2 == suf3) {         if (ans == AAAA || ans == ABBA) {           ans = ABBA;         } else {           foo();         }       } else {         foo();       }     }     switch (ans) {       case AABB:         cout <<  aabb n ;         break;       case ABAB:         cout <<  abab n ;         break;       case ABBA:         cout <<  abba n ;         break;       case AAAA:         cout <<  aaaa n ;         break;       default:         foo();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   struct outputer;   struct outputable {};   template <typename T>   inline auto sqr(T x) -> decltype(x * x) {     return x * x;   }   template <typename T1, typename T2>   inline bool umx(T1& a, T2 b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <typename T1, typename T2>   inline bool umn(T1& a, T2 b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   const int N = 200000;   struct Input {     int n;     int a[N];     vector<int> e[N];     bool read() {       if (!(cin >> n)) {         return 0;       }       for (int i = int(0); i < int(n); ++i) {         scanf( %d , &a[i]);         --a[i];       }       for (int i = int(0); i < int(n - 1); ++i) {         int x, y;         scanf( %d%d , &x, &y);         --x;         --y;         e[x].emplace_back(y);         e[y].emplace_back(x);       }       return 1;     }     void init(const Input& input) { *this = input; }   };   struct Data : Input {     int ans;     void write() { cout << ans << endl; }   };   namespace Main {   struct Solution : Data {     int mx;     array<int, 2> calc(int v, int pr) {       array<int, 2> res{0, 0};       if (a[v] != -1) {         res[a[v]] = 1;       }       for (int to : e[v]) {         if (to == pr) {           continue;         }         array<int, 2> cur = calc(to, v);         for (int t = int(0); t < int(2); ++t) {           umx(mx, res[t] + cur[!t]);         }         for (int t = int(0); t < int(2); ++t) {           umx(res[t], cur[t]);           if (a[v] == t) {             umx(res[t], cur[!t] + 1);           }         }       }       for (int t = int(0); t < int(2); ++t) {         umx(mx, res[t]);       }       return res;     }     void solve() {       mx = 0;       calc(0, -1);       ans = mx / 2 + 1;     }     void clear() {       for (int i = int(0); i < int(n); ++i) {         e[i] = vector<int>();       }     }   };   }  // namespace Main   Main::Solution sol;   int main() {     cout.setf(ios::showpoint | ios::fixed);     cout.precision(20);     int t;     cin >> t;     for (int i = int(0); i < int(t); ++i) {       sol.read();       sol.solve();       sol.write();       sol.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, A, B, inf = 1e9, f[110][110], x, y, K, g[110][110], Cnt[110],                   d[110][110];   bool vis[110][110], V[110][110], Must[110][110];   vector<int> E1[110], E2[110], E[110][110];   queue<pair<int, int> > h;   void read(int &x) {     char ch = getchar();     int mark = 1;     for (; ch !=  -  && (ch <  0  || ch >  9 ); ch = getchar())       ;     if (ch ==  - ) mark = -1, ch = getchar();     for (x = 0; ch >=  0  && ch <=  9 ; ch = getchar()) x = x * 10 + ch - 48;     x *= mark;   }   int main() {     read(n);     read(m);     read(A);     read(B);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++) f[i][j] = f[j][i] = inf;     for (int i = 1; i <= m; i++) {       read(x);       read(y);       f[x][y] = 1;       E1[x].push_back(y);       E2[y].push_back(x);     }     for (int k = 1; k <= n; k++)       for (int i = 1; i <= n; i++)         for (int j = 1; j <= n; j++) f[i][j] = min(f[i][j], f[i][k] + f[k][j]);     read(K);     for (int i = 1; i <= K; i++) {       read(x);       read(y);       int dis = f[x][y];       if (dis == inf) continue;       memset(Cnt, 0, sizeof(Cnt));       for (int j = 1; j <= n; j++)         if (f[x][j] + f[j][y] == dis) {           V[i][j] = 1;           Cnt[f[x][j]]++;           for (int k = 0; k < E1[j].size(); k++) {             int v = E1[j][k];             if (f[x][j] + 1 + f[v][y] == dis) E[i][v].push_back(j), d[i][j]++;           }         }       for (int j = 1; j <= n; j++)         if (V[i][j] && Cnt[f[x][j]] == 1) Must[i][j] = 1;     }     for (int i = 1; i <= K; i++)       if (V[i][B]) {         vis[B][i] = 1, g[B][i] = 1;         h.push(make_pair(B, i));       }     for (int _ = 1; _ <= K; _++) {       while (h.size()) {         pair<int, int> now = h.front();         h.pop();         int u = now.first, x = now.second;         for (int i = 0; i < E[x][u].size(); i++) {           int v = E[x][u][i];           d[x][v]--;           if (d[x][v] == 0 && !vis[v][x]) {             vis[v][x] = 1;             g[v][x] = g[u][x];             h.push(make_pair(v, x));           }         }       }       for (int i = 1; i <= K; i++)         if (vis[A][i] && Must[i][A]) {           printf( %d n , _);           return 0;         }       for (int i = 1; i <= n; i++)         for (int j = 1; j <= K; j++)           if (vis[i][j] && Must[j][i] && g[i][j] == _) {             for (int k = 1; k <= K; k++)               if (!vis[i][k] && V[k][i]) {                 g[i][k] = g[i][j] + 1;                 vis[i][k] = 1;                 h.push(make_pair(i, k));               }           }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string S;   signed long long mo = 1000000007;   int N;   string qs[100005];   signed long long memo[20][100005];   signed long long dig[20][100005];   void solve() {     int i, j, k, l, r, x, y;     string s;     cin >> qs[0];     cin >> N;     N++;     qs[0] =  0->  + qs[0];     for (i = 1; i < N; i++) cin >> qs[i];     for (i = 0; i < 10; i++) memo[i][N] = i, dig[i][N] = 10;     for (i = N - 1; i >= 0; i--) {       for (j = 0; j < 10; j++)         memo[j][i] = memo[j][i + 1], dig[j][i] = dig[j][i + 1];       int from = qs[i][0] -  0 ;       memo[from][i] = 0;       dig[from][i] = 1;       for (j = qs[i].size() - 1; j >= 3; j--) {         int nn = qs[i][j] -  0 ;         memo[from][i] = (memo[from][i] + memo[nn][i + 1] * dig[from][i]) % mo;         dig[from][i] = (dig[from][i] * dig[nn][i + 1]) % mo;       }     }     cout << memo[0][0] << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false);     for (i = 0; i < argc - 1; i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < s.size(); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   const double pi = acos(-1);   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int N = 2e5 + 5;   int n, m, idx;   char s[N], ans[N];   bool st[10];   set<int> all;   bool check(int x) {     if (x == 2) return 0;     for (int i = 2; i <= x / i; ++i)       if (x % i == 0) return 1;     return 0;   }   void dfs(int i, int sum) {     if (i > n) {       all.insert(sum);       return;     }     ans[++idx] = s[i];     dfs(i + 1, sum * 10 + s[i] -  0 );     --idx;     dfs(i + 1, sum);   }   int main() {     st[2] = st[3] = st[5] = st[7] = 1;     int t;     cin >> t;     while (t--) {       cin >> n >> s + 1;       int cnt[10] = {0};       idx = 0;       for (int i = 1; i <= n; ++i) {         if (!st[s[i] -  0 ]) {           ans[++idx] = s[i];           goto out;         }       }       for (int i = 1; i <= n; ++i) {         cnt[s[i] -  0 ]++;         if (cnt[s[i] -  0 ] > 1) {           ans[++idx] = s[i];           ans[++idx] = s[i];           goto out;         }       }       all.clear();       dfs(1, 0);       for (int i : all)         if (check(i)) {           int k = i;           while (k) {             ans[++idx] = k % 10 +  0 ;             k /= 10;           }           reverse(ans + 1, ans + 1 + idx);           break;         }     out:       printf( %d n , idx);       for (int i = 1; i <= idx; ++i) printf( %c , ans[i]);       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m, sum = 0, i, j;     int a[500][3], b[500][3];     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d %d %d , &a[i][0], &a[i][1], &a[i][2]);     scanf( %d , &m);     for (i = 0; i < m; i++) scanf( %d %d %d , &b[i][0], &b[i][1], &b[i][2]);     for (i = 0; i < n; i++) {       int min = 1e9;       int x = (a[i][0] + a[i][1]) * 2;       for (j = 0; j < m; j++) {         int y;         if (a[i][2] > b[j][0]) continue;         y = b[j][0] / a[i][2] * b[j][1];         if (x % y == 0) {           y = x / y;         } else {           y = x / y + 1;         }         if (y * b[j][2] < min) min = y * b[j][2];       }       sum += min;     }     printf( %d n , sum);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long, long long> a[100001];   long long start = 0;   long long h;   long long res;   long long c[100001];   long long n;   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> h;     for (int i = 1; i <= n; ++i) {       cin >> a[i].first;       a[i].second = i;     }     sort(a + 1, a + n + 1);     res = a[n].first + a[n - 1].first - a[1].first - a[2].first;     for (int i = n; i >= 2; --i) {       long long curmax, curmin;       if (i == n)         curmax =             max(a[n].first + a[n - 1].first + h, a[n - 1].first + a[n - 2].first);       else         curmax =             max(a[n].first + a[n - 1].first, a[n].first + a[i - 1].first + h);       if (i != 2)         curmin = min(a[i].first + a[1].first + h, a[1].first + a[2].first);       else         curmin = min(a[2].first + a[1].first + h, a[2].first + a[3].first);       long long curdif = curmax - curmin;       if (curdif < res) {         res = curdif;         start = i - 1;       }     }     for (int i = 1; i <= start; ++i) {       c[a[i].second] = 1;     }     cout << res << endl;     for (int i = 1; i <= n; ++i) {       if (c[i])         cout << c[i] <<    ;       else         cout << 2 <<    ;     }   }