malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(228);   const int M = 1791791791;   const int B = 239;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, m;     cin >> n >> m;     vector<string> a(n), b(m);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       cin >> b[i];     }     map<int, int> ans;     for (int i = 0; i + m - 1 < n; i++) {       int kek = 0;       for (int x = i; x <= i + m - 1; x++) {         for (int y = 0; y < m; y++) {           kek = (kek * (long long)B + a[x][y]) % M;         }       }       ans[kek] = i;     }     for (int j = 0; j + m - 1 < n; j++) {       int kek = 0;       for (int x = 0; x < m; x++) {         for (int y = j; y <= j + m - 1; y++) {           kek = (kek * (long long)B + b[x][y]) % M;         }       }       if (ans.count(kek)) {         cout << ans[kek] + 1 <<     << j + 1 <<   n ;         return 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 1e1;   long long n;   long long r, avg;   long long must, ans = 0, sum = 0;   pair<long long, long long> d[MAXN];   int main() {     cin >> n >> r >> avg;     long long x, y;     for (long long i = 1; i <= n; i++) {       scanf( %I64d%I64d , &x, &y);       sum += x;       d[i] = make_pair(y, x);     }     must = max(n * avg - sum, 1LL * 0);     sort(d + 1, d + n + 1);     long long i = 1;     while (must) {       ans += min(must, r - d[i].second) * d[i].first;       must -= min(must, r - d[i].second);       i++;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int a[100001];   stack<int> st;   int main() {     ios::sync_with_stdio(0);     int n;     cin >> n;     long long int sum = 0;     for (int i = 0; i < n; i++) cin >> a[i];     sum += a[0];     for (int i = 1; i < n; i++) sum += max(a[i] - a[i - 1], 0);     cout << sum <<   n ;     for (int i = 0; i < a[0]; i++) st.push(0);     for (int i = 1; i < n; i++) {       if (a[i] - a[i - 1] > 0) {         for (int j = 0; j < a[i] - a[i - 1]; j++) st.push(i);       } else if (st.size() != 0) {         int num = abs(a[i] - a[i - 1]);         for (int j = 0; j < num; j++) {           int inde = st.top();           inde++;           st.pop();           cout << inde <<     << i <<   n ;         }       }     }     for (int i = 0; i < a[n - 1]; i++) {       if (st.size() != 0) {         cout << st.top() + 1 <<     << n <<   n ;         st.pop();       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long xx, yy, n, m, i, g, j, k, x, y;     std::vector<long long> v;     vector<pair<long long, long long>> vp;     cin >> n >> m;     map<pair<long long, long long>, long long> mp;     for (i = 0; i < m; i++) {       cin >> x >> y;       vp.push_back({x, y});       mp[{x, y}]++;     }     for (i = 1; i * i <= n; i++) {       if (n % i == 0) {         v.push_back(i);         v.push_back(n / i);       }       if ((n % i == 0 && i == n / i) || i == 1) {         v.pop_back();       }     }     for (auto itr : v) {       g = 1;       k = itr;       for (i = 0; i < m; i++) {         xx = vp[i].first + k;         yy = vp[i].second + k;         if (xx >= n + 1) {           xx = xx % (n + 1) + 1;         }         if (yy >= n + 1) {           yy = yy % (n + 1) + 1;         }         if (mp.find({xx, yy}) == mp.end() && mp.find({yy, xx}) == mp.end()) {           g = 0;           break;         }       }       if (g) {         cout <<  Yes               <<   n ;         return 0;       }     }     cout <<  No           <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long sum = 0, n, m;   const long long mod = 1e9 + 7;   long long f[25];   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % mod;       a = (a * a) % mod;       b >>= 1;     }     return ans;   }   long long getc(long long a, long long b) {     if (a < b) return 0;     if (b > a - b) b = a - b;     long long s1 = 1, s2 = 1;     for (long long i = 0; i < b; i++) {       s1 = s1 * (a - i) % mod;       s2 = s2 * (i + 1) % mod;     }     return s1 * qpow(s2, mod - 2) % mod;   }   long long lucas(long long n, long long k) {     if (k == 0) return 1;     return getc(n % mod, k % mod) * lucas(n / mod, k / mod) % mod;   }   long long solve() {     long long ans = 0;     for (int i = 0; i < (1 << n); i++) {       long long cnt = 0, sum = m;       for (int j = 0; j < n; j++) {         if (i & (1 << j)) {           sum -= f[j] + 1;           cnt++;         }       }       if (sum < 0) continue;       if (cnt & 1)         ans -= lucas(sum + n - 1, n - 1);       else         ans += lucas(sum + n - 1, n - 1);       ans %= mod;     }     return (ans + mod) % mod;   }   int main() {     scanf( %lld%lld , &n, &m);     for (int i = 0; i < n; i++) scanf( %lld , &f[i]);     printf( %lld n , solve());     return 0;   }
#include <bits/stdc++.h>   const int inf = 1e5 + 10;   const long long mod = 998244353;   const int LARGEST = 0x3f3f3f3f;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int dx[] = {0, 1, 1, 1, 0, -1, -1, -1};   int dy[] = {1, 1, 0, -1, -1, -1, 0, 1};   int bx[] = {0, 1, 0, -1};   int by[] = {-1, 0, 1, 0};   using namespace std;   int a[inf], stmin[inf][20], stmax[inf][20];   pair<int, int> q[inf];   int dp[inf];   int n, s, len, head, tail;   int ask(int x, int y) {     int tlen = log(y - x + 1) / log(2);     int p = max(stmax[x][tlen], stmax[y - (1 << tlen) + 1][tlen]);     int q = min(stmin[x][tlen], stmin[y - (1 << tlen) + 1][tlen]);     return p - q;   }   int main() {     ios::sync_with_stdio(0);     cin >> n >> s >> len;     for (int i = 1; i <= n; i++) {       cin >> a[i];       stmax[i][0] = stmin[i][0] = a[i];     }     for (int j = 1; j < 20; j++)       for (int i = 1; i <= n; i++)         if (i + (1 << (j - 1)) <= n) {           stmax[i][j] = max(stmax[i][j - 1], stmax[i + (1 << (j - 1))][j - 1]);           stmin[i][j] = min(stmin[i][j - 1], stmin[i + (1 << (j - 1))][j - 1]);         }     if (len > n || ask(1, len) > s) {       cout << -1 << endl;       return 0;     }     for (int i = 1; i <= n; i++) dp[i] = LARGEST;     dp[0] = 0;     dp[len] = 1;     head = tail = 1;     q[tail++] = make_pair(dp[0], 0);     for (int i = len + 1; i <= n; i++) {       int l = 1, r = i - len + 1, ans = -1;       while (l < r) {         int mid = (l + r) >> 1;         if (ask(mid, i) <= s)           r = ans = mid;         else           l = mid + 1;       }       if ((ask(l, i) <= s) && ans == -1)         ans = l;       else if (ans != -1 && (ask(l, i) <= s))         ans = min(ans, l);       while (head < tail && q[tail - 1].first >= dp[i - len]) tail--;       q[tail++] = make_pair(dp[i - len], i - len);       if (ans != -1) {         while (head < tail && q[head].second < ans - 1) head++;         if (head < tail) dp[i] = min(dp[i], q[head].first + 1);       }     }     if (dp[n] != LARGEST)       cout << dp[n] << endl;     else       cout << -1 << endl;   }
#include <bits/stdc++.h>   const double PI = acos(-1.0);   using namespace std;   const int MAXN = 200117, MAXM = 1200117, C = 5, MAXX = 1000000120;   int n, k, a[MAXN], b, c, m, p[MAXM];   long long ans, s[C];   priority_queue<long long> q[C];   inline void add(int x) {     int rx = ((x % C) + C) % C;     for (int i = 0; i < C; i++) {       int d = c * ((i < rx) ? (C + i - rx) : (i - rx));       long long xx =           d + 1LL * b *                   (((MAXX + i) - (x + ((i < rx) ? (C + i - rx) : (i - rx)))) / C);       if (((int)(q[i]).size()) < k)         s[i] += xx, q[i].push(xx);       else if (q[i].top() > xx)         s[i] -= q[i].top() - xx, q[i].pop(), q[i].push(xx);     }   }   int main() {     scanf( %d %d %d %d , &n, &k, &b, &c);     b = min(b, 5 * c);     for (int i = 0; i < n; scanf( %d , &a[i++]))       ;     for (int i = 0; i < n; i++)       for (int j = 0; j <= 5; j++) p[m++] = a[i] + j;     sort(p, p + m);     m = unique(p, p + m) - p;     sort(a, a + n);     ans = (2117117117117117117LL);     for (int i = 0, j = 0; i < m; i++) {       for (; j < n && p[i] >= a[j]; add(a[j++]))         ;       int t = ((p[i] % C) + C) % C;       if (((int)(q[t]).size()) == k)         ans = min(ans, s[t] - 1LL * k * b * (((MAXX + t) - p[i]) / C));     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int po(long long int x, long long int y, long long int p) {     long long int res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y >>= 1;       x = (x * x) % p;     }     return res % p;   }   long long int modInverse(long long int n, long long int p) {     return po(n, p - 2, p);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int n;     cin >> n;     long long int cnt = 0;     for (long long int i = 1; i < n + 1; i++) {       long long int c = 0;       long long int x = i;       for (long long int j = 2; j * j <= i; j++) {         if (x % j == 0) {           c++;           while (x % j == 0) x /= j;         }       }       if (x != 1) c++;       if (c == 2) cnt++;     }     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   struct listNode {     long long int n;     listNode *next;     listNode(long long int n = 0LL) : n(n), next(NULL) {}   };   long long int num;   listNode *edge[100100], *tail[100100];   long long int color[100100];   void insertEdge(long long int a, long long int b) {     if (!edge[a]) {       edge[a] = new listNode(b);       tail[a] = edge[a];     } else {       tail[a]->next = new listNode(b);       tail[a] = tail[a]->next;     }   }   void dfs(long long int node, long long int parent, long long int &res0,            long long int &res1) {     long long int a, b, temp;     if (color[node]) {       res0 = 0LL;       res1 = 1LL;     } else {       res0 = 1LL;       res1 = 0LL;     }     for (listNode *ptr = edge[node]; ptr; ptr = ptr->next) {       if (ptr->n == parent) continue;       dfs(ptr->n, node, a, b);       if (color[node]) {         res1 *= (a + b);         if (res1 >= 1000000007) res1 %= 1000000007;       } else {         res1 *= (a + b);         if (res1 >= 1000000007) res1 %= 1000000007;         temp = res0 * b;         if (temp >= 1000000007) temp %= 1000000007;         res1 += temp;         if (res1 >= 1000000007) res1 %= 1000000007;         res0 *= (a + b);         if (res0 >= 1000000007) res0 %= 1000000007;       }     }   }   int main() {     long long int i, a, b;     scanf( %I64d , &num);     for (i = 1; i <= num - 1; i++) {       scanf( %I64d , &a);       insertEdge(i, a);       insertEdge(a, i);     }     for (i = 0; i < num; i++) scanf( %I64d , color + i);     dfs(0, 0, a, b);     printf( %I64d n , b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s1;     int tc;     cin >> tc;     getchar();     while (tc--) {       cin >> s1;       for (int i = 0; i < s1.length(); i += 2) {         cout << s1[i];       }       cout << s1[s1.size() - 1] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long row1[n], row2[n];     for (int i = 0; i < n; i++) cin >> row1[i];     for (int i = 0; i < n; i++) cin >> row2[i];     long long first, second, pref = 0, pres = 0;     for (int i = 0; i < n; i++) {       first = max(pref, pres + row1[i]);       second = max(pres, pref + row2[i]);       pref = first;       pres = second;     }     cout << max(pref, pres);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int a[n], i, j, ans = 1;       int c[201][n + 1];       vector<int> v[201];       memset(c, 0, sizeof(c));       for (i = 0; i < n; i++) {         cin >> a[i];         v[a[i]].push_back(i);         c[a[i]][i + 1]++;       }       for (i = 1; i <= 200; i++) {         for (j = 1; j <= n; j++) c[i][j] += c[i][j - 1];         ans = max(ans, c[i][n]);       }       for (i = 1; i <= n / 2; i++) {         for (j = 1; j <= 200; j++) {           int l = v[j].size();           if (2 * i <= l) {             for (int k = 1; k <= 200; k++)               ans = max(ans, 2 * i + c[k][v[j][l - i]] - c[k][v[j][i - 1] + 1]);           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   const int maxn = 100010;   char s[maxn];   int main() {     int a = 0, b = 0, c = 0, i;     scanf( %s , s);     int len = strlen(s);     if (s[0] ==  )  || s[len - 1] ==  (  || s[0] ==  # ) {       printf( -1 n );       return 0;     }     for (i = len - 1; i >= 0; i--) {       if (s[i] ==  ( ) a++;       if (s[i] ==  ) ) b++;       if (a > b) {         printf( -1 n );         return 0;       }       if (s[i] ==  # ) break;     }     a = 0, b = 0;     for (i = 0; i < len; i++) {       if (s[i] ==  ( ) a++;       if (s[i] ==  ) ) {         if (s[i - 1] ==  ( ) {           s[i - 1] =  . ;           s[i] =  . ;           b--;           a--;         }         b++;       }       if (s[i] ==  # ) {         b++;         c++;       }       if (b > a) {         printf( -1 n );         return 0;       }     }     b -= c;     if (a - b < c) {       printf( -1 n );       return 0;     }     a = 0;     for (i = 0; i < len; i++) {       if (s[i] ==  ( ) a++;       if (s[i] ==  ) ) {         b--;         a--;       }       if (s[i] ==  # ) {         if (c > 1) {           printf( 1 n );           a--;           c--;         } else           printf( %d n , a - b);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int min(int a, int b) {     if (a > b)       return b;     else       return a;   }   int main() {     int tc;     cin >> tc;     while (tc--) {       long long int n;       cin >> n;       vector<int> a(n + 1, 0);       vector<int> ans(n + 1, 0);       for (int i = 1; i <= n; i++) {         cin >> a[i];       }       vector<int> ones;       vector<int> zeros;       ;       string s;       cin >> s;       int one = 0;       for (int i = 0; i < n; i++) {         if (s[i] ==  1 ) {           ones.push_back(a[i + 1]);         } else           zeros.push_back(a[i + 1]);       }       int k = ones.size();       int max = n - k;       sort(ones.begin(), ones.end());       sort(zeros.begin(), zeros.end());       map<int, int> m;       map<int, int> p;       int j = n;       for (int i = k - 1; i >= 0; i--) {         m[ones[i]] = j;         j--;       }       for (int i = 0; i < max; i++) {         p[zeros[i]] = i + 1;       }       for (int i = 1; i <= n; i++) {         if (s[i - 1] ==  0 ) {           ans[i] = p[a[i]];         } else {           ans[i] = m[a[i]];         }       }       for (int i = 1; i <= n; i++) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<vector<int> > D;   int main(int argc, char **argv) {     cin >> n >> m;     for (int i = 0; i < n; i++) {       string t;       cin >> t;       D.push_back(vector<int>());       for (int j = 0; j < m; j++) {         D[D.size() - 1].push_back(t[j] ==  1 );       }     }     int c0[400][400], c1[400][400];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int k;         for (k = 0;; k++) {           if (i + k >= n || j + k >= m || D[i + k][j + k]) break;         }         c0[i][j] = k;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         int k;         for (k = 0;; k++) {           if (i + k >= n || j - k < 0 || D[i + k][j - k]) break;         }         c1[i][j] = k;       }     int s = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         if (D[i][j]) continue;         for (int k = 1;; k++) {           if (j + k >= m || i + k >= n || D[i][j + k] || D[i + k][j]) break;           if (c1[i][j + k] > k) s += 1;         }         for (int k = 1;; k++) {           if (j - k < 0 || i + k >= n || D[i][j - k] || D[i + k][j]) break;           if (c0[i][j - k] > k) s += 1;         }         for (int k = 1;; k++) {           if (j + k >= m || i - k < 0 || D[i][j + k] || D[i - k][j]) break;           if (c0[i - k][j] > k) s += 1;         }         for (int k = 1;; k++) {           if (j - k < 0 || i - k < 0 || D[i][j - k] || D[i - k][j]) break;           if (c1[i - k][j] > k) s += 1;         }         for (int k = 1;; k++) {           if (i + k >= n || j + k >= m || j - k < 0 || D[i][j + k] || D[i][j - k])             break;           if (c0[i][j - k] > k && c1[i][j + k] > k) s += 1;         }         for (int k = 1;; k++) {           if (i - k < 0 || j + k >= m || j - k < 0 || D[i][j + k] || D[i][j - k])             break;           if (c0[i - k][j] > k && c1[i - k][j] > k) s += 1;         }         for (int k = 1;; k++) {           if (i - k < 0 || i + k >= n || j + k >= m || D[i - k][j] || D[i + k][j])             break;           if (c0[i - k][j] > k && c1[i][j + k] > k) s += 1;         }         for (int k = 1;; k++) {           if (i - k < 0 || i + k >= n || j - k >= m || D[i - k][j] || D[i + k][j])             break;           if (c0[i][j - k] > k && c1[i - k][j] > k) s += 1;         }       }     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 111;   const int INF = (int)1e9;   const int mod = (int)1e9 + 7;   int n, m;   vector<int> v[N];   int get(int i, int j) {     if (i > j) swap(i, j);     int s = j - i;     s = min(s, m - s);     return s;   }   int get_res(int x, int y) {     auto left = v[y].begin(), right = v[y].end();     --right;     int s = get(x, *left);     s = min(s, get(x, *right));     auto it = upper_bound(v[y].begin(), v[y].end(), x);     if (it != v[y].end()) {       s = min(s, get(x, *it));     }     if (it != v[y].begin()) {       --it;       s = min(s, get(x, *it));     }     return s;   }   int main() {     scanf( %d%d n , &n, &m);     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         char x;         x = getchar();         if (x ==  1 ) v[i].push_back(j);       }       scanf(  n );     }     int ans = (int)1e9;     for (int j = 0; j < m; ++j) {       int res = 0;       for (int i = 0; i < n; ++i) {         if (!v[i].size()) {           puts( -1 );           return 0;         }         res += get_res(j, i);       }       ans = min(ans, res);     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   int read() {     register int x = 0;     register char f = 1, ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = !f;     for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^  0 );     return f ? x : -x;   }   int n, fac[200005], dp[200005], sz[200005];   int edge, to[200005 << 1], pr[200005 << 1], hd[200005];   void addedge(int u, int v) { to[++edge] = v, pr[edge] = hd[u], hd[u] = edge; }   void dfs(int u, int fa = 0) {     sz[u] = 1, dp[u] = 1;     int d = 0;     for (register int i = hd[u], v; i; i = pr[i])       if ((v = to[i]) != fa)         dfs(v, u), sz[u] += sz[v], ++d, dp[u] = 1ll * dp[u] * dp[v] % 998244353;     if (!fa)       dp[u] = 1ll * n * dp[u] % 998244353 * fac[d] % 998244353;     else       dp[u] = 1ll * (d + 1) * dp[u] % 998244353 * fac[d] % 998244353;   }   int main() {     n = read();     for (register int i = 1, u, v; i < n; ++i)       u = read(), v = read(), addedge(u, v), addedge(v, u);     fac[0] = 1;     for (register int i = 1; i <= n; ++i)       fac[i] = 1ll * fac[i - 1] * i % 998244353;     dfs(1);     printf( %d n , dp[1]);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 4;   int n, k, a[N];   bool used[N], inStack[N];   set<int> s;   set<int> q;   void add(int& it) {     if (s.size() && *s.begin() < a[it]) {       cout << -1;       exit(0);     }     inStack[a[it]] = 1;     used[a[it]] = 1;     s.insert(a[it]);     ++it;   }   void sovle() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       q.insert(i);     }     for (int i = 0; i < k; ++i) {       cin >> a[i];       used[a[i]] = 1;       q.erase(a[i]);     }     int it = 0;     for (int i = 1; i <= n;) {       if (used[i]) {         if (inStack[i]) {           int top = *s.begin();           if (top != i) {             cout << -1;             exit(0);           } else {             s.erase(top);             ++i;           }         } else {           add(it);         }       } else {         if (it < k) {           add(it);         } else {           if (s.empty()) {             a[it] = *q.rbegin();             add(it);             q.erase(*q.rbegin());           } else {             auto findIt = q.lower_bound(*s.begin());             if (findIt == q.begin()) {               cout << -1;               exit(0);             } else {               --findIt;               a[it] = *findIt;               add(it);               q.erase(findIt);             }           }         }       }     }     for (int i = 0; i < n; ++i) {       cout << a[i] <<    ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cout.tie(0);     cin.tie(0);     sovle();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int MAXN = 100;   int cnt[MAXN];   int pre[MAXN];   ll fact[MAXN];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     fact[0] = 1;     for (int i = 1; i < MAXN; i++) {       fact[i] = fact[i - 1] * i;     }     int kase;     cin >> kase;     while (kase--) {       memset(cnt, 0, sizeof(cnt));       memset(pre, 0, sizeof(pre));       ll n;       cin >> n;       int idx = 2;       while (n) {         cnt[n % idx]++;         n /= idx;         idx++;       }       pre[0] = cnt[0];       for (int i = 1; i <= idx; i++) {         pre[i] = pre[i - 1] + cnt[i];       }       ll same = 1;       for (int i = 0; i < idx; i++) {         same *= fact[cnt[i]];       }       ll ans = 1;       idx--;       for (int i = 1; i < idx; i++) {         ans *= (pre[i] - i + 1);       }       ll cost = pre[0];       for (int i = 0; i < idx; i++) {         pre[i]--;       }       for (int i = 1; i < idx - 1; i++) {         cost *= (pre[i] - i + 1);       }       cout << (ans - cost) / same - 1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int d[5001];   int t[5001];   int l[5001];   int r[5001];   int x[5001];   vector<int> cl, cr, num, cx;   int eksi[5001];   int ek[5001][5001];   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> m;     for (int i = 1; i <= n; i++) d[i] = 1000000000;     for (int ad = 1; ad <= m; ad++) {       cin >> t[ad] >> l[ad] >> r[ad] >> x[ad];       if (t[ad] == 1)         for (int i = l[ad]; i <= r[ad]; i++) eksi[i] += x[ad];       else {         int ma = -1000000000;         for (int i = l[ad]; i <= r[ad]; i++) ma = max(ma, d[i] + eksi[i]);         if (ma < x[ad]) {           cout <<  NO  << endl;           return 0;         } else           for (int i = l[ad]; i <= r[ad]; i++)             if (d[i] > x[ad] - eksi[i]) d[i] = x[ad] - eksi[i];       }     }     for (int i = 1; i <= n; i++) eksi[i] = d[i];     for (int i = 1; i <= m; i++) {       if (t[i] == 1) {         for (int j = l[i]; j <= r[i]; j++) eksi[j] += x[i];       } else if (t[i] == 2) {         int ma = -1000000000;         for (int j = l[i]; j <= r[i]; j++) ma = max(ma, eksi[j]);         if (x[i] != ma) {           cout <<  NO  << endl;           return 0;         }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= n; i++) cout << d[i] <<    ;     cout << endl;     return 0;   }