malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   std::vector<int> V[200010], V2[200010];   int check[200010];   std::stack<int> St;   void init(int k) {     if (check[k] == 1) return;     check[k] = 1;     for (int i = 0; i < V[k].size(); i++) init(V[k][i]);     St.push(k);   }   int color[200010];   void makeSCC(int k, int c) {     if (color[k] > 0) return;     color[k] = c;     for (int i = 0; i < V2[k].size(); i++) makeSCC(V2[k][i], c);   }   int x[200010], cost[200010];   std::vector<int> V3[200010];   int main() {     int a;     scanf( %d , &a);     for (int i = 1; i <= a; i++) scanf( %d , &x[i]);     for (int i = 1; i <= a; i++) {       int b;       scanf( %d , &b);       V[i].push_back(b);       V2[b].push_back(i);     }     for (int i = 1; i <= a; i++) init(i);     int c = 1;     while (!St.empty()) {       int k = St.top();       St.pop();       if (color[k] == 0) makeSCC(k, c++);     }     for (int i = 1; i <= a; i++) cost[i] = 123456789;     for (int i = 1; i <= a; i++)       cost[color[i]] = cost[color[i]] < x[i] ? cost[color[i]] : x[i];     for (int i = 1; i <= a; i++)       if (color[i] != color[V[i][0]]) V3[color[i]].push_back(color[V[i][0]]);     long long int ans = 0;     for (int i = 1; i <= a; i++)       if (V3[i].size() == 0 && cost[i] < 123456789) ans += cost[i];     printf( %lld , ans);   }
#include <bits/stdc++.h>   int n, ust, x, y, mark[10];   int main() {     scanf( %d , &n);     scanf( %d , &ust);     for (int i = 0; i < n; i++) {       scanf( %d %d , &x, &y);       mark[x] = 1;       mark[y] = 1;       mark[7 - x] = 1;       mark[7 - y] = 1;       if (!mark[7 - ust])         for (int j = 0; j < 7; j++) mark[j] = 0;       else {         printf( NO n );         return 0;       }     }     printf( YES n );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000001;   int n, kt[N], a[N], cnt, x[N];   long long k, s;   long long cal(int i) {     long long res = i;     return res * (res + 1) / 2;   }   int main() {     scanf( %d%lld , &n, &k);     if (k < cal(n)) {       printf( -1 );       return 0;     }     for (int i = n; i > 0; i--) {       int h = n - (n - i) / 2;       if (k - h < cal(i - 1)) h = k - cal(i - 1);       k -= h;       kt[h]++;       if (kt[h] == 2) a[++cnt] = h;     }     for (int i = 1; i <= n; i++) s += kt[i] * i;     printf( %lld n , s);     for (int i = 1; i <= n; i++) {       if (kt[i] == 1)         x[i] = i;       else if (kt[i] == 0) {         x[a[cnt]] = i;         x[i] = a[cnt];         cnt--;       }     }     for (int i = 1; i <= n; i++) printf( %d  , i);     printf(  n );     for (int i = 1; i <= n; i++) printf( %d  , x[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, m, q;     cin >> n >> m >> q;     vector<vector<int>> r(n), c(m);     for (int i = 0; i < q; ++i) {       int x, y;       cin >> x >> y;       --x;       --y;       r[x].push_back(y);       c[y].push_back(x);     }     if (n == 1) {       cout << m - q;       return 0;     }     if (m == 1) {       cout << n - q;       return 0;     }     vector<char> used_row(n, false);     vector<char> used_col(m, false);     int ans = 0;     vector<int> cols_to_add(r[0]), next_cols_to_add;     used_row[0] = true;     for (int i = 0; i < m; ++i) {       if (used_col[i]) continue;       while (!cols_to_add.empty()) {         next_cols_to_add.clear();         for (int col : cols_to_add) {           if (used_col[col]) continue;           used_col[col] = true;           for (int row : c[col]) {             if (used_row[row]) continue;             used_row[row] = true;             for (int new_col : r[row]) {               next_cols_to_add.push_back(new_col);             }           }         }         cols_to_add = next_cols_to_add;       }       if (!used_col[i]) {         ++ans;         cols_to_add.push_back(i);       }     }     while (!cols_to_add.empty()) {       next_cols_to_add.clear();       for (int col : cols_to_add) {         if (used_col[col]) continue;         used_col[col] = true;         for (int row : c[col]) {           if (used_row[row]) continue;           used_row[row] = true;           for (int new_col : r[row]) {             next_cols_to_add.push_back(new_col);           }         }       }       cols_to_add = next_cols_to_add;     }     for (int i = 1; i < n; ++i) {       if (!used_row[i]) {         ++ans;       }     }     cout << ans;   }
#include <bits/stdc++.h>   bool canWin(long long b, long long e) {     if (e % 2 == 1) {       return b % 2 == 0;     } else if (e < 2 * b) {       return b % 2 == 1;     } else if (e < 4 * b) {       return 1;     } else {       return canWin(b, e / 4);     }   }   bool canLose(long long b, long long e) {     if (e < 2 * b) {       return 1;     } else if (e / 2 % 2 == 1) {       return b % 2 == 0;     } else if (e < 4 * b) {       return b % 2 == 1;     } else {       return canLose(b, e / 4);     }   }   int main() {     int t;     scanf( %d , &t);     bool canBeWinner, canBeLoser;     bool canBeFirst = true;     bool canBeSecond = false;     for (int i = 0; i < t; i++) {       long long b, e;       scanf( %lld%lld , &b, &e);       bool cWin = canWin(b, e);       bool cLose = canLose(b, e);       canBeWinner = (canBeFirst && cWin) || (canBeSecond && !cWin);       canBeLoser = (canBeFirst && cLose) || (canBeSecond && !cLose);       canBeFirst = canBeLoser;       canBeSecond = canBeWinner;     }     printf( %d %d n , canBeWinner, canBeLoser);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   const long long N = 4e7 + 5, N_ = 4e6 + 5;   int cnt = 0, prime[N_];   bitset<N> vis;   void pre() {     for (int i = 2; i < N; ++i) {       if (!vis[i]) prime[cnt++] = i;       for (int j = 0; i * prime[j] < N; ++j) {         vis[i * prime[j]] = 1;         if (i % prime[j] == 0) break;       }     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n;     if (n == 2) {       cout <<  1 1  << endl;       return 0;     }     if (n == 3) {       cout <<  1 1 2  << endl;       return 0;     }     if (n == 4) {       cout <<  1 1 2 1  << endl;       return 0;     }     if (n == 5) {       cout <<  1 2 1 1 1  << endl;       return 0;     }     if (n == 6) {       cout <<  1 2 1 1 1 1  << endl;       return 0;     }     pre();     m = n * (n + 1) / 2;     bool sign = 0;     vector<int> res(n + 1, 0);     int flag = 0;     if (m & 1) {       if (!vis[m - 2]) {         ++res[2];         res.erase(res.begin());         for (auto i : res) cout << i + 1 <<    ;         cout << endl;         return 0;       }       m -= 3;       flag = 3;       res[3] = 2;     }     for (auto i : prime) {       int t = m - i;       if (!i || t < 0) break;       if (!vis[t]) {         for (int i = n; t && i > flag; --i) {           if (i == flag) continue;           if (i <= t) {             t -= i;             ++res[i];           }         }         if (t) {           res = vector<int>(n + 1, 0);           res[flag] = 2;         } else {           sign = 1;           break;         }       }     }     if (!sign) {       cout << -1 << endl;       return 0;     }     res.erase(res.begin());     for (auto i : res) cout << i + 1 <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   inline long long read() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 3) + (x << 1) + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = 1ll * ans * a % 1000000007;       a = 1ll * a * a % 1000000007;       b >>= 1;     }     return ans % 1000000007;   }   signed main() {     cin >> n >> m;     long long c = n - m + 1;     c *= 2;     n++;     n *= 2;     m--;     long long tot = qpow(n, m);     long long amo = (c * tot) % 1000000007;     amo %= 1000000007;     cout << amo;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, k;   int pr(int i) { return (i - 1 + n) % n; }   int nx(int i) { return (i + 1) % n; }   int get(int i, int j) {     if (i > j) swap(i, j);     return min(j - i, n - j + i);   }   char no(char el) {     if (el ==  B )       return  W ;     else       return  B ;   }   int gg(string s) {     int b = 1;     for (char i : s) {       if (i !=  B ) b = 0;     }     int w = 1;     for (char i : s) {       if (i !=  W ) w = 0;     }     return max(w, b);   }   signed main() {     string s;     cin >> n >> k >> s;     if (gg(s)) {       cout << s;       return 0;     }     vector<int> used(n, 0);     int l = 0, r = 0, op = 1e6;     bool ch = false;     while (l < n && op > 0) {       --op;       if (used[l]) {         ++l;       } else if (s[l] == s[pr(l)]) {         ch = true;         while (s[l] == s[nx(l)]) used[l] = 1, l = nx(l);         r = nx(l);         while (s[r] != s[nx(r)]) used[r] = 1, r = nx(r);         int cr = r;         while (s[nx(cr)] == s[cr]) used[cr] = 1, cr = nx(cr);         char last = s[l];         for (int i = nx(l); i != r; i = nx(i)) {           if (get(l, i) > k && get(r, i) > k)             s[i] = no(last), last = no(last);           else if (get(l, i) < get(r, i))             s[i] = s[l], last = s[l];           else if (get(l, i) >= get(r, i))             s[i] = s[r], last = s[r];         }         ++l;       } else {         ++l;       }     }     if (!ch) {       if (k % 2 == 0)         cout << s;       else         for (char i : s) cout << no(i);       return 0;     }     cout << s;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> g[100100];   int aa[100100];   long long dfs(int u, int fa) {     vector<long long> tmp;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != fa && aa[v] - 1 >= 0) {         aa[v] -= 1;         tmp.push_back(dfs(v, u));       }     }     sort(tmp.begin(), tmp.end());     int cc = tmp.size();     long long ans = 0;     for (int i = aa[u]; i >= 1; i--) {       if (cc > 0) {         ans += tmp[--cc] + 2;         aa[u]--;       } else {         break;       }     }     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v != fa) {         int tmp = min(aa[u], aa[v]);         ans += tmp * 2;         aa[u] -= tmp;         aa[v] -= tmp;       }     }     return ans;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &aa[i]);     }     for (int i = 0; i < n - 1; i++) {       int u, v;       scanf( %d%d , &u, &v);       g[u].push_back(v);       g[v].push_back(u);     }     int s;     scanf( %d , &s);     printf( %I64d n , dfs(s, -1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     long long int TESTS, k, a, n, b, c, d, m, x, i, y, z;     cin >> TESTS;     while (TESTS--) {       cin >> n;       cin >> s;       long long int ans = n;       for (long long int i = 0; i <= n - 1; i++) {         if (s[i] ==  1 ) {           a = max(i + 1, n - i);           ans = max(ans, 2 * a);         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int limit = 10000;   int query(vector<long long> &v) {     int n = (int)v.size();     cout << n <<    ;     for (int i = 0; i < n; i++) {       cout << v[i] << (i == n - 1 ?   n  :    );     }     int k;     cin >> k;     if (k == -1) {       exit(0);     } else if (k == -2) {       assert(false);     }     return k;   }   int main() {     vector<vector<long long>> dp(6, vector<long long>(10010));     for (int q = 1; q <= 5; q++) {       for (long long p = 1; p <= limit; p++) {         if (q == 5 && p == 2) {           break;         }         long long x = p;         for (int i = 0; i < p; i++) {           x += dp[q - 1][min(10000LL, x)];           x++;         }         x += dp[q - 1][min(10000LL, x)];         dp[q][p] = x - p;       }     }     long long lb = 1, ub = 10004205361450474LL;     for (int q = 5; q >= 1; q--) {       vector<long long> hoge;       long long x = lb;       for (int i = 0; i < min(10000LL, lb); i++) {         x += dp[q - 1][min((long long)10000, x)];         hoge.push_back(x);         x++;       }       x += dp[q - 1][min(10000LL, x)];       int k = query(hoge);       if (k == 0) {         ub = hoge[0] - 1;       } else if (k == (int)hoge.size()) {         lb = hoge.back() + 1;       } else {         lb = hoge[k - 1] + 1;         ub = hoge[k] - 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)1e5 + 10;   int sx[MAXN], sy[MAXN], sz[MAXN];   char s[MAXN];   void solve(int x, int y, int z) {     if (x + y + z < 3) {       printf( YES n );       return;     }     int e = (x + y + z) / 3;     vector<int> v;     v.push_back(x);     v.push_back(y);     v.push_back(z);     sort(v.begin(), v.end());     if ((x + y + z) % 3 == 0) {       if (x == e && y == e && z == e)         printf( YES n );       else         printf( NO n );       return;     } else if ((x + y + z) % 3 == 1) {       if (v[2] == e + 1 && v[1] == e)         printf( YES n );       else         printf( NO n );       return;     } else {       if (v[2] == e + 1 && v[1] == e + 1)         printf( YES n );       else         printf( NO n );       return;     }   }   int main() {     scanf( %s , s);     int n = strlen(s);     for (int i = 1; i <= n; i++) {       sx[i] = sx[i - 1] + (s[i - 1] ==  x );       sy[i] = sy[i - 1] + (s[i - 1] ==  y );       sz[i] = sz[i - 1] + (s[i - 1] ==  z );     }     int m;     scanf( %d , &m);     for (int i = 1; i <= m; i++) {       int l, r;       scanf( %d%d , &l, &r);       int x = sx[r] - sx[l - 1], y = sy[r] - sy[l - 1], z = sz[r] - sz[l - 1];       solve(x, y, z);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int siz = 3e5 + 5;   map<int, vector<int>> adjList;   long long int ans[siz] = {0};   long long int cum[siz] = {0};   map<long long int, long long int> q[siz];   void dfs(int cur, int parent, int level, long long int val) {     for (pair<long long int, long long int> temp : q[cur]) {       cum[level] += temp.second;       cum[min(level + temp.first + 1, siz - 1)] -= temp.second;     }     val += cum[level];     ans[cur] = val;     for (int child : adjList[cur]) {       if (child != parent) {         dfs(child, cur, level + 1, val);       }     }     for (pair<long long int, long long int> temp : q[cur]) {       cum[level] -= temp.second;       cum[min(level + temp.first + 1, siz - 1)] += temp.second;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     int n;     cin >> n;     int y;     long long int x;     for (int i = 0; i < (int)(n - 1); i++) {       cin >> x >> y;       adjList[x].push_back(y);       adjList[y].push_back(x);     }     int m;     cin >> m;     int d, v;     for (int i = 0; i < (int)(m); i++) {       cin >> v >> d >> x;       q[v][d] += x;     }     dfs(1, -1, 1, 0);     for (int i = 1; i <= (int)(n); i++) {       cout << ans[i] <<    ;     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   unsigned long long n, a[130], i, b = 1, f[10002];   int main() {     cin >> n;     for (i = 1; i <= n; i++) {       cin >> a[i];       f[a[i]]++;     }     sort(a + 1, a + n + 1);     cout << a[n] <<    ;     for (i = 1; i < n; i++) {       if (f[a[i]] == 1 && a[n] % a[i] != 0) {         b = a[i];       } else if (f[a[i]] == 2) {         b = a[i];       }     }     cout << b;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long MOD = 998244353;   inline long long Msum(long long x) { return x; }   template <typename... Rest>   inline long long Msum(long long x, Rest... rest) {     return (x + Msum(rest...)) % MOD;   }   inline long long Mprod(long long x) { return x; }   template <typename... Rest>   inline long long Mprod(long long x, Rest... rest) {     return x * Mprod(rest...) % MOD;   }   inline long long Mnorm(long long x) { return (x % MOD + MOD) % MOD; }   long long Msq(long long x) { return x * x % MOD; }   long long Mpow(long long b, long long e) {     return e ? Mprod(Msq(Mpow(b, e >> 1)), (e & 1 ? b : 1)) : 1;   }   long long Minv(long long x) { return Mpow(x, MOD - 2); }   const int MAXN = 51;   int sns[MAXN], w[MAXN];   int wi, sn;   int sl, sd, S;   long long dp[MAXN][MAXN][MAXN];   long long f(int h, int hl, int hd, int t) {     if (!t) return 0;     long long &ret = dp[h][hl][hd];     if (ret != -1) return ret;     ret = 0;     long long cS = S + hl - hd + sn * h;     ret += Mprod(wi + sn * h, Minv(cS), 1 + f(h + 1, hl, hd, t - 1));     ret = Mnorm(ret);     ret += Mprod(sl + hl, Minv(cS), f(h, hl + 1, hd, t - 1));     ret = Mnorm(ret);     ret += Mprod(sd - hd, Minv(cS), f(h, hl, hd + 1, t - 1));     ret = Mnorm(ret);     assert(sd - hd + sl + hl + wi + sn * h == cS);     return ret;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , &sns[i]);       sns[i] = sns[i] * 2 - 1;     }     for (int i = 0; i < n; i++) {       scanf( %d , &w[i]);     }     for (int i = 0; i < n; i++) {       S = sl = sd = 0;       wi = w[i];       sn = sns[i];       for (int j = 0; j < (int)n; j++) {         S += w[j];         if (j != i) {           if (sns[j] == 1)             sl += w[j];           else             sd += w[j];         }       }       memset(dp, -1, sizeof(dp));       printf( %lld n , Mnorm(wi + sn * f(0, 0, 0, m)));     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1111111;   int a[N];   int n, k;   vector<int> prime, p;   void Getprime() {     for (int i = 2; i <= 1000; i++) {       bool bo = 1;       for (int j = 2; j * j <= i; j++) {         if (i % j == 0) {           bo = 0;           break;         }       }       if (bo) {         prime.push_back(i);       }     }   }   int main() {     Getprime();     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     int K = k;     for (int i = 0; i < prime.size() && prime[i] * prime[i] <= k; ++i) {       int t = prime[i];       if (k % t == 0) {         int m = 1;         while (K % t == 0 && K) {           m *= t;           K /= t;         }         p.push_back(m);       }     }     if (K != 1) {       p.push_back(K);     }     for (int i = 0; i < p.size(); ++i) {       int pr = p[i];       bool flag = false;       for (int j = 1; j <= n; ++j) {         if (a[j] % pr == 0) {           flag = true;           break;         }       }       if (!flag) {         puts( No );         return 0;       }     }     puts( Yes );   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void smn(T &a, const T &b) {     if (b < a) a = b;   }   template <class T>   inline void smx(T &a, const T &b) {     if (b > a) a = b;   }   template <class T>   inline T gcd(T x, T y) {     return y ? gcd(y, x % y) : x;   }   namespace std {   template <class T, class U>   struct hash<pair<T, U>> {     inline size_t operator()(const pair<T, U> &p) const {       return hash<T>()(p.first) * 701 + hash<U>()(p.second);     }   };   }  // namespace std   const double eps = 1e-8;   const int key = 701;   const int MN = 1000 * 1000 + 1000;   string s;   long long h1[MN], pw1[MN], h2[MN], pw2[MN];   const int MOD = 1000 * 1000 * 1000 + 7;   long long add[MN];   int n, k;   pair<long long, long long> get(int s, int e) {     long long res1 = h1[e];     if (s != 0) res1 -= pw1[e - s + 1] * h1[s - 1];     long long res2 = h2[e];     if (s != 0) res2 -= pw2[e - s + 1] * h2[s - 1], res2 %= MOD;     if (res2 < 0) res2 += MOD;     return make_pair(res1, res2);   }   bool check(int l) {     auto v = get(0, l - 1);     int now = l;     for (int i = 1; i < k; i++) {       if (get(now, now + l - 1) != v) return 0;       now += l;     }     return 1;   }   int fnd(int p) {     int s = 1, e = n - p, res = 0;     while (s <= e) {       int m = (s + e) / 2;       if (get(0, m - 1) == get(p, p + m - 1))         res = m, s = m + 1;       else         e = m - 1;     }     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k >> s;     long long now = 0;     for (int i = 0; i < n; i++) now = now * 701 + s[i], h1[i] = now;     pw1[0] = 1;     for (int i = 1; i <= n; i++) pw1[i] = 701 * pw1[i - 1];     now = 0;     for (int i = 0; i < n; i++) now = (now * 701 + s[i]) % MOD, h2[i] = now;     pw2[0] = 1;     for (int i = 1; i <= n; i++) pw2[i] = (701 * pw2[i - 1]) % MOD;     for (int i = 1; i <= n; i++)       if (n / i >= k && check(i)) {         int t = i * k;         int b = fnd(t);         smn(b, i);         add[t - 1] += 1;         add[t + b] += -1;       }     now = 0;     for (int i = 0; i < n; i++) {       now += add[i];       cout << (now ? 1 : 0);     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int upd(int& a, int b) { return a = min(a, b); }   inline int _abs(int x) { return x > 0 ? x : -x; }   char c;   int n, cnt[3], type[80];   int pos[3][80], leq[3][80];   int dp[80][80][80][80];   void getpos(void) {     for (int p = 0; p <= 2; p++) {       cnt[p] = 0;       for (int y = 1; y <= n; y++) {         while (y <= n && type[y] != p) y++;         if (y <= n) pos[p][++cnt[p]] = y;       }       leq[p][0] = 0;       for (int i = 1; i <= n; i++) leq[p][i] = leq[p][i - 1] + (type[i] == p);     }     return;   }   void trans(int i, int j, int k, int lst) {     int p0 = pos[0][i], p1 = pos[1][j], p2 = pos[2][k];     if (i > 0)       upd(dp[0][i][j][k],           dp[lst][i - 1][j][k] + _abs(j - leq[1][p0]) + _abs(k - leq[2][p0]));     if (j > 0)       upd(dp[1][i][j][k],           dp[lst][i][j - 1][k] + _abs(i - leq[0][p1]) + _abs(k - leq[2][p1]));     if (k > 0 && lst != 1)       upd(dp[2][i][j][k],           dp[lst][i][j][k - 1] + _abs(i - leq[0][p2]) + _abs(j - leq[1][p2]));     return;   }   int main(void) {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf(  %c , &c);       type[i] = (c ==  V  ? 1 : (c ==  K  ? 2 : 0));     }     getpos();     memset(dp, 0x1f, sizeof(dp));     dp[0][0][0][0] = 0;     for (int i = 0; i <= cnt[0]; i++)       for (int j = 0; j <= cnt[1]; j++)         for (int k = 0; k <= cnt[2]; k++)           for (int lst = 0; lst <= 2; lst++) trans(i, j, k, lst);     int ans = n * n;     for (int i = 0; i <= 2; i++) upd(ans, dp[i][cnt[0]][cnt[1]][cnt[2]]);     printf( %d n , ans >> 1);     return 0;   }