malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   const int N = 1e7 + 100;   unordered_map<int, int> vis, Cnt;   vector<int> Mice;   vector<int> Cheese;   int main() {     int n, m, y0, y1;     scanf( %d%d%d%d , &n, &m, &y0, &y1);     for (int i = 0; i < n; i++) {       int x;       scanf( %d , &x);       Mice.push_back(x);     }     for (int i = 0; i < m; i++) {       int x;       scanf( %d , &x);       Cheese.push_back(x);     }     int Ans = 0;     for (int x : Mice) {       int L = INF, R = INF;       auto it = lower_bound(Cheese.begin(), Cheese.end(), x);       if (it != Cheese.end()) R = *it;       if (it != Cheese.begin()) it--;       L = *it;       int cur = min(abs(x - L), abs(R - x));       if (x - L == R - x) {         if (!vis.count(L))           vis[L] = x - L, Cnt[L] = 1;         else {           if (vis[L] == x - L)             Cnt[L]++;           else {             if (!vis.count(R))               vis[R] = cur, Cnt[R] = 1;             else if (vis[R] > cur) {               Ans += vis[R];               vis[R] = cur;               Cnt[R] = 1;             } else if (vis[R] == cur)               Cnt[R]++;             else               Ans++;           }         }       } else {         int d = (x - L < R - x ? L : R);         if (!vis.count(d))           vis[d] = cur, Cnt[d] = 1;         else {           if (vis[d] > cur) {             Ans += Cnt[d];             vis[d] = cur;             Cnt[d] = 1;           } else if (vis[d] < cur)             Ans++;           else             Cnt[d]++;         }       }     }     printf( %d n , Ans);     return 0;   }
#include<bits/stdc++.h>   #define x first   #define y second      using namespace std;      typedef long long LL;   typedef long double LD;   typedef pair<int,int> PII;      const int N=100005;      int n,m,T;      int main(){    cin>>T;       int k1,k2,t1,t2,x1,x2;       while(T--){           cin>>n>>k1>>k2;           cin>>t1>>t2;           x1=(k1+k2)/2;           if((k1+k2)&1) n--;           x2=n-x1;           if( t1<=x1 && t2<=x2 ) cout<< YES <<endl;           else cout<< NO <<endl;       }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, size[200010] = {0};   vector<int> w[200010];   int dpMax(int, int);   int dpMin(int, int);   int child(int x) {     int ret = 0;     for (int i = 0; i < w[x].size(); i++) ret += child(w[x][i]);     return size[x] = ret + !w[x].size();   }   int dpMax(int x, int t) {     int ret1, ret2;     ret1 = ret2 = !w[x].size();     for (int i = 0; i < w[x].size(); i++) {       if (!t)         ret1 = max(ret1, size[x] - size[w[x][i]] + dpMin(w[x][i], 0));       else         ret2 += (dpMin(w[x][i], 1));     }     return !t ? ret1 : ret2;   }   int dpMin(int x, int t) {     int ret1, ret2;     ret1 = 1;     ret2 = 1 + (1 << 28) * (w[x].size() > 0);     for (int i = 0; i < w[x].size(); i++) {       if (!t)         ret1 += (dpMax(w[x][i], 0) - 1);       else         ret2 = min(ret2, (dpMax(w[x][i], 1)));     }     return !t ? ret1 : ret2;   }   int main() {     scanf( %d , &n);     for (int i = 0, a, b; i < n - 1; i++) {       scanf( %d%d , &a, &b);       w[a].push_back(b);     }     child(1);     printf( %d %d n , dpMax(1, 0), dpMax(1, 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int P = 1e9 + 7;   int n, m;   namespace flow {   int n, s, t;   int head[200306], to[200306 << 1], nex[200306 << 1], wto[200306 << 1], ecn = 1;   int ade(int u, int v, int w) {     to[++ecn] = v, nex[ecn] = head[u], wto[ecn] = w, head[u] = ecn;     to[++ecn] = u, nex[ecn] = head[v], wto[ecn] = 0, head[v] = ecn;     return ecn;   }   queue<int> Q;   int dep[200306], cur[200306];   const int inf = 1e9;   void clear() {     for (int i = (1), iend = (n); i <= iend; ++i) head[i] = dep[i] = cur[i] = 0;     ecn = 1;   }   bool bfs() {     Q.push(s);     for (int i = (1), iend = (n); i <= iend; ++i) cur[i] = head[i];     memset(dep, 0x3f, sizeof dep);     dep[s] = 0;     while (!Q.empty()) {       int u = Q.front();       Q.pop();       for (int i = head[u]; i; i = nex[i])         if (dep[to[i]] > inf && wto[i]) dep[to[i]] = dep[u] + 1, Q.push(to[i]);     }     return dep[t] < inf;   }   long long dfs(int u, long long lim) {     if (!lim || u == t) return lim;     long long flow = 0, f;     for (int& i = cur[u]; i; i = nex[i])       if (dep[to[i]] == dep[u] + 1 && (f = dfs(to[i], min(lim, 1ll * wto[i])))) {         lim -= f, flow += f, wto[i] -= f, wto[i ^ 1] += f;         if (!lim) break;       }     return flow;   }   long long dinic() {     long long res = 0;     while (bfs()) res += dfs(s, 0x3f3f3f3f3f3f3f3f);     return res;   }   }  // namespace flow   pair<int, int> ed[200306];   int bc[200306];   long long chk(int x) {     for (int i = (1), iend = (n); i <= iend; ++i) flow::ade(n + m + 1, i, x);     for (int i = (1), iend = (m); i <= iend; ++i) {       int u = ed[i].first, v = ed[i].second;       bc[i] = flow::ade(u, i + n, 1);       flow::ade(v, i + n, 1);       flow::ade(i + n, n + m + 2, 1);     }     long long as = flow::dinic();     flow::clear();     return as;   }   void solve() {     cin >> n >> m;     for (int i = (1), iend = (m); i <= iend; ++i) {       int u, v;       scanf( %d%d , &u, &v);       ed[i] = make_pair(u, v);     }     int l = 0, r = n;     flow::s = n + m + 1, flow::t = n + m + 2, flow::n = n + m + 2;     while (l <= r) {       int mid = l + r >> 1;       long long as = chk(mid);       if (as == m) {         r = mid - 1;       } else         l = mid + 1;     }     cout << l << endl;     chk(l);     for (int i = (1), iend = (m); i <= iend; ++i) {       int u = ed[i].first, v = ed[i].second;       if (flow::wto[bc[i]])         printf( %d %d n , u, v);       else         printf( %d %d n , v, u);     }   }   signed main() { solve(); }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 5;   vector<pair<int, int> > adj[MAXN];   int n;   bool mark[MAXN];   int p[MAXN];   int curv;   void dfs(int v, int ind = -1) {     mark[v] = 1;     for (int i = 0; i < adj[v].size(); i++) {       pair<int, int> u = adj[v][i];       if (!mark[u.first]) {         dfs(u.first, u.second);       } else if (u.second != ind) {         curv = u.first;       }     }   }   int main() {     cin >> n;     int x;     int d = -1;     for (int i = 1; i <= n; i++) {       cin >> x;       if (x == i) {         d = i;       }       p[i] = x;       adj[i].push_back({x, i});       adj[x].push_back({i, i});     }     int cnt = 0;     vector<int> ve;     for (int i = 1; i <= n; i++) {       if (!mark[i]) {         dfs(i);         cnt++;         ve.push_back(curv);       }     }     if (d != -1) {       cout << cnt - 1 <<   n ;       for (int i = 0; i < ve.size(); i++) {         p[ve[i]] = d;       }       for (int i = 1; i <= n; i++) {         cout << p[i] <<    ;       }       return 0;     }     cout << cnt <<   n ;     for (int i = 0; i < ve.size(); i++) {       p[ve[i]] = ve[0];     }     for (int i = 1; i <= n; i++) {       cout << p[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long maxn = 4e5 + 1;   struct dak {     long long val, pos;   };   long long l[maxn], r[maxn];   long long pre[maxn], pre2[maxn];   vector<dak> p;   vector<pair<long long, long long> > v;   vector<pair<long long, long long> > qr;   long long n, m, q;   long long cur = 0;   long long res[maxn];   inline long long get(long long r, long long x) { return pre[r] - pre[r - x]; }   inline long long cnt(long long x) { return pre2[x] - pre2[l[x] - 1]; }   void join(long long pos) {     cur -= get(pos - 1, cnt(pos - 1)) + get(r[pos], cnt(r[pos])) -            get(r[pos], cnt(r[pos]) + cnt(pos - 1));     r[l[pos - 1]] = r[pos];     l[r[pos]] = l[pos - 1];   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> q;     for (long long i = 1; i <= n; i++) {       long long x;       cin >> x;       v.push_back({x, 1});       cur += x;     }     for (long long i = 1; i <= m; i++) {       long long x;       cin >> x;       v.push_back({x, 0});     }     sort(v.begin(), v.end());     for (long long i = 1; i <= n + m; i++) {       l[i] = r[i] = i;       pre[i] = pre[i - 1] + v[i - 1].first;       pre2[i] = pre2[i - 1] + v[i - 1].second;     }     for (long long i = 1; i < n + m; i++) {       p.push_back({v[i].first - v[i - 1].first, i + 1});     }     sort(p.begin(), p.end(),          [](const dak &a, const dak &b) { return a.val < b.val; });     for (long long i = 1, x; i <= q; i++) {       cin >> x;       qr.push_back({x, i});     }     sort(qr.begin(), qr.end());     long long pos = 0;     for (pair<long long, long long> &query : qr) {       while (pos < p.size() && p[pos].val <= query.first) {         join(p[pos].pos);         pos++;       }       res[query.second] = cur;     }     for (long long i = 1; i <= q; i++) cout << res[i] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 2;   int n, m, a[N], cnt[N], nxt[N];   bool vis[N];   int main() {     int test;     cin >> test;     while (test--) {       cin >> n >> m;       for (int i = 0; i <= n; ++i) cnt[i] = 0;       for (int i = 1; i <= n; ++i) {         cin >> a[i];         int t1 = i + n - a[i], t2 = i - a[i] + 1;         int k1 = -1, k2 = -1;         if (t1 < n) {           k1 = t1;         }         if (t2 > 0) {           k2 = t2 - 1;         }         if (k1 >= 0) ++cnt[k1];         if (k2 >= 0) cnt[k2] += k1 != k2;       }       vector<int> ans;       ans.clear();       for (int i = 0; i < n; ++i) {         if (n - cnt[i] > m * 2) continue;         for (int j = 1; j <= n; ++j) {           vis[j] = false;           if (a[j] <= n - i) {             nxt[j] = i + a[j];           } else {             nxt[j] = a[j] - (n - i);           }         }         int cycles = 0;         for (int j = 1; j <= n; ++j)           if (nxt[j] != j && !vis[j]) {             int u = j;             ++cycles;             vis[j] = true;             while (nxt[u] != j) {               u = nxt[u];               vis[u] = true;             }           }         if (n - cnt[i] - cycles <= m) {           ans.push_back(i);         }       }       cout << (int)ans.size() <<    ;       for (int i : ans) cout << i <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long K = 10000000000LL;   vector<long long> L;   void init(long long crr) {     if (crr > K) return;     if (crr != 0) L.push_back(crr);     init(crr * 10 + 4);     init(crr * 10 + 7);   }   bool is_lucky(long long x) {     if (x == 0) return false;     while (x > 0) {       if (x % 10 != 4 && x % 10 != 7) return false;       x /= 10;     }     return true;   }   const int MAX_M = 20;   long long fact(long long k) {     long long res = 1;     for (int i = 1; i <= k; ++i) res *= i;     return res;   }   vector<int> kth_permutation(int n, long long k) {     vector<int> res(n), num(n);     for (int i = 0; i < (int)(n); i++) num[i] = i;     if (k >= fact(n)) return vector<int>();     for (int i = 0; i < (int)(n); i++) {       long long f = fact(n - i - 1);       res[i] = num[k / f];       num.erase(num.begin() + (k / f));       k %= f;     }     return res;   }   long long perm_n, perm_m;   vector<int> perm_last;   bool init_permutation(long long n, long long k) {     perm_n = n;     perm_last = kth_permutation(min(n, 20LL), k);     if (perm_last.empty()) return false;     perm_m = perm_n - perm_last.size();     return true;   }   long long get_permutation(long long i) {     if (i < perm_m)       return i;     else       return perm_m + perm_last[i - perm_m];   }   int bruteforce(int N, int K) {     vector<int> A(N);     for (int i = 0; i < (int)(N); i++) A[i] = i + 1;     for (int i = 0; i < (int)(K - 1); i++)       next_permutation((A).begin(), (A).end());     int ans = 0;     for (int i = 0; i < (int)(N); i++)       if (is_lucky(i + 1) && is_lucky(A[i])) ++ans;     return ans;   }   int main() {     init(0);     long long N, K;     while (cin >> N >> K) {       --K;       if (!init_permutation(N, K)) {         puts( -1 );         continue;       }       long long ans = 0;       for (int i = 0; i < (int)(L.size()); i++) {         long long l = L[i];         if (1 <= l && l <= N && is_lucky(1 + get_permutation(l - 1))) ++ans;       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, m;     cin >> n >> m;     vector<vector<long long> > a(m, vector<long long>(n));     for (long long i = 0; i <= n - 1; i++) {       for (long long j = 0; j <= m - 1; j++) {         cin >> a[j][i];         a[j][i]--;       }     }     long long ans = 0;     for (long long i = 0; i <= m - 1; i++) {       vector<long long> temp(n, 0);       for (long long j = 0; j <= n - 1; j++) {         if (a[i][j] % m == i) {           long long x = a[i][j] / m;           if (x < n) {             temp[(j - x + n) % n]++;           }         }       }       long long lol = INT_MAX;       for (long long j = 0; j <= n - 1; j++) {         lol = min(lol, (n - temp[j] + j));       }       ans += lol;     }     cout << ans <<   n ;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t = 1;     for (long long i = 1; i <= t; i++) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long SIZE = 1e5;   long long n, a[SIZE], dp[SIZE][2][2];   void Max(long long &a, long long b) { a = max(a, b); }   signed main() {     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];     }     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < 2; j++) {         for (long long k = 0; k < 2; k++) {           dp[i][j][k] = 1;         }       }     }     for (long long i = 0; i < (n - 1); i++) {       if (a[i] < a[i + 1]) {         Max(dp[i + 1][0][0], dp[i][0][0] + 1);         Max(dp[i + 1][1][0], dp[i][1][0] + 1);       }       Max(dp[i + 1][1][1], dp[i][0][0] + 1);       if (i && (a[i + 1] - a[i - 1] > 1)) {         Max(dp[i + 1][1][0], dp[i][1][1] + 1);       }     }     long long ans = 1;     for (long long i = 0; i < n; i++) {       Max(ans, min(dp[i][0][0] + 1, n));       for (long long j = 0; j < 2; j++) {         Max(ans, dp[i][1][j]);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long leader[110000], p[110000];   long long n, m, i, j, k;   bool can(long long cost) {     for (i = 0, j = 0; i < n && j < m; ++i) {       long long summ = cost;       if (leader[i] == p[j] && j < m) ++j;       if (j >= m) break;       summ -= abs(leader[i] - p[j]);       long long temp = leader[i] - p[j];       if (summ < 0) continue;       if (temp > 0) {         int t = j;         while (p[j] <= leader[i] && j < m) ++j;         while (cost >= p[j] - p[t] + min(p[j] - leader[i], leader[i] - p[t]) &&                j < m)           ++j;         if (j >= m) break;       } else {         while (p[j] <= leader[i] + cost && j < m) ++j;         if (j >= m) break;       }     }     if (j >= m)       return 1;     else       return 0;   }   int main() {     long long cost = 0;     scanf( %I64d%I64d , &n, &m);     for (i = 0; i < n; ++i) scanf( %I64d , &leader[i]);     for (i = 0; i < m; ++i) scanf( %I64d , &p[i]);     i = 0, j = 0;     long long l = -1, r = max(p[m - 1] * 2, leader[n - 1] * 2);     if (n != 1)       while (r - l > 1) {         long long mid = l + (r - l) / 2;         if (can(mid))           r = mid;         else           l = mid;       }     if (n != 1)       printf( %I64d , r);     else {       if (leader[0] < p[0])         printf( %I64d , p[m - 1] - leader[0]);       else if (leader[0] > p[m - 1])         printf( %I64d , leader[0] - p[0]);       else {         printf( %I64d ,                p[m - 1] - p[0] + min(leader[0] - p[0], p[m - 1] - leader[0]));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = (int)1e9 + 7;   template <typename Arg1>   void __f(const char* name, Arg1&& arg1) {     cout << name <<   :   << arg1 <<   n ;   }   template <typename Arg1, typename... Args>   void __f(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cout.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   void solve() {     int n;     cin >> n;     if (n % 2 == 0) {       cout <<  -1 n ;       return;     }     for (int i = 0; i < n; i++) {       cout << i <<    ;     }     cout <<   n ;     for (int i = 0; i < n; i++) {       cout << (i + 1) % n <<    ;     }     cout <<   n ;     for (int i = 0; i < n; i++) {       cout << (i + i + 1) % n <<    ;     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     solve();   }
#include <bits/stdc++.h>   using namespace std;   void build(int ss, int se, int si);   long long query(int ss, int se, int si, int qs, int qe);   set<pair<long long, int> > s;   set<pair<long long, int> >::iterator it, last;   long long A[100001], st[400005], dp[100001];   int main(void) {     int i, n, c;     long long sum, ans = 0, min_i;     cin >> n >> c;     if (c == 1) {       cout << 0 << endl;       return 0;     }     for (i = 0; i < n; i++) {       cin >> A[i];       ans = ans + A[i];     }     build(0, n - 1, 0);     for (i = c - 1; i < n; i++)       dp[i] = max(dp[i - 1], ((i - c >= 0) ? dp[i - c] : 0) +                                  query(0, n - 1, 0, i - c + 1, i));     cout << ans - dp[n - 1] << endl;   }   void build(int ss, int se, int si) {     if (ss == se) {       st[si] = A[ss];       return;     }     int mid = (ss + se) / 2;     build(ss, mid, 2 * si + 1);     build(mid + 1, se, 2 * si + 2);     st[si] = min(st[2 * si + 1], st[2 * si + 2]);   }   long long query(int ss, int se, int si, int qs, int qe) {     if (ss >= qs && se <= qe) return st[si];     if (ss > qe || se < qs) return INT_MAX;     int mid = (ss + se) / 2;     return min(query(ss, mid, 2 * si + 1, qs, qe),                query(mid + 1, se, 2 * si + 2, qs, qe));   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, N, bitl, bitr;     long long l, r;     scanf( %d , &N);     while (N--) {       scanf( %lld%lld , &l, &r);       bitl = bitr = 0;       if (l == r) {         printf( %lld n , l);         continue;       }       while ((1LL << bitl) <= l) ++bitl;       while ((1LL << bitr) <= r) ++bitr;       --bitl;       --bitr;       if (bitl < bitr) {         if ((1LL << (bitr + 1)) - 1 == r)           printf( %lld n , r);         else           printf( %lld n , (1LL << bitr) - 1);         continue;       }       for (i = bitr; i >= 0; --i) {         if (((l >> i) % 2) != ((r >> i) % 2)) break;       }       if ((((1LL << (i + 1)) - 1) & r) == (1LL << (i + 1)) - 1)         printf( %lld n , r);       else {         r |= (1LL << i) - 1;         r &= ~(1LL << i);         printf( %lld n , r);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void cmax(long long int &a, long long int b) {     if (a < b) a = b;   }   const int mod = 1000000007;   bool comp(int x, int y) { return x > y; }   void printarr(int arr[], int n) {     for (int i = 0; i < n; ++i) std::cout << arr[i] << (i < n - 1 ?     :   n );   }   template <typename T>   void printv(T &a) {     for (auto it = a.begin(); it != a.end(); ++it) std::cerr << *it <<    ;     std::cerr <<   n ;   }   int gint() {     int n;     cin >> n;     return n;   }   const int maxn = 200009;   long long int ans;   int arr[maxn];   void solve() {     ans = 0;     bool ok = false;     int m = gint();     int n = gint();     long long int sum = 0;     for (int i = 0; i < n; ++i) {       arr[i] = i + 1;       sum += arr[i];       if (sum > m) ok = 1;     }     if (!ok) {       for (int i = 0; i < n; ++i) {         arr[i] += (m - sum) / n;       }       int res = (m - sum) % n;       for (int i = n - 2; i >= 0; --i) {         int temp;         arr[i + 1] += temp = min(arr[i] * 2 - arr[i + 1], res);         res -= temp;       }       sum = arr[0];       for (int i = 1; !ok && i < n; ++i) {         ok = (arr[i] > arr[i - 1] * 2);         sum += arr[i];       }       ok = !(sum == m);     }     std::cout << (!ok ?  YES  :  NO );     std::cout <<   n ;     if (!ok) printarr(arr, n);     std::cout <<   n ;   }   void sol() {}   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     int testcases = 1;     for (int t = 0; t < testcases; ++t) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 4e18;   const long long N = 2e5 + 10;   void testCase() {     long long n;     cin >> n;     long long a[n + 1];     for (long long i = 1; i <= n; i++) cin >> a[i];     vector<long long> sma(n + 2), suf(n + 2);     for (long long i = n; i >= 1; i--) {       sma[i] = max(a[i], sma[i + 1] + 1);       suf[i] = suf[i + 1] + sma[i] - a[i];     }     long long ans = inf;     long long pma = 0, pref = 0;     for (long long i = 1; i <= n; i++) {       pma = max(pma + 1, a[i]);       long long cur = pref + suf[i + 1] + max(pma, sma[i]) - a[i];       ans = min(ans, cur);       pref += pma - a[i];     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr), cout.tie(nullptr);     long long t_c = 1;     while (t_c--) testCase();   }
#include <bits/stdc++.h>   using namespace std;   int const N = 200001;   int main() {     int t;     scanf( %d , &t);     while (t--) {       int n;       string s, t;       scanf( %d , &n);       cin >> s >> t;       set<int> msA[200], msB[200];       map<char, int> f;       for (int i = 0; i < n; ++i) {         msA[s[i]].insert(i);         msB[t[i]].insert(i);         ++f[s[i]], ++f[t[i]];       }       bool ok = true;       for (char i =  a ; i <=  z ; ++i)         if (f[i] & 1) {           ok = false;           break;         }       vector<pair<int, int> > an;       if (!ok) {         puts( NO );         continue;       }       for (int i = 0; i < n; ++i) {         if (s[i] == t[i]) continue;         int sp = -1;         for (int j = i + 1; j < n; ++j) {           if (s[j] == s[i]) sp = j;           if (s[j] != t[j] && s[j] == s[i]) {             sp = j;             break;           }         }         if (~sp) {           an.push_back({sp, i});           swap(s[sp], t[i]);           continue;         }         for (int j = i + 1; j < n; ++j) {           if (t[j] == s[i]) sp = j;           if (s[j] != t[j] && t[j] == s[i]) {             sp = j;             break;           }         }         if (~sp) {           an.push_back({sp, sp});           swap(s[sp], t[sp]);           an.push_back({sp, i});           swap(s[sp], t[i]);           continue;         }         break;       }       if (s != t || an.size() > 2 * n)         puts( NO );       else {         printf( YES n%d n , an.size());         for (auto i : an) printf( %d %d n , i.first + 1, i.second + 1);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int n = 5000;   const long long mod = 998244353;   long long f[n + 10][n + 10];   int main() {     int a, b, c;     for (int i = 1; i < n + 10; i++) {       for (int j = 1; j < n + 10; j++) {         if (i == 1)           f[i][j] = j + 1;         else if (j < i)           f[i][j] = f[j][i];         else {           (f[i][j] += j * f[i - 1][j - 1] % mod) %= mod;           (f[i][j] += f[i - 1][j]) %= mod;         }       }     }     while (scanf( %d%d%d , &a, &b, &c) != EOF) {       long long ans = ((f[a][b] * f[b][c]) % mod) * f[c][a] % mod;       printf( %lld n , ans);     }     return 0;   }