func_code_string: #include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:200000000 )   const double EPS = 1E-9;   const int INF = 1000000000;   const long long INF64 = (long long)1E18;   const double PI = 3.1415926535897932384626433832795;   const int NMAX = 310000;   set<pair<int, int> > q[3][3];   int a[NMAX], b[NMAX], n, w, c[NMAX][3];   long long s;   char st[NMAX];   void out() {     puts(st);     exit(0);   }   void add(int id) {     int cur = st[id] -  0 ;     s += c[id][cur];     for (int i = 0; i < (int)(3); i++) {       if (i == cur) continue;       q[cur][i].insert(make_pair(c[id][i] - c[id][cur], id));     }   }   void erase(int id) {     int cur = st[id] -  0 ;     s -= c[id][cur];     for (int i = 0; i < (int)(3); i++) {       if (i == cur) continue;       q[cur][i].erase(make_pair(c[id][i] - c[id][cur], id));     }   }   void perf(int st1, int st2) {     int id = q[st1][st2].begin()->second;     erase(id);     st[id] = st2 +  0 ;     add(id);   }   bool can2(int f1, int t1, int f2, int t2) {     if (q[f1][t1].empty()) return false;     int id1 = q[f1][t1].begin()->second;     int v1 = q[f1][t1].begin()->first;     erase(id1);     if (q[f2][t2].empty()) {       add(id1);       return false;     }     int id2 = q[f2][t2].begin()->second;     int v2 = q[f2][t2].begin()->first;     erase(id2);     if (v1 + v2 >= 0) {       add(id1);       add(id2);       return false;     }     st[id1] = t1 +  0 ;     add(id1);     st[id2] = t2 +  0 ;     add(id2);     return true;   }   bool can3(int f1, int t1, int f2, int t2, int f3, int t3) {     if (q[f1][t1].empty()) return false;     int id1 = q[f1][t1].begin()->second;     long long v1 = q[f1][t1].begin()->first;     erase(id1);     if (q[f2][t2].empty()) {       add(id1);       return false;     }     int id2 = q[f2][t2].begin()->second;     long long v2 = q[f2][t2].begin()->first;     erase(id2);     if (q[f3][t3].empty()) {       add(id1);       add(id2);       return false;     }     int id3 = q[f3][t3].begin()->second;     long long v3 = q[f3][t3].begin()->first;     erase(id3);     if (v1 + v2 + v3 >= 0) {       add(id1);       add(id2);       add(id3);       return false;     }     st[id1] = t1 +  0 ;     add(id1);     st[id2] = t2 +  0 ;     add(id2);     st[id3] = t3 +  0 ;     add(id3);     return true;   }   long long solve(long long ans = -1) {     for (int i = 0; i < (int)(3); i++)       for (int j = 0; j < (int)(3); j++) q[i][j].clear();     for (int i = 0; i < (int)(n); i++) st[i] =  0 ;     for (int i = 0; i < (int)(n); i++) add(i);     s = 0;     int left = w;     while (left) {       if (left >= 2 && q[0][2].size()) {         perf(0, 2);         left -= 2;       } else if (left >= 1 && q[0][1].size()) {         perf(0, 1);         left--;       }     }     if (left) throw;     long long res = s;     if (s == ans) out();     bool change = true;     while (change) {       change = false;       change |= can2(0, 1, 1, 0);       change |= can2(0, 1, 2, 1);       change |= can2(1, 2, 2, 1);       change |= can2(1, 2, 1, 0);       change |= can2(0, 2, 2, 0);       change |= can3(0, 2, 2, 1, 2, 1);       change |= can3(0, 2, 1, 0, 2, 1);       change |= can3(0, 2, 1, 0, 1, 0);       change |= can3(2, 0, 1, 2, 1, 2);       change |= can3(2, 0, 0, 1, 1, 2);       change |= can3(2, 0, 0, 1, 0, 1);       if (res == ans) out();       res = min(res, s);     }     return res;   }   int main() {     cin >> n >> w;     for (int i = 0; i < (int)(n); i++) {       scanf( %d%d , &a[i], &b[i]);       c[i][0] = 0;       c[i][1] = a[i];       c[i][2] = b[i];     }     long long ans = solve();     cout << ans << endl;     solve(ans);     return 0;   }   