malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct node {     int l;     int r;     int val;   };   node tree[800010];   vector<int> pre[200010];   int ary[200010];   int n, q;   void pushup(int cur) {     tree[cur].val = min(tree[2 * cur].val, tree[2 * cur + 1].val);   }   void build(int l, int r, int cur) {     int m;     tree[cur].l = l;     tree[cur].r = r;     tree[cur].val = 0;     if (l == r) {       tree[cur].val = ary[l];       return;     }     m = (l + r) / 2;     build(l, m, 2 * cur);     build(m + 1, r, 2 * cur + 1);     pushup(cur);   }   int query(int pl, int pr, int cur) {     int res;     if (pl <= tree[cur].l && tree[cur].r <= pr) return tree[cur].val;     res = 1000000;     if (pl <= tree[2 * cur].r) res = min(res, query(pl, pr, 2 * cur));     if (pr >= tree[2 * cur + 1].l) res = min(res, query(pl, pr, 2 * cur + 1));     return res;   }   int main() {     int i, j, flag, p, l, r, res;     scanf( %d%d , &n, &q);     flag = 0;     for (i = 1; i <= n; i++) {       scanf( %d , &ary[i]);       if (ary[i] != 0) flag = 1;     }     if (flag == 0) {       printf( YES n );       for (i = 1; i <= n; i++) {         printf( %d  , q);       }       printf(  n );       return 0;     }     flag = 0;     for (i = 1; i <= n; i++) {       if (ary[i] == q) {         flag = 1;         break;       }     }     if (flag == 0) {       p = 0;       for (i = 1; i <= n; i++) {         if (ary[i] != 0)           p = ary[i];         else {           if (flag == 0) {             ary[i] = q;             flag = 1;           } else             ary[i] = p;         }       }       p = 0;       for (i = n; i >= 1; i--) {         if (ary[i] != 0)           p = ary[i];         else           ary[i] = p;       }     } else {       p = 0;       for (i = 1; i <= n; i++) {         if (ary[i] != 0)           p = ary[i];         else           ary[i] = p;       }       p = 0;       for (i = n; i >= 1; i--) {         if (ary[i] != 0)           p = ary[i];         else           ary[i] = p;       }     }     flag = 0;     for (i = 1; i <= n; i++) {       if (ary[i] == q) {         flag = 1;         break;       }     }     if (flag == 0) {       printf( NO n );       return 0;     }     for (i = 1; i <= n; i++) {       pre[ary[i]].push_back(i);     }     build(1, n, 1);     flag = 1;     for (i = 1; i <= q; i++) {       if (pre[i].size() > 1) {         for (j = 1; j < pre[i].size(); j++) {           l = pre[i][j - 1] + 1, r = pre[i][j] - 1;           if (l <= r) {             res = query(l, r, 1);             if (res < i) {               flag = 0;               break;             }           }         }         if (flag == 0) break;       }     }     if (flag) {       printf( YES n );       for (i = 1; i <= n; i++) {         printf( %d  , ary[i]);       }       printf(  n );     } else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long d[10000005];   int snt[664600], dem;   bool p[10000005];   void sieve() {     int i, j;     snt[0] = 2, dem = 1;     p[0] = p[1] = true;     for (i = 4; i <= 1e7; i += 2) p[i] = true;     for (i = 3; i <= 3163; i += 2)       if (!p[i]) {         snt[dem++] = i;         for (j = i * i; j <= 1e7; j += i) p[j] = true;       }     for (; i <= 1e7; i += 2)       if (!p[i]) snt[dem++] = i;   }   void factor(int x) {     int i;     if (!p[x]) {       d[x]++;       return;     }     for (i = 0; i < dem && snt[i] * snt[i] <= x; i++)       if (x % snt[i] == 0) {         d[snt[i]]++;         while (x % snt[i] == 0) x /= snt[i];       }     if (x != 1) d[x]++;   }   void input() {     int i, n, l, r, x, nq;     sieve();     scanf( %d , &n);     for ((i) = 0; (i) < (n); (i)++) scanf( %d , &x), factor(x);     for ((i) = (3); (i) <= (10000000); (i)++) d[i] += d[i - 1];     scanf( %d , &nq);     while (nq--) {       scanf( %d %d , &l, &r);       l = ((l) < (10000000) ? (l) : (10000000));       r = ((r) < (10000000) ? (r) : (10000000));       printf( %I64d n , d[r] - d[l - 1]);     }   }   int main() {     input();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string a, b;     cin >> a >> b;     string aa =   , bb =   ;     int i = 0;     for (; i < a.size(); i++) {       if (a[i] !=  0 ) break;     }     for (; i < a.size(); i++) aa += a[i];     i = 0;     for (; i < b.size(); i++) {       if (b[i] !=  0 ) break;     }     for (; i < b.size(); i++) bb += b[i];     int mx = max((int)aa.size(), (int)bb.size());     bb = string(mx - bb.size(),  0 ) + bb;     aa = string(mx - aa.size(),  0 ) + aa;     for (int i = 0; i < aa.size(); i++) {       if (aa[i] == bb[i]) continue;       if (aa[i] > bb[i]) {         cout <<  > ;         return 0;       } else if (aa[i] < bb[i]) {         cout <<  < ;         return 0;       }     }     cout <<  = ;   }
#include <bits/stdc++.h>   using namespace std;   string name[1010];   int score[1010];   bool good[1010];   map<string, int> mp;   int main(void) {     int N, i;     cin >> N;     for ((i) = 0; (i) < (int)(N); (i)++) cin >> name[i] >> score[i];     for ((i) = 0; (i) < (int)(N); (i)++) mp[name[i]] += score[i];     int M = 0;     for (__typeof((mp).begin()) itr = (mp).begin(); itr != (mp).end(); itr++)       M = max(M, (itr->second));     for ((i) = 0; (i) < (int)(N); (i)++) good[i] = (mp[name[i]] == M);     mp.clear();     for ((i) = 0; (i) < (int)(N); (i)++) {       mp[name[i]] += score[i];       if (good[i] && mp[name[i]] >= M) break;     }     cout << name[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t, i, j, n, r, it, cc, best, u[22], msk[22], bc[1100100], ok[1100100];   bool c[22][22];   char a[100100], b[100100];   void dfs(int i) {     u[i] = it;     for (int j = 0; j < 20; j++)       if ((c[i][j] || c[j][i]) && u[j] != it) dfs(j);   }   int main() {     scanf( %d , &t);     for (it = 1; it <= t; it++) {       scanf( %d , &n);       for (i = 0; i < 20; i++)         for (j = 0; j < 20; j++) c[i][j] = false;       scanf( %s , a);       scanf( %s , b);       for (i = 0; i < n; i++)         if (a[i] != b[i]) c[a[i] -  a ][b[i] -  a ] = true;       for (cc = i = 0; i < 20; i++) {         if (u[i] != it) {           ++cc;           dfs(i);         }         for (msk[i] = j = 0; j < 20; j++)           if (c[i][j]) msk[i] |= (1 << j);       }       ok[0] = it;       best = 0;       for (i = 1; i < (1 << 20); i++) {         bc[i] = bc[i / 2] + (i & 1);         for (j = 0; j < 20; j++)           if (((i >> j) & 1) && ok[i ^ (1 << j)] == it && (msk[j] & i) == 0)             ok[i] = it;         if (ok[i] == it) best = max(best, bc[i]);       }       printf( %d n , 40 - best - cc);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int test;     cin >> test;     while (test--) {       cin >> n;       vector<int> a;       int mini = -1;       int ii;       for (ii = 2; ii * ii < n; ii++) {         if (n % ii != 0) continue;         if (mini < 0) mini = ii;         a.push_back(ii);         a.push_back(n / ii);       }       if (ii * ii == n) a.push_back(ii);       a.push_back(n);       bool pk = true;       for (int x : a) {         if (x % mini != 0) {           pk = false;           break;         }       }       if (pk) {         for (int x : a) cout << x <<    ;         cout <<   n ;         cout << 0 <<   n ;         continue;       }       if (a.size() == 3) {         for (int x : a) cout << x <<    ;         cout <<   n ;         cout << 1 <<   n ;         continue;       }       vector<int> primes;       int m = n;       int cnt = 2;       while (cnt * cnt <= m) {         if (m % cnt == 0) {           primes.push_back(cnt);           while (m % cnt == 0) m /= cnt;         }         cnt++;       }       if (m > 1) primes.push_back(m);       map<int, bool> ma;       for (int pi = 0; pi + 1 < primes.size(); pi++) {         ma[primes[pi]] = true;         ma[primes[pi] * primes[pi + 1]] = true;       }       ma[primes.back()] = true;       ma[n] = true;       vector<bool> was(a.size(), false);       for (int i = 0; i < a.size(); i++) {         if (ma[a[i]]) was[i] = true;       }       vector<int> ans;       for (int pi = 0; pi + 1 < primes.size(); pi++) {         ans.push_back(primes[pi]);         for (int i = 0; i < a.size(); i++) {           if (!was[i] && a[i] % primes[pi] == 0 &&               a[i] != primes[pi + 1] * primes[pi]) {             was[i] = true;             ans.push_back(a[i]);           }         }         ans.push_back(primes[pi + 1] * primes[pi]);       }       ans.push_back(primes.back());       for (int i = 0; i < a.size(); i++) {         if (!was[i] && a[i] % primes.back() == 0) {           was[i] = true;           ans.push_back(a[i]);         }       }       ans.push_back(n);       for (int x : ans) cout << x <<    ;       cout <<   n ;       cout << 0 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int longestSubstring(string s) {     int i, j;     int l = s.length();     int maxi = 0;     map<string, int> mpp;     for (i = 0; i < l; i++) {       string temp =   ;       for (j = i; j < l; j++) {         temp += s[j];         mpp[temp]++;         maxi = max(maxi, mpp[temp]);       }     }     auto it = mpp.begin();     int len = 0;     string ans =   ;     while (it != mpp.end()) {       if (it->second >= 2) {         string temp = it->first;         if (temp.length() > len) {           ans = temp;           len = temp.length();         } else if (temp.length() == len) {           if (temp < ans) ans = temp;         }       }       it++;     }     return len;   }   int main() {     string s;     cin >> s;     int ans = longestSubstring(s);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n;   struct node {     int pos, len;     friend bool operator<(node a, node b) { return a.len > b.len; }   } f[100005];   vector<int> po;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       int x = i * 2 - 1;       f[i].pos = x;       scanf( %d , &f[i].len);     }     sort(f + 1, f + n + 1);     int jl = 0;     for (int i = 1; i <= n; i++) {       po.push_back(f[i].pos);       if (i == 1)         jl = f[i].pos;       else {         printf( %d %d n , jl, f[i].pos);         jl = f[i].pos;       }     }     for (int i = 1; i <= n; i++) {       int now = f[i].pos + 1;       int len = f[i].len;       if (len - 1 + i <= po.size()) {         printf( %d %d n , now, po[i + len - 2]);         if (len - 1 + i == po.size()) po.push_back(now);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T1, typename T2>   bool mini(T1 &a, T2 b) {     if (a > b) {       a = b;       return true;     }     return false;   }   template <typename T1, typename T2>   bool maxi(T1 &a, T2 b) {     if (a < b) {       a = b;       return true;     }     return false;   }   const int N = 2e5 + 5;   const int oo = 1e9;   struct segtree {     int n;     vector<int> st;     vector<int> lz;     segtree(int _n) {       n = _n;       st.assign(4 * n + 5, 0);       lz.assign(4 * n + 5, 0);     }     void push(int id) {       for (int i = (id << 1); i <= (id << 1 | 1); i++) {         st[i] += lz[id];         lz[i] += lz[id];       }       lz[id] = 0;     }     void update(int id, int l, int r, int u, int v, int val) {       if (l > v || r < u) return;       if (l >= u && r <= v) return (void)(st[id] += val, lz[id] += val);       int mid = (l + r) >> 1;       push(id);       update(id << 1, l, mid, u, v, val);       update(id << 1 | 1, mid + 1, r, u, v, val);       st[id] = max(st[id << 1], st[id << 1 | 1]);     }     void update(int l, int r, int val) { update(1, 1, n, l, r, val); }     int getmax(int id, int l, int r, int u, int v) {       if (l > v || r < u) return 0;       if (l >= u && r <= v) return st[id];       int mid = (l + r) >> 1;       int lnode = getmax(id << 1, l, mid, u, v);       int rnode = getmax(id << 1 | 1, mid + 1, r, u, v);       return max(lnode, rnode);     }     int getmax(int l, int r) { return getmax(1, 1, n, l, r); }   };   segtree st[2] = {segtree(N << 1), segtree(N << 1)};   vector<int> r[2][N << 1];   pair<int, int> seg[N];   int dp[2][N << 1];   int c[N];   int n;   bool upd[2][N << 1];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     vector<int> val;     for (int i = 1; i <= n; i++) {       cin >> seg[i].first >> seg[i].second >> c[i];       c[i]--;       val.push_back(seg[i].first);       val.push_back(seg[i].second);     }     sort(val.begin(), val.end());     val.resize(unique(val.begin(), val.end()) - val.begin());     for (int i = 1; i <= n; i++) {       seg[i].first =           lower_bound(val.begin(), val.end(), seg[i].first) - val.begin() + 1;       seg[i].second =           lower_bound(val.begin(), val.end(), seg[i].second) - val.begin() + 1;       r[c[i]][seg[i].first].push_back(seg[i].second);     }     for (int i = (n << 1); i >= 0; i--) {       for (int j = 0; j <= 1; j++) dp[j][i] = st[j ^ 1].getmax(i, n << 1);       for (int j = 0; j <= 1; j++)         for (int x : r[j][i]) {           if (!upd[j][x]) {             st[j].update(x, x, dp[j][x]);             upd[j][x] = true;           }           st[j].update(x, n << 1, 1);         }     }     cout << max(dp[0][0], dp[1][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int a[100001], b[100001], c[100001];   vector<int> rev[100001];   vector<int> e[100001];   int get(int far) {     int cur = k;     for (int i = 1; i <= n; i++) {       int x = e[i].back();       rev[x].push_back(i);     }     priority_queue<int, vector<int>, greater<int> > q;     for (int i = 1; i <= n; i++) {       if (cur >= a[i])         cur += b[i];       else {         while (!q.empty() && cur < a[i]) q.pop(), cur++;         if (cur < a[i]) return -1;         cur += b[i];       }       for (int j = 0; j < rev[i].size(); j++) q.push(c[rev[i][j]]), cur--;     }     int ans = 0;     while (cur < 0) q.pop(), cur++;     while (!q.empty()) ans += q.top(), q.pop();     return ans;   }   signed main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; i++) scanf( %d%d%d , &a[i], &b[i], &c[i]);     for (int i = 1; i <= m; i++) {       int u, v;       scanf( %d%d , &u, &v);       if (u > v) swap(u, v);       e[u].push_back(v);     }     for (int i = 1; i <= n; i++) {       e[i].push_back(i);       sort(e[i].begin(), e[i].end());     }     int ans = get(n);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   bool o;   int n, m, k, a, t;   int dp[2][775], suf[776];   struct poi {     int r, c;   } p[100010];   bool operator<(poi x, poi y) { return x.c < y.c; }   int main() {     scanf( %d%d , &n, &k), m = sqrt(6 * k);     for (int i = 1; i <= k; ++i) {       scanf( %d%d , &p[i].r, &p[i].c);       if ((p[i].r = n - p[i].r + 1) > m) a += 3, --i, --k;     }     std::sort(p + 1, p + k + 1);     for (int i = 1; i <= m; ++i) dp[o][i] = 1e9;     for (int i = 1, j = 1; i <= n + 1; ++i, o ^= 1) {       for (int j = 1; j <= m; ++j) suf[j] = 0;       while (p[j].c == i) suf[p[j].r] += 3, ++j;       for (int j = m - 1; j; --j) suf[j] += suf[j + 1];       dp[o ^ 1][0] = std::min(t = dp[o][0], dp[o][1]) + suf[1];       for (int j = 1; j < m; ++j)         dp[o ^ 1][j] = std::min((t = std::min(t, dp[o][j])) + j * (j + 1) / 2 + 2,                                 dp[o][j + 1]) +                        suf[j + 1];       dp[o ^ 1][m] = t + m * (m + 1) / 2 + 2;     }     printf( %d n , dp[o][0] + a);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7, N = 2e5;   int mul(int a, int b) { return (a * 1LL * b) % mod; }   int mul2(int a, int b) { return (a * 1LL * b) % (mod - 1); }   int Pow(int v, long long p) {     int ans = 1;     while (p) {       if (p & 1) {         ans = mul(ans, v);       }       p /= 2;       v = mul(v, v);     }     return ans;   }   long long F(int n) { return n * 1LL * (n + 1) / 2; }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     map<int, int> p;     while (n--) {       int x;       cin >> x;       ++p[x];     }     int mult = 1, sum = 1, last = 1;     for (auto e : p) {       last = Pow(last, e.second + 1);       mult = Pow(Pow(e.first, F(e.second)), sum);       sum = mul2(sum, e.second + 1);       last = mul(mult, last);     }     cout << last;     return 0;   }
#include <bits/stdc++.h>   int main() {     int life[200001], N, a, i;     for (i = 0; i < 200001; i++) life[i] = 0;     scanf( %d , &N);     for (i = 0; i < N; i++) {       scanf( %d , &a);       if (a != 0) life[a + 100000] = 1;     }     int diff = 0;     for (i = 0; i < 200001; i++) diff += life[i];     printf( %d n , diff);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     string s;     cin >> s;     while (m--) {       int a1, a2;       char a3, a4;       scanf( %d %d %c %c , &a1, &a2, &a3, &a4);       a1--;       a2--;       while (a1 <= a2) {         if (s[a1] == a3) s[a1] = a4;         a1++;       }     }     cout << s <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200100;   int arr[MAXN], tmp[MAXN];   vector<int> ve[MAXN];   map<pair<int, int>, vector<int> > mapa;   int ind[MAXN];   vector<int> out[MAXN];   int sol = 0;   vector<int> t1, t2;   vector<int> comp;   map<int, int> aaa;   void tour(int x, int i) {     while (ind[x] < ve[x].size()) {       int y = ve[x][ind[x]++];       int ind = mapa[{x, y}].back();       mapa[{x, y}].pop_back();       tour(y, ind);     }     out[sol].push_back(i);     return;   }   int main() {     ios_base::sync_with_stdio(false);     int n, s;     cin >> n >> s;     for (int i = (0); i < (n); i++) {       cin >> arr[i];       comp.push_back(arr[i]);     }     sort(comp.begin(), comp.end());     comp.resize(unique(comp.begin(), comp.end()) - comp.begin());     for (int i = (0); i < (comp.size()); i++) {       aaa[comp[i]] = i;     }     for (int i = (0); i < (n); i++) {       arr[i] = aaa[arr[i]];       tmp[i] = arr[i];     }     sort(tmp, tmp + n);     for (int i = (0); i < (n); i++) {       if (arr[i] != tmp[i]) {         mapa[{tmp[i], arr[i]}].push_back(i);         ve[tmp[i]].push_back(arr[i]);       }     }     int uk = 0;     for (int i = (0); i < (n); i++) {       tour(tmp[i], i);       out[sol].pop_back();       if (out[sol].size()) {         reverse(out[sol].begin(), out[sol].end());         uk += out[sol].size();         sol++;       }     }     if (uk > s) {       cout <<  -1 n ;       return 0;     }     int m = min(sol, s - uk);     for (int i = (0); i < (m); i++) {       sol--;       for (int x : out[sol]) t1.push_back(x);       t2.push_back(out[sol][0]);     }     if (m == 1) sol++;     if (m <= 1) {       cout << sol << endl;       for (int i = (0); i < (sol); i++) {         cout << out[i].size() <<   n ;         for (int x : out[i]) cout << x + 1 <<    ;         cout <<   n ;       }     } else {       reverse(t2.begin(), t2.end());       cout << sol + 2 << endl;       cout << t1.size() << endl;       for (int x : t1) cout << x + 1 <<    ;       cout << endl;       cout << t2.size() << endl;       for (int x : t2) cout << x + 1 <<    ;       cout << endl;       for (int i = (0); i < (sol); i++) {         cout << out[i].size() <<   n ;         for (int x : out[i]) cout << x + 1 <<    ;         cout <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     set<long long> s;     vector<long long> ar(n + 1, 0);     for (long long i = 0; i < n; i++) {       s.insert(i + 1);     }     for (long long i = 1; i <= m; i++) {       long long li, ri, xi;       vector<long long> temp;       cin >> li >> ri >> xi;       auto itl = s.lower_bound(li);       auto itr = s.upper_bound(ri);       for (auto it = itl; it != itr && (*it) <= ri; it++) temp.push_back(*it);       for (auto i : temp) {         if (i != xi) {           s.erase(i);           ar[i] = xi;         }       }     }     for (long long i = 1; i <= n; i++) cout << ar[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000002;   const long long INFLL = 100000000000000000ll;   const long long MOD = 1000000007;   int Cycle[100005], N, Real[100005], Pos[100005], V[100005], P[100005][20],       D[100005], Edg, K;   long long M[100005];   vector<int> E[100005], E2[100005];   void dfs(int n, int p, int from) {     if (Real[n] != n) return;     if (Pos[n] > 0) {       Cycle[n] = 1;       for (int i = (Pos[n] + 1); i <= (p - 1); i++) Real[V[i]] = n;       return;     }     Pos[n] = p;     V[p] = n;     for (int v : E[n])       if (v != from) dfs(v, p + 1, n);   }   void dfs2(int n, int p, int d, long long mult) {     D[n] = d;     M[n] = mult;     P[n][0] = p;     for (int v : E2[n])       if (v != p) dfs2(v, n, d + 1, mult + Cycle[v]);   }   int lca(int a, int b) {     if (D[a] > D[b]) return lca(b, a);     int diff = D[b] - D[a];     for (int i = (0); i <= (17); i++)       if (diff & (1 << i)) b = P[b][i];     if (a == b) return a;     for (int i = (17); i >= (0); i--)       if (P[a][i] != P[b][i]) a = P[a][i], b = P[b][i];     return P[a][0];   }   long long exp(long long n, int e) {     if (e == 0) return 1;     if (e % 2) return (exp(n, e - 1) * n) % MOD;     long long q = exp(n, e / 2);     return (q * q) % MOD;   }   int main() {     cin >> N >> Edg;     for (int i = (1); i <= (Edg); i++) {       int a, b;       scanf( %d %d , &a, &b);       E[a].push_back(b), E[b].push_back(a);     }     for (int i = (1); i <= (N); i++) Real[i] = i;     dfs(1, 1, 0);     for (int i = (1); i <= (N); i++)       for (int v : E[i]) {         int v1 = Real[i];         int v2 = Real[v];         if (v1 != v2) E2[v1].push_back(v2);       }     dfs2(Real[1], 0, 1, Cycle[Real[1]]);     for (int j = (1); j <= (17); j++)       for (int i = (1); i <= (N); i++) P[i][j] = P[P[i][j - 1]][j - 1];     cin >> K;     for (int kk = (1); kk <= (K); kk++) {       int a, b;       scanf( %d %d , &a, &b);       a = Real[a], b = Real[b];       if (a == b) {         printf( 2 n );         continue;       }       int l = lca(a, b);       int par = P[l][0];       long long val = M[a] + M[b] - M[par] - M[par] - Cycle[l];       printf( %I64d n , exp(2, val));     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 20;   const int X = 1 << MAXN;   int N, M, K;   long long a[MAXN];   long long p[MAXN][MAXN];   long long dp[MAXN][X + 5];   long long max(long long a, long long b) { return a > b ? a : b; }   int main() {     scanf( %d %d %d , &N, &M, &K);     for (int i = 1; i <= N; i++) scanf( %I64d , &a[i]);     int u, v;     long long w;     for (int i = 0; i < K; i++) {       scanf( %d %d %I64d , &u, &v, &w);       p[u][v] = w;     }     for (int i = 1; i <= N; i++) dp[i][1 << i - 1] = a[i];     long long ans = 0;     int cnt;     for (int i = 0; i < (1 << N); i++) {       cnt = 0;       for (int j = 1; j <= N; j++) {         if (i & (1 << j - 1)) {           cnt++;           for (int k = 1; k <= N; k++)             if (!(i & (1 << k - 1)))               dp[k][i | (1 << k - 1)] =                   max(dp[k][i | (1 << k - 1)], dp[j][i] + a[k] + p[j][k]);         }       }       if (cnt == M) {         for (int j = 1; j <= N; j++)           if (i & (1 << j - 1)) ans = max(ans, dp[j][i]);       }     }     printf( %I64d , ans);   }