malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 500005;   struct node {     char s[10];     int len, i, v, num, ty;   } p[N], q[3][N];   int n, vst[N], tot = 0, s[3] = {0};   int f[3][N] = {0};   struct data {     char s[10];     int ty, c[2], len;   } ans[N];   int F(char s[10]) {     int i, ad = 0;     for (i = 0; i < strlen(s); i++) {       if (s[i] <  0  || s[i] >  9 ) return 0;       if (ad == 0 && s[i] ==  0 ) return 0;       ad = ad * 10 + s[i] -  0 ;     }     return ad;   }   int main() {     scanf( %d , &n);     int i, j, k, t, n1 = 0, n2;     for (i = 1; i <= n; i++) {       scanf( %s%d , p[i].s, &p[i].v);       p[i].len = strlen(p[i].s);       p[i].num = F(p[i].s);       n1 += p[i].v;     }     n2 = n - n1;     for (i = 1; i <= n; i++)       if (p[i].num && p[i].num <= n) {         vst[p[i].num] = 1;         if ((p[i].v && p[i].num <= n1) || (!p[i].v && p[i].num > n1))           p[i].ty = 3;         else {           if (p[i].v)             p[i].ty = 2, q[2][++s[2]] = p[i];           else             p[i].ty = 1, q[1][++s[1]] = p[i];         }       } else         p[i].ty = 0, q[0][++s[0]] = p[i];     for (i = 1; i <= n1; i++)       if (!vst[i]) f[1][++f[1][0]] = i;     for (i = n1 + 1; i <= n; i++)       if (!vst[i]) f[2][++f[2][0]] = i;     while (s[1] + s[2]) {       if (f[1][0] + f[2][0]) {         if (f[1][0] && s[2])           k = 1, t = 2;         else           k = 2, t = 1;         ans[++tot].ty = 1;         ans[tot].c[0] = q[t][s[t]].num;         ans[tot].c[1] = f[k][f[k][0]];         f[t][++f[t][0]] = q[t][s[t]].num;         f[k][0]--;         s[t]--;       } else {         if (s[1])           k = 2;         else           k = 1;         ans[++tot].ty = 1;         ans[tot].c[0] = q[k][s[k]].num;         ans[tot].c[1] = 999999;         f[k][++f[k][0]] = q[k][s[k]].num;         q[0][++s[0]] = q[k][s[k]];         q[0][s[0]].ty = q[0][s[0]].num = 0;         q[0][s[0]].len = 6;         for (t = 0; t < 6; t++) q[0][s[0]].s[t] =  9 ;         s[k]--;       }     }     while (s[0]) {       k = 2 - q[0][s[0]].v;       ans[++tot].ty = 2;       ans[tot].len = q[0][s[0]].len;       for (t = 0; t < ans[tot].len; t++) ans[tot].s[t] = q[0][s[0]].s[t];       ans[tot].c[0] = f[k][f[k][0]];       s[0]--;       f[k][0]--;     }     printf( %d n , tot);     for (i = 1; i <= tot; i++) {       if (ans[i].ty == 1)         printf( move %d %d n , ans[i].c[0], ans[i].c[1]);       else {         printf( move  );         for (t = 0; t < ans[i].len; t++) printf( %c , ans[i].s[t]);         printf(  %d n , ans[i].c[0]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool cmp_vector(const vector<int>& a, const vector<int>& b) {     int i;     for (i = 0; i < a.size(); i++) {       if (a[i] > b[i]) {         return false;       } else if (a[i] < b[i]) {         return true;       }     }     return false;   }   int main() {     int h, i, j, k;     int t, n, m;     int in;     scanf( %d , &n);     int c[n];     vector<vector<int> > a;     for (i = 0; i < n; i++) {       scanf( %d , &c[i]);       vector<int> e;       for (j = 0; j < c[i]; j++) {         scanf( %d , &in);         e.push_back(in);       }       a.push_back(e);     }     scanf( %d , &m);     vector<vector<int> > b;     for (i = 0; i < m; i++) {       vector<int> e;       for (j = 0; j < n; j++) {         scanf( %d , &in);         e.push_back(in - 1);       }       b.push_back(e);     }     sort(b.begin(), b.end(), cmp_vector);     vector<int> test(n);     int maxpower = 0;     vector<int> answer(n);     for (i = 0; i < n; i++) {       test[i] = c[i] - 1;     }     if (!binary_search(b.begin(), b.end(), test)) {       int power = 0;       for (i = 0; i < n; i++) {         power += a[i][test[i]];       }       if (power > maxpower) {         maxpower = power;         for (i = 0; i < n; i++) {           answer[i] = test[i];         }       }     }     for (i = 0; i < b.size(); i++) {       for (j = 0; j < n; j++) {         test[j] = b[i][j];       }       for (j = 0; j < n; j++) {         if (b[i][j] != 0) {           test[j]--;           if (!binary_search(b.begin(), b.end(), test)) {             int power = 0;             for (k = 0; k < n; k++) {               power += a[k][test[k]];             }             if (power > maxpower) {               maxpower = power;               for (k = 0; k < n; k++) {                 answer[k] = test[k];               }             }           }           test[j]++;         }       }     }     for (i = 0; i < n; i++) {       printf( %d  , answer[i] + 1);     }     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = (int)5e5 + 5;   vector<int> edges[MAXN];   int n;   int l[MAXN];   int r[MAXN];   int cur = 2;   void go(int node, int p = 0) {     int tt = 0;     for (int i : edges[node]) {       if (i == p) continue;       tt++;     }     r[node] = cur + tt;     int val = cur + tt - 1;     for (int i : edges[node]) {       if (i == p) continue;       l[i] = val;       val--;     }     cur = r[node] + 1;     for (int i : edges[node]) {       if (i == p) continue;       go(i, node);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       edges[a].push_back(b);       edges[b].push_back(a);     }     l[1] = 1;     go(1);     for (int i = 1; i <= n; i++) cout << l[i] <<     << r[i] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   FILE* in = stdin;   FILE* out = stdout;   const int MAX = 2002;   int n, k;   char a[MAX];   void solve() {     vector<pair<int, int> > ans;     int idx = 0;     while (k > 1) {       if (a[idx] !=  ( ) {         int nxt = idx + 1;         while (a[nxt] !=  ( ) nxt++;         ans.push_back(make_pair(idx, nxt));         reverse(a + idx, a + nxt + 1);       }       idx++;       if (a[idx] !=  ) ) {         int nxt = idx + 1;         while (a[nxt] !=  ) ) nxt++;         ans.push_back(make_pair(idx, nxt));         reverse(a + idx, a + nxt + 1);       }       idx++;       k--;     }     int rem = (n - idx) / 2;     for (int i = 0; i < rem; i++) {       if (a[idx + i] ==  ( ) {         continue;       } else {         int nxt = idx + i + 1;         while (a[nxt] !=  ( ) nxt++;         ans.push_back(make_pair(idx + i, nxt));         reverse(a + idx + i, a + nxt + 1);       }     }     fprintf(out,  %d n , (int)ans.size());     for (int i = 0; i < (int)ans.size(); i++)       fprintf(out,  %d %d n , ans[i].first + 1, ans[i].second + 1);   }   int main(void) {     int numTests;     fscanf(in,  %d , &numTests);     for (int test = 0; test < numTests; test++) {       fscanf(in,  %d %d , &n, &k);       fscanf(in,  %s , a);       solve();     }     return 0;   }
// Omar_Elaraby   #include <bits/stdc++.h>   using namespace std;   typedef long long ll;   #define EPS 1e-9      int main() {    ios::sync_with_stdio(false);    cin.tie(0), cout.tie(0);   // freopen( in.txt ,  r , stdin);   // freopen( out.txt ,  w , stdout);       int tt;    cin >> tt;    while (tt--) {     long long p;     vector<ll> v(3);     cin >> p;     for (ll &i : v) {      cin >> i;     }        long long ans = LLONG_MAX;     for (int i = 0; i < 3; ++i) {      if (v[i] >= p) ans = min(ans, v[i] - p);      else ans = min(ans, v[i] * ((p + v[i] - 1) / v[i]) - p);     }     cout << ans <<   n ;    }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int n, m, z;   int mapp[maxn][maxn][maxn];   bool vis[maxn][maxn][maxn];   string s;   int main() {     int ans = 0, num;     memset(vis, false, sizeof(vis));     memset(mapp, 0, sizeof(mapp));     scanf( %d%d%d , &n, &m, &z);     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         cin >> s;         for (int k = 0; k < z; k++) {           if (s[k] ==  1 ) mapp[i][j][k + 1] = 1;         }       }     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         for (int k = 1; k <= z; k++) {           if (mapp[i][j][k]) {             if (mapp[i - 1][j][k] && mapp[i + 1][j][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i][j - 1][k] && mapp[i][j + 1][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i][j][k - 1] && mapp[i][j][k + 1] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i + 1][j][k] && mapp[i][j - 1][k] &&                 !mapp[i + 1][j - 1][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (!mapp[i - 1][j + 1][k] && mapp[i][j + 1][k] &&                 mapp[i - 1][j][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i + 1][j][k] && mapp[i][j][k - 1] &&                 !mapp[i + 1][j][k - 1] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (!mapp[i - 1][j][k + 1] && mapp[i][j][k + 1] &&                 mapp[i - 1][j][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (mapp[i][j + 1][k] && mapp[i][j][k - 1] &&                 !mapp[i][j + 1][k - 1] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }             if (!mapp[i][j - 1][k + 1] && mapp[i][j][k + 1] &&                 mapp[i][j - 1][k] && !vis[i][j][k]) {               ans++;               vis[i][j][k] = true;             }           }         }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int OO = 1e9;   const double EPS = 1e-9;   template <class T>   void _db(const char* dbStr, T e) {     cout << dbStr <<   =   << e << endl;   }   template <class T, class... L>   void _db(const char* dbStr, T e, L... r) {     while (*dbStr !=  , ) cout << *dbStr++;     cout <<   =   << e <<  , ;     _db(dbStr + 1, r...);   }   template <class S, class T>   ostream& operator<<(ostream& o, const map<S, T>& v) {     o <<  [ ;     int i = 0;     for (const pair<S, T>& pr : v)       o << (!i++ ?    :  ,  ) <<  {  << pr.first <<   :   << pr.second <<  } ;     return o <<  ] ;   }   template <template <class, class...> class S, class T, class... L>   ostream& operator<<(ostream& o, const S<T, L...>& v) {     o <<  [ ;     int i = 0;     for (const auto& e : v) o << (!i++ ?    :  ,  ) << e;     return o <<  ] ;   }   template <class S, class T>   ostream& operator<<(ostream& o, const pair<S, T>& pr) {     return o <<  (  << pr.first <<  ,   << pr.second <<  ) ;   }   ostream& operator<<(ostream& o, const string& s) {     for (const char& c : s) o << c;     return o;   }   template <class T>   using V = vector<T>;   template <class T>   using VV = V<V<T>>;   template <class T>   using VVV = VV<V<T>>;   using ll = long long;   using pii = pair<int, int>;   using vi = V<int>;   using vii = V<pii>;   using vvi = VV<int>;   using mii = map<int, int>;   using umii = unordered_map<int, int>;   using si = set<int>;   using usi = unordered_set<int>;   int n, r, c;   V<string> s;   vi sum;   vvi adj;   vi path;   pii ans = make_pair(0, 0);   bool good(int i, int j) { return sum[j] - sum[i - 1] + (j - i) > c; }   void dfs(int u, int p) {     path.push_back(u);     int l = path[max(int(path.size()) - 1 - r, 0)] - u;     true;     if (l > ans.first) ans = make_pair(l, u);     for (auto& v : adj[u]) {       if (v != p) dfs(v, u);     }     path.pop_back();   }   int main() {     ios::sync_with_stdio(false);     cout.precision(10);     cin.tie(0);     cin >> n >> r >> c;     s.assign(n + 2,   );     sum.assign(n + 2, 0);     adj.assign(n + 2, vi());     for (int i = 1; i <= n; ++i) {       cin >> s[i];       sum[i] = sum[i - 1] + int(s[i].size());     }     sum.back() = OO;     vi next(n + 2, n + 1);     for (int i = 1; i <= n; ++i) {       int lo = i, hi = n + 1;       while (lo < hi) {         int mid = (lo + hi) / 2;         if (good(i, mid))           hi = mid;         else           lo = mid + 1;       }       true;       next[i] = lo;       adj[next[i]].push_back(i);     }     true;     for (int i = 1; i <= n + 1; ++i) {       if (next[i] == i) dfs(i, i);     }     true;     if (!ans.first)       cout <<   n ;     else {       for (int l = ans.second, r = ans.second + ans.first, Sz = int(s[l].size());            l < r; ++l) {         cout << s[l];         if (l + 1 == r || (l + 1 < r && Sz + 1 + int(s[l + 1].size()) > c)) {           cout <<   n ;           Sz = int(s[l + 1].size());         } else {           cout <<    ;           Sz += 1 + int(s[l + 1].size());         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int q;     cin >> q;     for (int j = 0; j < q; j++) {       int n;       long long int k;       cin >> n >> k;       long long int a[n];       for (int i = 0; i < n; i++) {         cin >> a[i];       }       sort(a, a + n);       long long int mi, ma;       mi = a[0];       ma = a[n - 1];       long long int diff = ma - mi;       if (diff % 2 == 0)         diff = diff / 2;       else         diff = diff / 2 + 1;       if (k >= diff) {         cout << mi + k << endl;       } else         cout << -1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   using vi = vector<int>;   using vvi = vector<vi>;   using vvvi = vector<vvi>;   using ll = long long;   using vll = vector<ll>;   using vvll = vector<vll>;   using vvvll = vector<vvll>;   using ull = unsigned long long;   using vb = vector<bool>;   using vvb = vector<vb>;   using vd = vector<double>;   using vvd = vector<vd>;   using vvvd = vector<vvd>;   using vs = vector<string>;   using vvs = vector<vs>;   using vc = vector<char>;   using vvc = vector<vc>;   using ii = pair<int, int>;   using vii = vector<ii>;   using vvii = vector<vii>;   using dd = pair<double, double>;   using vdd = vector<dd>;   using vvdd = vector<vdd>;   using Mii = map<int, int>;   using vMii = vector<Mii>;   using Si = set<int>;   using vSi = vector<Si>;   using vvSi = vector<vSi>;   int main() {     int n;     while (cin >> n) {       vi a;       vector<pair<ll, ll>> v(n);       for (int i = 0; i < n; ++i) {         int x, y;         cin >> x >> y;         v[i] = {x, y};       }       vll d(n);       for (int i = 0; i < n; ++i) {         d[i] = (v[i].first - v[0].first) * (v[i].first - v[0].first) +                (v[i].second - v[0].second) * (v[i].second - v[0].second);       }       bool par = true;       for (int i = 0; i < n and par; ++i) {         if (d[i] & 1LL) par = false;       }       while (par) {         for (int i = 0; i < n; ++i) {           d[i] >>= 1LL;           if (d[i] & 1LL) par = false;         }       }       for (int i = 0; i < n; ++i)         if (d[i] & 1LL) a.push_back(i + 1);       cout << a.size() << endl;       for (int x : a) cout << x <<    ;       cout << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int N;   signed long long mo = 1000000007;   signed long long ret = 1;   signed long long from[303][303];   signed long long to[303][303];   signed long long combi(int P_, int Q_) {     static const int N_ = 1020;     static signed long long C_[N_][N_];     if (C_[0][0] == 0) {       int i, j;       for (i = 0; i < (N_); i++) C_[i][0] = C_[i][i] = 1;       for (i = 1; i < N_; i++)         for (j = 1; j < i; j++) C_[i][j] = (C_[i - 1][j - 1] + C_[i - 1][j]) % mo;     }     if (P_ < 0 || P_ > N_ || Q_ < 0 || Q_ > P_) return 0;     return C_[P_][Q_];   }   signed long long hcomb(int P_, int Q_) {     return (P_ == 0 && Q_ == 0) ? 1 : combi(P_ + Q_ - 1, Q_);   }   void solve() {     int i, j, k, l, r, x, y;     string s;     map<int, int> M;     cin >> N;     for (i = 0; i < (N); i++) {       cin >> x;       for (j = 2; j * j <= x; j++)         while (x % (j * j) == 0) x /= j * j;       M[x]++;     }     from[1][0] = 1;     for (auto& r : M) {       int cnt = r.second;       for (j = 1; j <= cnt; j++) ret = ret * j % mo;       memset(to, 0, sizeof(to));       for (x = 0; x < (N + 2); x++)         for (y = 0; y < (N + 2); y++)           if (from[x][y]) {             for (j = 1; j <= min(x + y, cnt); j++) {               signed long long a = hcomb(j, cnt - j);               int add = cnt - j;               for (int z = 0; z <= min(j, x); z++) {                 int w = j - z;                 if (w > y) continue;                 signed long long b = combi(x, z);                 signed long long c = combi(y, w);                 (to[x + z + 2 * w][y - w + add] +=                  a * b % mo * c % mo * from[x][y]) %= mo;               }             }           }       swap(from, to);     }     cout << ret * from[N + 1][0] % mo << endl;   }   int main(int argc, char** argv) {     string s;     int i;     if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);     for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s +=   n ;     for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 52;   struct node {     int v, w, nxt;   } e[N << 1];   int s, n, m, first[N], cnt = 1, siz[N], de[N];   inline void add(int u, int v, int w) {     e[++cnt].v = v;     e[cnt].w = w;     e[cnt].nxt = first[u];     first[u] = cnt;     ++de[u];   }   inline void dfs(int u, int f) {     for (int i = first[u]; i; i = e[i].nxt) {       int v = e[i].v;       if (v == f) continue;       dfs(v, u);       siz[u] += siz[v];     }   }   int dp[N << 1][N][N];   inline int solve(int i, int x, int y) {     if (x + y == 0) return 0;     int v = e[i].v;     int &f = dp[i][x][y];     if (f != -1) return f;     if (de[v] == 1) {       if (y == 0)         return 0;       else {         f = solve(i ^ 1, y, 0) + e[i].w;         return f;       }     }     int g[N];     memset(g, 0, sizeof(g));     g[0] = 0x3f3f3f3f;     for (int j = first[v]; j; j = e[j].nxt) {       if (j == (i ^ 1)) continue;       for (int k = x; k >= 1; --k)         for (int w = k; w; --w)           g[k] = max(g[k], min(g[k - w], e[j].w + solve(j, w, x + y - w)));     }     return f = g[x];   }   int main() {     memset(dp, -1, sizeof(dp));     scanf( %d , &n);     for (int i = 1, u, v, w; i < n; ++i) {       scanf( %d%d%d , &u, &v, &w);       add(u, v, w);       add(v, u, w);     }     scanf( %d%d , &s, &m);     for (int i = 1, x; i <= m; ++i) {       scanf( %d , &x);       siz[x]++;     }     dfs(s, 0);     int ans = 0x3f3f3f3f;     for (int i = first[s]; i; i = e[i].nxt) {       int v = e[i].v;       ans = min(ans, solve(i, siz[v], m - siz[v]) + e[i].w);     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct chip {     char dir;     chip *u, *r, *d, *l;     chip(char _dir) {       dir = _dir;       u = r = d = l = NULL;     }   };   int main(int argc, char* argv[]) {     int n, m;     cin >> n >> m;     chip*** t;     t = (chip***)malloc(n * sizeof(chip**));     for (int i = 0; i < n; i++) t[i] = (chip**)malloc(m * sizeof(chip*));     char d;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> d;         if (d !=  . ) {           t[i][j] = new chip(d);           if (i > 0) {             int k = i - 1;             while ((k >= 0) && (t[k][j] == NULL)) k--;             if (k >= 0) {               t[k][j]->d = t[i][j];               t[i][j]->u = t[k][j];             }           }           if (j > 0) {             int k = j - 1;             while ((k >= 0) && (t[i][k] == NULL)) k--;             if (k >= 0) {               t[i][k]->r = t[i][j];               t[i][j]->l = t[i][k];             }           }         } else           t[i][j] = NULL;       }     }     int max = 0;     int count = 0;     vector<chip*> v;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         v.clear();         chip* c = t[i][j];         while (c != NULL) {           v.push_back(c);           chip* e;           if (c->dir ==  U ) e = c->u;           if (c->dir ==  R ) e = c->r;           if (c->dir ==  D ) e = c->d;           if (c->dir ==  L ) e = c->l;           if (c->u != NULL) c->u->d = c->d;           if (c->r != NULL) c->r->l = c->l;           if (c->d != NULL) c->d->u = c->u;           if (c->l != NULL) c->l->r = c->r;           c = e;         }         if (v.size() > max) {           max = v.size();           count = 0;         }         if (v.size() == max) count++;         for (vector<chip*>::reverse_iterator r = v.rbegin(); r < v.rend(); r++) {           chip* e = *r;           if (e->u != NULL) e->u->d = e;           if (e->r != NULL) e->r->l = e;           if (e->d != NULL) e->d->u = e;           if (e->l != NULL) e->l->r = e;         }       }     }     cout << max <<     << count << endl;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) free(t[i][j]);     for (int i = 0; i < n; i++) free(t[i]);     free(t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, ans, c, d;   int a[1005][1005], b[1005][1005];   string s[1003];   int main() {     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> s[i];     }     for (int i = 0; i < n; i++) {       d = 0;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  * ) d++;       }       (d > 0) ? d-- : d;       for (int j = 0; j < m; j++) {         if (s[i][j] ==  * ) a[i][j] = d;       }     }     for (int i = 0; i < m; i++) {       d = 0;       for (int j = 0; j < n; j++) {         if (s[j][i] ==  * ) d++;       }       (d > 0) ? d-- : d;       for (int j = 0; j < n; j++) {         if (s[j][i] ==  * ) b[j][i] = d;       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (s[i][j] ==  * ) {           ans += a[i][j] * b[i][j];         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N_MAX = 102;   const int K_MAX = 10002;   const int MOD = 1e9 + 7;   int pwr(int a, long long b) {     if (b == 0) return 1;     if (b & 1) return 1LL * a * pwr(a, (b ^ 1)) % MOD;     int aux = pwr(a, (b >> 1));     return 1LL * aux * aux % MOD;   }   int n, k;   long long m;   int comb[N_MAX];   int pw[N_MAX][N_MAX];   int dp[N_MAX][K_MAX];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 0; i <= n; i++) {       comb[i] = 1;       for (int j = i + 1; j <= n; j++) comb[i] = 1LL * comb[i] * j % MOD;       for (int j = 1; j <= n - i; j++)         comb[i] = 1LL * comb[i] * pwr(j, MOD - 2) % MOD;     }     for (int c = 0; c <= n; c++)       for (int i = 1; i <= n; i++) pw[c][i] = pwr(comb[c], (m - i) / n + 1);     dp[0][0] = 1;     for (int i = 1; i <= n; i++)       for (int j = 0; j <= k; j++) {         for (int c = 0; c <= j && c <= n; c++) {           dp[i][j] += 1LL * dp[i - 1][j - c] * pw[c][i] % MOD;           if (dp[i][j] >= MOD) dp[i][j] -= MOD;         }       }     cout << dp[n][k] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<int> A(n + 7);     for (int i = 1; i <= n; i++) cin >> A[i];     vector<int> B(n);     for (int i = 1; i <= n; i++) B[i - 1] = i;     sort(B.begin(), B.end(), [&](int a, int b) { return A[a] > A[b]; });     set<int> G, S;     multiset<int> O;     G.insert(0);     G.insert(n + 1);     O.insert(n + 1);     int ret = A[B[0]] + 1, loc = 1;     for (int bb = 0; bb < n; bb++) {       int b = B[bb];       auto jt = G.upper_bound(b);       auto it = prev(jt);       int dif = (*jt - *it);       O.erase(O.find(dif));       int p = (*jt - b);       int q = (b - *it);       if (p != 1) O.insert(p);       if (q != 1) O.insert(q);       if ((O.empty() or *O.begin() == *O.rbegin()) and loc <= int(O.size())) {         loc = int(O.size());         ret = A[B[bb + 1]] + 1;       }       G.insert(b);     }     cout << ret <<   n ;     return 0;   }