malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m, t1, t2;   vector<int> q1, q2;   vector<vector<int> > Visted;   int des(int point1, int point2, int point3, int point4) {     return abs(point1 - point3) + abs(point2 - point4);   }   int main() {     cin >> n >> m >> t1;     Visted.resize(n + 10, vector<int>(m + 10));     q1.resize(t1);     for (int i = 0; i < t1; i++) cin >> q1[i];     cin >> t2;     q2.resize(t2);     for (int i = 0; i < t2; i++) cin >> q2[i];     sort(q1.begin(), q1.end());     sort(q2.begin(), q2.end());     for (int i = 0; i < t1; i++) {       bool take = false;       int desEnd = -1e9, X, Y;       for (int j = 1; j <= n; j++) {         for (int z = 1; z <= m; z++) {           if (!Visted[j][z] && des(0, 0, j, z) <= q1[i] &&               des(0, m + 1, j, z) > desEnd) {             desEnd = des(0, m + 1, j, z);             take = true;             X = j, Y = z;           }         }       }       if (take) {         Visted[X][Y] = 1;       } else {         cout <<  NO ;         return 0;       }     }     for (int i = 0; i < t2; i++) {       bool take = false;       int desEnd = 1e9, X, Y;       for (int j = 1; j <= n; j++) {         for (int z = 1; z <= m; z++) {           if (!Visted[j][z] && des(0, m + 1, j, z) <= q2[i] &&               des(0, m + 1, j, z) < desEnd) {             take = true;             X = j, Y = z;           }         }       }       if (take) {         Visted[X][Y] = 1;       } else {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class TH>   void _dbg(const char *sdbg, TH h) {     cerr << sdbg <<  =  << h << endl;   }   template <class TH, class... TA>   void _dbg(const char *sdbg, TH h, TA... a) {     while (*sdbg !=  , ) cerr << *sdbg++;     cerr <<  =  << h <<  , ;     _dbg(sdbg + 1, a...);   }   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [ ;     for (auto vv : V) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class T>   using min_heap = priority_queue<T, vector<T>, greater<T>>;   template <class T>   using max_heap = priority_queue<T>;   const int mod = 1e9 + 7;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   struct PairHash {     template <typename T1, typename T2>     std::size_t operator()(const pair<T1, T2> &p) const {       return hash<T1>()(p.first) ^ hash<T2>()(p.second);     }   };   void solve(int ncase) {     int a, b, c, d;     cin >> a >> b >> c >> d;     int minx = min({a, b, c});     a -= minx;     b -= minx;     c -= minx;     cout << (((a % 2 + b % 2 + c % 2 + (d + 3 * 1LL * minx) % 2) <= 1) ||                      (minx >= 1 && ((a + 1) % 2 + (b + 1) % 2 + (c + 1) % 2 +                                     (d + 3 * 1LL * minx - 3) % 2) <= 1)                  ?  Yes                   :  No )          << endl;   }   void solve_all_cases() {     int T = 1;     cin >> T;     int ncase = 0;     while (T--) {       solve(++ncase);     }   }   int main() {     cout << std::fixed;     cout << setprecision(6);     solve_all_cases();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n - 1; i++) cout << (a[i] + a[i + 1]) <<    ;     cout << a[n - 1];   }
#include <bits/stdc++.h>   using namespace std;   int j, i, a, b, c, k, d, e, f[1005], n, mi, ma;   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> f[i];       ma = max(f[i], ma);     }     for (i = 0; i < n - 1; i++)       for (j = i + 1; j < n; j++) {         c = 0;         for (k = i; k <= j; k++) c = f[k] ^ c;         ma = max(ma, c);       }     cout << ma;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target(         avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   long long MOD = 1e9 + 7;   long long k;   vector<long long> v, w, num;   vector<pair<long long, pair<long long, long long> > > zp;   vector<vector<long long> > dp;   long long st(long long t, long long id, long long mod) {     long long res = 1, a = t, n = id;     while (n) {       if (n & 1) res = (res * a) % mod;       a = (a * a) % mod;       n >>= 1;     }     return res % mod;   }   void add(long long id) {     vector<long long> mem(k + 1);     dp.push_back(mem);     long long lst = dp.size() - 1;     for (int i = 0; i < k + 1; i++) {       dp[lst][i] = dp[lst - 1][i];       if (i >= w[id])         dp[lst][i] = max(dp[lst - 1][i], dp[lst - 1][i - w[id]] + v[id]);     }   }   void del() { dp.pop_back(); }   long long ans() {     long long lst = dp.size() - 1;     long long anss = 0;     for (int i = 1; i < k + 1; i++) {       anss = ((10000019 * (long long)anss) + (long long)dp[lst][k - i + 1]) % MOD;       if (anss > MOD) anss -= MOD;     }     return anss;   }   void get(long long l, long long r) {     if (r == l + 1) {       if (zp[l].first == 3) {         zp[l].second.first = ans();       }       return;     }     long long mid = (l + r) / 2;     long long kol = 0;     for (int i = mid; i < r; i++) {       if (zp[i].first == 2) {         if (num[zp[i].second.second] < l) {           add(zp[i].second.second);           kol++;         }       }     }     get(l, mid);     while (kol--) del();     kol = 0;     for (int i = l; i < mid; i++) {       if (zp[i].first == 1) {         if (zp[i].second.second >= r) {           add(zp[i].second.first);           kol++;         }       }     }     get(mid, r);     while (kol--) del();   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),         cout << fixed << setprecision(20);     long long n;     cin >> n >> k;     v.resize(n), w.resize(n), num.resize(n);     vector<long long> mem(k + 1);     dp.push_back(mem);     for (int i = 0; i < n; i++) {       cin >> v[i] >> w[i];       zp.push_back({1, {i, MOD}});       num[i] = i;     }     long long q;     cin >> q;     while (q--) {       long long sz = zp.size();       zp.push_back({0, {num.size(), MOD}});       cin >> zp[zp.size() - 1].first;       if (zp.back().first == 1) {         long long vv, ww;         cin >> vv >> ww;         v.push_back(vv);         w.push_back(ww);         num.push_back(sz);       }       if (zp.back().first == 2) {         long long x;         cin >> x;         x--;         zp[num[x]].second.second = sz;         zp[sz].second.second = x;       }     }     get(0, zp.size());     for (auto i : zp) {       if (i.first == 3) {         cout << i.second.first << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long w = 0;     char c = getchar();     while (c <  0  || c >  9 ) c = getchar();     while (c >=  0  && c <=  9 ) w = w * 10 + c - 48, c = getchar();     return w;   }   long long n, s[100005], e[100005];   bool f[100005][2];   bool check(long long x, long long y, long long op) {     if ((y & 1) && (!op)) return (y - x) & 1;     long long h = y >> 1;     if (x > h) return op ? 1 : (y - x) & 1;     return check(x, h, op ^ 1);   }   signed main() {     n = read();     for (long long i = 1; i <= n; i++)       s[i] = read(), e[i] = read(), f[i][0] = check(s[i], e[i], 0),       f[i][1] = check(s[i], e[i], 1);     bool need = f[n][0];     for (long long i = n - 1; i > 0; i--) need = f[i][need];     printf(need ?  1   :  0  );     need = f[n][1];     for (long long i = n - 1; i > 0; i--) need = f[i][need];     printf(need ?  1  :  0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 16, Inf = 1e9, lastS = (1 << N) - 1;   static int n, sqrn, R, B, ans, lasts;   struct TCard {     bool c;     int r, b;   } card[N];   static int f[lastS][N * N + 1][2], cardr[lastS], cardb[lastS];   inline int GetF(int s, int rem, bool c) {     rem = min(rem, sqrn);     if (s == lasts) return 0;     auto &fs = f[s][rem][c];     if (fs != -1) return fs;     fs = Inf;     for (int i = 0; i < n; ++i) {       if (s & 1 << i) continue;       int R = max(0, card[i].r - cardr[s]), B = max(0, card[i].b - cardb[s]),           turn, _r, _b;       if (c) {         turn = max(R - rem, B);         _r = rem + turn - R;         _b = turn - B;       } else {         turn = max(B - rem, R);         _b = rem + turn - B;         _r = turn - R;       }       if (_r)         fs = min(fs, turn + GetF(s ^ 1 << i, _r, 1));       else         fs = min(fs, turn + GetF(s ^ 1 << i, _b, 0));     }     return fs;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n;     sqrn = n * n;     lasts = (1 << n) - 1;     for_each(card, card + n, [](TCard &C) {       char tmp;       cin >> tmp >> C.r >> C.b;       C.c = tmp ==  R ;       if (C.r > n) R += C.r - n, C.r = n;       if (C.b > n) B += C.b - n, C.b = n;     });     for (int s = 1; s <= lasts; ++s) {       int i = __builtin_ctz(s);       cardr[s] = cardr[s ^ 1 << i] + card[i].c;       cardb[s] = cardb[s ^ 1 << i] + !card[i].c;     }     memset(f, -1, sizeof f);     if (R > B)       ans = R + GetF(0, R - B, 0);     else       ans = B + GetF(0, B - R, 1);     cout << ans + n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ifstream file( input.txt );   using namespace std;   void maker(int x);   int main() {     int y;     cin >> y;     maker(y + 1);   }   void maker(int x) {     int a, b, c, d;     a = (x / 1000) % 10;     b = (x / 100) % 10;     c = (x / 10) % 10;     d = (x / 1) % 10;     while (a == b || a == c || a == d || b == c || b == d || c == d) {       x++;       a = (x / 1000) % 10;       b = (x / 100) % 10;       c = (x / 10) % 10;       d = (x / 1) % 10;     }     cout << (a * 1000 + b * 100 + c * 10 + d);   }
#include <bits/stdc++.h>   using namespace std;   template <typename... Args>   void logger(string vars, Args&&... values) {}   template <typename T>   inline void maxa(T& a, T b) {     a = max(a, b);   }   template <typename T>   inline void mina(T& a, T b) {     a = min(a, b);   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const int mxN = 2e5 + 5;   const int mod = 1e9 + 7;   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> a(n);     vector<char> ans(n);     for (int& i : a) cin >> i;     string s;     cin >> s;     sort(a.begin(), a.end());     int cnt = 0;     for (int i = 1; i < n; i++) cnt += (s[i] != s[i - 1]);     int l = n - cnt - 1;     int r = n - cnt - 1;     cout << a[l] <<     << s[0] <<   n ;     ans[l] = s[0];     for (int i = 1; i < (int)(s.size()); i++) {       if (s[i] != s[i - 1]) {         ans[++r] = ans[r] ==  L  ?  R  :  L ;         cout << a[r] <<     << ans[r] <<   n ;       } else {         ans[--l] = ans[l] ==  L  ?  R  :  L ;         cout << a[l] <<     << ans[l] <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000 + 100;   map<pair<long long, long long>, int> rat;   int n;   pair<long long, long long> px[maxn], py[maxn];   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   int main() {     cin >> n;     for (int i = 1, a, b, c; i <= n; i++) {       cin >> a >> b >> c;       px[i] = make_pair(c * b, a * a + b * b);       py[i] = make_pair(a * c, a * a + b * b);     }     long long ans = 0;     for (int i = 1; i <= n; i++) {       rat.clear();       long long two0 = 0;       for (int j = i + 1; j <= n; j++) {         long long a = px[j].first * px[i].second - px[j].second * px[i].first;         long long b = py[j].first * py[i].second - py[j].second * py[i].first;         long long g = gcd(abs(a), abs(b));         if (g != 0) a /= g, b /= g;         if (a == 0 && b == 0) {           two0++;           ans += j - i - 1;         } else {           if (a == 0) b = 1;           if (b == 0) a = 1;           if (a < 0 && b < 0) a *= -1, b *= -1;           if (a > 0 && b < 0) a *= -1, b *= -1;           ans += two0;           if (rat.count(make_pair(a, b))) {             ans += rat[make_pair(a, b)];             rat[make_pair(a, b)]++;           } else             rat[make_pair(a, b)] = 1;         }       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 25;   int dp[MAXN][MAXN][MAXN];   int n, t;   int main() {     scanf( %d%d , &n, &t);     t = 2 * t;     dp[1][0][1] = dp[1][0][2] = dp[1][0][3] = 1;     for (int i = 1; i < n; ++i)       for (int j = 0; j <= t; ++j)         for (int k = 1; k <= 4; ++k)           for (int l = 1; l <= 4; ++l) {             if ((i == 1 && l > k) || (i != 1 && l != k)) {               int nj = j;               if (j % 2 && l < k)                 ++nj;               else if (j % 2 == 0 && l > k)                 ++nj;               dp[i + 1][nj][l] += dp[i][j][k];             }           }     int ans = 0;     for (int i = 1; i <= 4; ++i) ans += dp[n][t][i];     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     multiset<long long int> s;     map<string, int> mp;     while (t--) {       char ch;       long long int x;       cin >> ch >> x;       string str(18,  0 );       string temp = to_string(x);       int j = 17;       for (int i = ((int)(temp).size()) - 1; i >= 0; i--) {         if ((temp[i] -  0 ) % 2 != 0) {           str[j] =  1 ;         }         j--;       }       if (ch ==  + ) {         mp[str]++;       } else if (ch ==  - ) {         mp[str]--;       } else {         cout << mp[str] <<   n ;       }     }   }
#include <bits/stdc++.h>   #pragma warning(disable : 4996)   #pragma comment(linker,  /STACK:666000000 )   using namespace std;   const int INF = (1 << 30) - 1;   const long double EPS = 1e-9;   const long double PI = fabs(atan2(0.0, -1.0));   int n;   void load() { cin >> n; }   const int SZ = 1010;   int sv[SZ];   int rec(const int v) {     if (v < SZ && -1 != sv[v]) return sv[v];     bool can[10];     int p9;     memset(can, false, sizeof(can));     {       int p = 0;       int tmp = v;       while (tmp != 0) {         can[tmp % 10] = true;         if (9 == tmp % 10) p9 = p;         tmp /= 10;         p *= 10;       }     }     if (v >= SZ) {       if (can[9] && p9 > 10) {         int cnt = 9 * (p9 / 10) - 8;         return cnt + rec(v - cnt * 9);       }       for (int i = 9; i >= 1; i--)         if (can[i]) return 1 + rec(v - i);     }     int res = INT_MAX;     for (int i = 1; i <= 9; i++)       if (can[i]) res = min(res, 1 + rec(v - i));     if (v < SZ) sv[v] = res;     return res;   }   void solve() {     memset(sv, -1, sizeof(sv));     sv[0] = 0;     int res = rec(n);     cout << res;   }   int main() {     load();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5;   map<int, int> dic;   int n, a[N + 10], ma[N + 10], ma2[N + 10];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     ma[1] = a[1];     ma2[1] = -1;     for (int i = 2; i <= n; i++) {       if (a[i] > ma[i - 1]) {         ma2[i] = ma[i - 1];         ma[i] = a[i];       } else {         ma[i] = ma[i - 1];         if (ma2[i - 1] < a[i]) {           ma2[i] = a[i];         } else           ma2[i] = ma2[i - 1];       }       if (a[i] != ma[i] && a[i] == ma2[i]) {         dic[ma[i]]++;       }     }     int tot = -1e6, idx = -1;     for (int i = 1; i <= n; i++) {       int temp = dic[a[i]];       if (a[i] == ma[i]) temp--;       if (temp > tot) {         tot = temp;         idx = a[i];       } else if (temp == tot) {         idx = min(idx, a[i]);       }     }     cout << idx << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[1000005] = {0};   long long b[1000005] = {0};   long long c[1000005] = {0};   long long d[1000005] = {0};   long long s;   long long i, j = 0, l;   long long count1 = 0;   long long count2 = 0;   long long count3 = 0;   long long count4 = 0;   long long ans = 0;   bool cmp(long long aa, long long bb) { return aa > bb; }   int main() {     long long n;     scanf( %lld n , &n);     for (i = 0; i < n; i++) {       cin >> s >> j;       if (s == 11) {         a[count1++] = j;         ans += j;       } else if (s == 10) {         b[count2++] = j;       } else if (s == 1) {         c[count3++] = j;       } else {         d[count4++] = j;       }     }     sort(b, b + count2, cmp);     sort(c, c + count3, cmp);     for (i = 0; i < min(count2, count3); i++) ans += (b[i] + c[i]);     for (i = 0; i < abs(count2 - count3); i++) {       if (count3 > count2)         d[count4 + i] = c[min(count2, count3) + i];       else if (count3 < count2)         d[count4 + i] = b[min(count2, count3) + i];     }     count4 += abs(count2 - count3);     sort(d, d + count4, cmp);     for (i = 0; i < count1 && i < count4; i++) ans += d[i];     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[35], b[35], diff[35];   int main() {     std::ios::sync_with_stdio(false);     int t;     t = 1;     while (t--) {       long long x, x1, val, val1, i, j, res = 0;       cout <<  ? 0 0  << endl;       cin >> x;       x1 = x;       if (x == 0) {         for (i = 0; i < 30; i++) {           val = (1 << i);           cout <<  ?   << val <<     << 0 << endl;           cin >> x;           if (x == -1) {             res += (1 << i);           }         }         cout <<  !   << res <<     << res << endl;       } else {         {           x1 = x;           i = 29;           val = 0;           val1 = 0;           for (i = 29; i >= 0; i--) {             val += (1 << i);             val1 += (1 << i);             cout <<  ?   << val <<     << val1 << endl;             cin >> x;             if (x != x1) {               diff[i] = 1;               val -= (1 << i);               if (x == -1) {                 a[i] = 1;                 b[i] = 0;               } else {                 a[i] = 0;                 b[i] = 1;               }               cout <<  ?   << val <<     << val1 << endl;               cin >> x;               x1 = x;             } else {               diff[i] = 0;             }           }           for (i = 29; i >= 0; i--) {             val = 0;             val1 = 0;             if (diff[i]) {               continue;             }             for (j = 0; j < 30; j++) {               if (j == i) {                 continue;               }               if (diff[j]) {                 val += (1 << j);               }             }             {               val += (1 << i);               cout <<  ?   << val <<     << val1 << endl;               cin >> x;               if (x == -1) {                 a[i] = 1;                 b[i] = 1;               } else {                 a[i] = 0;                 b[i] = 0;               }             }           }           val = 0;           val1 = 0;           for (i = 0; i < 30; i++) {             if (a[i]) {               val += (1 << i);             }             if (b[i]) {               val1 += (1 << i);             }           }           cout <<  !   << val <<     << val1 << endl;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1e9 + 7;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, k;     cin >> n >> k;     long long int ans = 1;     while (k % 2 == 0) {       k = k / 2;       ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e4 + 10, mod = 1e9 + 7, M = 510;   const double PI = 3.1415926535;   long long res[40], p[40], ei[40], sum[N], cnt;   double pre[N];   int path[100];   void dfs(int u, int s, long long va) {     if (u == -1) {       sum[s] = ((long long)sum[s] + va) % mod;       return;     }     for (int i = 0; i <= cnt; i++) {       path[i]++;       if (res[i] - path[i] + 1)         dfs(u - 1, s + i, (long long)va * (res[i] - path[i] + 1) % mod);       path[i]--;     }   }   int main() {     int n;     scanf( %d , &n);     vector<int> temp;     int t = n;     while (t) t /= 10, cnt++;     p[1] = 1;     for (int i = 2; i <= 11; i++) p[i] = p[i - 1] * 10;     ei[0] = 1;     for (int i = 1; i < 11; i++) ei[i] = ei[i - 1] * 8;     for (int i = 0; i < (1 << cnt); i++) {       vector<int> temp;       for (int j = 0; j < cnt; j++)         if (i >> j & 1) temp.push_back(j);       int len = temp.size();       for (int j = 0; j < 1 << len; j++) {         int a[15] = {0};         for (int k = 0; k < len; k++)           if (j >> k & 1)             a[temp[k]] = 7;           else             a[temp[k]] = 4;         long long f = p[cnt], va = 0;         for (long long k = cnt - 1, r = 1; k >= 0; k--, r *= 10)           va += (long long)a[k] * r;         if (va > n) continue;         for (int k = 0; k < cnt; k++) {           if (a[k]) {             f /= 10;             continue;           }           for (int r = 9; r >= 0; r--)             if ((long long)r * f + va <= n) {               a[k] = r, va = r * f + va;               break;             }           f /= 10;         }         long long num = 0, ans = 0;         for (int k = 0; k < cnt; k++) {           if (num < temp.size() && temp[num] == k) {             num++;             if (k == cnt - 1) ans++;             continue;           }           if (a[k] == 7 || a[k] == 4) {             int sum = cnt - 1 - k;             int ts = temp.size() - num;             int tnum = a[k] + 1;             if (a[k] == 4)               tnum--;             else               tnum -= 2;             ans = ans + ei[sum - ts] * (long long)tnum;             break;           } else {             int sum = cnt - 1 - k;             int ts = temp.size() - num;             int tnum = a[k] + 1;             if (a[k] > 7)               tnum -= 3;             else if (a[k] > 4)               tnum -= 2;             else               tnum--;             if (k == cnt - 1) tnum++;             ans = ans + ei[sum - ts] * (long long)tnum;           }         }         res[len] = (res[len] + (long long)ans);       }     }     res[0]--;     dfs(5, 0, 1);     long long ans = 0, pre = 0;     for (int i = 1; i <= cnt; i++) {       pre = pre + sum[i - 1];       ans = (ans + pre * res[i]) % mod;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, good;   bool prime[100010];   vector<int> fact, num, lis;   int main() {     memset(prime, true, sizeof(prime));     for (int i = 2; i * i <= 100000; i++)       if (prime[i])         for (int j = 2; i * j <= 100000; j++) prime[i * j] = false;     for (int i = 2; i <= 100000; i++)       if (prime[i]) {         num.push_back(i);         lis.push_back(0);       }     scanf( %d , &N);     while (N--) {       scanf( %d , &good);       int temp = good;       fact.clear();       int longest = 0;       for (int i = 0; i < num.size() && num[i] * num[i] <= good; i++)         if (good % num[i] == 0) {           fact.push_back(i);           longest = max(longest, lis[i] + 1);           while (temp % num[i] == 0) temp /= num[i];         }       if (temp > 1) {         int i = lower_bound(num.begin(), num.end(), temp) - num.begin();         fact.push_back(i);         longest = max(longest, lis[i] + 1);       }       for (int i = 0; i < fact.size(); i++)         lis[fact[i]] = max(lis[fact[i]], longest);     }     int ans = 1;     for (int i = 0; i < num.size(); i++) ans = max(ans, lis[i]);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2300;   int dp[N], a[N], res = 0, n;   void dfs(int u, int d) {     if (d == n) {       dp[u] = 0;       return;     }     int l = u * 2, r = l + 1;     dfs(l, d + 1);     dfs(r, d + 1);     int x = dp[l] + a[l], y = dp[r] + a[r];     if (x < y) swap(x, y);     dp[u] = x;     res += x - y;   }   int main() {     cin >> n;     for (int i = 2; i < (1 << n + 1); i++) {       scanf( %d , &a[i]);     }     dfs(1, 0);     cout << res << endl;   }