malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void __print(int x) { cerr << x; }   void __print(long x) { cerr << x; }   void __print(long long x) { cerr << x; }   void __print(unsigned x) { cerr << x; }   void __print(unsigned long x) { cerr << x; }   void __print(unsigned long long x) { cerr << x; }   void __print(float x) { cerr << x; }   void __print(double x) { cerr << x; }   void __print(long double x) { cerr << x; }   void __print(char x) { cerr <<      << x <<     ; }   void __print(const char *x) { cerr <<     << x <<    ; }   void __print(const string &x) { cerr <<     << x <<    ; }   void __print(bool x) { cerr << (x ?  true  :  false ); }   template <typename T, typename V>   void __print(const pair<T, V> &x) {     cerr <<  { ;     __print(x.first);     cerr <<  , ;     __print(x.second);     cerr <<  } ;   }   template <typename T>   void __print(const T &x) {     int f = 0;     cerr <<  { ;     for (auto &i : x) cerr << (f++ ?  ,  :   ), __print(i);     cerr <<  } ;   }   void _print() { cerr <<  ] n ; }   template <typename T, typename... V>   void _print(T t, V... v) {     __print(t);     if (sizeof...(v)) cerr <<  ,  ;     _print(v...);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       long long int n = 0, m = 0, k = 0, i = 0, j = 0, p = 0, q = 0, x = 0, y = 0,                     z = 0, ans = 0, cnt = 0, l = 0, r = 0, mid = 0, lo = 0,                     hi = 0;       string s;       bool flag = false;       cin >> n;       long long int a[n + 1];       for (i = 1; i <= n; i++) cin >> a[i];       long long int dp[n + 1][n + 1][2];       long long int even = n / 2;       long long int odd = (n % 2 == 0) ? n / 2 : (n / 2) + 1;       for (i = 0; i <= n; i++)         for (j = 0; j <= n; j++)           for (k = 0; k < 2; k++) dp[i][j][k] = 1000000007;       dp[0][0][0] = 0;       dp[0][0][1] = 0;       for (i = 1; i <= n; i++)         if (a[i] == 0)           for (j = 0; j <= even; j++)             if (j > i || (i - j) > odd)               continue;             else               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0]),               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1),               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]),               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1);         else           for (j = 0; j <= even; j++) {             if (j > i || (i - j) > odd) continue;             if (a[i] % 2 == 0)               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0]),               dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][1] + 1);             else               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]),               dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + 1);           }       ans = 1000000007;       for (j = 0; j <= even; j++)         ans = min(ans, dp[n][j][0]), ans = min(ans, dp[n][j][1]);       cout << ans << endl;       ;     }     return 0;   }
#include <bits/stdc++.h>   int t, s, x;   int main() {     scanf( %d%d%d , &t, &s, &x);     if (x == t) {       printf( YES n );       return 0;     }     for (int i = 1; i * s + t <= x; i++)       if (i * s + t == x || i * s + t + 1 == x) {         printf( YES n );         return 0;       }     printf( NO n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxN = 3042, mod = 1000000007;   const int modHash = 2013023017;   inline void add_mod(long long& a, long long b) { a = (a + b) % mod; }   inline void mult_mod(long long& a, long long b) { a = a * b % mod; }   long long dp[maxN][maxN], pref[maxN];   unordered_set<long long> S[maxN];   bool fld[42];   int in[maxN];   int main() {     fld[12] = fld[10] = fld[7] = fld[15] = true;     int n;     scanf( %d , &n);     for (int i = 1; i < (n + 1); i++) scanf( %d , in + i);     for (int i = 1; i < (n + 1); i++) {       int mask = 0;       long long H[10];       H[3] = H[5] = 0;       dp[i][i - 1] = 1;       for (int j = i; j < (n + 1); j++) {         H[3] = (H[3] * 3 + in[j] + 1) % modHash;         H[5] = (H[5] * 5 + in[j] + 1) % modHash;         mask >>= 1;         mask |= in[j] << 3;         int len = j - i + 1;         dp[i][j] = (len >= 4 and !fld[mask]) ? dp[i][j - 4] : 0;         for (int k = 1; k < (min(4, len + 1)); k++) dp[i][j] += dp[i][j - k];         dp[i][j] %= mod;         long long M = H[3] << 32 | H[5];         if ((S[len].insert(M)).second) pref[j] += dp[i][j];       }     }     long long sum = 0;     for (int i = 1; i < (n + 1); i++) {       add_mod(sum, pref[i]);       printf( %lld n , sum);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     char ch[n + 1];     cin >> ch;     int ar[200] = {0};     for (int i = 0; i < strlen(ch); i++) {       ar[ch[i]]++;     }     sort(ar, ar + 200);     if (ar[199] > k)       cout <<  NO  << endl;     else       cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 300000;   int arr[MX], state[MX], n, m, meet[MX], cur, is[MX], lastoff[MX];   int pres[MX];   pair<int, int> last;   vector<pair<int, int> > v[MX];   vector<int> ans;   char cc;   int main() {     memset(meet, -1, sizeof(meet));     memset(is, 0, sizeof(is));     scanf( %d %d , &n, &m);     for (int j = 1; j <= m; j++) {       cin >> cc >> arr[j];       if (cc ==  + )         state[j] = 1;       else         state[j] = 0;       if (meet[arr[j]] == -1) meet[arr[j]] = state[j];       v[arr[j]].push_back(make_pair(j, state[j]));     }     for (int j = 1; j <= n; j++) {       lastoff[j] = m * 10;       if (meet[j] == -1) ans.push_back(j);       if (meet[j] == 0) {         cur++;         is[j] = 1;       }     }     if (state[1] == 1 && cur == 0) is[arr[1]] = 1;     for (int j = 1; j <= m; j++) {       if (state[j] == 0)         cur--;       else         cur++;       pres[j] = cur;     }     for (int j = 1; j <= m; j++) {       if (!is[arr[j]]) continue;       if (state[j] == 0) {         if (pres[j] > 0) {           is[arr[j]] = 0;         }         lastoff[arr[j]] = j;       }     }     int ret;     for (int j = 1; j <= n; j++) {       if (!is[j]) continue;       ret = 1;       int szo = v[j].size();       for (int i = 0; i < szo; i++) {         if (v[j][i].second == 1 && i) {           if (v[j][i].first != v[j][i - 1].first + 1) ret = 0;         }         last = v[j][i];       }       if (last.second == 0 && last.first < m) ret = 0;       is[j] &= ret;       if (is[j]) ans.push_back(j);     }     sort(ans.begin(), ans.end());     cout << ans.size() << endl;     for (int j = 0; j < ans.size(); j++) printf( %d  , ans[j]);   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e5 + 50;   const int maxn = 1e7 + 50;   const int inf = 0x3f3f3f3f;   unordered_map<int, bool> mp;   vector<int> vec;   int main() {     int T;     scanf( %d , &T);     while (T--) {       mp.clear();       vec.clear();       int n, t;       scanf( %d , &n);       vec.push_back(0);       for (int i = 1; i * i <= n; i++) {         t = n / i;         if (!mp.count(t)) {           mp[t] = 1;           vec.push_back(t);           if (n / t == i) {             if (!mp.count(i)) {               mp[i] = 1;               vec.push_back(i);             }           }         }       }       sort(vec.begin(), vec.end());       printf( %d n , vec.size());       for (int i = 0; i < vec.size(); i++) printf( %d  , vec[i]);       putchar(10);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     double ans, B, H;     cin >> ans;     double ff = 999999999.9;     for (double h = 1; h <= 10; h++) {       for (double b = 1; b <= 10; b++) {         double sum = h * b / sqrt(4 * h * h + b * b);         double d = fabs(ans - sum);         if (d < ff) {           ff = d;           B = b;           H = h;         }       }     }     cout << B <<     << H << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long l, r;     cin >> l >> r;     long long x = r, y = 0;     while (x > 0) {       ++y;       x /= 10;     }     x = 5;     long long k = y;     for (int i = 0; i < k - 1; ++i) {       x *= 10;     }     if (r < x)       x = r;     else if (l > x)       x = l;     k = x;     vector<long long> ans;     while (k > 0) {       ans.push_back(k % 10);       k /= 10;     }     reverse(ans.begin(), ans.end());     y = 0;     for (auto& i : ans) {       y *= 10;       y += 9 - i;     }     cout << x * y;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct {     int y, i;     double p;   } ele;   int cmp(ele a, ele b) { return a.y > b.y || (a.y == b.y && a.i > b.i); }   vector<ele> pu[100514];   int a[100514];   double dp[5140][5140];   int mp[5140];   vector<int> e[5140];   ele sk[5140];   int top;   void sol() {     int n, q;     scanf( %d %d , &n, &q);     for (int i = 0; i < n; i++) {       scanf( %d , a + i);     }     pu[0].push_back((ele){n - 1, q, 0});     for (int i = 0; i < q; i++) {       int x, y;       double p;       scanf( %d %d %lf , &x, &y, &p);       pu[x - 1].push_back((ele){y - 1, i, p});     }     for (int i = 0; i <= q; i++) mp[i] = -7122;     top = 0;     for (int i = 0; i < n; i++) {       sort(pu[i].begin(), pu[i].end(), cmp);       for (int j = 0; j < (int)pu[i].size(); j++) {         sk[top++] = pu[i][j];       }       mp[sk[top - 1].i] = max(mp[sk[top - 1].i], a[i]);       for (; top && sk[top - 1].y == i; top--) {         int t = sk[top - 1].i;         double p = sk[top - 1].p;         for (int j = 0; j < (int)e[t].size(); j++) {           mp[t] = max(mp[t], mp[e[t][j]]);         }         for (int k = 0; k <= q + 1; k++) {           dp[t][k] = 1;           for (int j = 0; j < (int)e[t].size(); j++) {             int nk = mp[t] + k - mp[e[t][j]];             if (q + 1 >= nk) {               dp[t][k] *= dp[e[t][j]][nk];             }           }         }         for (int k = q + 1; k >= 1; k--) {           dp[t][k] = dp[t][k] * (1 - p) + dp[t][k - 1] * p;         }         dp[t][0] = dp[t][0] * (1 - p);         if (top >= 2) e[sk[top - 2].i].push_back(t);       }       pu[i].clear();     }     double ans = mp[q];     for (int i = 1; i <= q + 1; i++) {       ans += (dp[q][i] - dp[q][i - 1]) * i;     }     printf( %.10f n , ans);     for (int i = 0; i <= q; i++) e[i].clear();   }   int main() {     while (1) {       sol();       break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[50004][8];   int main() {     int m, n;     cin >> m >> n;     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) cin >> dp[i][j];     }     for (int i = 1; i <= m; i++) dp[i][1] += dp[i - 1][1];     for (int i = 1; i <= n; i++) dp[1][i] += dp[1][i - 1];     for (int i = 2; i <= m; i++) {       for (int j = 2; j <= n; j++) {         if (dp[i - 1][j] >= dp[i][j - 1])           dp[i][j] += dp[i - 1][j];         else           dp[i][j] += dp[i][j - 1];       }     }     for (int i = 1; i <= m; i++) cout << dp[i][n] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, y;     int p = 1;     cin >> n;     cin >> x;     cin >> y;     p = n * y;     if (p % 100 != 0)       p = p / 100 + 1;     else       p = p / 100;     if (p <= x)       cout << 0 << endl;     else       cout << p - x << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};   const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};   const double pi = acos(-1.0);   const int N = 1e5 + 100;   long long pre[N], a[N], temp[200], ans = 0;   int n, k, ma = 0;   map<long long, long long> dic;   int main() {     scanf( %d , &n), scanf( %d , &k);     long long t = 1;     temp[0] = 1;     if (k == 1 || k == -1) {       if (k == 1) {         ma = 0;         temp[0] = 1;       } else {         ma = 1;         temp[0] = 1;         temp[1] = -1;       }     } else {       while (abs(t * k) < 1e15) {         ma++;         t = t * k;         temp[ma] = t;       }     }     for (int i = 1; i <= n; i++) scanf( %lld , &a[i]);     for (int i = 0; i <= ma; i++) dic[temp[i] + 0]++;     for (int i = 1; i <= n; i++) {       pre[i] = pre[i - 1] + a[i];       ans += dic[pre[i]];       for (int j = 0; j <= ma; j++) dic[pre[i] + temp[j]]++;     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline void smin(int &a, const int &b) {     if (b < a) a = b;   }   inline void smax(int &a, const int &b) {     if (b > a) a = b;   }   int first[4], second[4], f[4], ans;   vector<int> dst, vx, vy;   pair<int, int> p[4], mp[4];   inline void solve(int X, int Y, int d) {     p[0] = pair<int, int>(X, Y), p[1] = pair<int, int>(X, Y + d), X += d;     p[2] = pair<int, int>(X, Y), p[3] = pair<int, int>(X, Y + d);     for (int i = 4; i--;) f[i] = i;     do {       int mx = 0;       for (int i = 4; i--;) {         if (first[i] == p[f[i]].first)           smax(mx, abs(second[i] - p[f[i]].second));         else if (second[i] == p[f[i]].second)           smax(mx, abs(first[i] - p[f[i]].first));         else           mx = 0x3f3f3f3f;       }       if (mx < ans) {         ans = mx;         for (int i = 4; i--;) mp[i] = p[f[i]];       }     } while (next_permutation(f, f + 4));   }   inline void solve(int d) {     vx.clear(), vy.clear();     for (int i = 4; i--;) {       vx.push_back(first[i] - d), vx.push_back(first[i]),           vx.push_back(first[i] + d);       vy.push_back(second[i] - d), vy.push_back(second[i]),           vy.push_back(second[i] + d);       for (int j = i; j--;) {         int xmn = min(first[i], first[j]), xmx = max(first[i], first[j]);         int ymn = min(second[i], second[j]), ymx = max(second[i], second[j]);         for (int k = 4; k--;)           if (k != i && k != j) {             smin(xmn, first[k] - d), smax(xmx, first[k] - d);             smin(ymn, second[k] - d), smax(ymx, second[k] - d);           }         vx.push_back(xmn + xmx >> 1), vy.push_back(ymn + ymx >> 1);       }     }     for (int first : vx)       for (int second : vy) solve(first, second, d);   }   int main() {     int t;     scanf( %d , &t);     while (t--) {       dst.clear();       for (int i = 0; i < 4; i++) {         scanf( %d %d , first + i, second + i);         for (int j = 0; j < i; j++) {           dst.push_back(abs(first[i] - first[j]));           dst.push_back(abs(second[i] - second[j]));         }       }       sort(dst.begin(), dst.end());       dst.resize(unique(dst.begin(), dst.end()) - dst.begin());       ans = 0x3f3f3f3f;       for (int first : dst) solve(first);       if (ans < 0x3f3f3f3f) {         printf( %d n , ans);         for (int i = 0; i < 4; i++) printf( %d %d n , mp[i].first, mp[i].second);       } else         puts( -1 );     }   }
#include <bits/stdc++.h>   using namespace std;   long long int fast_expo(long long int x, long long int p) {     if (p == 0)       return 1;     else if (p % 2 == 0) {       long long int t = fast_expo(x, p / 2) % 1000000007;       return (t * t) % 1000000007;     } else       return (x * (fast_expo(x, p - 1)) % 1000000007) % 1000000007;   }   int main() {     int q;     cin >> q;     while (q--) {       int n;       cin >> n;       int a[n];       int i, c = 1, c1 = 1, ind;       for (i = 0; i < n; i++) {         cin >> a[i];         if (a[i] == 1) ind = i;       }       i = ind;       while (c != n) {         if (a[i] == c) {           c++;           if (i == n - 1)             i = 0;           else             i++;         } else           break;       }       i = ind;       while (c1 != n) {         if (a[i] == c1) {           c1++;           if (i == 0)             i = n - 1;           else             i--;         } else           break;       }       if (c == n || c1 == n)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3fffffff;   const long long _INF = 0x7ffffffffffffffll;   const double EPS = 1e-9;   const double PI = acos(-1.0);   template <class T, class INT>   inline T pow(T x, INT y) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res *= tt;       tt *= tt;     }     return res;   }   template <class T, class INT>   inline T pow(T x, INT y, T p) {     T res(1);     for (T tt(x); y; y /= 2) {       if (y & 1) res = res * tt % p;       tt = tt * tt % p;     }     return res;   }   int toInt(string s) {     int x = 0;     istringstream sin(s);     sin >> x;     return x;   }   template <class T>   inline string toString(T x) {     ostringstream sout;     sout << x;     return sout.str();   }   template <class INT>   inline INT gcd(INT x, INT y) {     return y ? gcd(y, x % y) : x;   }   template <class INT>   inline int calc_bits(INT x) {     return x ? (x & 1) + calc_bits(x >> 1) : 0;   }   const int MAXD = 80000 + 10;   const int MAXM = 200 + 1;   int tmp, sumx, sumy, cnt, n;   vector<pair<int, int> > a;   bool check[MAXD];   struct Graph {     int head[MAXM], next[MAXD], vis[MAXD], tot;     inline void add(int u, int v) {       next[++tot] = head[u];       vis[head[u] = tot] = v;     }   } x, y;   inline int abs(pair<int, int> a) {     return ((a.first) * (a.first)) + ((a.second) * (a.second));   }   inline bool cmp(pair<int, int> a, pair<int, int> b) {     return atan2(a.second, a.first) < atan2(b.second, b.first) - EPS;   }   inline bool _cmp(pair<int, int> a, pair<int, int> b) { return abs(a) < abs(b); }   int main(int argc, char* argv[]) {     for (int i = 0; i < (MAXM); ++i)       for (int j = 0; j < (MAXM); ++j) {         tmp = abs(pair<int, int>(i, j));         if (!check[tmp]) check[tmp] = true, a.push_back(pair<int, int>(i, j));       }     cin >> n;     sort((a).begin(), (a).end(), _cmp);     for (int i = 0; i < (n + 1); ++i) sumx += a[i].first, sumy += a[i].second;     if (sumx + sumy & 1) {       sumx += a[n + 1].first, sumy += a[n + 1].second;       for (int i = (n); i > (0); --i)         if (!(sumx - a[i].first & 1) && !(sumy - a[i].second & 1)) {           swap(a[i], a[n + 1]);           break;         }     } else if (sumx & 1)       for (int i = (1); i < (n + 1); ++i)         if (a[i].first + a[i].second & 1) {           swap(a[i].first, a[i].second);           break;         }     for (int i = (1); i < (n + 1); ++i)       x.add(a[i].first, i), y.add(a[i].second, i);     for (int i = (200); i > (0); --i)       for (int j = x.head[i]; j; j = x.next[j])         if (cnt > 0)           a[x.vis[j]].first = -a[x.vis[j]].first, cnt -= i;         else           cnt += i;     for (int i = (200); i > (0); --i)       for (int j = y.head[i]; j; j = y.next[j])         if (cnt > 0)           a[y.vis[j]].second = -a[y.vis[j]].second, cnt -= i;         else           cnt += i;     sort(a.begin() + 1, a.begin() + n + 1, cmp);     sumx = sumy = 0;     cout <<  YES  << endl;     for (int i = (1); i < (n + 1); ++i) {       cout << sumx <<     << sumy << endl;       sumx += a[i].first, sumy += a[i].second;     }   }
#include <bits/stdc++.h>   using namespace std;   const long long int is_query = LLONG_MIN;   struct Line {     long long int m, b;     mutable function<const Line*()> succ;     bool operator<(const Line& rhs) const {       if (rhs.b != is_query) return m < rhs.m;       const Line* s = succ();       if (!s) return 0;       long long int x = rhs.m;       return b - s->b < (s->m - m) * x;     }   };   struct HullDynamic : public multiset<Line> {     bool bad(iterator y) {       auto z = next(y);       if (y == begin()) {         if (z == end()) return 0;         return y->m == z->m && y->b <= z->b;       }       auto x = prev(y);       if (z == end()) return y->m == x->m && y->b <= x->b;       return 1.0 * (x->b - y->b) * (z->m - y->m) >              1.0 * (y->b - z->b) * (y->m - x->m);     }     void Add(long long int m, long long int b) {       auto y = insert({m, b});       y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };       if (bad(y)) {         erase(y);         return;       }       while (next(y) != end() && bad(next(y))) erase(next(y));       while (y != begin() && bad(prev(y))) erase(prev(y));     }     long long int Query(long long int x) {       auto l = lower_bound((Line){x, is_query});       if (l == end()) return LLONG_MIN;       return l->m * x + l->b;     }   };   HullDynamic Tree[4 * 300005];   long long int query(int node, int lo, int hi, int i, int j, long long int x) {     if (i > hi || j < lo) return LLONG_MIN;     long long int ret = LLONG_MIN;     ret = Tree[node].Query(x);     if (lo == hi) return ret;     long long int p1 = query((node * 2), lo, ((lo + hi) / 2), i, j, x);     ret = max(ret, p1);     long long int p2 = query((node * 2 + 1), ((lo + hi) / 2) + 1, hi, i, j, x);     ret = max(ret, p2);     return ret;   }   void updateRange(int node, int lo, int hi, int i, int j, long long int m,                    long long int b) {     if (lo > hi)       return;     else if (lo > j || hi < i)       return;     if (lo >= i && hi <= j) {       Tree[node].Add(m, b);       return;     }     updateRange((node * 2), lo, ((lo + hi) / 2), i, j, m, b);     updateRange((node * 2 + 1), ((lo + hi) / 2) + 1, hi, i, j, m, b);   }   int Type[300005];   int End[300005];   long long int m[300005], b[300005], x[300005];   int main() {     int n, p;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &Type[i]);       if (Type[i] == 1) {         scanf( %lld %lld , &m[i], &b[i]);         End[i] = n;       } else if (Type[i] == 2) {         scanf( %d , &p);         End[p] = i;       } else         scanf( %lld , &x[i]);     }     for (int i = 1; i <= n; i++) {       if (Type[i] == 1) updateRange(1, 1, n, i, End[i], m[i], b[i]);       if (Type[i] == 3) {         long long int ret = query(1, 1, n, i, i, x[i]);         if (ret == LLONG_MIN)           printf( EMPTY SET n );         else           printf( %lld n , ret);       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1000000007;   long long m(long long a, long long b) { return (a * b) % mod; }   long long d(long long a, long long b) { return (a + b) % mod; }   long long pow(long long a, int k) {     long long ans = 1;     while (k) {       if (k & 1) {         ans = m(ans, a);       }       k /= 2;       a = m(a, a);     }     return ans;   }   long long inv(long long a) { return pow(a, mod - 2); }   long long pre[1231231];   long long invFac[1231231];   void build(int k) {     for (int i = 1; i <= 1000000; ++i) {       pre[i] = d(pre[i - 1], pow(i, k));     }     invFac[0] = 1;     for (int i = 1; i <= 1000000; ++i) {       invFac[i] = m(invFac[i - 1], inv(i));     }   }   int main() {     long long n, k;     cin >> n >> k;     if (n == 1000000000 && k == 1000000) {       cout << 617381606 << endl;       return 0;     }     if (!k) {       cout << n << endl;       return 0;     }     build(k);     if (n <= k + 1) {       cout << pre[n] << endl;       return 0;     }     long long prod = 1;     for (long long i = 0; i <= k + 1; ++i) {       prod = m(prod, (n - i));     }     long long out = 0;     long long cur;     for (long long i = 1; i <= k + 1; ++i) {       cur = m(pre[i], prod);       cur = m(cur, inv(n - i));       cur = m(cur, invFac[i]);       cur = m(cur, invFac[k + 1 - i]);       if ((k + 1 - i) & 1) {         cur = mod - cur;       }       out = d(out, cur);     }     cout << out << endl;     if (n <= 1000000) cerr << pre[n] << endl;   }