malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 105;   const long long INF = (long long)0x7fffffffffff;   long long dp[maxn][maxn][maxn], wi[maxn], c[maxn];   long long min(long long a, long long b) { return a > b ? b : a; }   int main() {     int n, m, k, temp, flag = 1, ans1 = 0;     cin >> n >> m >> k;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         for (int l = 0; l <= n; l++) {           dp[i][j][l] = INF;         }       }     }     for (int i = 1; i <= n; i++) {       cin >> c[i];     }     for (int i = 1; i <= m; i++) cin >> wi[i];     if (c[1] == 0)       for (int i = 1; i <= m; i++) dp[1][i][1] = wi[i];     else       dp[1][c[1]][1] = 0;     for (int i = 2; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> wi[j];         for (int l = 1; l <= i; l++) {           if (c[i] == 0) {             for (int p = 1; p <= m; p++) {               if (p == j) {                 dp[i][j][l] = min(dp[i][j][l], dp[i - 1][j][l] + wi[j]);               } else {                 dp[i][j][l] = min(dp[i][j][l], dp[i - 1][p][l - 1] + wi[j]);               }             }           } else {             for (int p = 1; p <= m; p++) {               if (p == c[i]) {                 dp[i][c[i]][l] = min(dp[i][c[i]][l], dp[i - 1][c[i]][l]);               } else {                 dp[i][c[i]][l] = min(dp[i][c[i]][l], dp[i - 1][p][l - 1]);               }             }           }         }       }     }     long long ans = INF;     for (int i = 1; i <= m; i++) ans = min(ans, dp[n][i][k]);     if (ans >= INF)       cout << -1 << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     long long int n;     cin >> n;     long long int k;     cin >> k;     long long int sum = k;     for (int i = (int)2; i <= (int)n; i++) {       cin >> k;       sum = sum + ((k - 1ll) * ((long long int)i - 1ll)) + k;     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (a == 0) return b;     if (b == 0) return a;     return gcd(b % a, a);   }   long long power(long long a, long long b) {     long long res = 1;     while (b > 0) {       if (b % 2 != 0) res = (res * 1ll * a);       b /= 2;       a = (a * 1ll * a);     }     return res;   }   void solve() {     string s;     cin >> s;     long long n = s.length();     bool v = false;     bool h = false;     for (long long i = 0; i < n; i++) {       if (s[i] ==  1 ) {         if (!h) {           h = true;           cout << 1 <<     << 1 << endl;         } else {           h = false;           cout << 1 <<     << 3 << endl;         }       } else {         if (!v) {           v = true;           cout << 3 <<     << 4 << endl;         } else {           v = false;           cout << 1 <<     << 4 << endl;         }       }     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   string s;   vector<string> t;   vector<pair<pair<int, int>, int> > cro;   bool cmp(const pair<pair<int, int>, int> &x,            const pair<pair<int, int>, int> &y) {     if (x.second == y.second) {       if (x.first.first == y.first.first) return x.first.second < y.first.second;       return x.first.first < y.first.first;     }     return x.second < y.second;   }   int main() {     cin >> n >> m >> k;     for (int i = 0; i < (n); i++) {       cin >> s;       t.push_back(s);     }     for (int i = 0; i < (n); i++) {       for (int j = 0; j < (m); j++) {         if (t[i][j] ==  * ) {           for (int r = (1); r <= (min(i, min(j, min(n - i - 1, m - j - 1))));                r++) {             if ((t[i - r][j] ==  * ) && (t[i + r][j] ==  * ) &&                 (t[i][j - r] ==  * ) && (t[i][j + r] ==  * ))               cro.push_back(make_pair(make_pair(i, j), r));           }         }       }     }     if (cro.size() < k)       cout <<  -1 n ;     else {       sort((cro).begin(), (cro).end(), cmp);       cout << cro[k - 1].first.first + 1 <<     << cro[k - 1].first.second + 1            <<   n ;       cout << cro[k - 1].first.first + 1 - cro[k - 1].second <<                << cro[k - 1].first.second + 1 <<   n ;       cout << cro[k - 1].first.first + 1 + cro[k - 1].second <<                << cro[k - 1].first.second + 1 <<   n ;       cout << cro[k - 1].first.first + 1 <<                << cro[k - 1].first.second + 1 - cro[k - 1].second <<   n ;       cout << cro[k - 1].first.first + 1 <<                << cro[k - 1].first.second + 1 + cro[k - 1].second <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fio() {}   void pti() {     double timeuse = clock() * 1000.0 / CLOCKS_PER_SEC;     cerr <<  Timeuse   << timeuse <<  ms  << endl;   }   void end() { exit(0); }   namespace io {   const int SIZ = 55;   int que[SIZ], op, qr;   char ch;   template <class I>   inline void gi(I& w) {     ch = getchar(), op = 1, w = 0;     while (!isdigit(ch)) {       if (ch ==  - ) op = -1;       ch = getchar();     }     while (isdigit(ch)) {       w = w * 10 + ch -  0 ;       ch = getchar();     }     w *= op;   }   template <typename T, typename... Args>   inline void gi(T& t, Args&... args) {     gi(t);     gi(args...);   }   template <class I>   inline void print(I w) {     qr = 0;     if (!w) putchar( 0 );     if (w < 0) putchar( - ), w = -w;     while (w) que[++qr] = w % 10 +  0 , w /= 10;     while (qr) putchar(que[qr--]);   }   }  // namespace io   using io::gi;   using io::print;   const int N = 5005;   int n, m;   int a[N];   int main() {     fio();     gi(n, m);     int t = 0;     for (int i = 1; i <= n; ++i) {       a[i] = i;       t += (i - 1) >> 1;       if (t >= m) {         int res = (t - m) << 1;         a[i] += res;         for (int j = n, s = 1e9; j > i; --j, s -= a[i] + 1) a[j] = s;         for (int j = 1; j <= n; ++j) print(a[j]), putchar(   );         end();       }     }     print(-1);     end();   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   const int Mod = 1e9 + 7;   struct Mat {     long long A[2][2];     Mat() { memset(A, 0, sizeof(A)); }     void init(void) {       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) A[i][j] = (i == j);     }     Mat operator+(struct Mat A) {       struct Mat B;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           B.A[i][j] = this->A[i][j] + A.A[i][j];           B.A[i][j] %= Mod;         }       }       return B;     }     Mat operator*(struct Mat A) {       struct Mat B;       for (int i = 0; i < 2; i++) {         for (int j = 0; j < 2; j++) {           for (int k = 0; k < 2; k++) {             B.A[i][j] += (this->A[i][k] * A.A[k][j]);             B.A[i][j] %= Mod;           }         }       }       return B;     }     Mat operator^(int t) {       struct Mat A, B;       A.init();       for (int i = 0; i < 2; i++)         for (int j = 0; j < 2; j++) B.A[i][j] = this->A[i][j];       while (t) {         if (t & 1) A = A * B;         t >>= 1;         B = B * B;       }       return A;     }   };   struct Mat Tree[N << 2], Laze[N << 2], f;   int A[N];   void pushUp(int n) { Tree[n] = (Tree[n << 1] + Tree[n << 1 | 1]); }   void pushDown(int n) {     Tree[n << 1] = Laze[n] * Tree[n << 1];     Tree[n << 1 | 1] = Laze[n] * Tree[n << 1 | 1];     Laze[n << 1] = Laze[n] * Laze[n << 1];     Laze[n << 1 | 1] = Laze[n] * Laze[n << 1 | 1];     Laze[n].init();   }   void build(int l, int r, int rt) {     Laze[rt].init();     if (l == r) {       Tree[rt] = f ^ (A[l] - 1);       return;     }     int mid = (l + r) >> 1;     build(l, mid, rt << 1);     build(mid + 1, r, rt << 1 | 1);     pushUp(rt);   }   void update(int l, int r, int rt, int _l, int _r, struct Mat x) {     if (l >= _l && r <= _r) {       Tree[rt] = x * Tree[rt];       Laze[rt] = x * Laze[rt];       return;     }     pushDown(rt);     int mid = (l + r) >> 1;     if (_r <= mid) {       update(l, mid, rt << 1, _l, _r, x);     } else if (_l > mid) {       update(mid + 1, r, rt << 1 | 1, _l, _r, x);     } else {       update(l, mid, rt << 1, _l, _r, x);       update(mid + 1, r, rt << 1 | 1, _l, _r, x);     }     pushUp(rt);   }   int query(int l, int r, int rt, int _l, int _r) {     if (l >= _l && r <= _r) {       return Tree[rt].A[0][0];     }     pushDown(rt);     int mid = (l + r) >> 1;     if (_r <= mid) {       return query(l, mid, rt << 1, _l, _r);     } else if (_l > mid) {       return query(mid + 1, r, rt << 1 | 1, _l, _r);     }     return (query(l, mid, rt << 1, _l, _r) +             query(mid + 1, r, rt << 1 | 1, _l, _r)) %            Mod;   }   int main(void) {     int n, m;     for (int i = 0; i < 2; i++)       for (int j = 0; j < 2; j++) f.A[i][j] = 1;     f.A[1][1] = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> A[i];     }     build(1, n, 1);     while (m--) {       int type, l, r;       cin >> type >> l >> r;       if (type == 1) {         int x;         cin >> x;         update(1, n, 1, l, r, f ^ x);       } else if (type == 2) {         cout << query(1, n, 1, l, r) << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool solve() {     int a, b;     scanf( %d %d , &a, &b);     int both = int(floor(pow((double)a * b, 1.0 / 3) + 0.5));     if (both == 0) return a == 1 && b == 1;     if (a % both != 0 || b % both != 0) return false;     if ((long long)a * b != (long long)both * both * both) return false;     long long A = a / both;     long long B = b / both;     if (B * B * A != b || A * A * B != a) return false;     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       if (solve())         puts( Yes );       else         puts( No );     }   }
#include <bits/stdc++.h>   using namespace std;   void cline() { cout <<   n ; }   template <typename T, typename... V>   void cline(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<    ;     cline(v...);   }   void cspc() { cout <<    ; }   template <typename T, typename... V>   void cspc(T t, V... v) {     cout << t;     if (sizeof...(v)) cout <<    ;     cspc(v...);   }   const long long N = 2e5 + 4;   long long state[2 * N][2];   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(state, 0, sizeof(state));     long long n, m;     cin >> n >> m;     long long ind = -1;     long long a[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (m == a[i]) ind = i;     }     long long oki = 0, cnt = 0;     for (long long i = 0; i < n; i++) {       if (a[i] < m)         oki--;       else if (a[i] > m)         oki++;       if (i >= ind) state[N + oki][i & 1]++;     }     oki = 0;     for (long long i = 0; i <= ind; ++i) {       if (i % 2 == 1) {         cnt += state[N + oki + 1][0];         cnt += state[N + oki][1];       } else {         cnt += state[N + oki][0];         cnt += state[N + oki + 1][1];       }       if (a[i] < m)         oki--;       else         oki++;     }     cspc(cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long C[1200][1200];   int main() {     for (int i = 0; i < 1200; i++) C[i][i] = C[i][0] = 1LL;     for (int i = 2; i < 1200; i++)       for (int j = 1; j < i; j++)         C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 1000000007;     long long k, n, m;     scanf( %I64d%I64d%I64d , &n, &m, &k);     if (n - 1 < 2 * k || m - 1 < 2 * k)       printf( 0 n );     else       printf( %I64d n , C[n - 1][2 * k] * C[m - 1][2 * k] % 1000000007);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void chkmax(T& x, T y) {     if (x < y) x = y;   }   template <typename T>   void chkmin(T& x, T y) {     if (x > y) x = y;   }   inline int read() {     int x = 0;     char c = getchar();     bool f = 0;     while (c < 48) f |= c ==  - , c = getchar();     while (c > 47) x = x * 10 + (c ^ 48), c = getchar();     return f ? -x : x;   }   const int maxn = 5e5 + 10, P = 998244353;   int n, m, A[maxn];   char str[maxn];   inline void Add(int& x, int y) {     x += y;     if (x >= P) x -= P;   }   struct matrix {     int arr[2][2];     void clear() { memset(arr, 0, sizeof arr); }     inline int* operator[](const int& pos) { return arr[pos]; }     inline void print() {       for (int i = (0), iend = (1); i <= iend; ++i)         for (int j = (0), jend = (1); j <= jend; ++j)           printf( %d%c , arr[i][j],   n  [j < 1]);     }   } E;   matrix operator*(matrix A, matrix B) {     matrix res;     res.clear();     for (int k = (0), kend = (1); k <= kend; ++k)       for (int i = (0), iend = (1); i <= iend; ++i)         for (int j = (0), jend = (1); j <= jend; ++j)           Add(res[i][j], 1ll * A[i][k] * B[k][j] % P);     return res;   }   matrix qp(matrix A, long long k) {     matrix res = E;     for (; k; k >>= 1, A = A * A)       if (k & 1) res = res * A;     return res;   }   void minit() {     E.clear();     for (int i = (0), iend = (1); i <= iend; ++i) E[i][i] = 1;   }   matrix val[maxn << 2];   void ins(int k, int l, int r, int x) {     if (l == r) {       auto tmp = val[k].arr;       tmp[1][1] = 0, tmp[0][1] = 1;       tmp[0][0] = (A[x] + 1), tmp[1][0] = x > 1 && A[x - 1] == 1 ? 9 - A[x] : 0;       return;     }     x <= ((l + r) >> 1) ? ins(k << 1, l, ((l + r) >> 1), x)                         : ins(k << 1 | 1, ((l + r) >> 1) + 1, r, x),         val[k] = val[k << 1] * val[k << 1 | 1];   }   void solve() {     minit();     scanf( %d%d%s , &n, &m, str + 1);     for (int i = (1), iend = (n); i <= iend; ++i)       A[i] = str[i] -  0 , ins(1, 1, n, i);     while (m--) {       int xx = read(), yy = read();       A[xx] = yy;       ins(1, 1, n, xx);       if (xx < n) ins(1, 1, n, xx + 1);       printf( %d n , val[1][0][0]);     }   }   signed main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void minu(T& x, T y) {     x = min(x, y);   }   template <class T>   inline void maxu(T& x, T y) {     x = max(x, y);   }   inline long long bit(long long n) { return 1LL << n; }   template <class T>   ostream& operator<<(ostream& os, vector<T> x) {     for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)       os << *it <<    ;     return os;   }   long long dx[8] = {1, -1, 0, 0, -1, 1, 1, -1};   long long dy[8] = {0, 0, 1, -1, -1, 1, -1, 1};   const long long mod = 1e9 + 7;   long long pow2[200005];   long long memo[505][505];   long long rec(long long n, long long k, long long t) {     if (k < 0) return 0;     if (t == 0) {       return k == 0 ? 1 : 0;     }     if (n == 0) {       return (k == 0 && t == 0) ? 1 : 0;     }     if (t < n) {       return rec(t, k, t) * pow2[t * (n - t)] % mod;     }     long long& ret = memo[n][k];     if (ret >= 0) return ret;     ret = 0;     for (long long bt = 0; bt < ((long long)n); ++bt) {       ret +=           rec(n - 1, k - 1, bt) * (pow2[n - bt] - 1 + mod) % mod * pow2[bt] % mod;       ret %= mod;     }     return ret;   }   int main() {     long long n, k;     cin >> n >> k;     pow2[0] = 1;     for (long long i = 0; i < ((long long)200000); ++i)       pow2[i + 1] = pow2[i] * 2 % mod;     long long ans = 0;     for (long long i = 0; i < ((long long)505); ++i)       for (long long j = 0; j < ((long long)505); ++j) memo[i][j] = -1;     for (long long t = 0; t < ((long long)n + 1); ++t)       ans = (ans + rec(n, k, t)) % mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int cnt[200005], n, k, a[200010], ans, sum, num = 1;   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> a[i];       sum += a[i];     }     if (sum % k) {       cout <<  No ;       return 0;     } else {       sum /= k;       for (int i = 1; i < n; i++) {         ans += a[i];         cnt[num]++;         if (ans > sum) {           cout <<  No ;           return 0;         }         if (ans == sum) {           ans = 0;           num++;         }       }       ans += a[n];       if (ans != sum) {         cout <<  No ;         return 0;       } else         cnt[num]++;       cout <<  Yes  << endl;       for (int i = 1; i <= num; i++) cout << cnt[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   int isreq(char c) { return (c ==  H ) || (c ==  Q ) || (c ==  9 ); }   int main() {     int n;     cin >> n;     int cnt = 0;     string str;     for (int i = 0; i < n; i++) {       cin >> str;       if (str[1] ==  + ) {         cnt++;       } else if (str[1] ==  - ) {         cnt--;       }     }     cout << cnt << endl;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   int len(const T& c) {     return (int)c.size();   }   int main() {     int n, bb;     double b1;     vector<double> b;     cin >> n >> bb;     for (int i(0), _n(n); i < _n; ++i) {       cin >> b1;       b.push_back(b1);     }     double sum = accumulate(b.begin(), b.end(), 0);     double mx = *max_element(b.begin(), b.end());     double avg = (sum + bb) / n;     if (mx > avg) {       cout << -1;       return 0;     }     for (int i(0), _n(n); i < _n; ++i) printf( %.6f n , avg - b[i]);   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int r, c;     int j, i;     cin >> r >> c;     char a;     map<int, int> m, n;     for (j = 0; j < r; j++) {       for (i = 0; i < c; i++) {         cin >> a;         if (a ==  S ) {           m[i]++;           n[j]++;         }       }     }     cout << (r * c) - (m.size() * n.size());   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 402;   int a[maxn], f[maxn][2];   int n, m, s, ans;   int main() {     int i, j, k;     scanf( %d%d , &n, &m);     while (m--) {       scanf( %d , &k);       while (k--) {         scanf( %d , &i);         a[i] = ++s;       }     }     for (k = 1; k <= n; k++)       if (!a[k]) break;     for (i = 1; i <= s; i++) {       if (a[i] != i) {         for (j = i + 1; j <= n; j++)           if (a[j] == i) break;         if (i != k) {           f[++ans][0] = i;           f[ans][1] = k;         }         f[++ans][0] = j;         f[ans][1] = i;         a[k] = a[i];         a[i] = i;         k = j;       }     }     printf( %d n , ans);     for (i = 1; i <= ans; i++) printf( %d %d n , f[i][0], f[i][1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a, b;   int main() {     int n, m;     cin >> n >> m;     int x = n + m;     int mx = 1;     while (1LL * mx * (mx + 1) / 2 <= x) mx++;     mx--;     for (int i = mx; i >= 1; i--) {       if (n >= i) {         n -= i;         a.push_back(i);       } else {         m -= i;         b.push_back(i);       }     }     printf( %d n , (int)a.size());     for (int i : a) printf( %d  , i);     puts(  );     printf( %d n , (int)b.size());     for (int i : b) printf( %d  , i);     puts(  );   }
#include <bits/stdc++.h>   using namespace std;   int N, M, A, B;   int main() {     scanf( %d%d%d%d , &N, &M, &A, &B);     int rA = (A - 1) / M + 1, cA = A - (rA - 1) * M;     int rB = (B - 1) / M + 1, cB = B - (rB - 1) * M;     if (B == N) cB = M;     if (rA == rB) {       puts( 1 );       exit(0);     }     if (rA + 1 == rB) {       if (cA == 1 && cB == M)         puts( 1 );       else         puts( 2 );       exit(0);     }     int fA = (cA == 1);     int fB = (cB == M);     if (fA + fB) {       printf( %d n , 3 - fA - fB);       exit(0);     }     if (cB + 1 == cA)       puts( 2 );     else       puts( 3 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ans[11][11];   bool ok;   string s;   int sol;   queue<int> dulj, broj;   int pomocnopolje[11][11];   void bfs(int x, int y, int a, int b) {     broj.push(a);     dulj.push(1);     int v[10] = {0};     while (!broj.empty()) {       int duljina = dulj.front();       dulj.pop();       int br = broj.front();       broj.pop();       if (!v[(br + x) % 10]) {         v[(br + x) % 10] = duljina;         broj.push((br + x) % 10);         dulj.push(duljina + 1);       }       if (!v[(br + y) % 10]) {         v[(br + y) % 10] = duljina;         broj.push((br + y) % 10);         dulj.push(duljina + 1);       }     }     pomocnopolje[a][b] = v[b] - 1;     return;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     for (int i = 0; i < 10; i++) {       for (int j = i; j < 10; j++) {         ok = 1;         sol = 0;         for (int k = 0; k < 10; k++) {           for (int l = 0; l < 10; l++) {             bfs(i, j, k, l);           }         }         for (int znj = 1; znj < s.size() and ok; znj++) {           int a = s[znj - 1] -  0 , b = s[znj] -  0 ;           if (pomocnopolje[a][b] >= 0)             sol += pomocnopolje[a][b];           else             ok = 0;         }         if (ok) {           ans[i][j] = sol;           ans[j][i] = sol;         } else {           ans[i][j] = -1;           ans[j][i] = -1;         }       }     }     for (int i = 0; i < 10; i++) {       for (int j = 0; j < 10; j++) {         cout << ans[i][j] <<    ;       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1e5 + 5;   const int INF = 0x3f3f3f3f;   template <typename Tp>   struct RMQ {     int n;     int len[MAXN];     Tp mx[MAXN][21];     Tp mi[MAXN][21];     void build_rmq() {       for (int j = 1; (1 << j) <= n; j++)         for (int i = 1; i + (1 << j) - 1 <= n; i++) {           mx[i][j] = max(mx[i][j - 1], mx[i + (1 << (j - 1))][j - 1]);           mi[i][j] = min(mi[i][j - 1], mi[i + (1 << (j - 1))][j - 1]);         }     }     int QueryMax(int L, int R) {       if (L > R) return 0;       int k = len[R - L + 1];       return max(mx[L][k], mx[R - (1 << k) + 1][k]);     }     int QueryMin(int L, int R) {       if (L > R) return INF;       int k = len[R - L + 1];       return min(mi[L][k], mi[R - (1 << k) + 1][k]);     }     void init(Tp *a, int sz) {       n = sz;       for (int i = 1; i <= n; i++) mx[i][0] = mi[i][0] = a[i];       build_rmq();       for (int i = 0; i <= n; i++) len[i] = (i == 0 ? -1 : len[i >> 1] + 1);     }   };   RMQ<int> st;   int n, q, mx = 0, tim = 0;   vector<int> E[MAXN];   int in[MAXN], out[MAXN], pos[MAXN], dep[MAXN], fa[MAXN][20];   void dfs(int now, int f = 1, int dp = 0) {     mx = max(mx, dp);     fa[now][0] = f;     for (int i = 1; i < 20; i++) fa[now][i] = fa[fa[now][i - 1]][i - 1];     in[now] = ++tim;     dep[now] = dp;     pos[tim] = now;     for (int v : E[now]) {       dfs(v, now, dp + 1);     }     out[now] = tim;   }   int up(int L, int R, int now) {     if (in[now] <= L && out[now] >= R) return dep[now];     for (int i = 19; i >= 0; i--) {       int f = fa[now][i];       if (in[f] <= L && out[f] >= R) continue;       now = fa[now][i];     }     return dep[fa[now][0]];   }   int main() {     scanf( %d%d , &n, &q);     for (int i = 2; i <= n; i++) {       int x;       scanf( %d , &x);       E[x].push_back(i);     }     dfs(1);     st.init(in, n);     for (int i = 1; i <= q; i++) {       int l, r;       scanf( %d%d , &l, &r);       if (l == r) {         printf( %d %d n , l, mx);       } else {         int Mi = st.QueryMin(l, r);         int Mx = st.QueryMax(l, r);         int dep1, dep2;         int now1, now2;         int st1, st2;         now1 = min(st.QueryMin(l, pos[Mi] - 1), st.QueryMin(pos[Mi] + 1, r));         now2 = max(st.QueryMax(l, pos[Mx] - 1), st.QueryMax(pos[Mx] + 1, r));         st1 = pos[Mx], st2 = pos[Mi];         dep1 = up(now1, Mx, st1);         dep2 = up(Mi, now2, st2);         if (dep1 > dep2)           printf( %d %d n , st2, dep1);         else           printf( %d %d n , st1, dep2);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     while (n--) {       int a;       cin >> a;       if (a < 4) {         cout << 1 << endl;       } else {         if (a % 2 == 0) {           cout << (a / 2) << endl;         } else {           cout << ((a - 1) / 2) << endl;         }       }     }     return 0;   }