malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     int n, i, j, k, value;     cin >> n;     int x = n;     while (x--) {       cin >> value;       v.push_back(value);     }     for (i = 0; i < n; i++)       for (j = 0; j < n; j++) {         if (i == j) j++;         for (k = j + 1; k <= n - 1; k++) {           if (k == i) k++;           if (k == n) break;           if (v[i] == v[j] + v[k]) {             cout << i + 1 <<     << k + 1 <<     << j + 1;             return 0;           }         }       }     cout <<  -1 ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     int ans = 0;     int n = s.length();     for (int i = 0; i < n; i++) {       if (s[i] != s[n - i - 1]) {         ans = -1;         break;       }     }     if (ans != -1)       cout << 0 << endl;     else {       cout << 3 << endl;       cout <<  R   << 2 << endl;       cout <<  L   << s.length() << endl;       cout <<  L   << s.length() - 1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   string second, pre, suf;   int main() {     ios::sync_with_stdio(false);     cin >> second;     int n = (int)second.size();     int l = 0;     int r = n - 1;     while (l + 1 < r - 1) {       if (second[l] == second[r]) {         pre += second[l];         suf += second[r];       } else {         if (second[l] == second[r - 1])           pre += second[l], suf += second[r - 1];         else if (second[l + 1] == second[r])           pre += second[l + 1], suf += second[r];         else           pre += second[l + 1], suf += second[r - 1];       }       l += 2;       r -= 2;     }     if (n % 4 != 0) {       pre += second[n / 2];     }     reverse(suf.begin(), suf.end());     pre = pre + suf;     cout << pre;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 1e6 + 42;   int k;   int f[6];   long long dp[MX];   long long eval(int val) {     long long ret = 0;     for (int dig = 0; dig < 6; dig++) {       int d = val % 10;       if (d % 3 == 0) ret = ret + 1LL * d / 3 * f[dig];       val = val / 10;     }     return ret;   }   void push(long long object, long long gain) {     if (object >= MX) return;     for (int i = MX - 1; i >= object; i--)       dp[i] = max(dp[i], dp[i - object] + gain);   }   void prec() {     for (int i = 0; i < MX; i++) dp[i] = -1e18;     dp[0] = 0;     for (int dig = 0; dig < 6; dig++) {       int mult = 1;       for (int t = 0; t < dig; t++) mult = mult * 10;       mult = mult * 3;       long long remain = 3 * (k - 1), object = mult, gain = f[dig];       while (remain) {         if (remain % 2 == 0) {           push(object, gain);           remain--;         }         if (remain % 2 == 1) {           push(object, gain);           remain--;         }         object = object * 2;         gain = gain * 2;         remain = remain / 2;       }     }   }   long long solve(int cur) {     long long ret = 0;     for (int i = 0; i <= cur; i++) ret = max(ret, dp[i] + eval(cur - i));     return ret;   }   int main() {     scanf( %i , &k);     for (int i = 0; i < 6; i++) scanf( %i , &f[i]);     prec();     int q;     scanf( %i , &q);     for (int i = 1; i <= q; i++) {       int val;       scanf( %i , &val);       printf( %lld n , solve(val));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int logx = 30;   const long long int N = 1e6 + 5;   const long long int INF = 1e18 + 5;   const long long int mod = 321555123;   const double PI = 3.14159265358979323846;   inline long long int mul(long long int a, long long int b) {     return (a * 1ll * b) % mod;   }   inline long long int sub(long long int a, long long int b) {     long long int c = a - b;     if (c < 0) c += mod;     return c;   }   inline long long int add(long long int a, long long int b) {     long long int c = a + b;     if (c > mod) c -= mod;     return c;   }   template <typename T>   T power(T x, T y, long long int m) {     T ans = 1;     while (y > 0) {       if (y & 1LL) ans = (ans * x) % m;       y >>= 1ll;       x = (x * x) % m;     }     return ans % m;   }   vector<long long int> bit[N];   long long int n, q, a[N], b[N];   void Update(long long int idx, long long int val) {     idx++;     while (idx <= n) {       bit[idx].push_back(val);       idx += (idx & -idx);     }   }   long long int Query(long long int idx, long long int val) {     long long int sum = 0;     idx++;     while (idx > 0) {       long long int lb =           lower_bound(bit[idx].begin(), bit[idx].end(), val) - bit[idx].begin();       sum += lb;       idx -= (idx & -idx);     }     return sum;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ;     cin >> n;     long long int sum = 0;     map<long long int, long long int> first;     for (long long int i = 0; i < n; i++) {       cin >> a[i];     }     for (long long int i = n - 1; i >= 0; i--) {       first[a[i]]++;       b[i] = first[a[i]];     }     for (long long int i = 0; i < n; i++) {       Update(i, b[i]);     }     for (long long int i = 1; i <= n + 1; i++) {       sort(bit[i].begin(), bit[i].end());     }     first.clear();     for (long long int i = 0; i < n; i++) {       long long int l = i + 1;       long long int r = n - 1;       first[a[i]]++;       sum += Query(r, first[a[i]]) - Query(l - 1, first[a[i]]);     }     cout << sum << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 50100;   int n, l[MAXN], p[MAXN], idx[MAXN];   double ev[MAXN], el[MAXN];   int idxCMP(int i, int j) {     return p[i] * l[i] * (100 - p[j]) > p[j] * l[j] * (100 - p[i]);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     for (int i = 0; i < n; i++) {       cin >> l[i] >> p[i];       idx[i] = i;     }     sort(idx, idx + n, idxCMP);     for (int i = 1; i <= n; i++) {       ev[i] =           ev[i - 1] + (el[i - 1] * (100 - p[idx[i - 1]]) / 100.0) + l[idx[i - 1]];       el[i] = el[i - 1] + l[idx[i - 1]] * p[idx[i - 1]] / 100.0;     }     cout << fixed << setprecision(10) << ev[n] << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct Node {     int id, k;   };   const int N = 2e5 + 10;   int a[N];   int C[N];   Node b[N];   int n;   int lowbit(int x) { return (x & -x); }   int sum(int x) {     int ret = 0;     while (x > 0) {       ret += C[x];       x -= lowbit(x);     }     return ret;   }   void add(int x, int d) {     while (x <= n) {       C[x] += d;       x += lowbit(x);     }   }   bool cmp(const Node& x, const Node& y) {     if (x.k == y.k) return x.id < y.id;     return x.k < y.k;   }   int main() {     long long tot;     int p;     scanf( %d , &n);     memset(C, 0, sizeof(C));     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     if (n == 1) {       printf( 0 n );       return 0;     }     for (int i = 2; i <= n; i++) {       b[i].k = min(a[i], i - 1);       b[i].id = i;     }     sort(b + 2, b + n + 1, cmp);     p = 2;     tot = 0;     for (int i = 1; i <= n; i++) {       if (a[i] > i) {         add(i + 1, 1);         add(min(a[i], n) + 1, -1);       }       while (p <= n && b[p].k == i) {         tot += sum(b[p].id);         p++;       }       if (p > n) break;     }     printf( %I64d n , tot);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   pair<long long int, long long int> p[300002];   int see(long long int a, long long int b, long long int c) {     for (long long int i = 0; i < c; i++) {       if (p[i].first == a || p[i].first == b || p[i].second == a ||           p[i].second == b)         continue;       if (b == -1)         return see(a, p[i].first, c) || see(a, p[i].second, c);       else         return 0;     }     return 1;   }   int main() {     long long int n, m, i;     cin >> n >> m;     for (i = 0; i < m; i++) cin >> p[i].first >> p[i].second;     if (see(p[0].first, -1, m) || see(p[0].second, -1, m))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   int num = 0;   int main() {     cin >> n;     int pre[n + 1];     pre[0] = 0;     vector<int> all;     for (int i = 0; i < n; i++) {       int a;       cin >> a;       pre[i + 1] = pre[i] + a;     }     for (int i = 1; i <= n; i++) {       for (int k = 0; k < i; k++) {         all.push_back(pre[i] - pre[k]);       }     }     vector<pair<int, int>> op;     for (auto i : all) {       int cnt = 0;       vector<pair<int, int>> top;       for (int k = 0; k < n;) {         map<int, int> m;         m.insert(make_pair(pre[k], k));         bool findone = false;         while (!findone && k < n) {           int t = pre[k + 1] - i;           if (m.count(t)) {             findone = true;             cnt++;             top.push_back(make_pair(k + 1, m[t] + 1));           }           m.insert(make_pair(pre[k + 1], k + 1));           k++;         }       }       if (cnt > num) {         num = cnt;         op = top;       }     }     cout << num << endl;     for (auto v : op) cout << v.second <<     << v.first << endl;   }
#include <bits/stdc++.h>   int N, XL, XR, YL, YR, SX, SY, VX, VY;   long long LN, LD = 1, RN = 1000000000000LL, RD = 1;   inline bool cmp(long long a, long long b, long long c, long long d) {     return a * d < b * c;   }   void LIM(int v, int s, int l, int r) {     if (v == 0) {       if (s <= l || s >= r) {         puts( -1 );         exit(0);       }     } else {       l -= s;       r -= s;       if (v < 0) {         int tmp = l;         l = r;         r = tmp;         l = -l;         r = -r;         v = -v;       }       if (cmp(LN, LD, l, v)) {         LN = l;         LD = v;       }       if (cmp(r, v, RN, RD)) {         RN = r;         RD = v;       }     }   }   int main() {     for (scanf( %d%d%d%d%d , &N, &XL, &YL, &XR, &YR); N--;) {       scanf( %d%d%d%d , &SX, &SY, &VX, &VY);       LIM(VX, SX, XL, XR);       LIM(VY, SY, YL, YR);     }     if (cmp(LN, LD, RN, RD))       printf( %.12f n , (double)LN / LD);     else       puts( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long f[200200], sum[200200];   long long n;   void init() {     f[0] = 1LL;     for (int i = 1; i <= n; i++) f[i] = f[i - 1] * 10LL % 998244353;     return;   }   void solve() {     for (long long i = 1; i <= n; i++) {       long long ans = 0;       if (i == n)         ans = 10;       else if (i == n - 1)         ans = 180;       else {         ans += (10LL * 9LL * 9LL * (n - i - 1) * f[n - i - 2]) % 998244353;         ans += (10LL * 9LL * 2LL * f[n - i - 1]) % 998244353;         ans %= 998244353;       }       printf( %lld  , ans);       if (i != n) printf(   );     }     return;   }   int main() {     scanf( %lld , &n);     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, k;       cin >> n >> k;       long long int a[n * k], c = 0;       for (long long int i = 0; i < n * k; i++) {         cin >> a[i];       }       long long int m = (ceil)((double)n / 2);       for (long long int i = (m - 1) * k; i < n * k; i += n - m + 1) {         c += a[i];       }       cout << c << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x, i;     cin >> n;     x = n / 2;     cout << x << endl;     for (i = 1; i < x; i++) {       cout <<  2  ;     }     if (n % 2 == 0)       cout <<  2 n ;     else       cout <<  3 n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   namespace IO {   inline bool read() { return true; }   template <class T1, class... T2>   bool read(T1 &a, T2 &...rest) {     return (cin >> a) ? read(rest...) : 0;   }   template <class... T>   bool read(char *a, T &...rest) {     return (cin >> a) ? read(rest...) : 0;   }   template <class... T>   bool read(char *a, char *b, T &...rest) {     return (cin >> a >> b) ? read(rest...) : 0;   }   template <class... T>   bool read(char *a, char *b, char *c, T &...rest) {     return (cin >> a >> b >> c) ? read(rest...) : 0;   }   void put() { cout <<   n ; }   template <class T1, class... T2>   void put(const T1 num, const T2... rest) {     cout << num <<    ;     put(rest...);   }   void yes() { put( YES ); }   void no() { put( NO ); }   void ff() { cout.flush(); }   }  // namespace IO   using namespace IO;   using db = double;   using vi = vector<int>;   using pii = pair<int, int>;   using ll = long long;   using cp = complex<double>;   const int mod = 998244353, inv2 = (mod + 1) / 2;   const int maxn = 1e3 + 10;   const int inf = 1e9 + 3;   short d[41][maxn][maxn];   ll n, m, k;   void prepare() {}   short a[maxn][maxn];   queue<pair<short, short> > q[41];   vector<pair<short, short> > c[41];   short fff = 2e4;   short dx[4] = {1, -1, 0, 0};   short dy[4] = {0, 0, 1, -1};   void bfs(int k, short (&d)[maxn][maxn], queue<pair<short, short> > &q) {     vi vis(44);     vis[k] = 1;     while (!q.empty()) {       auto x = q.front().first, y = q.front().second;       q.pop();       if (!vis[a[x][y]])         for (auto g : c[a[x][y]]) {           auto x1 = g.first, y1 = g.second;           if (d[x1][y1] == fff) {             d[x1][y1] = d[x][y] + 1;             q.push(make_pair(x1, y1));           }         }       vis[a[x][y]] = 1;       for (int i = 0; i < 4; i++) {         auto xx = x + dx[i], yy = y + dy[i];         if (d[xx][yy] != fff) continue;         d[xx][yy] = d[x][y] + 1;         q.push(make_pair(xx, yy));       }     }   }   void Solve(int cas = 1) {     read(n, m, k);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         for (int q = 1; q <= k; q++) {           d[q][i][j] = fff;         }         read(a[i][j]);         c[a[i][j]].emplace_back(i, j);         d[a[i][j]][i][j] = 0;         q[a[i][j]].push(make_pair(i, j));       }     }     for (int i = 1; i <= k; i++) {       bfs(1, d[i], q[i]);     }     int q;     read(q);     while (q--) {       short r1, c1, r2, c2;       read(r1, c1, r2, c2);       int min1 = abs(r1 - r2) + abs(c1 - c2);       for (int i = 1; i <= k; i++) {         min1 = min(min1, d[i][r1][c1] + 1 + d[i][r2][c2]);       }       put(min1);     }   }   void Solvem() {     int T;     read(T);     for (int i = 1; i <= T; i++) Solve(i);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     prepare();     Solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long l1, l2, r1, r2, q;   long long p1, p2;   int main() {     scanf( %lld , &q);     for (int i = 1; i <= q; i++) {       scanf( %lld%lld%lld%lld , &l1, &r1, &l2, &r2);       p1 = l1;       p2 = l2;       if (p1 == p2) p2 = r2;       printf( %lld %lld n , p1, p2);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) { return (!y ? x : gcd(y, x % y)); }   long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }   void file() {}   void fast() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     file();   }   int dx[] = {-1, 0, 1, 0};   int dy[] = {0, 1, 0, -1};   const double eps = 1e-9;   const int mod = 1e9 + 7;   const int N = 1e5 + 5;   int n;   string s;   int dp[N][10][2];   int upd(int x) {     int sum = 0;     while (x) sum += x % 10, x /= 10;     return sum;   }   int solve(int idx, int sum, bool ok) {     if (idx == n) {       if (sum % 3 == 0) return 0;       return 1e9;     }     int &ret = dp[idx][sum][ok];     if (~ret) return ret;     ret = solve(idx + 1, sum, ok) + 1;     if (ok || s[idx] !=  0 )       ret = min(ret, solve(idx + 1, upd(sum + s[idx] - 48), 1));     return ret;   }   void solve2(int idx, int sum, bool ok) {     if (idx == n) {       return;     }     int &ret = dp[idx][sum][ok];     if (ret == solve(idx + 1, sum, ok) + 1) {       solve2(idx + 1, sum, ok);       return;     }     cout << s[idx];     solve2(idx + 1, upd(sum + s[idx] - 48), 1);     return;   }   int main() {     fast();     memset((dp), -1, sizeof(dp));     cin >> s;     n = (int)s.size();     bool ok = 0;     for (int i = 0; i < (int)s.size(); i++) {       ok |= s[i] ==  0 ;     }     int x = solve(0, 0, 0);     if (x == n) {       if (!ok)         cout << -1;       else         cout << 0;       return 0;     }     solve2(0, 0, 0);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double x[111111];   double sX, sY;   int n, K;   double Solve(int l, int r) {     if (l > r) return 0;     return min(hypot(x[l] - sX, sY), hypot(x[r] - sX, sY)) + x[r] - x[l];   }   int main() {     scanf( %d%d , &n, &K);     K--;     for (int i = 0; i < n; ++i) scanf( %lf , x + i);     scanf( %lf%lf , &sX, &sY);     double ans = 1e100;     if (K == n) {       sort(x, x + n);       ans = Solve(0, n - 1);       return printf( %.9f n , ans), 0;     }     K = x[K];     sort(x, x + n);     K = lower_bound(x, x + n, K) - x;     for (int l = 0; l <= K; l++) {       double a = x[K] - x[l], b = x[n - 1] - x[K], t;       ans = min(ans, 2 * b + a + hypot(x[l] - sX, sY) + Solve(0, l - 1));       ans = min(ans, 2 * a + b + hypot(x[n - 1] - sX, sY) + Solve(0, l - 1));     }     for (int r = K; r < n; r++) {       double a = x[K] - x[0], b = x[r] - x[K], t;       ans = min(ans, 2 * b + a + hypot(x[0] - sX, sY) + Solve(r + 1, n - 1));       ans = min(ans, 2 * a + b + hypot(x[r] - sX, sY) + Solve(r + 1, n - 1));     }     printf( %.9f n , ans);     return 0;   }
#include <bits/stdc++.h>   const int mod = 998244353;   using namespace std;   int a[200010], b[200010];   void solve() {     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     int x;     for (int i = 1; i <= n; i++) cin >> x, b[i] = a[i] - x;     sort(b + 1, b + n + 1);     long long ans = 0;     for (int i = 1; i <= n - 1; i++) {       if (b[i] > 0)         ans += n - i;       else {         int j = upper_bound(b + 1, b + n + 1, -b[i]) - b;         ans += max(0, n - j + 1);       }     }     cout << ans <<   n ;   }   int main() {     ios::sync_with_stdio(false), cin.tie(nullptr);     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void swapll(long long *a, long long *b) {     long long tmp = *a;     *a = *b;     *b = tmp;   }   void swapc(char *a, char *b) {     char tmp = *a;     *a = *b;     *b = tmp;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, t;     cin >> n;     cin >> t;     vector<long long> v(n, 0);     for (long long i = 0; i < n; i++) cin >> v[i];     ;     long long count = 0;     for (long long i = 0; i < n; i++) {       t -= (86400 - v[i]);       count++;       if (t <= 0) {         break;       }     }     cout << count << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x = 0, y;     int a[100];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     for (int i = 0; i < n; i++) {       x = max(x, a[i]);     }     y = a[n - 1];     printf( %d , y ^ x);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 250;   int t, a[N];   void read_input() {     for (int i = 0; i < N; i++) cin >> a[i];   }   void solve() {     int sum = 0;     for (int i = 0; i < N; i++) sum += a[i] * a[i];     double P = sqrt(1. * sum / N);     for (int i = 0; i < N; i++)       if (abs(a[i]) > 2 * P) {         cout <<  poisson n ;         return;       }     cout <<  uniform n ;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     for (cin >> t; t--; read_input(), solve())       ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long t;     cin >> t;     while (t--) {       long long n, m;       cin >> n >> m;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           if (j == 1 || i == 1)             cout <<  B ;           else {             cout <<  W ;           }         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   long long s[101000], d[101000], ad[101000];   int find(int l, int r, long long v) {     int re = 0;     while (l <= r) {       int mid = (l + r) / 2;       if (d[mid] <= v) {         re = max(re, mid);         l = mid + 1;       } else {         r = mid - 1;       }     }     return re;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &s[i]);     sort(s + 1, s + n + 1);     for (int i = 1; i < n; i++) {       d[i] = s[i + 1] - s[i];     }     d[0] = 0;     d[n] = 1000000000000000010LL;     sort(d + 1, d + n + 1);     for (int i = 1; i <= n; i++) ad[i] = ad[i - 1] + d[i];     scanf( %d , &q);     for (int i = 1; i <= q; i++) {       long long l, r;       scanf( %I64d%I64d , &l, &r);       long long len = r - l;       int k = find(0, n, len);       printf( %I64d  , (len + 1) * (n - k) + ad[k]);     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1E6 + 10;   int n, a[maxn][20], b[maxn][20], c[maxn], LOG[maxn];   bool Judge(int l, int r) {     int len = LOG[r - l + 1];     int A = 100 * max(a[l][len], a[r - (1 << len) + 1][len]);     int B = min(b[l][len], b[r - (1 << len) + 1][len]);     return A < B;   }   int main() {     int k;     cin >> n >> k;     for (int i = 1; i <= n; i++) scanf( %d , &a[i][0]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i][0]);     for (int j = 1; j < 20; j++)       for (int i = 1; i <= n; i++) {         if (i + (1 << j - 1) > n) break;         a[i][j] = max(a[i][j - 1], a[i + (1 << (j - 1))][j - 1]);         b[i][j] = min(b[i][j - 1], b[i + (1 << (j - 1))][j - 1]);       }     int now = 0, sum = 1;     for (int i = 1; i <= n; i++) {       if (sum >= i)         LOG[i] = now - 1;       else {         sum <<= 1;         ++now;         LOG[i] = now - 1;       }     }     LOG[1] = 0;     for (int i = 1; i <= n; i++) {       int L, R;       L = i;       R = n;       while (R - L > 1) {         int mid = (L + R) >> 1;         if (Judge(i, mid))           L = mid;         else           R = mid;       }       int len = LOG[L - i + 1];       int A = 100 * max(a[i][len], a[L - (1 << len) + 1][len]);       int B = min(b[i][len], b[L - (1 << len) + 1][len]);       c[i] = min(A, B);       len = LOG[R - i + 1];       A = 100 * max(a[i][len], a[R - (1 << len) + 1][len]);       B = min(b[i][len], b[R - (1 << len) + 1][len]);       c[i] = max(c[i], min(A, B));     }     sort(c + 1, c + n + 1);     double ans = 0;     double N = n - 1;     double M = k - 1;     double v = (double)(k) / (double)(n);     for (int i = 1; i <= n; i++) {       if (n - i < k - 1) break;       ans += v * (double)(c[i]);       v = v / N * (N - M);       N -= 1.00;     }     printf( %.10f , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool found;   int n, x, nums[1000], smaller, larger, eq;   void Naive() {     int median = ((n + 1) / 2);     sort(nums, nums + n);     if (nums[--median] == x) {       printf( 0 );       return;     }     if (found) {       for (int i = 0; i < n && nums[i] <= x; i++)         if (x == nums[i] && abs(smaller - median) > abs(i - median)) smaller = i;     }     larger = n - smaller - found;   }   void Smart() {     larger = n - smaller - eq;     if (found) {       eq--;       int diff = abs(smaller - larger);       if (larger <= smaller) {         if (diff <= eq) {           larger = smaller;           eq -= diff;           larger += eq / 2 + (eq % 2);           smaller += eq / 2;         } else {           larger += eq;           eq = 0;         }       } else {         if (diff <= eq) {           smaller = larger;           eq -= diff;           larger += eq / 2 + (eq % 2);           smaller += eq / 2;         } else {           smaller += eq;           eq = 0;         }       }     }   }   void Greedy() {     Smart();     printf( %d , !found + abs(smaller - larger) - (larger > smaller));   }   int main() {     found = false;     scanf( %d %d , &n, &x);     for (int i = 0; i < n; i++) {       scanf( %d , &nums[i]);       smaller += (nums[i] < x);       eq += (nums[i] == x);       found |= (nums[i] == x);     }     Greedy();   }