malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000007;   int ans, K, n;   vector<int> s[101010];   int fa[101010], f[101010][222][3], g[222][3], sz[101010], jc[222], S[222][222];   void dfs(int x) {     int c, i, y, j, k;     sz[x] = 1;     f[x][0][0] = 1;     c = s[x].size();     for (i = 0; i < c; i++) {       y = s[x][i];       if (fa[x] == y) continue;       fa[y] = x;       dfs(y);       for (j = 0; j <= min(K, sz[x] - 1); j++)         for (k = 0; k <= 2; k++) g[j][k] = f[x][j][k];       for (j = 0; j <= min(K, sz[x] - 1); j++)         for (k = 0; k <= min(K, sz[y] - 1); k++) {           if (j + k <= K) {             f[x][j + k][1] =                 (f[x][j + k][1] + (long long)g[j][0] * f[y][k][0] % INF) % INF;             f[x][j + k][2] =                 (f[x][j + k][2] + (long long)g[j][1] * f[y][k][0] % INF) % INF;             f[x][j + k][2] =                 (f[x][j + k][2] + (long long)g[j][2] * f[y][k][0] % INF) % INF;           }           if (j + k + 1 <= K) {             f[x][j + k + 1][1] =                 (f[x][j + k + 1][1] + (long long)g[j][0] * f[y][k][0] % INF) %                 INF;             f[x][j + k + 1][2] =                 (f[x][j + k + 1][2] + (long long)g[j][1] * f[y][k][0] % INF) %                 INF;             f[x][j + k + 1][2] =                 (f[x][j + k + 1][2] + (long long)g[j][2] * f[y][k][0] % INF) %                 INF;           }         }       sz[x] += sz[y];     }     for (i = 0; i <= min(K, sz[x] - 1); i++)       ans = (ans + (long long)jc[i] * S[K][i] % INF *                        (f[x][i][2] * 2 % INF + (f[x][i][1] + f[x][i][0]) % INF) %                        INF) %             INF,       f[x][i][0] =           ((long long)f[x][i][0] + f[x][i][1] * 2 + f[x][i][2] * 2) % INF;   }   int main() {     int i, x, y, j;     scanf( %d%d , &n, &K);     for (i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       s[x].push_back(y);       s[y].push_back(x);     }     jc[0] = 1;     S[0][0] = 1;     for (i = 1; i <= K; i++) {       jc[i] = (long long)jc[i - 1] * i % INF;       S[i][0] = 0;       for (j = 1; j <= i; j++)         S[i][j] = (S[i - 1][j - 1] + (long long)S[i - 1][j] * j % INF) % INF;     }     dfs(1);     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 212345, LG = 21, mod = 1000000007;   const double eps = 1e-3, pi = acos(-1.0);   char s[5], t[5], a[3];   int main() {     long long n, k;     scanf( %lld , &n), scanf( %lld , &k);     if (n / 2 > k) {       printf( %lld n , k * (2 * k - 1) + (n - 2 * k) * 2 * k);     } else {       printf( %lld n , (n * (n - 1)) / 2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     map<string, string> m;     int q;     cin >> q;     int i;     string s1, s2;     while (q--) {       cin >> s1 >> s2;       if (m.count(s1) == 0)         m[s2] = s1;       else {         m[s2] = m[s1];         m.erase(s1);       }     }     cout << m.size() << endl;     map<string, string>::iterator it;     for (it = m.begin(); it != m.end(); it++)       cout << it->second <<     << it->first << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     x = x > y ? x : y;   }   template <typename T>   void chkmin(T &x, T y) {     x = x > y ? y : x;   }   const int INF = 2139062143;   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 0;     } while (ch >  9  || ch <  0 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     x = f ? x : -x;   }   template <typename T>   void write(T x) {     if (x < 0) x = ~x + 1, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 1000 + 5;   const int mod = 998244353;   int n, k, ans, a[N], f[N][N], s[N][N];   int main() {     read(n);     read(k);     for (int i = 1; i <= n; i++) read(a[i]);     sort(a + 1, a + n + 1);     a[0] = -INF;     for (int v = 1; v * (k - 1) <= a[n]; v++) {       f[0][0] = s[0][0] = 1;       int now = 0;       for (int i = 1; i <= n; i++) {         while (a[i] - a[now] >= v) now++;         f[i][0] = 0;         s[i][0] = (s[i - 1][0] + f[i][0]) % mod;         for (int j = 1; j <= k; j++) {           f[i][j] = s[now - 1][j - 1];           s[i][j] = (s[i - 1][j] + f[i][j]) % mod;         }       }       ans = (ans + 1ll * s[n][k]) % mod;     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   const long long INF = 1e18;   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     long long n, r1, r2, r3, d;     cin >> n >> r1 >> r2 >> r3 >> d;     vector<long long> a(n), x(n), y(n);     vector<vector<long long>> dp(n + 1, vector<long long>(2, INF));     dp[0][0] = 0;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       x[i] = a[i] * r1 + r3;       y[i] = min(r1 + r2, (a[i] + 2) * r1);       y[i] = min(y[i], x[i]);     }     for (long long i = 0; i < n; i++) {       dp[i + 1][0] = min(dp[i][0] + x[i], dp[i][1] + y[i] + d);       dp[i + 1][1] = dp[i][0] + y[i] + d;       if (i == n - 1) dp[i + 1][0] = min(dp[i + 1][0], dp[i][1] + x[i]);     }     long long ans = min(dp[n][0], dp[n][1] + d);     ans += d * (n - 1);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, c, l = 0, t, ans = 0;     cin >> n >> c;     for (int i = 0; i < n; i++) {       cin >> t;       if (l) {         long long x = min(t, c - l);         l += x;         t -= x;       }       ans += t / c + (l != 0);       l = t % c;     }     ans += l != 0;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char ch[1000100];   int l;   void dfs(int k) {     if (k >= l) return;     if (ch[k] ==  l ) {       dfs(k + 1);       printf( %d n , k + 1);     } else {       printf( %d n , k + 1);       dfs(k + 1);     }   }   int main() {     scanf( %s , ch);     l = strlen(ch);     dfs(0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = (int)1e9;   int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1};   int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};   long long n, x, y;   bool ok;   map<long long, long long> cnt;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> x;       for (int j = 0; j < x; j++) {         cin >> y;         cnt[y]++;       }     }     for (int i = 1; i <= 100; i++) {       if (cnt[i] == n) {         cout << i <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 12 + 1, M = 1 << N | 5;   bool dp1[M][N + N], dp2[M][N + N];   int n, k, mx[M], c[N + N];   int main() {     cin >> n;     dp1[0][1] = true;     for (int i = 0; i < n; i++) {       cin >> c[i];       if (c[i] < 2) n--, k++, i--;     }     if (n > k) return cout <<  NO , 0;     for (int i = 1; i <= k; i++) {       dp1[0][i] = true;       dp2[0][i] = (i > 1);     }     for (int i = 0; i < n; i++) dp1[1 << i][c[i] - 1] = (c[i] > 2);     for (int i = 1; i < 1 << n; i++) {       int &u = mx[i] = __builtin_ctz(i);       if (i ^ i & -i && c[u] < c[mx[i ^ i & -i]]) u = mx[i ^ i & -i];       for (int j = 1; j <= k; j++)         for (int x = i; x; --x &= i)           for (int y = 0; y <= j; y++) {             if (~x >> u & 1 && c[u] == __builtin_popcount(i) + j)               dp1[i][j] |= dp1[x][y] && (dp1[i ^ x ^ 1 << u][j - y] ||                                          dp2[i ^ x ^ 1 << u][j - y]);             dp2[i][j] |= dp1[x][y] && (dp1[i ^ x][j - y] || dp2[i ^ x][j - y]);           }     }     cout << (dp1[(1 << n) - 1][k] ?  YES  :  NO );   }
#include <bits/stdc++.h>   int a[3005];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     int cnt = 0;     for (int i = 1; i < n; ++i)       for (int j = 0; j < i; ++j)         if (a[i] < a[j]) ++cnt;     if (cnt & 1)       printf( %d , cnt * 2 - 1);     else       printf( %d , 2 * cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int M = 1000000007;   int n;   int dp[1000010];   int main() {     while (~scanf( %d , &n)) {       int a = 0;       for (int i = 1; i <= n; i++) {         int x;         scanf( %d , &x);         if (x == 1) a++;       }       dp[0] = dp[1] = 1;       for (int i = 2; i <= a; i++)         dp[i] = (dp[i - 1] + (long long)dp[i - 2] * (i - 1)) % M;       int ans = dp[a];       for (int i = a + 1; i <= n; i++) ans = (long long)ans * i % M;       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int MOD = 1e9 + 7;   const int MAXN = 3e5 + 5;   const double PI = acos(-1);   long long a[MAXN][2];   long long dp[MAXN][2][2];   int main(void) {     int n, x;     scanf( %d%d , &n, &x);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i][0]);       a[i][1] = a[i][0] * x;     }     dp[0][0][1] = 0;     dp[0][1][1] = 0;     dp[0][0][0] = 0;     dp[0][1][0] = 0;     long long ans = 0;     for (int i = 1; i <= n; i++) {       dp[i][0][0] = max(1ll * a[i][0], dp[i - 1][0][0] + 1ll * a[i][0]);       dp[i][1][1] = max(1ll * a[i][1], dp[i - 1][1][1] + 1ll * a[i][1]);       dp[i][1][0] = max(a[i][0], dp[i - 1][1][1] + 1ll * a[i][0]);       dp[i][1][0] = max(dp[i][1][0], dp[i - 1][1][0] + 1ll * a[i][0]);       dp[i][1][0] = max(dp[i][1][0], dp[i - 1][0][1] + 1ll * a[i][0]);       dp[i][0][1] = max(a[i][1], dp[i - 1][0][1] + 1ll * a[i][1]);       dp[i][0][1] = max(dp[i][0][1], dp[i - 1][0][0] + a[i][1]);       ans = max(ans, dp[i][0][1]);       ans = max(ans, dp[i][0][0]);       ans = max(ans, dp[i][1][1]);       ans = max(ans, dp[i][1][0]);     }     printf( %lld n , ans);   }
#include <bits/stdc++.h>   using namespace std;   struct P {     int x, y, z;     bool operator<(const P &a) const { return y > a.y; };   };   int a, b, c, d, i, k, n, m, e, dx[10] = {1, 0, -1, 0, 1, 1, -1, -1},                                  dy[10] = {0, 1, 0, -1, 1, -1, 1, -1};   long long o[500101];   int l[500111];   int j[201001];   long long x, y, z, mod = 998244353;   string r;   P u[500101];   queue<int> q;   stack<int> s;   map<int, int> p;   vector<int> v;   bool as(P a, P b) {     if (a.x != b.x) return a.x < b.x;     return a.y > b.y;   }   int main() {     scanf( %d %d %d , &a, &b, &c);     for (int t = 1; t <= c; t++) {       scanf( %d %d %d , &n, &m, &k);       u[t] = {n, m, k};     }     sort(u + 1, u + c + 1, as);     z = 1;     for (int i = 0; i < b; i++) {       e = 0;       for (int t = 1; t <= a + 1; t++) l[t] = o[t] = 0;       for (int t = 1; t <= c; t++)         if (u[t].z & (1 << i)) {           int p;           for (p = max(e + 1, u[t].x); p <= u[t].y; p++) l[p] = 1;           e = p - 1;         }       e = a + 1;       n = a;       o[a + 1] = 1;       x = 1;       for (int t = c; t; t--)         if ((u[t].z & (1 << i)) == 0 && u[t].x <= n) {           for (; n > u[t].y; n--)             if (!l[n]) o[n] = x, x *= 2, x %= mod;           for (; n >= u[t].x; n--)             if (!l[n]) {               o[n] = x, x *= 2, x %= mod;             }           for (; e > u[t].y; e--) x = (x - o[e] + mod) % mod;         }       for (; n >= 1; n--)         if (!l[n]) x *= 2, x %= mod;       z *= x, z %= mod;     }     printf( %lld , z);   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       ll a, b, n;       cin >> a >> b >> n;       ll cnt = 0;       if (a > b) swap(a, b);       while (max(a, b) <= n) {         a += b;         if (a > b) {           swap(a, b);         }         cnt++;       }       cout << cnt <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n, k;     cin >> n >> k;     long long int arr[n];     long long int i;     for (i = 0; i < n; i++) cin >> arr[i];     double ma = 0.0;     for (i = k; i <= n; i++) {       double s = 0.0;       int j;       for (j = 0; j < i; j++) s += arr[j];       ma = max(ma, s / i);       for (j = i; j < n; j++) {         s -= arr[j - i];         s += arr[j];         ma = max(ma, s / i);       }     }     cout << fixed << setprecision(20) << ma;   }
#include <bits/stdc++.h>   using namespace std;   const long double INF = 1e18 + 7;   long long N = 1e6 * 5;   long double EPS = 1 / 1e18;   long long a[1005];   map<long long, long long> cnt;   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t;     cin >> t;     for (long long i = 0; i < t; i++) {       long long k = 0, err = 0, n;       cin >> n;       for (long long j = 2; j <= round(sqrt(n)); j++) {         if (!(n % j)) {           a[k++] = j;           cnt[j]++;           a[k++] = n / j;           cnt[n / j]++;         }       }       for (long long i = 0; i < k; i++) {         for (long long j = 0; j < k; j++) {           if (!(a[i] % a[j]) && cnt[a[i] / a[j]] != 0 && a[j] != n / a[i] &&               a[j] != a[i] / a[j] && n / a[i] != a[i] / a[j]) {             cout <<  YES n                   << a[j] <<     << a[i] / a[j] <<     << n / a[i] <<   n ;             err = 1;             break;           }         }         if (err) break;       }       if (!err) cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     for (int cas = 0; cas < t; cas++) {       int n;       cin >> n;       vector<int> numbers(n);       int sum = 0;       int zer = 0;       int ans;       for (int i = 0; i < n; i++) {         cin >> numbers[i];         sum = sum + numbers[i];         if (numbers[i] == 0) zer++;       }       if (sum > 0) {         ans = zer;       } else if (sum < 0) {         if (sum == -zer) {           ans = zer + 1;         } else {           ans = zer;         }       } else {         if (zer == 0) {           ans = 1;         } else {           ans = zer;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char c[55][55];   int n, i, j, m1, m2, m3, m4;   int main() {     scanf( %d , &n);     for (i = 1; i <= n; i++) scanf( %s , c[i] + 1);     m1 = m3 = n + 1;     for (i = 1; i <= n; i++)       for (j = 1; j <= n; j++)         if (c[i][j] ==  4 ) {           m1 = min(m1, i);           m2 = max(m2, i);           m3 = min(m3, j);           m4 = max(m4, j);         }     for (i = m1; i <= m2; i++) {       for (j = m3; j <= m4; j++)         if (c[i][j] !=  4 ) break;       if (j <= m4) break;     }     if (i <= m2) {       puts( No );       return 0;     }     for (i = 1; i <= n; i++) {       for (j = 1; j <= n; j++)         if (c[i][j] !=  0  &&             (i < m1 - 1 || i > m2 + 1 || j < m3 - 1 || j > m4 + 1))           break;       if (j <= n) break;     }     if (i <= n) {       puts( No );       return 0;     }     for (i = m1; i <= m2; i++)       if (m3 > 1 && c[i][m3 - 1] !=  2  || m4 < n && c[i][m4 + 1] !=  2 ) break;     if (i <= m2) {       puts( No );       return 0;     }     for (i = m3; i <= m4; i++)       if (m1 > 1 && c[m1 - 1][i] !=  2  || m2 < n && c[m2 + 1][i] !=  2 ) break;     if (i <= m4) {       puts( No );       return 0;     }     if (m1 > 1 && m3 > 1 && c[m1 - 1][m3 - 1] !=  1  ||         m1 > 1 && m4 < n && c[m1 - 1][m4 + 1] !=  1  ||         m2 < n && m3 > 1 && c[m2 + 1][m3 - 1] !=  1  ||         m2 < n && m4 < n && c[m2 + 1][m4 + 1] !=  1 ) {       puts( No );       return 0;     }     puts( Yes );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct debugger {     template <typename T>     debugger& operator,(const T& v) {       cerr << v <<    ;       return *this;     }   } dbg;   int main() {     int T;     cin >> T;     while (T--) {       char c;       int x1 = -1, y1 = -1, x2 = -1, y2 = -1;       for (int i = (0), _n = (8); i < _n; i++) {         for (int j = (0), _n = (8); j < _n; j++) {           cin >> c;           if (c ==  K  && (x1 == -1 && y1 == -1)) {             x1 = i;             y1 = j;           } else if (c ==  K  && (x2 == -1 && y2 == -1)) {             x2 = i;             y2 = j;           }         }       }       int a = abs(x2 - x1);       int b = abs(y2 - y1);       if (a % 4 == 0 && b % 4 == 0)         cout <<  YES n ;       else         cout <<  NO n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 7;   char s[maxn];   int fa[maxn], siz[maxn];   int l[maxn][2];   int n, k;   int findset(int x) {     if (fa[x] == x) return x;     return fa[x] = findset(fa[x]);   }   void Union(int x, int y) {     int rx = findset(x), ry = findset(y);     if (!ry) swap(rx, ry);     if (rx) siz[rx] += siz[ry];     fa[ry] = rx;   }   int cal(int x) {     int y = x <= k ? x + k : x - k;     x = findset(x), y = findset(y);     if (!x || !y) return siz[x + y];     return min(siz[x], siz[y]);   }   int main() {     scanf( %d%d , &n, &k);     scanf( %s , s + 1);     for (int i = 1; i <= k; i++) {       int m;       scanf( %d , &m);       for (int j = 1; j <= m; j++) {         int x;         scanf( %d , &x);         if (l[x][0] == 0)           l[x][0] = i;         else           l[x][1] = i;       }       siz[i] = 1;       fa[i] = i;       fa[i + k] = i + k;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int x = l[i][0], y = l[i][1];       int rx = findset(x), ry = findset(y);       int rxk = findset(x + k), ryk = findset(y + k);       if (!y) {         ans -= cal(x);         if (s[i] ==  1 ) fa[rx] = 0;         if (s[i] ==  0 ) fa[rxk] = 0;         ans += cal(x);       } else if (s[i] ==  0  && rx != ryk) {         ans -= cal(x);         ans -= cal(y);         Union(x, y + k);         Union(y, x + k);         ans += cal(x);       } else if (s[i] ==  1  && rx != ry) {         ans -= cal(x);         ans -= cal(y);         Union(x, y);         Union(x + k, y + k);         ans += cal(x);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using P = pair<ll, ll>;   using PP = pair<ll, P>;   using VB = vector<bool>;   using VI = vector<ll>;   using VS = vector<string>;   using VC = vector<char>;   using VP = vector<P>;   using VPP = vector<PP>;   using VD = vector<double>;   using VVI = vector<VI>;   using VVP = vector<VP>;   using VVC = vector<VC>;   using VVB = vector<VB>;   using VVVI = vector<VVI>;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < k; i++) {       if (n % 10 == 0)         n /= 10;       else         n--;     }     cout << n << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100100, M = 32401000, S = 90, oo = 1000000000;   int i, j, k, n, m, ch, ff;   int s[N];   int F[M];   void R(int &x) {     ff = x = 0;     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) ff = 1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = getchar();     if (ff) x = -x;   }   int P(int l, int r, int k) {     int t = 0;     l--;     r--;     k--;     t = (l * S * 2 + n - r - l + S) * S + k;     return t;   }   int min(const int &x, const int &y) {     if (x < y) return x;     return y;   }   int max(const int &x, const int &y) {     if (x > y) return x;     return y;   }   int f(int l, int r, int k, int o) {     if (r - l + 1 < k) return 0;     if (o == 1) {       int ans = f(l, r - k, k, 0) - s[r] + s[r - k];       if (r - l + 1 >= k + 1)         ans = min(ans, f(l, r - k - 1, k + 1, 0) - s[r] + s[r - k - 1]);       return ans;     } else {       int t = P(l, r, k);       if (F[t] < oo) return F[t];       int ans;       ans = s[l + k - 1] - s[l - 1] + f(l + k, r, k, 1);       if (r - l + 1 >= k + 1)         ans = max(ans, s[l + k] - s[l - 1] + f(l + k + 1, r, k + 1, 1));       return F[t] = ans;     }   }   int main() {     memset(F, 60, sizeof F);     R(n);     for (i = 1; i <= n; i++) R(s[i]), s[i] += s[i - 1];     printf( %d n , f(1, n, 1, 0));   }
#include <bits/stdc++.h>   inline int getx() {     char c;     int x;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       ;     for (x = 0; c >=  0  && c <=  9 ; c = getchar())       x = (x << 3) + (x << 1) + c -  0 ;     return x;   }   bool upmax(int &a, const int &b) { return a < b ? a = b, 1 : 0; }   const int MAX_N = 10050;   int n, m;   int v[MAX_N], c[MAX_N];   int f[MAX_N];   int main() {     n = getx(), m = getx();     int c0 = getx(), d0 = getx();     for (int i = c0; i <= n; ++i) upmax(f[i], f[i - c0] + d0);     for (int i = 1; i <= m; ++i) {       int a = getx(), b = getx(), c = getx(), d = getx();       for (int p = b; p <= a; p += b) {         for (int j = n; j >= c; --j) upmax(f[j], f[j - c] + d);       }     }     printf( %d n , f[n]);   }
#include <bits/stdc++.h>   using namespace std;   struct guy {     int x;     int y;     int t;   };   int r, n;   vector<guy> arr;   vector<int> dp;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> r >> n;     arr = vector<guy>(n);     dp = vector<int>(n, 0);     for (int i = 0; i < n; i++) {       cin >> arr[i].t >> arr[i].x >> arr[i].y;     }     for (int i = n - 1; i >= 0; i--) {       for (int j = i + 1; j < min(n, i + 4 * r); j++) {         if (abs(arr[j].y - arr[i].y) + abs(arr[j].x - arr[i].x) <=             arr[j].t - arr[i].t)           dp[i] = max(dp[i], 1 + dp[j]);       }     }     int ans = 0;     for (int i = 0; i < n; i++) {       if (abs(1 - arr[i].y) + abs(1 - arr[i].x) <= arr[i].t) {         ans = max(ans, 1 + dp[i]);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INFint = 2e9;   const long long INF = 1e18;   const long long MOD = 1000000007ll;   int g[100][100];   vector<int> used;   set<int> roots;   int n, m;   void dfs(int v, int p) {     used[v] = 1;     for (int i = 0; i < n; i++) {       if (i == p || !g[v][i]) continue;       if (used[i] || roots.count(i)) {         cout <<  NO ;         exit(0);       }       dfs(i, v);     }     used[v] = 1;   }   vector<int> anc;   void addCycle(int st, int en) {     int v = en;     while (v != st) {       roots.insert(v);       v = anc[v];     }     roots.insert(st);   }   bool cycle(int v, int p = -1) {     used[v] = 1;     for (int i = 0; i < n; i++) {       if (i == p || !g[v][i]) continue;       if (used[i]) {         addCycle(i, v);         return 1;       }       anc[i] = v;       if (cycle(i, v)) return 1;     }     used[v] = 1;     return 0;   }   vector<int> p;   int get(int v) { return p[v] == v ? v : p[v] = get(p[v]); }   void unite(int a, int b) {     a = get(a);     b = get(b);     if (a == b) return;     if (rand() & 1) swap(a, b);     p[a] = b;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m;     used.resize(n);     p.resize(n);     for (int i = 0; i < n; i++) p[i] = i;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       a--, b--;       unite(a, b);       g[a][b] = g[b][a] = 1;     }     int cnt = 0;     for (int i = 0; i < n; i++)       if (p[i] == i) cnt++;     if (cnt != 1) {       cout <<  NO ;       return 0;     }     anc.resize(n);     for (int i = 0; i < n; i++) {       if (!used[i]) {         if (cycle(i)) break;       }     }     if (roots.size() < 3) {       cout <<  NO ;       return 0;     }     used.assign(n, 0);     for (auto v : roots) {       for (int i = 0; i < n; i++) {         if (g[v][i] && !roots.count(i)) {           dfs(i, v);         }       }     }     cout <<  FHTAGN! ;     fprintf(stderr,   nTIME = %lf n , 1.0 * clock() / CLOCKS_PER_SEC);     ;     return 0;   }