malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     long long l;     cin >> n >> l;     long double arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     sort(arr, arr + n);     long double ans = arr[0] - 0;     for (int i = 1; i < n; i++) {       ans = max(ans, (arr[i] - arr[i - 1]) / 2.0);     }     ans = max(ans, l - arr[n - 1]);     cout << fixed << setprecision(10) << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long flag, cnt, j, i, k, powe, count1, count2;   long long int n, a, b, c, x, y, m, ans;   long long maxy, miny, sum, ann[1000010];   string s, s2;   long long mod = 1000000007;   int main() {     cin >> n;     n--;     long long arr1[n], arr2[n];     for (i = 0; i < n; i++) {       cin >> arr1[i];       if (arr1[i] == 0) i--;     }     for (i = 0; i < n; i++) {       cin >> arr2[i];       if (arr2[i] == 0) i--;     }     for (i = 0; i < n; i++) {       if (arr2[i] == arr1[0]) break;     }     for (j = 0; j < n; j++) {       if (arr1[j] != arr2[(i + j) % n]) {         flag = 1;         break;       }     }     if (flag == 1)       cout <<  No ;     else       cout <<  Yes ;   }
#include <bits/stdc++.h>   using namespace std;   map<string, string> m;   string a =  ......... ;   inline int judge() {     for (int i = 0; i < 3; i++) {       if (a[3 * i] !=  . )         if (a[3 * i] == a[3 * i + 1] && a[3 * i] == a[3 * i + 2]) return 3 * i;       if (a[i] !=  . )         if (a[i] == a[i + 3] && a[i] == a[i + 6]) return i;     }     if (a[4] ==  . )       return -1;     else if ((a[0] == a[4] && a[4] == a[8]) || (a[2] == a[4] && a[4] == a[6]))       return 4;     return -1;   }   void search(int n) {     int s;     s = judge();     if (s != -1) {       m[a] = (a[s] ==  X  ?  the first player won  :  the second player won );       return;     } else if (n == 9) {       m[a] =  draw ;       return;     } else {       m[a] = (n % 2 == 0 ?  first  :  second );       for (int i = 0; i < 9; i++)         if (a[i] ==  . ) {           a[i] = (n % 2 == 0 ?  X  :  0 );           search(n + 1);           a[i] =  . ;         }     }   }   int main() {     search(0);     string str1, str2, str3;     cin >> str1 >> str2 >> str3;     a = str1 + str2 + str3;     if (m[a] !=   )       cout << m[a] << endl;     else       cout <<  illegal  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int c[100001], s[100001];   int mx, ans, n, nc, ns;   int i, j;   void checkAns(int k) {     if (ns <= 2) {       if ((mx - 1) * nc == (i - 1) || mx * (nc - 1) == (i - 1)) {         if (s[1] == 1 || s[1] == i || 1 == nc || s[mx] == 1) {           ans = i;         }       }     }   }   int main() {     int k;     cin >> n;     for (i = 1; i <= n; ++i) {       cin >> j;       k = c[j];       if (k) {         s[k]--;         if (!s[k]) {           ns--;         }       } else {         nc++;       }       c[j]++;       k++;       if (!s[k]) {         ns++;       }       s[k]++;       if (k > mx) {         mx = k;       }       checkAns(k);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #define ll long long    #define ld long double   #define vi vector<int>   #define pi pair<int,int>   #define F first   #define S second   #define pb push_back   #define mp make_pair   #define FOR for(int i=a;i<b;++i)   #define sq(a) (a)*(a)   #define vll vector<long long>    const int inf=INT_MAX;    const ll INF=LLONG_MAX;    const int MOD=1000000007;    //char-48   int dp[100000];    int main(){    ios::sync_with_stdio(0);     cin.tie(0);      ll t;     cin >> t;     while(t--){     ll n, ans=0;      cin >> n;      vector<ll> v;      for(ll i=0;i<n;++i){      ll u;       cin >> u;       v.pb(u);             ans=max(ans,u);       }     sort(v.begin(), v.end());      ll b=v.size()-1;      ll g=b;      for(ll i=0; i<b; ++i){      ans+=(v[i]-v[i+1])*(g*(i+1));                     --g;       }     cout << ans <<   n ;           }    }      //Erase reps   // sort(v.begin(), v.end() );   // v.erase(unique(v.begin(), v.end() ), v.end());      //Find something to eliminate   // auto i = find(begin(s), end(s),  { );   // s.erase(i);
#include <bits/stdc++.h>   using namespace std;   int i, t, n, ciel, jiro, aux, a[10005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     for (cin >> t; t; --t) {       cin >> n;       for (i = 1; i <= n; ++i) {         cin >> aux;         if (n & 1)           if (i == n / 2 + 1)             a[++a[0]] = aux;           else if (i <= n / 2)             ciel += aux;           else             jiro += aux;         else if (i <= n / 2)           ciel += aux;         else           jiro += aux;       }     }     sort(a + 1, a + a[0] + 1);     for (i = a[0]; i; --i)       if ((a[0] - i) & 1)         jiro += a[i];       else         ciel += a[i];     cout << ciel <<     << jiro <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   long long n, a[10], C[110][110], dp[110][10], ans;   inline long long add(long long x, long long y) {     x += y;     if (x > MOD) x -= MOD;     return x;   }   inline long long mul(long long x, long long y) {     x *= y;     if (x > MOD) x %= MOD;     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(ios::fixed);     cout.precision(20);     cin >> n;     for (int i = 0; i < 10; ++i) cin >> a[i];     C[0][0] = 1;     for (int i = 1; i <= 100; ++i) {       C[i][0] = 1;       for (int j = 1; j <= i; ++j) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]);     }     for (int i = a[9]; i <= n; ++i) dp[i][9] = 1;     for (int i = 0; i <= n; ++i) {       for (int j = 8; j > 0; --j)         for (int k = a[j]; k <= i; ++k)           dp[i][j] = add(dp[i][j], mul(dp[i - k][j + 1], C[i][k]));       for (int j = a[0]; j < i; ++j)         dp[i][0] = add(dp[i][0], mul(dp[i - j][1], C[i - 1][j]));     }     for (int i = 0; i <= n; ++i) ans = add(ans, dp[i][0]);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, ans, num;     scanf( %d , &n);     for (int i = 17; i >= 1; i--) {       num = (pow(2, i) - 1) * pow(2, i - 1);       if (n % num == 0) {         ans = num;         break;       }     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   int n, a[100000];   long long cost, mn;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) scanf( %d , a + i);     sort(a, a + n);     for (int i = 0; i < n; ++i) mn += a[i] - 1;     if (n > 40) return cout << mn, 0;     for (int i = 2; i <= 1e5; ++i) {       int k = 0;       cost = 0;       for (long long j = 1; j <= 1e10 && k < n; j *= i) {         cost += abs(a[k++] - j);       }       if (k == n) mn = min(mn, cost);     }     cout << mn;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e6 + 1e3;   long long all[MAXN];   struct node {     node *child[2];     node() { child[0] = child[1] = NULL; }   };   node *root;   deque<short> binary(long long x) {     deque<short> ans;     while (x) {       ans.push_front(x % 2);       x /= 2;     }     while (ans.size() < 50) ans.push_front(0);     return ans;   }   void add(long long x) {     deque<short> a = binary(x);     node *C = root;     while (a.size()) {       if (C->child[a[0]] == NULL) C->child[a[0]] = new node;       C = C->child[a[0]];       a.pop_front();     }   }   long long query(long long x) {     deque<short> a = binary(x);     long long ans = 0;     node *C = root;     while (a.size()) {       if (C->child[1 - a[0]] != NULL) {         C = C->child[1 - a[0]];         ans *= 2;         ans += 1;       } else {         C = C->child[a[0]];         ans *= 2;       }       a.pop_front();     }     return ans;   }   int main() {     root = new node;     int n;     cin >> n;     long long xorall = 0;     for (int i = 1; i <= n; ++i) {       cin >> all[i];       xorall ^= all[i];     }     long long maxgot = 0;     int ai = 0, bi = 0;     long long total = 0;     add(total);     for (int i = 1; i <= n; ++i) {       total ^= all[i];       add(total);       maxgot = max(maxgot, query(total ^ xorall));     }     cout << fixed << maxgot << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int MOD = 1e9 + 7;   const long long int INF = 1e10;   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     char c = s[0];     long long int a = s[1] -  0 ;     long long int ans = 0;     for (long long int i = -1; i <= 1; i++) {       for (long long int j = -1; j <= 1; j++) {         if (i == j && i == 0) continue;         if ((char)(c + i) <=  h  && (char)(c + i) >=  a ) {           if (a + j >= 1 && a + j <= 8) ans++;         }       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct UnionFind {     vector<int> par;     vector<int> rank;     vector<int> sz;     UnionFind(int n = 0) {       if (n > 0) initialize(n);     }     void initialize(int n) {       par.resize(n);       rank.resize(n);       sz.resize(n);       for (int i = 0; i < n; i++) {         par[i] = i;         rank[i] = 0;         sz[i] = 1;       }     }     int find(int x) {       if (par[x] == x) {         return x;       } else {         return par[x] = find(par[x]);       }     }     void unite(int x, int y) {       x = find(x);       y = find(y);       if (x == y) return;       if (rank[x] < rank[y]) {         par[x] = y;         sz[y] += sz[x];       } else {         par[y] = x;         sz[x] += sz[y];         if (rank[x] == rank[y]) rank[x]++;       }     }     bool same(int x, int y) { return find(x) == find(y); }   };   int main() {     int N, M;     cin >> N >> M;     static pair<int64_t, int> A[200000];     for (int i = 0; i < N; i++) {       int64_t a;       scanf( %lld , &a);       A[i] = {a, i};     }     vector<vector<int64_t>> edges;     for (int i = 0; i < M; i++) {       int64_t x, y, w;       scanf( %lld %lld %lld , &x, &y, &w);       edges.push_back({w, x - 1, y - 1});     }     sort(A, A + N);     int64_t first = A[0].second;     for (int i = 1; i < N; i++) {       int64_t j = A[i].second;       int64_t cost = A[0].first + A[i].first;       edges.push_back({cost, first, j});     }     sort(edges.begin(), edges.end());     int64_t ans = 0;     UnionFind uf(N);     for (auto& v : edges) {       int i = v[1], j = v[2];       if (!uf.same(i, j)) {         ans += v[0];         uf.unite(i, j);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, k;     int n;     cin >> n;     if (n % 2 == 0) {       k = n / 2;       cout << k <<   n ;       for (i = 0; i < k; i++) cout << 2 <<    ;     } else {       k = (n - 1) / 2;       cout << k <<   n ;       for (i = 0; i < k - 1; i++) {         cout << 2 <<    ;       }       cout << 3 <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 + 5;   int n, m, ord[N << 1], nord = 0;   vector<int> adj[N << 1], radj[N << 1];   bool vis[N << 1];   int ncmp = 0, cmp[N << 1];   vector<int> ans;   inline void addedge(int u, int v) {     adj[u].push_back((v > n ? v - n : v + n));     ;     radj[(v > n ? v - n : v + n)].push_back(u);     ;     adj[(u > n ? u - n : u + n)].push_back(v);     ;     radj[v].push_back((u > n ? u - n : u + n));     ;   }   inline void dfs(int v) {     vis[v] = 1;     for (int i = 0; i < (int)adj[v].size(); i++)       if (!vis[adj[v][i]]) dfs(adj[v][i]);     ord[++nord] = v;   }   inline void rdfs(int v) {     cmp[v] = ncmp;     vis[v] = 1;     for (int i = 0; i < (int)radj[v].size(); i++)       if (!vis[radj[v][i]]) rdfs(radj[v][i]);   }   int main() {     scanf( %d%d , &n, &m);     int u, v, c;     for (int i = 1; i <= m; i++) {       scanf( %d%d%d , &u, &v, &c);       if (!c) {         addedge(u, v);         addedge(v, u);       } else {         addedge(u, (v > n ? v - n : v + n));         addedge((v > n ? v - n : v + n), u);       }     }     memset(vis, 0, sizeof vis);     for (int i = 1; i <= 2 * n; i++)       if (!vis[i]) dfs(i);     memset(vis, 0, sizeof vis);     for (; nord--;) {       u = ord[nord];       if (!vis[u]) {         ncmp++;         rdfs(u);       }     }     for (int i = 1; i <= n; i++) {       if (cmp[i] == cmp[i + n]) {         printf( Impossible n );         return 0;       }       if (cmp[i + n] < cmp[i]) ans.push_back(i);       ;     }     printf( %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++) printf( %d  , ans[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long t, n;   int main() {     cin >> t;     vector<int> a;     for (int i = 1; i <= 10000; i++) {       n = i;       vector<int> v;       while (n > 0) {         v.push_back(n % 10);         n = n / 10;       }       reverse(v.begin(), v.end());       for (int j = 0; j < v.size(); j++) {         a.push_back(v[j]);       }     }     for (int i = 0; i < a.size(); i++) {       if (i + 1 == t) {         cout << a[i];         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int i, j = 1, x, k = 0;     int c, y;     int ar[1000];     char str[500];     scanf( %s , str);     for (i = 0; str[i] !=   0 ; i++) {       x = isdigit(str[i]);       if (x != 0) {         ar[j] = str[i];         j++;         k++;       }     }     int pass;     for (pass = 1; pass <= k; pass++) {       for (j = 1; j <= k - 1; j++) {         if (ar[j] > ar[j + 1]) {           c = ar[j];           ar[j] = ar[j + 1];           ar[j + 1] = c;         }       }     }     j = 1;     for (i = 0; str[i] !=   0 ; i++) {       y = isdigit(str[i]);       {         if (y != 0) {           str[i] = ar[j];           j++;         }       }     }     printf( %s , str);   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 2000000000000000000LL;   const int inf = 0x3f3f3f3f;   const long double EPS = 1e-9;   int dirx[] = {0, 0, -1, 1};   int diry[] = {-1, 1, 0, 0};   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int test;     cin >> test;     while (test--) {       int len;       string path;       cin >> len >> path;       std::map<pair<long long, long long>, int> visit;       long long mn = INF;       pair<long long, long long> mnpath{-1, -1}, pos{0, 0};       visit[{0, 0}] = 0;       for (int i = 0; i < len; i++) {         if (path[i] ==  L )           pos.first += dirx[0], pos.second += diry[0];         else if (path[i] ==  R )           pos.first += dirx[1], pos.second += diry[1];         else if (path[i] ==  U )           pos.first += dirx[2], pos.second += diry[2];         else if (path[i] ==  D )           pos.first += dirx[3], pos.second += diry[3];         if (visit.find(pos) != visit.end()) {           int dis = i - visit[pos] + 1;           if (mn >= dis) {             mn = dis;             mnpath = {visit[pos] + 1, i + 1};           }         }         visit[pos] = i + 1;       }       if (mn != INF)         cout << mnpath.first <<     << mnpath.second << endl;       else         cout << -1 << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   char s[maxn], t[maxn];   int p[maxn], q[maxn], r[maxn];   int main() {     int n, m, k, d;     scanf( %s%d , s, &m);     n = strlen(s);     while (m--) {       scanf( %d%d , &k, &d);       for (int i = 0; i < n; i++) p[i] = q[i] = i;       int id = 0;       for (int i = 0; i < d; i++) {         for (int j = i; j < k; j += d) p[id++] = j;       }       int last = p[0];       for (int i = 0; i < n - 1; i++) p[i] = p[i + 1];       p[n - 1] = last;       int pw = n - k + 1;       while (pw > 0) {         if (pw & 1) {           for (int i = 0; i < n; i++) r[i] = q[p[i]];           for (int i = 0; i < n; i++) q[i] = r[i];         }         for (int i = 0; i < n; i++) r[i] = p[p[i]];         for (int i = 0; i < n; i++) p[i] = r[i];         pw >>= 1;       }       for (int i = 0; i < n; i++) t[i] = s[q[(k + i - 1) % n]];       for (int i = 0; i < n; i++) s[i] = t[i];       puts(s);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int b[n];       int ans[2 * n];       for (long long i = 0; i < n; i++) cin >> b[i];       set<int> a;       for (long long i = 0; i < 2 * n; i++) a.insert(i + 1);       for (long long i = 0; i < n; i++) {         ans[2 * i] = b[i];         a.erase(b[i]);       }       bool poss = true;       for (long long i = 0; i < n; i++) {         set<int>::iterator up = upper_bound(a.begin(), a.end(), b[i]);         if (up != a.end()) {           ans[2 * i + 1] = *up;           a.erase(up);         } else {           cout << -1 <<   n ;           poss = false;           break;         }       }       if (poss) {         for (long long i = 0; i < 2 * n - 1; i++) cout << ans[i] <<    ;         cout << ans[2 * n - 1] <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   const int max_length = 1e6;   int a_cnt[max_length];   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     long long b = 0;     long long ans = 0;     int n = s.size();     for (int i = s.size() - 1; i >= 0; i--) {       if (s[i] ==  a  && b != 0) {         ans += b;         ans %= mod;         b = b * 2;         b %= mod;       } else if (s[i] ==  b )         b++;     }     cout << ans % mod;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int no_of_cards;     scanf( %d , &no_of_cards);     vector<int> card(no_of_cards);     for (int i = 0; i < no_of_cards; i++) scanf( %d , &card[i]);     if (no_of_cards == 1) {       printf( -1 n );       return 0;     }     vector<int> new_cards;     if (no_of_cards == 2 && (card[0] != card[1]) &&         (card[0] + card[1]) % 2 == 0) {       new_cards.push_back((card[0] + card[1]) / 2);     }     sort((card).begin(), (card).end());     int min_difference = card[1] - card[0];     for (int i = 2; i < no_of_cards; i++)       min_difference = min(min_difference, card[i] - card[i - 1]);     int ap_possible = true, new_middle_cards = 0;     for (int i = 1; i < no_of_cards; i++) {       if (card[i] - card[i - 1] != min_difference) {         if (card[i] - card[i - 1] == 2 * min_difference) {           new_middle_cards++;         } else {           ap_possible = false;         }       }     }     if (ap_possible) {       if (min_difference == 0) {         new_cards.push_back(card[0]);       } else if (new_middle_cards == 0) {         new_cards.push_back(card[0] - min_difference);         new_cards.push_back(card[no_of_cards - 1] + min_difference);       } else if (new_middle_cards == 1) {         for (int i = 1; i < no_of_cards; i++)           if (card[i] - card[i - 1] == 2 * min_difference)             new_cards.push_back(card[i - 1] + min_difference);       }     }     sort((new_cards).begin(), (new_cards).end());     printf( %d n , new_cards.size());     for (int i = 0; i < new_cards.size(); i++) printf( %d  , new_cards[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int dmap[45][45];   int ans[45];   int dans[45];   int nans, zans;   void dfs(int dn) {     if (dn == n + 1) {       if (nans > zans) {         zans = nans;       }       return;     }     int mark = 0;     for (int i = 1; i < dn; i++)       if (ans[i] == 1 && dmap[i][dn] == 0) mark = 1;     if (mark == 0) {       ans[dn] = 1;       nans++;       dfs(dn + 1);       nans--;     }     if (nans + n - dn > zans) {       ans[dn] = 0;       dfs(dn + 1);     }     return;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %d , &dmap[i][j]);     nans = 0;     zans = 0;     dfs(1);     double zzans = zans;     printf( %lf n , (zzans - 1) / zzans / 2 * m * m);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int x;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> x;     if (x == 3) {       cout << 5 << endl;       return 0;     }     for (int i = 1; i <= 199; i += 2) {       int temp = i * i + 1;       temp /= 2;       if (temp >= x) {         cout << i << endl;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool able[105], prime[105], left[105], flag = 0;   int least = 1;   string tp;   bool isPrime(int i) {     int to = int(sqrt(double(i) + 1.0));     if (i == 1 || i == 2 || i == 5) return 1;     for (int j = 2; j <= to; j++)       if (i % j == 0) return 0;     return 1;   }   int main() {     for (int i = 1; i <= 100; i++)       if (isPrime(i)) prime[i] = 1;     for (int i = 2; i <= 50; i++) {       if (prime[i] == 0) continue;       cout << i << endl;       cin >> tp;       if (tp[0] ==  y ) {         if (flag == 1) {           cout <<  composite  << endl;           fflush(stdout);           return 0;         }         if (i >= 11) {           cout <<  prime  << endl;           fflush(stdout);           return 0;         }         flag = 1;         cout << i * i << endl;         cin >> tp;         if (tp[0] ==  y ) {           cout <<  composite  << endl;           fflush(stdout);           return 0;         }       }     }     cout <<  prime  << endl;     fflush(stdout);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void err(istream_iterator<string> it) {}   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   n ;     err(++it, args...);   }   long long powMod(long long x, long long y) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % ((long long)1e9 + 7);       }       y /= 2;       x = (x * x) % ((long long)1e9 + 7);     }     return p;   }   long long CpowMod(long long x, long long y, long long w) {     long long p = 1;     while (y) {       if (y % 2) {         p = (p * x) % w;       }       y /= 2;       x = (x * x) % w;     }     return p;   }   long long invMod(long long x) { return powMod(x, ((long long)1e9 + 7) - 2); }   long long CinvMod(long long x, long long w) { return CpowMod(x, w - 2, w); }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   void solve() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       vector<long long> a(n, 0);       string s;       cin >> s;       map<long long, set<long long> > m;       map<long long, vector<long long> > v;       long long num = 1;       for (int i = 0; i <= n - 1; i++) {         long long x = s[i] -  0 ;         long long y = 1 - x;         if ((long long)m[y].size()) {           long long in = *m[y].rbegin();           m[y].erase(in);           m[x].insert(in);           v[in].push_back(i);         } else {           m[x].insert(num);           v[num].push_back(i);           num++;         }       }       for (auto &it : v) {         for (auto &is : it.second) {           a[is] = it.first;         }       }       cout << num - 1 <<   n ;       for (auto &it : a) {         cout << it <<    ;       }       cout <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cout.precision(20);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:102400000,102400000 )   long long cntx, cnty;   int vx[(1000000 + 10)], vy[(1000000 + 10)];   int main() {     int n, m;     scanf( %d%d , &n, &m);     long long ans = (long long)n * n;     cntx = n, cnty = n;     for (int i = 0; i < m; ++i) {       int x, y;       scanf( %d%d , &x, &y);       int e = 0;       if (!vx[x]) {         vx[x] = 1;         ans -= cnty;         cntx--;         e++;       }       if (!vy[y]) {         vy[y] = 1;         ans -= cntx;         cnty--;         e++;       }       cout << ans <<    ;     }     cout << endl;   }