malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long n, m, h, ts, calc[2000];   double p2, p1;   double gc(long n, long m) {     if (m > n) return 0;     double res = 0;     for (int i = n; i > n - m; i--)       res = res + log(i + .0), res = res - log(.0 + n - i + 1);     return exp(res);   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> m >> h;     for (int i = 1; i <= m; i++) {       cin >> calc[i];       ts += calc[i];     }     if (ts < n) {       cout << -1 << endl;       return 0;     }     if (n == 1) {       cout << 0 << endl;       return 0;     }     if (calc[h] == 1) {       cout << 0 << endl;       return 0;     }     --n;     --calc[h];     --ts;     double ans = 1.0;     for (int i = 1; i <= n; i++)       ans = ans * (ts - calc[h] - i + 1) / (ts - i + 1);     cout << fixed << 1.0 - ans << endl;     cin.get();     cin.get();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<int> a, b, g, ar;   vector<vector<int> > edg, nxt;   vector<long long> d;   long long f(int v) {     long long res = 0;     for (int w : edg[v]) {       long long tmp = f(w) + a[w];       if (tmp > 0) {         res += tmp;         nxt[w].push_back(v);         g[v]++;       } else {         nxt[v].push_back(w);         g[w]++;       }     }     return d[v] = res;   }   int main(void) {     cin >> n;     a.assign(n, 0);     b.assign(n, 0);     g.assign(n, 0);     edg.assign(n, vector<int>());     nxt.assign(n, vector<int>());     for (int i = 0; i < n; i++) cin >> a[i];     vector<int> c;     for (int i = 0; i < n; i++) {       cin >> b[i];       if (b[i] == -1) {         c.push_back(i);         continue;       }       b[i]--;       edg[b[i]].push_back(i);     }     long long ans = 0;     d.assign(n, 0);     for (int i = 0; i < n; i++) {       if (b[i] == -1) f(i);     }     for (int i = 0; i < n; i++) {       ans += d[i] + a[i];     }     queue<int> q;     for (int i = 0; i < n; i++) {       if (g[i] == 0) q.push(i);     }     while (!q.empty()) {       int v = q.front();       q.pop();       ar.push_back(v);       for (int w : nxt[v]) {         g[w]--;         if (g[w] == 0) q.push(w);       }     }     cout << ans << endl;     for (int v : ar) cout << v + 1 <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e9;   long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }   long long power(long long a, long long n) {     long long p = 1;     while (n > 0) {       if (n % 2) {         p = p * a;       }       n >>= 1;       a *= a;     }     return p;   }   int main() {     ios_base::sync_with_stdio(false);     string s, t;     int n, m, p, a, b, c, d, e, x, mx = -INF;     cin >> n;     for (int(i) = 0; (i) < (n); (i)++) {       cin >> s >> p >> m >> a >> b >> c >> d >> e;       x = 100 * p - 50 * m + a + b + c + d + e;       if (mx < x) {         t = s;         mx = x;       }     }     cout << t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long md(long long a, long long b) {     long long ret = 1;     a %= 1000000007;     while (b) {       if (b & 1) {         ret = (ret * a) % 1000000007;       }       a = (a * a) % 1000000007;       b >>= 1;     }     return ret;   }   int mp[41] = {2,       3,       5,       7,        13,       17,      19,                 31,      61,      89,      107,      127,      521,     607,                 1279,    2203,    2281,    3217,     4253,     4423,    9689,                 9941,    11213,   19937,   21701,    23209,    44497,   86243,                 110503,  132049,  216091,  756839,   859433,   1257787, 1398269,                 2976221, 3021377, 6972593, 13466917, 20996011, 24036583};   int main() {     int n;     scanf( %d , &n);     printf( %d n , md(2, mp[n - 1] - 1) - 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a;     string s;     cin >> a;     for (int i = 1; i <= a + 5; i++) {       stringstream sa;       string ssa;       sa << i;       sa >> ssa;       s.append(ssa);     }     cout << s[a - 1];     return 0;   }
#include <bits/stdc++.h>      using namespace std;      bool cutPaper(int n, int x, int y)   {       int count = 1;          while ( x % 2 == 0 || y % 2 == 0 )       {              if ( x % 2 == 0 ){               x /= 2;               count *= 2;            }else if ( y % 2 == 0 )  {               y /= 2;                count *= 2;            }              if ( count >= n )               return true;          }          if ( count >= n )               return true;             return false;          }   int main()   {          int t;       cin >> t;          while (t-- > 0)       {           int n, x, y;              cin >> x >> y >> n;              if (cutPaper(n, x, y))           {               cout <<  YES  << endl;           }           else           {               cout <<  NO  << endl;           }       }   }
#include <bits/stdc++.h>   using namespace std;   int a[3509];   int n, t, m, k;   deque<int> d;   vector<int> v;   int main() {     scanf( %d , &t);     for (int i = 0; i < t; i++) {       scanf( %d%d%d , &n, &m, &k);       for (int j = 0; j < n; j++) scanf( %d , &a[j]);       int g = n - m + 1;       v.clear();       for (int j = g - 1; j < n; j++) v.push_back(max(a[j - g + 1], a[j]));       int vlen = v.size();       int g2 = vlen - k;       g2 = max(1, g2);       d.clear();       for (int i = 0; i < g2; i++) {         if (!d.empty()) {           while (!d.empty() && d.back() > v[i]) d.pop_back();         }         d.push_back(v[i]);       }       int ans = d.front();       for (int i = g2; i < vlen; i++) {         if (!d.empty() && d.front() == v[i - g2]) {           d.pop_front();         }         while (!d.empty() && d.back() > v[i]) d.pop_back();         d.push_back(v[i]);         ans = max(ans, d.front());       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000004;   int a[N], arr[N], nxt[N], big[N], len[N];   int main() {     int n;     scanf( %d , &n);     int i, idx;     int mx1 = 0, mx2 = -1;     for (i = 0; i < n; i++) {       scanf( %d , &a[i]);       if (a[i] > mx1) {         mx2 = mx1;         mx1 = a[i];         idx = i;       } else if (a[i] > mx2)         mx2 = a[i];     }     int id = idx;     for (i = 1; i <= n; i++) {       arr[i] = a[id];       id = (id + 1) % n;     }     arr[n + 1] = 1000000007;     stack<int> st;     st.push(n + 1);     for (i = n; i >= 1; i--) {       while (!st.empty() && arr[st.top()] < arr[i]) st.pop();       nxt[i] = st.top();       st.push(i);     }     while (!st.empty()) st.pop();     st.push(n + 1);     for (i = n; i >= 1; i--) {       while (!st.empty() && arr[st.top()] <= arr[i]) st.pop();       big[i] = st.top();       st.push(i);     }     len[n + 1] = 1;     for (i = n; i >= 1; i--) len[i] = len[nxt[i]] + 1;     long long ans = 0;     for (i = 1; i <= n; i++) ans = ans + (len[i + 1] - len[big[i]] + 1);     for (i = 1; i <= n; i++) {       if (arr[i] == mx1 || arr[i] == mx2) ans--;     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 5e5 + 5;   std::vector<std::pair<int, int>> G[maxn];   std::vector<std::tuple<int, int, int>> q[maxn];   int in[maxn], out[maxn], id[maxn], tot, n, m;   long long dis[maxn], ans[maxn];   struct SegTree {     long long sum[maxn << 2], lazy[maxn << 2];     void pushdown(int o) {       if (lazy[o]) {         sum[o << 1] += lazy[o];         sum[o << 1 | 1] += lazy[o];         lazy[o << 1] += lazy[o];         lazy[o << 1 | 1] += lazy[o];         lazy[o] = 0;       }     }     void build(int o, int l, int r) {       if (l == r) {         sum[o] = dis[l];         return;       }       int m = (l + r) >> 1;       build(o << 1, l, m);       build(o << 1 | 1, m + 1, r);       sum[o] = std::min(sum[o << 1], sum[o << 1 | 1]);     }     void update(int o, int l, int r, int ql, int qr, int val) {       if (ql <= l && r <= qr) {         sum[o] += val;         lazy[o] += val;         return;       }       int m = (l + r) >> 1;       pushdown(o);       if (ql <= m) update(o << 1, l, m, ql, qr, val);       if (qr > m) update(o << 1 | 1, m + 1, r, ql, qr, val);       sum[o] = std::min(sum[o << 1], sum[o << 1 | 1]);     }     long long query(int o, int l, int r, int ql, int qr) {       if (ql <= l && r <= qr) {         return sum[o];       }       int m = (l + r) >> 1;       long long ans = 0x3f3f3f3f3f3f3f3f;       pushdown(o);       if (ql <= m) ans = std::min(ans, query(o << 1, l, m, ql, qr));       if (qr > m) ans = std::min(ans, query(o << 1 | 1, m + 1, r, ql, qr));       return ans;     }   } st;   void dfs1(int u, long long d) {     in[u] = ++tot;     for (auto &it : G[u]) dfs1(it.first, it.second + d);     if (G[u].empty())       dis[u] = d;     else       dis[u] = 0x3f3f3f3f3f3f3f3f;     out[u] = tot;   }   void dfs2(int u, long long d) {     for (auto &it : q[u])       ans[std::get<2>(it)] =           st.query(1, 1, n, std::get<0>(it), std::get<1>(it)) + d;     for (auto &it : G[u]) {       st.update(1, 1, n, in[it.first], out[it.first], -2 * it.second);       dfs2(it.first, it.second + d);       st.update(1, 1, n, in[it.first], out[it.first], 2 * it.second);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 2; i <= n; i++) {       int u, w;       scanf( %d%d , &u, &w);       G[u].emplace_back(i, w);     }     dfs1(1, 0);     st.build(1, 1, n);     for (int i = 1; i <= m; i++) {       int v, l, r;       scanf( %d%d%d , &v, &l, &r);       q[v].emplace_back(l, r, i);     }     dfs2(1, 0);     for (int i = 1; i <= m; i++) printf( %lld n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   bool umin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool umax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   int p[100009];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) p[i] = i;     if (n & 1) {       for (int i = n; i > 1; i -= 2) swap(p[i], p[i - 1]);     } else {       for (int i = 1; i < n; i += 2) swap(p[i], p[i + 1]);     }     for (int i = 1; i <= n; i++) printf( %d  , p[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300010, maxlg = 18;   struct edge {     int to, nxt;     long long val;   };   edge G[maxn << 1], G2[maxn];   int head[maxn], cnt;   int head2[maxn], cnt2;   struct node {     int u;     long long d;     inline bool operator<(const node &rhs) const { return d > rhs.d; }   };   priority_queue<node> PQ;   long long dis[maxn];   bool vis[maxn];   int deg[maxn];   edge T[maxn];   int headT[maxn], cntT;   queue<int> Q;   int lg[maxn];   int anc[maxn][maxlg], dep[maxn];   inline int lca(int, int);   void dfs(const int &);   int siz[maxn];   int main() {     int n, m, s;     scanf( %d %d %d , &n, &m, &s);     int u, v, w;     while (m--) {       scanf( %d %d %d , &u, &v, &w);       G[++cnt] = {v, head[u], w}, head[u] = cnt;       G[++cnt] = {u, head[v], w}, head[v] = cnt;     }     memset(dis, 0x3f, sizeof(dis));     dis[s] = 0, PQ.push({s, 0});     while (!PQ.empty()) {       u = PQ.top().u, PQ.pop();       if (vis[u]) continue;       vis[u] = true;       for (int i = head[u]; i; i = G[i].nxt)         if (dis[G[i].to] > dis[u] + G[i].val) {           dis[G[i].to] = dis[u] + G[i].val;           PQ.push({G[i].to, dis[G[i].to]});         }     }     for (int i = 1; i <= n; i++) {       anc[i][0] = -1;       for (int j = head[i]; j; j = G[j].nxt)         if (dis[G[j].to] == dis[i] + G[j].val)           G2[++cnt2] = {G[j].to, head2[i]}, head2[i] = cnt2, deg[G[j].to]++;     }     for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;     Q.push(s);     while (!Q.empty()) {       u = Q.front(), Q.pop();       if (u != s) {         dep[u] = dep[anc[u][0]] + 1;         T[++cntT] = {u, headT[anc[u][0]], 0}, headT[anc[u][0]] = cntT;         for (int i = 1; i <= lg[dep[u]]; i++)           anc[u][i] = anc[anc[u][i - 1]][i - 1];       }       for (int i = head2[u]; i; i = G2[i].nxt)         if (deg[G2[i].to]) {           anc[G2[i].to][0] = lca(anc[G2[i].to][0], u);           if (!--deg[G2[i].to]) Q.push(G2[i].to);         }     }     dfs(s);     int ans = 0;     for (int i = 1; i <= n; i++)       if (i != s && siz[i] > ans) ans = siz[i];     printf( %d n , ans);     return 0;   }   inline int lca(int u, int v) {     if (u == -1) return v;     if (dep[u] < dep[v]) u ^= v ^= u ^= v;     while (dep[u] != dep[v]) u = anc[u][lg[dep[u] - dep[v]]];     if (u == v) return u;     for (int i = lg[dep[u]]; i >= 0; i--)       if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];     return anc[u][0];   }   void dfs(const int &u) {     siz[u] = 1;     for (int i = headT[u]; i; i = T[i].nxt) dfs(T[i].to), siz[u] += siz[T[i].to];     return;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     vector<int> v1, v2;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a) v1.push_back(a);     }     for (int i = 0; i < n; i++) {       int a;       cin >> a;       if (a) v2.push_back(a);     }     for (int i = 0; i < n - 1; i++) {       if (v1[0] == v2[i]) {         rotate(v2.begin(), v2.begin() + i, v2.end());         break;       }     }     for (int i = 0; i < n - 1; i++) {       if (v1[i] != v2[i]) {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long k, m;     string s;     vector<int> rooms;     cin >> k >> m;     cin >> s;     for (int i = 0; i < s.length(); i++) {       if (s[i] ==  0 ) {         rooms.push_back(i);       }     }     long select = k;     k = 0;     while (k + m < rooms.size()) {       for (int i = k; i <= k + m; i++) {         if (max(rooms[i] - rooms[k], rooms[k + m] - rooms[i]) < select)           select = max(rooms[i] - rooms[k], rooms[k + m] - rooms[i]);       }       k++;     }     cout << select;   }
#include <bits/stdc++.h>   using namespace std;   const int sieve_size = 15000002;   bool sieve[sieve_size + 1];   vector<long long> prime;   void Sieve() {     prime.push_back(2);     for (int i = 3; i * i <= sieve_size; i += 2) {       if (!sieve[i]) {         long long p = i * 2;         for (int j = i * i; j <= sieve_size; j += p) {           sieve[j] = true;         }       }     }     for (int i = 3; i <= sieve_size; i += 2) {       if (!sieve[i]) prime.push_back(i);     }   }   int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};   inline int GA(long long n, vector<long long>& vec) {     for (int i = 0; i < n; ++i) {       long long x;       cin >> x;       vec.push_back(x);     }     return 0;   }   inline int GAEG(long long m, vector<long long> vec[]) {     for (int i = 0; i < m; ++i) {       long long x, y;       cin >> x >> y;       x--, y--;       vec[x].push_back(y);       vec[y].push_back(x);     }     return 0;   }   bool isvalid(long long xx, long long yy, long long n, long long m) {     return (xx >= 0 && xx < n && yy >= 0 && yy < m);   }   long long pw(long long x, long long y) {     if (y == 0) return 1;     long long o = y / 2;     long long f = pw(x, o);     if (y % 2) {       return (((f * f)) * x);     } else       return (f * f);   }   string s[60];   int main() {     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       for (int i = 0; i < n; ++i) cin >> s[i];       long long ans = 4;       bool bl = false;       for (int i = 0; i < n; ++i) {         int p = s[i].find( A );         if (p != -1) {           bl = true;           break;         }       }       if (!bl) {         cout <<  MORTAL  << endl;       } else {         if (s[0].find( A ) != -1 || s[n - 1].find( A ) != -1) ans = 3;         for (int i = 0; i < n; ++i) {           if (s[i][0] ==  A  || s[i][m - 1] ==  A ) {             ans = 3;             break;           }         }         if (s[0][0] ==  A  || s[n - 1][0] ==  A  || s[n - 1][m - 1] ==  A  ||             s[0][m - 1] ==  A )           ans = 2;         for (int i = 0; i < n; ++i) {           bool qq = false;           for (int j = 0; j < m; ++j) {             if (s[i][j] !=  A ) {               qq = true;               break;             }           }           if (!qq) {             if (i == 0 || i == n - 1)               ans = 1;             else               ans = min(ans, 2ll);           }         }         bool isP = false;         for (int i = 0; i < m; ++i) {           bool qq = false;           for (int j = 0; j < n; ++j) {             if (s[j][i] !=  A ) {               qq = true;               isP = true;               break;             }           }           if (!qq) {             if (i == 0 || i == m - 1)               ans = 1;             else               ans = min(ans, 2ll);           }         }         if (!isP)           cout << 0 << endl;         else           cout << ans << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, q;     cin >> n >> q;     long long int ans[q];     for (long long int i = 0; i < q; i++) {       long long int x, y, k = 0, cto = 0;       ;       cin >> x >> y;       if (n % 2 == 0) {         k = (n / 2) * (x - 1) + ((y / 2) + (y % 2));         if ((x + y) % 2 == 1) {           k += (n * n) / 2;         }       }       if (n % 2 == 1) {         if (x % 2 == 0) {           cto = (x / 2);         }         if (x % 2 == 1) {           cto = (x - 1) / 2;         }         k = (n / 2) * (x - 1) + cto + ((y / 2) + (y % 2));         if ((x + y) % 2 == 1) {           k += (n * n) / 2;           if (x % 2 == 1) {             k++;           }         }       }       ans[i] = k;     }     for (long long int i = 0; i < q; i++) {       cout << ans[i] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long arr[200022];   long long b[200022];   vector<vector<long long> > vect(4 * 200022);   void merge(long long i, long long a, long long j, long long b1, long long pos) {     long long s = i;     long long e = b1;     while (i <= a && j <= b1) {       if (b[i] < b[j]) {         vect[pos].push_back(b[i++]);       } else         vect[pos].push_back(b[j++]);     }     while (i <= a) vect[pos].push_back(b[i++]);     while (j <= b1) vect[pos].push_back(b[j++]);     long long k = 0;     for (; s <= e; s++) b[s] = vect[pos][k++];     return;   }   void mergesort(long long i, long long j, long long pos) {     if (i < j) {       long long mid = i + j;       mid /= 2;       mergesort(i, mid, pos * 2 + 1);       mergesort(mid + 1, j, pos * 2 + 2);       merge(i, mid, mid + 1, j, pos);     } else if (i == j) {       vect[pos].push_back(b[i]);     }   }   long long query(long long s, long long e, long long st, long long ed,                   long long pos, long long ele) {     if (s > ed || e < st)       return 0;     else if (s <= st && e >= ed) {       return vect[pos].end() -              lower_bound((vect[pos]).begin(), (vect[pos]).end(), ele);     } else {       return query(s, e, st, (st + ed) / 2, pos * 2 + 1, ele) +              query(s, e, ((st + ed) / 2) + 1, ed, pos * 2 + 2, ele);     }   }   int main() {     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> arr[i];       arr[i] = min(arr[i], n);       b[i] = arr[i];     }     mergesort(0, n - 1, 0);     long long ans = 0;     for (long long i = n; i >= 1; i--) {       long long end = min(i, arr[i - 1]);       if (end == i) end--;       ans += query(0, end - 1, 0, n - 1, 0, i);     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int dfs(int n) {}   int main() {     int n, k, x, y, a[200200], b[200200];     cin >> n >> k;     vector<vector<int> > v(n, vector<int>());     for (int i = 0; i < n; i++) {       cin >> a[i];       b[i] = a[i];     }     for (int i = 0; i < k; i++) {       cin >> x >> y;       v[x - 1].push_back(y - 1);       v[y - 1].push_back(x - 1);     }     sort(b, b + n);     for (int i = 0; i < n; i++) {       int x = i, res = lower_bound(b, b + n, a[i]) - b;       for (int j = 0; j < v[i].size(); j++)         if (a[v[i][j]] < a[i]) res--;       cout << res <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000;   const int MAX = 1000;   const int inf = 999999999;   const int p1 = 104393321, p2 = 104393329;   int a[MAX], adj[MAX][MAX], ans = inf;   int main() {     ios::sync_with_stdio(0);     int n, m;     cin >> n >> m;     for (int i = (0); i < int(n); ++i) cin >> a[i];     for (int i = (0); i < int(m); ++i) {       int x, y;       cin >> x >> y;       x--;       y--;       adj[x][y] = 1;       adj[y][x] = 1;     }     for (int i = (0); i < int(n); ++i) {       for (int j = (i + 1); j < int(n); ++j) {         for (int t = (j + 1); t < int(n); ++t) {           if (adj[i][j] && adj[j][t] && adj[i][t])             ans = min(ans, a[i] + a[t] + a[j]);         }       }     }     if (ans == inf)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, cnt = 0;   map<int, int> mp;   int main() {     cin >> n;     mp[n]++;     cnt++;     while (n) {       n++;       while (!(n % 10)) n /= 10;       if (mp[n]) break;       mp[n]++;       cnt++;     }     cout << cnt << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int SET(int n, int pos) { return n = n | (1 << pos); }   int RESET(int n, int pos) { return n = n & ~(1 << pos); }   int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); }   int str2int(string s) {     stringstream ss(s);     int x;     ss >> x;     return x;   }   string int2str(int a) {     stringstream ss;     ss << a;     string str = ss.str();     return str;   }   string char2str(char a) {     stringstream ss;     ss << a;     string str = ss.str();     return str;   }   long long int bigMod(long long int n, long long int power, long long int MOD) {     if (power == 0) return 1;     if (power % 2 == 0) {       long long int ret = bigMod(n, power / 2, MOD);       return ((ret % MOD) * (ret % MOD)) % MOD;     } else       return ((n % MOD) * (bigMod(n, power - 1, MOD) % MOD)) % MOD;   }   long long int modInverse(long long int n, long long int MOD) {     return bigMod(n, MOD - 2, MOD);   }   int POW(int x, int y) {     int res = 1;     for (; y;) {       if ((y & 1)) {         res *= x;       }       x *= x;       y >>= 1;     }     return res;   }   int inverse(int x) {     double p = ((double)1.0) / x;     return (p) + 1e-9;   }   int gcd(int a, int b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   int nC2(int n) { return n * (n - 1) / 2; }   long long int MOD(long long int n, long long int mod) {     if (n >= 0)       return n % mod;     else if (-n == mod)       return 0;     else       return mod + (n % mod);   }   int n, data[105], Mask[65], dp[105][(1 << 18) + 1], path[105][(1 << 18) + 1];   bool isPrime[65];   vector<int> prime;   void seive_N_logN(int N) {     memset(isPrime, true, sizeof isPrime);     prime.clear();     isPrime[1] = false;     for (int i = 4; i <= N; i = i + 2) isPrime[i] = false;     for (int i = 3; i * i <= N; i = i + 2) {       if (isPrime[i]) {         for (int j = i * i; j <= N; j += i) isPrime[j] = false;       }     }     for (int i = 1; i < N; i++)       if (isPrime[i]) prime.push_back(i);     for (int i = 1; i <= 60; i++) {       for (int j = 0; j < prime.size(); j++) {         if (i % prime[j] == 0) Mask[i] = SET(Mask[i], j);       }     }   }   int call(int i, int mask) {     if (i >= n) {       return 0;     }     int &ret = dp[i][mask];     if (ret != -1) return ret;     ret = 1000000000;     for (int j = 1; j <= 60; j++) {       if (mask & Mask[j]) continue;       int xx = call(i + 1, mask | Mask[j]) + abs(data[i] - j);       if (xx < ret) {         ret = xx;         path[i][mask] = j;       }     }     return ret;   }   int main() {     seive_N_logN(60);     int t, cas = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d , &data[i]);     }     memset(dp, -1, sizeof(dp));     call(0, 0);     int mask = 0;     for (int i = 0; i < n; i++) {       int ans = path[i][mask];       printf( %d  , ans);       mask |= Mask[ans];     }     printf(  n );     return 0;   }