malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, G[1005][1005], ans = 1000000000;   char str[1005][1005];   bool vis[1005][1005];   int dfs(int x, int y, int wx, int wy) {     vis[x][y] = true;     if ((G[x + wx - 1][y + wy] - G[x - 1][y + wy] - G[x + wx - 1][y + 1 - 1] +          G[x - 1][y + 1 - 1]) == wx * wy)       return wx + dfs(x, y + 1, wx, wy);     if ((G[x + wx][y + wy - 1] - G[x + 1 - 1][y + wy - 1] - G[x + wx][y - 1] +          G[x + 1 - 1][y - 1]) == wx * wy)       return wy + dfs(x + 1, y, wx, wy);     return 0;   }   int main() {     memset(vis, false, sizeof(vis));     scanf( %d%d n , &n, &m);     int flag = 0, px, py;     for (int i = 1; i <= n; i++) scanf( %s , str[i] + 1);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         if (str[i][j] ==  X ) {           if (!flag) {             flag = 1;             px = i;             py = j;           }           G[i][j] = G[i - 1][j] + G[i][j - 1] - G[i - 1][j - 1] + 1;         } else           G[i][j] = G[i - 1][j] + G[i][j - 1] - G[i - 1][j - 1];       }     int tmp, wx, wy;     for (tmp = px; str[tmp][py] ==  X ; tmp++)       ;     wx = tmp - px;     for (int i = py; str[px][i] ==  X ; i++)       if (dfs(px, py, wx, i - py + 1) + wx * (i - py + 1) == G[n][m])         ans = min(ans, wx * (i - py + 1));     for (tmp = py; str[px][tmp] ==  X ; tmp++)       ;     wy = tmp - py;     for (int i = px; str[i][py] ==  X ; i++)       if (dfs(px, py, i - px + 1, wy) + (i - px + 1) * wy == G[n][m])         ans = min(ans, (i - px + 1) * wy);     if (ans <= n * m)       printf( %d n , ans);     else       printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     unsigned long long n;     unsigned long long a[100050];     unsigned long long b[200050];     scanf( %lld , &n);     for (int i = 0; i < n / 2; i++) scanf( %lld , &a[i]);     b[0] = 0;     b[n - 1] = a[0];     for (int i = 1; i < n / 2; i++) {       b[n - 1 - i] = min(b[n - i], a[i] - b[i - 1]);       b[i] = a[i] - b[n - 1 - i];     }     for (int i = 0; i < n; i++) printf( %lld  , b[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int arr[100] = {0}, con = 0, d = 0;     ;     string x;     cin >> x;     for (int i = 0; i < x.size(); i++) {       if (x[i] ==  + ) {         for (int j = 0; j < con; j++) {           arr[d] += (x[i - j - 1] - 48) * pow(10, j);         }         d++;         con = 0;       } else         con++;     }     for (int j = 0; j < con; j++) {       arr[d] += (x[x.size() - j - 1] - 48) * pow(10, j);     }     sort(arr, arr + d + 1);     for (int j = 0; j <= d; j++) {       if (j == d)         cout << arr[j];       else         cout << arr[j] <<  + ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     cout.tie(nullptr);     long long t;     cin >> t;     while (t--) {       vector<vector<long long> > a(2);       vector<long long> ans;       long long n;       string b;       cin >> n >> b;       long long cou = 1;       for (char c : b) {         long long x = c -  0 ;         if (a[x].size() == 0) a[x].push_back(cou++);         ans.push_back(a[x].back());         a[!x].push_back(a[x].back());         a[x].pop_back();       }       cout << cou - 1 <<   n ;       for (long long i : ans) cout << i <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int comp(long long a, long long b) { return a > b; }   long long arr[100000], cdf[100000];   int main() {     int i, m;     long long k, n;     cin >> n;     cin >> arr[0];     for (i = 1; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n, comp);     cdf[0] = arr[0];     for (i = 1; i < n; i++) {       cdf[i] = arr[i] + cdf[i - 1];     }     cin >> m;     long long rrr = 0;     for (i = 1; i < n; i++) {       rrr += arr[i] * i;     }     int ll;     for (ll = 0; ll < m; ll++) {       cin >> k;       long long sum = 0LL;       if (k == 1)         cout << rrr <<    ;       else {         int mm;         long long as, t = 1;         for (as = 1, mm = 1; as < n; as = as + t, mm++) {           t *= k;           sum += (cdf[min(as + t - 1, n - 1)] - cdf[as - 1]) * mm;         }         cout << sum <<    ;       }     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace red {   inline long long read() {     long long x = 0;     char ch, f = 1;     for (ch = getchar(); (ch <  0  || ch >  9 ) && ch !=  - ; ch = getchar())       ;     if (ch ==  - ) f = 0, ch = getchar();     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return f ? x : -x;   }   const long long N = 1e6 + 10, inf = 1e9 + 7, base = 131, mod = 1e9 + 7;   long long n, m, t, ret;   char a[N], b[N], s[N];   long long nxt[N], f[N], g[N];   long long pw[N], ha[N], hs[N];   inline void prepare(char *a, long long *f) {     long long len = max(n, m);     for (long long i = pw[0] = 1; i <= len; ++i) pw[i] = pw[i - 1] * base % mod;     for (long long i = 1; i <= n; ++i) ha[i] = (ha[i - 1] * base + a[i]) % mod;     for (long long i = 1; i <= m; ++i) hs[i] = (hs[i - 1] * base + s[i]) % mod;     for (long long i = 1; i <= n; ++i) {       long long l = i, r = n;       while (l <= r) {         long long t1 = (ha[((l + r) >> 1)] -                         ha[i - 1] * pw[((l + r) >> 1) - i + 1] % mod + mod) %                        mod;         long long t2 = hs[((l + r) >> 1) - i + 1];         if (t1 == t2)           f[i] = ((l + r) >> 1) - i + 1, l = ((l + r) >> 1) + 1;         else           r = ((l + r) >> 1) - 1;       }       f[i] = min(f[i], m - 1);     }   }   struct BIT {     long long tr[N];     BIT() { memset(tr, 0, sizeof(tr)); }     inline void update(long long p, long long k) {       for (p++; p < N; p += p & (-p)) tr[p] += k;     }     inline long long query(long long p) {       long long ret = 0;       for (p++; p; p -= p & (-p)) ret += tr[p];       return ret;     }   } bit[2];   inline void main() {     n = read(), m = read();     scanf( %s%s%s , a + 1, b + 1, s + 1);     prepare(a, f);     reverse(s + 1, s + m + 1);     reverse(b + 1, b + n + 1);     prepare(b, g);     reverse(g + 1, g + n + 1);     for (long long i = n; i; --i) {       bit[0].update(g[i], 1);       bit[1].update(g[i], g[i]);       if (i + m - 1 <= n) {         bit[0].update(g[i + m - 1], -1);         bit[1].update(g[i + m - 1], -g[i + m - 1]);       }       if (!f[i]) continue;       long long v = m - f[i];       ret += bit[1].query(m) - bit[1].query(v - 1);       ret -= (bit[0].query(m) - bit[0].query(v - 1)) * (v - 1);     }     printf( %lld n , ret);   }   }  // namespace red   signed main() {     red::main();     return 0;   }
#include <bits/stdc++.h>   template <typename T>   inline void SWAP(T &a, T &b) {     T tmp = a;     a = b;     b = tmp;   }   template <typename T>   inline T ABS(const T &val) {     return val < 0 ? -val : val;   }   template <typename T>   inline T MAX(const T &a, const T &b) {     return a > b ? a : b;   }   template <typename T>   inline T MIN(const T &a, const T &b) {     return a < b ? a : b;   }   template <typename T>   inline T SQR(const T &a) {     return a * a;   }   const int INTinf = 2147483647;   const int nINTinf = 0 - 2147483648;   using namespace std;   int n;   char A[5005][5005];   bool was[5005];   bool bad[5005];   int CY[5005];   int kon = 0;   int POS = 0;   bool FF = false;   bool G = false;   void rec(const int &x) {     if (bad[x]) return;     if (was[x]) {       POS = x;       FF = true;     } else {       was[x] = true;       for (int i = 0; i != n; i++) {         if (A[x][i]) {           rec(i);           if (FF) {             if (!G) {               CY[kon++] = x;               if (POS == x) G = true;             }             return;           }         }       }       bad[x] = true;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i != n; i++) {       scanf( %s , A[i]);       for (int j = 0; j != n; j++) {         A[i][j] -=  0 ;       }     }     for (int i = 0; i != n; i++) {       if (!bad[i]) rec(i);       if (FF) break;     }     if (FF) {       reverse(CY, CY + kon);       int ST = CY[0];       for (int i = 2; i != kon; i++) {         if (A[CY[i]][ST]) {           cout << ST + 1 <<     << CY[i - 1] + 1 <<     << CY[i] + 1 << endl;           return 0;         }       }     } else {       cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 1e3 + 7;   long long dp[N][N][11][2], n, m, k;   string s, t;   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k >> s >> t;     for (long long l = 1; l <= k; l++) {       for (long long i = 1; i <= n; i++) {         for (long long j = 1; j <= m; j++) {           if (s[i - 1] == t[j - 1])             dp[i][j][l][0] =                 1 + max(dp[i - 1][j - 1][l - 1][1], dp[i - 1][j - 1][l][0]);           dp[i][j][l][1] =               max(dp[i][j][l][0], max(dp[i - 1][j][l][1], dp[i][j - 1][l][1]));         }       }     }     cout << dp[n][m][k][1];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       long long p, f;       cin >> p >> f;       long long cnt1, cnt2;       cin >> cnt1 >> cnt2;       long long s, w;       cin >> s >> w;       if (s > w) {         swap(s, w);         swap(cnt1, cnt2);       }       long long ans = 0;       for (long long i = 0; i <= min(cnt1, p / s); i++) {         long long cnt = i;         long long tmpp = p - i * s;         cnt += (min(cnt2, tmpp / w));         long long tmpw = cnt2 - min(cnt2, tmpp / w), tmps = cnt1 - i;         cnt += min(tmps, f / s);         long long tmpf = f - min(tmps, f / s) * s;         cnt += min(tmpw, tmpf / w);         ans = max(ans, cnt);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void in(int &n) {     n = 0;     int ch = getchar();     int sign = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) sign = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       n = (n << 3) + (n << 1) + ch -  0 , ch = getchar();     }     n = n * sign;   }   pair<int, int> a[100005];   long long int Fsum[100005], Rsum[100005];   long long int solve(long long int val, int low, int up) {     int n = up;     while (low < up) {       int mid = low + (up - low) / 2;       if (a[mid].first >= val) {         low = mid + 1;       } else {         up = mid;       }     }     long long int ans = val * (n - low + 1) - Rsum[low];     return ans;   }   int res[100005];   int main() {     int n;     long long int A;     int Cf, Cm;     in(n);     cin >> A;     in(Cf);     in(Cm);     long long int m;     cin >> m;     for (int i = 1; i <= n; i++) {       in(a[i].first);       a[i].second = i;     }     sort(a + 1, a + 1 + n);     reverse(a + 1, a + 1 + n);     Fsum[0] = 0;     for (int i = 1; i <= n; i++) {       Fsum[i] = Fsum[i - 1] + a[i].first;     }     Rsum[n + 1] = 0;     for (int i = n; i >= 1; i--) {       Rsum[i] = Rsum[i + 1] + a[i].first;     }     long long int ans = 0;     int X, Y;     if (A * n - Fsum[n] <= m) {       ans = n * Cf + A * Cm;       X = n;       Y = A;     }     for (int i = 1; i <= n; i++) {       int low = a[n].first;       int up = A;       while (low < up) {         int mid = low + (up - low + 1) / 2;         long long int total = A * (i - 1) - Fsum[i - 1] + solve(mid, i, n);         if (total <= m) {           low = mid;         } else {           up = mid - 1;         }       }       long long int total = A * (i - 1) - Fsum[i - 1] + solve(low, i, n);       if (total <= m) {         long long int p = low;         p *= Cm;         long long int curr = (i - 1) * Cf + p;         if (curr >= ans) {           ans = curr;           X = i - 1;           Y = low;         }       }     }     for (int i = 1; i <= n; i++) {       if (i <= X) {         res[a[i].second] = A;       } else {         res[a[i].second] = max(a[i].first, Y);       }     }     printf( %I64d n , ans);     for (int i = 1; i <= n; i++) {       printf( %d  , res[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   inline void chkmin(T1 &x, T2 y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, T2 y) {     if (x < y) x = y;   }   inline int readChar();   template <class T = int>   inline T readInt();   template <class T>   inline void writeInt(T x, char end = 0);   inline void writeChar(int x);   inline void writeWord(const char *s);   static const int buf_size = 4096;   inline int getChar() {     static char buf[buf_size];     static int len = 0, pos = 0;     if (pos == len) {       pos = 0, len = fread(buf, 1, buf_size, stdin);     }     if (pos == len) {       return -1;     }     return buf[pos++];   }   inline int readChar() {     int c = getChar();     while (c <= 32) {       c = getChar();     }     return c;   }   template <class T>   inline T readInt() {     int s = 1, c = readChar();     T x = 0;     if (c ==  - ) s = -1, c = getChar();     while ( 0  <= c && c <=  9 ) x = x * 10 + c -  0 , c = getChar();     return s == 1 ? x : -x;   }   static int write_pos = 0;   static char write_buf[buf_size];   inline void writeChar(int x) {     if (write_pos == buf_size)       fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;     write_buf[write_pos++] = x;   }   template <class T>   inline void writeInt(T x, char end) {     if (x < 0) writeChar( - ), x = -x;     char s[24];     int n = 0;     while (x || !n) s[n++] =  0  + x % 10, x /= 10;     while (n--) writeChar(s[n]);     if (end) writeChar(end);   }   inline void writeWord(const char *s) {     while (*s) writeChar(*s++);   }   struct Flusher {     ~Flusher() {       if (write_pos) fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;     }   } flusher;   const string FILENAME =  input ;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     if (n & 1) {       cout << (n / 2 + 1) * (n / 2 + 1) << endl;     } else {       cout << (n / 2 + 1) * (n / 2) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   FILE *in;   FILE *out;   int n, m, k;   char a[64][64];   int blocks[64][64];   int cell[64 * 64][2];   int dyn[64 * 64][4][2];   int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};   void fill(int row, int col, int color) {     blocks[row][col] = color;     for (int i = 0; i < 4; i++) {       int nrow = row + dir[i][0];       if (nrow < 0 || nrow >= n) continue;       int ncol = col + dir[i][1];       if (ncol < 0 || ncol >= m) continue;       if (a[row][col] == a[nrow][ncol] && blocks[nrow][ncol] == -1)         fill(nrow, ncol, color);     }   }   void getBlocks() {     int nextColor = 0;     memset(blocks, -1, sizeof(blocks));     for (int i = 0; i < n; i++) {       for (int c = 0; c < m; c++) {         if (a[i][c] !=  0  && blocks[i][c] == -1) {           fill(i, c, nextColor);           cell[nextColor][0] = i;           cell[nextColor][1] = c;           nextColor++;         }       }     }   }   int main(void) {     in = stdin;     out = stdout;     fscanf(in,  %d %d , &n, &k);     for (int i = 0; i < n; i++) fscanf(in,  %s , a[i]);     m = (int)strlen(a[0]);     getBlocks();     memset(dyn, -1, sizeof(dyn));     int rem = k, cur = 0;     int bp = 0, dp = 1, cp = 0;     int foundCycle = 0;     while (rem) {       rem--;       cur++;       if (!foundCycle && dyn[bp][dp][cp] != -1) {         foundCycle = 1;         rem %= (cur - dyn[bp][dp][cp]);       }       dyn[bp][dp][cp] = cur;       int row = cell[bp][0], col = cell[bp][1];       while (1) {         int nrow = row + dir[dp][0];         if (nrow < 0 || nrow >= n) break;         int ncol = col + dir[dp][1];         if (ncol < 0 || ncol >= m) break;         if (a[nrow][ncol] != a[row][col]) break;         row = nrow;         col = ncol;       }       int dd = (cp ? ((dp + 1) % 4) : ((dp + 3) % 4));       while (1) {         int nrow = row + dir[dd][0];         if (nrow < 0 || nrow >= n) break;         int ncol = col + dir[dd][1];         if (ncol < 0 || ncol >= m) break;         if (a[nrow][ncol] != a[row][col]) break;         row = nrow;         col = ncol;       }       int nrow = row + dir[dp][0];       int ncol = col + dir[dp][1];       if (nrow >= 0 && nrow < n && ncol >= 0 && ncol < m &&           a[nrow][ncol] !=  0 ) {         bp = blocks[nrow][ncol];         continue;       }       if (cp == 0)         cp = 1;       else {         cp = 0;         dp = (dp + 1) % 4;       }     }     fprintf(out,  %c n , a[cell[bp][0]][cell[bp][1]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 prng(chrono::steady_clock::now().time_since_epoch().count());   void testCase(int caseno) {     int n, k, a, b;     cin >> n >> k;     multiset<int> aa;     multiset<int> bb;     int sum = 0;     for (int i = 0; i < n; i++) {       cin >> a;       sum += a;       aa.insert(a);     }     for (int i = 0; i < n; i++) {       cin >> b;       bb.insert(b);     }     for (int i : aa) {     }     for (int i : bb) {     }     int it = 0;     while (*(aa.begin()) < *(--bb.end()) && it < k) {       it++;       sum -= *(aa.begin());       sum += *(--bb.end());       aa.insert(*(--bb.end()));       bb.insert(*(aa.begin()));       auto ita = aa.begin();       auto itb = --bb.end();       aa.erase(ita);       bb.erase(itb);     }     cout << sum << endl;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       testCase(i + 1);     }     return 0;   }
#include <bits/stdc++.h>   const double g = 9.8;   using namespace std;   const long long mod = 998244353;   long long quick(long long prea, long long bbb) {     long long res = 1;     while (bbb) {       if (bbb & 1) res = res * prea % mod;       prea = prea * prea % mod;       bbb >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   pair<int, int> pp;   const int w = 2e5 + 5;   long long a[w];   stack<long long> s;   int main() {     long long k, m, n, t, i, j;     cin >> n;     for (i = 0; i < n; i++) {       cin >> m;       if (s.empty())         s.push(m);       else {         if (abs(m - s.top()) % 2 == 0)           s.pop();         else           s.push(m);       }     }     if (s.size() > 1)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[m];     for (int i = 0; i < m; i++) {       cin >> a[i];       if (a[i] > n - i) {         cout << -1 << endl;         return 0;       }     }     long long suf_sum[m + 1];     suf_sum[m] = 0;     for (int i = m - 1; i >= 0; i--) {       suf_sum[i] = suf_sum[i + 1] + a[i];     }     if (suf_sum[0] < n) {       cout << -1 << endl;       return 0;     }     for (int i = 0; i < m; i++) {       cout << max((long long)i + 1, n - suf_sum[i] + 1) <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, mod = 998244353;   int inv[N], fac[N];   int ksm(int b, int n) {     int res = 1;     while (n) {       if (n & 1) res = 1ll * res * b % mod;       b = 1ll * b * b % mod;       n >>= 1;     }     return res;   }   void init(int n) {     fac[0] = 1;     for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;     inv[n] = ksm(fac[n], mod - 2);     for (int i = n - 1; i >= 0; --i) inv[i] = 1ll * (i + 1) * inv[i + 1] % mod;   }   int C(int n, int m) {     if (n < m || n < 0 || m < 0) return 0;     return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;   }   int calc(int n, int m, int lim) {     if (n == 0) return 1;     if (n < 0) return 0;     int ans = 0;     for (int i = 0; i <= m; ++i) {       int tmp = 1ll * C(n - lim * i + m - 1, m - 1) * C(m, i) % mod;       if (i & 1)         ans = (ans + mod - tmp) % mod;       else         ans = (ans + tmp) % mod;     }     return ans;   }   signed main() {     int p, s, r, ans = 0;     cin >> p >> s >> r;     init(1e5);     for (int i = r; i <= s; ++i)       for (int j = 1; j <= p; ++j) {         if (i * j + (p - j) * (i - 1) < s) continue;         int tmp = 1ll * calc(s - j * i, p - j, i) * C(p - 1, j - 1) % mod;         ans = (ans + 1ll * tmp * ksm(j, mod - 2)) % mod;       }     cout << 1ll * ans * ksm(C(s - r + p - 1, p - 1), mod - 2) % mod;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MOD = 1e9 + 7;   int main() {     cin.tie(0)->sync_with_stdio(0);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       vector<int> r;       for (string t : { twone ,  one ,  two }) {         for (size_t pos = 0; (pos = s.find(t, pos)) != string::npos;) {           s[pos + t.length() / 2] =  ? ;           r.push_back(pos + t.length() / 2);         }       }       cout << r.size() << endl;       for (auto rr : r) cout << rr + 1 <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int n;   int x[2001], y[2001];   int p[2001], mn[2001];   int k[2001], c[2001];   bool used[2001][2001];   unsigned long long dst[2001][2001];   unsigned long long dist(int i, int j) {     return (unsigned long long)(k[i] + k[j]) *            (unsigned long long)(abs(x[i] - x[j]) + abs(y[i] - y[j]));   }   void init() {     for (int i = 0; i < n; i++) {       p[i] = i;       mn[i] = c[i];     }     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         dst[i][j] = dist(i, j);         dst[j][i] = dst[i][j];       }     }   }   struct vertex {     unsigned long long len;     int x, y;     vertex(){};     vertex(unsigned long long _len, int _x, int _y) {       len = _len;       x = _x;       y = _y;     }     bool operator<(vertex b) { return len < b.len; }   };   bool operator<(const vertex& a, const vertex& b) { return a.len < b.len; }   multiset<vertex> s;   int get_anc(int x) {     if (x == p[x]) return x;     return p[x] = get_anc(p[x]);   }   void unite(int x, int y) {     x = get_anc(x);     y = get_anc(y);     if (x == y) return;     if (x < y) swap(x, y);     p[x] = y;     mn[y] = min(mn[x], mn[y]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     for (int i = 0; i < n; i++) cin >> c[i];     for (int i = 0; i < n; i++) cin >> k[i];     init();     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         s.insert(vertex(dst[i][j], i, j));       }     }     unsigned long long ans = 0;     int conn = 0;     while (!s.empty()) {       vertex cur = *s.begin();       s.erase(s.begin());       unsigned long long curlen = cur.len;       int curx = cur.x, cury = cur.y;       if (get_anc(curx) == get_anc(cury)) continue;       if (curlen + min(mn[get_anc(curx)], mn[get_anc(cury)]) >           mn[get_anc(curx)] + mn[get_anc(cury)])         continue;       unite(curx, cury);       ans += curlen;       used[curx][cury] = used[cury][curx] = 1;       conn++;     }     vector<int> way;     for (int i = 0; i < n; i++) {       int x = get_anc(i);       if (c[i] == mn[x]) {         ans += c[i];         mn[i] = -1;         way.push_back(i + 1);       }     }     cout << ans << endl;     cout << way.size() << endl;     for (int i = 0; i < way.size(); i++) cout << way[i] <<    ;     cout << endl;     cout << conn << endl;     for (int i = 0; i < n; i++) {       for (int j = i + 1; j < n; j++) {         if (used[i][j]) cout << i + 1 <<     << j + 1 << endl;       }     }     return 0;   }