malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   bool ansnull(int a, int b, int c, int d) {     int ans = 0;     if (a != 0) ++ans;     if (b != 0) ++ans;     if (c != 0) ++ans;     if (d != 0) ++ans;     if (ans >= 2)       return true;     else       return false;   }   int main() {     int a[100010][5];     int n, k;     cin >> n >> k;     for (int i = 0; i <= n; ++i)       for (int j = 1; j <= 4; ++j) a[i][j] = 0;     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= k; ++j) cin >> a[i][j];     vector<int> v(20, 0);     for (int i = 1; i <= n; ++i) {       int sum = 0;       for (int j = 1; j <= 4; ++j) {         sum += a[i][j] * (1 << (4 - j));       }       v[sum]++;     }     if (v[0] != 0) {       cout <<  YES ;       return 0;     }     if (ansnull(v[1], v[2], v[4], v[8])) {       cout <<  YES ;       return 0;     }     int ind = -1;     for (int i = 0; i <= 3; ++i)       if (v[(1 << i)] != 0) ind = (1 << i);     if (ansnull(v[12], v[3], 0, 0)) {       cout <<  YES ;       return 0;     }     if (ansnull(v[6], v[9], 0, 0)) {       cout <<  YES ;       return 0;     }     if (ansnull(v[5], v[10], 0, 0)) {       cout <<  YES ;       return 0;     }     if (ind != -1) {       if (v[15 - ind] != 0) {         cout <<  YES ;         return 0;       }       if (ind == 1) {         if (v[12] != 0 || v[6] != 0 || v[10] != 0) {           cout <<  YES ;           return 0;         }       }       if (ind == 2) {         if (v[12] != 0 || v[9] != 0 || v[5] != 0) {           cout <<  YES ;           return 0;         }       }       if (ind == 4) {         if (v[9] != 0 || v[3] != 0 || v[10] != 0) {           cout <<  YES ;           return 0;         }       }       if (ind == 8) {         if (v[6] != 0 || v[3] != 0 || v[5] != 0) {           cout <<  YES ;           return 0;         }       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a, b, c, k;     cin >> a >> b >> c >> k;     if (k >= a + b + c - 3) {       cout << a * b * c << endl;     } else {       long long res = 1;       for (int x1 = 0; x1 < a; x1++) {         long long help = (-k + x1) / (-2);         for (int n = -1; n < 1; n++) {           long long x2 = min(min(help + n, b - 1), k - x1);           long long x3 = min(k - x1 - x2, c - 1);           res = max(res, (1 + x1) * (1 + x2) * (1 + x3));         }       }       for (int x1 = 0; x1 < a; x1++) {         long long help = (-k + x1) / (-2);         for (int n = -1; n < 1; n++) {           long long x2 = min(min(help + n, c - 1), k - x1);           long long x3 = min(k - x1 - x2, b - 1);           res = max(res, (1 + x1) * (1 + x2) * (1 + x3));         }       }       cout << res << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j;     scanf( %d , &n);     int arr[n];     for (i = 0; i < n; i++) scanf( %d , &arr[i]);     int t = 0;     int index = -1;     for (i = 0; i < n; i++)       if (arr[i] - arr[(i + 1) % n] > 0) {         t++;         index = i;       }     if (t > 1) {       cout <<  -1 n ;       return 0;     }     if (index == -1)       cout <<  0 n ;     else       cout << (n - index - 1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int x, y, z;   };   node q[200001];   int n, m;   bool ok[2][100001];   char s[100005];   int main(void) {     scanf( %d %d , &n, &m);     for (int i = 0; i < 2; ++i) {       scanf( %s , s + 1);       for (int j = 1; j <= n; ++j)         if (s[j] ==  - ) ok[i][j] = true;     }     bool flag = false;     q[1].x = 0;     q[1].y = 1;     q[1].z = 0;     int h = 1, e = 1;     ok[0][1] = false;     while (h <= e) {       node p = q[h];       ++h;       int i = p.x, j = p.y, k = p.z;       if (j <= k) continue;       if ((j + 1 > n) || (j + m > n)) {         flag = true;         break;       }       if (ok[i][j + 1]) {         ++e;         q[e].x = i;         q[e].y = j + 1;         q[e].z = k + 1;         ok[i][j + 1] = false;       }       if (ok[i ^ 1][j + m]) {         ++e;         q[e].x = i ^ 1;         q[e].y = j + m;         q[e].z = k + 1;         ok[i ^ 1][j + m] = false;       }       if (ok[i][j - 1]) {         ++e;         q[e].x = i;         q[e].y = j - 1;         q[e].z = k + 1;         ok[i][j - 1] = false;       }     }     if (flag)       printf( YES n );     else       printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, cnt[2000000];     scanf( %d , &n);     for (int i = 0; i < 2000000; ++i) cnt[i] = 0;     for (int i = 0; i < n; ++i) {       scanf( %d , &t);       cnt[t]++;     }     long long ans = 0;     for (int i = 0; i < 2000000 - 1; ++i) {       cnt[i + 1] += cnt[i] / 2;       if (cnt[i] % 2) ++ans;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   auto random_address = [] {     char *p = new char;     delete p;     return (uint64_t)p;   };   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count() *               (random_address() | 1));   const int INF = 1e9 + 5;   struct edge {     int a, b, color, index;   };   int N, M, K;   vector<edge> edges;   vector<vector<int>> color_count;   void set_color(edge &e, int color) {     color_count[e.a][e.color]--;     color_count[e.b][e.color]--;     e.color = color;     color_count[e.a][e.color]++;     color_count[e.b][e.color]++;   }   bool fix() {     vector<int> minimum(N, INF), maximum(N, 0);     for (int i = 0; i < N; i++)       for (int k = 0; k < K; k++) {         minimum[i] = min(minimum[i], color_count[i][k]);         maximum[i] = max(maximum[i], color_count[i][k]);       }     bool change = false;     for (edge &e : edges)       if ((maximum[e.a] - minimum[e.a] > 2 &&            color_count[e.a][e.color] == maximum[e.a]) ||           (maximum[e.b] - minimum[e.b] > 2 &&            color_count[e.b][e.color] == maximum[e.b])) {         set_color(e, rng() % K);         change = true;       }     return change;   }   int main() {     cin >> N >> M >> K;     color_count.assign(N, vector<int>(K, 0));     for (int i = 0; i < N; i++) {       int _;       cin >> _;     }     edges.resize(M);     for (int i = 0; i < M; i++) {       edge &e = edges[i];       cin >> e.a >> e.b;       e.a--;       e.b--;       e.index = i;       e.color = rng() % K;       color_count[e.a][e.color]++;       color_count[e.b][e.color]++;     }     bool bad;     do {       shuffle(edges.begin(), edges.end(), rng);       bad = false;       while (fix()) bad = true;     } while (bad);     vector<int> answers(M);     for (edge &e : edges) answers[e.index] = e.color + 1;     for (int i = 0; i < M; i++) cout << answers[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   #pragma GCC diagnostic warning  -Wall    int main() {     int n;     scanf( %d , &n);     vector<vector<int> > sec(n);     for (typeof(n) i = (0); i < (n); i++) {       int k;       scanf( %d , &k);       sec[i].resize(k);       for (typeof(k) j = (0); j < (k); j++) scanf( %d , &sec[i][j]);       sort((sec[i]).begin(), (sec[i]).end());     }     int count = 0;     for (typeof(n) i = (0); i < (n); i++) {       int k = int(sec[i].size());       if (not k) continue;       int lasth = sec[i][0];       ;       int l = (i - 1 + n) % n;       int r = (i + 1) % n;       for (typeof(k) j = (1); j < (k); j++) {         int nl = lower_bound((sec[l]).begin(), (sec[l]).end(), sec[i][j]) -                  lower_bound((sec[l]).begin(), (sec[l]).end(), lasth);         int nr = lower_bound((sec[r]).begin(), (sec[r]).end(), sec[i][j]) -                  lower_bound((sec[r]).begin(), (sec[r]).end(), lasth);         if (nl != nr) count++;         lasth = sec[i][j];       }     }     printf( %d n , count);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, g;     cin >> n >> g;     vector<long long> v, ans;     map<long long, long long> m;     map<long long, long long>::iterator it;     for (int i = 0; i < n; i++) {       long long a;       cin >> a;       m[a]++;     }     for (it = m.begin(); it != m.end(); ++it) {       v.push_back(it->second);     }     long long s1 = 0;     for (int i = 0; i < v.size() - 1; i++) {       long long s = 0;       for (int j = i + 1; j < v.size(); j++) {         s += v[j];       }       s1 += s * v[i];     }     cout << s1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     cout << fixed << setprecision(15);     int N, M, S, K;     cin >> N >> M >> S >> K;     vector<int> type(N);     for (int i = 0; i < N; i++) {       cin >> type[i];       --type[i];     }     vector<vector<int>> adj(N);     for (int i = 0; i < M; i++) {       int u, v;       cin >> u >> v;       adj[u - 1].push_back(v - 1);       adj[v - 1].push_back(u - 1);     }     vector<vector<int>> opt(N);     for (int tp = 0; tp < S; tp++) {       vector<int> dist(N, -1);       queue<pair<int, int>> q;       for (int i = 0; i < N; i++) {         if (type[i] == tp) {           q.push({i, 0});           dist[i] = 0;         }       }       while (!q.empty()) {         int loc = q.front().first;         int tot = q.front().second;         q.pop();         for (int nbr : adj[loc]) {           if (dist[nbr] != -1) continue;           dist[nbr] = tot + 1;           q.push({nbr, tot + 1});         }       };       ;       for (int i = 0; i < N; i++) {         opt[i].push_back(dist[i]);       }     }     for (int i = 0; i < N; i++) {       sort((opt[i]).begin(), (opt[i]).end());       int ans = 0;       for (int j = 0; j < K; j++) {         ans += opt[i][j];       }       cout << ans <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int list[n];     int i;     for (i = 0; i < n; i++) cin >> list[i];     int total = accumulate(list, list + n, 0);     n++;     int count = 0;     for (i = 1; i <= 5; i++) {       if ((total + i) % n != 1) {         count++;       }     }     cout << count;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     long long l;     long long r;     long long s;     node* ln;     node* rn;     void change(long long n, long long k) {       if (l == r)         s += k;       else {         if (n <= (l + r) / 2) {           if (ln == 0) {             ln = new node;             *ln = {l, (l + r) / 2, 0};           }           ln->change(n, k);         } else {           if (rn == 0) {             rn = new node;             *rn = {(l + r) / 2 + 1, r, 0};           }           rn->change(n, k);         }         s = 0;         if (ln != 0) s += ln->s;         if (rn != 0) s += rn->s;       }     }     long long query(long long a, long long b) {       if (a == l && b == r) return s;       if (b < l || a > r) return 0;       long long v = 0;       if (ln != 0) v += ln->query(a, min(b, (l + r) / 2));       if (rn != 0) v += rn->query(max(a, (l + r) / 2 + 1), b);       return v;     }   };   int main() {     cin.sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     unordered_map<int, node> m;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       if (!m.count(c)) m[c] = {1, 1 << 30, 0};       if (a == 1)         m[c].change(b, 1);       else if (a == 2)         m[c].change(b, -1);       else         cout << m[c].query(1, b) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int x, y, k;       cin >> x >> y >> k;       long long int tot = y * k + k;       if (x >= tot) {         cout << 1 + k << endl;         continue;       } else if (x == 2) {         cout << tot - 1 + k << endl;       } else {         if ((tot - x) % (x - 1) != 0) {           cout << ((tot - x) / (x - 1)) + 2 + k << endl;         } else {           cout << ((tot - x) / (x - 1)) + 1 + k << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, c[1001], i, x, a, b;   int main() {     cin >> n >> k;     for (int x, i = 1; i <= n; ++i) {       cin >> x;       c[x]++;     }     for (i = 1; i <= k; ++i) {       a = a + c[i] / 2 * 2;       b = b + c[i] % 2;     }     cout << a + (b + 1) / 2;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e6;   const int maxv = 4e5;   const long long INF = 3e14 + 333;   struct Node {     int u, v, c;     void in() { scanf( %d%d%d , &u, &v, &c); }   } wo[maxn];   vector<int> G[maxv], st[maxv], ed[maxv];   int n, m;   int dfn = 0;   int d[maxv][2];   int wd[maxv];   void dfs(int v, int f) {     d[v][0] = dfn;     for (int i = 0; i < G[v].size(); i++) {       int u = G[v][i];       if (u == f) continue;       dfs(u, v);     }     for (int i = 0; i < st[v].size(); i++) wd[st[v][i]] = dfn++;     d[v][1] = dfn;   }   unsigned long long dp[maxn];   unsigned long long val[maxn], add[maxn];   void push(int o, int l, int r) {     if (r - l <= 1 || !add[o]) return;     val[((o << 1))] += add[o];     val[((o << 1) | 1)] += add[o];     add[((o << 1))] += add[o];     add[((o << 1) | 1)] += add[o];     add[o] = 0;   }   void change(int o, int p, int l, int r, unsigned long long x) {     push(o, l, r);     if (r - l <= 1) {       val[o] = x;       return;     }     if (p < ((r + l) >> 1))       change(((o << 1)), p, l, ((r + l) >> 1), x);     else       change(((o << 1) | 1), p, ((r + l) >> 1), r, x);     val[o] = min(val[((o << 1))], val[((o << 1) | 1)]);   }   void Add(int o, int a, int b, int l, int r, unsigned long long x) {     if (a >= r || b <= l) return;     push(o, l, r);     if (l >= a && r <= b) {       val[o] += x;       add[o] += x;       return;     }     Add(((o << 1)), a, b, l, ((r + l) >> 1), x);     Add(((o << 1) | 1), a, b, ((r + l) >> 1), r, x);     val[o] = min(val[((o << 1))], val[((o << 1) | 1)]);   }   unsigned long long rmq(int o, int a, int b, int l, int r) {     if (a >= r || b <= l) return INF;     push(o, l, r);     if (l >= a && r <= b) return val[o];     return min(rmq(((o << 1)), a, b, l, ((r + l) >> 1)),                rmq(((o << 1) | 1), a, b, ((r + l) >> 1), r));   }   unsigned long long ans = 0;   void DP(int v, int f) {     unsigned long long sum = 0;     for (int i = 0; i < G[v].size(); i++) {       int u = G[v][i];       if (u == f) continue;       DP(u, v);       sum += dp[u];     }     for (int i = 0; i < G[v].size(); i++) {       int u = G[v][i];       if (u == f) continue;       Add(1, d[u][0], d[u][1], 0, m, sum - dp[u]);     }     for (int i = 0; i < st[v].size(); i++) {       int w = st[v][i];       change(1, wd[w], 0, m, sum + wo[w].c);     }     for (int i = 0; i < ed[v].size(); i++) {       int w = ed[v][i];       change(1, wd[w], 0, m, INF);     }     if (v == 1) ans = sum;     dp[v] = rmq(1, d[v][0], d[v][1], 0, m);   }   int main() {     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       int x, y;       scanf( %d%d , &x, &y);       G[x].push_back(y);       G[y].push_back(x);     }     for (int i = 0; i < m; i++) {       wo[i].in();       st[wo[i].u].push_back(i);       ed[wo[i].v].push_back(i);     }     for (int i = 0; i < m; i++) change(1, i, 0, m, INF);     dfs(1, -1);     DP(1, -1);     if (ans >= INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-12;   int main() {     int n;     double r, v, T;     scanf( %d%lf%lf , &n, &r, &v);     T = 2 * acos(-1) * r / v;     for (int i = 0; i < n; i++) {       double s, f, tim, tot = 0;       scanf( %lf%lf , &s, &f);       tim = (f - s) / v;       tot = T * floor(tim / T);       tim -= tot;       double lef = 0.0, rig = T;       for (int j = 0; j < 100; j++) {         double t = (lef + rig) / 2.0;         double g = t + (2.0 * r / v) * sin(v * t / (2.0 * r));         if (g - tim >= -eps)           rig = t;         else           lef = t;       }       tot += lef;       printf( %.12lf n , tot);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     int ans = n;     if (k >= n) {       cout << 1;     } else {       for (int i = 2; i <= sqrt(n); i++) {         if (n % i == 0) {           if (i <= k) {             ans = min(ans, n / i);           }           if (n / i <= k) {             ans = min(ans, i);           }         }       }       cout << ans;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int test;     cin >> test;     for (int i = 1; i <= test; i++) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   char c[1010];   int main() {     scanf( %d , &n);     scanf( %s , c + 1);     c[0] =  0 , c[n + 1] =  0 ;     if (n == 1) {       if (c[1] ==  0 ) return 0 * puts( No );       return 0 * puts( Yes );     }     for (int i = 1; i < n; i++) {       if (c[i] ==  1  && c[i + 1] ==  1 ) return 0 * puts( No );     }     for (int i = 1; i <= n; i++) {       if (c[i - 1] ==  0  && c[i] ==  0  && c[i + 1] ==  0 )         return 0 * puts( No );     }     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       int arr[n];       int o, e;       o = e = 0;       int i = 0;       for (int j = 0; j < 10; j++) {       }       for (int j = 0; j < 10; j++) {       }       for (int j = 0; j < 10; j++) {       }       while (i < n) {         int x;         cin >> x;         if (x % 2 == 0) {           e++;         } else           o++;         i++;       }       if (o == 0)         cout <<  No  << endl;       else {         bool pos = false;         i = 1;         while (i <= o) {           if (i > x) break;           if ((x - i) <= e) {             pos = true;             break;           }           i = i + 2;         }         if (!pos)           cout <<  No  << endl;         else           cout <<  Yes  << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, mx = 0;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a;       if (a > mx) mx = a;     }     if (mx - 25 > 0)       cout << mx - 25 << endl;     else       cout << 0 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, dp[25][1100000], ans = 1e9;   char num[25][100005];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) scanf( %s , num[i] + 1);     for (int i = 1; i <= m; ++i) {       int t = 0;       for (int j = 1; j <= n; ++j) t = t * 2 + num[j][i] -  0 ;       ++dp[0][t];     }     for (int i = 1; i <= n; ++i)       for (int j = 0; j < 1 << n; ++j) {         for (int k = 1; k < 1 << n; k <<= 1)           dp[i][j] = dp[i][j] + dp[i - 1][j ^ k];         if (i >= 2) dp[i][j] = dp[i][j] + (i - 2 - n) * dp[i - 2][j];         dp[i][j] /= i;       }     for (int i = 1; i < 1 << n; ++i) {       int t = 0;       for (int j = 0; j <= n; ++j) t += min(j, n - j) * dp[j][i];       ans = min(ans, t);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long c, w, v, a, l, pages, days = 1;     cin >> c >> v >> w >> a >> l;     pages = v;     while (pages < c) {       v += a;       if (v > w) v = w;       pages = pages - l + v;       days++;     }     cout << days;   }
#include <bits/stdc++.h>   using namespace std;   int n, k, x, y;   struct node {     int L, R, e;     long long int Lsum, Rsum, Ls, Rs;     int mid() { return (L + R) / 2; }   } a[200005 * 4];   void BuildTree(int r, int L, int R) {     a[r].L = L;     a[r].R = R;     a[r].e = 0;     a[r].Lsum = 0;     a[r].Rsum = 0;     a[r].Ls = 0;     a[r].Rs = 0;     if (L == R) return;     BuildTree(r << 1 | 1, L, a[r].mid());     BuildTree(r << 1, a[r].mid() + 1, R);     a[r].Lsum = a[r << 1 | 1].Lsum + a[r << 1].Lsum;     a[r].Rsum = a[r << 1 | 1].Rsum + a[r << 1].Rsum;     a[r].Ls = a[r << 1 | 1].Ls + a[r << 1].Ls;     a[r].Rs = a[r << 1 | 1].Rs + a[r << 1].Rs;   }   void Update(int r, int L, int v) {     if (a[r].L == a[r].R && a[r].L == L) {       int kk = a[r].e;       a[r].e += v;       if (a[r].e >= y && kk < y) {         a[r].Lsum++;         a[r].Ls -= kk;       }       if (a[r].e >= x && kk < x) {         a[r].Rs -= kk;         a[r].Rsum++;       }       if (a[r].e < y) a[r].Ls = a[r].e;       if (a[r].e < x) a[r].Rs = a[r].e;       return;     }     if (L > a[r].mid())       Update(r << 1, L, v);     else       Update(r << 1 | 1, L, v);     a[r].Lsum = a[r << 1 | 1].Lsum + a[r << 1].Lsum;     a[r].Rsum = a[r << 1 | 1].Rsum + a[r << 1].Rsum;     a[r].Ls = a[r << 1 | 1].Ls + a[r << 1].Ls;     a[r].Rs = a[r << 1 | 1].Rs + a[r << 1].Rs;   }   long long int Qurry(int r, int L, int R, int b) {     if (L > R) return 0;     if (a[r].L == L && a[r].R == R) {       if (b == 1)         return a[r].Lsum * y + a[r].Ls;       else if (b == 2)         return a[r].Rsum * x + a[r].Rs;     }     if (L > a[r].mid())       return Qurry(r << 1, L, R, b);     else if (R <= a[r].mid())       return Qurry(r << 1 | 1, L, R, b);     else {       long long a1 = Qurry(r << 1 | 1, L, a[r].mid(), b);       long long a2 = Qurry(r << 1, a[r].mid() + 1, R, b);       return a1 + a2;     }   }   int main() {     int q;     while (scanf( %d , &n) != EOF) {       memset(a, 0, sizeof(0));       int u, v;       BuildTree(1, 1, n);       scanf( %d %d %d %d , &k, &x, &y, &q);       while (q--) {         int kk;         scanf( %d , &kk);         if (kk == 1) {           scanf( %d %d , &u, &v);           Update(1, u, v);         } else {           scanf( %d , &u);           long long int sum1 = Qurry(1, 1, u - 1, 1);           long long int sum2 = Qurry(1, u + k, n, 2);           printf( %lld n , sum1 + sum2);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1000000007;   const long long BIG = 1446803456761533460LL;   const int Big = 336860180;   const long long int INF = LONG_LONG_MAX;   const long long int adj4[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};   const long long int adj8[8][2] = {{0, 1},   {0, -1}, {1, 0},  {-1, 0},                                     {-1, -1}, {1, -1}, {-1, 1}, {1, 1}};   long long int clk_ar[10];   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int powMod(long long int a, long long int b) {     long long int n = 1;     long long int p = a;     while (b > 0) {       if (b % 2 == 1) {         n *= p;         n %= MOD;       }       p *= p;       p %= MOD;       b /= 2;     }     return n;   }   long long int modularInverse(long long int a) { return powMod(a, MOD - 2); }   stringstream sss;   const long long int maxn = 150010;   const long long int maxm = 310;   long long int dp[2][maxn];   long long int ts[maxm];   long long int ai[maxm];   void MAIN() {     long long int n, m, V;     cin >> n >> m >> V;     long long int sb = 0;     for (long long int i = 0; i < (m); ++i) {       long long int b;       cin >> ai[i + 1] >> b >> ts[i + 1];       --ai[i + 1];       sb += b;     }     for (long long int i = (1); i < (m + 1); ++i) {       long long int d = (ts[i] - ts[i - 1]) * V;       deque<long long int> q;       for (long long int j = 0; j < (min(d, n)); ++j) {         while (!q.empty() && dp[i & 1 ^ 1][j] >= dp[i & 1 ^ 1][q.back()]) {           q.pop_back();         }         q.push_back(j);       }       for (long long int j = 0; j < (n); ++j) {         if (j + d < n) {           while (!q.empty() && dp[i & 1 ^ 1][j + d] >= dp[i & 1 ^ 1][q.back()]) {             q.pop_back();           }           q.push_back(j + d);         }         dp[i & 1][j] = dp[i & 1 ^ 1][q.front()] - abs(j - ai[i]);         if (q.front() == j - d) {           q.pop_front();         }       }     }     cout << (sb + *max_element(dp[m & 1], dp[m & 1] + n)) <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout << fixed << setprecision(10);     sss << R (   50 3 1   49 1 1   26 1 4   6 1 10       ) ;     MAIN();     return 0;   }