malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void sc(char& c) {     char temp[4];     scanf( %s , temp);     c = temp[0];   }   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int testnum;   int a, b;   int lens[11];   void preprocess() {     lens[1] = 3;     for (int i = 2; i <= 10; i++) lens[i] = 4 * lens[i - 1] + 3;   }   pair<int, int> recurse(int a, int b) {     if (a == 1) {       if (b == 0) return make_pair(0, 0);       if (b == 1) return make_pair(0, 1);       if (b == 2) return make_pair(1, 1);       if (b == 3) return make_pair(1, 0);     }     int z = lens[a - 1];     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair(ret.second, ret.first);     }     b -= z + 1;     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair(ret.first, ret.second + (1 << (a - 1)));     }     b -= z + 1;     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair(ret.first + (1 << (a - 1)), ret.second + (1 << (a - 1)));     }     b -= z + 1;     if (b <= z) {       pair<int, int> ret = recurse(a - 1, b);       return make_pair((1 << a) - 1 - ret.second, (1 << (a - 1)) - 1 - ret.first);     }   }   void solve() {     pair<int, int> ret = recurse(a, b);     printf( %d %d n , ret.first, ret.second);   }   bool input() {     scanf( %d , &a);     scanf( %d , &b);     return true;   }   int main() {     preprocess();     int T = 1;     for (testnum = 1; testnum <= T; testnum++) {       if (!input()) break;       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 2200, MAX_K = 2200, INDEX = 1;   int n, k, a[MAX_N + INDEX], books[MAX_K + INDEX];   int ans = 0;   bool isBook(int x) {     for (int i = 1; i <= k; i++) {       if (books[i] == x) {         return true;       }     }     return false;   }   int dist(int book, int x) {     for (int i = 1; x + i <= n; i++) {       if (a[x + i] == book) {         return i;       }     }     return n + 1;   }   int getBest(int x) {     int best = 1;     for (int i = 2; i <= k; i++) {       if (dist(books[i], x) > dist(books[best], x)) {         best = i;       }     }     return best;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie();     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 1; i <= n; i++) {       if (!isBook((a[i]))) {         books[getBest(i)] = a[i];         ans++;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::ios::sync_with_stdio(false);     set<pair<string, int> > name, s;     int n;     cin >> n;     string a;     for (int i = 0; i < n; i++) {       cin >> a;       name.insert(make_pair(a, i + 1));       cin >> a;       name.insert(make_pair(a, i + 1));     }     int temp;     bool flag = true;     set<pair<string, int> >::iterator itr1 = name.begin();     for (int i = 0; i < n; i++) {       cin >> temp;       while ((*itr1).second != temp && itr1 != name.end()) itr1++;     }     if (itr1 != name.end())       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     int arr[n * n + 1], cnt[1001] = {0}, a[n + 1][n + 1];     vector<int> q4, q2, q1;     for (int i = 1; i <= n * n; i++) {       cin >> arr[i];       cnt[arr[i]]++;     }     for (int i = 1; i <= n * n; i++) {       int d = cnt[arr[i]];       for (int j = 1; j <= d / 4; j++) q4.push_back(arr[i]);       d %= 4;       for (int j = 1; j <= d / 2; j++) q2.push_back(arr[i]);       d %= 2;       if (d == 1) q1.push_back(arr[i]);       cnt[arr[i]] = 0;     }     if (n % 2 == 0) {       if (q2.size() || q1.size()) {         cout <<  NO ;         return;       }       cout <<  YES n ;       for (int i = 1; i <= n / 2; i++)         for (int j = 1; j <= n / 2; j++) {           int d = q4.back();           q4.pop_back();           a[i][j] = d;           a[i][n - j + 1] = d;           a[n - i + 1][j] = d;           a[n - i + 1][n - j + 1] = d;         }       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) cout << a[i][j] <<    ;         cout << endl;       }       return;     }     if (q1.size() != 1 || q4.size() < (n / 2) * (n / 2)) {       cout <<  NO ;       return;     }     cout <<  YES n ;     for (int i = 1; i <= n / 2; i++)       for (int j = 1; j <= n / 2; j++) {         int d = q4.back();         q4.pop_back();         a[i][j] = d;         a[i][n - j + 1] = d;         a[n - i + 1][j] = d;         a[n - i + 1][n - j + 1] = d;       }     while (q4.size()) {       int d = q4.back();       q2.push_back(d);       q2.push_back(d);       q4.pop_back();     }     for (int i = 1; i <= n / 2; i++) {       int d = q2.back();       q2.pop_back();       a[n / 2 + 1][i] = d;       a[n / 2 + 1][n + 1 - i] = d;       d = q2.back();       q2.pop_back();       a[i][n / 2 + 1] = d;       a[n + 1 - i][n / 2 + 1] = d;     }     a[n / 2 + 1][n / 2 + 1] = q1[0];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) cout << a[i][j] <<    ;       cout << endl;     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     solve();   }
#include <bits/stdc++.h>   using namespace std;   bool compare(string &s1, string &s2) { return s1.size() < s2.size(); }   bool sortmahstyle(const pair<int, int> &a, const pair<int, int> &b) {     if (a.first < b.first) return true;     return false;   }   long long int const maxm = 1e6;   long long int const minm = -1e9;   void solve() {     int n;     cin >> n;     int next[n + 1][2];     for (int i = 1; i <= n; i++) cin >> next[i][0] >> next[i][1];     vector<int> ans;     ans.push_back(3);     while (ans.size() < n) {       int cur = ans.back();       if (next[next[cur][0]][0] == next[cur][1] ||           next[next[cur][0]][1] == next[cur][1]) {         ans.push_back(next[cur][0]);         ans.push_back(next[cur][1]);       } else {         ans.push_back(next[cur][1]);         ans.push_back(next[cur][0]);       }     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t-- > 0) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[111][111];   int main() {     int N, K, i, k;     cin >> N >> K;     if (K > N * N)       puts( -1 );     else {       for (i = 0; i < N && K; i++)         for (k = i; k < N && K; k++) {           if (K == 1) {             if (i == k)               a[i][k] = 1;             else               a[i + 1][i + 1] = 1;             K = 0;           } else {             a[i][k] = a[k][i] = 1;             if (i == k)               K--;             else               K -= 2;           }         }       for (i = 0; i < N; i++)         for (k = 0; k < N; k++)           if (k == N - 1)             cout << a[i][k] << endl;           else             cout << a[i][k] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     std ::ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n;     cin >> n;     string s;     cin >> s;     long long a[2] = {0};     for (long long i = 0; i < n; i++) a[s[i] - 48]++;     if (a[0] == a[1]) {       cout <<  2 n  << s[0] <<    ;       for (long long i = 1; i < n; i++) cout << s[i];     } else {       cout <<  1 n  << s;     }   }
#include <bits/stdc++.h>   using namespace std;   int const INF = 100 + (int)1e9;   long long const INFL = 100 + (long long)1e18;   long double const PI = 3.141592653589793238462643L;   mt19937 tw(960172);   bool is_prime(long long x) {     for (long long y = 2; y * y <= x; ++y)       if (x % y == 0) return 0;     return x > 1;   }   long long rnd(long long x, long long y) {     static uniform_int_distribution<long long> d;     return d(tw) % (y - x + 1) + x;   }   long long sqr(int a) { return (long long)a * a; }   template <class T>   T sqr(T const& a) {     return a * a;   }   long long gcd(long long a, long long b) {     while (b > 0) {       long long t = a % b;       a = b;       b = t;     }     return a;   }   void solve() {     int n, k;     cin >> n >> k;     if (n <= 3 || k == 1 || k > 3 || (n == 4 && k == 2)) {       cout << -1 <<   n ;       return;     }     vector<pair<int, int>> edges;     if (k == 2) {       for (int i = 1; i < n; ++i) edges.emplace_back(i, i + 1);     } else {       edges.emplace_back(1, 2);       edges.emplace_back(2, 3);       edges.emplace_back(3, 4);       for (int i = 5; i <= n; ++i) {         edges.emplace_back(i, 1);         edges.emplace_back(i, 3);         if (i > 5) {           edges.emplace_back(i, i - 1);           if (i > 6) edges.emplace_back(i, 5);         }       }     }     cout << edges.size() <<   n ;     for (auto e : edges) cout << e.first <<     << e.second <<   n ;   }   int main() {     cout << setprecision(15) << fixed;     int tcnt = 1;     for (int test = 1; test <= tcnt; ++test) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000005;   char s[N], t[N], S[N];   int n, ch[N][26], fa[N];   int len[N], anc[N], dif[N], nd, la;   int ans[N], _ans[N], from[N];   void extend(int n) {     int c = S[n], p = la;     for (; S[n - len[p] - 1] != c; p = fa[p])       ;     if (!ch[p][c -  a ]) {       len[++nd] = len[p] + 2;       int q = fa[p];       for (; S[n - len[q] - 1] != c; q = fa[q])         ;       fa[nd] = ch[q][c -  a ];       ch[p][c -  a ] = nd;       dif[nd] = len[nd] - len[fa[nd]];       anc[nd] = (dif[nd] == dif[fa[nd]] ? anc[fa[nd]] : fa[nd]);     }     la = ch[p][c -  a ];   }   int main() {     scanf( %s%s , s + 1, t + 1);     n = strlen(s + 1);     for (int i = (int)(1); i <= (int)(n); i++)       S[i * 2 - 1] = s[i], S[i * 2] = t[i];     fa[0] = nd = 1;     len[1] = -1;     n *= 2;     for (int i = (int)(1); i <= (int)(n); i++) ans[i] = 1 << 30;     _ans[0] = 1;     for (int i = (int)(1); i <= (int)(n); i++) {       extend(i);       for (int p = la; p; p = anc[p]) {         _ans[p] = i - (len[anc[p]] + dif[p]);         if (dif[fa[p]] == dif[p])           if (ans[_ans[p]] > ans[_ans[fa[p]]]) _ans[p] = _ans[fa[p]];         if (!(i & 1) && ans[i] > ans[_ans[p]] + 1)           ans[i] = ans[_ans[p]] + 1, from[i] = _ans[p];       }       if (!(i & 1) && S[i - 1] == S[i] && ans[i] > ans[i - 2])         ans[i] = ans[i - 2], from[i] = i - 2;     }     if (ans[n] > 1e9) return puts( -1 ), 0;     printf( %d n , ans[n]);     for (int i = n; i; i = from[i])       if (i - from[i] > 2) printf( %d %d n , from[i] / 2 + 1, i / 2);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, i, j, n, m, po1, po2, w1, w2, z1, z2, lr, pr, li, pi, tw, ti;     cin >> n;     if ((n / 2) % 2 == 1) {       cout <<  ! -1 ;       return 0;     }     po1 = 1;     po2 = n / 2 + 1;     cout <<  ?   << po1 << endl;     cin >> w1;     cout <<  ?   << po2 << endl;     cin >> w2;     lr = w1 - w2;     pr = -lr;     li = 1;     pi = n / 2 + 1;     if (pr == 0) {       cout <<  !   << li;       return 0;     }     for (i = 0; i < 29; i++) {       ti = (pi + li) / 2;       cout <<  ?   << ti << endl;       cin >> z1;       cout <<  ?   << ti + n / 2 << endl;       cin >> z2;       tw = z1 - z2;       if (tw == 0) {         cout <<  !   << ti;         return 0;       }       if (tw < 0) {         if (lr < 0) {           lr = tw;           li = ti;         } else {           pr = tw;           pi = ti;         }       } else {         if (lr > 0) {           lr = tw;           li = ti;         } else {           pr = tw;           pi = ti;         }       }     }   }
#include <bits/stdc++.h>   const long long oo = 0x7f7f7f7f7f7f7f7f;   using namespace std;   const long long maxn = 1e6 + 999;   long long n, m, k, visa[maxn], visb[maxn], b[maxn], tota, totb, totc, totd;   struct goods {     long long val, id;     friend bool operator<(goods x, goods y) { return x.val < y.val; }   } a[maxn], A[maxn], B[maxn], C[maxn];   long long tot, cnt[maxn << 2], ls[maxn << 2], rs[maxn << 2], root;   long long sumv[maxn << 2];   void insert(long long pos, long long val, long long l, long long r,               long long &rt) {     if (val == 0 || pos == 0) return;     if (!rt) rt = ++tot;     if (val > 0)       sumv[rt] += val, cnt[rt]++;     else       sumv[rt] += val, cnt[rt]--;     if (l == r) {       return;     }     long long mid = l + r >> 1;     if (pos <= mid)       insert(pos, val, l, mid, ls[rt]);     else       insert(pos, val, mid + 1, r, rs[rt]);   }   long long query(long long k, long long l, long long r, long long rt) {     if (!k) return 0;     if (l == r) {       return min(k, cnt[rt]) * b[l];     }     long long cntt = cnt[ls[rt]];     long long mid = l + r >> 1;     if (k <= cntt)       return query(k, l, mid, ls[rt]);     else       return sumv[ls[rt]] + query(k - cntt, mid + 1, r, rs[rt]);   }   signed main() {     scanf( %lld%lld%lld , &n, &m, &k);     for (long long i = 1; i <= n; i++)       scanf( %lld , &a[i].val), b[i] = a[i].val, a[i].id = i;     sort(b + 1, b + 1 + n);     for (long long i = 1; i <= n; i++)       a[i].val = lower_bound(b + 1, b + 1 + n, a[i].val) - b;     long long x;     scanf( %lld , &x);     for (long long i = 1; i <= x; i++) {       long long p;       scanf( %lld , &p);       visa[p] = 1;     }     scanf( %d , &x);     for (long long i = 1; i <= x; i++) {       long long p;       scanf( %d , &p);       visb[p] = 1;     }     for (long long i = 1; i <= n; i++) {       if (visa[i] && visb[i])         A[++tota] = a[i];       else if (visa[i] && !visb[i])         B[++totb] = a[i];       else if (visb[i] && !visa[i])         C[++totc] = a[i];       insert(a[i].val, b[a[i].val], 1, n, root), totd++;     }     long long ans = oo, tmp = 0;     long long now1 = min(k, min(totb, totc));     sort(A + 1, A + 1 + tota);     sort(B + 1, B + 1 + totb);     sort(C + 1, C + 1 + totc);     for (long long i = 1; i <= now1; i++)       tmp += b[B[i].val] + b[C[i].val],           insert(C[i].val, -b[C[i].val], 1, n, root),           insert(B[i].val, -b[B[i].val], 1, n, root), totd -= 2;     long long ls = 0;     for (long long r = 0; r <= tota; r++) {       if (r + now1 == k && m - (r + now1 * 2) >= 0 &&           m - (r + now1 * 2) <= totd) {         ans = min(ans, tmp + query(m - (r + now1 * 2), 1, n, root));       }       tmp += b[A[r + 1].val];       insert(A[r + 1].val, -b[A[r + 1].val], 1, n, root), totd--;       if (r + 1 + now1 > k && now1 > 0) {         tmp -= b[B[now1].val] + b[C[now1].val],             insert(C[now1].val, b[C[now1].val], 1, n, root),             insert(B[now1].val, b[B[now1].val], 1, n, root), totd += 2;         now1--;       }     }     if (ans == oo) ans = -1;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int b1[] = {0, 0, 1, -1};   int b2[] = {1, -1, 0, 0};   int d1[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int d2[] = {-1, 0, 1, -1, 1, -1, 0, 1};   string st;   const int mxn = 1e6;   struct tp {     int tt, cl, op;   } tree[4 * mxn];   void build_tree(int s, int e, int index) {     tp obj;     obj.tt = obj.cl = obj.op = 0;     if (s == e) {       obj.cl = (st[s] ==  ) );       obj.op = (st[s] ==  ( );       tree[index] = obj;       return;     }     int mid = (s + e) / 2;     build_tree(s, mid, 2 * index);     build_tree(mid + 1, e, 2 * index + 1);     int min_blnc = min(tree[2 * index].op, tree[2 * index + 1].cl);     obj.tt = tree[2 * index].tt + tree[2 * index + 1].tt + 2 * min_blnc;     obj.cl = tree[2 * index].cl + tree[2 * index + 1].cl - min_blnc;     obj.op = tree[2 * index].op + tree[2 * index + 1].op - min_blnc;     tree[index] = obj;     return;   }   tp query(int second, int se, int qs, int qe, int index) {     tp obj;     obj.tt = obj.cl = obj.op = 0;     if (second >= qs and se <= qe) {       return tree[index];     }     if (qe < second || qs > se) return obj;     int mid = (second + se) / 2;     tp tp1 = query(second, mid, qs, qe, 2 * index);     tp tp2 = query(mid + 1, se, qs, qe, 2 * index + 1);     int min_blnc = min(tp1.op, tp2.cl);     obj.tt = tp1.tt + tp2.tt + 2 * min_blnc;     obj.cl = tp1.cl + tp2.cl - min_blnc;     obj.op = tp1.op + tp2.op - min_blnc;     return obj;   }   void solve() {     cin >> st;     int n = st.length();     build_tree(0, n - 1, 1);     int q;     cin >> q;     while (q--) {       int x, y;       cin >> x >> y;       x--, y--;       tp res = query(0, n - 1, x, y, 1);       cout << res.tt << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long inf = 1e18, M = 1e9 + 7;   const long long int N = 1;   bool left_turn(pair<long long int, long long int> a,                  pair<long long int, long long int> b,                  pair<long long int, long long int> c) {     if (a.first == b.first) {       if (a.second < b.second)         return c.first < b.first;       else         return c.first > b.first;     } else if (a.second == b.second) {       if (a.first < b.first)         return c.second > b.second;       else         return c.second < b.second;     }   }   void solve() {     long long int n;     cin >> n;     vector<pair<long long int, long long int> > v(n + 1);     for (long long int i = 0; i < n + 1; ++i) cin >> v[i].first >> v[i].second;     long long int ans = 0;     for (long long int i = 1; i < n; ++i) {       if (left_turn(v[i - 1], v[i], v[i + 1])) ++ans;     }     cout << ans;   }   int32_t main() {     long long int t = 1;     for (long long int z = 1; z <= t; ++z) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long min(long long x, long long y) { return x < y ? x : y; }   inline long long max(long long x, long long y) { return x > y ? x : y; }   const int Maxn = 1e4 + 5;   int n, k, m, ans = -1;   int a[Maxn], b[105], c[30], dis[30][Maxn], f[2000005], pw[30];   bool inq[Maxn];   void SPFA(register int x, register int p) {     dis[p][x] = 0;     queue<int> q;     q.push(x);     while (!q.empty()) {       x = q.front();       q.pop();       inq[x] = false;       for (register int i = 1, nx; i <= m; i++) {         nx = x + b[i];         if (nx <= n + 1)           if (dis[p][x] + 1 < dis[p][nx]) {             dis[p][nx] = dis[p][x] + 1;             if (!inq[nx]) {               q.push(nx);               inq[nx] = true;             }           }         nx = x - b[i];         if (nx > 0)           if (dis[p][x] + 1 < dis[p][nx]) {             dis[p][nx] = dis[p][x] + 1;             if (!inq[nx]) {               q.push(nx);               inq[nx] = true;             }           }       }     }   }   int main() {     pw[0] = 1;     for (int i = 1; i <= 25; i++) pw[i] = pw[i - 1] << 1;     memset(dis, 0x3f, sizeof(dis));     int pos, siz = 0;     cin >> n >> k >> m;     for (int i = 1; i <= k; i++) {       scanf( %d , &pos);       a[pos] = 1;     }     for (int i = 1; i <= m; i++) scanf( %d , &b[i]);     for (int i = 0; i <= n; i++)       if (a[i + 1] != a[i]) {         c[++siz] = i + 1;         SPFA(i + 1, siz);       }     n = siz;     memset(f, 0x3f, sizeof(f));     f[0] = 0;     int nx;     for (int i = 0; i < pw[n] - 3; i++)       for (int j = 1; j < n; j++)         for (int k = j + 1; k <= n; k++) {           if ((i & pw[j - 1]) || (i & pw[k - 1])) continue;           nx = i | pw[j - 1] | pw[k - 1];           f[nx] = min(f[nx], f[i] + dis[j][c[k]]);         }     if (f[pw[n] - 1] == 0x3f3f3f3f) f[pw[n] - 1] = -1;     cout << f[pw[n] - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long cnt, prime[100], pcnt;   long long flg;   long long gcd(long long a, long long b) {     if (!b) return a;     return gcd(b, a % b);   }   long long search(long long a, long long b) {     if (!b) return 0;     long long d = gcd(a, b);     a /= d;     b /= d;     long long minn = 1ll << 60;     for (int i = 1; i <= cnt; i++)       if (a % prime[i] == 0) minn = min(minn, b % prime[i]);     if (minn == 1ll << 60) return b;     return minn + search(a, b - minn);   }   int main() {     long long a, b;     scanf( %I64d%I64d , &a, &b);     long long A = a;     for (long long i = 2; i * i <= A; i++) {       if (a % i == 0) {         while (a % i == 0) {           a /= i;         }         prime[++cnt] = i;       }     }     if (a > prime[cnt]) prime[++cnt] = a;     if (a == A) {       printf( %I64d , A > b ? b : b % A + (b - b % A) / A);       return 0;     }     long long ans = search(A, b);     printf( %I64d , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int INF = 1e9;   int a[N], maxv[N << 2], addv[N << 2];   int dmax[N][21];   int n, ans;   void maintain(int rt, int l, int r) {     maxv[rt] = 0;     if (l < r) maxv[rt] = max(maxv[rt << 1], maxv[rt << 1 | 1]);     maxv[rt] += addv[rt];   }   void update(int ql, int qr, int v, int rt, int l, int r) {     if (ql <= l && qr >= r)       addv[rt] += v;     else {       int mid = (l + r) >> 1;       if (ql <= mid) update(ql, qr, v, rt << 1, l, mid);       if (qr > mid) update(ql, qr, v, rt << 1 | 1, mid + 1, r);     }     maintain(rt, l, r);   }   void querymax(int ql, int qr, int rt, int l, int r, int add) {     if (ql <= l && qr >= r)       ans = max(ans, maxv[rt] + add);     else {       int mid = (l + r) >> 1;       if (ql <= mid) querymax(ql, qr, rt << 1, l, mid, add + addv[rt]);       if (qr > mid) querymax(ql, qr, rt << 1 | 1, mid + 1, r, add + addv[rt]);     }   }   void build() {     for (int i = 1; i <= n; i++) dmax[i][0] = a[i];     for (int j = 1; (1 << j) <= n; j++) {       for (int i = 1; i + (1 << j) - 1 <= n; i++) {         dmax[i][j] = max(dmax[i][j - 1], dmax[i + (1 << (j - 1))][j - 1]);       }     }   }   int query(int l, int r) {     int k = 0;     while ((1 << (k + 1)) <= r - l + 1) k++;     return max(dmax[l][k], dmax[r - (1 << k) + 1][k]);   }   int main() {     int k, num, l, r, mid;     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     build();     memset(maxv, 0, sizeof(maxv));     for (int i = 1; i <= n; i++) {       l = 0;       r = i;       while (r - l > 1) {         mid = (l + r) >> 1;         if (query(mid, r - 1) >= a[i])           l = mid;         else           r = mid;       }       update(r, i, 1, 1, 1, n);       if (i >= k) {         ans = 0;         querymax(i - k + 1, i, 1, 1, n, 0);         printf( %d  , ans);       }     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e7 + 7;   long long mn = (long long)(1e18 + 7), mx = -(long long)(1e18 + 7);   long long n, m, k, s, q, t;   long long a, b, c, d, e;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> a >> b >> c >> d;     for (int i = 0; i <= N; i++) {       if (i * c <= n) mx = max(mx, i * a + ((n - i * c) / d * b));       if (i * d <= n) mx = max(mx, i * b + ((n - i * d) / c * a));     }     cout << mx;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI =       3.14159265358979323846264338327950288419716939937510582097494459230;   template <class T>   int getbit(T s, int i) {     return (s >> 1) & 1;   }   template <class T>   T onbit(T s, int i) {     return s | (T(1) << i);   }   template <class T>   T offbit(T s, int i) {     return s & (~(T(1) << i));   }   template <class T>   int cntbit(T s) {     return __builtin_popcount(s);   }   long long N;   long long modPow(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a;     long long tmp = modPow(a, b / 2);     if (b % 2 == 0) return ((tmp * tmp) % 1000000007LL);     return ((((tmp * tmp) % 1000000007LL) * a) % 1000000007LL);   }   void VarInput() { cin >> N; }   void ProSolve() {     long long ans = modPow(27, N) - modPow(7, N);     while (ans < 0) ans += 1000000007LL;     cout << ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     VarInput();     ProSolve();     return 0;   }