malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   struct Pt {     long long int x, y;     friend ostream& operator<<(ostream& os, const Pt& a) {       os << a.x <<     << a.y;       return os;     }   };   struct R {     long long int a, b, c;   };   int main() {     ios::sync_with_stdio(false);     long long int N, K;     cin >> N >> K;     vector<long long int> w[4];     for (long long int i = 0; i < (long long int)(4); ++i)       w[i] = vector<long long int>(N);     vector<Pt> wp[4];     for (long long int i = 0; i < (long long int)(4); ++i) wp[i] = vector<Pt>(N);     for (long long int i = 0; i < (long long int)(4); ++i)       for (int j = 0; j < N; ++j) wp[i][j] = {i + 1, j + 1};     for (long long int i = 0; i < (long long int)(4); ++i)       for (int j = 0; j < N; ++j) cin >> w[i][j];     vector<long long int> a[2];     for (long long int i = 0; i < (long long int)(2); ++i)       a[i] = vector<long long int>(2 * N);     vector<Pt> p[2];     for (long long int i = 0; i < (long long int)(2); ++i)       p[i] = vector<Pt>(2 * N);     for (long long int i = 0; i < (long long int)(N); ++i) a[0][i] = w[0][i];     for (long long int i = 0; i < (long long int)(N); ++i)       a[0][N + i] = w[3][N - 1 - i];     for (long long int i = 0; i < (long long int)(N); ++i) a[1][i] = w[1][i];     for (long long int i = 0; i < (long long int)(N); ++i)       a[1][N + i] = w[2][N - 1 - i];     for (long long int i = 0; i < (long long int)(N); ++i) p[0][i] = wp[0][i];     for (long long int i = 0; i < (long long int)(N); ++i)       p[0][N + i] = wp[3][N - 1 - i];     for (long long int i = 0; i < (long long int)(N); ++i) p[1][i] = wp[1][i];     for (long long int i = 0; i < (long long int)(N); ++i)       p[1][N + i] = wp[2][N - 1 - i];     N *= 2;     vector<R> res;     for (int t = 0; t < 151; ++t) {       long long int c = 0;       for (long long int i = 0; i < (long long int)(N); ++i) {         if (a[1][i] != 0 && a[1][i] == a[0][i]) {           res.push_back({a[1][i], p[0][i].x, p[0][i].y});           a[1][i] = 0;         }         if (a[1][i] == 0) c++;       }       if (c == N) break;       if (c == 0 || t == 150) {         cout << -1 << endl;         return 0;       }       int j = 0;       for (; j < N; ++j)         if (a[1][j] == 0) break;       for (int i = 0; i < N - 1; ++i) {         long long int w = (j + i) % N;         long long int q = (j + i + 1) % N;         if (a[1][q] != 0) {           res.push_back({a[1][q], p[1][w].x, p[1][w].y});           a[1][w] = a[1][q];           a[1][q] = 0;         }       }     }     cout << res.size() << endl;     for (long long int i = 0; i < (long long int)(res.size()); ++i) {       cout << res[i].a <<     << res[i].b <<     << res[i].c <<     << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int length;     cin >> length;     int query;     cin >> query;     string result;     cin >> result;     for (int i = 0; i < query; ++i) {       int left;       int right;       cin >> left >> right;       char which;       char what;       cin >> which >> what;       for (int j = left; j <= right; ++j)         if (result[j - 1] == which) result[j - 1] = what;     }     cout << result;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long int n, x, y, cn = 0, ans = 0;     string s;     cin >> n >> x >> y >> s;     for (int i = 0; i < n; i++) {       if (s[i] ==  0 )         cn++;       else {         if (cn) ans++;         cn = 0;       }     }     if (cn) ans++;     if (!ans)       cout << 0 << endl;     else       cout << (ans - 1) * min(x, y) + y << endl;     return 0;   }
#include <bits/stdc++.h>   long long MOD = 1000000007;   using namespace std;   bool sortbysec(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.second < b.second);   }   long long POW(long long a, long long b) {     if (b == 0) return 1;     if (b == 1) return a % MOD;     long long temp = POW(a, b / 2);     if (b % 2 == 0)       return (temp * temp) % MOD;     else       return (((temp * temp) % MOD) * a) % MOD;   }   vector<char> capl = { A ,  B ,  C ,  D ,  E ,  F ,  G ,  H ,  I ,                         J ,  K ,  L ,  M ,  N ,  O ,  P ,  Q ,  R ,                         S ,  T ,  U ,  V ,  W ,  X ,  Y ,  Z };   vector<char> sml = { a ,  b ,  c ,  d ,  e ,  f ,  g ,  h ,  i ,                        j ,  k ,  l ,  m ,  n ,  o ,  p ,  q ,  r ,                        s ,  t ,  u ,  v ,  w ,  x ,  y ,  z };   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       map<int, int> m;       for (int i = 1; i < 201; i++) {         m[i]++;       }       for (int i = 0; i < n; i++) {         cin >> arr[i];         m[arr[i]]--;       }       int b[2 * n];       for (int i = 0; i < n; i++) {         b[2 * i] = arr[i];         for (auto x : m) {           if (x.first > arr[i] && x.second != 0) {             b[2 * i + 1] = x.first;             m[x.first] = 0;             break;           }         }       }       int c[2 * n], f = 0;       copy(b, b + 2 * n, c);       sort(c, c + 2 * n);       for (int i = 0; i < 2 * n; i++) {         if (c[i] != i + 1) {           f = 1;           break;         }       }       if (f == 1) {         cout <<  -1 n ;       } else {         for (int i = 0; i < 2 * n; i++) {           cout << b[i] <<    ;         }         cout <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T sqr(T x) {     return x * x;   }   template <typename T>   T abs(T x) {     return x < 0 ? -x : x;   }   template <typename T>   T gcd(T a, T b) {     return b ? gcd(b, a % b) : a;   }   const int MAXN = 1e5 + 10;   int n;   int sum = 0;   pair<int, int> a[200000];   int col[MAXN];   int cost[300];   int ans = 2000000007;   inline bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first < b.first) return true;     if (a.first == b.first) return a.second > b.second;     return false;   }   int main() {     ios_base ::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i].first, col[a[i].first]++;     for (int i = 1; i <= n; i++) cin >> a[i].second, cost[a[i].second]++;     sort(a + 1, a + n + 1);     if (n == 1) {       cout << 0;       return 0;     }     if (n == 2) {       if (a[1].first != a[2].first)         cout << min(a[1].second, a[2].second);       else         cout << 0;       return 0;     }     a[0].first = 2000000007;     int s = 0;     for (int i = n; i; i--) {       s += a[i].second;       cost[a[i].second]--;       if (a[i].first != a[i - 1].first) {         int c = 0, del = max(0, i - col[a[i].first]);         for (int j = 1; j <= 200; j++) {           int r = min(del, cost[j]);           c += j * r, del -= r;           if (!del) break;         }         ans = min(ans, sum + c);         sum += s, s = 0;       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 10;   struct Node {     int is, id, x;     bool operator<(const Node &a) const {       if (x != a.x)         return x < a.x;       else         return is < a.is;     }   };   int a[maxn * 4], s[maxn], p[maxn], inc[maxn], b[maxn], treea[maxn * 4],       treeb[maxn * 4], pb[maxn];   int ans[maxn];   map<int, int> ma;   int cnt = 0, tt = 0;   Node que[maxn * 3];   int getid(int x) {     x = -x;     return ma[x];   }   void add1(int x, int y) {     for (int i = x; i < 4 * maxn; i += (i & -i)) treea[i] += y;   }   void add2(int x, int y) {     for (int i = x; i < 4 * maxn; i += (i & -i)) treeb[i] += -y;   }   int quer1(int x) {     int res = 0;     for (int i = x; i >= 1; i -= (i & -i)) res += treea[i];     return res;   }   int quer2(int x) {     int res = 0;     for (int i = x; i >= 1; i -= (i & -i)) res += treeb[i];     return res;   }   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &p[i]);     for (int i = 1; i <= n; i++) scanf( %d , &s[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     for (int i = 1; i <= m; i++) scanf( %d , &inc[i]);     for (int i = 1; i <= m; i++) scanf( %d , &pb[i]);     for (int i = 1; i <= n; i++) {       a[++cnt] = -(p[i] + b[i] - 1), a[++cnt] = -(b[i] - p[i]);       que[++tt] = Node{0, i, p[i]};       que[++tt] = Node{2, i, s[i]};     }     for (int i = 1; i <= m; i++) {       a[++cnt] = -(inc[i] + pb[i]), a[++cnt] = -(pb[i] - inc[i]);       que[++tt] = Node{1, i, inc[i]};     }     sort(que + 1, que + 1 + tt);     sort(a + 1, a + cnt + 1);     int pz = 1;     for (int i = 1; i <= cnt; i++)       if (ma[a[i]] == 0) ma[a[i]] = pz++;     for (int i = 1; i <= tt; i++) {       Node now = que[i];       if (now.is == 0) {         add1(getid(b[now.id] - p[now.id]), 1);         add2(getid(p[now.id] + b[now.id] - 1), 1);       } else if (now.is == 1) {         ans[now.id] = quer1(getid(pb[now.id] - inc[now.id])) +                       quer2(getid(inc[now.id] + pb[now.id]));       } else if (now.is == 2) {         add1(getid(b[now.id] - p[now.id]), -1);         add2(getid(p[now.id] + b[now.id] - 1), -1);       }     }     for (int i = 1; i <= m; i++) {       printf( %d  , ans[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int p, q, l, r;     cin >> p >> q >> l >> r;     vector<pair<int, int> > z_timing, x_timing;     int start, stop;     for (int i = 0; i < p; i++) {       cin >> start >> stop;       z_timing.push_back(make_pair(start, stop));     }     for (int i = 0; i < q; i++) {       cin >> start >> stop;       x_timing.push_back(make_pair(start, stop));     }     int answer = 0;     for (int i = l; i <= r; i++) {       for (int j = 0; j < q; j++) {         bool has_intersected = false;         start = x_timing[j].first + i;         stop = x_timing[j].second + i;         for (int k = 0; k < p; k++) {           if (start <= z_timing[k].second && stop >= z_timing[k].first) {             answer++;             has_intersected = true;             break;           }         }         if (has_intersected == true) {           break;         }       }     }     cout << answer;     return 0;   }
// vaziat meshki-ghermeze !   #include <bits/stdc++.h>      #define pb push_back   #define F first   #define S second   #define all(x) x.begin(), x.end()   #define debug(x) cerr << #x <<   :   << x <<   n       using namespace std;      typedef long long ll;   typedef long double ld;   typedef string str;   typedef pair<ll, ll> pll;      const ll Mod = 1000000007LL;   const int N = 2e5 + 10;   const ll Inf = 2242545357980376863LL;   const ll Log = 30;      pll A[N];   ll dis(ll i, ll j){    return (A[i].F - A[j].F)*(A[i].F - A[j].F) + (A[i].S - A[j].S)*(A[i].S - A[j].S);   }   ll mk[N];   int main(){    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);    int n;    cin >> n;    pll mn = {Inf, Inf};    ll idx = -1;    for(int i = 1; i <= n; i++){     cin >> A[i].F >> A[i].S;     if(A[i] < mn){      mn = A[i];      idx = i;     }    }    cout << idx <<    ;    mk[idx] = 1;    for(int i = 2; i <= n; i++){     ll mx = -1;     ll id = -1;     for(int j = 1; j <= n; j++){      if(mk[j]) continue;      if(mx < dis(idx, j)){       mx = dis(idx, j);       id = j;      }     }     idx = id;     mk[id] = 1;     cout << idx <<    ;    }    cout <<   n ;    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int SZ = 1e6 + 10;   const int INF = 1e9 + 10;   const int mod = 998244353;   const long double eps = 1e-8;   long long read() {     long long n = 0;     char a = getchar();     bool flag = 0;     while (a >  9  || a <  0 ) {       if (a ==  - ) flag = 1;       a = getchar();     }     while (a <=  9  && a >=  0 ) {       n = n * 10 + a -  0 , a = getchar();     }     if (flag) n = -n;     return n;   }   struct seg {     int l, r, mx, add;   } tree[SZ * 4];   void update(int p) { tree[p].mx = max(tree[p << 1].mx, tree[p << 1 | 1].mx); }   void build(int p, int l, int r) {     tree[p].l = l;     tree[p].r = r;     if (l == r) return;     int mid = l + r >> 1;     build(p << 1, l, mid);     build(p << 1 | 1, mid + 1, r);     update(p);   }   void pushadd(int p, int d) {     tree[p].add += d;     tree[p].mx += d;   }   void pushdown(int p) {     if (tree[p].add) {       pushadd(p << 1, tree[p].add);       pushadd(p << 1 | 1, tree[p].add);       tree[p].add = 0;     }   }   void change(int p, int l, int r, int d) {     if (l <= tree[p].l && tree[p].r <= r) {       pushadd(p, d);       return;     }     pushdown(p);     int mid = tree[p].l + tree[p].r >> 1;     if (l <= mid) change(p << 1, l, r, d);     if (mid < r) change(p << 1 | 1, l, r, d);     update(p);   }   struct haha {     int pos, x, y, d;   } l[SZ];   bool cmp(haha a, haha b) { return a.pos < b.pos; }   int lsh[SZ];   int main() {     int n = read(), m = read(), tot = 0;     for (int i = 1; i <= n; i++) {       int a = read(), b = read(), x, y;       x = a + b;       y = a - b;       l[++tot] = (haha){x - m, y - m, y + m, 1};       l[++tot] = (haha){x + m + 1, y - m, y + m, -1};     }     for (int i = 1; i <= tot; i++) {       lsh[++lsh[0]] = l[i].x;       lsh[++lsh[0]] = l[i].y;     }     sort(lsh + 1, lsh + 1 + lsh[0]);     lsh[0] = unique(lsh + 1, lsh + 1 + lsh[0]) - lsh - 1;     for (int i = 1; i <= tot; i++) {       l[i].x = lower_bound(lsh + 1, lsh + 1 + lsh[0], l[i].x) - lsh;       l[i].y = lower_bound(lsh + 1, lsh + 1 + lsh[0], l[i].y) - lsh;     }     int ans = 0;     build(1, 1, lsh[0]);     sort(l + 1, l + 1 + tot, cmp);     for (int i = 1, lst = 1; i <= tot; i++) {       if (i == tot || l[i + 1].pos != l[i].pos) {         for (int j = lst; j <= i; j++) {           change(1, l[j].x, l[j].y, l[j].d);         }         ans = max(ans, tree[1].mx);         lst = i + 1;       }     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     vector<int> a(n);     for (int i = 0; i < n; ++i) {       cin >> a[i];     }     vector<int> poss;     for (int i = 0; i < n; ++i) {       int x = a[i];       while (x > 0) {         poss.push_back(x);         x /= 2;       }     }     int ans = 1e9;     for (auto res : poss) {       vector<int> cnt;       for (int i = 0; i < n; ++i) {         int x = a[i];         int cur = 0;         while (x > res) {           x /= 2;           ++cur;         }         if (x == res) {           cnt.push_back(cur);         }       }       if (int(cnt.size()) < k) continue;       sort(cnt.begin(), cnt.end());       ans = min(ans, accumulate(cnt.begin(), cnt.begin() + k, 0));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> v(n);     for (int i = 0; i < n; i++) cin >> v[i];     sort(v.begin(), v.end());     int l = v[n - 1], q = v[n - 2];     int d = 0;     for (int i = 0; i < n - 2; i++) {       if (q > i + 1) d = i + 1;     }     cout << d << endl;   }   int main() {     std::ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (int i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   int main() {     long long p, y;     cin >> p >> y;     int flag = 1;     for (long long j = y; j > p; j--) {       flag = 0;       for (long long k = 2; k <= p && k * k <= j; k++) {         if (j % k == 0) {           flag = 1;           break;         }       }       if (flag == 0) {         cout << j;         return 0;       }     }     cout << -1;   }
#include <bits/stdc++.h>   using namespace std;   bool b[4000000];   int main() {     int n, cnt, x[2007], y[2007];     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> x[i];       b[x[i]] = 1;     }     for (int i = 1; i <= n; i++) {       cin >> y[i];       b[y[i]] = 1;     }     cnt = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++)         if (b[x[i] ^ y[j]]) cnt++;     }     if (cnt % 2)       puts( Koyomi );     else       puts( Karen );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 5000 + 5, mod = 1000 * 1000 * 1000 + 7;   long long dp[N][N], ps[N];   int main() {     long long n, a, b, k;     cin >> n >> a >> b >> k;     a--, b--;     for (int i = 0; i < n; i++) {       dp[0][i] = 1;     }     dp[0][b] = 0;     for (int i = 0; i < n; i++) {       ps[i + 1] = ps[i] + dp[0][i];       ps[i + 1] %= mod;     }     for (int i = 1; i <= k; i++) {       for (int j = 0; j < n; j++) {         if (j < b) {           dp[i][j] =               (ps[b] - ps[j + 1]) + (ps[j] - ps[max(0 * 1ll, j - (b - j) + 1)]);           dp[i][j] += 2 * mod;           dp[i][j] %= mod;         } else {           dp[i][j] = (ps[j] - ps[b + 1]) + (ps[min(n, j + (j - b))] - ps[j + 1]);           dp[i][j] += 2 * mod;           dp[i][j] %= mod;         }       }       ps[0] = 0;       for (int j = 0; j < n; j++) {         ps[j + 1] = ps[j] + dp[i][j];         ps[j + 1] += 2 * mod;         ps[j + 1] %= mod;       }     }     cout << dp[k][a] % mod;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   long long f[maxn], a[maxn];   int n;   map<long long, long long> pre, sum;   vector<long long> ans;   void fir() {     int st = 1;     while (st <= n) {       sum.clear();       pre.clear();       stack<long long> s;       for (int& i = st; i <= n; i++) {         if (pre[a[i]]) {           ans.push_back(pre[a[i]]);           ans.push_back(a[i]);           ans.push_back(pre[a[i]]);           ans.push_back(a[i]);           break;         }         while (!s.empty() &&                (sum[a[i]] > 1 || (sum[a[i]] == 1 && s.top() != a[i]))) {           pre[s.top()] = a[i];           sum[s.top()]--;           s.pop();         }         s.push(a[i]);         sum[a[i]]++;       }       st++;     }     printf( %d n , ans.size());     for (int i = 0; i < ans.size(); i++) {       printf( %I64d , ans[i]);       if (i == ans.size() - 1) {         printf(  n );       } else         printf(   );     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , &a[i]);     }     fir();   }
#include <bits/stdc++.h>   using namespace std;   int gi() {     int f = 1, x = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return f == 1 ? x : -x;   }   const int N = 1005;   int n, m, r, c;   double a[N][N], x[N];   void get_solution() {     for (int i = (1); i <= (m); ++i) {       double r = a[i + 1][i] / a[i][i];       a[i + 1][i] -= r * a[i][i];       a[i + 1][i + 1] -= r * a[i][i + 1];       a[i + 1][m + 1] -= r * a[i][m + 1];     }     for (int i = (m); i >= (1); --i) {       double r = a[i - 1][i] / a[i][i];       a[i - 1][i] = 0;       a[i - 1][m + 1] -= r * a[i][m + 1];       x[i] = a[i][m + 1] / a[i][i];     }   }   int main() {     n = gi(), m = gi(), r = gi(), c = gi();     if (m == 1)       return cout << fixed << setprecision(10) << (n - r) * 2 << endl, 0;     if (r == n) return puts( 0.0000000000 ), 0;     for (int _ = (n - 1); _ >= (1); --_) {       for (int i = (1); i <= (m); ++i) {         if (i == 1) {           a[i][i] = 2. / 3;           a[i][i + 1] = -1. / 3;           a[i][m + 1] = 1. / 3 * x[i] + 1;         } else if (i == m) {           a[i][i] = 2. / 3;           a[i][i - 1] = -1. / 3;           a[i][m + 1] = 1. / 3 * x[i] + 1;         } else {           a[i][i] = 3. / 4;           a[i][i + 1] = -1. / 4;           a[i][i - 1] = -1. / 4;           a[i][m + 1] = 1. / 4 * x[i] + 1;         }       }       get_solution();       if (_ == r) return cout << fixed << setprecision(10) << x[c] << endl, 0;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, c, d;     cin >> a >> b >> c >> d;     int p1 = max((3 * a) / 10, a - ((a / 250) * c));     int p2 = max((3 * b) / 10, b - ((b / 250) * d));     if (p1 == p2)       cout <<  Tie  << endl;     else if (p1 > p2)       cout <<  Misha  << endl;     else       cout <<  Vasya  << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 3005;   int a[MAX], b[MAX], c[MAX], dp[MAX][2];   int main() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) cin >> b[i];     for (int i = 1; i <= n; i++) cin >> c[i];     dp[1][0] = a[1];     dp[1][1] = b[1];     for (int i = 2; i <= n; i++) {       dp[i][0] = dp[i - 1][0] + b[i];       dp[i][1] = dp[i - 1][0] + c[i];       dp[i][0] = max(dp[i][0], dp[i - 1][1] + a[i]);       dp[i][1] = max(dp[i][1], dp[i - 1][1] + b[i]);     }     cout << dp[n][0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; i++) cin >> a[i];       sort(a, a + n);       long long flg = 0;       for (long long i = 0; i < n - 1; i++)         if (a[i] == a[i + 1]) flg = 1;       if (flg)         cout <<  YES  << endl;       else         cout <<  NO  << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1012345678;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     int N, Q;     cin >> N >> Q;     vector<vector<int> > g(N);     int limit = 0;     for (int i = 0; i < N; ++i) {       int x, rad = 1;       cin >> x;       for (int j = 2; j * j <= x; ++j) {         int cnt = 0;         while (x % j == 0) x /= j, cnt ^= 1;         if (cnt == 1) g[i].push_back(j), rad *= j;       }       if (x > 1) g[i].push_back(x), rad *= x;       limit = max(limit, rad);     }     vector<vector<pair<int, int> > > qs(N + 1);     for (int i = 0; i < Q; ++i) {       int L, R;       cin >> L >> R;       --L;       qs[R].push_back(make_pair(L, i));     }     vector<vector<int> > curopt(limit + 1, vector<int>(8, -inf));     vector<int> curbound(15, -inf);     vector<int> ans(Q);     for (int i = 0; i < N; ++i) {       for (int j = 0; j < 1 << g[i].size(); ++j) {         int rem = 0, mul = 1;         for (int k = 0; k < g[i].size(); ++k) {           if ((j >> k) & 1)             mul *= g[i][k];           else             ++rem;         }         for (int k = 0; k <= 7; ++k) {           curbound[rem + k] = max(curbound[rem + k], curopt[mul][k]);         }         curopt[mul][rem] = i;       }       for (pair<int, int> j : qs[i + 1]) {         for (int k = 0; k <= 14; ++k) {           if (curbound[k] >= j.first) {             ans[j.second] = k;             break;           }         }       }     }     for (int i = 0; i < Q; ++i) {       cout << ans[i] <<   n ;     }     return 0;   }