malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     static int x[27];     int n, k;     cin >> n >> k;     cin >> s;     for (int i = 0; i < k; i++) {       char r;       cin >> r;       x[r -  a ] = 1;     }     long long res = 0, tr = 0;     for (int i = 0; s[i]; i++) {       if (x[s[i] -  a ])         tr++;       else {         res += (tr * (tr + 1)) / 2;         tr = 0;       }     }     res += (tr * (tr + 1)) / 2;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> parent;   vector<int> Rank;   int root(int v) {     if (parent[v] == v) return v;     return parent[v] = root(parent[v]);   }   void DSU(int a, int b) {     a = root(a);     b = root(b);     if (a != b) {       if (Rank[b] > Rank[a]) swap(a, b);       Rank[a] += Rank[b];       parent[b] = a;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n, m, q;     cin >> n >> m >> q;     parent.resize(n + m + 3);     for (int i = 0; i < parent.size(); i++) {       parent[i] = i;     }     Rank.resize(n + m + 3, 1);     for (int i = 0; i < q; i++) {       int a, b;       cin >> a >> b;       b += n;       DSU(a, b);     }     set<int> roots;     for (int i = 1; i <= n + m; i++) {       roots.insert(root(i));     }     cout << roots.size() - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > Sh;   const int tmax = 155;   char table[tmax][tmax];   pair<int, int> mow[tmax];   pair<int, int> ccount(int row, int side, int ai) {     if (mow[row].second == 0 && mow[row + 1].second == 0) return make_pair(0, ai);     if (mow[row].second == 0) {       if (side == 0 && ai < mow[row + 1].second)         return make_pair(mow[row + 1].second - ai, mow[row + 1].second);       else if (side == 1 && ai >= mow[row + 1].first)         return make_pair(ai - mow[row + 1].first, mow[row + 1].first);       else         return make_pair(0, ai);     }     if (mow[row + 1].second == 0) {       if (side == 0)         return make_pair(mow[row].second - ai, mow[row].second);       else         return make_pair(ai - mow[row].first, mow[row].first);     }     if (side == 0)       return make_pair(max(mow[row + 1].second, mow[row].second) - ai,                        max(mow[row + 1].second, mow[row].second));     else       return make_pair(ai - min(mow[row + 1].first, mow[row].first),                        min(mow[row + 1].first, mow[row].first));   }   int main() {     int N, M;     scanf( %d %d , &N, &M);     for (int i = 0; i < tmax; i++) mow[i].first = 1 << 30, mow[i].second = 0;     int last = 0;     for (int i = 1; i <= N; i++) {       for (int j = 1; j <= M; j++) {         scanf(  %c , &table[i][j]);         if (table[i][j] ==  W ) {           mow[i].first = min(j, mow[i].first);           mow[i].second = max(j, mow[i].second);           last = max(last, i);         }       }     }     int side = 0, howmany = 0;     int ai = 1;     for (int i = 1; i < N; i++) {       pair<int, int> ret = ccount(i, side, ai);       howmany += ret.first;       ai = ret.second;       side ^= 1;     }     if (mow[N].second) {       if (side)         howmany += ai - mow[N].first;       else         howmany += mow[N].second - ai;     }     printf( %d n , max(howmany + last - 1, 0));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   ofstream outfile;   ifstream infile;   int main() {     infile.open( input.txt );     outfile.open( output.txt );     long long int a, b;     cin >> a >> b;     if (a > b) {       cout <<  0 n ;       return 0;     } else if (b - a <= 20) {       long long int digit = 1;       for (long long int i = a + 1; i <= b; ++i) {         digit = (digit * i) % 10;       }       cout << digit <<   n ;       return 0;     }     cout <<  0 n ;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T inline SQR(const T &a) {     return a * a;   }   long long MOD = 1000000007LL;   long long mypow(long long a, long long p) {     if (p == 0) return 1LL;     long long ans = mypow(a, p / 2);     ans *= ans;     ans %= MOD;     if (p & 1) return (a * ans) % MOD;     return ans;   }   int n, m, k;   int dp[1005][1005];   int solve(int pLeft, int sd) {     if (pLeft == 0) return 1;     if (sd <= 0) return 0;     int &val = dp[pLeft][sd];     if (val != -1) return val;     long long aux = 0;     for (int i = 1; i < sd - 1; ++i) {       aux += 1ll * (sd - 1 - i) * solve(pLeft - 1, i);     }     return val = aux % MOD;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> m >> k;     int MAXS = max(n, m) + 1;     for (int i = 0; i < k + 1; ++i)       for (int j = 0; j < MAXS; ++j) dp[i][j] = -1;     cout << (1ll * solve(k, n) * solve(k, m)) % MOD << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int apsz = 26;   const long long o = 1;   const int maxn = 300007;   const int ooi = 1e9 + 7;   const int up = 62;   int n;   long long mask[maxn];   long long val[maxn];   inline int hb(long long x) {     int k = 0;     while ((o << (k + 1)) <= x) k++;     return k;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n;     long long sum = 0;     for (int i = (0); i < (n); ++i) cin >> val[i] >> mask[i], sum += val[i];     vector<vector<int> > pos(up);     vector<vector<int> > exist(up);     for (int i = (0); i < (n); ++i) {       pos[hb(mask[i])].push_back(i);       for (int j = (0); j < (up); ++j)         if ((o << j) & mask[i]) exist[j].push_back(i);     }     long long ans = 0;     for (int i = (0); i < (up); ++i) {       if (pos[i].empty()) continue;       long long tmp = 0;       for (auto x : pos[i]) tmp += val[x];       if (tmp == 0) continue;       if (tmp > 0 == sum > 0) {         ans |= (o << (long long)i);         for (auto x : exist[i]) val[x] = -val[x];       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long res = 0;   int main() {     cin >> n;     long long tmp = 0;     int indez = 1;     for (int i = 1; i <= n - 1; i++) {       tmp += indez;       indez += 2;     }     res = tmp * 2;     res += (n * 2 - 1);     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 0x3f3f3f3f3f3f3f3fLL;   const int MOD = 1e9 + 7;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     int n, m;     cin >> n >> m;     vector<vector<int>> e(n + 1);     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       e[x].push_back(y);       e[y].push_back(x);     }     vector<int> val(n + 1);     for (int i = 1; i <= n; i++) {       cin >> val[i];     }     vector<int> order(n);     iota(order.begin(), order.end(), 1);     sort(order.begin(), order.end(),          [&](int i, int j) { return val[i] < val[j]; });     for (int i = 0; i < n; i++) {       set<int> s;       for (int x : e[order[i]]) {         s.insert(val[x]);       }       int c = 1;       while (s.count(c)) {         c++;       }       if (c != val[order[i]]) {         cout << -1 <<   n ;         return 0;       }     }     for (int i : order) {       cout << i <<    ;     }     cout <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   long long h[100000], p[100000], l, r;   int i, j, n, m;   long long getleft(long long x) {     int l = 0, r = m - 1;     while (r - l > 1) {       int mid = (l + r) / 2;       if (p[mid] > x)         r = mid;       else         l = mid;     }     if (p[l] > x)       return p[l];     else if (p[r] > x)       return p[r];     else       return -1;   }   bool ok(long long t) {     long long x1, x2, r = 0, q;     for (int i = 0; i < n; i++) {       long long x = t;       q = getleft(r);       if (q <= r || q >= h[i])         r = max(r, h[i] + x);       else if (t - (h[i] - q) < 0)         return false;       else {         if ((t - h[i] + q) / 2 > 0)           x2 = h[i] + (t - h[i] + q) / 2;         else           x2 = 0;         x1 = max(h[i], h[i] + (t - 2 * (h[i] - q)));         r = max(r, max(x1, x2));       }     }     if (p[m - 1] > r) return false;     return true;   }   int main() {     cin >> n >> m;     for (i = 0; i < n; i++) cin >> h[i];     for (i = 0; i < m; i++) cin >> p[i];     l = 0;     r = 100000000001;     while (r - l > 1) {       long long mid = (l + r) / 2;       if (ok(mid))         r = mid;       else         l = mid;     }     if (ok(l))       cout << l;     else if (ok(r))       cout << r;   }
#include <bits/stdc++.h>   const int MAXN = 100;   char cake[MAXN][MAXN + 1];   int main() {     int n;     scanf( %d , &n);     for (int row = 0; row < n; ++row) {       scanf( %s , cake[row]);     }     int pairs = 0;     for (int i = 0; i < n; ++i) {       int inRow = 0, inCol = 0;       for (int j = 0; j < n; ++j) {         inRow += cake[i][j] ==  C ;         inCol += cake[j][i] ==  C ;       }       pairs += inRow * (inRow - 1) / 2 + inCol * (inCol - 1) / 2;     }     printf( %d , pairs);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 10000000;   int main() {     int n;     cin >> n;     string a;     cin >> a;     for (int j = 1; j <= 25; j++)       for (int i = 0; i + 4 * j < a.size(); i++) {         if (a[i] ==  *  && a[i + j] ==  *  && a[i + 2 * j] ==  *  &&             a[i + 3 * j] ==  *  && a[i + 4 * j] ==  * ) {           cout <<  yes ;           return 0;         }       }     cout <<  no ;   }
#include <bits/stdc++.h>   using namespace std;   struct Pair {     int x, position;   } valiue[543211], b[543211];   int n, k, len, N, Partition, L, R;   int QWER[543211], REWQ[543211], otvet[543211], kol, i;   int Lowofbound[543211], Behind[543211], sled[543211], l, r, mn;   vector<pair<pair<int, int>, int> > a[800];   bool cmd(Pair q, Pair w) {     if (q.position < w.position)       return true;     else       return false;   }   bool cmp(Pair q, Pair w) {     if (q.x < w.x)       return true;     else       return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin >> n >> k;     for (i = 1; i <= n; ++i) {       cin >> valiue[i].x;       b[i].position = i;       b[i].x = valiue[i].x;     }     sort(b + 1, b + n + 1, cmp);     len = 0;     for (i = 1; i <= n; ++i) {       if (i == 1 || b[i].x != b[i - 1].x) {         ++len;       }       valiue[i].x = len;       valiue[i].position = b[i].position;     }     sort(valiue + 1, valiue + n + 1, cmd);     N = int(sqrt(n));     for (i = 1; i <= k; ++i) {       cin >> l >> r;       Partition = (l - 1) / N + 1;       a[Partition].push_back(make_pair(make_pair(r, l), i));     }     for (i = 1; i <= n; ++i) {       if (!QWER[valiue[i].x])         QWER[valiue[i].x] = i;       else         Behind[i] = QWER[valiue[i].x], QWER[valiue[i].x] = i;     }     for (i = n; i >= 1; --i) {       if (!REWQ[valiue[i].x])         REWQ[valiue[i].x] = i;       else         sled[i] = REWQ[valiue[i].x], REWQ[valiue[i].x] = i;     }     for (i = 1; i <= n; ++i) Lowofbound[(i - 1) / N + 1] = i;     for (i = 1; i <= 720; ++i)       if (a[i].size() > 0) {         sort(a[i].begin(), a[i].end());         mn = 2000000000;         R = Lowofbound[i];         L = R + 1;         for (int j = 0; j < a[i].size(); ++j) {           l = a[i][j].first.second;           r = a[i][j].first.first;           if (L <= r) {             while (R < r) {               R++;               if (Behind[R] > Lowofbound[i]) mn = min(mn, R - Behind[R]);             }             kol = mn;             for (int c = Lowofbound[i]; c >= l; --c)               if (sled[c] > 0 && sled[c] <= R) kol = min(kol, sled[c] - c);           } else {             kol = mn;             for (int c = l; c <= r; ++c)               if (sled[c] > 0 && sled[c] <= r) kol = min(kol, sled[c] - c);           }           if (kol != 2000000000)             otvet[a[i][j].second] = kol;           else             otvet[a[i][j].second] = -1;         }       }     for (i = 1; i <= k; ++i) cout << otvet[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     string s;     cin >> s;     int minval = 100000000, currsum = 0;     for (int i = 0; i < n; i++) {       if (s[i] ==  ( ) {         currsum++;         minval = min(minval, currsum);       } else {         currsum--;         minval = min(minval, currsum);       }     }     if (minval < -1)       cout <<  NO ;     else if (minval == -1) {       if (!currsum)         cout <<  YES ;       else         cout <<  NO ;     } else {       if (currsum)         cout <<  NO ;       else         cout <<  YES ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n;     cin >> s;     s +=  b ;     n = s.size();     for (int i = 0; i < n - 1; i++) {       if (s[i] != s[i + 1])         cout << 1 <<    ;       else         cout << 0 <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, steps = 0;     string s;     cin >> n >> d >> s;     for (int x = 0; x < n; steps++) {       if (x == n - 1) {         cout << steps;         break;       }       for (int a = d; a + 1; a--) {         if (!a) {           cout << -1;           return 0;         }         if (x + a < n && s[x + a] ==  1 ) {           x += a;           break;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100005;   int d[maxn], n;   struct node {     int a, b;   } data[maxn];   int main() {     cin >> n;     d[0] = -1;     for (int i = 1; i <= n; i++) cin >> d[i];     sort(d + 1, d + 1 + n);     int cnt = 0;     for (int i = 1; i <= n; i++) {       if (d[i] == d[i - 1])         data[cnt].b++;       else {         cnt++;         data[cnt].a = d[i];         data[cnt].b = 1;       }     }     bool flag = 1;     for (int i = 2; i <= cnt; i++) {       if (data[i].a - 1 != data[i - 1].a) {         flag = 0;         break;       }     }     if (flag) {       data[2].b -= data[1].b - 1;       for (int i = 2; i < cnt; i++) {         if (data[i].b < 2) {           flag = 0;           break;         } else           data[i + 1].b -= data[i].b - 2;       }       if (data[cnt].b != 1) flag = 0;     }     if (flag)       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[100][100];   int di[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};   int v[100][100];   int fst[4] = {1, 0, 1, 0};   int xi[4][2] = {1, 0, 0, 1, 2, 3, 3, 2};   int m, r;   struct zb {     int z[2];   } po[100][100][4][2];   void gx(int x, int y, int &a, int &b, int xi) {     if (xi == 0) {       if (x > a || (x == a && y > b)) {         a = x;         b = y;       }     }     if (xi == 1) {       if (x > a || (x == a && y < b)) {         a = x;         b = y;       }     }     if (xi == 2) {       if (x < a || (x == a && y > b)) {         a = x;         b = y;       }     }     if (xi == 3) {       if (x < a || (x == a && y < b)) {         a = x;         b = y;       }     }   }   void dfs(int x, int y, int cx, int cy) {     v[cx][cy] = 1;     int i, j;     for (i = 0; i < 4; i++)       for (j = 0; j < 2; j++) {         if (fst[i] == 1)           gx(cy, cx, po[x][y][i][j].z[1], po[x][y][i][j].z[0], xi[i][j]);         else           gx(cx, cy, po[x][y][i][j].z[0], po[x][y][i][j].z[1], xi[i][j]);       }     for (i = 0; i < 4; i++) {       int nx, ny;       nx = cx + di[i][0];       ny = cy + di[i][1];       if (nx >= 0 && nx < m && ny >= 0 && ny < r && v[nx][ny] == 0 &&           s[nx][ny] == s[x][y])         dfs(x, y, nx, ny);     }   }   int main() {     int n, i, j, k, l, bp, cp, dp, cx, cy;     while (scanf( %d%d , &m, &n) == 2) {       for (i = 0; i < m; i++) scanf( %s , s[i]);       r = strlen(s[0]);       for (i = 0; i < m; i++)         for (j = 0; j < r; j++) {           for (k = 0; k < 4; k++)             for (l = 0; l < 2; l++) {               po[i][j][k][l].z[0] = i;               po[i][j][k][l].z[1] = j;             }           memset(v, 0, sizeof(v));           if (s[i][j] !=  0 ) dfs(i, j, i, j);         }       cx = 0;       cy = 0;       cp = 0;       dp = 0;       while (n--) {         int nx, ny;         nx = po[cx][cy][cp][dp].z[0];         ny = po[cx][cy][cp][dp].z[1];         cx = nx;         cy = ny;         i = cp;         nx = cx + di[i][0];         ny = cy + di[i][1];         if (nx >= 0 && nx < m && ny >= 0 && ny < r && s[nx][ny] !=  0 ) {           cx = nx;           cy = ny;         } else {           if (dp == 0)             dp = 1;           else {             dp = 0;             cp = (cp + 1) % 4;           }         }       }       printf( %c n , s[cx][cy]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int s, x, y, a, b = 0;     cin >> s >> x;     int f = 1;     if (s < x) f = 0;     if (s == x) b = 2;     y = s - x;     if (y % 2 == 1) f = 0;     if (f) {       y /= 2, a = 1;       while (x > 0 || y > 0) {         if (x % 2 == 1) {           if (y % 2 == 0)             a *= 2;           else             f = 0;         }         x /= 2, y /= 2;       }     }     a *= f;     cout << a - b << endl;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int maxn = 1 << 18;   struct node {     int mx;     node() { mx = -1e9; }     node(int val) { mx = val; }   };   node temp;   node merge(node l, node r) {     temp.mx = min(l.mx, r.mx);     return temp;   }   struct segment_tree {     int n;     node t[2 * maxn];     void init(int sz) {       n = sz;       for (int i = 0; i < n; i++) t[i + n] = node();       for (int i = n - 1; i > 0; --i) t[i] = merge(t[i << 1], t[i << 1 | 1]);     }     void modify(int p, const node &value) {       for (t[p += n] = value; p >>= 1;) t[p] = merge(t[p << 1], t[p << 1 | 1]);     }     node query(int l, int r) {       node resl(1 << 30), resr(1 << 30);       for (l += n, r += n; l < r; l >>= 1, r >>= 1) {         if (l & 1) resl = merge(resl, t[l++]);         if (r & 1) resr = merge(t[--r], resr);       }       return merge(resl, resr);     }   };   vector<int> solve(int n, int m, vector<array<int, 2>> co,                     vector<array<int, 4>> qs) {     vector<int> ans(qs.size());     vector<vector<array<int, 4>>> qr(n + 1);     vector<vector<int>> here(n + 1);     for (auto [x, y] : co) here[x].push_back(y);     for (int i = 0; i < qs.size(); i++) {       qr[qs[i][2]].push_back({i, qs[i][1], qs[i][3], qs[i][0]});     }     segment_tree st;     st.init(m + 1);     for (int i = 1; i <= n; i++) {       for (auto j : here[i]) {         st.modify(j, node(i));       }       for (auto [id, yl, yr, xl] : qr[i]) {         ans[id] = st.query(yl, yr + 1).mx >= xl;       }     }     return ans;   }   int main() {     cin.tie(0)->sync_with_stdio(0);     int n, m, k, q;     cin >> n >> m >> k >> q;     vector<array<int, 2>> co(k);     vector<array<int, 4>> qs(q);     for (auto &i : co) cin >> i[0] >> i[1];     for (auto &i : qs) cin >> i[0] >> i[1] >> i[2] >> i[3];     auto ans1 = solve(n, m, co, qs);     for (auto &i : co) swap(i[0], i[1]);     for (auto &i : qs) swap(i[0], i[1]);     for (auto &i : qs) swap(i[2], i[3]);     auto ans2 = solve(m, n, co, qs);     for (int i = 0; i < q; i++)       cout << (ans1[i] || ans2[i] ?  YES  :  NO ) <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     edge(int to, int back, int orient = 0) : to(to), back(back), orient(orient) {}     int to;     int back;     int orient;   };   class Tarjan {    public:     vector<vector<int> > adj;     vector<int> comp;     int nb_cfc;       private:     vector<int> index;     vector<int> lowlink;     stack<int> s;     int id;     void tarjan(int i) {       int j, k;       index[i] = id;       lowlink[i] = id;       ++id;       s.push(i);       for (k = 0; k < (int)adj[i].size(); ++k) {         j = adj[i][k];         if (index[j] == -1) tarjan(j);         if (comp[j] == -1) lowlink[i] = min(lowlink[i], lowlink[j]);       }       if (lowlink[i] == index[i]) {         do {           j = s.top();           s.pop();           comp[j] = nb_cfc;         } while (i != j);         ++nb_cfc;       }     }       public:     void cfc() {       id = 0;       nb_cfc = 0;       comp.clear();       index.clear();       lowlink.clear();       comp.resize(adj.size(), -1);       index.resize(adj.size(), -1);       lowlink.resize(adj.size(), -1);       for (int i = 0; i < (int)adj.size(); ++i) {         if (index[i] == -1) tarjan(i);       }     }   };   void dfs(vector<vector<edge> > &graph, vector<bool> &mark, int x) {     if (mark[x]) return;     mark[x] = true;     for (int i = 0; i < (graph[x].size()); ++i) {       int y = graph[x][i].to;       if (graph[x][i].orient == 0) {         int j = graph[x][i].back;         graph[x][i].orient = 1;         graph[y][j].orient = -1;         dfs(graph, mark, y);       }     }   }   int main(void) {     int n, m;     cin >> n >> m;     vector<vector<edge> > graph(n);     for (int i = 0; i < (m); ++i) {       int x, y;       cin >> x >> y;       --x, --y;       int u = graph[x].size();       int v = graph[y].size();       graph[x].push_back(edge(y, v));       graph[y].push_back(edge(x, u));     }     vector<bool> mark(n, false);     dfs(graph, mark, 0);     Tarjan g;     g.adj.assign(n, vector<int>());     for (int x = 0; x < (n); ++x)       for (int i = 0; i < (graph[x].size()); ++i) {         int y = graph[x][i].to;         if (graph[x][i].orient > 0) g.adj[x].push_back(y);       }     g.cfc();     if (g.nb_cfc > 1)       cout << 0 << endl;     else {       for (int i = 0; i < (n); ++i)         for (int j = 0; j < (graph[i].size()); ++j) {           int x = i, y = graph[i][j].to;           if (y < x) continue;           if (graph[i][j].orient < 0) swap(x, y);           ++x, ++y;           cout << x <<     << y << endl;         }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long add(long long a, long long b) {     a = (a + b);     if (a >= 1000000007) a -= 1000000007;     return a;   }   inline long long sub(long long a, long long b) {     a = a - b;     if (a < 0) a += 1000000007;     return a;   }   inline long long mul(long long a, long long b) {     a = (a * b) % 1000000007;     return a;   }   const long long N = 1e6 + 5;   vector<long long> arr1(N, 0);   void pre() {     for (long long i = 2; i < N; i++) {       if (arr1[i] == 0) {         for (long long j = i; j < N; j += i) {           if (arr1[j] == 0) arr1[j] = i;         }       }     }   }   void mymain() {     long long n;     cin >> n;     vector<long long> arr(n);     for (long long& i : arr) cin >> i;     long long ans = 1;     vector<long long> dp(n + 1, 1);     for (long long i = 1; i <= n; i++) {       for (long long j = 2; j * i <= n; j++) {         long long k = j * i;         if (arr[k - 1] > arr[i - 1]) {           dp[k] = max(dp[k], dp[i] + 1);         }       }     }     for (long long i : dp) ans = max(i, ans);     cout << ans <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     long long t = 1;     cin >> t;     pre();     for (long long tt = 0; tt < t; tt++) {       mymain();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long lcm = 840;   long long w, cnt[10];   long long dp[10][lcm * 8 + 5];   int main() {     ios::sync_with_stdio(false);     cin >> w;     for (int i = 1; i <= 8; i++) {       cin >> cnt[i];     }     memset(dp, -1, sizeof(dp));     dp[0][0] = 0;     for (int i = 1; i <= 8; i++) {       for (int j = 0; j < 8 * lcm; j++) {         long long xx = min(lcm / i - 1, cnt[i]);         for (int k = 0; k <= xx; k++) {           if (j - k * i >= 0 && dp[i - 1][j - k * i] != -1)             dp[i][j] = max(dp[i][j], dp[i - 1][j - k * i] +                                          (cnt[i] - k) / (lcm / (long long)i));         }       }     }     long long ans = 0;     for (long long i = 0; i < 8 * lcm; i++) {       if (dp[8][i] == -1 || i > w) continue;       ans = max(ans, i + lcm * min(dp[8][i], (w - i) / lcm));     }     cout << ans;     return 0;   }