malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int Max(int x, int y, int z) { return max(max(x, y), z); }   const int N = 100005;   int n, m;   char s[N];   long long f[N][10];   int st[3], to[3];   long long ans;   inline int R(int b, int a[3]) {     if (a[1] != b && a[1] != b - 1) return 8;     int x = (a[1] < b ? 0 : 1);     int y = a[1] - a[0];     if (y != 0 && y != 1) return 8;     int z = a[2] - a[1];     if (z != 0 && z != 1) return 8;     return x + (y << 1) + (z << 2);   }   inline void T(int b, int S, int a[3]) {     int x = S & 1;     int y = S >> 1 & 1;     int z = S >> 2 & 1;     a[1] = (!x ? b - 1 : b);     a[0] = a[1] - y;     a[2] = a[1] + z;   }   inline void G(int b, char c) {     to[0] = max(st[1], st[0] + (c == s[b]));     to[1] = Max(to[0], st[2], st[1] + (c == s[b + 1]));     to[2] = max(to[1], st[2] + (c == s[b + 2]));   }   int main(void) {     scanf( %d %d , &n, &m);     scanf( %s , s + 1);     if (n <= 1) return printf( %d n , m - 1), 0;     if (s[1] == s[2]) {       st[0] = 0, st[1] = 0, st[2] = 0, f[1][R(1, st)] = m - 1;       st[0] = 0, st[1] = 1, st[2] = 1, f[1][R(1, st)] = 1;     } else {       st[0] = 0, st[1] = 0, st[2] = 0, f[1][R(1, st)] = m - 2;       st[0] = 0, st[1] = 1, st[2] = 1, f[1][R(1, st)] = 1;       st[0] = 0, st[1] = 0, st[2] = 1, f[1][R(1, st)] = 1;     }     for (register int i = (1), _b = (n - 1); i <= _b; i++)       for (register int S = (0), _b = (7); S <= _b; S++)         if (f[i][S] != 0) {           T(i, S, st);           for (register int j = (1), _b = (m); j <= _b; j++) {             G(i,  a  + j - 1);             f[i + 1][R(i + 1, to)] += f[i][S];           }         }     for (register int S = (0), _b = (7); S <= _b; S++)       if (f[n][S] != 0) {         T(n, S, st);         if (st[1] == n - 1) ans += f[n][S];       }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void frepn() {     freopen(                     .in ,          r , stdin);     freopen(                     .out ,          w , stdout);   }   const int N = 50500;   const long long INF = (1e17) + 777;   const int mod = (1e9) + 7;   int n, a[N], k, t;   int ans, ans2, ans3, ans4;   int main() {     ios_base::sync_with_stdio(0);     ;     cin >> n >> k >> t;     ans = k * t;     for (int i = 1; i <= n; i++) {       cin >> a[i];       ans4 += a[i];     }     sort(a + 1, a + 1 + n);     for (int i = n - k; i <= n; i++) {       ans2 += a[i];     }     for (int i = 1; i <= n - k; i++) {       ans3 += a[i];     }     if (ans2 < ans)       cout << ans4;     else       cout << ans3 + ans;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   typedef long long ll;   const int MAXN=1e9+1;   const ll mod=1e9+7;      int main(){       ios_base::sync_with_stdio(false);       cin.tie(NULL);       cout.tie(NULL);        int n,m,k;       cin>>n>>m>>k;       int hori[n][m-1];       for(int i=0;i<n;i++){           for(int j=0;j<m-1;j++){               cin>>hori[i][j];           }       }       int verti[n-1][m];       for(int i=0;i<n-1;i++){           for(int j=0;j<m;j++){               cin>>verti[i][j];           }       }       if(k%2!=0){           for(int i=0;i<n;i++){               for(int j=0;j<m;j++)cout<< -1  ;               cout<<endl;           }           return 0;       }       k/=2;       int dp[n][m][k+1];       for(int i=0;i<n;i++){           for(int j=0;j<m;j++){               for(int step=0;step<=k;step++)dp[i][j][step]=MAXN;           }       }       for(int i=0;i<n;i++){           for(int j=0;j<m;j++)dp[i][j][0]=0;       }       for (int step = 0; step < k; step++) {               for (int i = 0; i < n; i++) {                   for (int j = 0; j < m; j++) {                       if (i > 0) dp[i - 1][j][step + 1] = min(dp[i - 1][j][step + 1], dp[i][j][step] + verti[i-1][j]);                       if (i < n - 1) dp[i + 1][j][step + 1] = min(dp[i + 1][j][step + 1], dp[i][j][step] + verti[i][j]);                       if (j > 0) dp[i][j - 1][step + 1] = min(dp[i][j - 1][step + 1], dp[i][j][step] + hori[i][j-1]);                       if (j < m - 1) dp[i][j + 1][step + 1] = min(dp[i][j + 1][step + 1], dp[i][j][step] + hori[i][j]);                   }               }           }       for(int i=0;i<n;i++){           for(int j=0;j<m;j++){               cout<<(2*dp[i][j][k])<<   ;           }           cout<<endl;       }              return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   const int N = 110;   int Sqr(int x) { return x * x; }   int sum[N][N][N];   int n, m;   int vis[N][N], f[N][N];   int dp(int l, int r) {     if (l + 1 >= r) return 0;     if (vis[l][r]) return f[l][r];     vis[l][r] = 1;     int res = 0;     for (int k = l + 1; k < r; ++k) {       res = max(res, Sqr(sum[k][l][r]) + dp(l, k) + dp(k, r));     }     return f[l][r] = res;   }   int main() {     rd(n), rd(m);     for (int i = 1; i <= n; ++i) {       int t, l, r;       rd(t);       while (t--) {         rd(l), rd(r);         for (int j = l; j <= r; ++j) sum[j][l - 1][r + 1]++;       }     }     for (int i = 1; i <= m; ++i) {       for (int j = i - 1; j >= 0; --j)         for (int k = i + 1; k <= m + 1; ++k)           sum[i][j][k] +=               sum[i][j + 1][k] + sum[i][j][k - 1] - sum[i][j + 1][k - 1];     }     printf( %d , dp(0, m + 1));     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( avx,avx2,fma )   #pragma GCC optimization( unroll-loops )   long long int power(long long int x, long long int n) {     long long int result = 1;     while (n) {       if (n % 2 == 1) result = result * x;       n = n / 2;       x = x * x;     }     return result;   }   long long int gcd(long long int a, long long int b) {     if (!b) return a;     return gcd(b, a % b);   }   long long int lcm(long long int a, long long int b) {     return (a * b) / gcd(a, b);   }   long long int BS(long long int a[], long long int s, long long int n,                    long long int val) {     long long int mid, beg = s, end = n - 1;     while (beg <= end) {       mid = (beg + end) / 2;       if (val == a[mid]) {         break;       } else if (val > a[mid]) {         beg = mid + 1;       } else {         end = mid - 1;       }     }     return mid;   }   inline long long int mul(long long int x, long long int y, long long int m) {     long long int z = 1LL * x * y;     if (z >= m) {       z %= m;     }     return z;   }   long long int powmod(long long int x, long long int y, long long int m) {     long long int r = 1;     while (y) {       if (y & 1) {         r = mul(r, x, m);       }       y >>= 1;       x = mul(x, x, m);     }     return r;   }   using namespace std;   void start() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;   }   int main() {     start();     long long int n;     cin >> n;     long long int a[n], b[n];     for (long long int i = 0; i < n; i++) cin >> a[i] >> b[i];     long long int khatam = 0;     for (long long int i = 0; i < n; i++) {       if (a[i] != b[i]) {         khatam = 1;         break;       }     }     if (khatam) {       cout <<  rated n ;       return 0;     }     long long int khatam1 = 0;     for (long long int i = 1; i < n; i++) {       if (b[i] > b[i - 1]) {         khatam1 = 1;         break;       }     }     if (khatam1)       cout <<  unrated ;     else       cout <<  maybe ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, s = 0;     bool kt;     cin >> n >> m;     char a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];       }     }     for (int i = 0; i < n; i++) {       kt = true;       for (int j = 0; j < m; j++) {         if (a[i][j] ==  S ) {           kt = false;           break;         }       }       if (kt == true)         for (int j = 0; j < m; j++) a[i][j] =  1 ;     }     for (int j = 0; j < m; j++) {       kt = true;       for (int i = 0; i < n; i++) {         if (a[i][j] ==  S ) {           kt = false;           break;         }       }       if (kt == true)         for (int i = 0; i < n; i++) a[i][j] =  1 ;     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] ==  1 ) s++;       }     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans, len;   int a[2333];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     a[0] = 0;     a[n + 1] = 1001;     for (int i = 1; i <= n + 1; i++) {       if (a[i] == a[i - 1] + 1)         len++;       else {         ans = max(ans, len - 1);         len = 0;       }     }     ans = max(ans, len - 1);     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a[8][8], n, m, u, v, k = INT_MAX;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       cin >> u >> v;       a[u][v] = 1;       a[v][u] = 1;     }     if (n <= 6)       cout << m <<   n ;     else {       for (long long i = 1; i <= 7; i++) {         for (long long j = i + 1; j <= 7; j++) {           long long c = 0;           for (long long l = 1; l <= 7; l++)             if (a[i][l] == 1 && a[j][l] == 1) ++c;           k = min(k, c);         }       }       cout << m - k <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 9;   int n, p, q;   string s, t, a, b;   int c[2005], d[2005], h[2005], invH[2005], k[2005], invK[2005];   vector<pair<int, int>> memo;   int mul(int aa, int bb) { return ((long long)aa * bb) % MOD; }   int add(int aa, int bb) { return (aa + bb) % MOD; }   int sub(int aa, int bb) { return (aa - bb + MOD) % MOD; }   int modpow(int num, int pi) {     int res = 1;     while (pi > 0) {       if (pi & 1) res = mul(res, num);       num = mul(num, num);       pi >>= 1;     }     return res;   }   pair<int, int> getHash(int lo, int hi) {     return make_pair(mul(sub(c[hi], c[lo]), invH[lo]),                      mul(sub(d[hi], d[lo]), invK[lo]));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> s >> a >> b;     n = s.size();     p = a.size();     q = b.size();     h[0] = invH[0] = 1;     k[0] = invK[0] = 1;     for (int i = 1; i <= n; i++) {       h[i] = mul(h[i - 1], 31);       invH[i] = modpow(h[i], MOD - 2);       k[i] = mul(k[i - 1], 53);       invK[i] = modpow(k[i], MOD - 2);     }     for (int i = 0; i < n; i++) {       c[i + 1] = add(c[i], mul(h[i], s[i]));       d[i + 1] = add(d[i], mul(k[i], s[i]));     }     pair<int, int> x = make_pair(0, 0);     for (int i = 0; i < p; i++) {       x.first = add(x.first, mul(h[i], a[i]));       x.second = add(x.second, mul(k[i], a[i]));     }     pair<int, int> y = make_pair(0, 0);     for (int i = 0; i < q; i++) {       y.first = add(y.first, mul(h[i], b[i]));       y.second = add(y.second, mul(k[i], b[i]));     }     for (int i = 0; i < n - p + 1; i++) {       for (int j = i + max(0, p - q); j < n - q + 1; j++) {         if (x == getHash(i, i + p) && y == getHash(j, j + q)) {           memo.push_back(getHash(i, j + q));         }       }     }     sort(memo.begin(), memo.end());     int ans = unique(memo.begin(), memo.end()) - memo.begin();     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a, b, x, vx, vy;   map<long long, long long> mo;   map<long long, long long>::iterator it;   map<pair<long long, long long>, long long> ex;   map<pair<long long, long long>, long long>::iterator ti;   int main() {     scanf( %d%I64d%I64d , &n, &a, &b);     for (int i = 0; i < n; i++) {       scanf( %I64d%I64d%I64d , &x, &vx, &vy);       mo[vy - a * vx]++;       ex[make_pair(vx, vy)]++;     }     long long ans = 0;     for (it = mo.begin(); it != mo.end(); it++) {       long long tmp = it->second;       ans += tmp * (tmp - 1);     }     for (ti = ex.begin(); ti != ex.end(); ti++) {       long long tmp = ti->second;       ans -= tmp * (tmp - 1);     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(2)   using namespace std;   const int N = 5005;   int n, m;   double ans, F[N][N];   bool vis[N][N];   double cal(double b, double x, double y, double ps) {     return (1 - b) * ps * x + min(1 - ps, ps * b + (1 - ps) * (1 - y));   }   double f(int a, int b, int fl) {     if (!b) return 1;     if (!a) return 1 / (double)(b + 1);     if (vis[a][b]) return F[a][b];     double res = 1 / (double)(b + 1);     vis[a][b] = 1;     double y = f(b, a - 1, 0), x = 1 - f(b - 1, a, 0);     return F[a][b] =                max(res, cal(1 / (double)(b + 1), x, y,                             y * (double)(b + 1) / (1 + y * (double)(b + 1))));   }   int main() {     int i, j;     cin >> n >> m, ans = f(n, m, 0);     printf( %.9lf %.9lf , ans, 1 - ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n;     cin >> n;     vector<long long int> v(n), vv;     for (int i = 0; i < n; i++) cin >> v[i];     long long int mx = *max_element(v.begin(), v.end());     int len = 0, fg = 0;     for (long long int i = 0; i < n; i++) {       if (v[i] == mx) {         long long int j = i;         while (v[j] == mx && j <= n - 1) j++;         vv.push_back(j - i);         i = j;       }     }     sort(vv.begin(), vv.end());     cout << vv[vv.size() - 1];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};   int powmod(int a, int b) {     int tmp = 1;     a %= (1000000007);     for (; b; b >>= 1) {       if (b & 1) tmp = tmp * a % (1000000007);       a = a * a % (1000000007);     }     return tmp;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T>   inline void R(T &xx) {     xx = 0;     char ch = getchar();     bool F = 0;     while ((ch <  0  || ch >  9 ) && ch !=  - ) ch = getchar();     if (ch ==  - ) F = 1, ch = getchar();     while (ch >=  0  && ch <=  9 )       xx = xx + xx + (xx << 3) + ch - 48, ch = getchar();     if (F) xx = -xx;   }   template <class T>   inline void add(int &x, T y) {     for (x += y; x >= (1000000007); x -= (1000000007))       ;   }   int n, k, a[5011], f[5011][2222][2], ans;   int main() {     R(n);     R(k);     for (int i = 1; i <= n; i++) R(a[i]);     f[0][0][0] = 1;     for (int i = 1; i <= n; i++) {       if (a[i] == 0 || a[i] == 2)         for (int j = 0; j < (int)2049; j++) {           int p = min(j + 2, 2048);           add(f[i][p][1], f[i - 1][j][1]);           add(f[i][p][0], f[i - 1][j][0]);         }       if (a[i] == 0 || a[i] == 4)         for (int j = 0; j < (int)2049; j++) {           int p = min(j + 4, 2048);           if (j % 4)             add(f[i][4][j >= (1 << k)], f[i - 1][j][0]),                 add(f[i][4][1], f[i - 1][j][1]);           else             add(f[i][p][0], f[i - 1][j][0]), add(f[i][p][1], f[i - 1][j][1]);         }     }     for (int i = 0; i < (int)2049; i++) {       add(ans, f[n][i][1]);       if (i >= (1 << k)) add(ans, f[n][i][0]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int MOD = 1e9 + 7;   int n;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;     cin >> n;     int dp[] = {1, 0};     for (int i = 1; i < n; i++) dp[i % 2] = (dp[i % 2] + dp[1 - i % 2] + 1) % MOD;     cout << (dp[0] + dp[1]) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, i = 0, j, k = 0, l = 0, m = 10e9, a = 0, b = 0, c, sum = 0,                  x = 0, y = 0, z = 0;     cin >> n;     long long arr[n + 1];     for (i = 1; i <= n; i++) {       cin >> arr[i];       arr[i] = arr[i] / max(i - 1, n - i);     }     for (i = 1; i <= n; i++) {       l = arr[i];       m = min(m, l);     }     cout << m;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, j, q = 0;     string s, k, p =  go ;     cin >> n >> s;     vector<string> st(100);     st[0] =  ogo ;     for (i = 1; i < 100; i++) {       st[i] = st[i - 1] + p;     }     for (i = 0; i < n; i++) {       j = n - i;       q = 0;       for (j = n - i; j >= 3; j--) {         k = s.substr(i, j);         if (binary_search(st.begin(), st.end(), k)) {           i = i + j - 1;           cout <<  *** ;           q = 1;           break;         }       }       if (q == 0) cout << s[i];     }   }
#include <bits/stdc++.h>   using namespace std;   char inp[2000];   int toNum(char x) {     if (x >=  0  && x <=  9 ) return x -  0 ;     return 10 + x -  A ;   }   char toChar(int x) {     if (x < 10) return  0  + x;     return  A  + (x - 10);   }   long long ato10(int a) {     int len = strlen(inp);     int lw = 0;     while (lw < len && inp[lw] ==  0 ) lw++;     if (lw >= len) return 0;     long long ret = 0;     for (int i = lw; i < len; i++) {       ret = ret * a + toNum(inp[i]);     }     return ret;   }   char pI[] = { I ,  X ,  C ,  M };   char pV[] = { V ,  L ,  D };   int main() {     int a, b;     gets(inp);     bool iR = false;     int len = strlen(inp);     for (int i = 0; i < len; i++) {       if (inp[i] ==  R ) iR = true;     }     if (!iR)       sscanf(inp,  %d%d , &a, &b);     else       sscanf(inp,  %d , &a);     gets(inp);     long long number = ato10(a);     if (!iR) {       string ret =   ;       if (number == 0)         ret =  0 ;       else {         while (number) {           ret = toChar(number % b) + ret;           number /= b;         }       }       printf( %s n , ret.c_str());     } else {       int idx = 0;       string ret =   ;       while (number) {         int tdec = number % 10;         number /= 10;         if (tdec <= 3)           for (int t = 0; t < tdec; t++) ret = pI[idx] + ret;         else if (tdec == 4) {           ret = pV[idx] + ret;           ret = pI[idx] + ret;         } else if (tdec == 5)           ret = pV[idx] + ret;         else if (tdec <= 8) {           tdec -= 5;           for (int t = 0; t < tdec; t++) ret = pI[idx] + ret;           ret = pV[idx] + ret;         } else {           ret = pI[idx + 1] + ret;           ret = pI[idx] + ret;         }         idx++;       }       printf( %s n , ret.c_str());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int k;   long long int ways(long long int n) {     long long int calc, ways = 0;     for (int k = 2; k <= 10000000; k++) {       calc = n / (1ll * k * k * k);       ways += calc;       if (calc == 0) {         break;       }     }     return ways;   }   long long int binarysearch(long long int low, long long int high) {     long long int temp = high;     while (low <= high) {       long long int mid = low + (high - low) / 2;       long long int x = ways(mid);       if (x > k)         high = mid - 1;       else if (x < k)         low = mid + 1;       else if (x == k) {         temp = min(temp, mid);         high = mid - 1;       }     }     return temp;   }   int main() {     scanf( %lld , &k);     long long int MAX = 10 * k;     long long int ans = binarysearch(8, MAX);     if (ans == MAX) ans = -1;     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   namespace whatever {   const long long inf = 1000000000000000001ll;   template <typename type>   type read() {     char ch = getchar();     while (!isdigit(ch)) ch = getchar();     type value = ch -  0 ;     ch = getchar();     while (isdigit(ch)) {       value = value * 10 + ch -  0 ;       ch = getchar();     }     return value;   }   int n;   string f[201];   char result[202];   int fail[201];   int match(const string &str, int l) {     int cnt = 0;     int cur = 0;     for (char ch : str) {       while (cur && ch != result[cur + 1]) cur = fail[cur];       if (ch == result[cur + 1]) ++cur;       if (cur == l) {         ++cnt;         cur = fail[cur];       }     }     return cnt;   }   long long count(int l) {     static long long cnt[201];     int i;     for (i = 0; i <= n && (i < 2 || int(f[i - 2].size()) <= l); ++i)       cnt[i] = match(f[i], l);     if (i <= n) {       long long span_cnt[2];       span_cnt[i % 2] = match(           f[i - 2].substr(f[i - 2].size() - l + 1) + f[i - 1].substr(0, l - 1),           l);       span_cnt[1 - i % 2] = match(           f[i - 2].substr(f[i - 2].size() - l + 1) + f[i - 2].substr(0, l - 1),           l);       do {         cnt[i] = cnt[i - 2] + cnt[i - 1] + span_cnt[i % 2];         if (cnt[i] >= inf) return inf;       } while (++i <= n);     }     return cnt[n];   }   void insert(int l, char ch) {     result[l] = ch;     if (l == 1) return;     int cur = fail[l - 1];     while (cur && ch != result[cur + 1]) cur = fail[cur];     if (ch == result[cur + 1]) ++cur;     fail[l] = cur;   }   void run() {     n = read<int>();     long long k = read<long long>() + 1;     int m = read<int>();     f[0] =  0 ;     f[1] =  1 ;     int last = n;     for (int i = 2; i <= n; ++i)       if (int(f[i - 2].size()) <= m)         f[i] = f[i - 2] + f[i - 1];       else {         last = i - 1;         break;       }     cerr <<  last:   << last << endl;     fail[1] = 0;     for (int i = 1; i <= m; ++i) {       if (f[last].substr(f[last].size() - i + 1) ==           string(result + 1, result + i)) {         if (--k == 0) break;       }       insert(i,  0 );       long long cnt = count(i);       if (cnt >= k)         putchar( 0 );       else {         k -= cnt;         insert(i,  1 );         putchar( 1 );       }     }     putchar(  n );   }   }  // namespace whatever   int main() { whatever::run(); }
#include <bits/stdc++.h>   const long long N = 2e5 + 17;   using namespace std;   long long i, mn, ans = 0, als = 0, v, ii, r4 = 0, r1, r2, r3, mx, p, q, d, l, r,                    m, n, k, j;   string d1, d3, d2, s;   char kl, km, mk, lk;   double fg;   int inout() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     cin >> n >> q;     map<long long, long long> mp;     while (q--) {       cin >> r1 >> r2 >> r3;       als = 0;       ii = 0;       for (i = 1; i <= n; i++) {         if (r1 >= mp[i]) als++;         if (als == r2) break;       }       if (als == r2) {         for (i = 1; i <= n && r2; i++) {           if (r1 >= mp[i]) {             mp[i] = r1 + r3;             ii += i;             r2--;           }         }         cout << ii <<   n ;       } else         cout <<  -1               <<   n ;     }     return 0;   }