malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimization( unroll-loops )   #pragma GCC target( avx,avx2,fma )   using namespace std;   long long arr1[1000000], arr2[1000000], mp[2000000];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, m;     cin >> n >> m;     for (long long i = 0; i < n; i++) cin >> arr1[i];     for (int i = 1; i <= 1000000; i++) mp[i] = -1;     for (long long i = 0; i < m; i++) {       cin >> arr2[i];       mp[arr2[i]] = i;     }     deque<long long> di;     long long hi = 0, maxi = 0, r = -1;     for (long long i = 0; i < n; i++) {       r = max(r, i - 1);       long long asdf = 0;       while (1) {         if (mp[arr1[(r + 1) % n]] == -1) break;         if (di.empty())           di.push_back(mp[arr1[(r + 1) % n]] + hi), asdf++;         else {           if (mp[arr1[(r + 1) % n]] + hi > di[di.size() - 1])             di.push_back(mp[arr1[(r + 1) % n]] + hi), asdf++;           else if (mp[arr1[(r + 1) % n]] + m + hi > di[di.size() - 1] &&                    mp[arr1[(r + 1) % n]] + hi < di[0])             di.push_back(mp[arr1[(r + 1) % n]] + m + hi), asdf++;           else             break;         }         r++;       }       long long f = di.size();       maxi = max(maxi, f);       if (!di.empty()) {         di.pop_front();         if (!di.empty()) {           if (di[0] >= hi + m) hi += m;         }       }     }     cout << maxi;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i == j)           cout << k <<    ;         else           cout <<  0  ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[500005];   int st[500005], num[500005], top;   long long s[500005], pre[500005], suf[500005];   long long ans, pos;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) {       long long now = 1;       while (top && a[i] <= st[top]) {         now += num[top];         top--;       }       st[++top] = a[i];       num[top] = now;       s[top] = s[top - 1] + now * a[i];       pre[i] = s[top];     }     top = 0;     for (int i = n; i >= 1; i--) {       long long now = 1;       while (top && a[i] <= st[top]) {         now += num[top];         top--;       }       st[++top] = a[i];       num[top] = now;       s[top] = s[top - 1] + now * a[i];       suf[i] = s[top];     }     for (int i = 1; i <= n; i++) {       if (ans < pre[i] + suf[i] - a[i]) {         ans = pre[i] + suf[i] - a[i];         pos = i;       }     }     for (int i = pos - 1; i >= 1; i--) a[i] = min(a[i], a[i + 1]);     for (int i = pos + 1; i <= n; i++) a[i] = min(a[i], a[i - 1]);     for (int i = 1; i <= n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   const int N = 100005;   const int MOD = 1000000009;   int f[N];   int find(int x) {     if (x != f[x]) f[x] = find(f[x]);     return f[x];   }   int main() {     int i, n, m, x, y, a, b, r = 0;     scanf( %d%d , &n, &m);     for (i = 1; i <= n; i++) f[i] = i;     while (m--) {       scanf( %d%d , &a, &b);       x = find(a);       y = find(b);       if (x == y) {         r = (r + r + 1) % MOD;       } else {         f[y] = x;       }       printf( %d n , r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct {     double d;     int num;   } node;   node no[1005];   int cmp(node a, node b) { return a.d < b.d; }   double dis(int x, int y) { return sqrt(x * x + y * y); }   int main() {     int n, s;     scanf( %d%d , &n, &s);     for (int i = 0; i < n; ++i) {       double x, y;       scanf( %lf%lf%d , &x, &y, &no[i].num);       no[i].d = dis(x, y);     }     sort(no, no + n, cmp);     int ans;     for (ans = 0; ans < n; ++ans) {       if (s < 1000000) {         s += no[ans].num;         if (s >= 1000000) {           printf( %.7f n , no[ans].d);           break;         }       }     }     if (ans == n) printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, t;     cin >> n >> t;     long long dp[n + 3][2 * t + 3][5];     for (int i = 1; i <= 4; i++) {       dp[n][2 * t - 1][i] = 1;       for (int j = 0; j < 2 * t - 1; j++) {         dp[n][j][i] = 0;       }       for (int j = 1; j <= n; j++) {         dp[j][2 * t][i] = 0;       }     }     for (int i = n - 1; i >= 1; i--) {       for (int j = 2 * t - 1; j >= 0; j--) {         for (int k = 1; k <= 4; k++) {           dp[i][j][k] = 0;           if (j % 2 == 0) {             for (int p = 1; p < k; p++) {               dp[i][j][k] = dp[i][j][k] + dp[i + 1][j + 1][p];             }             for (int p = k + 1; p <= 4; p++) {               dp[i][j][k] = dp[i][j][k] + dp[i + 1][j][p];             }           } else {             for (int p = 1; p < k; p++) {               dp[i][j][k] = dp[i][j][k] + dp[i + 1][j][p];             }             for (int p = k + 1; p <= 4; p++) {               dp[i][j][k] = dp[i][j][k] + dp[i + 1][j + 1][p];             }           }         }       }     }     long long ans = 0;     for (int i = 1; i <= 4; i++) {       ans = ans + (i - 1) * dp[2][0][i];     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 22;   const int MX = 1 << N;   int n;   bool has[MX];   bool vis[MX];   bool num[MX];   void bfs(int node) {     vis[node] = true;     queue<pair<int, int> > nd;     nd.push(make_pair(node, 1));     int tt;     int rem;     while (!nd.empty()) {       node = nd.front().first;       tt = nd.front().second;       nd.pop();       if (tt == 1) {         if (!num[node]) {           num[node] = true;           nd.push(make_pair(node, 2));         }       } else {         rem = (1 << n) - 1 - node;         if (!vis[rem] and has[rem]) {           vis[rem] = true;           nd.push(make_pair(rem, 1));         }         for (int j = 0; j < n; j++) {           if (num[node | (1 << j)] == false) {             num[node | (1 << j)] = true;             nd.push(make_pair(node | (1 << j), 2));           }         }       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int m;     cin >> n >> m;     int x;     for (int i = 0; i < m; i++) {       cin >> x;       has[x] = true;     }     int ans = 0;     for (int i = 0; i < (1 << n); i++) {       if (has[i]) {         if (!vis[i]) {           bfs(i);           ans++;         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, d = 1440, e = 0, f = 2, g = 0, h[1001], i, j, k, p[1001];     string s, t, x;     cin >> a >> b;     for (i = 1; i <= a; i++) {       cin >> p[i];     }     sort(p + 1, p + a + 1);     for (i = 1; i < a; i++) {       for (j = i + 1; j <= a; j++) {         if (p[j] - p[i] <= b) {           e++;         } else {           break;         }       }     }     cout << 2 * e;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     long long a[n];     unordered_set<long long> st;     unordered_map<long long, long long> mp;     vector<long long> V;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (a[i] < 0) {         if (st.find(abs(a[i])) == st.end()) {           cout << -1 <<   n ;           return 0;         } else {           if (mp.find(abs(a[i])) == mp.end()) {             cout << -1 <<   n ;             return 0;           }           mp.erase(abs(a[i]));           if (mp.size() == 0) {             V.push_back(i);             st.clear();             mp.clear();           }         }       } else {         if (a[i] > 0 && st.find(a[i]) == st.end()) {           st.insert(a[i]);           mp[a[i]]++;         } else {           if (mp.size() != 0 && st.size() != 0) {             cout << -1 <<   n ;             return 0;           }           if (st.size() == 0 && mp.size() == 0) {             st.insert(a[i]);             mp[a[i]]++;           } else {             cout << -1 <<   n ;             break;           }         }       }     }     if (st.size() == 0 && mp.size() == 0) {       long long sz = V.size();       cout << sz <<   n ;       cout << V[0] + 1 <<    ;       for (long long i = 1; i < sz; i++) cout << V[i] - V[i - 1] <<    ;       cout <<   n ;     } else       cout << -1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int const mod = 1e9 + 7;   long long int const inf = 1e18;   long long int const mxn = 2e9 + 1;   inline void file() {}   int main() {     file();     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     {       long long int n, a, b;       cin >> n >> a >> b;       if (b < 0) {         b = abs(b) % n;         if (a > b)           cout << a - b;         else           cout << a - b + n;       } else {         a += b;         if (a % n == 0)           cout << n <<   n ;         else           cout << a % n <<   n ;       }     }   }
#include <bits/stdc++.h>   const int inf = (1 << 29) - 1;   const int maxn = (int)3e5 + 10;   const int mod = (int)1e9 + 7;   using namespace std;   int n, m, k;   vector<int> g[2020];   int col[2020][1010];   pair<int, int> e[maxn];   int ans[maxn];   void dfs(int v, int cur, int nxt) {     if (col[v][cur] == 0) {       return;     }     int val = col[v][cur];     col[v][cur] = 0;     col[e[val].first ^ e[val].second ^ v][cur] = 0;     dfs(e[val].first ^ e[val].second ^ v, nxt, cur);     col[v][nxt] = val;     col[e[val].first ^ e[val].second ^ v][nxt] = val;   }   void solve() {     cin >> n >> m >> k;     for (int i = 1; i <= k; i++) {       int x, y;       cin >> x >> y;       y += n;       e[i] = make_pair(x, y);     }     n += m;     for (int i = 1; i <= k; i++) {       int u = e[i].first;       int v = e[i].second;       int c1 = 1;       while (col[u][c1]) ++c1;       int c2 = 1;       while (col[v][c2]) ++c2;       if (c1 > c2) {         swap(u, v);         swap(c1, c2);       }       if (c1 == c2) {         col[u][c1] = col[v][c2] = i;         continue;       }       dfs(v, c1, c2);       col[v][c1] = i;       col[u][c1] = i;     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j < 1010; j++) {         ans[col[i][j]] = j;       }     }     cout << *max_element(ans + 1, ans + k + 1) <<   n ;     for (int i = 1; i <= k; i++) {       cout << ans[i] <<    ;     }   }   int main() {     int t = 1;     for (int i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x = 0, y = 0;     int n, m;     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         char ch;         cin >> ch;         if (ch ==  * ) {           x ^= i;           y ^= j;         }       }     }     cout << x + 1 <<     << y + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m = 1, a, t1 = 1, tong = 0;     cin >> n;     while (1) {       tong += t1;       if (tong > n) {         cout << --m;         return 0;       }       t1 += ++m;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};   int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};   void file() {}   void fast() {     std::ios_base::sync_with_stdio(0);     cin.tie(NULL);   }   const int N = 2e5 + 9;   int arr[N], qi[N], qs[N], qe[N];   long long qans[N], cnt;   int fre[N / 2 * 10 + 9];   long long calc(int num) { return 1LL * fre[num] * fre[num] * num; }   void add(int num) {     cnt -= calc(num);     fre[num]++;     cnt += calc(num);   }   void remove(int num) {     cnt -= calc(num);     fre[num]--;     cnt += calc(num);   }   int main() {     file();     fast();     int n, q;     cin >> n >> q;     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < q; i++) {       qi[i] = i;       cin >> qs[i] >> qe[i];       qs[i]--, qe[i]--;     }     int sq = sqrt(n);     sort(qi, qi + q, [sq](int a, int b) {       return make_pair(qs[a] / sq, qe[a]) < make_pair(qs[b] / sq, qe[b]);     });     int s = 0, e = 0;     for (int i = 0; i < q; i++) {       int idx = qi[i];       while (e <= qe[idx]) add(arr[e++]);       while (s > qs[idx]) add(arr[--s]);       while (e > qe[idx] + 1) remove(arr[--e]);       while (s < qs[idx]) remove(arr[s++]);       qans[idx] = cnt;     }     for (int i = 0; i < q; i++) cout << qans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[500000];   long long b[500000];   long long c[500000];   long long d[500000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i;     cin >> n;     for (i = 1; i <= n; i++) {       long long x;       cin >> x;       if (x == 1)         a[i]++;       else         b[i]++;     }     for (i = 1; i <= n; i++) {       a[i] += a[i - 1];       b[i] += b[i - 1];     }     for (i = 1; i <= 3 * n; i++) {       c[i] = 1e10;       d[i] = 1e10;     }     for (i = 1; i <= n; i++) {       if (c[a[i]] == 1e10) c[a[i]] = i;       if (d[b[i]] == 1e10) d[b[i]] = i;     }     vector<pair<long long, long long> > v;     for (long long l = 1; l <= n; l++) {       long long x = 0, y = 0;       long long px, py;       long long sx = 0, sy = 0;       long long last = 0;       while (1) {         if (c[x + l] > d[y + l]) {           px = a[d[y + l]];           py = b[d[y + l]];           sy++;           last = 2;         } else if (c[x + l] < d[y + l]) {           px = a[c[x + l]];           py = b[c[x + l]];           sx++;           last = 1;         } else {           if (c[x] == n || d[y] == n)             ;           else {             sx = 0;             sy = 0;           }           if (sx == sy) sx = 0, sy = 0;           if (sx > sy && last == 2 || sy > sx && last == 1) {             sx = 0;             sy = 0;           }           break;         }         x = px;         y = py;       }       if (max(sx, sy) > 0) v.push_back(make_pair(max(sx, sy), l));     }     sort((v).begin(), (v).end());     if (v.empty())       cout << 0;     else {       cout << v.size() <<   n ;       for (i = 0; i < v.size(); i++) {         cout << v[i].first <<     << v[i].second <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a, ta;   int b, tb;   int h, m;   bool read() {     if (!(cin >> a >> ta)) return false;     assert(cin >> b >> tb);     assert(scanf( %d:%d , &h, &m) == 2);     return true;   }   void solve() {     int x1 = h * 60 + m;     int y1 = x1 + ta;     int ans = 0;     for (int x2 = 5 * 60 + 0; x2 < 24 * 60; x2 += b) {       int y2 = x2 + tb;       int x = max(x1, x2), y = min(y1, y2);       if (x < y) ans++;     }     cout << ans << endl;   }   int main() {     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int a, b, c, d, e, f;     cin >> a >> b >> c >> d >> e;     while (e--) {       long long int A, B, C, D;       cin >> A >> B >> C >> D;       if (A == C) {         cout << max(B, D) - min(B, D) << endl;       } else {         if (B <= c && D <= c) {           cout << max(A, C) - min(A, C) + c - B + c - D << endl;         } else if (B >= d && D >= d) {           cout << max(A, C) - min(A, C) + B - d + D - d << endl;         } else {           cout << max(A, C) - min(A, C) + max(B, D) - min(B, D) << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<long long> v;     long long t, p;     char c;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       p = 0ll;       cin >> t >> c;       p = ((p << 8) | t);       cin >> t >> c;       p = ((p << 8) | t);       cin >> t >> c;       p = ((p << 8) | t);       cin >> t;       p = ((p << 8) | t);       v.push_back(p);     }     long long sub = 0ll;     for (long long i = 31; i >= 0; i--) {       sub = (sub | (1ll << i));       set<long long> s;       for (int j = 0; j < n; j++) {         s.insert(v[j] & sub);       }       if (s.size() == k)         break;       else if (s.size() > k) {         sub = -1;         break;       }     }     if (sub == -1)       cout <<  -1  << endl;     else {       vector<long long> last;       last.push_back(sub & ((1ll << 8) - 1ll));       sub = (sub >> 8);       last.push_back(sub & ((1ll << 8) - 1ll));       sub = (sub >> 8);       last.push_back(sub & ((1ll << 8) - 1ll));       sub = (sub >> 8);       last.push_back(sub & ((1ll << 8) - 1ll));       cout << last[3] <<  .  << last[2] <<  .  << last[1] <<  .  << last[0]            << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   bool on[N];   int n, m, x, par[N];   char c;   int chk(int x) {     int d = 2;     if (par[x] && x != 1) return par[x];     while (d * d <= x) {       if (x % d == 0) {         if (par[x / d]) return par[x / d];         if (par[d]) return par[d];       }       d++;     }     return 0;   }   int main() {     cin >> n >> m;     for (int i = 0; i < m; i++) {       scanf(  n%c%d , &c, &x);       if (c ==  + ) {         if (on[x]) {           printf( Already on n );           continue;         }         int t = chk(x);         if (t == 0) {           int d = 1;           while (d * d <= x) {             if (x % d == 0) par[d] = par[x / d] = x;             d++;           }           on[x] = true;           printf( Success n );         } else           printf( Conflict with %d n , t);       } else {         if (!on[x])           printf( Already off n );         else {           printf( Success n );           int d = 1;           while (d * d <= x) {             if (x % d == 0) par[d] = par[x / d] = 0;             d++;           }           on[x] = false;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[5050], t[5050], goal[5050];   int cnt[200], l, l2;   bool dfs(int p, bool v) {     if (p == l2) {       if (v)         return puts(goal), 1;       else         return 0;     }     if (v) {       for (int i =  a ; i <  z  + 1; i++)         if (cnt[i] > 0) {           cnt[i] -= 1;           goal[p] = i;           return dfs(p + 1, v);         }       return 1;     } else {       for (int i =  a ; i <  z  + 1; i++)         if (cnt[i] > 0 && i >= t[p]) {           cnt[i] -= 1;           goal[p] = i;           if (dfs(p + 1, v | (i > t[p]))) return 1;           cnt[i] += 1;         }     }     return 0;   }   int main() {     scanf( %s%s , s, t);     l = strlen(t);     l2 = strlen(s);     for (int i = 0; i < l2; i++) cnt[s[i]]++;     if (!dfs(0, 0)) puts( -1 );   }
#include <bits/stdc++.h>   using namespace std;   static const int INF = 500000000;   template <class T>   void debug(T a, T b) {     for (; a != b; ++a) cerr << *a <<    ;     cerr << endl;   }   int n;   double p[100005];   double get(int i) {     if (i == -1) return 0;     return p[i];   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %lf , &p[i]);     double res = 0, prev = 0;     for (int i = 0; i < n; ++i) {       prev = prev * p[i] + p[i] * get(i - 1) * 2;       prev += p[i] * (1 - get(i - 1));       res += prev;     }     printf( %.10f n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mx = 200100;   const int md = 1000000007;   bool compare(const pair<int, int>& a, const pair<int, int>& b) {     return a.first < b.first || (a.first == b.first && a.second > b.second);   }   int main() {     int n, m;     map<int, int> visit;     vector<int> ans, arr;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i += 1) {       int x;       scanf( %d , &x);       arr.push_back(x);     }     for (int i = 0; i < m; i += 1) {       int x;       scanf( %d , &x);       visit[x] = 1;     }     for (int i = 0; i < n; i += 1) {       if (visit[arr[i]]) ans.push_back(arr[i]);     }     for (int i = 0; i < ans.size(); i += 1) {       printf( %d  , ans[i]);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int t, n, i, k, j, lg, el, maxi, ok2;   int ok[5010][5010];   char v[5010], sol[5010];   int main() {     cin >> t;     for (; t--;) {       cin >> v + 1;       n = strlen(v + 1);       int st = 1, dr = n;       while (st <= dr && v[st] == v[dr]) st++, dr--;       if (st > dr) {         cout << v + 1 <<   n ;         continue;       }       for (i = 1; i <= n; i++)         for (j = 1; j <= n; j++) ok[i][j] = 0;       for (i = 1; i <= n; ++i) {         ok[i][i] = 1;         if (i < n && v[i] == v[i + 1]) ok[i][i + 1] = 1;       }       for (lg = 3; lg <= n; ++lg) {         for (i = 1; i + lg - 1 <= n; ++i) {           j = i + lg - 1;           if (ok[i + 1][j - 1] && v[i] == v[j]) ok[i][j] = 1;         }       }       maxi = 0;       for (i = 1; i <= n; i++) {         if (ok[1][i] && i > maxi) {           maxi = i;           for (j = 1; j <= i; j++) sol[j] = v[j];         }         if (ok[i][n] && (n - i + 1) > maxi) {           maxi = n - i + 1;           for (j = i; j <= n; j++) sol[j - i + 1] = v[j];         }       }       dr = n;       for (i = 1; i <= n; i++) {         st = 1, ok2 = 0;         for (j = n; j >= n - i + 1 && j > i; j--) {           if (v[st] != v[j]) {             ok2 = 1;             break;           }           st++;         }         if (j == n) continue;         if (st != i + 1) {           int nr = n - j;           if (2 * nr > maxi) {             maxi = 2 * nr, el = 0;             for (j = 1; j <= nr; j++) sol[++el] = v[j];             for (j = n - nr + 1; j <= n; j++) sol[++el] = v[j];           }           if (ok[nr + 1][i]) {             if (i + nr > maxi) {               maxi = i + nr, el = 0;               for (j = 1; j <= i; j++) sol[++el] = v[j];               for (j = n - nr + 1; j <= n; j++) sol[++el] = v[j];             }           }         } else {           for (j = i + 1; j <= n - i; j++) {             if (ok[j][n - i]) break;           }           int lg = n - i - j + 1;           if (2 * i + lg > maxi) {             maxi = 2 * i + lg, el = 0;             for (k = 1; k <= i; k++) sol[++el] = v[k];             for (k = j; k <= n; k++) sol[++el] = v[k];           }         }       }       for (i = 1; i <= maxi; i++) cout << sol[i];       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( avx2 )   using namespace std;   long long one = 1;   const long long INF = 1e18;   const long long MOD = 1e9 + 7;   const long long N = 2e5;   vector<vector<long long> > c, gr;   vector<long long> res;   bool flag = 1;   long long dfs1(long long v, long long p, long long j, long long k) {     long long ans = c[j][v];     if (gr[v].size() > 2) flag = 0;     for (long long u : gr[v]) {       if (u == p) continue;       ans += dfs1(u, v, k, 3 - j - k);     }     return ans;   }   void dfs2(long long v, long long p, long long j, long long k) {     res[v] = j + 1;     for (long long u : gr[v]) {       if (u == p) continue;       dfs2(u, v, k, 3 - j - k);     }   }   signed main() {     long long n;     cin >> n;     c.resize(3);     for (long long i = 0; i < 3; i++) {       c[i].resize(n);       for (long long j = 0; j < n; j++) cin >> c[i][j];     }     gr.resize(n);     for (long long i = 0; i < n - 1; i++) {       long long v, u;       cin >> v >> u;       v--;       u--;       gr[v].push_back(u);       gr[u].push_back(v);     }     long long st = -1;     for (long long i = 0; i < n; i++) {       if (gr[i].size() == 1) st = i;     }     long long ans = INF, ansj = -1, ansk = -1;     for (long long j = 0; j < 3; j++) {       for (long long k = 0; k < 3; k++) {         if (j == k) continue;         long long smth = dfs1(st, -1, j, k);         assert(smth >= 0);         if (smth < ans) {           ans = smth;           ansj = j;           ansk = k;         }       }     }     if (flag == 0) {       cout << -1 << endl;       return 0;     }     if (n > 20000) {     }     res.resize(n);     cout << ans << endl;     dfs2(st, -1, ansj, ansk);     for (long long i : res) cout << i <<    ;   }