malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     long long sum = 0;     int d[1000000 + 1] = {0};     for (int i = 1; i <= 1000000; i++) {       for (int j = i; j <= 1000000; j += i) {         d[j]++;       }     }     int a, b, c;     cin >> a >> b >> c;     for (auto(i) = (1); (i) < (a + 1); ++(i))       for (auto(j) = (1); (j) < (b + 1); ++(j))         for (auto(k) = (1); (k) < (c + 1); ++(k))           sum = (sum + d[i * j * k]) % 1073741824;     cout << sum % 1073741824;     return 0;   }
#include <bits/stdc++.h>   struct Seg {     int l;     int r;     int y;   };   struct Event {     int x;     enum { BEG, END } type;     Seg seg;     static Event beginOf(Seg seg) { return Event{seg.l, BEG, seg}; }     static Event endOf(Seg seg) { return Event{seg.r, END, seg}; }     friend bool operator<(const Event& a, const Event& b) {       return std::tie(a.x, a.type, a.seg.y) < std::tie(b.x, b.type, b.seg.y);     }   };   int main() {     int sx, sy;     std::cin >> sy >> sx;     std::vector<Event> events;     events.reserve(sy * sx);     for (int y = 0; y < sy; y++) {       int intervals;       std::cin >> intervals;       for (int i = 0; i < intervals; i++) {         int l, r;         std::cin >> l >> r;         Seg seg{l - 1, r, y};         events.push_back(Event::beginOf(seg));         events.push_back(Event::endOf(seg));       }     }     std::sort(events.begin(), events.end());     std::vector<std::vector<int>> dp(sx + 1, std::vector<int>(sx + 1, 0));     for (int len = 1; len <= sx; len++) {       for (int l = 0, r = len; r <= sx; l++, r++) {         int currHeight = 0;         auto currEv = events.begin();         for (int x = l; x < r; x++) {           for (; currEv != events.end() && currEv->x <= x; ++currEv) {             if (l <= currEv->seg.l && currEv->seg.r <= r) {               if (currEv->type == Event::BEG)                 currHeight++;               else                 currHeight--;             }           }           dp[l][r] = std::max(dp[l][r],                               dp[l][x] + dp[x + 1][r] + currHeight * currHeight);         }       }     }     std::cout << dp[0][sx] << std::endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<string> v;     int i, j, k, l, l1, l2;     string a, b, s1, s2, s;     cin >> a >> b;     l1 = a.size();     l2 = b.size();     for (i = 1; i <= l1; i++) {       for (j = 1; j <= l2; j++) {         for (k = 0, s1 =   ; k < i; k++) {           s1 += a[k];         }         for (l = 0, s2 =   ; l < j; l++) {           s2 += b[l];         }         s = s1 + s2;         v.push_back(s);       }     }     sort(v.begin(), v.end());     cout << v[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void ok(int x) {     cout << x <<   n ;     exit(0);   }   int main() {     int n, p;     cin >> n >> p;     for (int k = 0; k < int(1e8); k++) {       long long n1 = n - 1LL * p * k;       if (n1 < 0) continue;       if (n1 >= k && k >= __builtin_popcountll(n1)) ok(k);     }     ok(-1);   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > ans;   vector<int> e[100010];   void dfs(int x, int p, int entry) {     ans.emplace_back(x, entry);     if (x == 1) {       for (int it : e[x])         if (it != p) dfs(it, x, ++entry), ans.emplace_back(1, entry);     } else {       int cur = entry;       int sz = e[x].size() - 1;       if (entry - 1 >= sz) {         cur = entry - 1 - sz;         ans.emplace_back(x, cur);         for (int it : e[x])           if (it != p) {             cur++;             dfs(it, x, cur), ans.emplace_back(x, cur);           }       } else {         for (int it : e[x])           if (it != p) {             ++cur;             dfs(it, x, cur), ans.emplace_back(x, cur);             if (cur == sz + 1) {               cur = 0;               ans.emplace_back(x, 0);             }           }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     for (int i = 1, u, v; i < n; i++) {       cin >> u >> v;       e[u].emplace_back(v);       e[v].emplace_back(u);     }     dfs(1, 0, 0);     cout << ans.size() <<   n ;     for (auto &[u, v] : ans) cout << u <<     << v <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n, sumA = 0, sumG = 0;     cin >> n;     vector<pair<int, int>> vec(n);     for (int i = 0; i < n; i++) cin >> vec[i].first >> vec[i].second;     if (vec[0].first > vec[0].second) {       sumG = vec[0].second;       s.push_back( G );     } else {       sumA = vec[0].first;       s.push_back( A );     }     for (int i = 1; i < n; i++) {       if (sumA + vec[i].first - sumG <= 500) {         sumA += vec[i].first;         s.push_back( A );       } else {         sumG += vec[i].second;         s.push_back( G );       }     }     if (abs(sumA - sumG) <= 500)       cout << s;     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T gcd(T a, T b) {     if (a == 0) return b;     return gcd(b % a, a);   }   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;       b /= 2;       a = ((a % m) * (a % m)) % m;     }     return ans % m;   }   int n;   int a[1005];   int dp[1005][1005];   int solve(int f, int s) {     if (f > n) return 0;     if (s == n) {       return max(a[f], a[s]);     }     if (s > n) {       return a[f];     }     if (dp[f][s] != -1) return dp[f][s];     int ans = (long long)1e9 + 2;     ans = min(ans, max(a[f], a[s]) + solve(s + 1, s + 2));     ans = min(ans, max(a[f], a[s + 1]) + solve(s, s + 2));     ans = min(ans, max(a[s], a[s + 1]) + solve(f, s + 2));     return dp[f][s] = ans;   }   void print(int f, int s) {     if (f > n) return;     if (s == n) {       cout << f <<     << s <<   n ;       return;     }     if (s > n) {       cout << f;       return;     }     if (dp[f][s] == max(a[f], a[s]) + solve(s + 1, s + 2)) {       cout << f <<     << s <<   n ;       print(s + 1, s + 2);     } else if (dp[f][s] == max(a[f], a[s + 1]) + solve(s, s + 2)) {       cout << f <<     << s + 1 <<   n ;       print(s, s + 2);     } else if (dp[f][s] == max(a[s], a[s + 1]) + solve(f, s + 2)) {       cout << s <<     << s + 1 <<   n ;       print(f, s + 2);     }   }   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     memset(dp, -1, sizeof dp);     cout << solve(1, 2) <<   n ;     print(1, 2);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXH = 200000 + 10, MAXN = 2000 + 10;   const long long MOD = 1000000007;   struct Point {     int x, y;     bool operator<(const Point &p1) const { return x + y < p1.x + p1.y; }   } p[MAXN];   long long fac[MAXH], inv[MAXH];   long long f[MAXN];   inline long long Fastpow(long long a, long long b) {     long long res = 1;     while (b) {       if (b & 1) (res *= a) %= MOD;       (a *= a) %= MOD;       b >>= 1;     }     return res;   }   long long Calc(int a, int b) {     return ((((fac[a + b - 2] * inv[a - 1]) % MOD) * inv[b - 1]) % MOD);   }   int main() {     int h, w, n, mx;     scanf( %d%d%d , &h, &w, &n);     mx = h + w;     for (int i = 1; i <= n; ++i) scanf( %d%d , &p[i].x, &p[i].y);     p[++n] = (Point){h, w};     sort(p + 1, p + 1 + n);     fac[0] = inv[0] = 1;     for (int i = 1; i <= mx; ++i) fac[i] = fac[i - 1] * (long long)i % MOD;     for (int i = 1; i <= mx; ++i) inv[i] = Fastpow(fac[i], MOD - 2);     for (int i = 1; i <= n; ++i) {       f[i] = Calc(p[i].x, p[i].y);       for (int j = 1; j < i; ++j)         if (p[j].x <= p[i].x && p[j].y <= p[i].y) {           f[i] -= f[j] * Calc(p[i].x - p[j].x + 1, p[i].y - p[j].y + 1) % MOD;           ((f[i] %= MOD) += MOD) %= MOD;         }     }     cout << f[n] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0, y = 0;     cin >> n;     int *C = new int[n];     for (int i = 0; i < n; i++) {       cin >> C[i];     }     for (int j = 0; j < n; j++) {       if (j == 0) {         y = abs(C[j] - C[j + 1]);         x = abs(C[j] - C[n - 1]);       } else if (j == n - 1) {         x = max(abs(C[j] - C[n - 1]), abs(C[j] - C[0]));         y = abs(C[j] - C[j - 1]);       } else {         x = max(abs(C[j] - C[n - 1]), abs(C[j] - C[0]));         y = min(abs(C[j] - C[j + 1]), abs(C[j] - C[j - 1]));       }       cout << y <<     << x << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int modul(int a, int b) {     if (a - b < 0) return b - a;     return a - b;   }   int main() {     int n, k, st, et, s, e, d, v[103], j, m, stm, etm;     cin >> n >> k;     st = et = 0;     d = 0;     for (int i = 1; i <= n; i++) {       cin >> v[i];       if (v[i] == 1)         et++;       else         st++;     }     stm = etm = 0;     for (int i = 1; i <= k; i++) {       s = st;       e = et;       j = i;       while (j <= n) {         if (v[j] == 1)           e--;         else           s--;         j += k;       }       m = modul(s, e);       if (m > d) {         stm = s;         etm = e;         d = m;       }     }     cout << d;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010, L = 33, B = 7340033, root = 3;   int dp[L][N << 2];   int mypw(int x, int k) {     int ret = 1;     while (k) {       if (k & 1) ret = 1ll * ret * x % B;       k >>= 1;       x = 1ll * x * x % B;     }     return ret;   }   void change(int y[], int l) {     for (int i = 1, j = l / 2; i < l - 1; ++i) {       if (i < j) swap(y[i], y[j]);       int k = l / 2;       while (j >= k) {         j -= k;         k >>= 1;       }       if (j < k) j += k;     }   }   void fft(int y[], int l, int on) {     change(y, l);     for (int h = 2; h <= l; h <<= 1) {       int wn = mypw(root, (B - 1) / h);       if (on == -1) wn = mypw(wn, B - 2);       for (int j = 0; j < l; j += h) {         int w = 1;         for (int k = j; k < j + h / 2; ++k) {           int u = y[k];           int t = 1ll * y[k + h / 2] * w % B;           y[k] = u + t;           if (y[k] >= B) y[k] -= B;           y[k + h / 2] = u + B - t;           if (y[k + h / 2] >= B) y[k + h / 2] -= B;           w = 1ll * w * wn % B;         }       }     }     if (on == -1) {       int inv = mypw(l, B - 2);       for (int i = 0; i < l; ++i) {         y[i] = 1ll * y[i] * inv % B;       }     }   }   void calc(int a[], int b[], int l) {     l *= 2;     for (int i = 0; i < l; ++i) {       if (i < l / 2)         a[i] = b[i];       else         a[i] = 0;     }     fft(a, l, 1);     for (int i = 0; i < l; ++i) a[i] = 1ll * a[i] * a[i] % B;     fft(a, l, -1);   }   void init() {     dp[0][0] = 1;     for (int i = 1; i < L; ++i) {       calc(dp[i], dp[i - 1], 1 << 10);       calc(dp[i], dp[i], 1 << 10);       for (int j = (1 << 10) - 1; j > 0; --j) {         dp[i][j] = dp[i][j - 1];       }       dp[i][0] = 1;     }   }   int main() {     int q;     init();     scanf( %d , &q);     while (q--) {       int n, k;       scanf( %d%d , &n, &k);       int cnt = 0;       while (n > 1 && (n & 1)) {         ++cnt;         n >>= 1;       }       printf( %d n , dp[cnt][k]);     }     return 0;   }
#include <bits/stdc++.h>   const int BUFFSIZE = 10240;   char BUFF[BUFFSIZE + 1], *p = BUFF;   int CHAR, SIGN, BYTES = 0;   using namespace std;   vector<long long> V;   void dfs(long long N) {     if (N > 5000000000LL) return;     V.push_back(N);     dfs(N * 10 + 4);     dfs(N * 10 + 7);   }   int main() {     dfs(0);     sort(V.begin(), V.end());     long long pl, pr, vl, vr, k;     cin >> pl >> pr >> vl >> vr >> k;     double den = (pr - pl + 1) * (vr - vl + 1);     double num = 0;     for (int i = 1; i + k - 1 < V.size(); i++) {       long long x = V[i];       long long y = V[i + k - 1];       long long lftp = V[i - 1] + 1;       long long rgtp = x;       long long lftv = y;       long long rgtv = V[i + k] - 1;       lftp = max(lftp, pl);       rgtp = min(rgtp, pr);       lftv = max(lftv, vl);       rgtv = min(rgtv, vr);       if (lftp <= rgtp && lftv <= rgtv) {         double prob = (rgtp - lftp + 1.0) * (rgtv - lftv + 1.0);         num += prob;       }       lftv = V[i - 1] + 1;       rgtv = x;       lftp = y;       rgtp = V[i + k] - 1;       lftp = max(lftp, pl);       rgtp = min(rgtp, pr);       lftv = max(lftv, vl);       rgtv = min(rgtv, vr);       if (lftp <= rgtp && lftv <= rgtv) {         double prob = (rgtp - lftp + 1.0) * (rgtv - lftv + 1.0);         num += prob;       }     }     if (k == 1) {       for (int i = 1; i < V.size(); i++)         if (V[i] >= pl && V[i] <= pr && V[i] >= vl && V[i] <= vr) num -= 1;     }     double res = 1.0 * num / den;     printf( %.20lf n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   bitset<10000> B;   int BIT[100010];   int n;   void update(int pos, int x) {     for (; pos < n; pos |= pos + 1) BIT[pos] += x;   }   int qu(int pos) {     int ret = 0;     for (; pos; pos &= pos - 1) ret += BIT[pos - 1];     return ret;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     for (int len = 1; len <= 4; ++len) {       for (int mask = 0; mask < 1 << len; ++mask) {         int num = 0;         for (int bit = 0; bit < len; ++bit)           if (mask & (1 << bit))             num = num * 10 + 4;           else             num = num * 10 + 7;         B[num] = 1;       }     }     int m;     cin >> n >> m;     int a[n];     for (int i = 0; i < n; ++i) {       cin >> a[i];       if (B[a[i]]) update(i, 1);     }     while (m--) {       string type;       int l, r;       cin >> type >> l >> r;       if (type ==  count ) {         cout << qu(r) - qu(l - 1) <<   n ;       } else {         int d;         cin >> d;         for (int i = l - 1; i <= r - 1; ++i) {           if (B[a[i]]) update(i, -1);           a[i] += d;           if (B[a[i]]) update(i, 1);         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const int maxn = 1e5 + 5;   long long dp[205][15005];   long long p2[205], p5[205];   long long a[205];   int n, k;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       while (a[i] % 2 == 0) a[i] /= 2, p2[i]++;       while (a[i] % 5 == 0) a[i] /= 5, p5[i]++;     }     memset(dp, -0x3f3f3f3f, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i <= n; i++) {       for (int j = k; j >= 1; j--) {         for (int k = 12005; k >= p2[i]; k--) {           dp[j][k] = max(dp[j][k], dp[j - 1][k - p2[i]] + p5[i]);         }       }     }     long long mx = 0;     for (long long i = 0; i <= 12005; i++) {       mx = max(mx, min(i, dp[k][i]));     }     printf( %lld n , mx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<string, int> types;   int count(const string &data) {     int amps = 0, stars = 0, i, j;     for (i = 0; i < (int)data.size() && data[i] ==  & ; i++, amps++)       ;     for (j = data.size() - 1; j >= 0 && data[j] ==  * ; j--, stars++)       ;     string t = data.substr(i, j - i + 1);     if (!types.count(t) || types[t] == -1) return -1;     int answer = types[t];     answer += stars - amps, answer = max(-1, answer);     return answer;   }   int n;   string command, a, b;   int main() {     cin >> n;     types[ void ] = 0, types[ errtype ] = -1;     for (int i = 0; i < n; i++) {       cin >> command >> a;       if (command ==  typedef )         cin >> b, types[b] = count(a);       else {         int p = count(a);         if (p == -1)           cout <<  errtype  << endl;         else {           cout <<  void ;           for (int i = 0; i < p; i++) cout <<  * ;           cout << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int Case, n, sz, ans, A[300000 + 5], Min[300000 + 5], Max[300000 + 5],       Id[300000 + 5];   int main() {     for (scanf( %d , &Case); Case; Case--) {       scanf( %d , &n);       for (int i = 1; i <= n; i++) Id[i] = 0, Min[i] = n + 1, Max[i] = 0;       for (int i = 1; i <= n; i++) {         scanf( %d , A + i);         Id[A[i]] = 1;       }       for (int i = 1; i <= n; i++) Id[i] += Id[i - 1];       sz = Id[n];       for (int i = 1; i <= n; i++) {         A[i] = Id[A[i]];         Min[A[i]] = min(Min[A[i]], i);         Max[A[i]] = max(Max[A[i]], i);       }       ans = sz;       for (int l = 1, r = 0, mx; l <= sz; l++) {         if (r < l) r = l, mx = Max[l];         for (; r < sz && Min[r + 1] > mx; r++) mx = Max[r + 1];         ans = min(ans, sz - (r - l + 1));       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int k;   long long int m, lim = 2e18;   long long int dp[70][70][2];   long long int solve(string s, int pos, int k, bool f) {     if (k < 0) return 0;     if (pos == (int)s.size()) {       return (k == 0);     }     if (dp[pos][k][f] != -1) return dp[pos][k][f];     long long int ret = 0;     for (char c =  0 ; c <=  1 ; ++c) {       if (!f and s[pos] < c) continue;       ret += solve(s, pos + 1, k - (c ==  1 ), f | (s[pos] > c));     }     return dp[pos][k][f] = ret;   }   long long int get(string s) {     if (s ==  1 ) {       if (k == 1)         return 1;       else         return 0;     }     memset(dp, -1, sizeof dp);     return solve(s, 0, k, 0);   }   string binary(long long int num) {     string ret =   ;     while (num) {       if (num & 1)         ret +=  1 ;       else         ret +=  0 ;       num >>= 1LL;     }     reverse((ret).begin(), (ret).end());     return ret;   }   long long int search(long long int l, long long int r) {     long long int mid = (l + r) / 2LL;     long long int tot = get(binary(2 * mid)) - get(binary(mid));     if (tot == m)       return mid;     else if (tot < m)       return search(mid + 1, r);     return search(l, mid - 1);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     while (cin >> m >> k) {       long long int ans = search(1LL, lim);       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   int arr[1005];   int n;   using namespace std;   int main() {     int n;     scanf( %d , &n);     int sum = 0;     for (int i = 0; i < 505; i++) {       sum += i;       arr[i + 1] = sum;     }     if (n == 0) {       printf( a n );       return 0;     }     for (int i = 0; i < 26; i++) {       if (n == 0) {         return 0;       }       int howmany = lower_bound(arr, arr + 500, n) - arr;       if (arr[howmany] == n) {         for (int j = 0; j < howmany; j++) {           printf( %c ,  a  + i);         }         printf(  n );         return 0;       }       if (arr[howmany] > n) {         n -= arr[howmany - 1];         for (int j = 0; j < howmany - 1; j++) {           printf( %c ,  a  + i);         }         continue;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     vector<long long> p(n);     for (auto& i : p) cin >> i;     vector<long long> dp(n, 1);     vector<int> exist(n, false);     for (long long i = 0; i < (n); ++i) {       exist[p[i] - 1] = true;       if (p[i] != 1)         if (exist[p[i] - 2]) {           dp[p[i] - 1] = 1 + dp[p[i] - 2];         }     }     long long max_c = 0;     for (long long i = 0; i < (n); ++i) max_c = max(max_c, dp[i]);     cout << n - max_c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5 * 1e5 + 1;   int main() {     long long q;     cin >> q;     vector<long long> v(N);     for (int i = 0; i <= N; i++) {       v[i] = i;     }     deque<long long> dq;     vector<pair<long long, long long>> pq(q);     long long idx = 0;     while (q--) {       long long a;       cin >> a;       if (a == 1) {         long long b;         cin >> b;         pq[idx].first = b;         pq[idx].second = 0;         idx++;       } else {         long long b, c;         cin >> b >> c;         pq[idx].first = b;         pq[idx].second = c;         idx++;       }     }     for (int i = idx - 1; i >= 0; i--) {       if (pq[i].first != 0 && pq[i].second != 0) {         v[pq[i].first] = v[pq[i].second];       } else {         dq.push_front(v[pq[i].first]);       }     }     for (auto it : dq) {       cout << it <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int cap = 1e3;   int n, m;   char grid[cap][cap];   int vis[4][cap][cap] = {};   vector<pair<int, int>> dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};   bool dfs(int i, int j, int d, int t) {     if (i < 0 || i == n || j < 0 || j == m || grid[i][j] ==  *  ||         (vis[d][i][j] != -1 && t >= vis[d][i][j]))       return false;     if (grid[i][j] ==  T ) return true;     vis[d][i][j] = t;     int x, y;     x = i + dirs[d].first;     y = j + dirs[d].second;     if (dfs(x, y, d, t)) return true;     if (t < 2)       for (int k = 0; k < 4; ++k)         if (k != d) {           x = i + dirs[k].first;           y = j + dirs[k].second;           if (dfs(x, y, k, t + 1)) return true;         }     return false;   }   int main() {     memset(vis, -1, sizeof vis);     scanf( %d %d , &n, &m);     int i_s = -1, j_s = -1;     for (int i = 0; i < n; ++i)       for (int j = 0; j < m; ++j) {         scanf(  %c , &grid[i][j]);         if (grid[i][j] ==  S ) {           i_s = i;           j_s = j;         }       }     for (int d = 0; d < 4; ++d)       if (dfs(i_s, j_s, d, 0)) {         printf( YES );         return 0;       }     printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, pos, ans = 10000000000000000;   long long a[3000 + 5], b[3000 + 5], f[3000 + 5][3000 + 5], Min[3000 + 5];   long long read() {     char c;     long long x = 0, f = 1;     c = getchar();     while (c >  9  || c <  0 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     return x * f;   }   signed main() {     n = read();     for (register long long i = 1; i <= n; ++i) a[i] = read() - i, b[i] = a[i];     sort(b + 1, b + n + 1);     pos = unique(b + 1, b + n + 1) - b - 1;     for (register long long i = 1; i <= n; ++i) {       for (register long long j = 1; j <= pos; ++j)         f[i][j] = Min[j] + abs(a[i] - b[j]);       Min[0] = 10000000000000000;       for (register long long j = 1; j <= pos; ++j)         Min[j] = min(Min[j - 1], f[i][j]);     }     for (register long long i = 1; i <= pos; ++i) ans = min(ans, f[n][i]);     printf( %lld , ans);     return 0;   }
#include <bits/stdc++.h>   #define int long long int   #define us unsigned int   #define null 0   #define m_p make_pair   #define f_i first   #define s_e second   #define p_b push_back      using namespace std;         void IOS()   {       ios_base::sync_with_stdio(false);       cin.tie(NULL);   }                  int32_t main()   {       IOS();   int test;   cin>>test;   while(test--)   {       int n;       cin>>n;       string s;       cin>>s;       map<char,int> mp;       bool flag=true;          for(int i=0;i<n;i++)       {           if(mp.find(s[i])==mp.end())           {               mp[s[i]]=i;           }           else if(i-mp[s[i]]>1)           {               flag=false;               break;           }           mp[s[i]]=i;       }          if(flag)       {           cout<< YES <<endl;       }          else       {           cout<< NO <<endl;       }   }      }
#include <bits/stdc++.h>   using namespace std;   const int Y = 10;   int n;   string fcol =   ;   bool place(int y, int x) {     cout << x <<     << y << endl;     string ret;     cin >> ret;     return (ret == fcol);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     cout <<  0   << Y << endl;     cin >> fcol;     bool lastbl = true;     int cx = 0;     int jmp = (1 << 28);     for (int i = 0; i < n - 1; ++i) {       if (lastbl) {         lastbl = place(Y, cx + jmp);         cx += jmp;       } else {         lastbl = place(Y, cx - jmp);         cx -= jmp;       }       jmp /= 2;     }     if (lastbl) {       cout << cx <<     << Y + 1 <<     << cx + 1 <<     << Y - 1 << endl;     } else {       cout << cx <<     << Y + 1 <<     << cx - 1 <<     << Y - 1 << endl;     }     return 0;   }