malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   bool map[21][21];   int i, j, k, n, m, lim, tot, l, t, c[1 << 10];   long long f[1 << 10][1 << 10], ans;   int main() {     scanf( %d%d%d , &n, &m, &lim);     tot = 1 << n;     memset(map, 0, sizeof(map));     memset(f, 0, sizeof(f));     for (i = 0; i < tot; i++)       for (j = i, c[i] = 0; j; j >>= 1) c[i] += j & 1;     for (i = 1; i <= m; i++) {       scanf( %d%d , &j, &k);       map[j][k] = map[k][j] = 1;       f[(1 << (j - 1)) + (1 << (k - 1))][(1 << (j - 1)) + (1 << (k - 1))] = 1;     }     for (i = 1; i < tot; i++)       for (j = 1; j < i; j++) {         if (c[i] <= c[j]) continue;         for (k = j, l = 1; k; k >>= 1, l++) {           if (!(k & 1)) continue;           for (t = 1; t <= n; t++)             if (map[t][l] && (i >> (t - 1)) % 2 && (j >> (t - 1)) % 2 == 0)               f[i][j] +=                   f[i - (1 << (l - 1))][j - (1 << (l - 1))] +                   f[i - (1 << (l - 1))][j - (1 << (l - 1)) + (1 << (t - 1))];         }         f[i][j] /= c[j];       }     for (i = 1; i < tot; i++) {       if (c[i] == lim) ans += f[tot - 1][i];     }     printf( %I64d n , ans);   }
#include <bits/stdc++.h>   const long long LL_INF = (long long)2e18 + 5;   using namespace std;   const long long N = 2e5 + 10;   void solve() {     long long n, a0, a, b0, b, k;     cin >> n;     vector<long long> v(n), pref(n + 1);     ;     {       for (auto &i : v) cin >> i;     }     sort(v.begin(), v.end()), reverse(v.begin(), v.end());     for (long long i = (long long)(1); i < (long long)(n + 1); i++)       pref[i] = pref[i - 1] + v[i - 1];     cin >> a0 >> a >> b0 >> b >> k;     if (a0 < b0) swap(a0, b0), swap(a, b);     auto sum = [&](long long l, long long r) { return pref[r] - pref[l]; };     long long ctall = 0, cta = 0, ctb = 0;     for (long long i = (long long)(1); i < (long long)(n + 1); i++) {       if (i % a == 0 and i % b == 0)         ctall++;       else if (i % a == 0)         cta++;       else if (i % b == 0)         ctb++;       if (sum(0, ctall) * (a0 + b0) / 100 + sum(ctall, ctall + cta) * a0 / 100 +               sum(ctall + cta, ctall + cta + ctb) * b0 / 100 >=           k) {         cout << i <<   n ;         return;       }     }     cout <<  -1 n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long tt;     cin >> tt;     while (tt--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   struct cate {     long long num, t;     bool operator<(const cate& other) const { return t > other.t; }   } a[maxn];   int n;   set<long long> has;   map<long long, long long> fa;   long long find(long long x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i].num;       fa[a[i].num] = a[i].num;     }     for (int i = 1; i <= n; ++i) cin >> a[i].t;     sort(a + 1, a + n + 1);     long long ans = 0;     for (int i = 1; i <= n; ++i) {       long long cur = a[i].num;       if (has.find(cur) != has.end()) {         cur = find(cur);         cur += 1;         fa[cur] = cur;         ans += (cur - a[i].num) * a[i].t;       }       has.insert(cur);       if (has.find(cur - 1) != has.end()) fa[cur - 1] = cur;       if (has.find(cur + 1) != has.end()) fa[cur] = cur + 1;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   int main() {     long long n, w = 0, i, j, k;     bool y[1261] = {0};     scanf( %I64d , &n);     k = 1260;     for (i = 2; i <= 10; i++)       for (j = 1; j <= 1260; j++)         if (j % i == 0 && y[j] == 0) {           y[j] = 1;           k--;         }     w = 0;     w = n / 1260 * k;     n %= 1260;     for (i = 1; i <= n; i++)       if (y[i] == 0) w++;     printf( %I64d , w);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int present(int *lib, int k, int x) {     int i;     for (i = 0; i < k; i++) {       if (lib[i] == x) return 1;     }     return 0;   }   int findMax(int *lib, int k, queue<int> *q, int n) {     int i, max = -1, maxi = 0;     for (i = 0; i < k; i++) {       if (q[lib[i]].empty()) return i;       if (max < q[lib[i]].front()) {         max = q[lib[i]].front();         maxi = i;       }     }     return maxi;   }   int main() {     int n, k, i, ans = 0, size = 0, z;     scanf( %d%d , &n, &k);     int *lib = (int *)calloc(k, sizeof(int));     int *arr = (int *)calloc(n, sizeof(int));     queue<int> q[n + 1];     for (i = 0; i < n; i++) {       scanf( %d , &arr[i]);       q[arr[i]].push(i);     }     for (i = 0; i < n; i++) {       if (present(lib, k, arr[i]) == 0) {         if (size < k) {           q[arr[i]].pop();           lib[size++] = arr[i];           ans++;         } else {           q[arr[i]].pop();           z = findMax(lib, k, q, n);           lib[z] = arr[i];           ans++;         }       } else {         q[arr[i]].pop();       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 3e5 + 5;   using namespace std;   long long n, m;   int main() {     scanf( %d%d , &n, &m);     if (min(n, m) == 1) {       long long t = max(n, m);       long long ti = t / 6, res = t % 6;       printf( %lld n , ti * 6 + max(0ll, res - 3) * 2);       return 0;     }     if ((n % 2) && (m % 2)) {       printf( %lld n , n * m - 1);     } else if (n % 2 == 0 && m % 2 == 0) {       if (max(n, m) <= 2)         printf( 0 n );       else         printf( %lld n , n * m);     } else {       if (min(n, m) == 2) {         long long t = max(n, m);         if (t == 3 || t == 7)           printf( %lld n , n * m - 2);         else           printf( %lld n , n * m);       } else         printf( %lld n , n * m);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double p[600][600], pp[600][600];   double f[600][600];   bool checkInRound(int I, int K, int Round) {     int i = I - 1;     int k = K - 1;     if (i / (1 << Round) != k / (1 << Round)) return false;     if (i / (1 << (Round - 1)) == k / (1 << (Round - 1))) return false;     return true;   }   int main() {     memset(f, 0, sizeof(f));     int N;     cin >> N;     int SL = 1 << N;     for (int i = 1; i <= SL; i++) {       int temp;       for (int j = 1; j <= SL; j++) {         scanf( %d , &temp);         p[i][j] = temp * 0.01;       }     }     int Round = N;     for (int i = 1; i <= SL; i++) {       if (i % 2) {         f[i][1] = p[i][i + 1];       } else {         f[i][1] = p[i][i - 1];       }     }     for (int i = 1; i <= SL; i++) pp[i][1] = f[i][1];     for (int R = 2; R <= Round; R++) {       for (int i = 1; i <= SL; i++) {         for (int k = 1; k <= SL; k++) {           if (checkInRound(i, k, R)) {             pp[i][R] += pp[i][R - 1] * pp[k][R - 1] * p[i][k];           }         }       }     }     for (int R = 2; R <= Round; R++) {       for (int i = 1; i <= SL; i++) {         double mem = 0;         for (int k = 1; k <= SL; k++) {           if (checkInRound(i, k, R)) {             f[i][R] += pp[i][R - 1] * pp[k][R - 1] * p[i][k] * (1 << (R - 1));             mem = max(mem, f[k][R - 1]);           }         }         f[i][R] += mem + f[i][R - 1];       }     }     double ans = 0;     for (int i = 1; i <= SL; i++) ans = max(ans, f[i][Round]);     printf( %.12f , ans);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, x, p, m = 0;     stack<int> s;     cin >> n;     p = n % 2;     for (int i = 0; i < n; i++) {       cin >> x;       m = max(x, m);       if (!s.empty() && s.top() < x) cout <<  NO , exit(0);       if (s.empty() || (s.top() != x))         s.push(x);       else         s.pop();     }     if (p) {       if (s.size() == 0) {         cout <<  YES ;       } else if (s.size() == 1 && s.top() == m) {         cout <<  YES ;       } else {         cout <<  NO ;       }     } else {       if (s.size())         cout <<  NO ;       else         cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool check(char s) {     if (s ==  A  || s ==  H  || s ==  I  || s ==  M  || s ==  O  || s ==  T  ||         s ==  U  || s ==  V  || s ==  W  || s ==  X  || s ==  Y )       return true;     else       return false;   }   int main() {     int n, i, x, p;     bool ans = true;     string st;     cin >> st;     n = st.size();     if (n == 1 && check(st[0]) == true) {       cout <<  YES n ;       ;     } else if (n == 2 && st[0] == st[1] && check(st[0]) == true) {       cout <<  YES n ;       ;     } else if (n >= 3) {       ans = true;       x = 0, p = n - 1;       while (x <= p) {         if (st[x] == st[p] && check(st[x]) == true) {           x += 1, p -= 1;         } else {           ans = false;           break;         }       }       if (ans == false) {         cout <<  NO n ;         ;       } else {         cout <<  YES n ;         ;       }     } else {       cout <<  NO n ;       ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int count[26] = {0}, c = 0, i;     string str;     getline(cin, str);     for (i = 1; i <= str.length() - 1; i++) {       if (str[i] ==  }  || str[i] ==  , ) count[str[i - 1] -  a ]++;     }     for (i = 0; i <= 25; i++)       if (count[i] > 0) c++;     printf( %d n , c);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     long long t;     cin >> t;     while (t--) {       vector<long long> v(7);       for (auto& e : v) cin >> e;       sort(v.begin(), v.end());       cout << v[0] <<     << v[1] <<    ;       if (v[2] != v[1] + v[0])         cout << v[2] << endl;       else         cout << v[3] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[1000100], n, m;   int sum[1000100], now;   long long ans;   int idx, cnt;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]), ans += a[i];     if (ans % m) {       puts( No );       return 0;     }     ans /= m;     for (int i = 1; i <= n; i++) {       cnt += a[i], now++;       if (cnt == ans) {         sum[++idx] = now;         now = 0, cnt = 0;       } else if (cnt > ans) {         puts( No );         return 0;       }     }     puts( Yes );     for (int i = 1; i <= idx; i++) printf( %d  , sum[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read(int f = 1, int x = 0, char ch =    ) {     while (!isdigit(ch = getchar()))       if (ch ==  - ) f = -1;     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return f * x;   }   const int N = 2e5 + 5;   int m, n, T, s[2][N], c[2], f[2], ans, q[N], t[N], type[N], tot;   long long a, b;   int main() {     m = read();     while (m--) {       n = read(), T = read(), a = read(), b = read();       c[0] = c[1] = f[0] = f[1] = ans = 0;       for (int i = 1; i <= n; ++i) type[i] = read(), s[0][i] = s[1][i] = 0;       for (int i = 1; i <= n; ++i) q[i] = t[i] = read();       sort(q + 1, q + 1 + n), tot = unique(q + 1, q + 1 + n) - q - 1;       for (int i = 1; i <= n; ++i) {         int j = lower_bound(q + 1, q + 1 + tot, t[i]) - q;         ++s[type[i]][j], ++c[type[i]];       }       q[tot + 1] = max(q[tot] + 1, T + 1);       for (int i = 0; i <= tot; ++i) {         f[0] += s[0][i], f[1] += s[1][i];         int t = min(q[i + 1] - 1, T), resa = c[0] - f[0], resb = c[1] - f[1];         ;         if (f[0] * a + f[1] * b > t) continue;         int rest = t - (f[0] * a + f[1] * b);         if (resa * a <= rest)           ans = max(f[0] + f[1] + resa + min((rest - resa * a) / b, 1ll * resb),                     1ll * ans);         else           ans = max(f[0] + f[1] + rest / a, 1ll * ans);       }       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:66777216 )   using namespace std;   const double eps = 1e-7;   const double pi = acos(-1.0);   const long long INF = (long long)2e9 + 1;   const long long LINF = (long long)8e18;   const long long inf = (long long)2e9 + 1;   const long long linf = (long long)8e18;   const long long MM = (long long)1e9 + 7;   int solve();   void gen();   int main() {     solve();     return 0;   }   const int dd = 3e5 + 7;   int get(int t) {     while (t < 0) t += 360;     while (t > 360) t -= 360;     return min(t, 360 - t);   }   int solve() {     long long x;     cin >> x;     x *= -1;     x %= 360;     vector<pair<int, int> > M;     M.push_back(make_pair(get(x), 0));     M.push_back(make_pair(get(x + 90), 1));     M.push_back(make_pair(get(x + 180), 2));     M.push_back(make_pair(get(x + 270), 3));     sort(M.begin(), M.end());     cout << M[0].second;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 10 + 1e6;   const int INF = 1e9 + 10;   long long a, b;   map<long long, int> f;   map<long long, long long> dad;   long long ans[100];   void dfs(long long x, int s) {     if (x > b) return;     if (f[2 * x] == 0 || f[2 * x] > s + 1) {       dad[2 * x] = x;       f[2 * x] = s + 1;       dfs(2 * x, s + 1);     }     if (f[10 * x + 1] == 0 || f[10 * x + 1] > s + 1) {       dad[10 * x + 1] = x;       f[10 * x + 1] = s + 1;       dfs(10 * x + 1, s + 1);     }   }   int main() {     cin >> a >> b;     dad[a] = a;     dfs(a, 1);     if (f[b] == 0)       cout <<  NO ;     else {       cout <<  YES  << endl;       int l = 0;       while (dad[b] != b) {         ans[++l] = b;         b = dad[b];       }       l++;       ans[l] = a;       cout << l << endl;       for (int i = (l), _b = (1); i >= _b; i--) cout << ans[i] <<    ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s, t;     cin >> s >> t;     for (int i = 0; i < s.size(); i++) {       if (s[i] == t[s.size() - i - 1]) {         continue;       } else {         cout <<  NO ;         return 0;       }     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a, b;   int main() {     cin >> n >> a >> b;     long long chores[n];     for (int i = 0; i < n; i++) cin >> chores[i];     sort(chores, chores + n);     cout << chores[b] - chores[b - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       double n, x;       cin >> n >> x;       vector<double> a(n);       for (__typeof(n) i = 0; i < n; i++) {         cin >> a[i];       }       sort(a.rbegin(), a.rend());       a.push_back(0);       double no = 1, am = a[0];       while ((am / no >= x) && (no <= n)) {         am += a[no];         no++;       }       cout << no - 1 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int fromStrtoInt(string s, string c) {     int x = 0;     for (int i = 0; i < c.size(); i++) {       x *= 10;       x += s[c[i] -  0 ] -  0 ;     }     return x;   }   int main() {     int n, k;     cin >> n >> k;     string s, arr[n];     for (int i = 0; i < n; i++) cin >> arr[i];     for (int i = 0; i < k; i++) s += i +  0 ;     int a[n];     int ans = 1e9;     do {       for (int i = 0; i < n; i++) a[i] = fromStrtoInt(arr[i], s);       sort(a, a + n);       ans = min(ans, a[n - 1] - a[0]);     } while (next_permutation(s.begin(), s.end()));     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int full = 0;   long long int arr[51][51];   long long int n, t;   void solve(long long int i, long long int j, long long int level) {     if (level > n - 1) {       return;     } else {       if (arr[i][j] < (1ll << level)) {         arr[i][j]++;         if (arr[i][j] == (1ll << level)) {           full++;         }       } else {         solve(i + 1, j + 1, level + 1);         solve(i + 1, j, level + 1);       }     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> t;     for (long long int i = 0; i < 10ll; i++) {       for (long long int j = 0; j < 10ll; j++) {         arr[i][j] = 0;       }     }     for (long long int i = 1; i <= t; i++) {       solve(0, 0, 0);     }     cout << full << endl;   }
#include <bits/stdc++.h>   using namespace std;   int V[102][102], M2[2][102];   int main() {     int n, a;     scanf( %d , &n);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         scanf( %d , &a);         M2[0][i] += a;         M2[1][j] += a;       }     int cnt = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (M2[0][i] < M2[1][j]) cnt++;     cout << cnt << endl;   }
#include <bits/stdc++.h>   unsigned long long c;   int n, i, j, k, ks, ke, pd, pp, pa;   char s[1000100];   bool f, ff, fff;   int main() {     scanf( %s , s);     n = strlen(s);     for (i = 0; i < n; i++) {       if (s[i] >=  a  && s[i] <=  z ) {         k = 0, f = 1, ff = 0, fff = 0, ks = 1, ke = 0, pa = 0, pd = 0, pp = 0;         for (j = i + 1; f && j < n; j++) {           if (!k) {             if (s[j] ==  @ )               ++k, pa = j;             else if (!((s[j] >=  a  && s[j] <=  z ) ||                        (s[j] >=  0  && s[j] <=  9 ) || s[j] ==  _ ))               f = 0;             else if (s[j] >=  a  && s[j] <=  z )               ++ks;           } else if (k == 1) {             if (s[j] ==  . )               ++k, pd = j;             else if ((s[j] >=  a  && s[j] <=  z ) || (s[j] >=  0  && s[j] <=  9 ))               ff = 1;             else               f = 0;           } else {             if (s[j] >=  a  && s[j] <=  z )               fff = 1, ++ke, pp = j;             else               f = 0;           }         }         if (ff && fff) c += (unsigned long long)ks * ke;         if (pa)           i = pa;         else if (pd)           i = pd;         else if (pp)           i = pp - 1;         else           i = j - 1;       }     }     printf( %I64u n , c);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2000;   int n, i, j;   char s[maxn];   long long F[maxn][maxn];   long long P[maxn];   int main() {     scanf( %d , &n);     scanf( %s , s);     P[1] = 1;     for (i = 2; i <= 18; ++i) P[i] = 10LL * P[i - 1];     memset(F, 0, sizeof F);     for (i = 0; i <= n; ++i)       for (j = 0; j <= n; ++j) {         if (i)           F[i][j] =               max(F[i][j], F[i - 1][j] + P[i - 1] * (s[n + n - i - j] -  0 ));         if (j)           F[i][j] =               max(F[i][j], F[i][j - 1] + P[j - 1] * (s[n + n - i - j] -  0 ));       }     i = n, j = n;     while (i || j) {       if (i && F[i][j] == (F[i - 1][j] + P[i - 1] * (s[n + n - i - j] -  0 )))         putchar( H ), --i;       else         putchar( M ), --j;     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   int n, from[300005], p[300005], dis[300005], a[300005], b[300005];   std::queue<int> que;   std::set<int, std::greater<int>> l;   void work(int now) {     if (now != n) work(from[now]), std::cout << p[now] <<    ;   }   void print(int now) {     std::cout << dis[now] + 1 << std::endl;     work(now);     std::cout << 0 << std::endl;     exit(0);   }   signed main() {     std::ios::sync_with_stdio(false);     std::cin >> n;     for (int i = 1; i <= n; ++i) std::cin >> a[i];     for (int i = 1; i <= n; ++i) std::cin >> b[i];     for (int i = 0; i <= n; ++i) l.insert(i);     std::fill(dis, dis + n, INT_MAX);     que.push(n);     while (!que.empty()) {       int now = que.front();       que.pop();       if (now - a[now] <= 0) print(now);       for (std::set<int>::iterator i = l.lower_bound(now);            i != l.end() && now - *i <= a[now]; l.erase(i++)) {         int tmp = *i + b[*i];         if (dis[tmp] > dis[now] + 1)           dis[tmp] = dis[now] + 1, p[tmp] = *i, from[tmp] = now, que.push(tmp);       }     }     std::cout << -1 << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MAX = -1000000000000000000;   const long long MIN = 1000000000000000000;   const long long inf = 1000000000;   const long long KOK = 100000;   const long long LOG = 30;   const long long li = 500005;   const long long mod = 1000000007;   int n, m, b[li], a[li], k, flag, t, yes, say, ind, cev1, mn, cev2;   int cev;   string s;   vector<int> v;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> s;     for (int i = 0; i < (int)s.size(); i++) {       if (s[i] ==  # ) {         say++;         ind = i;       }     }     for (int i = 0; i < (int)s.size(); i++) {       if (ind == i) {         if (cev <= 0) {           printf( -1 n );           return 0;         }         a[1] = cev;         cev = 0;         continue;       }       if (i > ind) {         if (s[i] ==  ( )           cev++;         else if (s[i] ==  )  && cev > 0) {           cev--;         } else if (s[i] ==  )  && a[1] > 1) {           a[1]--;         } else {           printf( -1 n );           return 0;         }       } else {         if (s[i] ==  ( )           cev++;         else           cev--;         if (cev < 0) {           printf( -1 n );           return 0;         }       }     }     if (cev > 0) {       printf( -1 n );       return 0;     }     for (int i = 1; i < say; i++) printf( 1 n );     printf( %d n , a[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n, k;     cin >> n >> k;     long long a;     int g = 0;     for (int i = 0; i < n; i++) {       cin >> a;       set<int> d;       while (a) {         if (a % 10 <= k) {           d.insert(a % 10);         }         a /= 10;       }       if (d.size() == k + 1) {         g++;       }     }     cout << g;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     set<int> st;     for (int i = 2; i <= n; i++) {       int a = i;       for (int j = 2; j * j <= a; j++) {         int num = 1;         while (a % j == 0 and a > 1) {           a /= j;           num *= j;         }         if (num != 1) st.insert(num);       }       if (a > 1) st.insert(a);     }     cout << st.size() << endl;     for (auto item : st) cout << item <<    ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T &x, T y) {     x = x > y ? x : y;   }   template <typename T>   void chkmin(T &x, T y) {     x = x > y ? y : x;   }   const int INF = (1ll << 30);   template <typename T>   void read(T &x) {     x = 0;     bool f = 1;     char ch;     do {       ch = getchar();       if (ch ==  - ) f = 0;     } while (ch >  9  || ch <  0 );     do {       x = x * 10 + ch -  0 ;       ch = getchar();     } while (ch >=  0  && ch <=  9 );     x = f ? x : -x;   }   template <typename T>   void write(T x) {     if (x < 0) x = ~x + 1, putchar( - );     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   const int N = 5000 + 5;   const int M = 1e5 + 7;   map<int, int> mp;   int n, m, ans, cnt, a[N], b[N], g[N], f[N], prime[M];   bool vis[M];   inline int gcd(int a, int b) {     if (a < b) swap(a, b);     return b == 0 ? a : gcd(b, a % b);   }   inline void init(int NN) {     for (int i = 2; i <= NN; i++) {       if (!vis[i]) {         prime[++cnt] = i;       }       for (int j = 1; j <= cnt && prime[j] * i <= NN; j++) {         vis[prime[j] * i] = true;         if (i % prime[j] == 0) break;       }     }   }   inline int divide(int x) {     if (mp.count(x)) return mp[x];     int p = 0, tp = x;     for (int i = 1; i <= m && b[i] <= x; i++) {       while (x % b[i] == 0) x /= b[i], p--;     }     for (int i = 1; i <= cnt && 1ll * prime[i] * prime[i] <= x; i++) {       while (x % prime[i] == 0) x /= prime[i], p++;     }     if (x != 1) p++;     return mp[tp] = p;   }   int main() {     read(n);     read(m);     for (int i = 1; i <= n; i++) read(a[i]), g[i] = gcd(a[i], g[i - 1]);     for (int i = 1; i <= m; i++) read(b[i]);     init(1e5);     ans = 0;     for (int i = 1; i <= n; i++) ans += divide(a[i]);     for (int i = 1; i <= n; i++) f[i] = ans - i * divide(g[i]);     for (int i = n; i >= 1; i--) {       ans = max(ans, f[i]);       for (int j = i - 1; j >= 1; j--) {         int gg = g[j] / g[i];         f[j] = max(f[j], f[i] - j * divide(gg));         chkmax(ans, f[j]);       }     }     printf( %d n , ans);     return 0;   }