malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10, P = 998244353;   const double Pi = acos(-1);   inline int read() {     int x = 0, f = 1, ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) x = x * 10 + ch - 48, ch = getchar();     return x * f;   }   inline int Add(int a, int b) { return a + b >= P ? a + b - P : a + b; }   inline int Sub(int a, int b) { return a - b < 0 ? a - b + P : a - b; }   inline int Mul(int a, int b) {     long long res = 1ll * a * b;     return res >= P ? res % P : res;   }   inline int qpow(int a, int b) {     int res = 1;     while (b) {       if (b & 1) res = Mul(res, a);       a = Mul(a, a);       b >>= 1;     }     return res;   }   int n;   int dp[3][N];   int cnt, head[N];   struct Edge {     int to, nxt;   } edge[N << 1];   inline void AddEdge(int u, int v) {     edge[++cnt] = (Edge){v, head[u]};     head[u] = cnt;     return;   }   void solve(int u, int fa) {     dp[0][u] = dp[2][u] = 1;     for (int i = head[u], v; i; i = edge[i].nxt) {       v = edge[i].to;       if (v == fa) continue;       solve(v, u);       dp[0][u] = Mul(dp[0][u], Add(dp[0][v], dp[1][v]));       dp[1][u] = Add(dp[1][u],                      Mul(dp[2][v], qpow(Add(dp[0][v], Mul(2, dp[1][v])), P - 2)));       dp[2][u] = Mul(dp[2][u], Add(dp[0][v], Mul(2, dp[1][v])));     }     dp[1][u] = Mul(dp[1][u], dp[2][u]);   }   signed main() {     n = read();     for (register int i = 2; i <= n; ++i) {       int a = read(), b = read();       AddEdge(a, b), AddEdge(b, a);     }     solve(1, 0);     printf( %d n , Add(dp[0][1], dp[1][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1 << 22;   bool visit[2][N];   int main() {     int n, m;     cin >> n >> m;     for (int i = 0; i < N; i++) {       visit[0][i] = 1;     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       visit[0][x] = 0;     }     int ans = 0;     for (int i = 0; i < (1 << n); i++) {       if (visit[0][i]) continue;       visit[0][i] = 1;       ans++;       if (!visit[1][i]) {         visit[1][i] = 1;         queue<int> q;         q.push(i);         while (q.size()) {           int v = q.front();           q.pop();           if (visit[0][(1 << n) - v - 1] == 0) {             visit[0][(1 << n) - v - 1] = 1;             visit[1][(1 << n) - v - 1] = 1;             q.push((1 << n) - v - 1);           }           for (int j = 0; j < n; j++) {             if ((v & (1 << j)) == 0 && !visit[1][v | (1 << j)]) {               q.push(v | (1 << j));               visit[1][v | (1 << j)] = 1;             }           }         }       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000LL;   const long double EPS = 1e-9;   vector<pair<int, int> > clear(vector<pair<int, int> > v) {     vector<pair<int, int> > ret;     int tox = v[1].first;     int x = v[0].first, y = v[0].second;     while (x <= tox) {       ret.push_back({x, y});       ++x;     }     int tx = v[1].first, ty = v[1].second;     while (ty != y) {       ret.push_back({tx, ty});       (ty > y) ? --ty : ++ty;     }     tox = v[2].first;     int toy = v[2].second;     int p = v[0].second, q = v[1].second;     if (p > q) swap(p, q);     if (v[2].second >= p and v[2].second <= q) {       while (x <= tox) {         ret.push_back({x, toy});         ++x;       }     } else if (v[2].second < p) {       while (x <= tox) {         ret.push_back({x, p});         ++x;       }       while (toy != p) {         ret.push_back({tox, toy});         (toy > p) ? --toy : ++toy;       }     } else {       while (x <= tox) {         ret.push_back({x, q});         ++x;       }       while (toy != q) {         ret.push_back({tox, toy});         (toy > q) ? --toy : ++toy;       }     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     vector<pair<int, int> > v(3);     for (int i = 0; i < 3; ++i) cin >> v[i].first >> v[i].second;     sort((v).begin(), (v).end());     auto res = clear(v);     sort((res).begin(), (res).end());     res.erase(unique((res).begin(), (res).end()), res.end());     cout << res.size() <<   n ;     for (auto x : res) cout << x.first <<     << x.second <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   vector<int> ans;   char s1[maxn], s2[maxn];   int n;   void op(int x) {     for (int i = 1; i <= x; ++i) {       s1[i] = s1[i] ==  0  ?  1  :  0 ;     }     reverse(s1 + 1, s1 + 1 + x);     ans.push_back(x);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     cin >> t;     while (t--) {       cin >> n;       cin >> s1 + 1 >> s2 + 1;       ans.clear();       for (int i = n; i >= 1; --i) {         if (s1[i] == s2[i]) continue;         if (i == 1)           op(1);         else {           if (s1[1] == s2[i]) op(1);           op(i);         }       }       cout << ((int)ans.size());       for (auto &v : ans) cout <<     << v;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e17 + 10;   const int N = 1e6 + 10;   const long long mod = 998244353;   map<string, int> ml;   long long b[N], vis[N], po[N], num[N], t, n, m, x, y, k, a[N];   long long ex, ey, cnt, ans, sum, flag;   long long dist[N];   long long dp[N];   vector<int> v[N];   map<int, int> mp;   priority_queue<pair<int, int> > q;   priority_queue<pair<int, int> > tq;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     string s;     cin >> s;     for (int i = 0; s[i]; i++) {       a[i] = cnt;       if (s[i] ==  ( )         cnt++;       else         cnt--;       if (a[i - 1] < 0) a[i] = -1;     }     cnt = 0;     for (int i = n - 1; i >= 0; i--) {       b[i] = cnt;       if (s[i] ==  ) )         cnt++;       else         cnt--;       if (b[i + 1] < 0) b[i] = -1;     }     for (int i = 0; s[i]; i++) {       if (a[i] < 0 && b[i] < 0) return cout << 0 << endl, 0;       num[i] = a[i] - b[i];       if (s[i] ==  (  && num[i] == 1 && a[i] >= 0 && b[i] >= 0) ans++;       if (s[i] ==  )  && num[i] == -1 && a[i] >= 0 && b[i] >= 0) ans++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[1111], b[1111];   const int inf = 1e9;   map<int, int> mp, mp1;   int nsd(int x, int y) {     while (x > 0 && y > 0)       if (x > y)         x %= y;       else         y %= x;     return x + y;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     mp[a[1]] = b[1];     for (int i = 2; i <= n; i++) {       for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {         int heh = it->first;         int kok = it->second;         if (!mp1[heh] || mp1[heh] > kok) mp1[heh] = kok;         int kek = nsd(a[i], heh);         if (!mp1[kek] || mp1[kek] > kok + b[i]) mp1[kek] = kok + b[i];       }       mp = mp1;       mp1.clear();       if (!mp[a[i]] || mp[a[i]] > b[i]) mp[a[i]] = b[i];     }     if (mp[1] == 0)       cout << -1;     else       cout << mp[1];   }
#include <bits/stdc++.h>   using namespace std;   char s[10], a1[] = { vaporeon }, a2[] = { jolteon }, a3[] = { flareon },               a4[] = { espeon }, a5[] = { umbreon }, a6[] = { leafeon },               a7[] = { glaceon }, a8[] = { sylveon };   int n, i;   int main() {     cin >> n;     cin >> s;     if (n == 6) {       cout << a4;       return 0;     }     if (n == 8) {       cout << a1;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a2[i]) break;     }     if (i == n) {       cout << a2;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a3[i]) break;     }     if (i == n) {       cout << a3;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a5[i]) break;     }     if (i == n) {       cout << a5;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a6[i]) break;     }     if (i == n) {       cout << a6;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a7[i]) break;     }     if (i == n) {       cout << a7;       return 0;     }     for (i = 0; i < n; i++) {       if (s[i] !=  . )         if (s[i] != a8[i]) break;     }     if (i == n) {       cout << a8;       return 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[600000];   int main() {     int n = 6 * 1e5;     a[0] = 0;     for (int i = 1; i < n; ++i) {       int cur = i;       int t = 0;       while (cur % 5 == 0) {         cur /= 5;         t++;       }       a[i] = a[i - 1] + t;     }     int m;     cin >> m;     vector<int> res;     for (int i = 1; i < n; ++i) {       if (a[i] == m) {         res.push_back(i);       }     }     cout << res.size() << endl;     for (int i = 0; i < res.size(); ++i) {       cout << res[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, k, t;     cin >> n >> m >> k;     if (k > n + m - 2)       cout <<  -1 n ;     else {       if (k < max(n, m))         cout << max(n * (m / (k + 1)), m * (n / (k + 1))) << endl;       else         cout << max(m / (k - n + 2), n / (k - m + 2)) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char cc[10] =  RGBYW ;   int d[5][5];   int cnt(int x) {     int res = 0;     while (x) {       res += x & 1;       x >>= 1;     }     return res;   }   int main() {     int(n);     scanf( %d , &n);     for (int i = 0; i < (n); ++i) {       char s[10];       scanf( %s , (s));       int x, y;       for (int j = 0; j < (5); ++j) {         if (s[0] == cc[j]) {           x = j;           break;         }       }       y = s[1] -  1 ;       d[x][y]++;     }     int an = 10;     for (int i = 0; i < (32); ++i)       for (int j = 0; j < (32); ++j) {         int ha[6][6] = {};         for (int k1 = 0; k1 < (5); ++k1)           for (int k2 = 0; k2 < (5); ++k2) {             if (d[k1][k2]) {               if (((i >> k1) & 1) && ((j >> k2) & 1)) {                 ha[k1 + 1][k2 + 1]++;               } else if (((i >> k1) & 1) && ((j >> k2) & 1) == 0) {                 ha[k1 + 1][0]++;               } else if (((i >> k1) & 1) == 0 && ((j >> k2) & 1)) {                 ha[0][k2 + 1]++;               } else                 ha[0][0]++;             }           }         bool err = false;         for (int k1 = 0; k1 < (6); ++k1)           for (int k2 = 0; k2 < (6); ++k2) {             if (ha[k1][k2] > 1) err = true;           }         if (!err) an = min(an, cnt(i) + cnt(j));       }     printf( %d n , an);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static inline void canhazfast() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);   }   template <typename T>   T gcd(T a, T b) {     return b == 0 ? a : gcd(b, a % b);   }   template <typename T>   T extgcd(T a, T b, T &x, T &y) {     T x0 = 1, y0 = 0, x1 = 0, y1 = 1;     while (b) {       T q = a / b;       a %= b;       swap(a, b);       x0 -= q * x1;       swap(x0, x1);       y0 -= q * y1;       swap(y0, y1);     }     x = x0;     y = y0;     return a;   }   static inline int ctz(unsigned x) { return __builtin_ctz(x); }   static inline int ctzll(unsigned long long x) { return __builtin_ctzll(x); }   static inline int clz(unsigned x) { return __builtin_clz(x); }   static inline int clzll(unsigned long long x) { return __builtin_clzll(x); }   static inline int popcnt(unsigned x) { return __builtin_popcount(x); }   static inline int popcntll(unsigned long long x) {     return __builtin_popcountll(x);   }   static inline int bsr(unsigned x) { return 31 ^ clz(x); }   static inline int bsrll(unsigned long long x) { return 63 ^ clzll(x); }   int main() {     canhazfast();     int n, m, k;     int x2, y2, x3, y3;     long long p, r;     cin >> n >> m >> k;     p = 2LL * n * m;     r = p % k;     if (r) return cout <<  NO , 0;     p /= k;     x2 = n;     y3 = (p - 1) / n + 1;     x3 = (long long)x2 * y3 - p;     y2 = 1;     cout <<  YES n0 0 n  << x2 <<     << y2 <<   n  << x3 <<     << y3;     return 0;   }
#include <bits/stdc++.h>   //#include <ext/pb_ds/assoc_container.hpp>   //#include <ext/pb_ds/tree_policy.hpp>    using namespace std;   //using namespace __gnu_pbds;   #define rep(i,a,b) for(i=(a);i<=(b);i++)   #define ll long long   #define pll pair<ll, ll>   #define pii pair<int,int>   #define pb push_back   #define F first   #define S second   #define mod 1000000007   #define maxn 100005   #define inf 1e18   #define boost ios::sync_with_stdio(false);cin.tie(0)   #define fr freopen( source.txt , r ,stdin),freopen( output.txt , w ,stdout)   #define SET(a,b) memset(a,b,sizeof(a))   #define deb(x) cout << #x <<  =  << x << endl   #define deb2(x, y) cout << #x <<  =  << x <<  ,  << #y <<  =  << y << endl   #define all(x) x.begin(), x.end()   #define ps(x,y) fixed<<setprecision(y)<<x   //template<typename T>   //using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;   template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {       return out <<   (  << a.F <<  ,   << a.S <<  ) ;   }       template<class A> ostream& operator << (ostream& out, const vector<A> &a) {       out <<  [ ;       for (auto it = a.begin(); it != a.end(); ++it) {           if (it != a.begin())               out <<  ,  ;           out << *it;       }       return out <<  ] ;   }   void solve(){       ll n,i,j,x,t,y;       cin>>n;       string s[n];       for(i=0;i<n;i++) cin>>s[i];       map<ll,ll>mp;       for(i=0;i<n;i++){           for(j=0;j<n;j++){               if(s[i][j]!= . ) mp[(i+j)%3]++;           }       }       y=min({mp[0],mp[1],mp[2]});       if(mp[0]==y) x=0;       else if(mp[1]==y) x=1;       else x=2;       for(i=0;i<n;i++){           for(j=0;j<n;j++){               if(s[i][j]!= . &&(i+j)%3==x) s[i][j]= O ;           }       }       for(i=0;i<n;i++) cout<<s[i]<<  n ;   }   int main()   {       boost;       ll n,i,j,x,t,y;       cin>>t;       while(t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int v[5][5], sum;   int main() {     for (int i = 1; i <= 3; i++)       for (int h = 1; h <= 3; h++) cin >> v[i][h];     if (v[1][1] == 0) {       for (int i = 1; i <= 100000; i++) {         int a = v[2][1] + v[2][3] - i;         if (a + v[1][2] + v[1][3] == v[3][1] + v[3][2] + i) {           v[1][1] = a, v[3][3] = i,           v[2][2] = v[3][1] + v[3][2] + i - v[2][1] - v[2][3];           break;         }       }       for (int i = 1; i <= 3; i++) {         for (int h = 1; h <= 3; h++) cout << v[i][h] <<    ;         cout <<   n ;       }       return 0;     }     for (int i = 1; i <= 100000; i++) {       int a = v[2][1] + v[2][3] - i;       if (a + v[1][2] + v[1][1] == v[3][2] + v[3][3] + i) {         v[1][3] = a, v[3][1] = i,         v[2][2] = v[3][2] + v[3][3] + i - v[2][1] - v[2][3];         break;       }     }     for (int i = 1; i <= 3; i++) {       for (int h = 1; h <= 3; h++) cout << v[i][h] <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int vis[10005];   int main() {     int n;     scanf( %d , &n);     int maxn = -1;     for (int i = 1; i <= n; i++) {       int tmp;       scanf( %d , &tmp);       vis[tmp]++;       maxn = max(maxn, tmp);     }     long long ans1 = -1, ans2 = -1;     for (int i = 1; i <= maxn; i++) {       if (vis[i] != 0) {         if (i > ans1) {           ans1 = i;         }       }     }     for (int i = 1; i <= maxn; i++) {       if (vis[i] == 2 || (ans1 % i != 0 && vis[i] == 1)) {         if (i > ans2) {           ans2 = i;         }       }     }     printf( %lld %lld n , ans1, ans2);   }
#include <bits/stdc++.h>   using namespace std;   int ord[100100];   int inv_ord[100100];   int dep[100100];   int fa[100100][17];   vector<int> g[100100];   set<int> ss;   int ts;   void dfs(int p, int f) {     ord[p] = ++ts;     inv_ord[ord[p]] = p;     dep[p] = dep[f] + 1;     fa[p][0] = f;     for (int i = 0; i < 16; i++) fa[p][i + 1] = fa[fa[p][i]][i];     for (int i = 0; i < g[p].size(); i++)       if (g[p][i] != f) dfs(g[p][i], p);   }   inline int bit(int x, int i) { return (x >> i) & 1; }   int lca(int a, int b) {     if (dep[a] > dep[b]) swap(a, b);     for (int i = 0; i < 17; i++)       if (bit(dep[a] - dep[b], i)) b = fa[b][i];     if (a == b) return a;     for (int i = 16; i >= 0; i--)       if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];     return fa[a][0];   }   int calc(int p) {     if (ss.empty()) return 1;     set<int>::iterator it = ss.lower_bound(ord[p]);     int a = inv_ord[it == ss.end() ? *ss.begin() : *it];     int b = inv_ord[it == ss.begin() ? *ss.rbegin() : *--it];     return dep[p] - dep[lca(a, p)] - dep[lca(b, p)] + dep[lca(a, b)];   }   int main() {     int n, k, a, b;     while (cin >> n >> k) {       for (int i = 1; i < n; i++) {         cin >> a >> b;         g[a].push_back(b);         g[b].push_back(a);       }       ts = 0;       dfs(1, 0);       int v = 0;       int sol = 1;       for (int i = 1, j = 0; i <= n; i++) {         while (v <= k) {           sol = max(sol, j - i + 1);           if (j == n) break;           j++;           v += calc(j);           ss.insert(ord[j]);         }         ss.erase(ord[i]);         v -= calc(i);       }       cout << sol << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool inrange(int y) { return ((y >= 1) && (y <= 9)); }   int main() {     int r1, r2, c1, c2, d1, d2;     bool taken[9] = {false};     cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;     int x = (r1 + r2);     int y = (c1 + c2);     int z = (d1 + d2);     int w;     if (x == y && y == z) {       if ((r1 + c2 - d1) % 2) {         cout <<  -1 n ;         return 0;       }       y = (r1 + c2 - d1) / 2;       if (!inrange(y)) {         cout <<  -1 n ;         return 0;       }       if (taken[y - 1]) {         cout <<  -1 n ;         return 0;       } else         taken[y - 1] = true;       x = r1 - y;       if (!inrange(x)) {         cout <<  -1 n ;         return 0;       }       if (taken[x - 1]) {         cout <<  -1 n ;         return 0;       } else {         taken[x - 1] = true;       }       w = d2 - y;       if (!inrange(w)) {         cout <<  -1 n ;         return 0;       }       if (taken[w - 1]) {         cout <<  -1 n ;         return 0;       } else {         taken[w - 1] = true;       }       z = c2 - y;       if (!inrange(z)) {         cout <<  -1 n ;         return 0;       }       if (taken[z - 1]) {         cout <<  -1 n ;         return 0;       } else {         taken[z - 1] = true;       }       cout << x <<     << y <<   n ;       cout << w <<     << z <<   n ;     } else       cout <<  -1 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 7;   int n;   int main() {     ios::sync_with_stdio(false);     cin.tie(0), cout.tie(0);     int _;     cin >> _;     while (_--) {       cin >> n;       for (int i = 1; i <= n; i++) {         cout << i + 1 <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   signed main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int n, m;     cin >> n;     vector<string> a(n);     for (int i = 0; i < n; i++) cin >> a[i];     cin >> m;     vector<vector<string>> b(m);     bool new_problem = 1;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       b[i].resize(k);       for (int j = 0; j < k; j++) cin >> b[i][j];       int cnt = 0;       for (int j = 0; j < n; j++) {         for (int p = 0; p < k; p++) {           if (a[j] == b[i][p]) {             cnt++;             break;           }         }       }       new_problem &= cnt != n;     }     if (new_problem) {       cout <<  Brand new problem! n ;       return 0;     }     vector<int> p(n);     iota(p.begin(), p.end(), 0);     const int INF = 1e9;     pair<int, int> best = {INF, INF};     do {       int cost = 0;       for (int i = 1; i < n; i++) {         for (int j = i - 1; j >= 0; j--) cost += p[i] < p[j];       }       int take = -1;       for (int i = 0; i < m; i++) {         int ptr = 0;         for (int j = 0; j < (int)b[i].size(); j++) {           if (a[p[ptr]] == b[i][j]) ptr++;           if (ptr == n) {             break;           }         }         if (ptr == n) {           take = i;           break;         }       }       if (take != -1) {         if (cost < best.first || (cost == best.first && take < best.second))           best = {cost, take};       }     } while (next_permutation(p.begin(), p.end()));     int x = (n * (n - 1) / 2 - best.first + 1);     cout << best.second + 1 <<   n ;     cout <<  [: ;     while (x) {       cout <<  | ;       x--;     }     cout <<  :] n ;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e3 + 3;   long long n, mod = 1e9 + 7, dp[N][N][2];   long long f(long long idx, long long diff, long long stat) {     long long &ret = dp[idx][diff][stat];     if (ret != -1) return ret;     if (idx == n) {       ret = 0;       return ret;     }     ret = 0;     if (stat == 0) {       if (n - idx - 1 >= diff + 1) {         ret =             (f(idx + 1, diff + 1, 0) + (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) %             mod;         ret = max(ret, (f(idx + 1, diff + 1, 1) + 1 +                         (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) %                            mod);         ret = max(ret, (f(idx + 1, diff + 1, 0) +                         (diff > 0 ? 1 + f(idx + 1, diff - 1, 1) : 0)) %                            mod);       } else {         if (diff > 0)           ret = max(f(idx + 1, diff - 1, 0), 1 + f(idx + 1, diff - 1, 1));         else           ret = 0;       }     } else {       if (n - idx - 1 >= diff + 1) {         ret =             (f(idx + 1, diff + 1, 0) + (diff > 0 ? f(idx + 1, diff - 1, 0) : 0)) %             mod;       } else {         if (diff > 0)           ret = f(idx + 1, diff - 1, 0);         else           ret = 0;       }     }     return ret;   }   int main() {     cin >> n;     n *= 2;     for (long long i = 0; i <= n; i++)       for (long long ii = 0; ii <= n; ii++)         for (long long iii = 0; iii < 2; iii++) dp[i][ii][iii] = -1;     cout << f(0, 0, 0) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const long long inf64 = 1e18;   void solve() {     int n, m;     cin >> n >> m;     vector<vector<int>> a(n, vector<int>(m)), b;     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++) {       for (int j = 0; j < m; j++) {         int c = 0;         if (i > 0) c++;         if (j > 0) c++;         if (i + 1 < n) c++;         if (j + 1 < m) c++;         if (a[i][j] > c) {           cout <<  NO n ;           return;         }         a[i][j] = c;       }     }     cout <<  YES n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << a[i][j] <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tt;     cin >> tt;     while (tt--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int main() {     ios_base::sync_with_stdio(false);     int n, x[10], y[10], nx[10], ny[10];     cin >> n;     for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> nx[i] >> ny[i];     int mnx = 1000000, mny = 1000000, mxx = 0, mxy = 0;     for (int i = 0; i < n; i++) {       mnx = min(mnx, x[i]);       mny = min(mny, y[i]);       mxx = max(mxx, nx[i]);       mxy = max(mxy, ny[i]);     }     long long area = (mxx - mnx) * (mxy - mny);     long long realarea = 0;     for (int i = 0; i < n; i++) {       realarea += (nx[i] - x[i]) * (ny[i] - y[i]);     }     if (mxx - mnx == mxy - mny && area == realarea)       printf( YES );     else       printf( NO );   }