malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int p = 1000000007;   long long n;   int k, ans;   int inv[123];   int F[55][55][10110];   int exp(int a, int b, int c) {     int d = 1;     while (b) {       if (b & 1) d = 1LL * d * a % c;       b >>= 1;       a = 1LL * a * a % c;     }     return d;   }   int f(int lim, int now, int k) {     if (F[lim][now][k] != 0) return F[lim][now][k];     if (k == 1) return inv[now + 1];     int res = 0;     for (int i = lim; i <= now; i++) res = (res + f(lim, i, k - 1)) % p;     res = 1LL * res * inv[now + 1] % p;     F[lim][now][k] = res;     return res;   }   int main() {     scanf( %I64d%d , &n, &k);     int res = 1;     inv[1] = 1;     for (int i = 2; i <= 100; i++) inv[i] = -1LL * inv[p % i] * (p / i) % p;     for (int i = 2; 1LL * i * i <= n; i++)       if (n % i == 0) {         int c = 0, inv = exp(i, p - 2, p), ans = 0;         int u = 1;         while (n % i == 0) n /= i, c++, u = 1LL * u * i % p;         for (int j = c; j >= 0; j--) {           ans = (ans + 1LL * u * f(j, c, k)) % p;           u = 1LL * u * inv % p;         }         res = 1LL * res * ans % p;       }     if (n != 1) {       res = 1LL * res * (f(0, 1, k) % p + 1LL * n % p * f(1, 1, k) % p) % p;     }     if (res < 0) res += p;     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   string a[33];   int z[33][33];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     cin >> n >> m;     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         z[i + 1][j + 1] = z[i + 1][j] + z[i][j + 1] - z[i][j] + (a[i][j] ==  1 );       }     int sol = 0;     for (int p = 0; p < n; p++)       for (int q = 0; q < m; q++)         for (int r = p + 1; r <= n; r++)           for (int s = q + 1; s <= m; s++) {             int c = 0;             c += z[p][q];             c += z[r][s];             c -= z[p][s];             c -= z[r][q];             if (c == 0) {               sol = max(sol, r - p + s - q);             }           }     cout << 2 * sol <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, i, j = 0, r, ctr = 0, ans;     cin >> n;     string s, s7;     cin >> s;     string s1 =  RGB ;     string s2 =  GBR ;     string s3 =  BGR ;     string s4 =  GRB ;     string s5 =  RBG ;     string s6 =  BRG ;     j = 0;     for (i = 0; i < n; i++) {       if (s1[j] != s[i]) {         ctr++;       }       j++;       if (j == 3) {         j = 0;       }     }     ans = ctr;     ctr = 0;     s7 = s1;     j = 0;     for (i = 0; i < n; i++) {       if (s2[j] != s[i]) {         ctr++;       }       j++;       if (j == 3) {         j = 0;       }     }     if (ans > ctr) {       ans = ctr;       s7 = s2;     }     ctr = 0;     j = 0;     for (i = 0; i < n; i++) {       if (s3[j] != s[i]) {         ctr++;       }       j++;       if (j == 3) {         j = 0;       }     }     if (ans > ctr) {       ans = ctr;       s7 = s3;     }     ctr = 0;     j = 0;     for (i = 0; i < n; i++) {       if (s4[j] != s[i]) {         ctr++;       }       j++;       if (j == 3) {         j = 0;       }     }     if (ans > ctr) {       ans = ctr;       s7 = s4;     }     ctr = 0;     j = 0;     for (i = 0; i < n; i++) {       if (s5[j] != s[i]) {         ctr++;       }       j++;       if (j == 3) {         j = 0;       }     }     if (ans > ctr) {       ans = ctr;       s7 = s5;     }     ctr = 0;     j = 0;     for (i = 0; i < n; i++) {       if (s6[j] != s[i]) {         ctr++;       }       j++;       if (j == 3) {         j = 0;       }     }     if (ans > ctr) {       ans = ctr;       s7 = s6;     }     j = 0;     for (i = 0; i < n - 3; i++) {       s7.push_back(s7[j]);       j++;       if (j == 3) {         j = 0;       }     }     if (n < 3) {       if (n == 1) {         cout <<  0  << endl;         cout << s;       } else if (n == 2) {         if (s[i] == s[i + 1]) {           if (s[i] ==  R ) {             s[i] =  G ;           } else if (s[i] ==  G ) {             s[i] =  B ;           } else if (s[i] ==  B ) {             s[i] =  R ;           }           cout <<  1  << endl;           cout << s;         } else {           cout <<  0  << endl;           cout << s;         }       }     } else {       cout << ans << endl;       cout << s7;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, k;     cin >> n >> m >> k;     vector<int> arr(n);     for (int i = 0; i < n; i++) cin >> arr[i];     vector<int> temp;     for (int i = 1; i < n; i++) {       int val = arr[i] - arr[i - 1] - 1;       temp.push_back(val);     }     sort(temp.begin(), temp.end());     long long int ans = arr[n - 1] - arr[0] + 1;     for (int i = 1; i < k; i++) {       ans = ans - temp[n - 1 - i];     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s, ans, temp;     cin >> s;     int flag = 0;     for (int i = 0; i < k; i++) {       for (int j = i; j < n; j += k) {         if (s[i] != s[j]) {           flag = 1;           break;         }       }       if (flag) break;     }     if (!flag) {       cout << s.length() << endl;       cout << s << endl;       return 0;     }     for (int i = 0; i < k; i++) temp += s[i];     for (int i = 0; i < n / k; i++) ans += temp;     int i = 0;     while (ans.length() < s.length()) {       ans += temp[i];       i++;     }     if (ans >= s) {       cout << ans.length() << endl;       cout << ans << endl;       return 0;     }     i = 0, flag = 0;     for (i = k - 1; i >= 0; i--) {       if (s[i] <  9 ) {         s[i] = s[i] + 1;         flag = 1;         break;       }     }     if (flag) {       i++;       for (i; i < k; i++) s[i] =  0 ;     }     temp.clear(), ans.clear();     for (int i = 0; i < k; i++) temp += s[i];     for (int i = 0; i < n / k; i++) ans += temp;     i = 0;     while (ans.length() < s.length()) {       ans += temp[i];       i++;     }     cout << ans.length() << endl;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int a[100100];   int num[100100];   int main() {     set<int> s;     int n;     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = n; i >= 1; i--) {       s.insert(a[i]);       num[i] = s.size();     }     s.clear();     long long sum = 0;     for (int i = 1; i <= n; i++) {       if (s.find(a[i]) == s.end()) {         s.insert(a[i]);         sum += num[i + 1];       }     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     int a[n][m];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) cin >> a[i][j];     }     int b[m][n];     bool flag = false;     int index = -1;     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++) {         cin >> b[i][j];         if (b[i][j] == a[0][0] && !flag) {           flag = true;           index = i;         }       }     }     for (int i = 0; i < n; i++) {       int curr = b[index][i];       for (int j = 0; j < n; j++) {         if (a[j][0] == curr) {           for (int k = 0; k < m; k++) cout << a[j][k] <<    ;           cout << endl;         }       }     }   }   int main() {     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long u, long long v) {     if (u < v) swap(u, v);     while (v != 0) {       int r = u % v;       u = v;       v = r;     }     return u;   }   pair<int, int> row[200000], col[200000];   int main(void) {     int n, m, k;     cin >> n >> m >> k;     for (int i = 0; i < 200000; ++i) {       row[i] = make_pair(0, -1);       col[i] = make_pair(0, -1);     }     int t = 0;     for (int i = 0; i < k; ++i) {       t++;       int q;       cin >> q;       if (q == 1) {         int r, a;         cin >> r >> a;         r--;         row[r] = make_pair(a, t);       } else if (q == 2) {         int c, a;         cin >> c >> a;         c--;         col[c] = make_pair(a, t);       }     }     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (row[i].second > col[j].second)           cout << row[i].first;         else           cout << col[j].first;         if (j != m - 1) cout <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   int dizi[100015];   int main() {     int i, m, n, fark, k, j;     scanf( %d %d %d %d , &m, &n, &k, &j);     for (i = 1;; i++) {       j = (j * m + n) % k;       if (dizi[j]) {         printf( %d , i - dizi[j]);         break;       }       dizi[j] = i;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, i, j, k, a1, a2, a3, a4, res, ans, sum;   bool k1, k2, k3;   long long l, r, M;   string s, q, s1, s2;   long long a[5000000];   int main() {     cin >> n >> a4;     for (i = 1; i <= n; i++) cin >> a1 >> a2, a[i] = a1 * a2;     for (i = 2; i <= n; i++) a[i] += a[i - 1];     for (i = 1; i <= a4; i++) {       cin >> j;       l = 1;       r = n;       while (l + 1 < r) {         m = (l + r) / 2;         if (a[m] >= j)           r = m;         else           l = m + 1;       }       if (a[l] >= j)         cout << l << endl;       else         cout << r << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int sum(int a) {     int sum = a;     while (a) {       sum += a % 10;       a /= 10;     }     return sum;   }   int main() {     vector<int> v;     int a;     cin >> a;     int b = a;     while (a) {       int check = sum(a);       if (check == b)         v.push_back(a);       else if (check + 100 < b)         break;       a--;     }     cout << v.size() << endl;     reverse(v.begin(), v.end());     for (auto i : v) {       cout << i << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, Cnt = 0;   double A[4005], C[4005], Ans = 0.0, Anx;   double Abs(double x) { return x < 0 ? -x : x; }   int main() {     scanf( %d , &N);     for (int i = 1; i <= 2 * N; i++) scanf( %lf , &A[i]), C[i] = A[i] - (int)A[i];     for (int i = 1; i <= 2 * N; i++) {       if (C[i] == 0) Cnt++;       Ans += -C[i];     }     Anx = Abs(Ans + 1.0 * N);     for (int i = max(N - Cnt, 0); i <= N; i++) {       Anx = min(Anx, Abs(Ans + i));     }     printf( %.3f n , Anx);     return 0;   }
#include <bits/stdc++.h>   int main() {     int k, a, b;     scanf( %d , &k);     for (int i = k / 2000 + (k % 2000 > 0);; ++i) {       b = i * 2000 - k;       a = i - b;       if (b <= 1e6 && a < 0 && a >= -1e6) break;     }     puts( 2000 );     for (int i = 1; i <= 1998; ++i) printf( 0  );     printf( %d %d n , a, b);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     string s, s1 =   , s2 =   ;     cin >> n >> s;     reverse(s.begin(), s.end());     for (int i = 0; i < s.size(); ++i) {       if (i % 2 == 0)         s1 += s[i];       else         s2 += s[i];     }     reverse(s1.begin(), s1.end());     cout << s2 << s1;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:10000000000 )   #pragma GCC optimize( O3 )   using namespace std;   const int MOD = 1000000007;   const int INF = 1000000007LL;   const long long INF2 = 1LL << 62LL;   const long double EPS = 1e-9;   const int SIZE = 200010;   mt19937 rng(time(0));   uniform_int_distribution<int> uid(-1000000000, 1000000000);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int tt;     cin >> tt;     for (int rep_iter = 0; rep_iter < tt; ++rep_iter) {       int n, x, y, ost;       cin >> n >> x >> y;       vector<int> b(n, -1);       set<int> used_color;       map<int, vector<int> > pos;       for (int i2 = 0; i2 < n; ++i2) {         int a;         cin >> a;         used_color.insert(a);         pos[a].push_back(i2);       }       for (int i = 1; i <= n + 1; ++i) {         if (!(used_color.find(i) != used_color.end())) {           ost = i;           break;         }       }       set<pair<int, int> > colors;       for (auto& i : pos) colors.insert({i.second.size(), i.first});       for (int rep_iter = 0; rep_iter < x; ++rep_iter) {         auto p = *(--colors.end());         colors.erase(--colors.end());         --p.first;         int color = p.second;         int j = pos[color].back();         pos[color].pop_back();         b[j] = color;         if (p.first) colors.insert(p);       }       y -= x;       int m = n - x;       int real_y;       if (colors.size())         real_y = min(m, (m - (--colors.end())->first) * 2);       else         real_y = m;       if (real_y < y) {         cout <<  NO n ;         continue;       }       cout <<  YES n ;       vector<int> v;       int j = -1;       for (auto& i : colors) {         if (i.first) j = v.size();         for (int rep_iter = 0; rep_iter < i.first; ++rep_iter)           v.push_back(i.second);       }       for (auto& color : v) {         if (!y) break;         --y;         int color_move = v[j];         j = (j + 1) % v.size();         while (color_move == color) {           color_move = v[j];           j = (j + 1) % v.size();         }         int k = pos[color].back();         pos[color].pop_back();         b[k] = color_move;       }       for (auto& i : b) {         if (i == -1) i = ost;       }       for (auto& i : b) cout << i <<    ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( O2 )   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   template <typename T>   ostream& operator<<(ostream& os, const vector<T>& v) {     for (long long i = 0; i < v.size(); ++i) os << v[i] <<    ;     return os;   }   template <typename T>   ostream& operator<<(ostream& os, const set<T>& v) {     for (auto it : v) os << it <<    ;     return os;   }   template <typename T, typename S>   ostream& operator<<(ostream& os, const pair<T, S>& v) {     os << v.first <<     << v.second;     return os;   }   const long long mod = 1e9 + 7;   const long long inf = 2e18;   const long long ninf = -2e18;   long long pow(long long a, long long b, long long m) {     long long ans = 1;     while (b) {       if (b & 1) ans = (ans * a) % m;       b /= 2;       a = (a * a) % m;     }     return ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     time_t t1, t2;     t1 = clock();     long long n, m, ta, tb, k;     cin >> n >> m >> ta >> tb >> k;     vector<long long> arra(n);     for (long long i = 0; i < n; i++) {       cin >> arra[i];     }     vector<long long> arrb(m);     for (long long i = 0; i < m; i++) {       cin >> arrb[i];     }     if (n <= k || m <= k) {       cout << -1 <<   n ;       return 0;     }     long long ans = -1;     for (long long i = 0; i <= k; i++) {       long long curr = arra[i] + ta;       long long req = lower_bound(arrb.begin(), arrb.end(), curr) - arrb.begin();       long long rem = k - i;       if (req + rem > m - 1) {         ans = inf;         break;       }       long long ap = arrb[req + rem] + tb;       ans = max(ap, ans);     }     if (ans != inf) {       cout << ans <<   n ;     } else       cout << -1 <<   n ;     t2 = clock();     cerr <<   n  << t2 - t1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> arr;   int n, k;   long long sum[5500];   double mx = -1e9;   int main() {     cin >> n >> k;     for (int x, i = 1; i <= n; i++) {       cin >> x;       arr.push_back(x);       sum[i] = sum[i - 1] + x;     }     for (int i = 1; i <= n; i++) {       for (int j = i + k - 1; j <= n; j++) {         mx = max(mx, (sum[j] - sum[i - 1]) / (double(j - i + 1)));       }     }     printf( %0.15lf , mx);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, i, j, f, n;     cin >> t;     while (t--) {       cin >> n;       string s;       cin >> s;       f = 0;       for (i = 0; i < n; i++)         if (s[i] ==  0 ) {           f = 1;           if (i >= n / 2)             cout << 1 <<     << i + 1 <<     << 1 <<     << i << endl;           else             cout << i + 1 <<     << n <<     << i + 2 <<     << n << endl;           break;         }       if (!f) cout << 1 <<     << n - 1 <<     << 2 <<     << n << endl;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( -O2 )   using namespace std;   void err(istream_iterator<string> it) { cerr << endl; }   template <typename T, typename... Args>   void err(istream_iterator<string> it, T a, Args... args) {     cerr << *it <<   =   << a <<   t ;     err(++it, args...);   }   template <typename T1, typename T2>   ostream& operator<<(ostream& c, pair<T1, T2>& v) {     c <<  (  << v.F <<  ,  << v.S <<  ) ;     return c;   }   template <template <class...> class TT, class... T>   ostream& operator<<(ostream& out, TT<T...>& c) {     out <<  {  ;     for (auto& x : c) out << x <<    ;     out <<  } ;     return out;   }   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   const int N = 200005;   long long xx[N];   void solve() {     long long n, x, y;     cin >> n;     long long ans = n;     for (long long i = 1; i <= n - 1; i++) {       cin >> x >> y;       ans = (((ans * (++xx[x])) % 998244353) * (++xx[y])) % 998244353;     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   static const double EPS = 1e-9;   int ROUND(double x) { return (int)(x + 0.5); }   bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }   bool ISEQUAL(double x, double y) {     return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y)));   }   double SQSUM(double x, double y) { return x * x + y * y; }   template <class T>   bool INRANGE(T x, T a, T b) {     return a <= x && x <= b;   }   long long get(long long tmp) {     long long a = 0;     long long b = 0;     long long base = 1;     while (tmp) {       a += base * (tmp % 10);       b += base * (9 - (tmp % 10));       tmp /= 10;       base *= 10;     }     long long c = a * b;     return c;   }   int main() {     int tmp1, tmp2;     scanf( %d %d  , &tmp1, &tmp2);     long long l = tmp1, r = tmp2;     vector<long long> res;     res.push_back(get(l));     res.push_back(get(r));     for (long long i = 5; i <= r; i *= 10) {       if (INRANGE(i, l, r)) {         res.push_back(get(i));       }     }     sort(res.rbegin(), res.rend());     cout << res[0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 3e5 + 5, mod = 1e8, inf = 1e9 + 5;   long double pi = acos(-1);   long long n, m, k, dp[N][15], a[N];   int main() {     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) cin >> a[i];     long long maxans = 0;     for (int i = 0; i <= m; i++) {       dp[0][i] = -1e12;     }     for (int i = 1; i <= n; i++) {       long long ans = 0;       for (int j = 1; j <= m; j++) {         if (j == 1) {           dp[i][j] = max(a[i] - k, dp[i - 1][m] + a[i] - k);         } else           dp[i][j] = dp[i - 1][j - 1] + a[i];         maxans = max(maxans, dp[i][j]);       }     }     cout << maxans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   long long a[maxn], x[maxn], y[maxn], c[7], d[7], ans;   int n, m;   bool cmp(long long x, long long y) { return x > y; }   void sol(int pos, int num, int flag) {     memset(d, 0, sizeof(d));     if (flag) {       for (int i = 1; i <= pos; i++) {         long long w = y[i];         for (int j = 0; j < 4 - num; j++) {           w -= a[(c[j] - 1) * m + i];         }         d[num] = w;         sort(d, d + num + 1, cmp);       }       long long ac = 0;       for (int i = 0; i < num; i++) {         ac += d[i];       }       for (int j = 0; j < 4 - num; j++) {         ac += x[c[j]];       }       ans = max(ans, ac);     } else {       for (int i = 1; i <= pos; i++) {         long long w = x[i];         for (int j = 0; j < 4 - num; j++) {           w -= a[(i - 1) * m + c[j]];         }         d[num] = w;         sort(d, d + num + 1, cmp);       }       long long ac = 0;       for (int i = 0; i < num; i++) {         ac += d[i];       }       for (int j = 0; j < 4 - num; j++) {         ac += y[c[j]];       }       ans = max(ans, ac);     }   }   int main() {     scanf( %d%d , &n, &m);     long long sum = 0;     for (int i = 1; i <= n * m; i++) {       scanf( %lld , &a[i]);       sum += a[i];     }     memset(d, 0, sizeof(d));     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         x[i] += a[(i - 1) * m + j];       }       d[4] = x[i];       sort(d, d + 5, cmp);     }     for (int i = 0; i < 4; i++) {       ans += d[i];     }     long long xxx = 0;     memset(d, 0, sizeof(d));     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         y[i] += a[(j - 1) * m + i];       }       d[4] = y[i];       sort(d, d + 5, cmp);     }     for (int i = 0; i < 4; i++) {       xxx += d[i];     }     ans = max(xxx, ans);     if (n <= 4 || m <= 4) {       printf( %lld n , sum);       return 0;     }     for (int i = 1; i <= n; i++) {       c[0] = i;       sol(m, 3, 1);     }     for (int i = 1; i <= m; i++) {       c[0] = i;       sol(n, 3, 0);     }     if (n > m) {       for (int i = 1; i <= m; i++) {         for (int j = i + 1; j <= m; j++) {           c[0] = i;           c[1] = j;           sol(n, 2, 0);         }       }     } else {       for (int i = 1; i <= n; i++) {         for (int j = i + 1; j <= n; j++) {           c[0] = i;           c[1] = j;           sol(m, 2, 1);         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void umax(T &x, T y) {     if (y > x) x = y;   }   template <class T>   inline void umin(T &x, T y) {     if (y < x) x = y;   }   const int N = 2e5 + 5, B = 0x7fffffff;   struct edge {     int u, v, l, r;   } a[N];   vector<pair<int, pair<int, int>>> g[N];   int n, m;   int ans;   bool bfs(int x, int ql, int qr) {     bool vis[N];     memset(vis, 0, sizeof vis);     queue<int> Q;     Q.push(x);     vis[x] = 1;     while (!Q.empty()) {       int fr = Q.front();       Q.pop();       for (pair<int, pair<int, int>> ss : g[fr]) {         if (vis[ss.first] != 1 && ss.second.first <= ql &&             qr <= ss.second.second) {           vis[ss.first] = 1;           Q.push(ss.first);         }       }     }     return vis[n];   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= m; i++) {       scanf( %d%d%d%d , &a[i].u, &a[i].v, &a[i].l, &a[i].r);       int x = a[i].u;       int y = a[i].v;       int l = a[i].l;       int r = a[i].r;       g[x].push_back({y, {l, r}});       g[y].push_back({x, {l, r}});     }     for (int i = 1; i <= m; i++) {       int l = 1, r = 1e9, ann = -1;       while (l <= r) {         int mid = (l + r) >> 1;         if (bfs(1, a[i].l, mid))           l = mid + 1, ann = mid;         else           r = mid - 1;       }       if (ann != -1) umax(ans, (ann - a[i].l) + 1);     }     if (ans == 0)       puts( Nice work, Dima! );     else       printf( %d , ans);     return !!0;   }