malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000 * 100 * 2 + 10;   long long int a[MAXN];   long long int b[MAXN];   long long int p[MAXN];   long long int d[MAXN];   long long int mod = 1000 * 1000 * 1000 + 7;   int main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     int n, c;     cin >> n >> c;     for (int i = 0; i < n - 1; i++) {       cin >> a[i];     }     for (int i = 0; i < n - 1; i++) {       cin >> b[i];     }     cout << 0 <<    ;     for (int i = 0; i < n - 1; i++) {       if (i == 0) {         d[i] = c + b[i];         p[i] = a[i];       } else {         d[i] = min(d[i - 1] + b[i], p[i - 1] + b[i] + c);         p[i] = min(p[i - 1] + a[i], d[i - 1] + a[i]);       }       cout << min(d[i], p[i]) <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int l[1000005], n, m;   long long f[5005][5005], g[2][5005], fa[5005], fac[5005], p, sum;   inline int read() {     int ret = 0;     char fa = getchar();     while (!isdigit(fa)) fa = getchar();     while (isdigit(fa)) {       ret = (ret << 1) + (ret << 3) + fa -  0 ;       fa = getchar();     }     return ret;   }   inline void Aireen() {     n = read();     m = read();     p = (long long)(read());     for (int i = 1; i <= n; ++i) l[i] = read();     fa[0] = fac[0] = 1ll;     for (int i = 1, j = m; i < 5005 && j; ++i, --j) {       fa[i] = fa[i - 1] * (long long)(i) % p;       fac[i] = fac[i - 1] * (long long)(j) % p;     }     f[0][0] = 1ll;     for (int i = 1; i < 5005; ++i)       for (int j = min(m, i); j; --j)         f[i][j] = (f[i - 1][j - 1] + f[i - 1][j] * (long long)(j - 1) % p) % p;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= l[i + 1]; ++j) g[i & 1][j] = 0ll;       if (i == 1) {         for (int j = min(l[i], m); j; --j) g[i][j] = fac[j] * f[l[i]][j] % p;       } else {         sum = 0ll;         for (int j = min(l[i - 1], m); j; --j) sum = (sum + g[i & 1 ^ 1][j]) % p;         for (int j = min(l[i], m); j; --j) {           g[i & 1][j] = (fac[j] * sum % p - fa[j] * g[i & 1 ^ 1][j] % p + p) % p *                         f[l[i]][j] % p;         }       }     }     sum = 0ll;     for (int j = min(l[n], m); j; --j) sum = (sum + g[n & 1][j]) % p;     cout << sum << endl;   }   int main() {     Aireen();     fclose(stdin);     fclose(stdout);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   long long max(long long a, long long b) {     if (a > b) {       return a;     } else {       return b;     }   }   long long min(long long a, long long b) {     if (a < b) {       return a;     } else {       return b;     }   }   long long power(long long b, long long e) {     if (e == 0) return 1;     if (e % 2)       return ((b * power((b) * (b), (e - 1) / 2)));     else       return power((b) * (b), e / 2);   }   long long modpower(long long b, long long e, long long q) {     long long MOD = q;     if (e == 0) return 1;     if (e % 2)       return ((b % MOD) * modpower((b % MOD) * (b % MOD), (e - 1) / 2, q)) % MOD;     else       return modpower((b % MOD) * (b % MOD), e / 2, q) % MOD;   }   void dpv(vector<long long> v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;   }   void dpv(vector<pair<long long, long long> > v) {     for (long long i = 0; i < v.size(); i++) {       cout << v[i].first <<     << v[i].second << endl;     }   }   void dpv(set<long long> v) {     for (auto i : v) {       cout << i <<    ;     }     cout << endl;   }   long long dp[31][31][51];   long long f(long long a, long long b, long long c) {     if (dp[a][b][c] || a * b == c || !c) {       return dp[a][b][c];     }     long long ans = 1e18;     for (long long i = 1; i <= a - i; i++) {       for (long long j = 0; j <= c; j++) {         ans = min(ans, b * b + f(a - i, b, j) + f(i, b, c - j));       }     }     for (long long i = 1; i <= b - i; i++) {       for (long long j = 0; j <= c; j++) {         ans = min(ans, a * a + f(a, i, j) + f(a, b - i, c - j));       }     }     return dp[a][b][c] = ans;   }   void oblivious() {     long long a, b, c;     cin >> a >> b >> c;     cout << f(a, b, c) << endl;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, 0, sizeof(dp));     long long t = 1;     cin >> t;     while (t--) {       oblivious();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, k;     cin >> n >> k;     string s;     cin >> s;     unordered_map<char, int> m;     char last = s[0];     int streak = 1;     int cur_max = 0;     if (k == 1) {       cur_max = 1;       m[last] = 1;       streak = 0;     }     for (int i = 1; i < s.size(); i++) {       if (s[i] == last) {         streak++;       } else {         streak = 1;       }       if (streak == k) {         streak = 0;         if (m.find(s[i]) == m.end()) {           m[s[i]] = 1;         } else {           m[s[i]]++;         }         cur_max = m[s[i]] > cur_max ? m[s[i]] : cur_max;       }       last = s[i];     }     cout << cur_max << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename TT>   ostream &operator<<(ostream &s, pair<T, TT> t) {     return s <<  (  << t.first <<  ,  << t.second <<  ) ;   }   template <typename T>   ostream &operator<<(ostream &s, vector<T> t) {     s <<  { ;     for (int i = 0; i < t.size(); i++)       s << t[i] << (i == t.size() - 1 ?    :  , );     return s <<  }  << endl;   }   int main() {     ios_base::sync_with_stdio(0);     int n, m, a1, b1, a2, b2;     cin >> n >> m >> a1 >> b1 >> a2 >> b2;     if (abs(a1 - a2) + abs(b1 - b2) <= 4)       cout <<  First ;     else if (abs(a1 - a2) + abs(b1 - b2) == 5 &&              min(abs(a1 - a2), abs(b1 - b2)) >= 1)       cout <<  First ;     else if (abs(a1 - a2) + abs(b1 - b2) == 6 &&              min(abs(a1 - a2), abs(b1 - b2)) >= 2)       cout <<  First ;     else       cout <<  Second ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const int maxn = 100010;   static const int INF = 0x3f3f3f3f;   static const int mod = (int)1e9 + 7;   static const double eps = 1e-6;   static const double pi = acos(-1);   void redirect() {}   char s[maxn];   int cnt[26];   int main() {     redirect();     int T;     scanf( %d , &T);     while (T--) {       memset(cnt, 0, sizeof(cnt));       scanf( %s , s);       for (int i = 0; s[i]; i++) cnt[s[i] -  a ]++;       bool flag = true;       for (int i = 0; i < 26; i++)         if (cnt[i] > 1) flag = false;       int i = 0;       while (i < 26 && cnt[i] == 0) i++;       while (i < 26 && cnt[i] == 1) i++;       for (; i < 26; i++)         if (cnt[i]) flag = false;       if (flag)         puts( Yes );       else         puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   struct MCMF {     enum { MAXN = 6500 };     struct Edge {       int x, y;       int cap, cost;     };     vector<Edge> E;     vector<int> adj[MAXN];     int N, prev[MAXN];     int dist[MAXN], phi[MAXN];     MCMF(int NN) : N(NN) {}     void add(int x, int y, int cap, int cost) {       Edge e1 = {x, y, cap, cost}, e2 = {y, x, 0, -cost};       adj[e1.x].push_back(E.size());       E.push_back(e1);       adj[e2.x].push_back(E.size());       E.push_back(e2);     }     vector<queue<int> > Q;     void mcmf(int s, int t, int &flowVal, int &flowCost) {       int x;       flowVal = flowCost = 0;       memset(phi, 0, sizeof(phi));       Q.resize(6500);       while (true) {         for (x = 0; x < N; x++) prev[x] = -1;         for (x = 0; x < N; x++) dist[x] = 1000000000;         dist[s] = prev[s] = 0;         Q[dist[s]].push(s);         for (int i = 0; i < 6400; i++) {           while (!Q[i].empty()) {             x = Q[i].front();             Q[i].pop();             if (dist[x] < i) continue;             vector<int>::iterator it;             for (it = adj[x].begin(); it != adj[x].end(); it++) {               const Edge &e = E[*it];               if (e.cap <= 0) continue;               int cc = e.cost + phi[x] - phi[e.y];               if (dist[x] + cc < dist[e.y]) {                 dist[e.y] = dist[x] + cc;                 prev[e.y] = *it;                 Q[dist[e.y]].push(e.y);               }             }           }         }         if (prev[t] == -1) break;         int z = 1000000000;         for (x = t; x != s; x = E[prev[x]].x) z = min(z, E[prev[x]].cap);         for (x = t; x != s; x = E[prev[x]].x) {           E[prev[x]].cap -= z;           E[prev[x] ^ 1].cap += z;         }         flowVal += z;         flowCost += z * (dist[t] - phi[s] + phi[t]);         for (x = 0; x < N; x++)           if (prev[x] != -1) phi[x] += dist[x];       }     }   } * mc;   int a[90][90];   int main() {     int i, j, k, n, m;     scanf( %d %d , &n, &m);     mc = new MCMF(n * m + 10);     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) cin >> a[i][j];     int src = n * m + 1;     int dest = n * m + 2;     for (i = 0; i < n; i++) {       for (j = 0; j < m; j++) {         if ((i + j) % 2 == 0)           mc->add(src, i * m + j, 1, 0);         else {           mc->add(i * m + j, dest, 1, 0);           continue;         }         for (k = 0; k < 4; k++) {           int ni = i + dx[k];           int nj = j + dy[k];           if (ni < n && nj < m && ni >= 0 && nj >= 0) {             mc->add(i * m + j, ni * m + nj, 1, a[i][j] != a[ni][nj]);           }         }       }     }     int fval, fcost;     mc->mcmf(src, dest, fval, fcost);     cout << fcost << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3005;   const int mod = 1e9 + 7;   int dp1[N][N], dp2[N][N], a[N];   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       scanf( %d , &n);       for (int i = 1; i <= n; i++) {         scanf( %d , &a[i]);       }       memset(dp1, 0, sizeof(dp1));       memset(dp2, 0, sizeof(dp2));       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           dp1[i][j] = dp1[i - 1][j];         }         dp1[i][a[i]]++;       }       for (int i = n; i >= 1; i--) {         for (int j = 1; j <= n; j++) {           dp2[i][j] = dp2[i + 1][j];         }         dp2[i][a[i]]++;       }       long long ans = 0;       for (int i = 2; i <= n; i++) {         for (int j = i + 1; j < n; j++) {           ans += dp1[i - 1][a[j]] * dp2[j + 1][a[i]];         }       }       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     std::cin.tie(0);     std::ios::sync_with_stdio(false);     long long n;     cin >> n;     if (n <= 5) {       cout << -1 << endl;     } else {       cout << 1 <<     << 2 << endl;       for (int i = 3; i <= n; i++) {         if (i % 2)           cout << 1 <<     << i << endl;         else           cout << 2 <<     << i << endl;       }     }     for (int i = 2; i <= n; i++) cout << 1 <<     << i << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ull = unsigned long long;   using ld = long double;   bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     int mx = -1, my = -1;     while (t--) {       char c;       int t1, t2;       cin >> c >> t1 >> t2;       if (t1 > t2) swap(t1, t2);       if (c ==  + ) {         mx = max(mx, t1);         my = max(my, t2);       } else {         if (mx <= t1 && my <= t2)           cout <<  YES n ;         else           cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-5;   bool board[8][8];   const int dx[8] = {1, 2, 2, 1, -1, -2, -2, -1};   const int dy[8] = {2, 1, -1, -2, -2, -1, 1, 2};   void check(int x, int y, int n) {     board[x][y] = true;     if (n == 1) {       for (int i = (0); i < (int)(8); ++i) {         board[i][y] = true;         board[x][i] = true;       }     }     for (int r = (0); r < (int)(8); ++r) {       if (x + dx[r] < 8 && x + dx[r] >= 0) {         if (y + dy[r] < 8 && y + dy[r] >= 0) {           board[x + dx[r]][y + dy[r]] = true;         }       }     }   }   int main(void) {     int x, y, count = 0;     string line;     cin >> line;     x = line[0] -  a ;     y = line[1] -  1 ;     check(x, y, 1);     cin >> line;     x = line[0] -  a ;     y = line[1] -  1 ;     check(x, y, 2);     for (int x = (0); x < (int)(8); ++x) {       for (int y = (0); y < (int)(8); ++y) {         if (board[x][y]) count++;       }     }     cout << 64 - count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100000 + 10;   int SL[MAXN], SR[MAXN];   int A[MAXN][2], n;   int main() {     while (~scanf( %d , &n)) {       SL[0] = SR[0] = 0;       for (int i = 1; i <= n; i++) {         scanf( %d%d , &A[i][0], &A[i][1]);         SL[i] = A[i][0] + SL[i - 1];         SR[i] = A[i][1] + SR[i - 1];       }       int maxn = abs(SL[n] - SR[n]);       int ans = 0;       for (int i = 1; i <= n; i++) {         int _SL = SL[n] - A[i][0] + A[i][1];         int _SR = SR[n] - A[i][1] + A[i][0];         int _ans = abs(_SL - _SR);         if (maxn < _ans) {           maxn = _ans;           ans = i;         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a[300005], tp, lt, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++) {       tp = min(a[i] / 2, lt);       lt -= tp;       a[i] -= tp * 2;       ans += tp + a[i] / 3;       lt += a[i] % 3;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char my_array[50][50];   bool visited[50][50];   bool dfs(int i, int j, int c_i, int c_j) {     if (visited[i][j]) {       return true;     }     visited[i][j] = true;     char col = my_array[i][j];     bool res = false;     if (i > 0 && col == my_array[i - 1][j] && c_i != i - 1) {       res |= dfs(i - 1, j, i, j);     }     if (j > 0 && col == my_array[i][j - 1] && c_j != j - 1) {       res |= dfs(i, j - 1, i, j);     }     if (i < n - 1 && col == my_array[i + 1][j] && c_i != i + 1) {       res |= dfs(i + 1, j, i, j);     }     if (j < m - 1 && col == my_array[i][j + 1] && c_j != j + 1) {       res |= dfs(i, j + 1, i, j);     }     return res;   }   int main(int argc, const char* argv[]) {     cin >> n >> m;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> my_array[i][j];       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (!visited[i][j] && dfs(i, j, -1, -1)) {           cout <<  Yes ;           return 0;         }       }     }     cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int N = 1e6, N2 = 5e3, delta = 46639, mod = 1e9 + 7, oo = 1e16;   const long double PI = 3.141592653589793;   int main() {     long long int n, cnt1 = 1, cnt2 = 1, mx = 0;     string s;     cin >> n >> s;     for (long long int i = 0; i < n; i++) {       for (long long int j = i; j < n; j++) {         string t = s;         long long int cnt = 0, trn = 0, ans = 0;         swap(t[i], t[j]);         for (long long int k = 0; k < n; k++) {           if (t[k] ==  ( )             cnt++;           else {             if (cnt <= 0)               trn++;             else               cnt--;           }         }         for (long long int k = n - 1; k >= 0; k--) {           if (cnt == 0 && trn == 0) ans++;           if (t[k] ==  ( )             cnt--, trn--;           else             cnt++, trn++;         }         mx = max(mx, ans);         if (mx == ans) cnt1 = i + 1, cnt2 = j + 1;       }     }     cout << mx <<   n  << cnt1 <<     << cnt2;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2002;   int main() {     int h, m;     char c1, c2, c3, c4;     double r1, r2;     cin >> c1 >> c2 >> c3 >> c3 >> c4;     h = (c1 -  0 ) * 10 + (c2 -  0 );     m = (c3 -  0 ) * 10 + (c4 -  0 );     h %= 12;     double hh = h + double(m) / 60;     r1 = hh / 12.0 * 360;     r2 = double(m) / 60.0 * 360;     printf( %0.10f %0.10f n , r1, r2);   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:256000000 )   using namespace std;   const long double PI = 3.14159265358979323846;   const long double eps = 1e-5;   const int INF = numeric_limits<int>::max();   const long long LINF = numeric_limits<long long>::max();   const long long mod = 1000 * 1000 * 1000 + 7;   struct moves {     int r1, c1, r2, c2;     moves(int _r1, int _c1, int _r2, int _c2)         : r1(_r1), c1(_c1), r2(_r2), c2(_c2) {}   };   vector<moves> solve(int n, int m, vector<vector<int> > b,                       vector<pair<int, int> > p) {     vector<moves> res;     int c = -1;     for (int j = 0; j < n; ++j) {       for (int i = 0; i < n; ++i) {         if (b[i][j] == -1) {           continue;         }         ++c;         int d = c - j;         if (d < 0) {           for (int k = 0; k < -d; ++k) {             swap(b[i][j - k], b[i][j - 1 - k]);             res.push_back(moves(i, j - k, i, j - 1 - k));           }         }         if (d == 0) {           continue;         }         if (d > 0) {           --c;           int l = j + 1;           while (b[i][l] != -1) ++l;           for (int k = l - 1; k >= j; --k) {             swap(b[i][k], b[i][k + 1]);             res.push_back(moves(i, k, i, k + 1));           }         }       }     }     for (int j = 0; j < n; ++j) {       if (b[0][j] != -1) {         swap(b[0][j], b[1][j]);         res.push_back(moves(0, j, 1, j));       }     }     for (int i = 2; i < n; ++i) {       for (int j = 0; j < n; ++j) {         if (b[i][j] != -1) {           for (int k = i - 1; k >= 1; --k) {             swap(b[k + 1][j], b[k][j]);             res.push_back(moves(k + 1, j, k, j));           }         }       }     }     for (int t = 0; t < m; ++t) {       int cl = 0;       while (b[1][cl] != t) ++cl;       swap(b[1][cl], b[0][cl]);       res.push_back(moves(1, cl, 0, cl));       for (int j = cl; j > t; --j) {         swap(b[0][j], b[0][j - 1]);         res.push_back(moves(0, j, 0, j - 1));       }       for (int j = cl; j > t; --j) {         swap(b[1][j], b[1][j - 1]);         res.push_back(moves(1, j - 1, 1, j));       }     }     return res;   }   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int> > b1(n, vector<int>(n, -1)), b2(n, vector<int>(n, -1));     vector<pair<int, int> > p1(m), p2(m);     for (int i = 0; i < m; ++i) {       int r, c;       cin >> r >> c;       --r, --c;       p1[i] = pair<int, int>(r, c);       b1[r][c] = i;     }     for (int i = 0; i < m; ++i) {       int r, c;       cin >> r >> c;       --r, --c;       p2[i] = pair<int, int>(r, c);       b2[r][c] = i;     }     if (n == 1) {       cout << 0 << endl;       return;     }     vector<moves> r1 = solve(n, m, b1, p1);     vector<moves> r2 = solve(n, m, b2, p2);     cout << r1.size() + r2.size() <<   n ;     for (int i = 0; i < r1.size(); ++i) {       cout << r1[i].r1 + 1 <<     << r1[i].c1 + 1 <<     << r1[i].r2 + 1 <<                << r1[i].c2 + 1 <<   n ;     }     for (int i = r2.size() - 1; i >= 0; --i) {       cout << r2[i].r2 + 1 <<     << r2[i].c2 + 1 <<     << r2[i].r1 + 1 <<                << r2[i].c1 + 1 <<   n ;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool grid[3][10004];   int n;   long long dp[10004][8];   long long calc(int i, int mask) {     int mask2 = 0;     if (grid[0][i]) mask2 |= 1;     if (grid[1][i]) mask2 |= 2;     if (grid[2][i]) mask2 |= 4;     if ((mask & mask2) != 0) {       return 0;     }     mask |= mask2;     long long ret = dp[i][mask];     if (ret != -1) {       return ret;     }     if (i == n - 1) {       if (mask == 1 || mask == 4 || mask == 7) {         return 1;       } else         return 0;     }     switch (mask) {       case 0:         ret = calc(i + 1, 4);         ret += calc(i + 1, 1);         ret += calc(i + 1, 7);         ret %= 1000000007;         break;       case 1:         ret = calc(i + 1, 6);         ret += calc(i + 1, 0);         ret %= 1000000007;         break;       case 2:         ret = calc(i + 1, 5);         break;       case 3:         ret = calc(i + 1, 4);         break;       case 4:         ret = calc(i + 1, 3);         ret += calc(i + 1, 0);         ret %= 1000000007;         break;       case 5:         ret = calc(i + 1, 2);         break;       case 6:         ret = calc(i + 1, 1);         break;       case 7:         ret = calc(i + 1, 0);         break;       default:         break;     }     dp[i][mask] = ret;     return ret;   }   int main() {     cin >> n;     string a, b, c;     cin >> a >> b >> c;     memset(grid, true, sizeof grid);     memset(dp, -1, sizeof dp);     for (int i = 0; i < n; i++) {       if (a[i] ==  . ) {         grid[0][i] = false;       }     }     for (int i = 0; i < n; i++) {       if (b[i] ==  . ) {         grid[1][i] = false;       }     }     for (int i = 0; i < n; i++) {       if (c[i] ==  . ) {         grid[2][i] = false;       }     }     if (a.find( O ) == string::npos && c.find( O ) == string::npos &&         b.find( O ) != 0 && b.find( O ) != n - 1) {       long long x = calc(0, 0);       int p = b.find( O );       memset(dp, -1, sizeof dp);       grid[1][p - 1] = true;       grid[2][p - 1] = true;       grid[0][p + 1] = true;       grid[1][p + 1] = true;       long long y = calc(0, 0);       grid[0][p - 1] = true;       grid[2][p - 1] = false;       grid[0][p + 1] = false;       grid[2][p + 1] = true;       memset(dp, -1, sizeof(dp));       long long z = calc(0, 0);       cout << (x - y - z + 1000000007 + 1000000007) % 1000000007 << endl;     } else {       cout << calc(0, 0) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename U>   inline void smin(T &a, const U &b) {     if (a > b) a = b;   }   template <typename T, typename U>   inline void smax(T &a, const U &b) {     if (a < b) a = b;   }   template <class T>   inline void gn(T &first) {     char c, sg = 0;     while (c = getchar(), (c >  9  || c <  0 ) && c !=  - )       ;     for ((c ==  -  ? sg = 1, c = getchar() : 0), first = 0; c >=  0  && c <=  9 ;          c = getchar())       first = (first << 1) + (first << 3) + c -  0 ;     if (sg) first = -first;   }   template <class T1, class T2>   inline void gn(T1 &x1, T2 &x2) {     gn(x1), gn(x2);   }   int power(int a, int b, int m, int ans = 1) {     for (; b; b >>= 1, a = 1LL * a * a % m)       if (b & 1) ans = 1LL * ans * a % m;     return ans;   }   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int> > vec;     vector<pair<int, int> > event;     multiset<int> s;     for (int i = 0; i < m; i++) {       int l, r, t;       gn(l, r);       gn(t);       event.push_back(pair<int, int>(l, t));       event.push_back(pair<int, int>(r, -t - 1));     }     sort(event.begin(), event.end());     for (pair<int, int> e : event) {       if (!s.empty()) vec.push_back(pair<int, int>(*s.begin() - e.first, 1));       if (e.second < 0)         s.erase(s.find(-e.second - 1));       else         s.insert(e.second);       if (!s.empty()) vec.push_back(pair<int, int>(*s.begin() - e.first, -1));     }     sort(vec.begin(), vec.end());     long long now = 0, d = 0;     int cur = 0;     int pre = -1e9;     for (int i = 0; i < n; i++) {       int t;       gn(t);       while (cur < vec.size() && vec[cur].first < t) {         now += d * (vec[cur].first - pre);         d += vec[cur].second;         pre = vec[cur].first;         cur++;       }       printf( %I64d n , now + d * (t - pre));     }     return 0;   }