malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) { return b == 0 ? a : GCD(b, a % b); }   const long long inf = 0x7f7f7f7f;   const long long mod = 1e9 + 7;   double pi = acos(-1.0);   long long a[120];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, m, q;     cin >> n >> m >> q;     long long t = GCD(n, m);     n /= t;     m /= t;     long long x1, y1, x2, y2;     for (int i = 1; i <= q; i++) {       cin >> x1 >> y1 >> x2 >> y2;       if (t == 1) {         cout <<  YES  << endl;         continue;       }       long long p1, p2;       if (x1 == 1) {         p1 = y1 / n;         if (y1 % n) p1++;       } else {         p1 = y1 / m;         if (y1 % m) p1++;       }       if (x2 == 1) {         p2 = y2 / n;         if (y2 % n) p2++;       } else {         p2 = y2 / m;         if (y2 % m) p2++;       }       if (p1 == p2)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e9, maxn = 5e5 + 5, mod = 1e9 + 7;   long long x[maxn], y[maxn], sz[maxn], n, m;   set<long long> S;   unordered_map<long long, long long> cnt, id;   vector<long long> son[maxn];   long long gc(long long x) {     long long ret = 0, j = 0;     while (x <= n) {       ret += min(x + (1 << j) - 1, n) - x + 1;       x <<= 1;       ++j;       ret %= mod;     }     return ret;   }   void dfs(long long x) {     if (S.count(x)) {       cnt[x] = 1;       if ((x << 1) <= n) dfs(x << 1);       if ((x << 1 | 1) <= n) dfs(x << 1 | 1);     } else       cnt[x] = gc(x);   }   long long vis[maxn];   long long dfs2(long long x) {     vis[x] = 1;     long long ret = sz[x];     for (auto js : son[x])       if (!vis[js]) {         (ret += dfs2(js)) %= mod;       }     vis[x] = 0;     return ret;   }   signed main() {     scanf( %lld%lld , &n, &m);     if (m == 0) return printf( %lld n , 1ll * n * n % mod), 0;     for (long long i = 1; i <= m; i++) {       scanf( %lld%lld , &x[i], &y[i]);       long long tmp = x[i];       while (tmp) {         S.insert(tmp);         tmp >>= 1;       }       tmp = y[i];       while (tmp) {         S.insert(tmp);         tmp >>= 1;       }     }     S.insert(1);     dfs(1);     long long idc = 0;     for (auto i : cnt) id[i.first] = ++idc;     for (auto i : cnt) {       long long u = id[i.first];       sz[u] = i.second;       for (long long j = 0; j <= 1; j++) {         long long v = i.first << 1 | j;         if (!cnt.count(v)) continue;         v = id[v];         son[u].push_back(v);         son[v].push_back(u);       }     }     for (long long i = 1; i <= m; i++)       son[id[x[i]]].push_back(id[y[i]]), son[id[y[i]]].push_back(id[x[i]]);     long long ans = 0;     for (long long i = 1; i <= idc; i++)       ans = (ans + 1ll * sz[i] * sz[i] % mod) % mod;     for (long long i = 1; i <= idc; i++) {       vis[i] = 1;       long long cura = 0;       for (auto js : son[i]) {         cura = (cura + dfs2(js)) % mod;       }       ans = (ans + 1ll * cura * sz[i] % mod) % mod;       vis[i] = 0;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x = 0;     int n;     string ch;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> ch;       {         if (ch[1] ==  + ) x++;         if (ch[1] ==  - ) x--;       }     }     cout << x <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100000 + 100;   pair<int, int> khar[maxn];   bool mk[10 * maxn];   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       mk[a] = true;       khar[i] = pair<int, int>(a, b);     }     sort(khar, khar + n);     int k = khar[n - 1].first;     int x[k + 1];     fill(x, x + k + 1, 0);     if (mk[0]) x[0] = 1;     for (int i = 1; i <= k; i++) {       if (mk[i])         x[i] += x[i - 1] + 1;       else         x[i] += x[i - 1];     }     int h[n];     fill(h, h + n, 0);     for (int i = 1; i < n; i++) {       if (khar[i].first - khar[i].second <= 0) {         h[i] = i;         continue;       }       h[i] = x[khar[i].first - 1] - x[khar[i].first - khar[i].second - 1];     }     int g[n];     fill(g, g + n, 0);     for (int i = 1; i < n; i++) {       if (khar[i].first - khar[i].second <= 0) {         g[i] = i;         continue;       }       if (h[i] == 0)         g[i] = g[i - 1];       else         g[i] = h[i] + g[i - h[i] - 1];     }     for (int i = 0; i < n; i++) g[i] += n - i - 1;     sort(g, g + n);     cout << g[0] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dirx[] = {-1, -1, -1, 0, 0, 1, 1, 1};   int diry[] = {-1, 0, 1, -1, 1, -1, 0, 1};   int dx[] = {-1, 1, 0, 0};   int dy[] = {0, 0, -1, 1};   class SorT {    public:     bool operator()(pair<int, int>& p1, pair<int, int>& p2) {       return p1.second < p2.second;     }   };   int ans[1000010];   int main() {     string s;     cin >> s;     int left = 0, right = s.size() - 1;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  l )         ans[right--] = i + 1;       else         ans[left++] = i + 1;     }     for (int i = 0; i < s.size(); i++) {       printf( %d n , ans[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1e9 + 7;   void solve() {     long long int n;     cin >> n;     long long int a[n];     long long int hi = 0;     for (long long int i = 0; i < n; ++i) {       cin >> a[i];       hi += a[i];     }     sort(a, a + n);     long long int ans = hi - n;     if (n > 50) {       cout << ans;       return;     }     for (long long int i = 1; i < 1e9 + 1; ++i) {       long long int c = i;       long long int tmp = 0;       long long int dig = 0;       while (c > 0) {         c = c / 10;         dig++;       }       long long int no = 1;       c = i;       bool ex = true;       for (long long int j = 0; j < n; ++j) {         tmp += abs(a[j] - no);         if ((no * c) > 1e14 || (no * c) < 0) {           ex = false;           break;         }         long long int digi = 0, yo = no;         while (yo > 0) {           yo = yo / 10;           digi++;         }         if (digi + dig > 16) {           ex = false;           break;         }         no = no * c;       }       if (ex)         ans = min(ans, tmp);       else {         break;       }     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t = 1;     while (t--) {       solve();     }     cerr <<  Time elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;   }
#include <bits/stdc++.h>   using namespace std;   long long n, x, y;   long long bs1(long long l, long long r, long long num) {     long long mid = (l + r) / 2;     if (r - l <= 0) {       return -1;     }     long long time = mid * x;     long long highnow = mid + ((mid * x + x - 1) / y);     long long lownow = mid + ((time) / y);     if (highnow >= num && lownow < num) {       return mid;     }     if (highnow < num) {       return bs1(mid + 1, r, num);     }     return bs1(l, mid, num);   }   long long bs2(long long l, long long r, long long num) {     long long mid = (l + r) / 2;     if (r - l <= 0) {       return -1;     }     long long time = mid * y;     long long highnow = mid + ((mid * y + y - 1) / x);     long long lownow = mid + ((time) / x);     if (highnow >= num && lownow < num) {       return mid;     }     if (highnow < num) {       return bs2(mid + 1, r, num);     }     return bs2(l, mid, num);   }   int main() {     cin >> n >> x >> y;     for (int i = 0; i < n; i++) {       long long num;       cin >> num;       long long ansy = bs1(0, num + 1, num);       long long ansx = bs2(0, num + 1, num);       if (ansy == -1 && ansx == -1) {         cout <<  Both  << endl;         continue;       }       if (ansx == -1) {         cout <<  Vanya  << endl;         continue;       }       if (ansy == -1) {         cout <<  Vova  << endl;         continue;       }       cout <<  Both  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ii = pair<int, int>;   const int mod = 1e9 + 7;   int v[200005];   int n, k;   bool guess(int x) {     ll spent = x - v[n / 2];     for (int i = n / 2 + 1; i < n; i++) {       spent += max(0, x - v[i]);       if (spent > (ll)k) return false;     }     return spent <= (ll)k;   }   int solve() {     int x = -1;     for (int b = v[n - 1] + k; b >= 1; b /= 2)       while (guess(x + b)) x += b;     return x;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k;     for (int i = 0; i < n; i++) cin >> v[i];     sort(v, v + n);     cout << solve() <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500010;   const int MOD = 1000000007;   int n, m, q;   char s[14];   int f[(1 << 12) + 10][(1 << 12) + 10], w[13], freq[(1 << 12) + 10];   int v[(1 << 12) + 10][100 * 14];   int main() {     cin >> n >> m >> q;     for (int i = 0; i < n; ++i) {       scanf( %d , &w[i]);     }     for (int i = 0; i < m; ++i) {       scanf( %s , s);       int val = 0;       for (int j = 0; j < n; ++j) {         val += (s[j] -  0 ) * (1 << j);       }       freq[val]++;     }     for (int msk = 0; msk < (1 << n); ++msk) {       for (int go = 0; go < (1 << n); ++go) {         for (int bit = 0; bit < n; ++bit) {           f[msk][go] += (((go & (1 << bit)) == (msk & (1 << bit))) * w[bit]);         }       }     }     for (int msk = 0; msk < (1 << n); ++msk) {       for (int go = 0; go < (1 << n); ++go) {         v[msk][f[msk][go]] += freq[go];       }       for (int j = 1; j <= 1300; ++j) {         v[msk][j] += v[msk][j - 1];       }     }     for (int k, i = 0; i < q; ++i) {       scanf( %s%d , s, &k);       int cur = 0;       for (int j = 0; j < n; ++j) {         cur += (1 << j) * (s[j] -  0 );       }       printf( %d n , v[cur][k]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 100, LEN = 21, M = 1 << LEN, inF = N * 30;   int n, len, ps[N], dp0[N], dp1[N], mini[M][LEN];   string s[N];   void _min(int &a, int b) { a = min(a, b); }   int same(string a, string b) {     int A = 0, B = 0, res = 0;     for (int i = 0; i < len; i++) {       A |= (a[len - i - 1] -  0 ) << i;       B = (B << 1) | (b[i] -  0 );       if (A == B) res = i + 1;     }     return res;   }   int dif(string a, string b) { return len - same(a, b); }   void add(int dex) {     _min(mini[0][0], dp1[dex] - ps[dex] + len - 0);     int val = 0;     for (int i = 1; i <= len; i++)       val |= (s[dex - 1][len - i] -  0 ) << (i - 1),           _min(mini[val][i], dp1[dex] - ps[dex] + len - i);   }   void find_dp() {     dp0[0] = dp1[0] = len;     for (int i = 1; i < n; i++) {       dp0[i] = min(dp0[i - 1], dp1[i - 1]) + dif(s[i - 1], s[i]);       dp1[i] = min((i == 1 ? len << 1 : dp1[i - 1] + dif(s[i - 2], s[i])),                    ps[i - 1] + len);       int val = 0;       _min(dp1[i], mini[val][0] + ps[i - 1]);       for (int j = 1; j <= len; j++)         val = (val << 1) | (s[i][j - 1] -  0 ),         _min(dp1[i], mini[val][j] + ps[i - 1]);       if (i != n - 1) add(i);     }   }   int main() {     for (int i = 0; i < M; i++) fill(mini[i], mini[i] + LEN, inF);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s[i];       ps[i] = (i ? ps[i - 1] + dif(s[i - 1], s[i]) : len = s[i].length());     }     find_dp();     cout << min(dp0[n - 1], dp1[n - 1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int64_t>> board, vis, diag1, diag2;   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int64_t n;     cin >> n;     for (int64_t i = 0; i < n; i++) {       vector<int64_t> temp;       vector<int64_t> zero;       for (int64_t j = 0; j < n; j++) {         int64_t t;         cin >> t;         temp.push_back(t);         zero.push_back(0);       }       board.push_back(temp);       vis.push_back(zero);       diag1.push_back(zero);       diag2.push_back(zero);     }     for (int64_t i = 0; i < n; i++) {       for (int64_t j = 0; j < n; j++) {         if (vis[i][j]) continue;         int64_t t1 = i, t2 = j, s = 0;         while (1) {           vis[t1][t2] = 1;           s += board[t1][t2];           t1 -= -1;           t2 -= -1;           if (t1 >= n || t2 >= n) break;         }         t1 = i, t2 = j;         while (1) {           diag1[t1][t2] = s;           t1 -= -1;           t2 -= -1;           if (t1 >= n || t2 >= n) break;         }       }     }     for (int64_t i = 0; i < n; i++)       for (int64_t j = 0; j < n; j++) vis[i][j] = 0;     for (int64_t i = 0; i < n; i++) {       for (int64_t j = 0; j < n; j++) {         if (vis[i][j]) continue;         int64_t t1 = i, t2 = j, s = 0;         while (1) {           vis[t1][t2] = 1;           s += board[t1][t2];           t1 -= -1;           t2 += -1;           if (t1 >= n || t2 < 0) break;         }         t1 = i, t2 = j;         while (1) {           diag2[t1][t2] = s;           t1 -= -1;           t2 += -1;           if (t1 >= n || t2 < 0) break;         }       }     }     int64_t m1 = 0, m2 = 0, x1 = 0, x2 = 0, y1 = 0, y2 = 0;     for (int64_t i = 0; i < n; i++) {       for (int64_t j = 0; j < n; j++) {         int64_t tmp = diag1[i][j] + diag2[i][j] - board[i][j];         if ((i + j) % 2) {           if (tmp >= m1) {             m1 = tmp;             x1 = i + 1;             y1 = j + 1;           }         } else {           if (tmp >= m2) {             m2 = tmp;             x2 = i + 1;             y2 = j + 1;           }         }       }     }     cout << m1 + m2 << endl;     cout << x1 <<     << y1 <<     << x2 <<     << y2;   }
#include <bits/stdc++.h>   using namespace std;   void boost() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   void free() {     freopen( A.in ,  r , stdin);     freopen( A.out ,  w , stdout);   }   int a[100001];   int main() {     boost();     int n;     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i];     long long ans = 1, h = a[0];     ans += h;     for (int i = 1; i < n; i++) {       if (a[i] >= h)         ans += (a[i] - h + 1), h = a[i];       else if (a[i] < h)         ans += (h - a[i] + 1), h = a[i];       ans++;     }     cout << ans, exit(0);   }
#include <bits/stdc++.h>   using namespace std;   inline void read(long long &num) {     num = 0;     long long f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       num = num * 10 + c - 48;       c = getchar();     }     num *= f;   }   const long long maxn = 1e5 + 7;   long long n, a[maxn], al, t;   signed main() {     read(n);     al = 0;     for (long long i = 1; i <= n; ++i) read(a[i]), al ^= a[i];     if (!(n & 1) && al) {       puts( NO );       return 0;     }     if (!(n & 1)) --n;     puts( YES );     cout << n - 1 << endl;     for (long long i = 1; i <= n - 2; i += 2)       cout << i <<     << i + 1 <<     << i + 2 << endl;     for (long long i = 1; i <= n - 2; i += 2)       cout << i <<     << i + 1 <<     << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int mod = 1000000007;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int l = 1, h, i, n, x, t, q, y = -1, z = 0, a = 0, b = 0, c = 0, k,                   sum = 0, m, d = 0, r, w, j, ans, s, mini = INT_MAX,                   maxi = INT_MIN;     bool cou;     float kl;     long long int count = 0;     t = 1;     vector<bool> sie(1000001, 0);     char cg;     string str, std;     a = 1;     while (t--) {       cin >> n >> m;       vector<int> vec(n);       map<int, bool> mp;       for (i = 0; i < n; ++i) cin >> vec[i];       for (i = 0; i < m; ++i) {         cin >> x;         mp[x] = 1;       }       for (i = 0; i < n; ++i) {         if (mp[vec[i]]) cout << vec[i] <<    ;       }     }   }
#include <bits/stdc++.h>   #include<stdlib.h>   using namespace std;   #define pb push_back   #define ll long long   #define ff first   #define ss second   #define ppb pop_back   #define mp make_pair   #define vl vector<ll>   #define vi vector<int>   #define endl   n    #define all(x) x.begin(), x.end()   #define deb(x) cout << #x <<     << x << endl;   #define f(i, n) for(i=0; i<n; i++)   #define F(i, k, n) for(i=k; i<n; i++)   #define max(a,b) (a<b?b:a)   #define min(a,b) (a>b?b:a)   #define INF 1001001001   #define PI 3.1415926535897932384626   #define MOD 1000000007      void FAST() {     ios::sync_with_stdio(0);    cin.tie(0);    cout.tie(0);   }      // template<typename... T>   // void read(T&... args) {   //  FAST();   //  ((cin >> args), ...);   // }      // template<typename... T>   // void write(T&&... args) {    //  FAST();   //  ((cout << args <<    ), ...);   // }      // template<typename T>   // T gcd(T a, T b) {   //     if (b == 0)    //         return a;    //     return gcd(b, a % b);     // }       // template <typename T>   // void printContainer(T &v){   //     for(auto i : v){   //         cout<<i<<   ;    //     }   //     cout <<endl;   // }      int main() {    FAST();    //code       ll t;       cin>>t;       ll p;       f(p,t){           string s;           cin>>s;           ll i, a1=0, x1=0, x2=0, a2=0,b1=0,b2=0;           f(i,s.size()){               if(s[i]== ( ){                   a1++;                   x1++;               }               else if(s[i]== )  && x1>0){                   a2++;                   x1--;               }               else if(s[i]== [ ){                   b1++;                   x2++;               }               else if(s[i]== ]  && x2>0){                   b2++;                   x2--;               }           }           cout<<min(a1,a2)+min(b1,b2)<<endl;              }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5;   map<long long, long long> freq, freq2;   void func1(long long a[], long long n) {     int i = 0, j = 0;     while (i < n) {       if (a[i] == 0) {         i++;         continue;       }       j = i;       while (j < n && a[j] != 0) {         j++;       }       for (int p = 1; p <= (j - i); p++) {         freq[p] += (j - i) - p + 1;       }       i = j;     }   }   void func2(long long a[], long long n) {     int i = 0, j = 0;     while (i < n) {       if (a[i] == 0) {         i++;         continue;       }       j = i;       while (j < n && a[j] != 0) {         j++;       }       for (int p = 1; p <= (j - i); p++) {         freq2[p] += (j - i) - p + 1;       }       i = j;     }   }   int main() {     long long n, a[N], b[N], r = 0, c = 0, ans = 0, cnt = 0, sum = 0, k, m;     cin >> n >> m >> k;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < m; i++) cin >> b[i];     func1(a, n);     func2(b, m);     for (int p = 1; p <= sqrt(k); p++) {       if (k % p == 0) {         ans += freq[p] * freq2[k / p];         if (p != (k / p)) ans += freq[k / p] * freq2[p];       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a, x, b, y;     cin >> n >> a >> x >> b >> y;     while (a != x && b != y) {       if (a == b) break;       a = (a % n) + 1;       if (b == 1)         b = n;       else         b--;     }     if (a == b)       cout <<  YES ;     else       cout <<  NO ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   int lcm(int a, int b) { return a / gcd(a, b) * b; }   const int mod = 1e9 + 7;   long long binpow(long long a, long long b) {     long long res = 1;     while (b > 0)       if (b & 1) {         res = (long long)(res * 1ll * a);         --b;       } else {         a = (long long)(a * 1ll * a);         b >>= 1;       }     return (long long)res;   }   vector<vector<int>> g;   vector<bool> used;   int pred = -1;   int timer = 0;   vector<int> tin, tout;   void dfs(int v, int p = -1) {     used[v] = true;     tin[v] = timer;     timer++;     for (auto to : g[v]) {       if (!used[to]) dfs(to);     }     tout[v] = timer;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int q;     cin >> q;     while (q--) {       int n, a, b, da, db;       cin >> n >> a >> b >> da >> db;       vector<vector<int>> g;       g.resize(n);       for (int i = 0; i < n - 1; i++) {         int u, v;         cin >> u >> v;         u--;         v--;         g[u].push_back(v);         g[v].push_back(u);       }       if (da * 2 >= db) {         cout <<  Alice  << endl;         continue;       }       int starta = a - 1;       int startb = b - 1;       vector<bool> used(n);       queue<int> q;       used[starta] = true;       q.push(starta);       vector<int> d(n);       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (!used[to]) {             used[to] = true;             q.push(to);             d[to] = d[v] + 1;           }         }       }       int ind_max = 0;       int maxi = 0;       for (int i = 0; i < n; i++) {         if (d[i] > maxi) {           maxi = d[i];           ind_max = i;         }       }       if (abs(d[startb]) <= da) {         cout <<  Alice  << endl;         continue;       }       used.clear();       used.resize(n);       used[ind_max] = true;       q.push(ind_max);       d.clear();       d.resize(n);       while (!q.empty()) {         int v = q.front();         q.pop();         for (auto to : g[v]) {           if (!used[to]) {             used[to] = true;             q.push(to);             d[to] = d[v] + 1;           }         }       }       int ans = 0;       for (int i = 0; i < n; i++) {         ans = max(ans, d[i]);       }       if (double(ans) / da > 2.0) {         cout <<  Bob  << endl;       } else {         cout <<  Alice  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   template <typename T>   T pow(T a, T b, long long m) {     T ans = 1;     while (b > 0) {       if (b % 2 == 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans % m;   }   using namespace std;   bool B[100], G[100];   int main() {     int n, m;     cin >> n >> m;     int b;     cin >> b;     for (int(i) = (0); (i) < (b); (i)++) {       int first;       cin >> first;       B[first] = 1;     }     int g;     cin >> g;     for (int(i) = (0); (i) < (g); (i)++) {       int first;       cin >> first;       G[first] = 1;     }     for (int(i) = (0); (i) < (10000000); (i)++)       B[i % n] = G[i % m] = B[i % n] | G[i % m];     bool boys = 1, girls = 1;     for (int(i) = (0); (i) < (n); (i)++) boys &= B[i];     for (int(i) = (0); (i) < (m); (i)++) girls &= G[i];     if (boys && girls)       cout <<  Yes  <<   n ;     else       cout <<  No  <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, lim;   struct node {     int to;     int val;   };   stack<int> ans;   vector<node> g[5500];   int f[5500][5500];   int fa[5500][5500];   void dfs(int u, int dep) {     for (int i = 0; i != g[u].size(); i++) {       int& co = g[u][i].val;       int& v = g[u][i].to;       if (f[dep][u] + co <= lim && f[dep][u] + co < f[dep + 1][v]) {         fa[v][dep] = u;         f[dep + 1][v] = f[dep][u] + co;         dfs(v, dep + 1);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &lim);     int t1, t2, t3;     for (int i = 0; i != m; i++) {       scanf( %d%d%d , &t1, &t2, &t3);       g[t1].push_back(node{t2, t3});     }     memset(f, 0x7f, sizeof(f));     f[1][1] = 0;     dfs(1, 1);     int i = n;     while (!fa[n][i]) i--;     cout << i + 1 << endl;     ans.push(n);     while (fa[n][i]) {       ans.push(fa[n][i]);       n = fa[n][i];       i--;     }     cout << ans.top();     ans.pop();     while (!ans.empty()) {       cout <<     << ans.top();       ans.pop();     }     cout << endl;   }