malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n;   string a;   int f[1005][5];   int main() {     cin >> n >> a;     string t =   , s =   ;     char cur =  0 ;     for (int i = 0; i <= n - 1; i++) {       t += cur;       s +=  1  - cur +  0 ;       cur =  1  - cur +  0 ;     }     int ans = (int)2e9;     int res = 0, res1 = 0;     for (int i = 0; i <= n - 1; i++) {       if (a[i] != s[i]) res++;       if (a[i] != t[i]) res1++;     }     ans = min(res1, res);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, k;   string s;   int MOD = 1e9 + 7;   const int INF = 1e9;   const long long INF64 = 2e18;   const double PI = 3.141592653589793238463;   long long ar[1000004], ar1[1000004], vis[1000004], pre[1000004], dp[3004][3004];   vector<long long> gr[1000004], path;   set<long long> myset;   pair<long long, long long> seg[1000004];   map<long long, long long> mymap;   long long c = 0;   string st1[1000004], st2[1000004];   vector<long long> arr[1000004];   int comp(pair<long long, long long> a, pair<long long, long long> b) {     return a.second < b.second;   }   int gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(nullptr);     cin >> n;     double w, cargo;     cin >> w;     for (int i = 0; i < int(n); i++) cin >> ar[i];     for (int i = 0; i < int(n); i++) cin >> ar1[i];     if (ar[0] == 1 || ar1[0] == 1) return cout << -1, 0;     cargo = w;     w += w / (ar1[0] - 1);     for (int i = n - 1; i > 0; i--) {       if (ar[i] == 1 || ar1[i] == 1) return cout << -1, 0;       w += w / (ar[i] - 1);       w += w / (ar1[i] - 1);     }     w += w / (ar[0] - 1);     return printf( %10.10f , w - cargo), 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 7005;   const int M = 200000;   struct state {     int l, r, val;     state() {}     state(int l, int r, int val) {       this->l = l;       this->r = r;       this->val = val;     }   };   int n, m, dl[M], dr[M];   vector<state> v[N];   int solve(int d, int x, int y) {     set<int> ans;     for (int i = d; i <= n; i++) {       for (int j = 0; j < v[i].size(); j++) {         state& c = v[i][j];         if (c.l <= y && c.r >= x) ans.insert(c.val);       }       x = (dl[x] == -1 ? dr[x] : dl[x]);       y = dr[y];     }     return ans.size();   }   void init() {     int cnt = 1, p = 3;     memset(dl, -1, sizeof(dl));     memset(dr, -1, sizeof(dr));     dl[1] = 1;     dr[1] = 2;     for (int i = 2; i < M; i++) {       if ((1 << cnt) == i) {         cnt++;         dl[i] = p++;       }       dr[i] = p++;     }   }   int main() {     init();     int order, d, x, y, val;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d , &order);       if (order == 1) {         scanf( %d%d%d%d , &d, &x, &y, &val);         v[d].push_back(state(x, y, val));       } else {         scanf( %d%d , &d, &x);         printf( %d n , solve(d, x, x));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modpow(long long base, long long exp, long long modulus) {     base %= modulus;     long long result = 1;     while (exp > 0) {       if (exp & 1) result = (result * base) % modulus;       base = (base * base) % modulus;       exp >>= 1;     }     return result;   }   int main() {     long long n, k;     cin >> n >> k;     long long w[100001];     long long q[100001];     memset(q, 0, sizeof(q));     memset(w, 0, sizeof(w));     w[0] = 1;     if (1 >= k)       w[1] = 2;     else       w[1] = 1;     q[0] = 0;     q[1] += q[0] + w[1];     for (long long i = 2; i < 100001; i++) {       if (k <= i) {         w[i] += (w[i - 1] + w[i - k] - 1000000007) % 1000000007;       } else         w[i] = 1;       q[i] += (q[i - 1] + w[i] - 1000000007) % 1000000007;       q[i] %= 1000000007;     }     while (n--) {       long long a, b;       cin >> a >> b;       cout << (q[b] - q[a - 1] + 1000000007) % 1000000007 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   const long long inf = 0x3f3f3f3f;   using namespace std;   const long long maxn = 2e5 + 100;   long long n, k;   long long a[maxn];   int32_t main() {     long long q;     scanf( %lld , &(q));     while (q--) {       scanf( %lld%lld , &(n), &(k));       long long maxx = 0, minn = 0x3f3f3f3f;       for (long long i = (1); i <= (n); i++) {         scanf( %lld , &(a[i]));         if (maxx < a[i]) maxx = a[i];         if (minn > a[i]) minn = a[i];       }       long long x = minn + k;       if (abs(x - maxx) > k)         printf( -1 );       else         printf( %lld , (x));       printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline int read() {     char c = getchar();     int x = 0, f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = x * 10 + c -  0 ;       c = getchar();     }     return x * f;   }   const int maxn = 1e6 + 10;   const int inf = 2147483647;   int main() {     vector<int> v, prim;     vector<bool> isprim;     int lim = sqrt(1.0 * 1000000000) + 10;     isprim.resize(lim);     isprim[0] = isprim[1] = 1;     for (int i = 2; i <= lim; ++i) {       if (isprim[i] == false) {         for (int j = i + i; j <= lim; j = j + i) isprim[j] = true;       }     }     for (int i = 2; i <= lim; ++i) {       if (isprim[i] == false) prim.push_back(i);     }     int sz = prim.size();     set<int> se;     set<int>::iterator it;     int T;     scanf( %d , &T);     while (T--) {       int n = read();       bool flag = false;       se.clear();       for (int i = 2; i * i <= n; ++i) {         if (n % i == 0 && isprim[i] == false) {           se.insert(i);           n /= i;           flag = true;           break;         }       }       if (!flag) {         puts( NO );         continue;       }       flag = false;       for (int i = sqrt(n); i >= 2; i--) {         if (n % i == 0 && se.count(i) == 0 && se.count(n / i) == 0 &&             i != n / i) {           flag = true;           se.insert(i);           se.insert(n / i);           break;         }       }       if (!flag) {         puts( NO );         continue;       }       puts( YES );       for (it = se.begin(); it != se.end(); ++it) {         printf( %d  , *it);       }       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   int max(int a, int b) { return a < b ? b : a; }   int min(int a, int b) { return a < b ? a : b; }   void swap(int *a, int *b) {     int t = *a;     *a = *b;     *b = t;   }   int can(int x, int y, int a, int b) {     if ((x <= a && y <= b) || (x <= b && y <= a)) return 1;     return 0;   }   int cal(int x1, int y1, int x2, int y2, int a, int b) {     if (x1 > y1) swap(&x1, &y1);     if (x2 > y2) swap(&x2, &y2);     if (can(x1 + x2, max(y1, y2), a, b)) return x1 * y1 + x2 * y2;     if (can(max(x1, x2), y1 + y2, a, b)) return x1 * y1 + x2 * y2;     if (can(max(x2, y1), x1 + y2, a, b)) return x1 * y1 + x2 * y2;     if (can(max(x1, y2), y1 + x2, a, b)) return x1 * y1 + x2 * y2;     return 0;   }   int main() {     int maxx = 0, n, a, b, i, j, s[200][2];     scanf( %d %d %d , &n, &a, &b);     for (i = 0; i < n; i++) scanf( %d %d , &s[i][0], &s[i][1]);     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         int k = cal(s[i][0], s[i][1], s[j][0], s[j][1], a, b);         if (maxx < k) maxx = k;       }     }     printf( %d n , maxx);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 300000;   int x[N][2];   int ans[N];   bool hear[N];   vector<pair<int, int> > G[N];   int color[N];   void dfs1(int s) {     color[s] = 1;     for (int i = 0; i < (int)G[s].size(); i++) {       int v = G[s][i].first;       if (color[v] == 0) {         if (G[s][i].second > 0) {           ans[G[s][i].second] = 1;         } else {           ans[-G[s][i].second] = 0;         }         dfs1(v);       }     }     color[s] = 2;   }   pair<int, int> cyc;   void dfs2(int s, int per = -1) {     color[s] = 1;     for (int i = 0; i < (int)G[s].size(); i++) {       int v = G[s][i].first;       if (color[v] == 0) {         dfs2(v, abs(G[s][i].second));       }       if ((color[v] == 1) && (per != abs(G[s][i].second))) {         cyc.first = s;         cyc.second = i;       }     }     color[s] = 2;   }   int color1[N];   void dfs3(int s, int per) {     color1[s] = 1;     for (int i = 0; i < (int)G[s].size(); i++) {       int v = G[s][i].first;       if (abs(G[s][i].second) == per) {         continue;       }       if (color1[v] == 0) {         ans[abs(G[s][i].second)] = (G[s][i].second > 0 ? 1 : 0);         dfs3(v, abs(G[s][i].second));       }     }     color1[s] = 2;   }   int main() {     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       int k;       scanf( %d , &k);       for (int j = 0; j < k; j++) {         int r;         scanf( %d , &r);         if (x[abs(r)][0] == 0) {           x[abs(r)][0] = i * (r > 0 ? 1 : -1);         } else {           x[abs(r)][1] = i * (r > 0 ? 1 : -1);         }       }     }     for (int i = 1; i <= m; i++) {       if ((x[i][0] >= 0) && (x[i][1] >= 0)) {         ans[i] = 1;         hear[x[i][0]] = 1;         hear[x[i][1]] = 1;       } else if ((x[i][0] <= 0) && (x[i][1] <= 0)) {         ans[i] = 0;         hear[-x[i][0]] = 1;         hear[-x[i][1]] = 1;       } else {         int v1 = abs(x[i][0]);         int v2 = abs(x[i][1]);         G[v1].push_back(make_pair(v2, i * (x[i][1] > 0 ? 1 : -1)));         G[v2].push_back(make_pair(v1, i * (x[i][0] > 0 ? 1 : -1)));       }     }     for (int i = 1; i <= n; i++) {       if ((hear[i] == 1) && (color[i] == 0)) {         dfs1(i);       }     }     for (int i = 1; i <= n; i++) {       if (color[i] == 0) {         cyc.first = 0;         dfs2(i);         if (cyc.first == 0) {           cout <<  NO  << endl;           return 0;         } else {           int s = cyc.first;           int j = cyc.second;           ans[abs(G[s][j].second)] = (G[s][j].second > 0 ? 1 : 0);           dfs3(G[s][j].first, abs(G[s][j].second));         }       }     }     cout <<  YES  << endl;     for (int i = 1; i <= m; i++) {       cout << ans[i];     }     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int bits = 10;   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     vector<pair<string, int> > commands;     for (int i = 0; i < n; ++i) {       string tp;       int x;       cin >> tp >> x;       commands.emplace_back(tp, x);     }     int ansxor = 0;     int ansand = (1 << bits) - 1;     int ansor = 0;     for (int bit = 0; bit < bits; ++bit) {       vector<int> f = {0, 1};       for (int index = 0; index < 2; ++index) {         for (int i = 0; i < n; ++i) {           string tp;           int x;           tie(tp, x) = commands[i];           x = (x >> bit) & 1;           if (tp ==  & ) f[index] &= x;           if (tp ==  | ) f[index] |= x;           if (tp ==  ^ ) f[index] ^= x;         }       }       if (f == vector<int>{0, 0}) {         ansand ^= 1 << bit;       } else if (f == vector<int>{1, 0}) {         ansxor ^= 1 << bit;       } else if (f == vector<int>{1, 1}) {         ansor ^= 1 << bit;       }     }     cout << 3 << endl;     cout <<  ^   << ansxor << endl;     cout <<  &   << ansand << endl;     cout <<  |   << ansor << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     vector<pair<int, int>> times;     for (int i = 0; i < m; i++) {       int s, e;       cin >> s >> e;       times.push_back(make_pair(s, e));     }     sort(times.begin(), times.end(), [](pair<int, int> a, pair<int, int> b) {       return (a.first == b.first) ? (a.second < b.second) : (a.first < b.first);     });     vector<int> ans(n, 0);     for (auto t : times) {       for (int i = t.first + 1; i <= t.second; i++) {         ans[i - 1] = !ans[i - 2];       }     }     for (auto a : ans) cout << a;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[100001];   long long vis[100001] = {0};   long long n;   long long nodecolor[100001];   long long treecolor[100001];   long long cc[100001];   map<long long, long long> colorcnt;   long long dfs(long long root, long long col) {     long long cnt = 1;     vis[root] = 1;     treecolor[root] = nodecolor[root];     for (auto x : adj[root]) {       if (vis[x] == 0 && nodecolor[x] != col) treecolor[root] = -1;     }     long long flag = 0;     for (auto x : adj[root]) {       if (vis[x] == 0) {         flag = 1;         cnt += dfs(x, nodecolor[x]);         if (treecolor[x] != nodecolor[root]) treecolor[root] = -1;       }     }     if (flag == 0) {       treecolor[root] = nodecolor[root];     }     return cc[root] = cnt;   }   long long fun(long long root) {     vis[root] = 1;     long long flag = 0;     set<long long> st;     long long parentcolor = -1;     for (auto x : adj[root]) {       if (vis[x] == 0) {         if (treecolor[x] == -1) flag = 1;       } else {         parentcolor = nodecolor[x];       }     }     if (flag == 0) {       if (parentcolor == -1) return root;       for (auto x : adj[root]) {         if (vis[x] == 0) {           colorcnt[treecolor[x]] -= cc[x];         }       }       colorcnt[nodecolor[root]]--;       if (colorcnt[parentcolor] == n - cc[root]) {         return root;       }       for (auto x : adj[root]) {         if (vis[x] == 0) {           colorcnt[treecolor[x]] += cc[x];         }       }       colorcnt[nodecolor[root]]++;     }     long long ans = -1;     for (auto x : adj[root]) {       if (vis[x] == 0) {         ans = fun(x);         if (ans != -1) return ans;       }     }     return ans;   }   void solve(long long cno) {     long long m, i, j, k, l;     cin >> n;     long long flag = 0;     for (i = 0; i < n - 1; i++) {       cin >> j >> k;       j--;       k--;       adj[j].push_back(k);       adj[k].push_back(j);     }     for (i = 0; i < n; i++) {       cin >> nodecolor[i];       colorcnt[nodecolor[i]]++;     }     long long temp = dfs(0, nodecolor[0]);     for (i = 0; i < n; i++) vis[i] = 0;     long long ans = -1;     ans = fun(0);     if (ans == -1)       cout <<  NO ;     else {       cout <<  YES  <<   n  << ans + 1;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     long long i = 1;     while (TESTS--) {       solve(i);       i++;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 5;   long long dp[N], f[N], ok[N], p[N];   vector<long long> node[N];   long long cur, now;   void dfs(long long u, long long p) {     for (auto j : node[u]) {       if (j == p) continue;       dfs(j, u);       if (f[j]) {         dp[u] += dp[j] + 1;         f[u] = 1;       }     }     if (ok[u]) f[u] = 1;   }   void find_dia(long long u, long long p, long long dis) {     if (dis >= cur && ok[u]) {       if (dis > cur)         now = u;       else         now = min(now, u);       cur = dis;     }     for (auto j : node[u]) {       if (j == p) continue;       find_dia(j, u, dis + 1);     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     if (fopen( A.INP ,  r )) {       freopen( A.INP ,  r , stdin);       freopen( A.OUT ,  w , stdout);     }     long long n, m;     cin >> n >> m;     for (int i = 1; i < n; i++) {       long long u, v;       cin >> u >> v;       node[u].push_back(v);       node[v].push_back(u);     }     for (int i = 1; i <= m; i++) cin >> p[i], ok[p[i]] = 1;     dfs(p[1], p[1]);     long long ans = dp[p[1]] * 2;     cur = 0;     now = 1e9;     find_dia(p[1], p[1], 0);     cur = 0;     long long f = now;     now = 1e9;     find_dia(f, f, 0);     cout << min(f, now) <<   n ;     cout << ans - cur;   }
#include <bits/stdc++.h>   using namespace std;   long long Set(long long N, int pos) { return N = N | (1LL << pos); }   long long reset(long long N, int pos) { return N = N & ~(1LL << pos); }   bool check(long long N, int pos) { return (bool)(N & (1LL << pos)); }   struct node {     bool endmark;     node *next[2];     node() {       endmark = 0;       for (int i = 0; i < 2; i++) next[i] = NULL;     }   } * root;   void insert(long long m) {     node *cur = root;     for (int i = 63; i >= 0; i--) {       int id = check(m, i);       if (cur->next[id] == NULL) cur->next[id] = new node();       cur = cur->next[id];     }     cur->endmark = true;   }   long long query(long long m) {     node *cur = root;     long long ret = 0;     for (int i = 63; i >= 0; i--) {       int id = check(m, i);       int a = 1 - id;       if (cur->next[a] != NULL) {         ret = Set(ret, i);         cur = cur->next[a];       } else         cur = cur->next[id];     }     return ret;   }   long long ara[100005], lft[100005], rgt[100005];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     root = new node();     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> ara[i];     for (int i = 1; i <= n; i++) lft[i] = lft[i - 1] ^ ara[i];     for (int i = n; i >= 1; i--) rgt[i] = rgt[i + 1] ^ ara[i];     long long ans = 0;     insert(0);     for (int i = 1; i <= n; i++) {       long long temp = query(rgt[i]);       ans = max(ans, temp);       insert(lft[i]);     }     ans = max(ans, query(0));     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string to_string(string c) { return string(c); }   string to_string(char ch) { return string(1, ch); }   template <size_t N>   string to_string(bitset<N> B) {     string second =   ;     for (long long i = 0; i < (long long)N; i++) second += (char) 0  + B[i];     return second;   }   template <typename T, typename U>   string to_string(pair<T, U> P) {     return  {  + to_string(P.first) +  ,  + to_string(P.second) +  } ;   }   template <typename T>   string to_string(T A) {     string second =  [ ;     bool first = 0;     for (auto x : A) {       if (first) second +=    ;       first = 1;       second += to_string(x);     }     return second +  ] ;   }   template <typename T, size_t N>   string to_string(T (&A)[N]) {     string second =  [ ;     bool first = 0;     for (long long i = 0; i < N; i++) {       if (first) second +=    ;       first = 1;       second += to_string(A[i]);     }     return second +  ] ;   }   void _deb() {     cerr <<  ]           <<   n ;   }   template <typename T, typename... U>   void _deb(const T& t, const U&... u) {     cerr << to_string(t);     if (sizeof...(u)) cout <<  ,  ;     _deb(u...);   }   long long ceil(long long a, long long b) {     return a / b + (a % b && (a ^ b) > 0);   }   long long floor(long long a, long long b) {     return a / b - (a % b && (a ^ b) < 0);   }   long long SBITS(long long n) { return __builtin_popcountll(n); }   long long BITS(long long n) { return 63 - __builtin_clzll(n); }   const long long MX = 3e5 + 5;   const long long OO = 1e18;   const long long MOD = 998244353;   long long DX[8] = {1, 0, -1, 0, 1, -1, 1, -1};   long long DY[8] = {0, 1, 0, -1, 1, -1, -1, 1};   long long FAC[MX];   long long FACINV[MX];   long long nCr(long long n, long long r) {     if (n < r) return 0;     return FAC[n] * FACINV[r] % MOD * FACINV[n - r] % MOD;   }   long long fastExp(long long base, long long expo, long long mod) {     if (expo == 0) return 1;     if (expo == 1) return base % mod;     long long t = fastExp(base, expo / 2, mod);     t = (t * t) % mod;     if (expo % 2 == 0)       return t;     else       return ((base % mod) * t) % mod;   }   void calcFact() {     FAC[1] = 1;     for (long long i = 2; i < MX; i++) FAC[i] = i * FAC[i - 1] % MOD;     FACINV[MX - 1] = fastExp(FAC[MX - 1], MOD - 2, MOD);     for (long long i = MX - 1; i > 0; i--) FACINV[i - 1] = i * FACINV[i] % MOD;   }   void solve() {     calcFact();     long long n, ans = 0;     cin >> n;     vector<long long> l(n), r(n);     for (long long i = 0; i < n; i++) cin >> l[i];     for (long long i = 0; i < n; i++) cin >> r[i];     sort(l.begin(), l.end());     sort(r.begin(), r.end());     reverse(r.begin(), r.end());     for (long long i = 0; i < n; i++) ans += abs(l[i] - r[i]);     ans %= MOD;     ans *= nCr(2 * n, n);     ans %= MOD;     cout << ans <<   n ;   }   int32_t main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   char s[maxn], t[maxn], st[maxn];   long long cnts[maxn], cntt[maxn];   long long Next[maxn];   int n, m;   long long ans;   long long lent, lens;   long long f, e;   void init() {     ans = 0;     lent = lens = 0;     s[0] = t[0] = 0;     char c[2];     long long x;     for (int i = 1; i <= n; i++) {       scanf( %I64d-%s , &x, c);       if (c[0] == s[lens])         cnts[lens] += x;       else {         cnts[++lens] = x;         s[lens] = c[0];       }     }     for (int i = 1; i <= m; i++) {       scanf( %I64d-%s , &x, c);       if (c[0] == t[lent])         cntt[lent] += x;       else {         cntt[++lent] = x;         t[lent] = c[0];       }     }   }   void getnxt() {     Next[0] = Next[1] = 0;     long long j = 0;     for (long long i = 2; i <= lent - 2; i++) {       while (j && (st[j + 1] != st[i] || cntt[i] != cntt[j + 1])) j = Next[j];       if (st[j + 1] == st[i] && cntt[i] == cntt[j + 1]) j++;       Next[i] = j;     }   }   long long kmp() {     long long sum = 0;     long long j = 0;     for (long long i = 2; i < lens; i++) {       while (j && (st[j + 1] != s[i] || cnts[i] != cntt[j + 1])) j = Next[j];       if (st[j + 1] == s[i] && cnts[i] == cntt[j + 1]) j++;       if (j == lent - 2) {         if (s[i - (lent - 2)] == t[1] && s[i + 1] == t[lent] &&             cnts[i - (lent - 2)] >= f && cnts[i + 1] >= e)           sum++;         j = Next[j];       }     }     return sum;   }   int main() {     while (scanf( %d %d , &n, &m) != EOF) {       init();       if (lent == 1) {         for (int i = 1; i <= lens; i++) {           if (s[i] == t[lent] && cnts[i] >= cntt[lent])             ans += cnts[i] - cntt[lent] + 1;         }       } else if (lent == 2) {         for (int i = 1; i < lens; i++) {           if (s[i] == t[1] && s[i + 1] == t[2] && cnts[i] >= cntt[1] &&               cnts[i + 1] >= cntt[2])             ans++;         }       } else {         strcpy(st + 1, t + 2);         st[lent] = 0;         f = cntt[1], e = cntt[lent];         for (int i = 1; i < lent; i++) cntt[i] = cntt[i + 1];         getnxt();         ans = kmp();       }       printf( %I64d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   int n, a[N], b[N];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     sort(a + 1, a + 1 + n);     for (int i = 1; i <= n / 2; i++) {       b[i * 2 - 1] = a[i];       b[i * 2] = a[n - i + 1];     }     if (n % 2) b[n] = a[n / 2 + 1];     int flag = 1;     for (int i = 3; i <= n; i += 2) {       if (b[i] > b[i - 1]) {         flag = 0;         break;       }     }     for (int i = 2; i <= n && flag; i += 2) {       if (b[i] < b[i - 1]) {         flag = 0;         break;       }     }     if (!flag) {       puts( Impossible );       return 0;     }     for (int i = 1; i <= n; i++) {       printf( %d , b[i]);       putchar(i == n ?   n  :    );     }     return 0;   }