malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, otv = 0, otv1 = 0;     cin >> n;     vector<long long> v(n);     for (long long j = 0; j < n; j++) {       cin >> v[j];     }     for (long long j = 1; j < n; j++) {       if (v[j] != v[0]) {         otv = j;       }     }     for (long long j = 0; j < n - 1; j++) {       if (v[j] != v[n - 1]) {         otv1 = n - 1 - j;         cout << max(otv, otv1);         return 0;       }     }     cout << max(otv, otv1);   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   const double error = 1e-10;   const double PI = acos(-1);   inline long long int MOD(long long int x, long long int m = mod) {     long long int y = x % m;     return (y >= 0) ? y : y + m;   }   const int inf = INT_MAX;   const long long int infl = LLONG_MAX;   const int nmax = 1e5 + 3;   int grundy[nmax], best[nmax];   vector<int> reach[nmax];   void dp() {     for (int i = 1; i < nmax; i++) {       sort(reach[i].begin(), reach[i].end());       int j, k;       for (k = 0, j = 0; k < nmax; k++) {         while (j < reach[i].size()) {           if (reach[i][j] >= k) break;           j++;         }         if (reach[i].size() == j || reach[i][j] > k) break;       }       grundy[i] = k;       reach[i].clear();       int sum = 0, xorval = 0;       for (int j = i; j > 0 && sum < nmax; j--) {         sum += j;         if (sum >= nmax) continue;         xorval ^= grundy[j];         reach[sum].push_back(xorval);         if (xorval == 0) best[sum] = i - j + 1;       }     }   }   int main() {     int n;     scanf( %d , &n);     dp();     if (grundy[n] == 0)       printf( -1 );     else       printf( %d , best[n]);   }
#include <bits/stdc++.h>   using namespace std;   int n, x1, x2;   struct server {     int c, ind;     bool b1, b2;     int r1, r2;   } * *srv;   void qs(server** a, int l, int r) {     int i = l, j = r;     int p = a[(l + r) >> 1]->c;     do {       while (i < r && a[i]->c < p) i++;       while (j > l && a[j]->c > p) j--;       if (i <= j) swap(a[i++], a[j--]);     } while (i <= j);     if (i < r) qs(a, i, r);     if (j > l) qs(a, l, j);   }   int main() {     scanf( %d %d %d , &n, &x1, &x2);     srv = new server*[n];     for (int i = 0; i < n; i++) {       srv[i] = new server;       scanf( %d , &srv[i]->c);       srv[i]->ind = i;     }     qs(srv, 0, n - 1);     for (int i = n - 1; i >= 0; i--) {       srv[i]->r1 = ((long long)x1 + (long long)srv[i]->c - (long long)1) /                    (long long)srv[i]->c;       srv[i]->r2 = ((long long)x2 + (long long)srv[i]->c - (long long)1) /                    (long long)srv[i]->c;       if (i < n - 1 && srv[i + 1]->b1)         srv[i]->b1 = 1;       else if (srv[i]->r1 <= n - i)         srv[i]->b1 = 1;       else         srv[i]->b1 = 0;       if (i < n - 1 && srv[i + 1]->b2)         srv[i]->b2 = 1;       else if (srv[i]->r2 <= n - i)         srv[i]->b2 = 1;       else         srv[i]->b2 = 0;     }     for (int i = 0; i < n - 1; i++) {       if (srv[i]->r1 < n - i && srv[i + srv[i]->r1]->b2) {         for (int j = i + srv[i]->r1; j < n; j++) {           if (srv[j]->r2 <= n - j) {             printf( Yes n );             printf( %d %d n , srv[i]->r1, srv[j]->r2);             for (int k = 0; k < srv[i]->r1; k++)               printf( %d  , srv[i + k]->ind + 1);             printf(  n );             for (int k = 0; k < srv[j]->r2; k++)               printf( %d  , srv[j + k]->ind + 1);             printf(  n );             return 0;           }         }       }     }     for (int i = 0; i < n - 1; i++) {       if (srv[i]->r2 < n - i && srv[i + srv[i]->r2]->b1) {         for (int j = i + srv[i]->r2; j < n; j++) {           if (srv[j]->r1 <= n - j) {             printf( Yes n );             printf( %d %d n , srv[j]->r1, srv[i]->r2);             for (int k = 0; k < srv[j]->r1; k++)               printf( %d  , srv[j + k]->ind + 1);             printf(  n );             for (int k = 0; k < srv[i]->r2; k++)               printf( %d  , srv[i + k]->ind + 1);             printf(  n );             return 0;           }         }       }     }     printf( No n );     return 0;   }
#include<bits/stdc++.h>   using namespace std;      #define imax(a,b) (((a)>(b))?(a):(b))   #define imin(a,b) (((a)<(b))?(a):(b))   #define mp make_pair      typedef long long ll;      const int N = 3e5 + 10;      typedef pair<int, int> intp;   int T, n, dfstime, L[N], R[N], ans, num;   vector<int> sd[2][N];   set<intp> np;      void read(int& x)   {    x = 0; char ch = getchar(); bool f = 0;    while (!(ch >=  0  && ch <=  9 )) f |= (ch ==  - ), ch = getchar();    while ((ch >=  0  && ch <=  9 )) x = (x << 3) + (x << 1) + ch -  0 , ch = getchar();    if (f) x = -x;   }      void kdfs(int x)   {    L[x] = ++dfstime;    for (vector<int>::iterator iter = sd[1][x].begin();iter != sd[1][x].end();++iter)     kdfs(*iter);    R[x] = dfstime;   }      int nofa(int fa, int son){return (L[fa] <= L[son] && R[son] <= R[fa]) ? 0 : 1;}      void sdfs(int x)   {    int mark = num;    set<intp>::iterator now = np.lower_bound({ L[x],0 });    if (now != np.end()) num += nofa(x, now->second);    if (now != np.begin())    {     set<intp>::iterator fnow = now--;     num += nofa(now->second, x);     if (fnow != np.end()) num -= nofa(now->second, fnow->second);    }    np.insert({ L[x],x });    ans = imax(ans, num);    for (vector<int>::iterator iter = sd[0][x].begin();iter != sd[0][x].end();++iter)     sdfs(*iter);    np.erase({ L[x],x });    num = mark;   }      int main()   {    read(T);    while (T--)    {     read(n);     for (int h = 0;h < 2;++h)     for (int i = 2;i <= n;++i)     {      int a; read(a);      sd[h][a].push_back(i);     }     dfstime = 0; kdfs(1);     ans = 1; num = 1; sdfs(1);     for (int i = 1;i <= n;++i) sd[0][i].clear(), sd[1][i].clear();     printf( %d n , ans);    }    return 0;   }
#include <bits/stdc++.h>   bool vis[1001][1001], ret[1001][1001];   const int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};   const int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf(  n );       for (int j = 1; j <= m; ++j) {         char ch = getchar();         if (ch ==  # ) vis[i][j] = 1;       }     }     for (int i = 2; i < n; ++i)       for (int j = 2; j < m; ++j) {         bool ok = true;         for (int k = 0; k < 8; ++k)           if (!vis[i + dx[k]][j + dy[k]]) {             ok = false;             break;           }         if (ok)           for (int k = 0; k < 8; ++k) ret[i + dx[k]][j + dy[k]] = true;       }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (vis[i][j] != ret[i][j]) return printf( NO ), 0;     printf( YES );   }
#include <bits/stdc++.h>   using namespace std;   const int N = 255;   double f[N][N * N];   int x, k, p;   int main() {     scanf( %d%d%d , &x, &k, &p);     for (int i = 0; i <= k; i++) {       int xx = x + i, cnt = 0;       while (xx % 2 == 0) {         xx /= 2;         cnt++;       }       f[0][i] = cnt;     }     for (int i = 1; i <= k; i++) {       for (int j = 0; j <= k; j++) {         f[i][j << 1] += (f[i - 1][j] + 1) * p / 100.0;         f[i][j] += f[i - 1][j + 1] * (100 - p) / 100.0;       }     }     printf( %.10lf n , f[k][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   template <typename T1, typename T2>   inline void chkmin(T1 &x, const T2 &y) {     if (x > y) x = y;   }   template <typename T1, typename T2>   inline void chkmax(T1 &x, const T2 &y) {     if (x < y) x = y;   }   const int INF = 1e9 + 228 + 1337;   bool check(string s, string t) {     sort(s.begin(), s.end());     sort(t.begin(), t.end());     return s == t;   }   void solve() {     int n;     vector<string> a(2);     cin >> n >> a[0] >> a[1];     if (!check(a[0], a[1])) {       cout << -1 <<   n ;       return;     }     vector<vector<int>> dp(n + 1, vector<int>(n + 1, INF));     dp[0][0] = 0;     vector<vector<vector<int>>> cnt(         2, vector<vector<int>>(n + 1, vector<int>(26, 0)));     reverse(a[0].begin(), a[0].end());     reverse(a[1].begin(), a[1].end());     for (int it = 0; it < 2; it++) {       for (int i = 1; i <= n; i++) {         for (int alpha = 0; alpha < 26; alpha++) {           cnt[it][i][alpha] = cnt[it][i - 1][alpha];         }         cnt[it][i][a[it][i - 1] -  a ]++;       }     }     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= i; j++) {         if (i + 1 <= n && a[0][i] == a[1][j]) {           assert(j + 1 <= n);           chkmin(dp[i + 1][j + 1], dp[i][j]);         }         char x = a[1][j] -  a ;         if (j + 1 <= n && cnt[0][i][x] > cnt[1][j][x]) {           chkmin(dp[i][j + 1], dp[i][j]);         }         if (i + 1 <= n) {           chkmin(dp[i + 1][j], dp[i][j] + 1);         }       }     }     int ans = -1;     if (dp[n][n] != INF) {       ans = dp[n][n];     }     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const int maxn = 5000;   int n, fir[maxn + 10], tmpN;   int nedge, to[2 * maxn + 10], nex[2 * maxn + 10], dis[2 * maxn + 10];   bool no[2 * maxn + 10];   long long ans, dp[maxn + 10], num[maxn + 10], allDis[maxn + 10];   int p[2];   inline void add_edge(int x, int y, int w) {     to[nedge] = y;     dis[nedge] = w;     nex[nedge] = fir[x];     fir[x] = nedge++;   }   void dfs(int x, int fa) {     num[x] = 0;     dp[x] = 0;     for (int i = fir[x]; ~i; i = nex[i]) {       int y = to[i];       if (y == fa) continue;       int w = dis[i];       dfs(y, x);       num[x] += num[y];       dp[x] += dp[y] + (long long)num[y] * w;     }     num[x]++;   }   void update(int x, int k) {     if (p[k] < 0 || allDis[x] < allDis[p[k]]) p[k] = x;   }   void dfs2(int x, int fa, int k) {     for (int i = fir[x]; ~i; i = nex[i]) {       int y = to[i];       if (y == fa) continue;       int w = dis[i];       allDis[y] =           allDis[x] - (long long)w * num[y] + (long long)(tmpN - num[y]) * w;       update(y, k);       dfs2(y, x, k);     }   }   void solve() {     ans = -1;     int N[2];     for (int i = 0; i < 2 * (n - 1); i += 2) {       memset(p, -1, sizeof p);       int x = to[i], y = to[i ^ 1], w = dis[i];       dfs(x, y);       tmpN = N[0] = num[x];       allDis[x] = dp[x];       update(x, 0);       dfs2(x, y, 0);       dfs(y, x);       tmpN = N[1] = num[y];       allDis[y] = dp[y];       update(y, 1);       dfs2(y, x, 1);       long long ret =           N[1] * (allDis[p[0]] + (long long)N[0] * w) + N[0] * allDis[p[1]];       long long ret2 = 0;       for (int(j) = 1; (j) <= (n); (j)++) ret2 += allDis[j];       ret2 /= 2;       ret += ret2;       if (ans < 0 || ret < ans) ans = ret;     }     cout << ans << endl;   }   int main() {     std::ios::sync_with_stdio(false);     int x, y, w;     while (cin >> n) {       memset(fir, -1, (n + 1) * sizeof fir[0]);       nedge = 0;       for (int(i) = 0; (i) < (n - 1); (i)++) {         cin >> x >> y >> w;         add_edge(x, y, w);         add_edge(y, x, w);       }       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, cnt = 0;     cin >> n;     int a[n + 1][n + 1];     vector<int> v;     vector<int> v1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cin >> a[i][j];       }     }     int no = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (a[i][j] == 1 || a[i][j] == 3) {           no = 1;         }       }       if (no != 1) {         v.push_back(i + 1);       }       no = 0;     }     if (v.size() == 0) {       cout <<  0  << endl;       return 0;     }     cout << v.size() << endl;     for (int i = 0; i < v.size(); i++) {       cout << v[i] <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, K, b[40004], a[40004];   int Wl, Wl2, w[40004], lg[40004], inv[40004] = {1, 1};   int Pow(int b, int k) {     int r = 1;     for (; k; k >>= 1, b = 1ll * b * b % 998244353)       if (k & 1) r = 1ll * r * b % 998244353;     return r;   }   void init(int n) {     for (Wl = 1; n >= Wl << 1; Wl <<= 1)       ;     int pw = Pow(3, (998244353 - 1) / (Wl2 = Wl << 1));     w[Wl] = 1;     for (int i = (Wl + 1), LIM = (Wl2 - 1); i <= LIM; i++)       w[i] = 1ll * w[i - 1] * pw % 998244353;     for (int i = (Wl - 1), LIM = (1); i >= LIM; i--) w[i] = w[i << 1];     for (int i = (2), LIM = (Wl2); i <= LIM; i++)       inv[i] = 1ll * (998244353 - 998244353 / i) * inv[998244353 % i] % 998244353,       lg[i] = lg[i >> 1] + 1;   }   void NTT(int *A, int n, int tp) {     static int r[40004];     static unsigned long long a[40004];     if (tp ^ 1) reverse(A + 1, A + n);     for (int i = (0), LIM = (n - 1); i <= LIM; i++)       r[i] = r[i >> 1] >> 1 | (i & 1) << (lg[n] - 1),       a[i] = (A[r[i]] += A[r[i]] >> 31 & 998244353);     for (int L = 1; L < n; L <<= 1)       for (int s = 0, L2 = L << 1; s < n; s += L2)         for (int k = s, x = L, t; k < s + L; k++, x++)           t = w[x] * a[k + L] % 998244353, a[k + L] = a[k] - t + 998244353,           a[k] += t;     for (int i = (0), LIM = (n - 1); i <= LIM; i++) A[i] = a[i] % 998244353;     if (tp ^ 1)       for (int i = (0), LIM = (n - 1); i <= LIM; i++)         A[i] = 1ll * A[i] * inv[n] % 998244353;   }   void Mul(int *A, int *B, int *C, int n, int m) {     static int st[2][40004];     int L = 1 << lg[n + m] + 1;     for (int i = (0), LIM = (L - 1); i <= LIM; i++)       st[0][i] = i <= n ? A[i] : 0, st[1][i] = i <= m ? B[i] : 0;     NTT(st[0], L, 1), NTT(st[1], L, 1);     for (int i = (0), LIM = (L - 1); i <= LIM; i++)       C[i] = 1ll * st[0][i] * st[1][i] % 998244353;     NTT(C, L, -1);   }   int *f[40004 << 2];   void Build(int u, int l, int r) {     f[u] = new int[1 << lg[r - l + 1] + 1];     if (l == r) return;     int m = l + r >> 1;     Build(u << 1, l, m), Build(u << 1 | 1, m + 1, r);   }   void Sol(int u, int l, int r) {     memset(f[u], 0, 4 * (1 << lg[r - l + 1] + 1));     if (l == r) return (void)(f[u][0] = 1, f[u][1] = b[l]);     int m = l + r >> 1;     Sol(u << 1, l, m), Sol(u << 1 | 1, m + 1, r);     Mul(f[u << 1], f[u << 1 | 1], f[u], m - l + 1, r - m);   }   int main() {     scanf( %d%d , &n, &K);     for (int i = (1), LIM = (n); i <= LIM; i++) scanf( %d , &a[i]);     init(n);     int Q;     scanf( %d , &Q);     Build(1, 1, n);     for (int op, q, i, d, l, r; Q--;) {       scanf( %d , &op);       memcpy(b, a, sizeof b);       if (op == 1) {         scanf( %d%d%d , &q, &i, &d);         b[i] = d;       } else {         scanf( %d%d%d%d , &q, &l, &r, &d);         for (int j = l; j <= r; j++) b[j] = (b[j] + d) % 998244353;       }       for (int i = (1), LIM = (n); i <= LIM; i++) b[i] = (q - b[i]) % 998244353;       Sol(1, 1, n);       printf( %d n , (f[1][K] + 998244353) % 998244353);     }   }
#include <bits/stdc++.h>   using namespace std;   double d(long long int x, long long int y, long long int x1, long long int y1) {     return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     pair<long long int, long long int> adil;     pair<long long int, long long int> bera;     pair<long long int, long long int> bin;     cin >> adil.first >> adil.second >> bera.first >> bera.second >> bin.first >>         bin.second;     double sum = 0;     long long int n;     cin >> n;     pair<int, int> MinAdil, Min1Adil, MinBera, Min1Bera;     double a, a1, b, b1;     a = a1 = b = b1 = 1e10;     for (int i = 0; i < n; i++) {       long long int x, y;       cin >> x >> y;       double dist = d(x, y, bin.first, bin.second);       sum += dist * 2;       double krati = d(adil.first, adil.second, x, y) - dist;       double t = dist;       dist = krati;       if (dist <= a) {         Min1Adil.first = MinAdil.first;         Min1Adil.second = MinAdil.second;         MinAdil.first = x;         MinAdil.second = y;         a1 = a;         a = dist;       } else {         if (dist < a1) {           Min1Adil.first = x;           Min1Adil.second = y;           a1 = dist;         }       }       dist = d(bera.first, bera.second, x, y) - t;       if (dist <= b) {         Min1Bera.first = MinBera.first;         Min1Bera.second = MinBera.second;         MinBera.first = x;         MinBera.second = y;         b1 = b;         b = dist;       } else {         if (dist < b1) {           Min1Bera.first = x;           Min1Bera.second = y;           b1 = dist;         }       }     }     double ans =         min(sum - d(bin.first, bin.second, MinAdil.first, MinAdil.second) +                 d(MinAdil.first, MinAdil.second, adil.first, adil.second),             sum - d(bin.first, bin.second, MinBera.first, MinBera.second) +                 d(MinBera.first, MinBera.second, bera.first, bera.second));     if (n > 1) {       if (MinAdil.first == MinBera.first && MinAdil.second == MinBera.second) {         ans = min(             ans, sum - d(bin.first, bin.second, MinAdil.first, MinAdil.second) -                      d(bin.first, bin.second, Min1Bera.first, Min1Bera.second) +                      d(MinAdil.first, MinAdil.second, adil.first, adil.second) +                      d(Min1Bera.first, Min1Bera.second, bera.first, bera.second));         ans = min(             ans, sum - d(bin.first, bin.second, Min1Adil.first, Min1Adil.second) -                      d(bin.first, bin.second, MinBera.first, MinBera.second) +                      d(Min1Adil.first, Min1Adil.second, adil.first, adil.second) +                      d(MinBera.first, MinBera.second, bera.first, bera.second));       } else {         ans = min(ans,                   sum - d(bin.first, bin.second, MinAdil.first, MinAdil.second) -                       d(bin.first, bin.second, MinBera.first, MinBera.second) +                       d(MinAdil.first, MinAdil.second, adil.first, adil.second) +                       d(MinBera.first, MinBera.second, bera.first, bera.second));       }     }     cout << setprecision(10) << fixed << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int suma = 0, ans = 0, count = 0;     for (int i = n - 1; i >= 0; i--) {       if (suma + arr[i] <= k)         suma = suma + arr[i];       else {         suma = arr[i];         count += 1;       }       if (count >= m) break;       ans += 1;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void rd(T &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) x = x * 10 -  0  + c, c = getchar();     x *= f;   }   template <class T>   inline void cmax(T &x, T y) {     if (x < y) x = y;   }   const int N = (1 << 18) + 10;   int f[N][2][2];   int vis[N];   void solve(int l, int r, int c) {     if (l + 1 == r) {       int x = vis[l], y = vis[r];       cmax(f[c][x][y], x | y);       cmax(f[c][y][x], x | y);       return;     }     int mid = l + r >> 1;     solve(l, mid, c << 1), solve(mid + 1, r, c << 1 | 1);     for (int lx = 0; lx < 2; ++lx)       for (int ly = 0; ly < 2; ++ly)         if (f[c << 1][lx][ly] >= 0)           for (int rx = 0; rx < 2; ++rx)             for (int ry = 0; ry < 2; ++ry)               if (f[c << 1 | 1][rx][ry] >= 0) {                 for (int S = 0; S < 8; ++S) {                   int a = (S & 1 ? lx : rx);                   int b = (S & 2 ? ly : ry);                   int d = (S & 4 ? (lx ^ rx ^ a) : b);                   cmax(f[c][a][d], f[c << 1][lx][ly] + f[c << 1 | 1][rx][ry] +                                        (lx | rx) + (ly | ry) +                                        ((lx ^ rx ^ a) | b));                 }               }   }   int main() {     int n, k;     rd(n), rd(k);     for (int i = 1, x; i <= k; ++i) rd(x), vis[x - 1] = 1;     memset(f, -0x3f, sizeof(f));     solve(0, (1 << n) - 1, 1);     int ans = -0x3f3f3f3f;     for (int x = 0; x < 2; ++x)       for (int y = 0; y < 2; ++y) cmax(ans, f[1][x][y] + (x | y));     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int BUF = 200005;   const long long INF = 1LL << 61;   int n;   long long toAdd;   long long arrive[BUF];   int maxOrder[BUF];   void read() {     cin >> n >> toAdd;     for (int i = 0; i < n; ++i) {       cin >> arrive[i];     }     for (int i = 0; i < n; ++i) {       cin >> maxOrder[i];     }   }   void work() {     for (int i = 0; i + 1 < n; ++i) {       if (maxOrder[i] != maxOrder[i + 1] &&           (maxOrder[i] != i + 1 || maxOrder[i] > maxOrder[i + 1])) {         cout <<  No  << endl;         return;       }     }     if (maxOrder[n - 1] != n) {       cout <<  No  << endl;       return;     }     vector<long long> ans;     for (int idx = 0; idx < n;) {       int nexIdx = idx;       while (nexIdx < n && maxOrder[nexIdx] == maxOrder[idx]) {         ++nexIdx;       }       long long start =           nexIdx < n ? arrive[nexIdx] + toAdd - (nexIdx - idx) : INF;       for (int i = 0; i < nexIdx - idx; ++i) {         if (i == 0 && start + nexIdx - idx - 1 < arrive[idx] + toAdd) {           cout <<  No  << endl;           return;         } else if (i > 0 && start + i < arrive[idx + i] + toAdd + 1) {           cout <<  No  << endl;           return;         }         ans.push_back(start + i);       }       idx = nexIdx;     }     for (int i = 0; i < n; ++i) {       if (i + 1 < n && maxOrder[i] != maxOrder[i + 1] &&           arrive[i + 1] + toAdd <= ans[i]) {         cout <<  No  << endl;         return;       }       if (arrive[i] + toAdd > ans[i]) {         cout <<  No  << endl;         return;       }     }     cout <<  Yes  << endl;     for (int i = 0; i < n; ++i) {       if (i) cout <<    ;       cout << ans[i];     }     cout << endl;   }   int main() {     read();     work();     return 0;   }
#include <bits/stdc++.h>   const long long int M = 1e9 + 7;   using namespace std;   bool visit[100000];   vector<int> G[100000];   void dfs1(int v, stack<int> &s) {     visit[v] = true;     for (int i = 0; i < G[v].size(); i++) {       int c = G[v][i];       if (!visit[c]) dfs1(c, s);     }     s.push(v);   }   void dfs(int n) {     stack<int> s;     for (int i = 1; i <= n; i++)       if (!visit[i]) dfs1(i, s);     while (!s.empty()) {       cout << s.top() <<    ;       s.pop();     }   }   int main() {     ios::sync_with_stdio(false);     int n, m, i, a, b;     cin >> n >> m;     for (i = 0; i < m; i++) {       cin >> a >> b;       G[b].push_back(a);     }     dfs(n);     return 0;   }