malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   map<int, vector<int>> pos;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) {       int n;       cin >> n;       vector<int> a(n), b(n);       for (int i = 0; i < n; i++) {         cin >> a[i];       }       for (int i = 0; i < n; i++) {         cin >> b[i];       }       pos.clear();       for (int i = n - 1; i >= 0; i--) {         pos[a[i]].push_back(i);       }       vector<int> tree(4 * n);       function<void(int, int, int)> build = [&](int v, int l, int r) {         if (l + 1 == r) {           tree[v] = a[l];           return;         }         int mid = (l + r) / 2;         build(2 * v, l, mid);         build(2 * v + 1, mid, r);         tree[v] = min(tree[2 * v], tree[2 * v + 1]);       };       function<int(int, int, int, int, int)> query_min =           [&](int ql, int qr, int v, int l, int r) {             if (ql <= l && r <= qr) return tree[v];             if (r <= ql || qr <= l) return int(1e6);             int mid = (l + r) / 2;             return min(query_min(ql, qr, 2 * v, l, mid),                        query_min(ql, qr, 2 * v + 1, mid, r));           };       function<void(int, int, int, int)> update = [&](int x, int v, int l,                                                       int r) {         if (l == x && r == l + 1) {           tree[v] = int(1e6);           return;         }         int mid = (l + r) / 2;         if (x < mid)           update(x, 2 * v, l, mid);         else           update(x, 2 * v + 1, mid, r);         tree[v] = min(tree[2 * v], tree[2 * v + 1]);       };       bool ok = true;       build(1, 0, n);       for (int i = 0; i < n; i++) {         if (pos[b[i]].size() == 0) {           ok = false;           break;         }         int x = pos[b[i]].back();         pos[b[i]].pop_back();         if (query_min(0, x + 1, 1, 0, n) != b[i]) {           ok = false;           break;         }         update(x, 1, 0, n);       }       if (ok)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxtop = 1025;   const int maxn = 100010;   const int mo = 1000000007;   int top;   int repeat[maxtop + 1];   int rest;   int a[maxn + 1];   int n, K;   int C[maxn + 1];   int f[2][maxtop + 1], old, now;   long long result;   void init() {     int i;     scanf( %d%d , &n, &K);     for (i = 1; i <= n; ++i) scanf( %d , &a[i]);     sort(a + 1, a + n + 1);   }   bool lucky(int x) {     int t;     while (x) {       t = x % 10;       if ((t != 4) && (t != 7)) return false;       x /= 10;     }     return true;   }   void calc_repeat() {     int i, j;     top = rest = 0;     i = 1;     while (i <= n) {       if (lucky(a[i])) {         j = i;         while ((j + 1 <= n) && (a[j + 1] == a[i])) ++j;         repeat[++top] = j - i + 1;         i = j + 1;       } else {         ++rest;         ++i;       }     }   }   int power(int x, int y) {     long long a, b;     b = x;     a = 1;     while (y) {       if (y & 1) a = (a * b) % mo;       b = (b * b) % mo;       y = (y >> 1);     }     return a;   }   void calc_C() {     int i;     long long tmp;     C[0] = 1;     if (rest == 0) return;     C[1] = rest;     for (i = 2; i <= rest; ++i) {       tmp = C[i - 1];       tmp = (tmp * (rest - i + 1)) % mo;       tmp = (tmp * power(i, mo - 2)) % mo;       C[i] = tmp;     }   }   void calc_result() {     int i, j, k;     long long tmp;     now = 0;     for (i = 1; i <= top; ++i) f[now][i] = 0;     f[now][0] = 1;     for (i = 1; i <= top; ++i) {       old = now;       now = 1 - now;       f[now][0] = 1;       for (j = 1; j <= i; ++j) {         if (j > K) break;         f[now][j] = 0;         if (j < i) f[now][j] += f[old][j];         tmp = f[old][j - 1];         tmp = (tmp * repeat[i]) % mo;         f[now][j] = (f[now][j] + tmp) % mo;       }     }     result = 0;     for (i = 0; i <= top; ++i) {       if (i > K) break;       if (K - i > rest) continue;       tmp = f[now][i];       tmp = (tmp * C[K - i]) % mo;       result += tmp;       if (result >= mo) result -= mo;     }   }   void work() {     calc_repeat();     calc_C();     calc_result();   }   void output() { printf( %d n , result); }   int main() {     init();     work();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   long long res, rem;   long long narr[100001];   long long tempint;   int main() {     scanf( %I64d , &n);     for (int i = 0; i < n; ++i) scanf( %I64d , narr + i);     sort(narr, narr + n);     reverse(narr, narr + n);     for (int i = 0; i < n; ++i) res += narr[i];     tempint = n - 1;     for (int i = 0; i < n; ++i, tempint -= 2) res += 2 * narr[i] * (tempint);     long long ores = res, on = n;     while (1) {       rem = ores % on;       if (rem == 0) {         break;       }       ores = on;       on = rem;     }     printf( %I64d %I64d , res / on, n / on);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1005;   char mp[MAXN][MAXN];   int ansmp[MAXN][MAXN];   int dire[4][2] = {0, -1, 0, 1, -1, 0, 1, 0};   int n, m;   void fillansmap(int x0, int y0, int x1, int y1) {     bool colorflag[5];     int dx = (x1 - x0 > 0);     int dy = (y1 - y0 > 0);     int dcolor;     for (int i = 1; i <= 4; i++) colorflag[i] = true;     for (int x = x0, y = y0; x <= x1 && y <= y1; x += dx, y += dy) {       for (int i = 0; i < 4; i++) {         int xx = x + dire[i][0];         int yy = y + dire[i][1];         if (0 <= xx && xx < n && 0 <= yy && yy < m)           colorflag[ansmp[xx][yy]] = false;       }     }     for (int i = 1; i <= 4; i++)       if (colorflag[i]) {         dcolor = i;         break;       }     for (int x = x0, y = y0; x <= x1 && y <= y1; x += dx, y += dy)       ansmp[x][y] = dcolor, mp[x][y] =  . ;     return;   }   bool CheckMap() {     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (mp[i][j] !=  . ) return false;     return true;   }   int main() {     bool ansflag = true;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++) scanf( %s , mp[i]);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++)         if (mp[i][j] ==  b ) {           if (i > 0 && mp[i - 1][j] ==  w  && i < n - 1 && mp[i + 1][j] ==  w )             fillansmap(i - 1, j, i + 1, j);           else if (j > 0 && mp[i][j - 1] ==  w  && j < m - 1 &&                    mp[i][j + 1] ==  w )             fillansmap(i, j - 1, i, j + 1);         }     if (CheckMap()) {       printf( YES n );       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++)           if (ansmp[i][j] == 0)             printf( . );           else             printf( %c , ansmp[i][j] - 1 +  a );         printf(  n );       }     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int INF = 2e9 + 9;   const long long INF1 = 1e18 + 9;   const long long MAXN = 4e5 + 7;   const long long MAXN1 = 1 << 11;   const long long MAXN2 = 4e6 + 9;   const long long MOD = 1e9 + 7;   const long long MOD1 = 1e9 + 9;   const long long ALPH = 50;   const long long PW1 = 239;   const long long PW2 = 199;   const long long PW3 = 193;   const long long PW4 = 117;   const long double EPS = 1e-9;   const long long BLOCK = 3684;   const long long BLOCK1 = 1 << 9;   void solve();   signed main() {     srand( a  +  l  +  e  +  x  +  X  +  5  +  1  +  2 );     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int q = 1;     if (0) cin >> q;     while (q--) solve();   }   set<int> v[MAXN];   void solve() {     int n, m;     cin >> n >> m;     vector<int> v1(n), v2(n);     for (int i = 0; i < m; ++i) {       int a, b;       cin >> a >> b;       v[a].emplace(b);       v[b].emplace(a);     }     for (int i = 1; i <= n; ++i) {       v[i].emplace(i);       if (v[i].size() == n) continue;       for (int j = 1; j <= n; ++j) {         if (v[i].find(j) == v[i].end()) {           cout <<  YES n ;           v2[i - 1] = v2[j - 1] = v1[i - 1] = 1;           v1[j - 1] = 2;           int ind = 2;           for (int t = 0; t < n; ++t)             if (v1[t] == 0) v1[t] = ++ind;           ind = 2;           for (int t = 0; t < n; ++t)             if (v2[t] == 0) v2[t] = ++ind;           for (auto &i : v1) cout << i <<    ;           cout <<   n ;           for (auto &i : v2) cout << i <<    ;           return;         }       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MAXN = 1e4 + 10;   int a[MAXN], b[MAXN], c[MAXN];   int n;   void fun(int pre) {     for (int i = 0; i < n; i++) c[i] = a[i];     for (int i = 0; i <= pre; i++) {       c[i] = a[n - pre - 1 + i];       c[n - pre - 1 + i] = a[i];     }     for (int i = 0; i < n; i++) a[i] = c[i];   }   int main() {     int T;     cin >> T;     while (T--) {       cin >> n;       for (int i = 0; i < n; i++) cin >> a[i];       for (int i = 0; i < n; i++) cin >> b[i];       if ((n % 2 == 1) && a[n / 2] != b[n / 2]) {         cout <<  No  << endl;       } else {         int retflag = 1;         for (int i = n / 2 - 1; i >= 0 && retflag; i--) {           if (a[i] == b[i] && a[n - i - 1] == b[n - i - 1]) continue;           int flag = 1;           for (int j = 0; j <= i && flag; j++) {             if (flag && a[j] == b[i] && a[n - j - 1] == b[n - i - 1]) {               flag = 0;               fun(j);               fun(i);             }             if (flag && a[j] == b[n - i - 1] && a[n - j - 1] == b[i]) {               flag = 0;               fun(j);               fun(0);               fun(i);             }           }           if (flag) retflag = 0;         }         if (retflag)           cout <<  Yes  << endl;         else           cout <<  No  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[n + 2];     a[0] = 0;     for (int i = 1; i < n; i++) {       scanf( %d , &a[i]);     }     for (int i = 1; i < n; i++) {       a[i] = a[i - 1] + a[i];     }     int x, y;     scanf( %d%d , &x, &y);     printf( %d , a[y - 1] - a[x - 1]);   }
#include <bits/stdc++.h>   using namespace std;   void init_code() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   long long dp[5002][5002];   long long solve(vector<long long>& v, long long k, long long n, long long idx) {     if (k == 0) return 0;     if (idx >= n) return 0;     if (dp[idx][k] != -1) return dp[idx][k];     auto i = (upper_bound(v.begin(), v.end(), v[idx] + 5) - v.begin());     long long cnt = i - idx;     long long temp = solve(v, k - 1, n, i) + cnt;     temp = max(temp, solve(v, k, n, idx + 1));     dp[idx][k] = temp;     return temp;   }   void solve() {     long long n, k;     cin >> n >> k;     vector<long long> v(n);     for (long long i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     memset(dp, -1, sizeof(dp));     cout << solve(v, k, n, 0);   }   signed main() {     init_code();     long long tc = 1;     long long num = 1;     while (tc--) {       num++;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int a1, a2, b1, b2;   bool sol(int a, int b) {     if (b + 1 < a) return 0;     if (b > (a + 1) * 2) return 0;     return 1;   }   int main() {     cin >> a1 >> a2 >> b1 >> b2;     if (sol(a1, b2) || sol(a2, b1))       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<int, int> arr[1000006];   int main() {     int n, v, ans = 0, i, j, a, b, v1;     scanf( %d , &n);     scanf( %d , &v);     for (i = 0; i < n; ++i) {       scanf( %d , &a);       scanf( %d , &b);       arr[a].first += b;       arr[a + 1].second += b;     }     for (i = 0; i < 4; ++i)       cerr <<  i             <<  :   << i <<   |              <<  arr[i].F             <<  :   << arr[i].first <<   |              <<  arr[i].S             <<  :   << arr[i].second << endl;     ;     v1 = v;     for (i = 0; i < 3002; ++i) {       v1 = v;       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  arr[i].F               <<  :   << arr[i].first <<   |                <<  arr[i].S               <<  :   << arr[i].second <<   |                <<  v               <<  :   << v << endl;       ;       if (arr[i].second > 0) {         if (arr[i].second - v <= 0) {           v -= arr[i].second;           ans += arr[i].second;           arr[i].second = 0;         } else {           ans += v;           arr[i].second -= v;           v = 0;         }       }       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  arr[i].F               <<  :   << arr[i].first <<   |                <<  arr[i].S               <<  :   << arr[i].second <<   |                <<  v               <<  :   << v << endl;       ;       if (arr[i].first > 0) {         if (arr[i].first - v <= 0) {           ans += arr[i].first;           arr[i + 1].second -= arr[i].first;           arr[i].first = 0;           v -= arr[i].first;         } else {           cerr <<  i                 <<  :   << i << endl;           ;           ans += v;           arr[i].first -= v;           arr[i + 1].second -= v;           v = 0;         }       }       v = v1;       if (i <= 3)         cerr <<  i               <<  :   << i <<   |                <<  ans               <<  :   << ans << endl;       ;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int a[6][6], i, j, k;     int dx[4] = {-1, 0, 1, -1}, dy[4] = {-1, -1, -1, 0};     char x;     memset(a, -1, sizeof(a));     for (i = 1; i < 5; i++) {       for (j = 1; j < 5; j++) {         x = getchar();         if (x ==  x ) a[i][j] = 1;         if (x ==  . ) a[i][j] = 0;       }       getchar();     }     for (i = 1; i < 5; i++) {       for (j = 1; j < 5; j++) {         for (k = 0; k < 4; k++)           if (a[i][j] + a[i + dx[k]][j + dy[k]] + a[i - dx[k]][j - dy[k]] > 1) {             printf( YES n );             return 0;           }       }     }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t;   int n, q;   vector<int> vi[300005];   bool used[300005];   int pre[300005];   vector<pair<int, int> > pos[300005];   int poss[300005];   int main() {     cin >> t;     while (t--) {       scanf( %d%d , &n, &q);       for (int i = 0; i < q; i++) vi[i].clear();       for (int i = 1; i <= n; i++) {         pre[i] = -1;         used[i] = 0;         pos[i].clear();       }       for (int i = 0; i < q; i++) {         int k;         scanf( %d , &k);         for (int j = 0; j < k; j++) {           int a;           scanf( %d , &a);           vi[i].push_back(a);         }       }       bool answer = 0;       for (int i = 0; i < q; i++) {         if (vi[i].size() < 614) continue;         for (int x = 0; x < vi[i].size(); x++) used[vi[i][x]] = 1;         for (int x = 0; x < vi[i].size(); x++) poss[vi[i][x]] = x;         for (int x = 0; x < vi[i].size(); x++)           if (x) pre[vi[i][x]] = vi[i][x - 1];         for (int j = 0; j < q; j++) {           if (i == j) continue;           bool in = 0;           int prre = 1000000000;           for (int k = 0; k < vi[j].size(); k++) {             if (used[vi[j][k]]) {               if (in) {                 int need = pre[vi[j][k]];                 int real = vi[j][k - 1];                 if (need != real && prre < poss[vi[j][k]]) {                   puts( Human );                   answer = 1;                   goto end;                 }               }               in = 1;               prre = min(prre, poss[vi[j][k]]);             }           }         }         for (int x = 0; x < vi[i].size(); x++) used[vi[i][x]] = 0;         for (int x = 0; x < vi[i].size(); x++)           if (x) pre[vi[i][x]] = -1;       }     end:;       if (answer) continue;       for (int i = 0; i < q; i++) {         if (vi[i].size() >= 614) continue;         for (int x = 0; x < vi[i].size(); x++) {           pos[vi[i][x]].push_back(make_pair(i, x));         }       }       for (int beg = 1; beg <= n; beg++) {         for (int i = 0; i < pos[beg].size(); i++) {           int id = pos[beg][i].first;           int nm = pos[beg][i].second;           for (int j = nm + 1; j < vi[id].size(); j++) {             int cur = vi[id][j];             int prre = vi[id][j - 1];             if (pre[cur] == -1) {               pre[cur] = prre;             } else if (pre[cur] != prre) {               puts( Human );               answer = 1;               goto end2;             }           }         }         for (int i = 0; i < pos[beg].size(); i++) {           int id = pos[beg][i].first;           int nm = pos[beg][i].second;           for (int j = nm + 1; j < vi[id].size(); j++) {             int cur = vi[id][j];             pre[cur] = -1;           }         }       }     end2:;       if (answer) continue;       puts( Robot );     }   }
#include <bits/stdc++.h>   using namespace std;   bool a[55][55], b[55][55], ans[55][55];   int n, m, ans_cnt;   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cin >> a[i][j];     for (int i = 1; i <= n - 1; i++)       for (int j = 1; j <= m - 1; j++)         if (a[i][j] && a[i + 1][j] && a[i][j + 1] && a[i + 1][j + 1]) {           ans[i][j] = true;           ans_cnt++;           b[i][j] = b[i + 1][j] = b[i][j + 1] = b[i + 1][j + 1] = true;         }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (a[i][j] != b[i][j]) {           cout << -1;           return 0;         }     cout << ans_cnt <<   n ;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (ans[i][j]) cout << i <<     << j <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans;     long long sum = 0;     map<long long, int> d;     cin >> n;     ans = n - 1;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       sum += t;       d[sum]++;       ans = min(ans, n - d[sum]);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int n = (int)s.size();     int pos[n + 1];     int st = 1, end = n;     int temp = 1;     for (auto x : s) {       if (st > end) break;       if (x ==  l ) {         pos[end--] = temp++;       } else {         pos[st++] = temp++;       }     }     for (int i = 1; i <= n; i++) {       printf( %d n , pos[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e5 + 7;   vector<long long> vec;   long long solve(vector<long long>& a, long long i) {     if (i == -1) return 0;     vector<long long> a1, a0;     for (long long x : a)       if (x & (1 << i))         a1.push_back(x);       else         a0.push_back(x);     if (a0.empty() || a1.empty()) return solve(a, i - 1);     return min(solve(a1, i - 1), solve(a0, i - 1)) + (1 << i);   }   int32_t main() {     long long n;     cin >> n;     for (long long i = 0, x; i < n; i++) cin >> x, vec.push_back(x);     cout << solve(vec, 30) << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline T bigmod(T p, T e, T M) {     long long ret = 1;     for (; e > 0; e >>= 1) {       if (e & 1) ret = (ret * p) % M;       p = (p * p) % M;     }     return (T)ret;   }   template <class T>   inline T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   inline T modinverse(T a, T M) {     return bigmod(a, M - 2, M);   }   int dis[4][1001][1001], n, m;   ;   queue<pair<int, int> > Q;   char pp[1011][1011];   int nxt[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   void go(int c) {     while (!Q.empty()) Q.pop();     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j)         if (pp[i][j] ==  0  + c) {           dis[c][i][j] = 0;           Q.push(make_pair(i, j));         }     }     while (!Q.empty()) {       pair<int, int> p = Q.front();       Q.pop();       for (int i = (0); i < (4); ++i) {         int x = p.first + nxt[i][0], y = p.second + nxt[i][1];         if (x < 0 || x >= n || y < 0 || y >= m || pp[x][y] ==  # ) continue;         if (dis[c][x][y] <= dis[c][p.first][p.second] + 1) continue;         dis[c][x][y] = dis[c][p.first][p.second] + 1;         Q.push(make_pair(x, y));       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     for (int i = (0); i < (n); ++i) cin >> pp[i];     memset(dis, 126, sizeof dis);     go(1);     go(2);     go(3);     int res = INT_MAX / 3;     for (int i = (1); i < (4); ++i) {       int dd[4];       memset(dd, 126, sizeof dd);       dd[i] = 1;       for (int j = (0); j < (n); ++j) {         for (int k = (0); k < (m); ++k) {           if (pp[j][k] >=  1  && pp[j][k] <=  3  && pp[j][k] !=  0  + i)             dd[pp[j][k] -  0 ] = min(dd[pp[j][k] -  0 ], dis[i][j][k]);         }       }       long long sum = 0;       for (int j = (1); j < (4); ++j) sum += dd[j] - 1;       if (sum < res) res = sum;     }     for (int i = (0); i < (n); ++i) {       for (int j = (0); j < (m); ++j) {         if (pp[i][j] !=  . ) continue;         long long sum = 1;         for (int k = (1); k < (4); ++k) {           sum += dis[k][i][j] - 1;         }         if (sum < res) res = sum;       }     }     if (res > 10000000)       cout << -1 << endl;     else       cout << res << endl;   }
#include <bits/stdc++.h>   const int MAX_N = 20;   int n, k, t;   int e[MAX_N + 1][MAX_N + 1];   int choosen[MAX_N + 1];   int mid;   int cnt;   void dfs(int x, int now_cost_sum) {     if (now_cost_sum > mid) return;     if (cnt >= t) return;     if (x > n) {       cnt++;       return;     }     dfs(x + 1, now_cost_sum);     for (int y = 1; y <= n && cnt < t; y++)       if (!choosen[y] && e[x][y]) {         choosen[y] = 1;         dfs(x + 1, now_cost_sum + e[x][y]);         choosen[y] = 0;       }   }   int main() {     scanf( %d%d%d , &n, &k, &t);     for (int i = 1; i <= k; i++) {       int h, w, r;       scanf( %d%d%d , &h, &w, &r);       e[h][w] = r;     }     int low = 0, high = 1000 * n;     while (low < high) {       mid = (low + high) >> 1;       cnt = 0;       dfs(1, 0);       if (cnt >= t)         high = mid;       else         low = mid + 1;     }     printf( %d n , low);   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<pair<long long int, long long int> > p_que;   long long int arr[300005];   long long int ans[300005];   int main(int argc, char const *argv[]) {     long long int n, k;     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     for (int i = 1; i <= k; i++) {       p_que.push(make_pair(arr[i], i));     }     long long int tot = 0;     for (int i = k + 1; i <= n + k; i++) {       if (i <= n) p_que.push(make_pair(arr[i], i));       pair<long long int, long long int> p = p_que.top();       p_que.pop();       tot = tot + (i - p.second) * p.first;       ans[p.second] = i;     }     cout << tot <<   n ;     for (int i = 1; i <= n; i++) {       cout << ans[i] <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   const long long MX = 2 * 100 * 1000 + 1000, inf = 3e18,                   mod = 1000 * 1000 * 1000 + 7;   using namespace std;   vector<long long> ans[MX];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long n = s.size();     long long one = 0, num = 0;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (one < num) {           ans[one].push_back(i);           one++;         } else {           return cout << -1 << endl, 0;         }       } else {         if (one > 0) {           one--;           ans[one].push_back(i);         } else {           ans[num].push_back(i);           num++;         }       }     }     if (one) {       return cout << -1 << endl, 0;     }     cout << num << endl;     for (long long i = 0; i < num; i++) {       cout << ans[i].size() <<    ;       for (long long j = 0; j < ans[i].size(); j++) {         cout << ans[i][j] + 1 <<    ;       }       cout << endl;     }   }