malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ull = unsigned long long;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int _;     for (cin >> _; _--;) {       int n, q;       cin >> n >> q;       string a;       cin >> a;       vector<int> p(n);       p[0] = (a[0] ==  +  ? 1 : -1);       for (int i = 1; i < n; i++) {         if (i % 2)           p[i] = p[i - 1] - (a[i] ==  +  ? 1 : -1);         else           p[i] = p[i - 1] + (a[i] ==  +  ? 1 : -1);       }       vector<int> s(n);       s[n - 1] = (a[n - 1] ==  +  ? 1 : -1);       for (int i = n - 2; i >= 0; i--) {         if ((n - 1 - i) % 2)           s[i] = s[i + 1] - (a[i] ==  +  ? 1 : -1);         else           s[i] = s[i + 1] + (a[i] ==  +  ? 1 : -1);       }       while (q--) {         int l, r;         cin >> l >> r;         l--, r--;         if (l == 0) {           if (p[r] == 0) {             cout <<  0 n ;             continue;           }         } else {           if (p[r] == p[l - 1]) {             cout <<  0 n ;             continue;           }         }         int s1 = 0, s2 = 0;         if (l == 0)           s1 = p[r];         else {           if (l % 2 == 0) {             s1 = p[r] - p[l - 1];           } else {             s1 = p[l - 1] - p[r];           }         }         if (r == n - 1)           s2 = s[l];         else {           if ((n - 1 - r) % 2 == 0) {             s2 = s[l] - s[r + 1];           } else {             s2 = s[r + 1] - s[l];           }         }         if (s1 == s2) {           cout <<  1 n ;         } else {           cout <<  2 n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1000 * 1000 * 1000 + 7;   const int INF = 2000 * 1000 * 1000;   const double EPS = 1e-9;   const double pi = acos(-1.0);   const int maxn = 1010;   const int maxsum = 10010;   template <typename T>   inline T sqr(T n) {     return (n * n);   }   int n, a[maxn], mem[maxn][2 * maxsum];   int* dp[maxn];   long long ans;   int main() {     scanf( %d , &n);     dp[0] = mem[0] + maxsum;     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       dp[i] = mem[i] + maxsum;     }     dp[0][0] = 1;     ans = 0;     for (int i = 1; i <= n; i++) {       for (int sum = -10000; sum <= 10000; sum++) {         if (sum + a[i] <= 10000) dp[i][sum] += dp[i - 1][sum + a[i]];         if (sum - a[i] >= -10000) dp[i][sum] += dp[i - 1][sum - a[i]];         dp[i][sum] %= MOD;       }       ans += dp[i][0];       ans %= MOD;       dp[i][0]++;     }     printf( %I64d , ans);     return 0;   }
#include <bits/stdc++.h>   const int mod = 1000000007;   using namespace std;   long long c[100005];   int v[100005];   set<int> s;   int n, k;   long long all, ans;   int main() {     scanf( %d %d , &n, &k);     for (int i = 1; i <= n; i++) scanf( %I64d , &c[i]);     for (int i = 0; i < k; i++) scanf( %d , &v[i]);     all = 0;     ans = 0;     for (int i = 1; i <= n; i++) all += c[i];     for (int i = 1; i < n; i++) ans += c[i] * c[i + 1];     ans += c[n] * c[1];     s.clear();     for (int i = 0; i < k; i++) {       all -= c[v[i]];       s.insert(v[i]);       long long tmp = all;       if (v[i] < n && s.find(v[i] + 1) == s.end()) tmp -= c[v[i] + 1];       if (v[i] == n && s.find(1) == s.end()) tmp -= c[1];       if (v[i] > 1 && s.find(v[i] - 1) == s.end()) tmp -= c[v[i] - 1];       if (v[i] == 1 && s.find(n) == s.end()) tmp -= c[n];       ans += c[v[i]] * tmp;     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9 + 1;   const int N = 200123;   int z, n, s;   deque<int> dq;   int t[N];   int main() {     ios_base::sync_with_stdio(0);     int ans = 0;     cin >> n >> s;     for (int i = 0; i < n; i++) {       cin >> t[i];       if (i + 1 == s) {         ans += (t[i] != 0);         n--;         i--;         s = inf;       } else if (t[i] == 0)         t[i] = n + 5;     }     sort(t, t + n);     for (int i = 0; i < n; i++) {       dq.push_back(t[i]);     }     int nxt = 1;     while (dq.size()) {       while (dq.size() && nxt < dq.front()) {         dq.pop_back();         nxt++;         ans++;       }       if (dq.size()) {         nxt = max(nxt, dq.front() + 1);         dq.pop_front();       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, s, idx;     cin >> n >> s;     s--;     int a[n], b[n];     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       cin >> b[i];     }     if (a[0] == 1) {       for (int i = 0; i < n; i++) {         if (i == s && a[i] == 1) {           cout <<  YES ;           return 0;         } else if (i > s && a[i] == 1 && b[i] == 1) {           for (int j = i; j >= 0; j--) {             if (j == s && b[j] == 1) {               cout <<  YES ;               return 0;             }           }         }       }     }     cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n + 1];     int ans = 1;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++) {       int m = 1;       for (int j = i; j < n - 1 and a[j] >= a[j + 1]; j++) m++;       for (int j = i; j > 0 and a[j] >= a[j - 1]; j--) m++;       ans = max(ans, m);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       int s, n;       cin >> s >> n;       int temp = s, p = 1;       while (temp > 0) {         temp /= 10;         p *= 10;       }       p /= 10;       while (n > 1) {         if (s - p >= n - 1) {           cout << p <<    ;           s -= p;           n--;         } else           p /= 10;       }       cout << s << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a[5][5], i, j, one[2], nr = 0, nc = 0;     for (i = 0; i < 5; i++) {       for (j = 0; j < 5; j++) {         cin >> a[i][j];         if (a[i][j] == 1) {           one[0] = i;           one[1] = j;         }       }     }     if (one[0] == 0 || one[0] == 4) {       nr = 2;     } else if (one[0] == 1 || one[0] == 3) {       nr = 1;     }     if (one[1] == 0 || one[1] == 4) {       nc = 2;     } else if (one[1] == 1 || one[1] == 3) {       nc = 1;     }     cout << nr + nc;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1e18 + 9;   const long long mod = 1e9 + 7;   const long long maxn = 2e5 + 8;   char s[5][5], t[5][5];   long long n, m;   void solve() {     long long i, j;     cin >> s[1] + 1 >> s[2] + 1 >> t[1] + 1 >> t[2] + 1;     if (s[2][2] ==  X ) swap(s[2][1], s[2][2]);     if (s[1][2] ==  X ) swap(s[1][1], s[1][2]);     if (s[1][1] ==  X ) swap(s[1][1], s[2][1]);     if (t[2][2] ==  X ) swap(t[2][1], t[2][2]);     if (t[1][2] ==  X ) swap(t[1][1], t[1][2]);     if (t[1][1] ==  X ) swap(t[1][1], t[2][1]);     if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&         s[2][2] == t[2][2])       return (void)(cout <<  YES  << endl);     swap(s[1][1], s[2][1]);     swap(s[1][1], s[1][2]);     swap(s[1][2], s[2][2]);     swap(s[2][1], s[2][2]);     if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&         s[2][2] == t[2][2])       return (void)(cout <<  YES  << endl);     swap(s[1][1], s[2][1]);     swap(s[1][1], s[1][2]);     swap(s[1][2], s[2][2]);     swap(s[2][1], s[2][2]);     if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&         s[2][2] == t[2][2])       return (void)(cout <<  YES  << endl);     swap(s[1][1], s[2][1]);     swap(s[1][1], s[1][2]);     swap(s[1][2], s[2][2]);     swap(s[2][1], s[2][2]);     if (s[1][1] == t[1][1] && s[1][2] == t[1][2] && s[2][1] == t[2][1] &&         s[2][2] == t[2][2])       return (void)(cout <<  YES  << endl);     cout <<  NO  << endl;   }   signed main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 150005;   const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;   const double pi = 3.14159265359;   int n, t[maxn], ans, cnt;   vector<int> v, vp;   inline bool check(const vector<int> &vt) {     for (const int &i : vt) {       if (i == 0) {         if (t[i] >= t[i + 1])           return false;         else           continue;       } else if (i == n - 1) {         if (i % 2 == 0 && t[i] >= t[i - 1])           return false;         else if (i % 2 == 1 && t[i] <= t[i - 1])           return false;         else           continue;       } else if (i % 2 == 1 && (t[i] <= t[i - 1] || t[i] <= t[i + 1]))         return false;       else if (i % 2 == 0 && (t[i] >= t[i - 1] || t[i] >= t[i + 1]))         return false;     }     return true;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &t[i]);     if (t[0] < t[1])       vp.push_back(0);     else {       cnt++;       v.push_back(0);     }     if ((n - 1) % 2 == 0 && t[n - 1] < t[n - 2])       vp.push_back(n - 1);     else if ((n - 1) % 2 == 1 && t[n - 1] > t[n - 2])       vp.push_back(n - 1);     else {       cnt++;       v.push_back(n - 1);     }     for (int i = int(1); i < int(n - 1); i++) {       if (i % 2 == 0 && t[i] < t[i - 1] && t[i] < t[i + 1])         vp.push_back(i);       else if (i % 2 == 1 && t[i] > t[i - 1] && t[i] > t[i + 1])         vp.push_back(i);       else {         cnt++;         v.push_back(i);       }     }     if (v.size() > 6) {       printf( %d n , 0);       exit(0);     }     for (int i = 0; i < v.size() - 1; i++) {       for (int j = int(i + 1); j < int(v.size()); j++) {         swap(t[v[i]], t[v[j]]);         if (check(v)) ans++;         swap(t[v[i]], t[v[j]]);       }     }     for (const int &i : v) {       for (const int &j : vp) {         swap(t[i], t[j]);         vector<int> vt(v);         vt.push_back(j);         if (check(vt)) ans++;         swap(t[i], t[j]);       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     while (t--) {       long long int n, i, j, k, l = 0, s, x, y, z = 0, r = 1000000001, rr = 0;       cin >> n >> s >> k;       long long int a[k];       for (i = 0; i < k; i++) cin >> a[i];       sort(a, a + k);       for (i = 0; i < k; i++) {         if (a[i] == s) z = 1;       }       if (z == 0)         cout <<  0  << endl;       else if (z == 1 && k == 1)         cout <<  1  << endl;       else {         if (a[0] != 1) {           r = std::min(r, s - (a[0] - 1));           r = std::min(r, s - 1);         }         if (a[k - 1] != n) {           r = std::min(r, (a[k - 1] + 1) - s);           r = std::min(r, n - s);         }         for (i = 0; i < k - 1; i++) {           if ((a[i + 1] - a[i]) > 1) {             rr = a[i + 1] - 1;             if (a[i] >= s) {               rr = a[i] + 1;               r = std::min(r, (rr - s));             } else if (a[i + 1] <= s) {               rr = a[i + 1] - 1;               r = std::min(r, (s - rr));             }           }         }         cout << r << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename F>   class SegTree {     int n;     T uni;     F f;     vector<T> dat;       public:     SegTree(int _n, F f, T uni) : f(f), uni(uni) {       n = 1;       while (n < _n) n *= 2;       dat = vector<T>(2 * n, uni);     }     void set(int k, const T x) { dat[k + n] = x; }     void build() {       for (int i = n - 1; i >= 0; i--) {         dat[i] = f(dat[2 * i], dat[2 * i + 1]);       }     }     void update(int k, T x) {       k += n;       dat[k] = x;       while (k >>= 1) {         dat[k] = f(dat[2 * k], dat[2 * k + 1]);       }     }     T query(int a, int b) {       T l = uni, r = uni;       for (a += n, b += n; a < b; a >>= 1, b >>= 1) {         if (a & 1) l = f(l, dat[a++]);         if (b & 1) r = f(dat[--b], r);       }       return f(l, r);     }   };   int main() {     int n, k, d;     scanf( %d %d %d , &n, &k, &d);     int a[n];     for (int i = 0; i < (int)n; i++) scanf( %d , &a[i]);     sort(a, a + n);     auto f = [](int a, int b) { return a + b; };     SegTree<int, decltype(f)> st(n + 1, f, 0);     st.update(0, 1);     for (int i = 0; i < (int)n; i++) {       int l = lower_bound(a, a + n, a[i] - d) - a;       int r = max(0, i - k + 2);       if (st.query(l, r) > 0) st.update(i + 1, 1);     }     cout << (st.query(n, n + 1) ?  YES  :  NO ) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, w, s, a[110];   int in[110], out[110];   int main() {     scanf( %d%d , &n, &w);     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       s += a[i];     }     if (n == 1 && w == a[0]) {       puts( Yes );       for (int i = 0; i < w * 2; i++) {         printf( 1  );       }     } else if (n >= 2 && w >= 2 && w <= s) {       in[0] = a[0] - 1;       in[1] = a[1] - 1;       for (int i = 2; i < n; i++) {         in[i] = a[i];       }       for (int i = 0; i < n; i++) {         int x = min(w - 2, in[i]);         in[i] -= x;         out[i] += x;         w -= x;       }       puts( Yes );       for (int i = 0; i < n; i++) {         for (int j = 0; j < out[i] * 2; j++) {           printf( %d  , i + 1);         }       }       printf( 1  );       for (int i = 1; i < n; i++) {         for (int j = 0; j < in[i] * 2; j++) {           printf( %d  , i + 1);         }       }       printf( 1 2  );       for (int i = 0; i < in[0] * 2; i++) {         printf( 1  );       }       puts( 2 );     } else if (n >= 2 && w == 1) {       int k = 0;       while (k < n && a[k] != 1) {         k++;       }       if (k == n) {         puts( No );       } else {         puts( Yes );         printf( %d  , k + 1);         for (int i = 0; i < n; i++) {           if (i == k) {             continue;           }           for (int j = 0; j < a[i] * 2; j++) {             printf( %d  , i + 1);           }         }         printf( %d n , k + 1);       }     } else {       puts( No );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     char ar[1002][1002];     int n, m, i, j, count, ar1[1002];     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) {       scanf( %s , ar[i]);     }     for (i = 0; i < m; i++) {       ar1[i] = 1;     }     for (i = 1; i < n; i++) {       for (j = 0; j < m; j++) {         if (ar1[j] == 1) {           if (ar[i][j] < ar[i - 1][j]) {             ar1[j] = 0;             i = 0;             break;           }           if (ar[i][j] > ar[i - 1][j]) {             break;           }         }       }     }     count = 0;     for (i = 0; i < m; i++) {       count += 1 - ar1[i];     }     printf( %d n , count);     return 0;   }
#include <bits/stdc++.h>   template <class T>   inline bool rd(T &ret) {     char c;     int sgn;     if (c = getchar(), c == EOF) return 0;     while (c !=  -  && (c <  0  || c >  9 )) c = getchar();     sgn = (c ==  - ) ? -1 : 1;     ret = (c ==  - ) ? 0 : (c -  0 );     while (c = getchar(), c >=  0  && c <=  9 ) ret = ret * 10 + (c -  0 );     ret *= sgn;     return 1;   }   template <class T>   inline void pt(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x > 9) pt(x / 10);     putchar(x % 10 +  0 );   }   using namespace std;   const long long N = 200050;   long long n, m;   struct node {     long long op, l, r, num, id;   } a[N * 2];   bool cmp(node x, node y) {     if (x.r != y.r) return x.r < y.r;     if (x.op != y.op) return x.op < y.op;   }   long long top, b[N];   void input() {     top = 0;     for (long long i = 1; i <= n; i++) {       rd(a[top].l);       rd(a[top].r);       a[top].op = 0;       a[top].id = i;       top++;     }     rd(m);     for (long long i = 1; i <= m; i++) {       rd(a[top].l);       rd(a[top].r);       rd(a[top].num);       a[top].op = 1;       a[top].id = i;       top++;     }     sort(a, a + top, cmp);   }   struct Edge {     long long id, l;     bool operator<(const Edge &e) const {       if (e.l != l) return e.l > l;       return e.id > id;     }     Edge(long long a = 0, long long b = 0) : id(a), l(b) {}   } tmp;   set<Edge> s;   set<Edge>::iterator p;   int main() {     while (cin >> n) {       input();       long long ans = 0;       s.clear();       for (long long i = 0; i < top; i++) {         if (a[i].op) {           while (s.size() && a[i].num--) {             p = s.lower_bound(Edge(0, a[i].l));             if (p == s.end()) break;             tmp = *p;             b[tmp.id] = a[i].id;             s.erase(p);             ans++;           }         } else {           s.insert(Edge(a[i].id, a[i].l));         }       }       if (ans == n) {         puts( YES );         for (long long i = 1; i <= n; i++) {           pt(b[i]);           putchar(   );         }       } else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1000000007;   int clean(vector<pair<int, int> > &I) {     for (int i = 0; i < (int)I.size(); i++) {       swap(I[i].first, I[i].second);       I[i].second *= -1;     }     sort(begin(I), end(I));     for (int i = 0; i < (int)I.size(); i++) {       I[i].second *= -1;       swap(I[i].first, I[i].second);     }     vector<pair<int, int> > I_nw;     int lastb = -1;     for (int i = 0; i < (int)I.size(); i++) {       if (lastb < I[i].first) I_nw.push_back(I[i]);       lastb = max(lastb, I[i].first);     }     I = I_nw;     return I_nw.size();   }   long long pw(long long a, long long e, long long mod) {     if (e <= 0) return 1;     long long x = pw(a, e / 2, mod);     x = (x * x) % mod;     if (e % 2) x = (x * a) % mod;     return x;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout << fixed << setprecision(10);     int K, N[2];     cin >> K >> N[0] >> N[1];     vector<pair<int, int> > I[2];     map<int, int> M;     M[0] = M[K] = 0;     for (int k = 0; k < 2; k++) {       I[k].resize(N[k]);       for (int i = 0; i < N[k]; i++) {         cin >> I[k][i].first >> I[k][i].second;         I[k][i].first--;       }       N[k] = clean(I[k]);       for (int i = 0; i < N[k]; i++) M[I[k][i].first] = M[I[k][i].second] = 0;     }     int m = 0, last = 0;     vector<int> len;     vector<long long> cnt;     for (auto it = M.begin(); it != M.end(); it++) {       it->second = m++;       if (it->first != last) len.push_back(it->first - last);       last = it->first;     }     int L = len.size();     cnt.resize(L);     for (int i = 0; i < L; i++) cnt[i] = (pw(2, len[i], mod) + mod - 2) % mod;     for (int k = 0; k < 2; k++)       for (int i = 0; i < N[k]; i++) {         I[k][i].first = M[I[k][i].first];         I[k][i].second = M[I[k][i].second];       }     vector<long long> ans[3];     for (int k = 0; k < 3; k++) ans[k].resize(L + 1, 0);     ans[2][0] = 1;     vector<long long> sum_ans[3];     for (int k = 0; k < 3; k++) sum_ans[k].resize(L + 1, 0);     int pos[2] = {0, 0}, last_st[2] = {-1, -1};     for (int i = 0; i < L; i++) {       for (int k = 0; k < 3; k++)         sum_ans[k][i + 1] = (sum_ans[k][i] + ans[k][i]) % mod;       ans[2][i + 1] = (ans[0][i] + ans[1][i] + ans[2][i]) * cnt[i] % mod;       for (int k = 0; k < 2; k++) {         while (pos[1 - k] < N[1 - k] && I[1 - k][pos[1 - k]].second <= i + 1) {           last_st[1 - k] = I[1 - k][pos[1 - k]].first;           pos[1 - k]++;         }         ans[k][i + 1] =             (sum_ans[2][i + 1] - sum_ans[2][last_st[1 - k] + 1] +              sum_ans[1 - k][i + 1] - sum_ans[1 - k][last_st[1 - k] + 1]) %             mod;       }     }     long long ansF = (ans[0][L] + ans[1][L] + ans[2][L]) % mod;     if (ansF < 0) ansF += mod;     cout << ansF <<   n ;     return 0;   }
#include<bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 50;   #define int long long   #define ll long long   #define pb push_back   #define mp make_pair   #define debug(a) cout << #a <<     << a <<   n ;   #define debug2(a , b) cout << #a <<     << a <<   ||   << #b <<     << b <<   n ;   #define ye cout <<  YES n    #define no cout <<  NO n    #define cn cout <<   n     const int mod = 1e9 + 7;   using namespace std;      int a[maxn];   signed main()    {    ios::sync_with_stdio(false);    cin.tie(0);    cout.tie(0);     int t;    cin >> t;    while(t --){     int n , k;     cin >> n >> k;     for(int i = 1 ; i <= n ; i ++) cin >> a[i];     if(k == 0){      cout << n <<   n ;      continue;     }     sort(a + 1 , a + 1 + n);     int ok = 1;     for(int i = 1 ; i <= n ; i ++){      if(a[i] != i - 1) {       ok = 0;       break;      }     }     if(ok){      cout << n + k <<   n ;      continue;     }     int ans = n;     int one = -1;     if(a[1] != 0)one = 0;     else{      for(int i = 1 ; i <= n ; i ++){       if(a[i] - a[i - 1] > 1){        one = a[i - 1] + 1;        break;       }      }     }     if(one == -1) one = a[n] + 1;     //debug(one)     one = ((one + a[n]) % 2 == 0 ? (one + a[n]) / 2 : (one + a[n] + 1) / 2);     ans ++;     //debug(one)     for(int i = 1 ; i <= n ; i ++){      if(a[i] > one) break;      if(one == a[i]){       ans --;       break;       }     }     cout << ans <<   n ;    }     return 0;    }   /*      0 1 2   0 1 2 3      */
#include <bits/stdc++.h>   using namespace std;   const long long MX = 1e2 + 5;   vector<long long> g[MX];   long long vis[2][MX], ways[2][MX], dist[2][MX];   void bfs(long long x, long long idx) {     vis[idx][x] = 1;     queue<long long> q;     q.push(x);     ways[idx][x] = 1;     while (!q.empty()) {       long long node = q.front();       q.pop();       for (auto it : g[node]) {         if (!vis[idx][it]) {           dist[idx][it] = dist[idx][node] + 1;           vis[idx][it] = 1;           ways[idx][it] += ways[idx][node];           q.push(it);         } else {           if (dist[idx][node] + 1 == dist[idx][it])             ways[idx][it] += ways[idx][node];         }       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     long long n, m;     cin >> n >> m;     for (long long i = 0; i < m; i++) {       long long x, y;       cin >> x >> y;       g[x].push_back(y);       g[y].push_back(x);     }     bfs(1, 0);     bfs(n, 1);     long long mx = -1;     for (long long i = 1; i <= n; i++) {       if (dist[0][i] + dist[1][i] != dist[0][n]) continue;       long long cur = ways[0][i] * ways[1][i];       if (i != 1 and i != n) cur *= 2;       mx = max(mx, cur);     }     long double ans = (long double)mx / ways[0][n];     cout << fixed << setprecision(12) << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x, y, z, t1, t2, t3;     cin >> x >> y >> z >> t1 >> t2 >> t3;     if (abs(x - y) * t2 + t3 * 3 + t2 * abs(z - x) <= abs(x - y) * t1)       cout <<  YES ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[156], T, n, k, ans, lw, que[100];   int main() {     int T;     cin >> T;     while (T--) {       cin >> k;       lw = 0;       for (int i = 1; i <= 7; i++) {         cin >> a[i];         a[i + 7] = a[i];         lw += a[i];       }       int n = k / lw;       if (k % lw == 0) {         int maxx = 0, ll = 0;         for (int i = 1; i <= 14; i++) {           if (a[i] == 0) {             ll++;             maxx = max(maxx, ll);           } else             ll = 0;         }         ans = n * 7 - maxx;       } else {         int yu = k % lw, front = 0, ll = 0, minn = 1000;         queue<int> q;         while (!q.empty()) q.pop();         for (int i = 1; i <= 14; i++) {           if (a[i] == 0) continue;           if (a[i] == 1) {             ll++;             q.push(i);             if (ll >= yu) {               front = q.front();               q.pop();               minn = min(i - front + 1, minn);             }           }         }         ans = n * 7 + minn;       }       cout << ans << endl;     }   }