malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 200000 + 5;   const int mod = 1000000000;   int a[N], f[N];   int main() {     int n, m, type, x, v, l, r, d, sum;     scanf( %d%d , &n, &m);     f[0] = f[1] = 1;     for (int i = 2; i < n; ++i) f[i] = (f[i - 1] + f[i - 2]) % mod;     for (int i = 0; i < n; ++i) scanf( %d , &a[i]);     for (int i = 0; i < m; ++i) {       scanf( %d , &type);       if (type == 1) {         scanf( %d%d , &x, &v);         x--;         a[x] = v;       } else if (type == 2) {         scanf( %d%d , &l, &r);         sum = 0;         r--;         l--;         for (int j = 0; j <= r - l; ++j) {           sum = (sum + (long long)(f[j]) * (long long)(a[l + j])) % mod;         }         cout << sum << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<long long, long long> > bl;   long long fact[200005];   long long ifact[200005];   long long invert_mod(long long a, long long p) {     long long n = 1, old = 0, q = p, r, h;     bool pos = false;     while (a > 0) {       r = q % a;       q = q / a;       h = q * n + old;       old = n;       n = h;       q = a;       a = r;       pos = !pos;     }     return pos ? old : (p - old);   }   void calc_fact() {     fact[0] = fact[1] = 1;     ifact[0] = ifact[1] = 1;     for (long long i = 2; i < 200005; i++) {       fact[i] = (i * fact[i - 1]) % 1000000007;       ifact[i] = invert_mod(fact[i], 1000000007) % 1000000007;     }   }   int main(void) {     ios_base::sync_with_stdio(false);     long long h, w, n;     cin >> h >> w >> n;     calc_fact();     bl.resize(n);     for (int i = 0; i < n; i++) {       cin >> bl[i].first >> bl[i].second;     }     bl.push_back(make_pair(h, w));     vector<long long> dp(n + 1, 0);     sort(bl.begin(), bl.end());     dp[0] = ((fact[bl[0].first + bl[0].second - 2] * ifact[bl[0].first - 1]) %              1000000007 * ifact[bl[0].second - 1]) %             1000000007;     for (int i = 1; i <= n; i++) {       dp[i] = ((fact[bl[i].first + bl[i].second - 2] * ifact[bl[i].first - 1]) %                1000000007 * ifact[bl[i].second - 1]) %               1000000007;       long long ans = 0;       for (int j = 0; j < i; j++) {         long long val;         if (bl[i].second >= bl[j].second && bl[i].first >= bl[j].first)           val = ((fact[(bl[i].first + bl[i].second) -                        (bl[j].first + bl[j].second)] *                   ifact[bl[i].first - bl[j].first]) %                  1000000007 * ifact[bl[i].second - bl[j].second]) %                 1000000007;         else           val = 0;         ans = (ans + (dp[j] * val) % 1000000007) % 1000000007;       }       dp[i] = (dp[i] + (1000000007 - ans)) % 1000000007;     }     cout << dp[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300110;   const int mod = 1e9 + 9;   int n, m;   int sumv[maxn * 4];   int f1[maxn * 4];   int f2[maxn * 4];   int num[maxn];   int sum[maxn];   int f[maxn];   int addv(int a, int b, int n) {     return ((((long long)f[n + 1] * (long long)b) % mod +              ((long long)f[n] * (long long)a) % mod) %                 mod +             (mod - b) % mod) %            mod;   }   int get(int a, int b, int n) {     return ((long long)f[n - 1] * (long long)b +             ((long long)f[n - 2] * (long long)a) % mod) %            mod;   }   void maintain(int o, int l, int r) {     int lc = o * 2, rc = lc + 1;     sumv[o] = 0;     if (r > l) sumv[o] = (sumv[lc] + sumv[rc]) % mod;     sumv[o] =         ((sumv[o] + ((long long)f[r - l + 2] * (long long)(f2[o])) % mod) % mod +          ((((long long)f[r - l + 1] * (long long)(f1[o])) % mod +            (mod - f2[o]) % mod) %           mod)) %         mod;   }   void update(int o, int l, int r, int yl, int yr) {     int lc = o * 2, rc = lc + 1;     int m = l + (r - l) / 2;     if (yl <= l && yr >= r) {       f1[o] = (f1[o] + f[l - yl + 1]) % mod;       f2[o] = (f2[o] + f[l - yl + 2]) % mod;     } else {       if (yl <= m) update(lc, l, m, yl, yr);       if (yr > m) update(rc, m + 1, r, yl, yr);     }     maintain(o, l, r);   }   int _sum;   void query(int o, int l, int r, int ql, int qr, int add_f1, int add_f2) {     int lc = o * 2, rc = lc + 1;     int m = l + (r - l) / 2;     if (ql <= l && qr >= r) {       _sum = ((_sum + sumv[o]) % mod + addv(add_f1, add_f2, r - l + 1)) % mod;     } else {       if (ql <= m)         query(lc, l, m, ql, qr, (add_f1 + f1[o]) % mod, (add_f2 + f2[o]) % mod);       if (qr > m)         query(rc, m + 1, r, ql, qr,               get((add_f1 + f1[o]) % mod, (add_f2 + f2[o]) % mod, m + 2 - l),               get((add_f1 + f1[o]) % mod, (add_f2 + f2[o]) % mod, m + 3 - l));     }   }   int main() {     memset(sumv, 0, sizeof(sumv));     memset(f1, 0, sizeof(f1));     memset(f2, 0, sizeof(f2));     f[0] = 0;     f[1] = 1;     f[2] = 1;     for (int i = 3; i < maxn; ++i) f[i] = (f[i - 1] + f[i - 2]) % mod;     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; ++i) scanf( %d , &num[i]);     sum[0] = 0;     for (int i = 1; i <= n; ++i) sum[i] = (sum[i - 1] + num[i]) % mod;     int x, y, z;     for (int i = 0; i < m; ++i) {       scanf( %d%d%d , &x, &y, &z);       if (x == 1)         update(1, 1, n, y, z);       else {         _sum = 0;         query(1, 1, n, y, z, 0, 0);         _sum = (_sum + (sum[z] - sum[y - 1] + mod) % mod) % mod;         printf( %d n , _sum);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a;   int main() {     int b;     int k;     int s;     cin >> b;     cin >> k;     for (int i = 1; i <= k; i++) {       cin >> a;       s += a;     }     if (b % 2 == 0)       if (a % 2 == 0) {         cout <<  even ;       } else {         cout <<  odd ;       }     if (b % 2 == 1)       if (s % 2 == 0) {         cout <<  even ;       } else {         cout <<  odd ;       }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);   }   long long dotproduct(vector<long long>& a, vector<long long>& b) {     long long sum = 0;     for (long long i = 0; i < a.size(); i += 1) {       sum += a[i] * b[i];     }     return sum;   }   int main() {     fast();     long long px, py, pz;     long long x, y, z;     cin >> px >> py >> pz >> x >> y >> z;     px *= 2;     py *= 2;     pz *= 2;     x *= 2;     y *= 2;     z *= 2;     long long a1, a2, a3, a4, a5, a6;     cin >> a1 >> a2 >> a3 >> a4 >> a5 >> a6;     long long res = 0;     vector<long long> zoxnv = {0, -1, 0};     vector<long long> zox2nv = {0, 1, 0};     vector<long long> xoynv = {0, 0, -1};     vector<long long> xoy2nv = {0, 0, 1};     vector<long long> yoznv = {-1, 0, 0};     vector<long long> yoz2nv = {1, 0, 0};     vector<long long> seezox = {px - (x / 2), py, pz - (z / 2)};     if (dotproduct(seezox, zoxnv) > 0) {       res += a1;     }     vector<long long> seezox2 = {px - (x / 2), py - y, pz - (z / 2)};     if (dotproduct(seezox2, zox2nv) > 0) {       res += a2;     }     vector<long long> seexoy = {px - (x / 2), py - (y / 2), pz};     if (dotproduct(seexoy, xoynv) > 0) {       res += a3;     }     vector<long long> seexoy2 = {px - (x / 2), py - (y / 2), pz - z};     if (dotproduct(seexoy2, xoy2nv) > 0) {       res += a4;     }     vector<long long> seeyoz = {px, py - (y / 2), pz - (z / 2)};     if (dotproduct(seeyoz, yoznv) > 0) {       res += a5;     }     vector<long long> seeyoz2 = {px - x, py - (y / 2), pz - (z / 2)};     if (dotproduct(seeyoz2, yoz2nv) > 0) {       res += a6;     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   int first(int a) {     int x = 1;     while (a) {       if (a % 10) x *= a % 10;       a /= 10;     }     return x;   }   int main() {     int q;     cin >> q;     vector<vector<int> > m(int(1e6 + 1));     for (int i = 0; i < int(1e6 + 1); ++i) m[i].resize(10);     vector<int> par(int(1e6 + 1));     for (int i = 1; i < int(1e6 + 1); ++i) {       int z = first(i);       while (z >= 10) {         z = par[z];       }       par[i] = z;       m[i][z]++;       for (int j = 0; j < 10; ++j) {         m[i][j] += m[i - 1][j];       }     }     while (q--) {       int l, r, k;       cin >> l >> r >> k;       cout << m[r][k] - m[l - 1][k] << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int Max(int a, int b) { return a > b ? a : b; }   int Min(int a, int b) { return a < b ? a : b; }   char s[10][10];   int n, k;   int a[10], mi, ma, ans;   int flag[10];   void dfs(int t) {     int i, j;     if (t == k) {       mi = ma = a[0];       for (i = 1; i < n; ++i) {         mi = Min(mi, a[i]);         ma = Max(ma, a[i]);       }       ans = Min(ans, ma - mi);       return;     }     for (i = 0; i < k; ++i) {       if (flag[i]) {         flag[i] = 0;         for (j = 0; j < n; ++j) {           a[j] *= 10;           a[j] += s[j][i] -  0 ;         }         dfs(t + 1);         for (j = 0; j < n; ++j) {           a[j] /= 10;         }         flag[i] = 1;       }     }   }   int main() {     int i;     scanf( %d%d , &n, &k);     for (i = 0; i < n; ++i) scanf( %s , s[i]);     ans = 1000000000;     memset(flag, 1, sizeof(flag));     dfs(0);     printf( %d n , ans);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   const int MOD = 998244353;   int n;   char s[N];   int solve() {     scanf( %d , &n);     scanf( %s , s);     bool ok = true;     for (int i = 0; i < n;) {       int j = i;       while (j < n && s[j] == s[i]) ++j;       if (s[i] ==  0  && i == 0) {         for (int k = i; k < j; ++k) printf( 0 );       } else if (s[i] ==  1  && j == n) {         for (int k = i; k < j; ++k) printf( 1 );       } else if (s[i] ==  1  && ok) {         printf( 0 );         ok = false;       }       i = j;     }     printf(  n );     return 0;   }   int main() {     int t = 1;     scanf( %d , &t);     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18 + 10;   const int maxn = 1e6 + 10;   struct node {     int d, l, r;     long long c;   } a[maxn];   long long L[maxn], R[maxn], vis[maxn];   bool cmp(node x, node y) { return x.d < y.d; }   int main() {     int n, m, k;     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= m; ++i) {       scanf( %d%d%d%I64d , &a[i].d, &a[i].l, &a[i].r, &a[i].c);     }     sort(a + 1, a + 1 + m, cmp);     memset(L, -1, sizeof L);     memset(R, -1, sizeof R);     memset(vis, 0, sizeof vis);     long long cnt = 0;     long long tot = 0;     for (int i = 1; i <= m; ++i) {       if (a[i].r != 0) continue;       if (!vis[a[i].l]) {         vis[a[i].l] = a[i].c;         cnt++;         tot += a[i].c;       } else {         if (vis[a[i].l] > a[i].c) {           tot = tot - vis[a[i].l] + a[i].c;           vis[a[i].l] = a[i].c;         }       }       if (cnt == n) {         L[i] = tot;       }     }     memset(vis, 0, sizeof vis);     cnt = 0;     tot = 0;     for (int i = m; i >= 1; --i) {       if (a[i].l != 0) continue;       if (!vis[a[i].r]) {         vis[a[i].r] = a[i].c;         cnt++;         tot += a[i].c;       } else {         if (vis[a[i].r] > a[i].c) {           tot = tot - vis[a[i].r] + a[i].c;           vis[a[i].r] = a[i].c;         }       }       if (cnt == n) {         R[i] = tot;       }     }     long long ans = INF;     for (int i = m; i >= 1; --i) {       if (R[i] == -1) continue;       if (R[i + 1] != -1) R[i] = min(R[i], R[i + 1]);     }     for (int i = 1; i <= m; ++i) {       if (L[i] == -1) continue;       int day = a[i].d + k + 1;       int l = i + 1, r = m, len = 50;       while (len--) {         int mid = (l + r) / 2;         if (a[mid].d >= day)           r = mid - 1;         else           l = mid + 1;       }       if (l == -1) continue;       if (R[l] != -1) {         ans = min(ans, L[i] + R[l]);       }     }     if (ans == INF) {       puts( -1 );     } else {       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxm = 20005, maxn = 1005;   double f[maxm][maxn];   int K, q, p, l, r, mid;   int main() {     scanf( %d%d , &K, &q);     f[0][0] = 1;     for (int i = 1; i <= maxm - 1; i++)       for (int j = 1; j <= K; j++)         f[i][j] = f[i - 1][j - 1] * (K - j + 1) / K + f[i - 1][j] * j / K;     while (q--) {       scanf( %d , &p);       l = 1;       r = maxm - 1;       while (l < r) {         mid = (l + r) >> 1;         if (f[mid][K] >= 1.0 * p / 2000 - 1e-10)           r = mid;         else           l = mid + 1;       }       printf( %d n , r);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   int len(const T& a) {     return a.size();   }   using ll = long long;   constexpr long double EPS = 1e-7;   long double MaxSubarray(const vector<long double>& a) {     long double best = -1e8;     long double cur = 0.0;     for (auto& i : a) {       cur = max((long double)0, cur + i);       best = max(best, cur);     }     return best;   }   long double MinSubarray(const vector<long double>& a) {     long double best = 1e8;     long double cur = 0.0;     for (auto& i : a) {       cur = min((long double)0, cur + i);       best = min(best, cur);     }     return best;   }   long double Check(const vector<long double>& a, long double x) {     vector<long double> new_a(a.size());     for (int i = 0; i < len(a); ++i) {       new_a[i] = (long double)a[i] - x;     }     return max(abs(MaxSubarray(new_a)), abs(MinSubarray(new_a)));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout << fixed << setprecision(6);     int n;     cin >> n;     vector<long double> a(n);     for (auto& i : a) cin >> i;     long double l = -1e4 - 10, r = 1e4 + 10;     for (int step = 0; step < 200; ++step) {       long double m1 = l + (r - l) / 3.0;       long double m2 = r - (r - l) / 3.0;       if (Check(a, m1) - Check(a, m2) > EPS) {         l = m1;       } else {         r = m2;       }     }     cout << Check(a, l);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2000001;   vector<long long> d1(N), d2(N);   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     long long x, y;     for (long long i = 0; i < n; i++) {       cin >> x >> y;       d1[x + y]++;       d2[x - y + 1000]++;     }     long long sums = 0;     for (long long i = 0; i <= 2001; i++) {       sums += 1LL * (d1[i]) * (d1[i] - 1) / 2;       sums += 1LL * (d2[i]) * (d2[i] - 1) / 2;     }     cout << sums <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int k, n;   long long ans, maxim, suma;   map<string, int> f;   deque<pair<string, int>> box[200001], b1, b2, b;   vector<pair<int, int>> trouble;   string s;   int val;   bool comp(pair<string, int> x, pair<string, int> y) {     return x.second > y.second;   }   int main() {     cin >> k >> n;     int nr = 0;     for (int i = 1; i <= k; i++) {       cin >> s >> val;       string s1 = s;       reverse(s1.begin(), s1.end());       s1 = min(s1, s);       if (f[s1] == 0) {         nr++;         f[s1] = nr;       }       box[f[s1]].push_back({s, val});     }     for (int i = 1; i <= nr; i++) {       b = box[i];       b1.clear();       b2.clear();       b1.push_back(b[0]);       for (int j = 1; j < b.size(); j++) {         if (b[j].first == b1[0].first)           b1.push_back(b[j]);         else           b2.push_back(b[j]);       }       sort(b1.begin(), b1.end(), comp);       sort(b2.begin(), b2.end(), comp);       if (!b2.empty()) {         while (b1.size() != b2.size()) {           if (b1.size() > b2.size())             b1.pop_back();           else             b2.pop_back();         }         for (int j = 0; j < b1.size(); j++)           if (b1[j].second + b2[j].second > 0) ans += b1[j].second + b2[j].second;       } else {         s = b1.front().first;         string s1 = s;         reverse(s1.begin(), s1.end());         if (s == s1) {           while (b1.size() >= 2) {             if (b1[0].second < 0 || b1[1].second < 0) break;             ans += b1[0].second + b1[1].second;             b1.pop_front();             b1.pop_front();           }           if (b1.size() == 1 && b1[0].second > 0)             trouble.push_back({b1[0].second, -1e8});           if (b1.size() >= 2 && b1[0].second > 0)             trouble.push_back({b1[0].second, b1[1].second});         }       }     }     for (auto i : trouble) {       suma += max(i.first + i.second, 0);       if (suma > maxim) maxim = suma;     }     for (auto i : trouble) {       long long sum1 = suma - max(i.first + i.second, 0) + i.first;       if (sum1 > maxim) maxim = sum1;     }     cout << ans + maxim;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(nullptr)->sync_with_stdio(false);     if (fopen(                  .in ,                r )) {       freopen(                         .in ,            r , stdin);       freopen(                         .out ,            w , stdout);     }     int n;     cin >> n;     vector<int> v(n);     for (auto &x : v) cin >> x;     sort(v.begin(), v.end());     int64_t sum = 0;     for (int i = 0; i < n; ++i) {       sum += abs(v[i] - i - 1);     }     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   char ch[100010], temp[100010];   bool ok[100010];   int main() {     int n;     cin >> n;     cin >> ch;     int m = strlen(ch);     for (int i = 1; i < n; i++) {       cin >> temp;       for (int j = 0; j < m; j++) {         if (ch[j] >=  a  && ch[j] <=  z  && temp[j] >=  a  && temp[j] <=  z  &&             ch[j] != temp[j])           ok[j] = 1, ch[j] =  ? ;         if (ch[j] ==  ?  && !ok[j]) ch[j] = temp[j];       }     }     for (int i = 0; i < m; i++) {       if (ch[i] ==  ?  && !ok[i])         cout <<  x ;       else         cout << ch[i];     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int n;     cin >> n;     long long int s = 0;     for (long long int i = 0; i < n; i++) {       long long int x;       cin >> x;       s += x;     }     if (s % n == 0)       cout << n;     else       cout << n - 1;   }
#include <bits/stdc++.h>   using namespace std;   long long choose(long long n, long long k);   bool isprime(long long n);   long long power(long long x, long long y, long long p);   long long power(long long x, long long y);   long long gcd(long long a, long long b);   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     queue<long long> q;     set<long long> st;     for (int i = 0; i < n; i++) {       long long x;       cin >> x;       if (st.find(x) == st.end()) {         if (q.size() == k) {           st.erase(st.find(q.front()));           q.pop();           q.push(x);         } else {           q.push(x);         }         st.insert(x);       }     }     cout << q.size() << endl;     vector<long long> v;     while (!q.empty()) v.push_back(q.front()), q.pop();     for (int i = v.size() - 1; i > -1; i--) cout << v[i] <<    ;     return 0;   }   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long choose(long long n, long long k) {     if (k == 0) return 1;     return (n * choose(n - 1, k - 1)) / k;   }   bool isprime(long long n) {     for (long long i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   long long power(long long x, long long y, long long p) {     long long res = 1;     x = x % p;     while (y > 0) {       if (y & 1) res = (res * x) % p;       y = y >> 1;       x = (x * x) % p;     }     return res;   }   long long power(long long x, long long y) {     long long res = 1;     while (y > 0) {       if (y & 1) res = res * x;       y = y >> 1;       x = x * x;     }     return res;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 102;   int w, h, n, qs, qt;   int area[maxn], areath;   pair<int, int> q[1000006];   int dx[4] = {-1, 0, 1, 0};   int dy[4] = {0, -1, 0, 1};   bool vis[maxn][maxn];   bool cut[maxn][maxn][4];   int bfs(int stx, int sty) {     qs = 0;     qt = 1;     q[0] = make_pair(stx, sty);     while (qs < qt) {       int nowx = q[qs].first;       int nowy = q[qs++].second;       for (int k = 0; k < 4; k++)         if (!cut[nowx][nowy][k]) {           int x = nowx + dx[k], y = nowy + dy[k];           if (x < 0 || x >= w || y < 0 || y >= h || vis[x][y]) continue;           vis[x][y] = true;           q[qt++] = make_pair(x, y);         }     }     return qt;   }   int main() {     cin >> w >> h >> n;     for (int i = 1; i <= n; i++) {       int xa, ya, xb, yb;       cin >> xa >> ya >> xb >> yb;       if (xa == xb)         for (int j = ya; j < yb; j++) cut[xa][j][0] = cut[xa - 1][j][2] = true;       else         for (int j = xa; j < xb; j++) cut[j][ya][1] = cut[j][ya - 1][3] = true;     }     for (int i = 0; i < w; i++)       for (int j = 0; j < h; j++)         if (!vis[i][j]) {           vis[i][j] = true;           area[++areath] = bfs(i, j);         }     sort(area + 1, area + areath + 1);     for (int i = 1; i < areath; i++) cout << area[i] <<    ;     cout << area[areath] << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize(3)   using namespace std;   inline char gc() {     static const int L = 1000;     static char sxd[L], *sss = sxd, *ttt = sxd;     if (sss == ttt) {       ttt = (sss = sxd) + fread(sxd, 1, L, stdin);       if (sss == ttt) return EOF;     }     return *sss++;   }   inline int read(int& x) {     x = 0;     char c = getchar();     bool f = false;     for (; !isdigit(c); c = getchar()) {       if (c == EOF) return -1;       if (c ==  - ) f = true;     }     for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;     return 1;   }   int i, j, a[1000], n, m, k, s, sum, z;   int main() {     read(n);     for (i = 1; i <= n; i++) read(a[i]);     while (!a[++s])       ;     for (; s <= n; s++) {       if (a[s]) {         if (sum < 2) z += sum;         sum = 0;         z++;       } else         sum++;     }     cout << z;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[5010];   int pw2[5010];   int ans = 1e9;   bool check(int x, int y) {     if (a[x] % a[y] != 0LL) return false;     if (pw2[y] - (y - x - 1) <= 0) return true;     return (pw2[x] + 1 == pw2[y] - (y - x - 1));   }   int dp[5010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %I64d , a + i);       while (a[i] % 2LL == 0LL) {         a[i] /= 2LL;         pw2[i]++;       }     }     for (int i = 1; i <= n; i++) {       dp[i] = i - 1;       for (int j = 1; j < i; j++) {         if (!check(j, i)) continue;         dp[i] = min(dp[i], dp[j] + (i - j - 1));       }       ans = min(ans, dp[i] + n - i);     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, x, l, r, i, s, a[10179];   int main() {     cin >> n >> m;     for (i = 1; i <= n; i++) cin >> a[i];     while (m--) {       cin >> l >> r >> x;       for (s = 0, i = l; i <= r; i++)         if (a[i] < a[x]) s++;       if (s + l == x)         cout <<  Yes n ;       else         cout <<  No n ;     }   }