malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read(T &t) {     t = 0;     char ch = getchar();     int f = 1;     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     do {       (t *= 10) += ch -  0 ;       ch = getchar();     } while ( 0  <= ch && ch <=  9 );     t *= f;   }   const long long mod = 998244353;   long long ksm(long long x, long long y) {     if (x < 0) x += mod;     if (x >= mod) x -= mod;     long long res = 1;     while (y) {       if (y & 1) res = res * x % mod;       x = x * x % mod;       y >>= 1;     }     return res;   }   long long n, m, N, L, R, ans, x, y;   int main() {     read(n);     read(m);     read(L);     read(R);     N = n * m;     x = R / 2 - (L - 1) / 2;     y = R - L + 1 - x;     if (N % 2 == 1)       ans = ksm(x + y, N);     else {       ans = ksm(x + y, N) + ksm(x - y, N);       ans %= mod;       if (N % 2 == 0) ans = ans * ksm(2, mod - 2) % mod;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T &k) {     k = 0;     int flag = 1;     char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) flag = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       k = k * 10 + c -  0 ;       c = getchar();     }     k *= flag;   }   const int N = 1005;   int n, m, k, s, t;   long long pa, pb, f[N][N], A, B;   void exgcd(long long a, long long b, long long &x, long long &y) {     if (a == 0) {       x = 0;       y = 1;       return;     }     exgcd(b % a, a, y, x);     x -= b / a * y;   }   long long inv(long long a) {     long long x, y;     exgcd(a, 1000000007, x, y);     return x;   }   int main() {     cin >> k >> pa >> pb;     A = pa * inv(pa + pb) % 1000000007;     B = pb * inv(pa + pb) % 1000000007;     for (int i = k; i >= 1; --i)       for (int j = k - 1; j >= 0; --j) {         if (i + j >= k) {           f[i][j] = (i + j + pa * inv(pb)) % 1000000007;         } else {           f[i][j] = (A * f[i + 1][j] + B * f[i][i + j]) % 1000000007;         }       }     cout << (f[1][0] + 1000000007) % 1000000007 << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.1415926535897923846;   const long long int MOD = 1000000007;   const long long int N = 998244353;   long long int power(long long int x, long long int n) {     long long int res = 1;     while (n > 0) {       if (n & 1) res = res * x % MOD;       x = x * x % MOD;       n >>= 1;     }     return res;   }   long long int modinverse(long long int a) { return power(a, MOD - 2); }   void solve() {     long long int n;     cin >> n;     vector<long long int> a(n);     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     if (n % 2 == 0) {       long long int xo = 0;       for (long long int i = 0; i < n - 1; i++) xo = (xo ^ a[i]);       if (a.back() - xo) {         cout <<  NO n ;         return;       }     }     n -= (1 - n % 2);     cout <<  YES n ;     cout << n - 1 << endl;     for (long long int i = 0; i + 2 < n; i += 2) {       cout << i + 1 <<     << i + 2 <<     << i + 3 << endl;     }     for (long long int i = n - 3; i >= 0; i -= 2) {       cout << i + 1 <<     << i + 2 <<     << i + 3 << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int test = 1;     while (test--) {       solve();     }     cerr <<  Time :   << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC          <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int p[3500];     int n;     cin >> n;     bool b = 1;     int j = 1;     for (int i = 1; i <= n; i++) {       cin >> p[i];     }     sort(p + 1, p + n + 1);     for (int i = 1; i <= n; i++) {       if (p[i] != j) {         cout << j;         return 0;       } else {         j++;       }     }     cout << p[n] + 1;     return 0;   }
#ifndef ONPC     #define _FORTIFY_SOURCE 0     #pragma GCC optimize( Ofast )     #pragma GCC optimize( no-stack-protector )     #pragma GCC optimize( unroll-loops )     #pragma GCC target( sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native )     #pragma GCC optimize( fast-math )   #endif      #include <bits/stdc++.h>      #define mp make_pair   #define eb emplace_back   #define x first   #define y second      template <typename T>   bool chmax(T &a, const T &b) {       if (a < b) {         a = b;           return true;       }       return false;   }      template <typename T>   bool chmin(T &a, const T &b) {       if (a > b) {         a = b;         return true;       }       return false;   }      using namespace std;      typedef long long ll;   typedef long double ld;   typedef pair<int, int> pt;      #ifdef ONPC   mt19937 rnd(228);   #else   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   #endif      const ll MOD = 1000000007LL;   const ll MOD2 = 998244353LL;   const ld PI = acos(-1);      #ifdef ONPC   const int MAXN = 100;   #else   const int MAXN = 300100;   #endif   //#define int long long   const ll INF = 1e18;      void solve(){     int n;     cin >> n;     vector<int> p(n);     for (int i = 1; i < n; i++){       cin >> p[i];       p[i]--;     }     vector<ll> a(n);     for (int i = 1; i < n; i++){       cin >> a[i];     }     vector<int> d(n, 0);     for (int i = 1; i < n; i++){       if (d[i]) continue;       vector<int> q;       int j = i;       while (j != 0) {         q.eb(j);         j = p[j];       }       reverse(begin(q), end(q));       for (int k = 0; k < q.size(); k++){         d[q[k]] = k + 1;       }     }        vector<vector<int>> v(n, vector<int>());     for (int i = 0; i < n; i++){       v[d[i]].eb(i);     }        vector<ll> dp(n, 0);     for (int i = 1; i < n; i++){       if (v[i].empty()) break;          ll mnc = INF, mxc = -INF;       for (int j : v[i]){         chmin(mnc, a[j]);         chmax(mxc, a[j]);       }       ll mx1 = -INF, mx2 = -INF;       for (int j : v[i]){         chmax(mx1, dp[p[j]] + a[j]);         chmax(mx2, dp[p[j]] - a[j]);       }       for (int j : v[i]){         dp[j] = dp[p[j]] + max(a[j] - mnc, mxc - a[j]);         chmax(dp[j], mx1 - a[j]);         chmax(dp[j], mx2 + a[j]);       }     }        ll ans = 0;     for (int i = 0; i < n; i++) chmax(ans, dp[i]);        //for (int i = 0; i < n; i++) cerr << i <<   :   << dp[i] <<   n ;        cout << ans <<   n ;   }      /*   #ifndef ONPC   #define FILEIO   #endif   */   signed main()   {       #ifdef FILEIO         freopen( input.txt ,  r , stdin);         freopen( output.txt ,  w , stdout);       #endif          ios_base::sync_with_stdio(0);       cin.tie(0);          int Q;       cin >> Q;       while (Q--)         solve();          return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int dx[] = {0, 1, 0, -1, -1, 1, -1, 1};   long long int dy[] = {-1, 0, 1, 0, -1, 1, 1, -1};   const long long int MAXN = 2e5 + 5;   const long long int N = 2e5 + 5;   long long int n, m;   void LCSubsequence(string s1, string s2) {     long long int n1 = s1.size(), n2 = s2.size();     vector<vector<long long int>> dp(n1 + 1, vector<long long int>(n2 + 1, 0));     long long int res = 0;     for (long long int i = 0; i <= n1; i++) {       for (long long int j = 0; j <= n2; j++) {         if (i == 0 || j == 0) {           dp[i][j] = 0;         } else if (s1[i - 1] == s2[j - 1]) {           dp[i][j] = dp[i - 1][j - 1] + (4 - 2);         } else {           dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) - 1;         }         if (dp[i][j] < 0) dp[i][j] = 0;         res = max(res, dp[i][j]);       }     }     cout << res <<   n ;   }   long long int goAns = 0;   long long int go(long long int i, long long int j, string s1, string s2) {     if (i >= n || j >= m) return 0;     long long int x = 0, y = 0, res = 0;     if (s1[i] == s2[j]) {       res = (4 - 2) + max(0LL, go(i + 1, j + 1, s1, s2));     } else {       x = -1 + go(i + 1, j, s1, s2);       y = -1 + go(i, j + 1, s1, s2);       res = max({0LL, x, y});     }     goAns = max(goAns, res);     return res;   }   void solve() {     long long int x, y, z;     cin >> n >> m;     string s1, s2;     cin >> s1 >> s2;     LCSubsequence(s1, s2);   }   int32_t main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int T = 1;     while (T--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, ans = 0x3f3f3f3f;   int a[100005], cnt;   int b[100005], gc;   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= 9; ++i) {       cnt = 0;       if (i == 1) b[1] = a[1] - 1, b[2] = a[2] - 1;       if (i == 2) b[1] = a[1] - 1, b[2] = a[2] + 0;       if (i == 3) b[1] = a[1] - 1, b[2] = a[2] + 1;       if (i == 4) b[1] = a[1] + 0, b[2] = a[2] - 1;       if (i == 5) b[1] = a[1] + 0, b[2] = a[2] + 0;       if (i == 6) b[1] = a[1] + 0, b[2] = a[2] + 1;       if (i == 7) b[1] = a[1] + 1, b[2] = a[2] - 1;       if (i == 8) b[1] = a[1] + 1, b[2] = a[2] + 0;       if (i == 9) b[1] = a[1] + 1, b[2] = a[2] + 1;       cnt = fabs(b[1] - a[1]) + fabs(b[2] - a[2]);       gc = fabs(b[2] - b[1]);       if (b[2] >= b[1])         for (int i = 3; i <= n; ++i) {           b[i] = a[i];           if (b[i] - gc - b[i - 1] > 1 || b[i] - gc - b[i - 1] < -1) {             cnt = 0x3f3f3f3f;             break;           } else {             if (b[i] == gc + b[i - 1])               continue;             else if (b[i] == gc + b[i - 1] + 1)               --b[i];             else if (b[i] == gc + b[i - 1] - 1)               ++b[i];             cnt += fabs(a[i] - b[i]);           }         }       if (b[2] < b[1]) {         for (int i = 3; i <= n; ++i) {           b[i] = a[i];           if (b[i] + gc - b[i - 1] > 1 || b[i] + gc - b[i - 1] < -1) {             cnt = 0x3f3f3f3f;             break;           } else {             if (b[i] == b[i - 1] - gc)               continue;             else if (b[i] == b[i - 1] - gc + 1)               --b[i];             else if (b[i] == b[i - 1] - gc - 1)               ++b[i];             cnt += fabs(a[i] - b[i]);           }         }       }       ans = min(cnt, ans);     }     if (ans == 0x3f3f3f3f)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma optimization_level 3   #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 )   #pragma GCC target( avx,avx2,fma )   using namespace std;   mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());   int a, k, nc = 0, isz = 0;   vector<unordered_set<int>> n, l;   vector<int> cmp, vrt;   void dfs(int v) {     cmp[v] = nc;     vrt.push_back(v);     for (int i : l[v]) {       if (cmp[i] == -1)         dfs(i);       else if (cmp[i] != nc) {         assert(cmp[i] == 0);         isz = 1;       }     }   }   int main() {     cin.tie(0);     cout.tie(0);     cin.sync_with_stdio(0);     cout.sync_with_stdio(0);     ;     cin >> a >> k;     cmp = vector<int>(a, -1);     l = vector<unordered_set<int>>(a, unordered_set<int>());     n = vector<unordered_set<int>>(a, unordered_set<int>());     for (int q = 0; q < k; q++) {       int x, y;       cin >> x >> y;       x--, y--;       n[x].insert(y);       n[y].insert(x);     }     for (int q = 0; q < a; q++) {       int sos = (a - 1) - n[q].size();       if (sos > a / 2) cmp[q] = 0;     }     for (int q = 0; q < a; q++) {       if (cmp[q] != -1) continue;       for (int w = 0; w < a; w++) {         if (w == q || n[q].count(w)) continue;         l[q].insert(w);       }     }     for (int q = 0; q < a; q++) {       if (cmp[q] != -1) continue;       nc = q + 1;       vrt.clear();       isz = 0;       dfs(q);       if (isz) {         for (int i : vrt) cmp[i] = 0;       }     }     map<int, int> mp;     for (int i : cmp) mp[i]++;     vector<int> u;     for (pair<int, int> p : mp) u.push_back(p.second);     sort(u.begin(), u.end());     cout << u.size() <<   n ;     for (int i : u) cout << i <<    ;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int main() {     int n, i, j, k, l, m;     cin >> n;     cin >> s;     int cnt, ans;     char c, c1, c2, c3;     ans = 0;     for (i = 0; i < n - 1; i++) {       cnt = 0;       if (s[i] == s[i + 1] && i < n - 1) {         c = s[i];         while (s[i] == c) {           i++;           cnt++;         }         ans += (cnt / 2);         if (i < n) c2 = s[i];         if (c2 ==  R  && c ==  B )           c1 =  G ;         else if (c2 ==  R  && c ==  G )           c1 =  B ;         else if (c2 ==  B  && c ==  G )           c1 =  R ;         else if (c2 ==  B  && c ==  R )           c1 =  G ;         else if (c2 ==  G  && c ==  B )           c1 =  R ;         else if (c2 ==  G  && c ==  R )           c1 =  B ;         if (i >= n) {           if (c ==  R )             c1 =  B ;           else if (c ==  B )             c1 =  G ;           else             c1 =  R ;         }         for (j = i - cnt + 1; j < i; j += 2) s[j] = c1;         i--;       }     }     printf( %d n , ans);     cout << s << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int x[100009], y[100009], z[100009], m, l, r;   int main() {     cin >> s;     cin >> m;     for (int i = 1; i <= s.size(); i++) {       x[i] = x[i - 1];       y[i] = y[i - 1];       z[i] = z[i - 1];       if (s[i - 1] ==  x ) x[i]++;       if (s[i - 1] ==  y ) y[i]++;       if (s[i - 1] ==  z ) z[i]++;     }     for (int i = 1; i <= m; i++) {       cin >> l >> r;       if (min(x[r] - x[l - 1], min(y[r] - y[l - 1], z[r] - z[l - 1])) + 1 >=           max(x[r] - x[l - 1], max(y[r] - y[l - 1], z[r] - z[l - 1]))) {         cout <<  YES n ;         continue;       }       if (r - l + 1 <= 2) {         cout <<  YES n ;         continue;       }       cout <<  NO n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     int a[110];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int i, one, two, j, ans = 0;     for (i = 0; i < k; i++) {       for (one = 0, two = 0, j = i; j < n; j += k) {         if (a[j] == 1)           one++;         else           two++;       }       ans += min(one, two);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int main() {     cin >> n >> a >> b;     int t = 1;     int r = 0;     if (a > b) {       a ^= b ^= a ^= b;     }     while (t < n) {       t <<= 1;       ++r;     }     t >>= 1;     if (a <= t && b > t) {       cout <<  Final!  << endl;       return 0;     }     while (a > t || b <= t) {       a -= a > t ? t : 0;       b -= b > t ? t : 0;       t >>= 1;       --r;     }     cout << r << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mo = 1e9 + 7;   const int maxi = 1e6 + 6;   long long a[maxi], x[maxi], b[maxi];   int n;   long long t;   int sum[maxi];   int los[maxi];   int ll[maxi];   int main() {     cin >> n >> t;     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 1; i <= n; i++) {       scanf( %lld , &x[i]);       sum[x[i] - 1]++;       sum[i - 1]--;     }     for (int i = n; i > 0; i--) sum[i] += sum[i + 1];     for (int i = 1; i <= n; i++)       if (x[i] < i || x[i] < x[i - 1]) return !printf( No n );     for (int i = 1; i <= n; i++)       if (sum[i] > 0)         b[i] = a[i + 1] + t;       else         b[i] = a[i] + t;     for (int i = 2; i <= n; i++)       if (b[i] <= b[i - 1]) b[i] = b[i - 1] + 1;     for (int i = 2; i <= n; i++)       if (a[i] + t > b[i - 1]) los[i] = 1;     for (int i = 1; i <= n; i++) ll[i] = ll[i - 1] + los[i];     for (int i = 1; i <= n; i++)       if (x[i] < n && x[i] - i > 0 && ll[x[i] + 1] - ll[i] == 0)         return !printf( No n );     printf( Yes n );     for (int i = 1; i <= n; i++) printf( %lld  , b[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef vector<vector<int>> graph;   ifstream in( buffcraft.in , ios::in);   ofstream out( buffcraft.out , ios::out);   int pl, pr, vl, vr, k;   vector<int> p;   void dfs(long long x) {     if (x < 1000000000) {       p.push_back(x);       dfs(x * 10 + 4);       dfs(x * 10 + 7);     }   }   int main() {     dfs(0);     p.push_back(INT_MAX);     sort(p.begin(), p.end());     cin >> pl >> pr >> vl >> vr >> k;     double cnt = 0;     double all = ((vr - vl) + 1.0) * ((pr - pl) + 1.0);     for (int i = 1; i < p.size() - k; i++) {       int lm = p[i - 1] + 1, l = p[i], r = p[i + k - 1], rp = p[i + k] - 1;       if (pl <= l && pr >= lm && vl <= rp && vr >= r)         cnt +=             (min(pr, l) - max(pl, lm) + 1.0) * (min(vr, rp) - max(vl, r) + 1.0);       if (vl <= l && vr >= lm && pl <= rp && pr >= r) {         cnt +=             (min(vr, l) - max(vl, lm) + 1.0) * (min(pr, rp) - max(pl, r) + 1.0);         if (k == 1) cnt -= 1.0;       }     }     cout << setprecision(10) << cnt / all;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 256;   int n, a[MAXN], k, ans;   list<int> L;   set<int> s, S;   multiset<int> M;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       if (i >= k) s.insert(a[i]);     }     if (s.size() > 1) {       cout << -1;       return 0;     }     ans = k - 1;     while (a[ans] == a[k]) --ans;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long ret = 0;   long long La, Ra, Ta;   long long Lb, Rb, Tb;   long long GCD = 0;   pair<long long, long long> gcd(long long a, long long b) {     if (b == 0) {       GCD = a;       return {1, 0};     }     pair<long long, long long> nxt = gcd(b, a % b);     long long x = nxt.first;     long long y = nxt.second;     long long k = a / b;     return {y, x - k * y};   }   int main() {     cout << setprecision(10);     ios::sync_with_stdio(0);     cin.tie(0);     cin >> La >> Ra >> Ta;     cin >> Lb >> Rb >> Tb;     pair<long long, long long> eq = gcd(Ta, Tb);     long long L0 = La % GCD, R0 = L0 + (Ra - La);     long long L1 = Lb % GCD, R1 = L1 + (Rb - Lb);     La = L0;     Ra = R0;     Lb = L1;     Rb = R1;     for (long long offA = -2; offA <= 2; offA++)       for (long long offB = -2; offB <= 2; offB++) {         long long N_Ra = Ra + offA * Ta;         long long N_La = La + offA * Ta;         long long N_Rb = Rb + offB * Tb;         long long N_Lb = Lb + offB * Tb;         ret = max(ret, min(N_Ra, N_Rb) - max(N_La, N_Lb) + 1);       }     cout << ret <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c;     while (cin >> a >> b >> c) {       if (b >= c) {         b = c - 1;       } else {         c = b + 1;       }       if (a >= b) {         a = b - 1;         cout << a + b + c << endl;       } else {         b = a + 1;         c = a + 2;         cout << a + b + c << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 10;   int n, m, ans, l;   int mark[MAXN], comp[MAXN], scc[MAXN], cyc[MAXN];   vector<int> edge[MAXN], adj[MAXN], radj[MAXN];   deque<int> dq;   void dfs(int source) {     mark[source]++;     ans++, comp[source] = l;     for (auto &u : edge[source])       if (!mark[u]) dfs(u);   }   void dfs1(int source) {     mark[source]++;     for (auto &u : adj[source])       if (!mark[u]) dfs1(u);     dq.push_back(source);   }   void rev(int source) {     mark[source]++;     scc[l]++;     for (auto &u : radj[source])       if (mark[u] == 1) rev(u);   }   int main() {     cin >> n >> m;     while (m--) {       int x, y;       cin >> x >> y;       edge[x].push_back(y), edge[y].push_back(x);       adj[x].push_back(y), radj[y].push_back(x);     }     for (int i = 1; i <= n; i++)       if (!mark[i]) ++l, dfs(i), ans--;     fill(mark, mark + MAXN, 0);     l = 0;     for (int i = 1; i <= n; i++)       if (!mark[i]) dfs1(i);     while (dq.size()) {       int x = dq.back();       dq.pop_back();       if (mark[x] < 2 && !cyc[comp[x]]) {         ++l, rev(x);         if (scc[l] > 1) cyc[comp[x]] = true, ans++;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int MAX3(long long int x, long long int y, long long int z) {     long long int t = max(x, y);     return max(t, z);   }   long long int power(long long int x, long long int n) {     long long int i, ans = 1;     for (i = 1; i <= (n); i += 1) {       ans = ans * x;     }     return ans;   }   void solve() {     long long int n, i, sum = 0;     vector<long long int> a;     cin >> n;     for (i = 0; i < (n); i += 1) {       long long int x;       cin >> x;       a.push_back(x);       if (i % 2 == 0) sum += x;     }     vector<long long int> a1, a2;     long long int m1 = 0, m2 = 0;     for (i = 0; i < (n - 1); i += 1) {       long long int t = -a[i] + a[i + 1];       i++;       a1.push_back(t);     }     for (i = 1; i < (n - 1); i += 1) {       long long int t = -a[i + 1] + a[i];       i++;       a2.push_back(t);     }     long long int s = a1.size();     long long int max_so_far = 0;     long long int max_ending_here = 0;     for (i = 0; i < (s); i += 1) {       max_ending_here += a1[i];       max_so_far = max(max_so_far, max_ending_here);       if (max_ending_here < 0) max_ending_here = 0;     }     m1 = max_so_far;     max_so_far = 0;     max_ending_here = 0;     s = a2.size();     for (i = 0; i < (s); i += 1) {       max_ending_here += a2[i];       max_so_far = max(max_so_far, max_ending_here);       if (max_ending_here < 0) max_ending_here = 0;     }     m2 = max_so_far;     long long int ans = max(m1, m2);     cout << ans + sum << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<vector<int> > a(n, vector<int>(n));     int sum = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         scanf( %d , &a[i][j]);         if (i == j) sum += a[i][j];       }     }     sum &= 1;     int q;     scanf( %d , &q);     const char *cc =  01 ;     while (q--) {       int t;       scanf( %d , &t);       if (t == 3) {         printf( %c , cc[sum]);       } else {         scanf( %d , &t);         sum ^= 1;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   vector<vector<int>> g;   vector<int> deg;   ll ans;   int n, m;   void add_edge(int x, int y) {     if (x > y) {       int t = x;       x = y;       y = t;     }     g[x].push_back(y);     deg[x]++;     deg[y]++;   }   void init() {     scanf( %d %d , &n, &m);     deg.resize(n, 0);     g.resize(n, vector<int>());     ans = 0;     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       y--;       add_edge(x, y);     }     ans = 0;     for (int i = 0; i < n; i++)       ans += (ll)g[i].size() * (ll)(deg[i] - g[i].size());   }   void work() {     int Q;     cout << ans << endl;     scanf( %d , &Q);     for (int qi = 0; qi < Q; qi++) {       int x;       scanf( %d , &x);       x--;       ans -= (ll)g[x].size() * (ll)(deg[x] - g[x].size());       ans += 0;       for (int y : g[x]) {         ll y_size = g[y].size();         ans -= (ll)y_size * (ll)(deg[y] - y_size);         g[y].push_back(x);         y_size++;         ans += (ll)y_size * (ll)(deg[y] - y_size);       }       g[x].clear();       printf( %lld n , ans);     }   }   int main() {     init();     work();     return 0;   }