malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long n, m1, m2, len, bo, ans, fa[1000005], f[1000000], dep[1000000],       nex[1000000], wen[1000000], hea[1000000], val[1000000], v[1000000];   struct arr {     long long x, y, z, bo;   } a[1000000];   bool cmp(arr x, arr y) { return x.z < y.z; }   void add(long long x, long long y, long long z) {     ++len;     nex[len] = hea[x];     wen[len] = y;     val[len] = z;     hea[x] = len;   }   long long find(long long x) {     if (fa[x] == x) return x;     fa[x] = find(fa[x]);     return fa[x];   }   void dfs(long long x, long long y) {     f[x] = y;     dep[x] = dep[y] + 1;     for (long long i = hea[x]; i; i = nex[i])       if (wen[i] != y) {         v[wen[i]] = val[i];         dfs(wen[i], x);       }   }   signed main() {     scanf( %lld%lld%lld , &n, &m1, &m2);     for (long long i = 1; i <= m1; i++) scanf( %lld%lld , &a[i].x, &a[i].y);     for (long long i = m1 + 1; i <= m1 + m2; i++)       scanf( %lld%lld%lld , &a[i].x, &a[i].y, &a[i].z);     sort(a + 1, a + m1 + m2 + 1, cmp);     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = 1, j = 0; i <= m1 + m2 && j < n - 1; i++) {       long long x = find(a[i].x), y = find(a[i].y);       if (x != y) {         ++j;         a[i].bo = 1;         fa[find(x)] = find(y);         add(a[i].x, a[i].y, a[i].z);         add(a[i].y, a[i].x, a[i].z);       }     }     dfs(1, 0);     for (long long i = 1; i <= n; i++) fa[i] = i;     for (long long i = m1 + 1; i <= m1 + m2; i++)       if (!a[i].bo) {         long long x = find(a[i].x), y = find(a[i].y), z = a[i].z;         while (x != y) {           if (dep[x] < dep[y]) swap(x, y);           if (v[x] == 0) ans += z, ++bo;           fa[x] = find(f[x]);           x = find(x);         }       }     if (bo < m1) ans = -1;     printf( %lld , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int MAXK = 1005, MAXM = 30, MOD = 7340033;   int f[MAXM][MAXK];   void DP() {     static int g[MAXK];     int m, k, i, j;     f[0][0] = 1;     for (m = 1; m < MAXM; m++) {       memset(g, 0, sizeof(g));       g[0] = 1;       for (i = 1; i <= 4; i++)         for (k = MAXK - 1; k >= 0; k--) {           for (j = 1; j <= k; j++)             g[k] = (g[k] + (long long)g[k - j] * f[m - 1][j]) % MOD;         }       f[m][0] = 1;       for (k = 1; k < MAXK; k++) f[m][k] = g[k - 1];     }   }   int GetM(int n) {     int res = 0;     for (; (n & 1) && n > 1; n >>= 1) res++;     return res;   }   int main() {     DP();     int tests, n, m, k;     scanf( %d , &tests);     while (tests--) {       scanf( %d%d , &n, &k);       m = GetM(n);       printf( %d n , f[m][k]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 2000 + 5;   char s[maxN];   int t, n, k;   vector<pair<int, int> > ans;   void Reverse(int l, int r) {     ans.push_back(make_pair(l, r));     for (int i = l; i <= (l + r) / 2; ++i) swap(s[i], s[l + r - i]);   }   int main() {     scanf( %d , &t);     while (t--) {       scanf( %d%d , &n, &k);       scanf( %s , s + 1);       ans.clear();       for (int i = 1; i <= n; ++i) {         if (i % 2 && s[i] ==  ) ) {           int j = i + 1;           while (s[j] ==  ) ) ++j;           Reverse(i, j);         }         if (i % 2 == 0 && s[i] ==  ( ) {           int j = i + 1;           while (s[j] ==  ( ) ++j;           Reverse(i, j);         }       }       if (k < n / 2) {         int pos = (k - 1) * 2 + 1;         ans.push_back(make_pair(pos + 1, n - 1));       }       printf( %d n , ans.size());       for (int i = 0; i != ans.size(); ++i)         printf( %d %d n , ans[i].first, ans[i].second);     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i, z = 0, o = 0;     char str[120];     scanf( %d , &n);     getchar();     gets(str);     for (i = 0; i < n; i++) {       if (str[i] ==  0 ) {         z++;       } else {         o++;       }     }     if (o > 0) {       printf( 1 );     }     for (i = 0; i < z; i++) {       printf( 0 );     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   vector<pair<int, int> > res;   vector<vector<int> > v;   int cl[100000 * 2 + 5];   bool visited[100000 * 2 + 5];   void dfs(int now, int color) {     if (visited[now]) return;     visited[now] = true;     cl[now] = color + 1;     for (int i = 0; i < v[now].size(); i++) {       dfs(v[now][i], !color);     }   }   int main() {     scanf( %d , &n);     v.resize(n * 2);     for (int i = 0; i < n; i++) {       scanf( %d %d , &a, &b);       a--;       b--;       res.push_back(make_pair(a, b));       v[a].push_back(b);       v[b].push_back(a);     }     for (int i = 0; i < 2 * n; i += 2) {       v[i].push_back((i + 1) % (n * 2));       v[(i + 1) % (n * 2)].push_back(i);     }     for (int i = 0; i < 2 * n; i++) {       if (!visited[i]) {         dfs(i, 0);       }     }     for (int i = 0; i < n; i++) {       printf( %d %d n , cl[res[i].first], cl[res[i].second]);     }   }
#include <bits/stdc++.h>   using namespace std;   string s;   long long int n, k;   long long int L, R;   bool query(long long int l, long long int r) {     l = max(1LL, l);     r = min(n, r);     cout << l <<     << r << endl;     cin >> s;     if (s ==  Bad ) exit(0);     if (s ==  Yes ) {       if (l == r) exit(0);       return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(0);     srand(time(NULL));     string s;     cin >> n >> k;     L = 1;     R = n;     while (true) {       long long int len = (R - L + 1);       if (len <= 5 * k + 4) {         len = rand() % len;         query(L + len, L + len);         L = max(1LL, L - k);         R = min(n, R + k);       } else {         long long int M = (L + R) / 2;         if (query(L, M)) {           L = L - k;           R = M + k;         } else {           L = M - k;           R = R + k;         }       }       L = max(1LL, L);       R = min(n, R);     }     exit(0);   }
#include <bits/stdc++.h>   using namespace std;   int a[200100];   int b[200100];   int p[200100];   int m[200100];   int main() {     int n;     scanf( %d , &n);     for (int i = (0); i < (n); ++i) scanf( %d , &a[i]);     for (int i = (0); i < (n); ++i) {       scanf( %d , &b[i]);       p[b[i]] = i;     }     int res = 0;     m[0] = p[a[0]];     for (int i = (1); i < (n); ++i)       m[i] = ((m[i - 1] < p[a[i]]) ? (p[a[i]]) : (m[i - 1]));     for (int i = n - 1; i > 0; --i)       if (m[i - 1] > p[a[i]]) res = n - i;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > v;   map<char, bool> mpp;   map<int, int>::iterator it;   set<string> s;   set<pair<int, int> >::iterator iter;   deque<char> d;   long long a[500001];   int main() {     ios::sync_with_stdio(false);     long long n, a, b, c, d, ans = 1, y1, y2, y3, y4;     cin >> n >> a >> b >> c >> d;     if (a >= d) {       y1 = 1;       y2 = a - d + 1;     } else {       y2 = 1;       y1 = d - a + 1;     }     y4 = c + y1 - b;     y3 = y4 + a - d;     if (y1 <= 0) {       y4 += 1 - y1;       y3 += 1 - y1;       y2 += 1 - y1;       y1 += 1 - y1;     }     if (y2 <= 0) {       y4 += 1 - y2;       y3 += 1 - y2;       y1 += 1 - y2;       y2 += 1 - y2;     }     if (y3 <= 0) {       y4 += 1 - y3;       y1 += 1 - y3;       y2 += 1 - y3;       y3 += 1 - y3;     }     if (y4 <= 0) {       y1 += 1 - y4;       y3 += 1 - y4;       y2 += 1 - y4;       y4 += 1 - y4;     }     if (y4 > n || y3 > n || y2 > n || y1 > n) {       cout << 0;       return 0;     }     if (n - max(y1, max(y2, max(y3, y4))) > 0)       ans += n - max(y1, max(y2, max(y3, y4)));     cout << ans * n;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int dp[maxn], num[30];   int main() {     int i, j, k, n, m, t, l, ans, x, y, z;     char s[maxn];     scanf( %d , &t);     while (t--) {       scanf( %d%d%d , &n, &m, &k);       scanf( %s , s);       ans = 1e9;       memset(num, 0, sizeof(num));       for (i = 0; i < k; i++) {         num[s[i] -  A  + 1]++;       }       for (l = 1; l <= 26; l++) {         if (num[l] == 0) continue;         for (i = 0; i <= k; i++) dp[i] = 0;         dp[0] = 1;         for (i = 1; i <= 26; i++) {           if (num[i] == 0 || i == l) continue;           for (j = k; j >= num[i]; j--)             if (dp[j - num[i]] == 1) dp[j] = 1;         }         for (i = 0; i <= k; i++) {           if (dp[i] == 1) {             if (i + num[l] >= n) {               x = max(0, n - i);               z = k - num[l] - i;               if (z + num[l] - x >= m) {                 y = max(0, m - z);                 ans = min(ans, x * y);               }             }           }         }       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 10;   const int INF = 0x3f3f3f3f;   const double eps = 1e-9;   const int mod = 1e9 + 7;   int dp[N];   int main() {     dp[0] = 1;     int num;     while (scanf( %d , &num) != EOF) {       bool flag = 0;       if (num == 1) {         printf( 1 1 n );         printf( 1 n );         return 0;       }       int ans, cnt;       for (int i = 1; i <= 2; i++) {         for (int j = 0; j < N; j++) {           if (j >= i) {             dp[j] += dp[j - i];           }           if (dp[j] == num) {             ans = j;             cnt = i;             flag = 1;             break;           }         }         if (flag) {           printf( %d %d n , ans, cnt);           if (cnt == 1)             printf( 1 n );           else             printf( 1 2 n );           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   const int mod = (int)1e+9 + 7;   const double pi = acos(-1.);   const int maxn = 1000100;   long long a[maxn];   int main() {     {       srand(time(0));       const string file =   ;       if (!file.empty()) {         freopen((file +  .in ).c_str(),  r , stdin);         freopen((file +  .out ).c_str(),  w , stdout);       }     }     int n;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %lld , &a[i]);     }     long long ans = 0, pref = 0;     for (int i = 0; i < n; i++) {       ans += pref * (min(a[i], i ? a[i - 1] : mod) - 1) + a[i] - 1;       ans %= mod;       long long h = min(i ? a[i - 1] : mod, i + 1 == n ? mod : a[i + 1]);       h = min(h, a[i]);       h--;       pref *= h;       pref += min(a[i], i + 1 < n ? a[i + 1] : mod) - 1;       pref %= mod;     }     printf( %lld , ans);     return (0);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long a1, a2, a3, a4, c = 0;     cin >> a1 >> a2 >> a3 >> a4;     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  1 )         c += a1;       else if (s[i] ==  2 )         c += a2;       else if (s[i] ==  3 )         c += a3;       else if (s[i] ==  4 )         c += a4;     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   class Edge {    public:     int neighbour;     int edge_number;     int weight;     Edge(int neigh, int edge_no, int weig) {       neighbour = neigh;       edge_number = edge_no;       weight = weig;     }   };   int main() {     int n, m;     cin >> n >> m;     vector<vector<Edge> > adj_list(n + 1);     for (int i = 1; i <= m; i++) {       int vertex1, vertex2, weight;       cin >> vertex1 >> vertex2 >> weight;       Edge temp = Edge(vertex2, i, weight);       adj_list[vertex1].push_back(temp);       temp = Edge(vertex1, i, weight);       adj_list[vertex2].push_back(temp);     }     int source;     cin >> source;     vector<bool> check_list(n + 1, false);     priority_queue<pair<long long int, int> > pq;     vector<pair<int, int> > parent(n + 1, make_pair(0, 0));     for (int i = 1; i <= n; i++) {       if (i != source)         pq.push(make_pair(LLONG_MIN, i));       else         pq.push(make_pair(0, i));     }     vector<pair<long long int, int> > dist(n + 1, make_pair(LLONG_MAX, 0));     dist[source].first = 0;     while (!pq.empty()) {       int vertex = pq.top().second;       pq.pop();       if (check_list[vertex] == false) {         check_list[vertex] = true;         for (int i = 0; i < adj_list[vertex].size(); i++) {           if (dist[adj_list[vertex][i].neighbour].first >               dist[vertex].first + adj_list[vertex][i].weight) {             parent[adj_list[vertex][i].neighbour].first =                 adj_list[vertex][i].edge_number;             parent[adj_list[vertex][i].neighbour].second =                 adj_list[vertex][i].weight;             dist[adj_list[vertex][i].neighbour].first =                 dist[vertex].first + adj_list[vertex][i].weight;             dist[adj_list[vertex][i].neighbour].second =                 adj_list[vertex][i].weight;             pq.push(make_pair((-1) * (dist[adj_list[vertex][i].neighbour].first),                               adj_list[vertex][i].neighbour));           } else if (dist[adj_list[vertex][i].neighbour].first ==                      dist[vertex].first + adj_list[vertex][i].weight) {             if (dist[adj_list[vertex][i].neighbour].second >                 adj_list[vertex][i].weight) {               parent[adj_list[vertex][i].neighbour].first =                   adj_list[vertex][i].edge_number;               parent[adj_list[vertex][i].neighbour].second =                   adj_list[vertex][i].weight;               dist[adj_list[vertex][i].neighbour].second =                   adj_list[vertex][i].weight;             }           }         }       }     }     long long int ans = 0;     for (int i = 1; i <= n; i++) {       ans += parent[i].second;     }     cout << ans << endl;     for (int i = 1; i <= n; i++) {       if (source != i) cout << parent[i].first <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long dp[55][55];   int main() {     int n, m, t;     cin >> n >> m >> t;     dp[0][0] = 1;     for (int i = 1; i <= 31; ++i)       for (int j = 1; j <= 31; ++j) dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];     long long sol = 0;     for (int i = 4; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (i + j == t) {           sol = sol + dp[n + 1][i + 1] * dp[m + 1][j + 1];         }     cout << sol <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[81][81][81][81];   vector<pair<int, int>> graph[81];   int solve(int v, int l, int r, int k) {     if (k == 0) return 0;     if (dp[v][l][r][k] != -1) return dp[v][l][r][k];     int &ret = dp[v][l][r][k];     ret = 1000000;     for (auto e : graph[v]) {       int w = e.second;       int u = e.first;       if (u < r && u > v) {         ret = min(ret, solve(u, v, r, k - 1) + w);       }       if (u > l && u < v) {         ret = min(ret, solve(u, l, v, k - 1) + w);       }     }     return ret;   }   int main() {     int n, k;     scanf( %d %d , &n, &k);     int m;     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int a, b, c;       scanf( %d %d %d , &a, &b, &c);       graph[a].push_back({b, c});     }     int ans = 1000000;     memset(dp, -1, sizeof dp);     for (int i = 1; i <= n; i++) {       ans = min(ans, solve(i, 0, n + 1, k - 1));     }     printf( %d n , ans >= 1000000 ? -1 : ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char s1[1000], s2[1000], s3[1000];     int i, l1, l2, l3;     scanf( %s%s%s , s1, s2, s3);     l1 = strlen(s1);     l2 = strlen(s2);     l3 = strlen(s3);     strcat(s1, s2);     sort(s1, s1 + l1 + l2);     sort(s3, s3 + l3);     if (l1 + l2 == l3) {       for (i = 0; i <= (l1 + l2); i++) {         if (s1[i] != s3[i]) {           printf( NO n );           break;         } else if (i == l1 + l2) {           printf( YES n );         }       }     } else {       printf( NO n );     }     return 0;   }
//   #include <bits/stdc++.h>   using namespace std;      #define fi first   #define se second   #define all(x) x.begin(), x.end()   #define lch (o << 1)   #define rch (o << 1 | 1)      typedef double db;   typedef long long ll;   typedef unsigned int ui;   typedef pair<int, int> pint;   typedef tuple<int, int, int> tint;      const int N = 1e5 + 5;   const int INF = 0x3f3f3f3f;   const ll INF_LL = 0x3f3f3f3f3f3f3f3f;      int a[N];   int mxsuf[N];      int main() {    ios::sync_with_stdio(0);       int n;    cin >> n;    for (int i = 1; i <= n; i++)     cin >> a[i];       vector<int> vec;    int pre = 1;    for (int i = 2; i < n; i++) {     int sgn1 = a[i] - a[i - 1];     sgn1 /= abs(sgn1);     int sgn2 = a[i + 1] - a[i];     sgn2 /= abs(sgn2);     if (sgn1 * sgn2 == -1) {      vec.push_back(i - pre + 1);      pre = i;     }    }    vec.push_back(n - pre + 1);       int m = vec.size();    for (int i = m - 1; i >= 0; i--)     mxsuf[i] = max(mxsuf[i + 1], vec[i]);       int dir = a[2] - a[1];    dir /= abs(dir);    int ans = 0;    int mxpre = 0;    for (int i = 0; i < m; i++) {     if (i - 2 >= 0)      mxpre = max(mxpre, vec[i - 2]);     if (dir == -1 && i > 0) {      int mx = max(vec[i - 1], vec[i]);      int mn = min(vec[i - 1], vec[i]);      bool flag = (mxpre >= mx);      if (i + 1 < m)       flag |= mxsuf[i + 1] >= mx;      flag |= (mn % 2 == 0);      flag |= (mn % 2 == 1) && (mn < mx);      ans += !flag;     }     dir *= -1;    }       cout << ans << endl;       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 700 + 5;   int n, m, d[N], cnt[N][N];   bitset<N> adj[N];   long long ans;   int main() {     scanf( %d%d , &n, &m);     for (int i = 0, u, v; i < m; i++) {       scanf( %d%d , &u, &v);       d[--u]++, d[--v]++;       adj[u][v] = adj[v][u] = true;     }     for (int u = 0; u < n; u++)       for (int v = u; v < n; v++)         cnt[u][v] = cnt[v][u] = (adj[u] & adj[v]).count();     for (int u = 0; u < n; u++)       for (int v = 0; v < n; v++)         if (adj[u][v]) {           for (int x = 0; x < n; x++)             ans += 1LL * (u ^ x && v ^ x) * (cnt[u][x] - adj[x][v]) *                    (cnt[v][x] - adj[x][u]);           ans -= cnt[u][v] * (d[u] - 2);         }     printf( %lld n , ans / 10);   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000000007;   struct Sync_stdio {     Sync_stdio() {       cin.tie(NULL);       ios_base::sync_with_stdio(false);     }   } _sync_stdio;   struct FAIL {     FAIL() {       cout <<  CHANGE!!!             <<   n ;     }   };   string go(int iter, long long a, long long b, long long x) {     string res;     vector<int> used(26);     for (int l = (0); l < (iter); ++l) {       int j = 0;       for (int i = (0); i < (a); ++i) {         while (used[j]) {           ++j;         }         res +=  a  + j;         ++j;       }       char sym = res[res.size() - x];       for (int i = (0); i < (b); ++i) {         res += sym;       }       for (int i = (0); i < (26); ++i) {         used[i] = 0;       }       for (int i = (0); i < (a); ++i) {         used[res[res.size() - 1 - i] -  a ] = 1;       }     }     return res;   }   int solve(int a, int b, int l, int r, int x) {     string s1 = go(10, a, b, x + 1);     set<char> ss;     for (int i = (l); i < (r + 1); ++i) {       ss.insert(s1[i]);     }     return ss.size();   }   int main() {     long long a, b, l, r;     cin >> a >> b >> l >> r;     --l, --r;     long long start = l / (a + b);     long long end = r / (a + b);     if (r - l > 6 * (a + b)) {       cout << max(a + 1LL, a + a - b) <<   n ;       return 0;     }     l -= start * (a + b);     r -= start * (a + b);     int res = INT_MAX;     for (int i = (0); i < (a); ++i) {       res = min(res, solve(a, b, l, r, i));     }     cout << res;   }
// Author: HarshKumar      #include <bits/stdc++.h>   using namespace std;   #define ll int64_t   const ll N = 1e6 + 6, M = 1e9 + 7;   int main()   {       ios::sync_with_stdio(false), cin.tie(nullptr);       ll n, k;       cin >> n >> k;       ll x = min(k * k + 1, n);       string s(x,  a );       map<char, ll> f;       for (ll i = 0; i < k; i++)           f[ a  + i] = i;       for (ll i = 1; i < x; i++)           s[i] =  a  + f[s[i - 1]] % k, f[s[i - 1]]++;       s.erase(s.begin());       cout <<  a ;       n--;       x--;       for (ll i = 0; i < n; i++)           cout << s[i % x];   }
#include <bits/stdc++.h>   using namespace std;   long long inf = std::numeric_limits<long long>::max();   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long T;     cin >> T;     while (T--) {       long long n, i;       cin >> n;       string str;       cin.ignore();       cin >> str;       long long len = str.length();       long long count = 0;       for (i = 0; i < len; i++) {         string y =   ;         y += str[i];         long long num = stoi(y);         if (num > 0) {           count += (num);         }         if (i != (n - 1) && num > 0) {           count++;         }       }       cout << count <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[10];   int f[2001], c[2001], mtr[2001][2001], n, m, q, x, y;   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = 1; i <= n; i++) {       f[i] = i;       for (int j = 1; j <= m; j++) {         scanf( %d , &mtr[i][j]);         c[j] = j;       }     }     while (q--) {       scanf( %s%d%d , s, &x, &y);       if (s[0] ==  c )         swap(c[x], c[y]);       else if (s[0] ==  r )         swap(f[x], f[y]);       else         printf( %d n , mtr[f[x]][c[y]]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   char s[maxn];   struct Node {     int sum, pmx, lmx, mi, ma, d;     Node() {}     Node(int a, int b, int c, int d, int e, int f) {       sum = a;       pmx = b;       lmx = c;       mi = d;       ma = e;       d = f;     }   };   Node segT[maxn << 2];   void maintain(int curPos) {     segT[curPos].sum = segT[curPos << 1].sum + segT[curPos << 1 | 1].sum;     segT[curPos].pmx =         max(segT[curPos << 1].pmx,             max(segT[curPos << 1 | 1].ma - 2 * segT[curPos << 1].mi +                     segT[curPos << 1].sum,                 segT[curPos << 1 | 1].pmx - segT[curPos << 1].sum));     segT[curPos].lmx =         max(segT[curPos << 1].lmx,             max(segT[curPos << 1 | 1].lmx - segT[curPos << 1].sum,                 segT[curPos << 1].ma - 2 * segT[curPos << 1 | 1].mi -                     2 * segT[curPos << 1].sum));     segT[curPos].mi = min(segT[curPos << 1].mi,                           segT[curPos << 1 | 1].mi + segT[curPos << 1].sum);     segT[curPos].ma = max(segT[curPos << 1].ma,                           segT[curPos << 1 | 1].ma + segT[curPos << 1].sum);     segT[curPos].d = max(max(segT[curPos << 1].d, segT[curPos << 1 | 1].d),                          max(segT[curPos << 1].ma + segT[curPos << 1 | 1].pmx -                                  segT[curPos << 1].sum,                              segT[curPos << 1].lmx + segT[curPos << 1].sum +                                  segT[curPos << 1 | 1].ma));   }   void build(int curPos, int curL, int curR) {     if (curL == curR) {       curR = s[curL] ==  (  ? 1 : -1;       segT[curPos] = Node(curR, -curR, -curR, curR, curR, 0);       return;     }     int mid = curL + curR >> 1;     build(curPos << 1, curL, mid);     build(curPos << 1 | 1, mid + 1, curR);     maintain(curPos);   }   void update(int pos, int curPos, int curL, int curR) {     if (curL == curR) return build(curPos, curL, curR);     int mid = curL + curR >> 1;     if (pos <= mid)       update(pos, curPos << 1, curL, mid);     else       update(pos, curPos << 1 | 1, mid + 1, curR);     maintain(curPos);   }   int main() {     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     n = n * 2 - 2;     build(1, 1, n);     printf( %d n , segT[1].d);     while (m--) {       int x, y;       scanf( %d%d , &x, &y);       swap(s[x], s[y]);       update(x, 1, 1, n);       update(y, 1, 1, n);       printf( %d n , segT[1].d);     }     return 0;   }