malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > cpu(3);   vector<vector<int> > g(201);   int vs[201];   bool mission[201];   int start[3];   int ans = 1000000000;   int main() {     int n, startms;     cin >> n;     start[0] = -1;     start[1] = -1;     start[2] = -1;     for (int i = 0; i < n; ++i) {       int comp;       cin >> comp;       cpu[comp - 1].push_back(i);       vs[i] = comp - 1;     }     for (int i = 0; i < n; ++i) {       int tmp;       cin >> tmp;       if (tmp == 0) {         start[vs[i]] = i;       }       for (int j = 0; j < tmp; ++j) {         int v;         cin >> v;         g[i].push_back(v - 1);       }     }     for (int u = 0; u < 3; ++u) {       if (start[u] == -1) continue;       for (int j = 0; j < n; ++j) mission[j] = false;       int pc = u;       mission[start[u]] = true;       int ost = n - 1;       int hour = 1;       while (ost != 0) {         for (int i = 0; i < cpu[pc].size(); ++i) {           int ms = cpu[pc][i];           if (mission[ms] == true) {             continue;           }           bool fl = true;           for (int j = 0; j < g[ms].size(); ++j) {             if (mission[g[ms][j]] == false) {               fl = false;               break;             }           }           if (fl == true) {             mission[ms] = true;             ost--;             hour++;             i = -1;           }         }         if (ost != 0) {           hour++;           if (pc == 0) {             pc = 1;             continue;           }           if (pc == 1) {             pc = 2;             continue;           }           if (pc == 2) {             pc = 0;             continue;           }         }       }       ans = min(hour, ans);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long const N = 5e5;   long long a[N];   void init_code() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);   }   void solve() {     long long n, d, e;     cin >> n >> d >> e;     long long md = n / d;     long long me = n / (5 * e);     long long ans = n;     for (long long i = 0; i * 5 * e <= n; i++) {       ans = min(ans, (n - i * 5 * e) % d);     }     cout << ans <<   n ;   }   signed main() {     init_code();     long long t = 1;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9;   void process() {     vector<vector<char> > d(8, vector<char>(8));     int x1 = 8, y1 = 8, x2 = 8, y2 = 8;     vector<vector<pair<int, int> > > steps(         8, vector<pair<int, int> >(8, make_pair(-INF, -INF)));     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         cin >> d[i][j];         if (d[i][j] ==  K )           if (x1 == 8) {             x1 = j;             y1 = i;           } else {             x2 = j;             y2 = i;           }       }     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++) {         if (abs(x1 - j) % 4 + abs(y1 - i) % 4 == 0) steps[i][j].first = 0;         if (abs(x1 - j) % 4 == 2 && abs(y1 - i) % 4 == 2) steps[i][j].first = 1;         if (abs(x2 - j) % 4 + abs(y2 - i) % 4 == 0) steps[i][j].second = 0;         if (abs(x2 - j) % 4 == 2 && abs(y2 - i) % 4 == 2) steps[i][j].second = 1;       }     for (int i = 0; i < 8; i++)       for (int j = 0; j < 8; j++)         if (steps[i][j].first == steps[i][j].second && steps[i][j].first >= 0 &&             d[i][j] !=  # ) {           cout <<  YES  << endl;           return;         }     cout <<  NO  << endl;     return;   }   int main() {     int n;     cin >> n;     for (int i = 0; i < n; i++) process();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     long long arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     int c = 2;     int max = 2;     for (int i = 2; i < n; i++) {       if (arr[i] == (arr[i - 2] + arr[i - 1])) {         c++;         if (c > max) {           max = c;         }       } else         c = 2;     }     if (n == 1)       cout <<  1 ;     else       cout << max;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, n, m, p;   int a[33], c[100010][33];   int fac[100010], inv[100010];   int l, r, L, R, len, Ans;   inline int Pow(int x, int y) {     int Ans = 1;     for (; y; y >>= 1, x = 1ll * x * x % p)       if (y & 1) Ans = 1ll * Ans * x % p;     return Ans;   }   inline void Init() {     int t = p;     for (int i = 2; i * i <= t; i++)       if (!(t % i)) {         a[++m] = i;         t /= i;         while (!(t % i)) t /= i;       }     if (t > 1) a[++m] = t;     int phi = p;     for (int i = 1; i <= m; i++) phi = phi / a[i] * (a[i] - 1);     fac[0] = inv[0] = 1;     for (int i = 1; i < 100010; i++) {       int x = i;       for (int j = 1; j <= m; j++) {         c[i][j] = c[i - 1][j];         while (!(x % a[j])) x /= a[j], c[i][j]++;       }       fac[i] = 1ll * fac[i - 1] * x % p;       inv[i] = Pow(fac[i], phi - 1);     }   }   inline int Calc(int x, int y) {     if (x < y || y < 0) return 0;     if (!y) return 1;     int Ans = 1ll * fac[x] * inv[y] % p * inv[x - y] % p;     for (int i = 1; i <= m; i++)       Ans = 1ll * Ans * Pow(a[i], c[x][i] - c[y][i] - c[x - y][i]) % p;     return Ans;   }   int main() {     scanf( %d%d%d%d , &n, &p, &l, &r);     Init();     for (i = 0; i <= n; i++)       len = n - i, Ans = (Ans + 1ll *                                     (Calc(len, (len - l >> 1)) -                                      Calc(len, (min(r, len) + len >> 1) + 1)) *                                     Calc(n, i)) %                          p;     if (Ans < 0) Ans += p;     cout << Ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 6, inf = 2e9 + 7;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int tc;     cin >> tc;     while (tc--) {       int n, x, y, d;       cin >> n >> x >> y >> d;       if (x == y)         cout <<  0 n ;       else if (abs(y - x) % d == 0)         cout << abs(y - x) / d <<   n ;       else {         int a = (x - 1) / d;         if ((x - 1) % d != 0) a++;         int t = n - x;         int b = t / d;         if (t % d != 0) b++;         if ((y - 1) % d == 0)           a = a + (y - 1) / d;         else           a = inf;         if ((n - y) % d == 0)           b = b + (n - y) / d;         else           b = inf;         a = min(a, b);         if (a == inf) a = -1;         cout << a <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (a % b != 0) return gcd(b, a % b);     return b;   }   int main() {     int n, x = 0, y = 0;     cin >> n;     string a, b;     cin >> a >> b;     int k = a.size() * b.size() / gcd(a.size(), b.size());     for (int i = 0; i < k; i++) {       int t1 = i % a.size(), t2 = i % b.size();       if (a[t1] != b[t2]) {         if ((a[t1] > b[t2] && a[t1] - b[t2] != 3) || b[t2] - a[t1] == 3)           x++;         else           y++;       }     }     x *= n / k;     y *= n / k;     n %= k;     for (int i = 0; i < n; i++) {       int t1 = i % a.size(), t2 = i % b.size();       if (a[t1] != b[t2]) {         if ((a[t1] > b[t2] && a[t1] - b[t2] != 3) || b[t2] - a[t1] == 3)           x++;         else           y++;       }     }     cout << x <<     << y;   }
#include <bits/stdc++.h>   using namespace std;   typedef struct st {     int a;     string b;   } st;   bool func(st x, st y) {     if (x.a == y.a)       return x.b > y.b;     else       return x.a > y.a;   }   int main() {     string a;     cin >> a;     int sum1 = 0;     for (int i = 0; i < a.size(); i++) sum1 += a[i] - 48;     if (a.size() == 1) {       cout << a;       return 0;     }     vector<st> v(1);     v[0].a = sum1;     v[0].b = a;     for (int i = a.size() - 2; i >= 0; i--) {       string s;       for (int j = 0; j <= i; j++) s += a[j];       s[s.size() - 1]--;       for (int j = i + 1; j < a.size(); j++) {         char f = 48 + 9;         s += f;       }       int sum2 = 0;       for (int j = 0; j < s.size(); j++) sum2 += s[j] - 48;       st x;       x.a = sum2;       x.b = s;       v.push_back(x);     }     sort(v.begin(), v.end(), func);     if (v[0].b[0] !=  0 )       cout << v[0].b;     else       for (int i = 1; i < v[0].b.size(); i++) cout << v[0].b[i];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   const int mod = 1e9 + 7;   const int inf = 1e9 + 7;   double dist(double a, double b, double x, double y) {     return sqrt((x - a) * (x - a) + (y - b) * (y - b));   }   int n, i;   double px, py, a1, a2, b1, b2, c1, c2, x1, x2, asfdasgas, y2, t, x, y,       r1 = 2e9, r2, dotx, doty;   double A[N], B[N];   int main() {     scanf( %d %lf %lf , &n, &px, &py);     for (i = 1; i <= n; i++) scanf( %lf %lf , A + i, B + i);     A[n + 1] = A[1];     B[n + 1] = B[1];     for (i = 1; i <= n; i++) {       x1 = A[i];       x2 = A[i + 1];       asfdasgas = B[i];       y2 = B[i + 1];       a1 = y2 - asfdasgas;       b1 = x1 - x2;       c1 = -a1 * x1 - b1 * asfdasgas;       a2 = x2 - x1;       b2 = y2 - asfdasgas;       c2 = -a2 * px - b2 * py;       y = (a2 * c1 - a1 * c2) / (a1 * b2 - b1 * a2);       x = (b1 * c2 - b2 * c1) / (b2 * a1 - b1 * a2);       if (x >= min(x1, x2) and x <= max(x1, x2) and y >= min(asfdasgas, y2) and           y <= max(asfdasgas, y2)) {         t = dist(px, py, x, y);         if (t <= r1) {           r1 = t;           dotx = x;           doty = y;         }       } else {         t = dist(px, py, x1, asfdasgas);         if (t <= r1) {           r1 = t;           dotx = x1;           doty = asfdasgas;         }         t = dist(px, py, x2, y2);         if (t <= r1) {           r1 = t;           dotx = x2;           doty = y2;         }       }     }     for (i = 1; i <= n; i++) r2 = max(r2, dist(px, py, A[i], B[i]));     printf( %.8lf , acos(-1) * r2 * r2 - acos(-1) * r1 * r1);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n;     cin >> m >> n;     double ans = m;     double i = 1;     while (1) {       if (i >= m) break;       double j = (m - i) / m;       double k = 1;       int q = n;       while (q != 0) {         if (q & 1 == 1) k *= j;         q = q >> 1;         j *= j;       }       if (k <= 0.00000001) break;       ans -= k;       i++;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   inline void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       x = x * 10 + c -  0 ;       c = getchar();     }     x *= f;   }   const int N = 350, mo = 1e9 + 7;   int n, f[N][N], len, A[N], fac[N], ifac[N], qz[N];   map<int, int> Map;   inline void exgcd(int a, int b, int &x, int &y) {     if (!b) {       x = 1;       y = 0;       return;     }     exgcd(b, a % b, y, x);     y -= a / b * x;   }   inline int inv(int a) {     int x, y;     exgcd(a, mo, x, y);     return x >= 0 ? x : x + mo;   }   inline int C(int n, int m) {     if (m < 0 || m > n) return 0;     return 1LL * fac[n] * ifac[m] % mo * ifac[n - m] % mo;   }   inline void add(int &a, int b) { a = a + b < mo ? a + b : a + b - mo; }   int main() {     read(n);     for (register int i = 1; i <= n; i++) {       int x;       read(x);       for (int j = 2; j * j <= x; j++) {         while (x % (j * j) == 0) x /= j * j;       }       Map[x]++;     }     while (!Map.empty()) {       A[++len] = (*Map.begin()).second;       qz[len] = qz[len - 1] + A[len];       Map.erase(Map.begin());     }     fac[0] = 1;     for (register int i = 1; i <= n; i++) fac[i] = 1LL * fac[i - 1] * i % mo;     ifac[n] = inv(fac[n]);     for (register int i = n - 1; i >= 0; i--)       ifac[i] = 1LL * ifac[i + 1] * (i + 1) % mo;     f[0][0] = 1;     for (register int i = 0; i <= len - 1; i++)       for (register int j = 0; j <= n + 1; j++)         if (f[i][j]) {           int now = f[i][j];           int red = j, blue = qz[i] - j + 1;           for (register int a = 0; a <= blue; a++)             for (register int b = 0; b <= red; b++)               if (a + b <= A[i + 1])                 add(f[i + 1][j - b + A[i + 1] - a - b],                     1LL * now * C(blue, a) % mo * C(red, b) % mo *                         C(A[i + 1] - 1, a + b - 1) % mo * fac[A[i + 1]] % mo);         }     cout << f[len][0];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string a;     cin >> a;     for (int i = 0; i < int(a.size() - 2); ++i) {       char x = a[i], y = a[i + 1], z = a[i + 2];       if (x !=  .  && y !=  .  && z !=  . )         if (x != y && x != z && y != z) {           cout <<  Yes  << endl;           return 0;         }     }     cout <<  No  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long i, j, k;     int n;     cin >> n;     vector<int> arr(n);     int f, l;     f = 1;     l = n;     int sz = 0;     while (sz < n) {       if (sz % 2 == 0) {         arr[sz] = f;         sz++;         f++;       } else {         arr[sz] = l;         sz++;         l--;       }     }     for (auto it : arr) {       cout << it <<    ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; ++i) cin >> a[i];     vector<int> d;     for (int i = 0; i < n; ++i) {       int pos = upper_bound(d.begin(), d.end(), a[i]) - d.begin();       if (pos == d.size())         d.push_back(a[i]);       else         d[pos] = a[i];     }     cout << d.size();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long x;     x = 2;     long long n;     cin >> n;     for (long long i = 1; i <= n; i++) {       long long y = (x / i);       if (y >= i * (i + 1) * (i + 1)) {         throw 1;       }       printf( %I64d n , i * (i + 1) * (i + 1) - y);       x = i * (i + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXp = 100000;   int p, d;   int p10[8];   int dig[8];   bool ip[MAXp];   int num[8];   vector<int> v[6][10][6][MAXp / 100];   int ans = 0;   void init() {     p10[0] = 1;     for (int i = 1; i < 8; i++) p10[i] = p10[i - 1] * 10;     ip[0] = ip[1] = 1;     for (int i = 2; i < MAXp; i++)       if (!ip[i]) {         for (int d = (1), _n = (5); d <= _n; d++)           for (int y = (0), _n = (min(d, 3)); y <= _n; y++)             if (i / p10[d - 1] < 10)               v[d][i / p10[d - 1]][y][i % p10[y]].push_back(i);         if (i < 1000)           for (long long j = i * i; j < MAXp; j += i) ip[j] = 1;       }   }   void bt(int r) {     if (r == 0) {       ans++;       return;     }     vector<int> &f = v[d][dig[r]][d - r - 1][num[r]];     int z = int((f).size());     int c = d - r - 1;     for (int i = 0, _n = (z); i < _n; i++) {       int x = f[i];       for (int j = (1), _n = (r - 1); j <= _n; j++)         num[j] += (x / p10[d - j - 1] % 10) * p10[c];       bt(r - 1);       for (int j = (1), _n = (r - 1); j <= _n; j++)         num[j] -= (x / p10[d - j - 1] % 10) * p10[c];     }   }   int main() {     init();     int ts;     for (cin >> ts; ts--;) {       cin >> p;       int tmp = p;       d = 0;       while (tmp) dig[d++] = tmp % 10, tmp /= 10;       reverse(dig, dig + d);       ans = 0;       bt(d - 1);       cout << ans << endl;     }     {       int _;       cin >> _;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int n, par[N], up[N], h[N], max_h[N];   vector<int> child[N], vec, ans;   void dfs(int v = 0) {     for (int u : child[v]) {       h[u] = max_h[u] = h[v] + 1;       dfs(u);       max_h[v] = max(max_h[v], max_h[u]);     }     sort(child[v].begin(), child[v].end(),          [](int u, int v) { return max_h[u] < max_h[v]; });   }   void bamboo(int v = 0) {     if (v) up[v] = vec.back();     vec.push_back(v);     for (int u : child[v]) bamboo(u);   }   void solve(int v = 0) {     while (v && up[v] != par[v]) {       ans.push_back(v);       up[v] = up[up[v]];     }     for (int u : child[v]) solve(u);   }   int main() {     ios::sync_with_stdio(false), cin.tie(0);     cin >> n;     for (int i = 1; i < n; i++) {       cin >> par[i];       child[par[i]].push_back(i);     }     dfs();     bamboo();     for (int v : vec) cout << v <<    ;     cout <<   n ;     solve();     cout << ans.size() <<   n ;     for (int u : ans) cout << u <<    ;   }
#include <bits/stdc++.h>   int main() {     int mem, arr[5001], i, tri = 0;     scanf( %d , &mem);     for (i = 1; i <= mem; i++) {       scanf( %d , &arr[i]);     }     for (i = 1; i <= mem; i++) {       if (i == arr[arr[arr[i]]]) {         tri = 1;       }     }     if (tri == 1) {       printf( YES n );     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long n, k, bottom, top;     cin >> n >> k;     bottom = 1;     top = n;     for (long i = 0; i < k - 1; i++) {       if (i % 2 == 0) {         cout << bottom <<    ;         bottom++;       } else {         cout << top <<    ;         top--;       }     }     long sum, val;     if ((k - 1) % 2 == 0) {       val = bottom;       sum = 1;     } else {       val = top;       sum = -1;     }     for (long i = 0; i <= n - k; i++) {       cout << val <<    ;       val += sum;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3050;   int n, p, s;   int sump[N], sum[N];   struct Student {     int a, b, id;     void input() { scanf( %d%d , &a, &b); }     bool operator<(const Student &student) const {       return b - a < student.b - student.a;     }   } data[N];   void del() {     sort(data + 1, data + n + 1);     sum[0] = 0;     sump[0] = 0;     for (int i = 1; i <= n; i++) {       sump[i] = sump[i - 1] + data[i].a;       sum[i] = sum[i - 1] + data[i].b - data[i].a;     }     int id = -1, ans = 0;     for (int i = 1; i <= n; i++) {       int cur;       if (i <= p)         cur = sump[n] + sum[n] - sum[p + 1] - data[i].a;       else         cur = sump[n] + sum[n] - sum[p] - data[i].b;       if (cur > ans) {         ans = cur;         id = i;       }     }     swap(data[id], data[n]);     n--;   }   void solve() {     for (int i = 1; i <= n; i++) scanf( %d , &data[i].a);     for (int i = 1; i <= n; i++) scanf( %d , &data[i].b);     for (int i = 1; i <= n; i++) data[i].id = i;     int k = n - p - s;     for (int i = 0; i < k; i++) del();     sort(data + 1, data + n + 1);     int ans = 0;     for (int i = 1; i <= p; i++) ans += data[i].a;     for (int i = p + 1; i <= n; i++) ans += data[i].b;     printf( %d n , ans);     for (int i = 1; i <= p; i++) printf( %d  , data[i].id);     puts(  );     for (int i = p + 1; i <= n; i++) printf( %d  , data[i].id);     puts(  );   }   int main() {     while (scanf( %d%d%d , &n, &p, &s) != EOF) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1e9;   const int MOD = 1e6 + 3;   const int N = 1e2 + 5;   int n, wid, hei;   long long f[N], phei[N];   struct matrix {     long long a[N][N];     matrix() { memset(a, 0, sizeof(a)); }   } base, cur;   matrix operator*(matrix a, matrix b) {     matrix ans;     for (auto i = (0); i <= (wid); i++)       for (auto j = (0); j <= (wid); j++)         for (auto k = (0); k <= (wid); k++)           ans.a[i][j] = (ans.a[i][j] + a.a[i][k] * b.a[k][j]) % MOD;     return ans;   }   void prepare() {     cin >> n >> wid >> hei;     phei[0] = 1;     for (auto i = (1); i <= (wid); i++) phei[i] = phei[i - 1] * hei % MOD;     f[0] = 1;     for (auto i = (1); i <= (wid); i++)       for (int j = 1; j <= min(i, wid); j++)         f[i] = (f[i] + f[i - j] * phei[j - 1]) % MOD;     for (auto i = (1); i <= (wid); i++) base.a[i][i - 1] = 1;     for (auto i = (0); i <= (wid); i++) base.a[i][wid] = phei[wid - i];   }   long long solve() {     n++;     if (n <= wid) return f[n];     n -= wid;     for (auto i = (0); i <= (wid); i++) cur.a[i][i] = 1;     while (n) {       if (n & 1) cur = cur * base;       base = base * base;       n >>= 1;     }     long long ans = 0;     for (auto i = (0); i <= (wid); i++) ans = (ans + f[i] * cur.a[i][wid]) % MOD;     return ans;   }   int main() {     prepare();     cout << solve();   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     cin >> s;     int cnt = 0;     int len = s.length();     for (int i = 0; i < len; i++) {       if (s.at(i) ==  a ) cnt++;     }     int ltr = len - cnt;     while (ltr >= cnt) {       ltr--;       len--;     }     cout << len;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int P = 1e9 + 7;   const int inf = 1e9;   const long long Inf = 1e15;   inline int IN() {     char ch = getchar();     int x = 0, f = 0;     while (ch <  0  || ch >  9 ) ch = getchar(), f = (ch ==  - );     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch - 48;       ch = getchar();     }     return f ? (-x) : x;   }   inline int Pow(int x, int y, int p) {     int an = 1;     for (; y; y >>= 1, x = (long long)x * x % p)       if (y & 1) an = (long long)an * x % p;     return an;   }   void renew(int &x, int y) {     x += y;     if (x < 0)       x += P;     else if (x >= P)       x -= P;   }   void setIO(string a) {     freopen((a +  .in ).c_str(),  r , stdin);     freopen((a +  .out ).c_str(),  w , stdout);   }   template <typename T>   inline void chkmin(T &a, const T &b) {     if (a > b) a = b;   }   template <typename T>   inline void chkmax(T &a, const T &b) {     if (a < b) a = b;   }   int n, k;   int dp[1000005], g[1000005], fac[1000005], inv[1000005];   int main() {     scanf( %d%d , &n, &k);     fac[0] = 1;     for (int i = (int)1; i <= (int)n; i++) fac[i] = (long long)fac[i - 1] * i % P;     inv[0] = inv[1] = 1;     for (int i = (int)2; i <= (int)n; i++)       inv[i] = (long long)inv[P % i] * (P - P / i) % P;     for (int i = (int)2; i <= (int)n; i++)       inv[i] = (long long)inv[i - 1] * inv[i] % P;     dp[1] = dp[0] = 1;     for (int i = (int)2; i <= (int)k; i++) dp[i] = (long long)dp[i - 1] * i % P;     for (int i = (int)1; i <= (int)k; i++)       g[i] = (g[i - 1] + (long long)inv[i] * dp[i]) % P;     for (int i = (int)k + 1; i <= (int)n; i++) {       dp[i] = (g[i - 1] + P - g[i - k - 1]) % P;       dp[i] = (long long)dp[i] * fac[i - 1] % P;       g[i] = (g[i - 1] + (long long)inv[i] * dp[i]) % P;     }     int ans = 0;     for (int i = (int)0; i <= (int)n - 1; i++)       ans = (ans + (long long)dp[i] * fac[n - 1] % P * inv[i]) % P;     ans = (0LL + fac[n] - ans) % P;     ans = (ans + P) % P;     printf( %d n , ans);     return 0;   }