malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int m, n, l, s = 0;     cin >> n >> m >> l;     vector<int> a(n);     vector<int> otvet;     for (int i = 0; i < n; ++i) cin >> a[i];     if (n == 1) {       for (int i = 0; i < m; ++i) {         int x;         cin >> x;         if (x == 0) {           if (a[0] <= l)             otvet.push_back(0);           else             otvet.push_back(1);           continue;         }         int y, z;         cin >> y >> z;         if (a[0] <= l) a[0] += z;       }       for (int i = 0; i < otvet.size(); ++i) cout << otvet[i] << endl;       return 0;     }     int i = 0;     while (i < n) {       if (a[i] <= l) {         ++i;         continue;       }       int j = i;       while (a[j] > l && j < n) {         j++;       }       s++;       i = j;     }     for (int i = 0; i < m; ++i) {       int x;       cin >> x;       if (x == 0) {         otvet.push_back(s);         continue;       }       int y, z;       cin >> y >> z;       y--;       if (a[y] > l) continue;       a[y] += z;       if (a[y] > l) {         if (y > 0 && y < n - 1) {           if (a[y - 1] <= l && a[y + 1] <= l)             s++;           else if (a[y - 1] > l && a[y + 1] > l) {             s--;           }         } else if (y == 0) {           if (a[y + 1] <= l) s++;         } else if (y == n - 1) {           if (a[y - 1] <= l) s++;         }       }     }     for (int i = 0; i < otvet.size(); ++i) cout << otvet[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void io() {     freopen( input.txt ,  r , stdin);     freopen( output.txt ,  w , stdout);   }   long long int a[100001], n, k, pos = 1000000000000000;   map<long long int, long long int> m;   set<long long int> s;   int main() {     cin >> n >> k;     s.clear();     for (long long int i = 0; i < n; i++) {       cin >> a[i];       if (s.size() < k) m[a[i]]++;       s.insert(a[i]);       if (s.size() == k) pos = min(pos, i);     }     if (pos == 1000000000000000) {       cout << -1 <<     << -1 << endl;       return 0;     }     for (long long int i = 0; i < pos + 1; i++) {       m[a[i]]--;       if (m[a[i]] == 0) {         cout << i + 1 <<     << pos + 1 << endl;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     int64_t res1 = 0, res2 = 0, sum = 0;     bool is;     std::cin >> n;     std::vector<int> m(n);     for (int i = 0; i < n; i++) {       std::cin >> m[i];       sum += m[i];     }     is = sum % n != 0;     sum /= n;     for (int i = 0; i < n; i++) {       if (m[i] < sum) {         res1 += sum - m[i];       } else if (is) {         if (m[i] > sum + 1) {           res2 += m[i] - sum - 1;         }       } else {         if (m[i] > sum) {           res2 += m[i] - sum;         }       }     }     std::cout << std::max(res1, res2);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 20009;   int INF = 2e9;   struct edge {     int to, cap, rev;     edge() {}     edge(int tt, int cc, int rr) {       to = tt;       cap = cc;       rev = rr;     }   };   vector<edge> Graph[N];   int level[N];   int iter[N];   void add_edge(int from, int to, int cap) {     Graph[from].push_back(edge(to, cap, Graph[to].size()));     Graph[to].push_back(edge(from, 0, Graph[from].size() - 1));   }   void bfs(int s) {     memset(level, -1, sizeof(level));     queue<int> que;     level[s] = 0;     que.push(s);     while (que.size()) {       int v = que.front();       que.pop();       for (int i = 0; i < Graph[v].size(); i++) {         edge &e = Graph[v][i];         if (e.cap > 0 && level[e.to] < 0) {           level[e.to] = level[v] + 1;           que.push(e.to);         }       }     }   }   int dfs(int v, int t, int f) {     if (v == t) return f;     for (int &i = iter[v]; i < Graph[v].size(); i++) {       edge &e = Graph[v][i];       if (e.cap > 0 && level[v] < level[e.to]) {         int d = dfs(e.to, t, min(f, e.cap));         if (d > 0) {           e.cap -= d;           Graph[e.to][e.rev].cap += d;           return d;         }       }     }     return 0;   }   int max_flow(int s, int t) {     int flow = 0;     while (1) {       bfs(s);       if (level[t] < 0) return flow;       memset(iter, 0, sizeof(iter));       int f;       while ((f = dfs(s, t, INF)) > 0) {         flow += f;       }     }     return flow;   }   int a[105], b[105], res[105][105], SumIn, SumOut;   int main() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = 0; i < n; i++)       scanf( %d , &a[i]), add_edge(0, i + 1, a[i]), SumIn += a[i];     for (int i = 0; i < n; i++)       scanf( %d , &b[i]), add_edge(i + 1 + n, 2 * n + 1, b[i]), SumOut += b[i];     for (int i = 0; i < n; i++) add_edge(i + 1, i + 1 + n, 1e6);     for (int i = 0; i < m; i++) {       int u, v;       scanf( %d%d , &u, &v);       add_edge(u, v + n, 1e6);       add_edge(v, u + n, 1e6);     }     if (SumIn != SumOut || SumIn != max_flow(0, 2 * n + 1))       return 0 * printf( NO n );     printf( YES n );     for (int i = 1; i <= n; i++)       for (auto &e : Graph[i])         if (e.to > n) res[i - 1][e.to - n - 1] = Graph[e.to][e.rev].cap;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) printf( %d  , res[i][j]);       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t;     cin >> t;     while (t--) {       long long int n, i, j;       cin >> n;       long long int arr[n][n];       for (i = 0; i < n; i++) {         string s;         cin >> s;         for (j = 0; j < n; j++) {           long long int temp;           temp = s[j] - 48;           arr[i][j] = temp;         }       }       int flag = 1;       for (i = 0; i < n; i++) {         for (j = 0; j < n; j++) {           if (arr[i][j] == 1) {             if (j != n - 1 && i != n - 1) {               if (arr[i + 1][j] != 1 && arr[i][j + 1] != 1) {                 flag = 0;                 break;               }             }           }         }         if (flag == 0) break;       }       if (flag == 1) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int DX[8] = {1, -1, 0, 0, 1, 1, -1, -1};   const int DY[8] = {0, 0, 1, -1, 1, -1, 1, -1};   const int intmax = 0x7fffffff;   const int mod = 1000000007;   int n, m;   int f[205];   int p[205];   vector<pair<int, int> > op;   int main() {     scanf( %d%d , &n, &m);     int cnt = 0;     for (int i = 0; i < m; i++) {       int nk;       scanf( %d , &nk);       for (int j = 0; j < nk; j++) {         int a;         scanf( %d , &a);         cnt++;         f[a] = cnt;         p[cnt] = a;       }     }     int pemp;     for (int i = 1; i <= n; i++)       if (!f[i]) pemp = i;     for (int j = 1; j <= cnt; j++) {       if (f[j] != j) {         if (!f[j] || j == pemp) {           pemp = p[j];           op.push_back(make_pair(p[j], j));           p[j] = j;           f[j] = j;           continue;         }         f[pemp] = f[j];         p[f[j]] = pemp;         op.push_back(make_pair(j, pemp));         int now = j;         while (f[now] != now && now <= cnt && now >= 1) {           op.push_back(make_pair(p[now], now));           int tmp = now;           f[now] = now;           now = p[now];           p[tmp] = tmp;         }         pemp = now;       }     }     printf( %d n , op.size());     for (int i = 0; i < op.size(); i++) {       printf( %d %d n , op[i].first, op[i].second);     }   }
#include <bits/stdc++.h>   using namespace std;   inline char nc() {     static char buf[100000], *p1 = buf, *p2 = buf;     return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)                ? EOF                : *p1++;   }   inline void read(int &x) {     char c = nc(), b = 1;     for (; !(c >=  0  && c <=  9 ); c = nc())       if (c ==  - ) b = -1;     for (x = 0; c >=  0  && c <=  9 ; x = x * 10 + c -  0 , c = nc())       ;     x *= b;   }   const int N = 55;   const int M = 2505;   struct edge {     int u, v, w, f;     int next;   } G[M << 1];   int head[N], inum = 1;   inline void add(int u, int v, int w, int f, int p) {     G[p].u = u;     G[p].v = v;     G[p].w = w;     G[p].f = f;     G[p].next = head[u];     head[u] = p;   }   inline void link(int u, int v, int w, int f) {     add(u, v, w, f, ++inum);     add(v, u, -w, 0, ++inum);   }   int n, m, P;   int S, T, Mincost;   int Q[N * M], l, r;   int dis[N], pre[N], ins[N];   inline bool SPFA() {     for (int i = 1; i <= n; i++) dis[i] = 1 << 29, pre[i] = 0, ins[i] = 0;     l = r = -1;     Q[++r] = S, dis[S] = 0, ins[S] = 1;     while (l < r) {       int u = Q[++l];       ins[u] = 0;       for (int p = head[u]; p; p = G[p].next)         if (G[p].f && dis[G[p].v] > dis[u] + G[p].w) {           dis[G[p].v] = dis[u] + G[p].w;           pre[G[p].v] = p;           if (!ins[G[p].v]) Q[++r] = G[p].v, ins[G[p].v] = 1;         }     }     if (dis[T] == 1 << 29) return 0;     Mincost += dis[T];     for (int p = pre[T]; p; p = pre[G[p].u]) G[p].f--, G[p ^ 1].f++;     return 1;   }   int _, Qry[123456];   double Ans[123456];   int main() {     int u, v, c, d;     read(n);     read(m);     S = 1;     T = n;     for (int i = 1; i <= m; i++)       read(u), read(v), read(d), c = 1, link(u, v, d, c);     read(_);     for (int i = 0; i < _; i++) read(Qry[i]);     double ans = 1e20;     int m = 0;     for (int i = 0; i < _; i++) Ans[i] = 1e20;     while (SPFA()) {       m++;       for (int i = 0; i < _; i++)         Ans[i] = min(Ans[i], ((double)(Mincost + Qry[i])) / m);       ans = min(ans, (double)(Mincost + P) / m);     }     for (int i = 0; i < _; i++) printf( %.10f n , Ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long getint() {     char ch = getchar();     long long f = 1, x = 0;     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f * x;   }   const int N = 200200;   int n;   struct dat {     long long w, h, c;   } a[N];   int bg[N], ed[N];   int cnt;   int ans;   bool operator<(const dat &a, const dat &b) {     return (a.w == b.w) ? a.h < b.h : a.w < b.w;   }   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   bool validate() {     for (int i = 2; i <= cnt; i++) {       if (ed[i] - bg[i] != ed[i - 1] - bg[i - 1]) return false;       for (int j = bg[i], k = bg[i - 1]; j <= ed[i]; j++, k++) {         if (a[j].h != a[k].h) return false;       }       long long g1, g2;       for (int j = bg[i], k = bg[i - 1]; j < ed[i]; j++, k++) {         g1 = gcd(a[j].c, a[j + 1].c);         g2 = gcd(a[k].c, a[k + 1].c);         if (a[j].c / g1 != a[k].c / g2 || a[j + 1].c / g1 != a[k + 1].c / g2)           return false;       }     }     return true;   }   void init() {     n = getint();     for (int i = 1; i <= n; i++) {       a[i].w = getint();       a[i].h = getint();       a[i].c = getint();     }     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n; i++) {       ++cnt;       bg[cnt] = i;       while (a[i].w == a[i + 1].w) i++;       ed[cnt] = i;     }   }   int main() {     init();     if (!validate()) {       puts( 0 );       return 0;     }     long long g = a[1].c;     for (int i = 2; i <= n; i++) {       g = gcd(g, a[i].c);     }     for (long long i = 1; i * i <= g; i++) {       if (g % i == 0) {         ans += (i * i == g) ? 1 : 2;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   priority_queue<long long, vector<long long>, greater<long long>> q;   int a[100005];   int main() {     int n, x;     long long b = 0, s;     scanf( %d , &n);     for (int i = 1; i <= n; ++i) scanf( %d , &a[i]);     for (int i = 1; i <= n; ++i) {       scanf( %d , &x);       s = 0;       q.push(a[i] + b);       while (!q.empty() && q.top() <= b + x) {         s += q.top() - b;         q.pop();       }       printf( %I64d  , s + (long long)q.size() * x);       b += x;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minpq = priority_queue<T, vector<T>, greater<T>>;   struct node {     int val, le, ri;     node() : val(1e9 + 5), le(0), ri(0) {}   };   const int N = 1e5 + 5;   int n, r, m, p, q, u, v, a[N], depth[N], root[N], tin[N], tout[N], ti = 1;   vector<int> adj[N];   bool vis[N];   vector<node> tree;   void dfs(int x) {     vis[x] = true;     tin[x] = ti++;     for (int y : adj[x]) {       if (!vis[y]) {         depth[y] = 1 + depth[x];         dfs(y);       }     }     tout[x] = ti;   }   int build(int l, int r) {     int k = ((int)(tree).size());     tree.emplace_back();     if (l < r) {       int m = (l + r) / 2;       tree[k].le = build(l, m);       tree[k].ri = build(m + 1, r);       tree[k].val = min(tree[tree[k].le].val, tree[tree[k].ri].val);     }     return k;   }   int upd(int i, int l, int r, int idx, int x) {     int k = ((int)(tree).size());     tree.emplace_back();     if (l < r) {       int m = (l + r) / 2;       if (idx <= m) {         tree[k].le = upd(tree[i].le, l, m, idx, x);         tree[k].ri = tree[i].ri;       } else {         tree[k].le = tree[i].le;         tree[k].ri = upd(tree[i].ri, m + 1, r, idx, x);       }       tree[k].val = min(tree[tree[k].le].val, tree[tree[k].ri].val);     } else {       tree[k].val = x;     }     return k;   }   int query(int i, int l, int r, int L, int R) {     if (r < L || R < l) return 1e9 + 5;     if (L <= l && r <= R) return tree[i].val;     int m = (l + r) / 2;     return min(query(tree[i].le, l, m, L, R), query(tree[i].ri, m + 1, r, L, R));   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> r;     for (int i = (1); i < (n + 1); i++) {       cin >> a[i];     }     for (int i = (0); i < (n - 1); i++) {       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     dfs(r);     vector<pair<int, int>> ve;     for (int i = (1); i < (n + 1); i++) {       ve.emplace_back(depth[i], i);     }     sort((ve).begin(), (ve).end());     root[0] = build(1, n);     int prevdepth = 0;     for (auto &p : ve) {       int u = p.second;       root[depth[u]] = upd(root[prevdepth], 1, n, tin[u], a[u]);       prevdepth = depth[u];     }     cin >> m;     int last = 0;     while (m--) {       cin >> p >> q;       int x = 1 + ((p + last) % n);       int k = (q + last) % n;       last = query(root[min(prevdepth, depth[x] + k)], 1, n, tin[x], tout[x] - 1);       cout << last <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[200005];   long long b[200005];   vector<long long> edge[200005];   vector<long long> roots;   vector<bool> visited;   long long max_val[200005];   long long ans = 0;   long long dfs(long long v) {     visited[v] = true;     long long ret = 0;     for (long long next : edge[v]) {       if (!visited[next]) {         ret += max(dfs(next), (long long)0);       }     }     ans += ret + a[v];     return max_val[v] = ret + a[v];   }   void dfs2(long long v) {     visited[v] = true;     for (long long next : edge[v]) {       if (!visited[next]) {         if (max_val[next] >= 0) {           dfs2(next);         }       }     }     printf( %lld  , v);     for (long long next : edge[v]) {       if (!visited[next]) {         dfs2(next);       }     }   }   int main() {     long long n;     scanf( %lld , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , a + i);     }     for (int j = 1; j <= n; j++) {       long long x;       scanf( %lld , &x);       if (x != -1) {         edge[x].push_back(j);       } else {         roots.push_back(j);       }     }     visited = vector<bool>(200005, false);     for (int i = 0; i < roots.size(); i++) {       dfs(roots[i]);     }     printf( %lld n , ans);     visited = vector<bool>(200005, false);     for (int i = 0; i < roots.size(); i++) {       dfs2(roots[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, n;     cin >> a >> b >> n;     long long l, t, m;     for (int i = 0; i < n; ++i) {       cin >> l >> t >> m;       long long sl = a + b * (l - 1), sr;       if (t < sl) {         cout << -1 << endl;         continue;       }       int lf = l, rt = (t - a) / b + 1;       int r = (lf + rt) / 2;       while (lf != r) {         sr = a + b * (r - 1);         if ((sl + sr) * (r - l + 1) / 2 <= t * m) {           lf = r;         } else {           rt = r - 1;         }         r = (lf + rt) / 2;       }       if ((sl + a + b * (rt - 1)) * (rt - l + 1) / 2 <= t * m) {         r = rt;       }       cout << r << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int32_t n;     std::cin >> n;     int32_t* arr = new int32_t[n];     for (int32_t i = 0; i < n; i++) {       std::cin >> arr[i];     }     std::string ans =   ;     char last =  b ;     for (int32_t i = n - 1; i >= 0; i--) {       if (arr[i] == 0) continue;       int32_t length = i + 1;       for (int32_t j = 0; j < arr[i]; j++) {         ans += std::string(length, last);         last = last ==  a  ?  b  :  a ;       }       for (int32_t j = i - 1; j >= 0; j--) arr[j] -= arr[i] * (i - j + 1);     }     std::cout << ans;     return 0;   };
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     scanf( %d %d , &a, &b);     if (a == 0 && b == 0)       printf( NO );     else if (fabs(a - b) == 1 || a - b == 0)       printf( YES );     else       printf( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int charToDec(char c) {     if ((c >=  0 ) && (c <=  9 )) return c -  0 ;     if ((c >=  A ) && (c <=  Z )) return c -  A  + 10;   }   char decToChar(int c) {     if ((c >= 0) && (c <= 9)) return c +  0 ;     if ((c >= 10) && (c <= 26)) return c +  A  - 10;   }   long long hzToDec(string s, int a) {     long long r = 0;     for (int i = 0; i < s.length(); i++) {       r *= a;       r += charToDec(s[i]);     }     return r;   }   string decToHz(long long x, int a) {     string s =   ;     while (x > 0) {       s = decToChar(x % a) + s;       x = x / a;     }     if (s ==   ) s =  0 ;     return s;   }   string toRome(long long X) {     string r[3100];     r[3000] =  MMM ;     r[2000] =  MM ;     r[1000] =  M ;     r[900] =  CM ;     r[800] =  DCCC ;     r[700] =  DCC ;     r[600] =  DC ;     r[500] =  D ;     r[400] =  CD ;     r[300] =  CCC ;     r[200] =  CC ;     r[100] =  C ;     r[90] =  XC ;     r[80] =  LXXX ;     r[70] =  LXX ;     r[60] =  LX ;     r[50] =  L ;     r[40] =  XL ;     r[30] =  XXX ;     r[20] =  XX ;     r[10] =  X ;     r[9] =  IX ;     r[8] =  VIII ;     r[7] =  VII ;     r[6] =  VI ;     r[5] =  V ;     r[4] =  IV ;     r[3] =  III ;     r[2] =  II ;     r[1] =  I ;     return r[X / 1000 * 1000] + r[(X % 1000) / 100 * 100] +            r[(X % 100) / 10 * 10] + r[X % 10];   }   int main() {     int a, b;     string bb, x;     long long x10;     cin >> a >> bb >> x;     x10 = hzToDec(x, a);     if (bb ==  R ) {       cout << toRome(x10);     } else       cout << decToHz(x10, atoi(bb.c_str()));     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast,inline,unroll-loops,fast-math )   using namespace std;   const bool d[3][2][2] = {       {           {false, true},           {true, false},       },       {           {true, false},           {true, true},       },       {           {true, true},           {false, true},       },   };   bitset<2020> f[2020];   bool c[2020][2][2], o[2020], z[2020];   void Multiply(const bool a[2][2], bool b[2][2]) {     bool c[2][2];     c[0][0] = (a[0][0] & b[0][0]) ^ (a[0][1] & b[1][0]);     c[0][1] = (a[0][0] & b[0][1]) ^ (a[0][1] & b[1][1]);     c[1][0] = (a[1][0] & b[0][0]) ^ (a[1][1] & b[1][0]);     c[1][1] = (a[1][0] & b[0][1]) ^ (a[1][1] & b[1][1]);     memcpy(b, c, sizeof(bool) * 4);     return;   }   int main(void) {     int n, m, k, x;     char s[4];     int i, j, l;     scanf( %d %d , &n, &m);     for (i = 0; i < n; i++) c[i][0][0] = c[i][1][1] = true;     for (i = l = 0; i < m; i++) {       scanf( %s %d , s, &k);       while (k--) {         scanf( %d , &x);         x--;         if (s[0] ==  m ) {           f[l][x << 1] = c[x][0][0];           f[l][x << 1 | 1] = c[x][0][1];           f[l + 1][x << 1] = c[x][1][0];           f[l + 1][x << 1 | 1] = c[x][1][1];         } else if (s[0] ==  R  && s[1] ==  Y )           Multiply(d[0], c[x]);         else if (s[0] ==  R  && s[1] ==  B )           Multiply(d[1], c[x]);         else           Multiply(d[2], c[x]);       }       if (s[0] ==  m ) {         scanf( %s , s);         f[l][n << 1] = s[0] ==  R  || s[0] ==  B ;         f[l + 1][n << 1] = s[0] ==  Y  || s[0] ==  B ;         l += 2;       }     }     for (i = k = 0; i < l && k < (n << 1); i++, k++) {       for (j = i; j < l && !f[j][k]; j++)         ;       if (j == l) {         z[k] = true;         i--;         continue;       }       swap(f[i], f[j]);       for (j = i + 1; j < l; j++)         if (f[j][k]) f[j] ^= f[i];     }     for (i = 0; i < l; i++) {       f[i].flip(n << 1);       if (f[i].none()) {         printf( NO n );         return 0;       }       f[i].flip(n << 1);     }     for (i = 0; i < l; i++)       for (j = k; j < (n << 1); j++) f[i][j] = false;     for (i = l - 1, j = k - 1; i > -1 && j > -1; i--) {       if (z[j]) {         j--;         i++;         continue;       }       if (f[i][j]) {         o[j] = f[i][n << 1];         for (k = i - 1; k > -1; k--)           if (f[k][j]) f[k] ^= f[i];         j--;       }     }     printf( YES n );     for (i = 0; i < n; i++) {       k = o[i << 1 | 1] << 1 | o[i << 1];       printf( %c , !k ?  .  : k == 1 ?  R  : k == 2 ?  Y  :  B );     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   const int maxn = 100035;   int n, num, cnt, pr[maxn], phi[maxn];   bool vis[maxn];   long long ans, f[maxn];   std::vector<int> fac[maxn], opt;   void makePrime() {     phi[1] = 1;     for (int i = 2; i < maxn; i++) {       if (!vis[i]) pr[++pr[0]] = i, phi[i] = i - 1;       for (int j = 1, chk = 1; j <= pr[0] && i * pr[j] < maxn && chk; j++)         if (pr[j] % i)           phi[i * pr[j]] = phi[i] * (pr[j] - 1);         else           chk = 0, phi[i * pr[j]] = phi[i] * pr[j];     }     for (int i = 1; i < maxn; i++)       for (int j = i; j < maxn; j += i) fac[j].push_back(i);   }   int qmi(int a, int b) {     int ret = 1;     for (; b; b >>= 1, a = 1ll * a * a % 1000000007)       if (b & 1) ret = 1ll * ret * a % 1000000007;     return ret;   }   int dmd;   void dfs(int x, int c, int t) {     if (x == opt.size())       ++dmd, cnt += ((t & 1) ? -num / c : num / c);     else {       dfs(x + 1, c, t);       dfs(x + 1, c * opt[x], t + 1);     }   }   int calc(int p, int d) {     bool debug = p == 12;     std::vector<int>().swap(opt), p /= d, num = n / d;     for (int i = 1; pr[i] <= p; i++)       if (p % pr[i] == 0) {         opt.push_back(pr[i]);         while (p % pr[i] == 0) p /= pr[i];       }     cnt = 0, dfs(0, 1, 0);     return cnt;   }   int main() {     scanf( %d , &n), ans = 1, f[1] = 0;     makePrime();     for (int i = 2; i <= n; i++) {       int lwr =           (1 - 1ll * qmi(n, 1000000007 - 2) * (n / i) % 1000000007 + 1000000007) %           1000000007;       for (int j = 1; j < fac[i].size() - 1; j++)         f[i] = (f[i] + 1ll * f[fac[i][j]] * calc(i, fac[i][j]) % 1000000007) %                1000000007;       f[i] = 1ll * (1ll * f[i] * qmi(n, 1000000007 - 2) % 1000000007 + 1) *              qmi(lwr, 1000000007 - 2) % 1000000007;       ans = (ans + f[i] + 1) % 1000000007;     }     printf( %lld n , 1ll * ans * qmi(n, 1000000007 - 2) % 1000000007);     return 0;   }