malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long num[200000];   int sn = 0, asn = 0, save[200000], as[200000], m, n;   struct str {     int v, x;     long long l, c;   } str[200000];   void pre1() {     scanf( %d , &m);     int i, j;     for (i = 0; i < m; i++) {       scanf( %I64d , &str[i].v);       if (str[i].v == 1) {         scanf( %I64d , &str[i].x);       } else         scanf( %I64d%I64d , &str[i].l, &str[i].c);     }     scanf( %d , &n);     for (j = 0; j < n; j++) scanf( %I64d , &num[j]);   }   void table() {     int i, k, j;     for (i = 0; i < m; i++) {       if (str[i].v == 1) {         save[sn++] = str[i].x;         if (sn == 100000) return;       } else {         for (k = 0; k < str[i].c; k++) {           for (j = 0; j < str[i].l; j++) {             save[sn++] = save[j];             if (sn == 100000) return;           }         }       }     }   }   void work1() {     table();     int j = 0, i = 0;     long long now = 0;     while (i < n) {       while (j < m) {         if (str[j].v == 1) {           now++;           if (now == num[i]) {             as[asn++] = str[j].x;             i++;             if (i >= n) return;             j++;             break;           }           j++;         } else {           long long nn = now;           now += str[j].l * str[j].c;           if (now >= num[i]) {             while (i < n) {               if (num[i] <= now) {                 as[asn++] = save[(num[i++] - nn - 1) % str[j].l % 100000];                 if (i >= n) return;               } else {                 j++;                 break;               }             }           } else {             j++;           }         }       }     }   }   int main() {     pre1();     work1();     for (int i = 0; i < asn - 1; i++) printf( %d  , as[i]);     printf( %d n , as[asn - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void setIO() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   const long long N = 3e2 + 0;   const long long M = 5e5 + 5;   const long long L = 2e1 + 1;   const long long inf = 9e17;   const long long mod = 1e9 + 7;   long long xyz = 1;   long long n, k;   long long dp[N][N];   long long fac[N];   long long inv[N];   long long chs[N][N];   long long pwr[2][N];   long long bin(long long b, long long e) {     return b == k ? pwr[0][e] : pwr[1][e];   }   long long cal(long long b, long long e) {     if (e == 0) return 1;     if (e == 1) return b;     if (e == 2) return b * b % mod;     return cal(cal(b, e / 2), 2) * cal(b, e % 2) % mod;   }   void prc(long long n, long long k) {     chs[n][k] = fac[n] * inv[k] % mod * inv[n - k] % mod;   }   void cmp(long long b, long long e) {     if (b == k - 0) {       pwr[0][e] = cal(b, e);     }     if (b == k - 1) {       pwr[1][e] = cal(b, e);     }   }   long long ncr(long long n, long long k) { return chs[n][k]; }   void run() {     cin >> n >> k;     fac[0] = 1;     inv[0] = 1;     for (long long i = 1; i <= n; i++) {       fac[i] = fac[i - 1] * i % mod;       inv[i] = inv[i - 1] * cal(i, mod - 2) % mod;     }     for (long long i = 0; i <= n; i++)       for (long long j = 0; j <= i; j++) prc(i, j);     for (long long i = 0; i <= n; i++) cmp(k, i), cmp(k - 1, i);     for (long long i = 1; i <= n; i++)       dp[1][i] = ncr(n, i) * bin(k - 1, n - i) % mod;     for (long long i = 2; i <= n; i++) {       for (long long j = 1; j <= n; j++) {         dp[i][j] = (bin(k, j) - bin(k - 1, j) + mod) * bin(k - 1, n - j) % mod *                    dp[i - 1][j] % mod;         for (long long x = 1; x < j; x++) {           dp[i][j] += bin(k - 1, n - j) * bin(k, x) % mod * ncr(n - x, j - x) %                       mod * dp[i - 1][x] % mod;           dp[i][j] %= mod;         }       }     }     cout << dp[n][n] << endl;   }   signed main() {     setIO();     while (xyz--) run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int odd[2000], even[2000];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n * n; i += 2) {       odd[(i - 1) / 2] = i;     }     for (int i = 2; i <= n * n; i += 2) {       even[i / 2 - 1] = i;     }     int i = 0, k = 0;     if (n == 3) {       cout <<  2 1 4 n ;       cout <<  3 5 7 n ;       cout <<  6 9 8 n ;       return 0;     }     for (int x = 0; x < n; x++) {       for (int y = 0; y < n; y++) {         if ((n - 1) % 4 == 0) {           if (x == y) {             cout << odd[i++] <<    ;             continue;           }           if ((x < n / 2 && y > n / 2) || (x > n / 2 && y < n / 2)) {             cout << odd[i++] <<    ;             continue;           }         } else {           if (y < n / 2) {             cout << odd[i++] <<    ;             continue;           }           if ((x == 0 && y < n - 2) || (x == 2 && y >= n - 2)) {             cout << odd[i++] <<    ;             continue;           }         }         cout << even[k++] <<    ;       }       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e3 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9,                   inf = 1e18 + 7;   const long long infll = 1e18 + 7;   long long n, k, X, Y, Z;   long long a[(long long)3e5 + 5];   long long dp[N][N];   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> k;     Y = n % k;     X = k - Y;     Z = n / k;     for (long long i = 1; i <= n; i++) {       cin >> a[i];     }     sort(a + 1, a + 1 + n);     for (long long i = 0; i <= X; i++) {       for (long long j = 0; j <= Y; j++) {         if (i == 0 && j == 0) {           dp[i][j] = 0;           continue;         }         dp[i][j] = inf;         long long t = i * Z + j * (Z + 1);         if (i) {           dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[t] - a[t - Z + 1]);         }         if (j) {           dp[i][j] = min(dp[i][j], dp[i][j - 1] + a[t] - a[t - Z]);         }       }     }     cout << dp[X][Y];   }
#include <bits/stdc++.h>   using namespace std;   int a[100][100];   int main() {     int n, m, z, sum, sum2, ans = 1e9, temp;     scanf( %d %d %d , &n, &m, &z);     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) scanf( %d , &a[i][j]);     if (n > 10)       for (int i = 0; i < n; i++) {         temp = 0;         for (int j = 0; j < n; j++)           if (i != j) {             sum = sum2 = 0;             for (int k = 0; k < m; k++) {               sum += (a[i][k] == a[j][k]);               sum2 += (a[i][k] != a[j][k]);             }             temp += min(sum, sum2);           }         ans = min(ans, temp);       }     else {       for (int i = 0; i < 1 << n; i++) {         temp = 0;         for (int j = 0; j < m; j++) {           sum = sum2 = 0;           for (int k = 0; k < n; k++) {             sum += (a[k][j] == ((i >> k) & 1));             sum2 += (a[k][j] != ((i >> k) & 1));           }           temp += min(sum, sum2);         }         ans = min(ans, temp);       }     }     printf( %d n , ans > z ? -1 : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n;     cin >> n;     vector<long long> arr(n);     for (long long i = 0; i < n; ++i) {       cin >> arr[i];     }     sort(arr.begin(), arr.end());     long long grp = 0;     long long ptr = 0;     unordered_map<long long, long long> mp;     long long last = 0;     for (long long i = 0; i < n; ++i) {       if (arr[i] == 1) {         grp++;         continue;       } else if (ptr > 0) {         ptr--;         if (ptr == 0 && arr[i] == arr[i - 1]) {           grp++;         } else {           ptr = arr[i] - (i - last + 1);         }       } else {         ptr = arr[i] - 1;         last = i;       }     }     cout << grp <<   n ;   }   int32_t main() {     long long t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[100005];   void solve() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     vector<long long> ans;     long long st = 0, end = n - 1;     while (end > st) {       ans.push_back(a[end]);       ans.push_back(a[st]);       st++;       end--;     }     if (st == end) {       ans.push_back(a[st]);     }     reverse((ans).begin(), (ans).end());     for (auto i : ans) {       cout << i <<    ;     }   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   int n, v[200000], m[200000];   long long s[200000];   pair<int, int> p[200000];   unordered_map<int, vector<pair<int, long long> > > mp;   bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &p[i].second, &p[i].first);     sort(p, p + n, cmp);     for (int i = 0; i < n; i++) {       int lo = 0;       int hi = i - 1;       int j = -1;       while (lo <= hi) {         int mid = (lo + hi) / 2;         if (p[mid].second <= p[i].first) {           lo = mid + 1;           j = mid;         } else           hi = mid - 1;       }       if (j > -1) {         v[i] = m[j] + p[i].second - p[i].first;         int lo = 0;         int hi = mp[m[j]].size() - 1;         int k = -1;         while (lo <= hi) {           int mid = (lo + hi) / 2;           if (mp[m[j]][mid].first <= j) {             k = mid;             lo = mid + 1;           } else             hi = mid - 1;         }         if (k > -1)           s[i] = mp[m[j]][k].second;         else           s[i] = 1LL;         if (mp[v[i]].size() == 0)           mp[v[i]].push_back({i, s[i]});         else           mp[v[i]].push_back({i, (mp[v[i]].back().second + s[i]) % mod});       } else {         v[i] = p[i].second - p[i].first;         s[i] = 1LL;         if (mp[v[i]].size() == 0)           mp[v[i]].push_back({i, 1LL});         else           mp[v[i]].push_back({i, (mp[v[i]].back().second + 1LL) % mod});       }       m[i] = max(i > 0 ? m[i - 1] : 0, v[i]);     }     int h = p[n - 1].second - v[n - 1];     int lo = p[n - 1].first;     long long res = 0;     for (int i = n - 1; i >= 0; i--) {       if (p[i].second <= lo) break;       if (h > p[i].second - v[i]) {         h = p[i].second - v[i];         res = s[i];       } else if (h == p[i].second - v[i])         res = (res + s[i]) % mod;       lo = max(lo, p[i].first);     }     cout << (res % mod) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int in() {     int32_t x;     scanf( %d , &x);     return x;   }   inline long long lin() {     long long x;     scanf( %lld , &x);     return x;   }   inline int mul(int a, int b) {     long long x = a;     x *= (long long)b;     if (x >= 1000000007) x %= 1000000007;     return x;   }   inline int add(int a, int b) {     return (a + b) >= 1000000007 ? a + b - 1000000007 : a + b;   }   inline int sub(int a, int b) {     return (a - b) < 0 ? 1000000007 - b + a : a - b;   }   const int MAX = INT_MAX;   const int MIN = INT_MIN;   char c[100005];   int y[100005];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> c[i];     int d = 0, d1 = 0;     for (int i = 0; i < n; i++) {       y[i] = c[i] -  0 ;       if (y[i] == 1) d++;       if (y[i] == 0) d1++;     }     int f = 1;     int f2 = 0;     for (int i = 1; i < n; i++) {       if (y[i - 1] != y[i]) f++;     }     for (int i = 0; i < n - 1; i++) {       if (y[i] == y[i + 1]) {         f2 = 1;         break;       }     }     cout << min(f + 2, n);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int ans[] = {0,  4,         10,        20,        35,       56,                      83, 350 - 234, 400 - 245, 450 - 252, 500 - 256};   int main() {     int n;     cin >> n;     if (n <= 10)       cout << ans[n] << endl;     else       cout << 1LL * n * 50 - n - 247 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, last;   struct rec {     int s, t;   } da[50100];   bool cmp(rec a, rec b) {     if (a.s < b.s) return true;     if (a.s > b.s) return false;     if (a.t < b.t) return true;     return false;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , &da[i].s, &da[i].t);     sort(da + 1, da + n + 1, cmp);     for (int i = 1; i <= n; i++)       if (da[i].t >= last) {         last = da[i].t;       } else         last = da[i].s;     printf( %d , last);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N;   long long A[10], rem[10];   int totnum, numv[10], pos[10], tat[10];   int result = 0x3f3f3f3f;   inline bool compare(const int& i1, const int& i2) {     return numv[i1] > numv[i2];   }   void Back(int x) {     if (x == N + 1) {       int num0 = 0;       for (int i = 1; i <= N; ++i)         if (tat[i] == 0) ++num0;       int resnow = (num0 >= 2) + N + totnum;       for (int i = 1; i <= N; ++i)         if (tat[i] != 0) resnow -= numv[pos[i]];       result = min(result, resnow);       return;     }     for (int i = 0; i <= x - 1; ++i)       if (i == 0 || rem[pos[i]] % A[pos[x]] == 0) {         rem[pos[i]] /= A[pos[x]];         tat[x] = i;         Back(x + 1);         rem[pos[i]] *= A[pos[x]];       }   }   int main() {     cin >> N;     for (int i = 1; i <= N; ++i) {       cin >> A[i];       long long aux = A[i];       for (int j = 2; 1LL * j * j <= aux; ++j)         while (aux % j == 0) {           ++numv[i];           aux /= j;         }       if (aux != 1) ++numv[i];       totnum += numv[i];       if (numv[i] == 1) --totnum;       pos[i] = i;       rem[i] = A[i];     }     sort(pos + 1, pos + N + 1, compare);     Back(1);     cout << result <<   n ;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const int SZ = 110;   const int INF = 1000 * 1000 * 1000;   double start, finish;   void prepare(string s) {     if ((int)s.size() != 0) {       freopen((s +  .in ).c_str(),  r , stdin);       freopen((s +  .out ).c_str(),  w , stdout);     }   }   void startTimer() {}   void stopTimer() {}   int n;   vector<int> g;   vector<vector<int> > p;   void getData() {     cin >> n;     g.resize(n);     for (int i = 0; i < n; ++i) {       cin >> g[i];     }     p.resize(n);     for (int i = 0; i < n; ++i) {       p[i].resize(g[i]);       for (int j = 0; j < g[i]; ++j) {         cin >> p[i][j];       }     }   }   void solve() {     int ans = INF;     g.assign(n, 0);     for (int i = 0; i < n; ++i) {       int cnt = 0;       for (int j = 0; j < (int)p[i].size(); ++j) {         cnt += p[i][j] * 5 + 15;       }       ans = min(ans, cnt);     }     cout << ans << endl;   }   int main() {     prepare(  );     ios::sync_with_stdio(false);     startTimer();     getData();     solve();     stopTimer();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void RI() {}   template <typename... T>   void RI(int& head, T&... tail) {     scanf( %d , &head);     RI(tail...);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     RI(n);     cout <<  YES  << endl;     while (n--) {       int x1, y1, x2, y2;       RI(x1, y1, x2, y2);       cout << (((x1 & 1) << 1) + (y1 & 1) + 1) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool point[2002][2002];   int N;   int x[3000], y[3000];   const int offset = 1001;   int main() {     while (scanf( %d , &N) != EOF) {       memset(point, 0, sizeof point);       for (int i = 0; i < N; ++i) {         scanf( %d%d , &x[i], &y[i]);         point[x[i] + offset][y[i] + offset] = true;       }       int tot = 0;       for (int i = 0; i < N; ++i) {         for (int j = i + 1; j < N; ++j) {           if (((x[i] + x[j]) & 1) == 1 || ((y[i] + y[j]) & 1) == 1) continue;           int mx = (x[i] + x[j]) >> 1;           int my = (y[i] + y[j]) >> 1;           if (point[mx + offset][my + offset]) ++tot;         }       }       printf( %d n , tot);     }   }
#include <bits/stdc++.h>   using namespace std;   int head[(1000 + 10)], to[(1000 + 10) * (1000 + 10)],       pre[(1000 + 10) * (1000 + 10)], tot;   bool vis[(1000 + 10)], color[(1000 + 10)];   int tag[(1000 + 10)], cc, L[(1000 + 10)], dis[(1000 + 10)];   int n, m;   void adde(int u, int v) { to[++tot] = v, pre[tot] = head[u], head[u] = tot; }   void dfs(int u) {     tag[u] = cc;     for (int i = head[u]; i; i = pre[i]) {       int v = to[i];       if (vis[v]) {         if (color[u] == color[v]) {           printf( -1 );           exit(0);         } else           continue;       }       vis[v] = 1, color[v] = 1 ^ color[u];       dfs(v);     }   }   void bfs(int u) {     memset(dis, 0xff, sizeof(dis));     dis[u] = 0;     int& res = L[tag[u]];     queue<int> Q;     Q.push(u);     while (!Q.empty()) {       int v = Q.front();       Q.pop();       for (int i = head[v]; i; i = pre[i]) {         int vv = to[i];         if (dis[vv] != -1) continue;         dis[vv] = dis[v] + 1;         Q.push(vv);         res = max(res, dis[vv]);       }     }   }   int main() {     scanf( %d %d , &n, &m);     while (m--) {       int u, v;       scanf( %d %d , &u, &v);       adde(u, v), adde(v, u);     }     for (int i = 1; i <= n; i++) {       if (!vis[i]) {         vis[i] = 1;         cc++;         dfs(i);       }     }     for (int i = 1; i <= n; i++) bfs(i);     int ans = 0;     for (int i = 1; i <= cc; i++) ans += L[i];     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const long long INF = 1e18;   const long long LIMIT = 1500000LL * 1500000LL;   vector<int> V;   int ans[MAXN];   struct node {     long long x, y, pos;     long long dis() { return x * x + y * y; }   };   node p[MAXN];   bool cmp(node A, node B) { return A.dis() > B.dis(); }   node operator+(const node &A, const node &B) {     node ans = A;     ans.x += B.x;     ans.y += B.y;     return ans;   }   node operator-(const node &A, const node &B) {     node ans = A;     ans.x -= B.x;     ans.y -= B.y;     return ans;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y, p[i].pos = i;     node cur{0, 0, 0};     for (int i = n - 1; i >= 0; i--) {       if (cmp(cur - p[i], cur + p[i]))         cur = cur + p[i], ans[i] = 1;       else         cur = cur - p[i], ans[i] = -1;     }     for (int i = 0; i < n; i++) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   const int N = 120005;   int n, p[N], m;   int stack1[N], top1, stack2[N], top2;   struct query {     int l, r, id;   } q[N];   bool operator<(query a, query b) { return a.r < b.r; }   int min[N << 2], num[N << 2], tag0[N << 2], tag1[N << 2];   long long sum[N << 2], ans[N];   void build(int o = 1, int l = 1, int r = n) {     min[o] = l, num[o] = 1;     if (l == r) return;     int mid = l + r >> 1;     build(o << 1, l, mid), build(o << 1 | 1, mid + 1, r);   }   void settag0(int o, int v) { tag0[o] += v, min[o] += v; }   void settag1(int o, int v) { sum[o] += (long long)v * num[o], tag1[o] += v; }   void pushdown(int o) {     if (tag0[o])       settag0(o << 1, tag0[o]), settag0(o << 1 | 1, tag0[o]), tag0[o] = 0;     if (tag1[o]) {       if (min[o] == min[o << 1]) settag1(o << 1, tag1[o]);       if (min[o] == min[o << 1 | 1]) settag1(o << 1 | 1, tag1[o]);       tag1[o] = 0;     }   }   void pushup(int o) {     min[o] = std::min(min[o << 1], min[o << 1 | 1]);     num[o] = 0;     if (min[o] == min[o << 1]) num[o] += num[o << 1];     if (min[o] == min[o << 1 | 1]) num[o] += num[o << 1 | 1];     sum[o] = sum[o << 1] + sum[o << 1 | 1];   }   void modify(int L, int R, int v, int o = 1, int l = 1, int r = n) {     if (L <= l && R >= r) return settag0(o, v);     int mid = l + r >> 1;     pushdown(o);     if (L <= mid) modify(L, R, v, o << 1, l, mid);     if (R > mid) modify(L, R, v, o << 1 | 1, mid + 1, r);     pushup(o);   }   long long query(int L, int o = 1, int l = 1, int r = n) {     if (L == l) return sum[o];     int mid = l + r >> 1;     pushdown(o);     if (L <= mid)       return query(L, o << 1, l, mid) + sum[o << 1 | 1];     else       return query(L, o << 1 | 1, mid + 1, r);   }   int main() {     std::ios::sync_with_stdio(0), std::cin.tie(0);     std::cin >> n;     for (int i = 1; i <= n; ++i) std::cin >> p[i];     std::cin >> m;     for (int i = 0; i < m; ++i) std::cin >> q[i].l >> q[i].r, q[i].id = i;     build(), std::sort(q, q + m);     int t = 0;     for (int i = 1; i <= n; ++i) {       while (top1 && p[stack1[top1]] < p[i])         modify(stack1[top1 - 1] + 1, stack1[top1], p[i] - p[stack1[top1]]),             --top1;       while (top2 && p[stack2[top2]] > p[i])         modify(stack2[top2 - 1] + 1, stack2[top2], p[stack2[top2]] - p[i]),             --top2;       stack1[++top1] = stack2[++top2] = i, settag1(1, 1);       while (t < m && q[t].r == i) ans[q[t].id] = query(q[t].l), ++t;     }     for (int i = 0; i < m; ++i) std::cout << ans[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long isqrt(long long k) {     long long r = sqrt(k) + 1;     while (r * r > k) r--;     return r;   }   inline long long icbrt(long long k) {     long long r = cbrt(k) + 1;     while (r * r * r > k) r--;     return r;   }   inline long long mnz(long long& a, long long b) { return a = (a > b ? b : a); }   inline long long mxz(long long& a, long long b) { return a = (a < b ? b : a); }   inline string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   double const eps = 1e-6;   long long const Base = 1e9 + 7, oo = 1e17, MAXN = 1e6;   long long A[MAXN + 5];   long long Solves() {     long long n, m, k, cnt = 0, ans = 0, x, y, q, c, sum = 0, v, t;     string s;     cin >> s;     for (long long i = 0; i + 1 <= s.length(); i++)       if (i and s[i] != s[i - 1]) ans = 1;     if (!ans) return cout << s << endl, 0;     for (long long i = 0; i + 1 <= s.length(); i++) {       if (s[i] == ans +  0 )         cout << (char)(ans +  0 );       else {         cout << (char)(ans +  0 );         cout << s[i];         ans = s[i] -  0 ;       }       ans ^= 1;     }     cout <<    << endl;     return 0;   }   int main() {     if (fopen( locin.txt ,  r )) freopen( locin.txt ,  r , stdin);     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long test = 1;     cin >> test;     for (long long T = 1; T <= test; T++) {       Solves();     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2005;   int n;   long long dp[N], a[N], ans, k, l[N], r[N];   int main() {     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; ++i) scanf( %lld%lld%lld , l + i, r + i, a + i);     int flag = 0;     for (int i = n; i >= 1; --i) {       if (r[i] == l[i + 1])         dp[i] = max((long long)0, a[i] + dp[i + 1] - (r[i] - l[i]) * k);       else         dp[i] = max((long long)0, a[i] - (r[i] - l[i]) * k);       if (dp[i] > k) {         flag = 1;         break;       }     }     if (flag) {       printf( -1 n );       return 0;     }     long long tmp = k;     for (int i = 1; i <= n; ++i) {       if (tmp < dp[i]) ans += tmp, tmp = k;       ans += a[i];       if (a[i] >= tmp)         a[i] -= tmp, tmp = k - a[i] % k;       else         tmp -= a[i];     }     printf( %lld n , ans);     return 0;   }