malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5, inf = 1e9 + 7;   long long n, k, cumm[N], m[26];   set<pair<long long, long long> > st;   string s;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long i, j, a, b, ans = 1;     cin >> n >> k >> s;     s =  #  + s;     for (i = 0; i < k; i++) st.insert(pair<long long, long long>(m[i], i));     for (i = 1; i < n + s.size(); i++) {       if (i < s.size())         a = s[i] -  a ;       else         a = st.begin()->second;       st.erase(st.find(pair<long long, long long>(m[a], a)));       if (m[a])         cumm[i] = cumm[i - 1] - cumm[m[a] - 1];       else         cumm[i] = cumm[i - 1] + 1;       m[a] = i;       st.insert(pair<long long, long long>(m[a], a));       cumm[i] = (cumm[i] % inf + cumm[i - 1] + inf) % inf;     }     cout << (cumm[i - 1] + 1) % inf;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3007;   const int M = 998244353;   int n, m, dp[N][N];   string s, t;   bool matches(int i, char c) {     if (i > m)       return true;     else       return t[i - 1] == c;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> s >> t;     n = s.size();     m = t.size();     for (int i = 1; i <= n + 1; i++) dp[i][i - 1] = 1;     for (int d = 1; d <= n; d++) {       char c = s[d - 1];       for (int i = 1, j = d; j <= n; i++, j++) {         if (matches(i, c)) {           dp[i][j] = (dp[i][j] + dp[i + 1][j]) % M;         }         if (matches(j, c)) {           dp[i][j] = (dp[i][j] + dp[i][j - 1]) % M;         }       }     }     int ans = 0;     for (int i = m; i <= n; i++) {       ans = (ans + dp[1][i]) % M;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   char ans[100];   int n;   int main() {     scanf( %s%d , ans, &n);     for (int i = 0; i < strlen(ans); i++) {       if (ans[i] <  a ) ans[i] +=  a  -  A ;       if (ans[i] < 97 + n) ans[i] +=  A  -  a ;     }     printf( %s n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       int a[3];       cin >> a[0] >> a[1] >> a[2];       sort(a, a + 3);       if (a[0] + a[1] >= a[2] - 1) {         cout <<  Yes n ;       } else         cout <<  No n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void sf(T &res) {     int f = 1;     char c;     res = 0;     while (c = getchar(), !isdigit(c))       ;     if (c ==  - ) f = -1, c = getchar();     do res = (res << 1) + (res << 3) + (c ^ 48);     while (c = getchar(), isdigit(c));     res *= f;   }   long long h, q, L, R, pos, ANS;   struct node {     long long l, r;     bool operator<(const node &a) const {       if (l != a.l) return l < a.l;       return r < a.r;     }   };   vector<node> v;   int main() {     sf(h), sf(q);     L = 1ll << (h - 1);     R = (1ll << h) - 1;     while (q--) {       long long l, r;       int f, ans;       sf(f), sf(l), sf(r), sf(ans);       for (int j = f; j < h; j++) l *= 2, r = r * 2 + 1;       if (ans) {         if (L <= l - 1) v.push_back((node){L, l - 1});         if (r + 1 <= R) v.push_back((node){r + 1, R});       } else         v.push_back((node){l, r});     }     pos = L, ANS = -1;     v.push_back((node){R + 1, R + 1});     sort(v.begin(), v.end());     for (int i = 0; i < v.size(); i++) {       long long x = v[i].l, y = v[i].r;       if (x > pos) {         if (x - pos == 1) {           if (ANS == -1)             ANS = pos;           else {             puts( Data not sufficient! );             return 0;           }         } else {           puts( Data not sufficient! );           return 0;         }       }       pos = max(pos, y + 1);     }     if (ANS == -1)       puts( Game cheated! );     else       cout << ANS << endl;     return 0;   }
#include <bits/stdc++.h>   char buf[1 << 21], *p1 = buf, *p2 = buf;   using namespace std;   template <class T>   void rd(T &k) {     char c =         (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)              ? EOF              : *p1++);     int f = 1;     k = 0;     while (c <  0  || c >  9 ) {       if (c ==  - ) f *= -1;       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     while (c >=  0  && c <=  9 ) {       k = k * 10 + c -  0 ;       c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)                ? EOF                : *p1++);     }     k *= f;   }   const int N = 300005;   int n, m, k, t, x, a[N], f[N];   int c[N], d[N];   long long ans;   char p[N];   queue<int> q;   int ok(int x) {     if (a[x] > 0 && c[x - 1] + 1 <= 9 && c[x] + 1 <= 9) return 1;     if (a[x] < 0 && c[x - 1] - 1 >= 0 && c[x] - 1 >= 0) return 1;     return 0;   }   int main() {     cin >> n;     cin >> p + 1;     for (int i = 1; i <= n; ++i) c[i] = p[i] - 48;     cin >> p + 1;     for (int i = 1; i <= n; ++i) d[i] = p[i] - 48;     for (register int i = 1; i < n; ++i) {       a[i + 1] = d[i] - (c[i] + a[i]);       ans += abs(a[i + 1]);     }     if (c[n] + a[n] != d[n]) return cout << -1, 0;     cout << ans <<   n ;     int xx = min(ans, 100000ll);     for (register int i = 2; i <= n; ++i) {       if (a[i] > 0 && c[i - 1] + 1 <= 9 && c[i] + 1 <= 9) q.push(i), f[i] = 1;       if (a[i] < 0 && c[i - 1] - 1 >= 0 && c[i] - 1 >= 0) q.push(i), f[i] = 1;     }     int x;     while (xx--) {       x = q.front();       q.pop();       while (f[x] == 0) {         x = q.front();         q.pop();       }       if (a[x] > 0) {         cout << x - 1 <<   1 n ;         ++c[x - 1];         ++c[x];         --a[x];       } else {         cout << x - 1 <<   -1 n ;         --c[x - 1];         --c[x];         ++a[x];       }       if (ok(x))         q.push(x);       else         f[x] = 0;       if (x >= 3) {         if (ok(x - 1)) {           if (f[x - 1] == 0) q.push(x - 1);           f[x - 1] = 1;         } else           f[x - 1] = 0;       }       if (x <= n - 1) {         if (ok(x + 1)) {           if (f[x + 1] == 0) q.push(x + 1);           f[x + 1] = 1;         } else           f[x + 1] = 0;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool gmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool gmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   const long long N = 110;   const long long K = 100010;   const long long INF = 1e12;   long long a[N], b[N], dp[N][2 * K];   long long n, k;   long long Rec(long long idx, long long sum) {     if (idx == n) {       return sum ? -INF : 0;     }     long long& ans = dp[idx][sum + K];     if (ans + 1) return ans;     ans = -INF;     gmax(ans, Rec(idx + 1, sum));     gmax(ans, a[idx] + Rec(idx + 1, sum + a[idx] - b[idx]));     return ans;   }   void solve() {     cin >> n >> k;     for (long long i = 0; i < (n); i++) cin >> a[i];     for (long long i = 0; i < (n); i++) cin >> b[i];     for (long long i = 0; i < (n); i++) b[i] *= k;     memset(dp, (long long)(-1), sizeof(dp));     long long Ans = Rec(0, 0);     cout << (Ans <= 0 ? -1 : Ans) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   bool check(string a) {     bool flag = true;     for (int i = 1; i <= a.size(); i++)       if (abs(a[i] - a[i - 1]) == 1) flag = false;     return flag;   }   int main() {     int T;     cin >> T;     while (T--) {       string s, one, two;       cin >> s;       for (int i = 0; i < s.size(); i++)         if (s[i] % 2)           one += s[i];         else           two += s[i];       sort(one.begin(), one.end());       sort(two.begin(), two.end());       if (check(one + two))         cout << one + two <<   n ;       else if (check(two + one))         cout << two + one <<   n ;       else         cout <<  No answer n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, k, x;   string s;   int main() {     cin >> s;     n = s.size();     for (int k = 0;; k++) {       if (s[k] ==  . ) {         t = k;         break;       }     }     if (s[t - 1] == 9 +  0 )       cout <<  GOTO Vasilisa. ;     else if (s[t + 1] < 5 +  0 ) {       for (int i = 0; i < t; i++) cout << s[i];     } else if (s[t + 1] >= 5 +  0 ) {       for (int i = 0; i < t - 1; i++) cout << s[i];       cout << s[t - 1] -  0  + 1;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int adj[8][2] = {{-1, 0},  {0, -1}, {1, 0}, {0, 1},                          {-1, -1}, {-1, 1}, {1, 1}, {1, -1}};   const long long int LLINF = 9e18;   const int INF = 2e9;   const int MOD = 1e9 + 7;   const double EPS = 1e-10;   const double PI = acos(-1);   const int SIZE = 200005;   int N;   long long int A[SIZE];   int cnt[SIZE], pos[SIZE];   vector<pair<int, pair<int, int> > > ans;   int main() {     scanf( %d , &N);     for (int i = 1; i <= N; i++) {       scanf( %lld , &A[i]);       cnt[A[i]]++;       pos[A[i]] = i;     }     int num, Mx = 0, idx;     for (int i = 0; i < SIZE; i++) {       if (Mx < cnt[i]) {         num = i;         Mx = cnt[i];         idx = pos[i];       }     }     for (int i = idx; i <= N; i++) {       if (num < A[i]) {         ans.push_back(make_pair(2, make_pair(i, i - 1)));       } else if (num > A[i]) {         ans.push_back(make_pair(1, make_pair(i, i - 1)));       }     }     for (int i = idx; i >= 1; i--) {       if (num < A[i]) {         ans.push_back(make_pair(2, make_pair(i, i + 1)));       } else if (num > A[i]) {         ans.push_back(make_pair(1, make_pair(i, i + 1)));       }     }     int n = ans.size();     printf( %d n , n);     for (int i = 0; i < n; i++) {       printf( %d %d %d n , ans[i].first, ans[i].second.first,              ans[i].second.second);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, a, b, da, db;   vector<long long> v[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n >> a >> b >> da >> db;       for (long long i = 0; i < n + 2; i++) v[i].clear();       for (long long i = 0; i < n - 1; i++) {         long long x, y;         cin >> x >> y;         v[x].push_back(y);         v[y].push_back(x);       }       long long vis[n + 1];       memset(vis, 0, sizeof(vis));       vis[a] = 1;       queue<long long> q;       q.push(a);       long long dis[n + 1];       dis[a] = 0;       while (!q.empty()) {         long long u = q.front();         q.pop();         for (auto it : v[u]) {           if (!vis[it]) {             dis[it] = dis[u] + 1;             vis[it] = 1;             q.push(it);           }         }       }       if (db <= 2 * da || dis[b] <= da) {         cout <<  Alice n ;         continue;       }       dis[b] = 0;       memset(vis, 0, sizeof(vis));       vis[b] = 1;       q.push(b);       while (!q.empty()) {         long long u = q.front();         q.pop();         for (auto it : v[u]) {           if (!vis[it]) {             dis[it] = dis[u] + 1;             vis[it] = 1;             q.push(it);           }         }       }       long long node, maxi = 0;       for (long long i = 1; i <= n; i++) {         if (dis[i] > maxi) {           maxi = dis[i];           node = i;         }       }       dis[node] = 0;       memset(vis, 0, sizeof(vis));       vis[node] = 1;       q.push(node);       while (!q.empty()) {         long long u = q.front();         q.pop();         for (auto it : v[u]) {           if (!vis[it]) {             dis[it] = dis[u] + 1;             vis[it] = 1;             q.push(it);           }         }       }       maxi = 0;       for (long long i = 1; i <= n; i++) {         if (dis[i] > maxi) {           maxi = dis[i];         }       }       if (maxi > 2 * da) {         cout <<  Bob n ;       } else         cout <<  Alice n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     long long r;     while (b != 0) {       r = a % b;       a = b;       b = r;     }     return a;   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   int const nmax = 1010;   int k, n;   vector<pair<int, int> > st, pe;   vector<int> ans[nmax];   bool dc[nmax];   long double p[nmax];   void solve() {     memset(dc, 0, sizeof(dc));     cin >> k >> n;     for (int i = 0; i < k; i++) {       int c, t;       cin >> c >> t;       p[i] = c;       if (t == 1)         st.push_back(pair<int, int>(c, i));       else         pe.push_back(pair<int, int>(c, i));     }     sort(st.begin(), st.end());     sort(pe.begin(), pe.end());     int k = 0;     while (!st.empty()) {       if (k >= n) k = n - 1;       dc[k] = 1;       ans[k].push_back(st.back().second);       st.pop_back();       k++;     }     for (int i = n - 1; i >= 0; i--) {       if (int((ans[i]).size()) > 0) break;       ans[i].push_back(pe.front().second);       pe.erase(pe.begin());     }     while (!pe.empty()) {       if (k >= n) k = n - 1;       ans[k].push_back(pe.back().second);       pe.pop_back();       k++;     }     long double sum = 0;     for (int i = 0; i < n; i++) {       long double m = INT_MAX;       for (int j = 0; j < int((ans[i]).size()); j++) {         int k = ans[i][j];         sum += p[k];         m = ((m) > (p[k]) ? (p[k]) : (m));       }       if (dc[i]) sum -= m / 2;     }     cout << fixed << setprecision(1) << sum <<   n ;     for (int i = 0; i < n; i++) {       cout << int((ans[i]).size()) <<    ;       for (int j = 0; j < int((ans[i]).size()); j++) cout << ans[i][j] + 1 <<    ;       cout <<   n ;     }   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 9;   int n, q, c[N];   void modify(int x, int v) {     if (x == 0) return;     for (int i = x; i <= n; i += i & -i) c[i] += v;   }   int query(int x) {     int s = 0;     for (int i = x; i >= 1; i -= i & -i) s += c[i];     return s;   }   void work(int a, int b, bool le) {     for (int i = a; i <= b; ++i) {       int t = query(i) - query(i - 1);       modify(i, -t);       if (le) {         modify(a - (i - a + 1), t);       } else         modify(b + (b - i + 1), t);     }   }   int L, R;   int get(int x) {     if (L <= R)       return x + L - 1;     else       return L + 1 - x;   }   int len() { return abs(L - R) + 1; }   int main() {     scanf( %d%d , &n, &q);     L = 1, R = n;     for (int i = 1; i <= n; ++i) modify(i, 1);     while (q--) {       int cmd, p, l, r;       scanf( %d , &cmd);       if (cmd == 1) {         scanf( %d , &p);         if (L <= R) {           if (p > len() - p) {             work(get(p + 1), R, 1);             R = get(p);             swap(L, R);           } else {             work(get(1), get(p), 0);             L = get(p + 1);           }         } else {           if (p > len() - p) {             work(R, get(p + 1), 0);             R = get(p);             swap(L, R);           } else {             work(get(p), get(1), 1);             L = get(p + 1);           }         }       } else {         scanf( %d%d , &l, &r);         l++;         l = get(l), r = get(r);         if (l > r) swap(l, r);         int s = query(r) - query(l - 1);         printf( %d n , s);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     string aux =  CODEFORCES ;     int i = 0;     cin >> s;     if (s.length() < aux.length())       cout <<  NO  << endl;     else {       while (aux[i] == s[i] && i < aux.length()) i++;       if (i == aux.length())         cout <<  YES  << endl;       else {         int j;         for (j = i; j < aux.length(); j++) {           if (aux[j] != s[s.length() - aux.length() + j]) break;         }         if (j == aux.length())           cout <<  YES  << endl;         else           cout <<  NO  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       int n, k;       cin >> n >> k;       if (n < k)         cout << k - n << endl;       else {         if ((n & 1) == (k & 1))           cout << 0 << endl;         else           cout << 1 << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   int n, m;   int a[maxn], b[maxn];   int main() {     cin >> n >> m;     m--;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     if (a[0] == 0) {       cout <<  NO ;       return 0;     }     if (b[m] == 0 && a[m] == 0) {       cout <<  NO ;       return 0;     }     if (a[m] != 0) {       cout <<  YES ;       return 0;     }     for (int i = m; i < n; i++) {       if (b[i] == 1 && a[i] == 1) {         cout <<  YES ;         return 0;       }     }     cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   const int dir[8][2] = {{0, 1},  {1, 1},   {1, 0},  {1, -1},                          {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};   const int dir8x[8] = {-1, -1, -1, 0, 0, 1, 1, 1};   const int dir8y[8] = {-1, 0, 1, 1, -1, -1, 0, 1};   const long long mod = 1e9 + 7;   const double PI = acos(-1.0);   long long po(long long a, long long b, long long mod) {     long long res = 1;     a %= mod;     for (; b; b >>= 1) {       if (b & 1) res = res * a % mod;       a = a * a % mod;     }     return res;   }   long long gcd(long long a, long long b) {     if (a == 0) {       return b;     } else {       return gcd(b % a, a);     }   }   int n;   long long val[maxn], dp[maxn];   void solve() {     scanf( %d , &(n));     for (int i = 1; i <= n; i++) {       scanf( %lld , &val[i]);     }     int last = 1;     for (int i = 2; i <= n; i++) {       dp[i] = max(dp[last - 1] + labs(val[i] - val[last]),                   dp[last] + labs(val[i] - val[last + 1]));       if (val[i] <= val[i + 1] && val[i] <= val[i - 1]) {         last = i;       }       if (val[i] >= val[i + 1] && val[i] >= val[i - 1]) {         last = i;       }     }     long long res = dp[n];     printf( %lld , res);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       unsigned long long int mino = LONG_MAX;       unsigned long long int minc = LONG_MAX;       unsigned long long int ans = 0;       unsigned long long int n;       cin >> n;       unsigned long long int o[n], c[n];       for (unsigned long long int i = 0; i < n; i++) {         unsigned long long int ora;         cin >> ora;         o[i] = ora;         if (ora < mino) {           mino = ora;         }       }       for (unsigned long long int i = 0; i < n; i++) {         unsigned long long int ca;         cin >> ca;         c[i] = ca;         if (ca < minc) {           minc = ca;         }       }       for (unsigned long long int i = 0; i < n; i++) {         unsigned long long int w = min(o[i] - mino, c[i] - minc);         ans = ans + w;         o[i] = o[i] - w;         c[i] = c[i] - w;         if (o[i] == mino) {           ans = ans + c[i] - minc;         } else {           ans = ans + o[i] - mino;         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> split(string s) {     vector<int> xs;     stringstream ss(s);     string item;     while (getline(ss, item,  , )) {       xs.push_back(stoi(item));     }     return xs;   }   int main() {     string s;     getline(cin, s);     vector<int> xxs = split(s);     sort(xxs.begin(), xxs.end());     vector<pair<int, int>> sol;     for (int i = 0; i < xxs.size(); i++) {       int st = xxs[i];       int e = st;       while (i < xxs.size() - 1 && (e + 1 == xxs[i + 1] || e == xxs[i + 1])) {         e = xxs[i + 1];         i++;       }       sol.push_back(make_pair(st, e));     }     for (int i = 0; i < sol.size(); i++) {       if (sol[i].first != sol[i].second) {         cout << sol[i].first <<  -  << sol[i].second;       } else {         cout << sol[i].first;       }       if (i != sol.size() - 1) {         cout <<  , ;       }     }     return 0;   }
#include <bits/stdc++.h>   const int kMaxN = 5000;   std::vector<int> way[kMaxN], cost[kMaxN];   int f[kMaxN], c[kMaxN];   short hash[kMaxN][kMaxN], father[kMaxN][2 * kMaxN];   int a[kMaxN], id[kMaxN], t[kMaxN];   inline bool cmp(int x, int y) { return a[x] < a[y]; }   void BuildTree(int u, int ff) {     f[u] = ff;     for (size_t i = 0; i < way[u].size(); ++i) {       int v = way[u][i];       if (v == ff) continue;       c[v] = cost[u][i];       BuildTree(v, u);     }   }   int Find(short *f, int x) {     int y = x, z;     while (f[y] != -1) y = f[y];     while (x != y) {       z = x;       x = f[x];       f[z] = y;     }     return y;   }   int Put(int x) {     int t = 0;     while (x != 0) {       ++t;       if (f[x] == 0) return t;       int ff = f[x];       t = Find(father[ff], t);       if (++hash[ff][t] == c[ff]) {         father[ff][t] = t + 1;       }       x = ff;     }     return 0;   }   int main() {     int n, x, y, cc;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       scanf( %d , a + i);       id[i] = i;     }     std::sort(id, id + n, cmp);     for (int j = 1; j < n; ++j) {       scanf( %d%d%d , &x, &y, &cc);       --x;       --y;       way[x].push_back(y);       way[y].push_back(x);       cost[x].push_back(cc);       cost[y].push_back(cc);     }     BuildTree(0, -1);     memset(father, -1, sizeof(father));     for (int i = 0; i < n; ++i) {       t[id[i]] = Put(id[i]);     }     for (int i = 0; i < n; ++i) {       if (i != 0) printf(   );       printf( %d , t[i]);     }     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isthere(string s1, string s2);   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       string s1, s2;       cin >> s1 >> s2;       if (s2.size() == s1.size()) {         if (isthere(s1, s2)) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }         continue;       }       if (s2.size() < s1.size()) {         cout <<  NO  << endl;         continue;       }       bool y = 0;       for (int i = 0; i <= (s2.size() - s1.size()); i++) {         string s = s2.substr(i, s1.size());         if (isthere(s1, s)) {           cout <<  YES  << endl;           y = 1;           break;         }       }       if (y == 0) {         cout <<  NO  << endl;       }     }     return 0;   }   bool isthere(string s1, string s2) {     sort(s1.begin(), s1.end());     sort(s2.begin(), s2.end());     if (s1.compare(s2) == 0) {       return true;     }     return false;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     char lowestChar =  z  + 1;     string s;     cin >> s;     vector<int> ans(s.size(), 0);     for (int i = 0; i < s.size(); ++i) {       char c = s[i];       if (c < lowestChar) {         ans[i] = 1;         lowestChar = c;       } else if (c == lowestChar) {         ans[i - 1] ^= 1;         ans[i] = 1;       }     }     for (auto& x : ans) cout << x <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> bomb[5005];   int n, m, st_time[5005], sol[5005], dist_min[5005];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; ++i) dist_min[i] = 2 * 5005;     int pos, val;     for (int i = 1; i <= m; ++i) {       cin >> pos >> val;       bomb[pos].push_back(val);       int comp = 0;       if (val >= pos)         comp = val - pos;       else         comp = n - (pos - val);       if (val != pos) dist_min[pos] = min(dist_min[pos], comp);     }     for (int i = 1; i <= n; ++i) {       int blen = bomb[i].size();       if (blen)         st_time[i] = n * (blen - 1) + dist_min[i];       else         st_time[i] = 0;     }     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= n; ++j)         if (!bomb[j].empty()) {           if (j < i)             sol[i] = max(sol[i], n - (i - j) + st_time[j]);           else             sol[i] = max(sol[i], j - i + st_time[j]);         }       cout << sol[i] <<    ;     }     return 0;   }