malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long int power(long long int x, long long int n, long long int p) {     long long int result = 1;     while (n > 0) {       if (n % 2 == 1) result = (result % p * x % p) % p;       x = (x % p * x % p) % p;       n = n / 2;     }     return result % p;   }   void solve() {     long long int n, m;     cin >> n >> m;     vector<long long int> cnt(1005);     for (long long int i = 0; i <= n - 1; i++) {       long long int a1;       cin >> a1;       cnt[a1] = 1;     }     for (long long int i = 0; i <= m - 1; i++) {       long long int a2;       cin >> a2;       if (cnt[a2] == 1) cnt[a2]++;     }     for (long long int i = 1; i <= 1000; i++) {       if (cnt[i] >= 2) {         cout <<  YES  << endl;         cout <<  1   << i << endl;         return;       }     }     cout <<  NO  << endl;     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long int t = 1;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int i, a[26], ans = 0, tot = 0;     string s;     map<pair<long long int, long long int>, long long int> mp;     for (i = 0; i < 26; i++) cin >> a[i];     cin >> s;     for (i = 0; i < s.length(); i++) {       ans += mp[{s[i] -  a , tot}];       tot += a[s[i] -  a ];       mp[{s[i] -  a , tot}]++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   using namespace std;   int main() {     cin.tie(NULL), ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       int a, b;       cin >> a >> b;       if (a > b) {         if ((b - a) % 2 == 0)           cout << 1 <<   n ;         else           cout << 2 <<   n ;       } else if (a == b)         cout << 0 <<   n ;       else {         if ((b - a) % 2 != 0)           cout << 1 <<   n ;         else           cout << 2 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   double pi = 3.14159265359;   using namespace std;   int main() {     ios::sync_with_stdio(false);     string a, b;     cin >> a >> b;     string c(a.size(),  0 );     int count = 0;     for (unsigned int i = 0; i < a.size(); i++)       if (a[i] == b[i]) c[i] = a[i], count++;     if ((a.size() - count) % 2)       cout <<  impossible ;     else {       bool ok = 0;       for (unsigned int i = 0; i < a.size(); i++)         if (a[i] != b[i] && !ok)           c[i] = a[i], ok = 1;         else if ((a[i] != b[i] && ok))           c[i] = b[i], ok = 0;       cout << c <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mul[100010], inv[100010];   const int mod = 998244353;   const int maxn = 5050;   void init() {     mul[0] = 1;     for (int i = 1; i < maxn; i++) mul[i] = (mul[i - 1] * i) % mod;     inv[0] = inv[1] = 1;     for (int i = 2; i < maxn; i++)       inv[i] = (long long)(mod - mod / i) * inv[mod % i] % mod;     for (int i = 1; i < maxn; i++) inv[i] = (inv[i - 1] * inv[i]) % mod;   }   long long C(int n, int m) { return mul[n] * inv[m] % mod * inv[n - m] % mod; }   long long f(long long a, long long b) {     long long ans = 0;     for (int i = 0; i <= min(a, b); i++)       ans = (ans + C(a, i) * C(b, i) % mod * mul[i] % mod) % mod;     return ans;   }   int main() {     int a, b, c;     init();     cin >> a >> b >> c;     cout << f(a, b) * f(a, c) % mod * f(b, c) % mod << endl;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = 2.0 * acos(0.0);   const double eps = 1.0e-9;   const int dr[] = {-1, 0, 1, 0}, dc[] = {0, 1, 0, -1};   const int dr6[] = {1, 1, 0, -1, -1, 0}, dc6[] = {0, 1, 1, 0, -1, -1};   const int dr8[] = {-1, -1, 0, 1, 1, 1, 0, -1},             dc8[] = {0, 1, 1, 1, 0, -1, -1, -1};   int main(void) {     int kase = 1000000000;     for (int ks = 1, n; ks <= kase && cin >> n; ++ks) {       int c[32] = {0};       for (int i = 0, x; i < n && cin >> x; ++i) ++c[x + 16];       long long s = (long long)c[16] * (c[16] - 1) / 2;       for (int i = 1; i <= 10; ++i) s += (long long)c[16 - i] * c[16 + i];       cout << s << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) {     if (b == 0)       return a;     else       return gcd(b, a % b);   }   int rev(int n) {     int ret = 0;     while (n != 0) {       ret = (10 * ret) + (n % 10);       n /= 10;     }     return ret;   }   int main() {     int mx, my, w;     int i, j, k, t;     int ax, ay;     vector<int> v;     map<pair<int, int>, vector<int> > mp;     scanf( %d%d%d , &mx, &my, &w);     for (i = 1; i <= my; i++) {       j = rev(i);       k = gcd(i, j);       mp[make_pair(i / k, j / k)].push_back(i);     }     vector<int> vec(my + 1, 0);     vector<vector<int> > vv;     vv.push_back(v);     for (i = 1; i <= mx; i++) {       j = rev(i);       k = gcd(i, j);       v = mp[make_pair(j / k, i / k)];       for (j = 0; j < v.size(); j++) vec[v[j]]++;       vv.push_back(v);     }     long long ans = -1;     for (i = mx, j = 0, k = 0; i > 0; i--) {       if (k < w && j < my) {         do {           j++;           k += vec[j];         } while (k < w && j < my);       }       if (k >= w && (ans == -1 || ans > (long long)i * j)) {         ans = (long long)i * j;         ax = i;         ay = j;       }       for (t = 0; t < vv[i].size(); t++) {         if (vv[i][t] <= j) k--;         vec[vv[i][t]]--;       }     }     if (ans == -1)       printf( -1 n );     else       printf( %d %d n , ax, ay);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 10;   int n, a[N], b[N], c[N], p[N];   vector<int> v;   int main() {     cin >> n;     for (int i = 1; i < N; i++) p[i] = i;     for (int i = 1; i <= n; i++) {       cin >> a[i] >> b[i];       if (a[i] == 2) cin >> c[i];     }     for (int i = n; i >= 1; i--) {       if (a[i] == 1)         v.push_back(p[b[i]]);       else if (a[i] == 2)         p[b[i]] = p[c[i]];     }     for (int i = v.size() - 1; i >= 0; i--) printf( %d  , v[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   queue<int> qQuit;   int ind[100000], n;   bool entered[100000];   priority_queue<pair<int, int>, vector<pair<int, int> >,                  greater<pair<int, int> > >       qLeft, qRight;   int data[100000];   int main(void) {     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int temp;       scanf( %d , &temp);       ind[temp - 1] = i;     }     for (int i = 0; i < n; i++) {       scanf( %d , data + i);       data[i]--;     }     for (int i = 0; i < n; i++) {       qQuit.push(data[i]);       if (i >= ind[data[i]])         qRight.push(make_pair(i - ind[data[i]], data[i]));       else {         qLeft.push(make_pair(ind[data[i]] - i, data[i]));         entered[data[i]] = true;       }     }     for (int i = 0; i < n; i++) {       int minVal = 99999999;       int minFrom;       if (qRight.size()) {         if (minVal > qRight.top().first - i) minFrom = qRight.top().second;         minVal = min(minVal, qRight.top().first - i);       }       while (qLeft.size() && entered[qLeft.top().second] == false) qLeft.pop();       if (qLeft.size()) {         if (minVal > qLeft.top().first + i) minFrom = qLeft.top().second;         minVal = min(minVal, qLeft.top().first + i);       }       printf( %d n , minVal);       while (qRight.size() && qRight.top().first - i == 0) {         pair<int, int> val = qRight.top();         qRight.pop();         qLeft.push(make_pair(-i, val.second));         entered[val.second] = true;       }       int toQuit = qQuit.front();       qQuit.pop();       entered[toQuit] = false;       qRight.push(make_pair(n - 1 - ind[toQuit] + (i + 1), toQuit));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dque[500005];   int s = 0, t = 0, num = 0, q, maxi;   double mean = 0;   int main() {     memset(dque, 0, sizeof(dque));     scanf( %d , &q);     while (q--) {       int type, x;       scanf( %d , &type);       if (type == 1) {         scanf( %d , &x);         if (num != 0) {           mean = (mean * num + x - maxi) / num;           dque[t++] = maxi;         } else {           mean = x;           num++;         }         maxi = x;         while (s < t && dque[s] < mean) {           mean = (mean * num + dque[s]) / (num + 1);           num++;           s++;         }       } else         printf( %.10f n , (double)maxi - mean);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dp[605][305][305];   int a[305][305];   int max(int a, int b) { return a > b ? a : b; }   int main() {     int n;     while (scanf( %d , &n) != EOF) {       int i, j, k;       for (i = 0; i < n; i++) {         for (j = 0; j < n; j++) {           scanf( %d , &a[i][j]);         }       }       for (i = 0; i <= 2 * n; i++) {         for (j = 0; j < n; j++) {           for (k = 0; k < n; k++) {             dp[i][j][k] = -1000000000;           }         }       }       dp[0][0][0] = a[0][0];       for (i = 1; i <= 2 * (n - 1); i++) {         for (j = 0; j < n && j <= i; j++) {           if (i - j >= n) continue;           for (k = 0; k < n && k <= i; k++) {             if (i - k >= n) continue;             int y1, y2, s;             if (j == k && i - j == i - k)               s = a[j][i - j];             else               s = a[j][i - j] + a[k][i - k];             if (j - 1 >= 0)               dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k] + s);             if (j - 1 >= 0 && k - 1 >= 0)               dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - 1][k - 1] + s);             if (k - 1 >= 0)               dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k - 1] + s);             dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j][k] + s);           }         }       }       printf( %d n , dp[2 * (n - 1)][n - 1][n - 1]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     deque<int> vec(300000);     int l = 0, r = 0;     for (int i = 0; i < n; i++) {       string s;       int id;       cin >> s >> id;       if (!i) {         vec[id] = l;         l--, r++;       } else {         if (s ==  L ) {           vec[id] = l;           l--;         }         if (s ==  R ) {           vec[id] = r;           r++;         }         if (s ==  ? ) {           cout << min(abs(vec[id] - l), abs(vec[id] - r)) - 1 << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> adj[1002];   map<long long, long long> vis;   map<pair<long long, long long>, long long> dia;   long long st[1002], en[1002];   void dfs(long long tar, long long cur, bool &found, long long mini,            long long &mini2) {     vis[cur] = 1;     if (tar == cur) {       found = true;       mini2 = min(mini, mini2);       return;     }     for (long long i = 0; i < adj[cur].size(); i++) {       if (vis[adj[cur][i]] == 0) {         dfs(tar, adj[cur][i], found, min(mini, dia[{cur, adj[cur][i]}]), mini2);       }     }   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long t, n, num, m, k;     cin >> n >> k;     for (long long i = 0; i < k; i++) {       long long a, b, d;       cin >> a >> b >> d;       adj[a].push_back(b);       adj[b].push_back(a);       st[a]++;       en[b]++;       dia[{a, b}] = d;       dia[{b, a}] = d;     }     vector<long long> v1, v2;     for (long long i = 1; i <= n; i++) {       if (en[i] == 0 && st[i] == 1) {         v1.push_back(i);       }       if (st[i] == 0 && en[i] == 1) {         v2.push_back(i);       }     }     cout << v1.size() <<   n ;     for (long long i = 0; i < v1.size(); i++) {       for (long long j = 0; j < v2.size(); j++) {         bool found = false;         long long mini2 = LLONG_MAX;         dfs(v2[j], v1[i], found, LLONG_MAX, mini2);         vis.clear();         if (found) {           cout << v1[i] <<     << v2[j] <<     << mini2 <<   n ;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char mp[1001][1001];   int visit[1001][1001];   int dist[1001][1001];   int N, M;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, 1, -1};   bool chk(int x, int y) { return 0 <= x && x < N && 0 <= y && y < M; }   void dfs(int x, int y, bool isfirst) {     visit[x][y] = 1;     if (!isfirst) dist[x][y] = 1;     for (int i = 0; i < 4; i++) {       int nx = x + dx[i];       int ny = y + dy[i];       if (chk(nx, ny) && mp[x][y] == mp[nx][ny] && visit[nx][ny] == 0) {         dist[x][y] = 1;         dfs(nx, ny, false);       }     }   }   int main(int argc, char *argv[]) {     int Q;     scanf( %d %d %d , &N, &M, &Q);     for (int i = 0; i < N; i++) scanf( %s , mp[i]);     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (visit[i][j] == 0) dfs(i, j, true);       }     }     queue<pair<int, int> > q;     for (int i = 0; i < N; i++) {       for (int j = 0; j < M; j++) {         if (dist[i][j] == 1) q.push({i, j});       }     }     while (!q.empty()) {       auto [x, y] = q.front();       q.pop();       for (int i = 0; i < 4; i++) {         int nx = x + dx[i], ny = y + dy[i];         if (chk(nx, ny) && dist[nx][ny] == 0) {           dist[nx][ny] = dist[x][y] + 1;           q.push({nx, ny});         }       }     }     while (Q--) {       long long x, y, t;       scanf( %lld %lld %lld , &x, &y, &t);       printf( %lld n , dist[x - 1][y - 1]                            ? ((mp[x - 1][y - 1] -  0 ) +                               max(t - (dist[x - 1][y - 1] - 1), 0LL)) %                                  2                            : mp[x - 1][y - 1] -  0 );     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-15;   const double pi = acos(-1.0);   const long long Mod = 1000000007;   const int N = 1e3 + 5;   int ks = 0;   int n, m, s, t;   long long dis[N], cost[N * 10], L;   int used[N], deleted[N * 10];   pair<int, int> parent[N];   vector<pair<int, int> > g[N];   struct edge {     int x, y;     long long z;     bool operator<(const edge &f) const { return z > f.z; }   } E[N * 10];   void SPFA() {     for (int i = 0; i < n; i++) {       dis[i] = LLONG_MAX;       used[i] = 0;     }     priority_queue<pair<long long, int>, vector<pair<long long, int> >,                    greater<pair<long long, int> > >         q;     q.emplace(0, s);     dis[s] = 0;     while (q.size()) {       int from = q.top().second;       used[from] = 1;       q.pop();       for (auto i : g[from]) {         int to = i.first;         int id = i.second;         if (dis[from] + cost[id] < dis[to]) {           dis[to] = dis[from] + cost[id];           parent[to] = {from, id};           if (!used[to]) q.emplace(dis[to], to);         }       }     }   }   int main() {     scanf( %d%d%I64d%d%d , &n, &m, &L, &s, &t);     for (int i = 0; i < m; i++) {       scanf( %d%d%I64d , &E[i].x, &E[i].y, &E[i].z);     }     sort(E, E + m);     int last = 0;     for (int i = 0; i < m && E[i].z; i++, last++) {       cost[i] = E[i].z;       g[E[i].x].emplace_back(E[i].y, i);       g[E[i].y].emplace_back(E[i].x, i);     }     SPFA();     if (dis[t] < L) {       puts( NO );       return 0;     }     for (int i = last; i < m; i++) {       deleted[i] = cost[i] = 1;       g[E[i].x].emplace_back(E[i].y, i);       g[E[i].y].emplace_back(E[i].x, i);     }     SPFA();     if (dis[t] > L) {       puts( NO );       return 0;     }     puts( YES );     while (dis[t] < L) {       int cur = t;       while (cur != s) {         int id = parent[cur].second;         cur = parent[cur].first;         if (deleted[id]) {           cost[id] += L - dis[t];           break;         }       }       SPFA();     }     bool done[N];     memset(done, false, sizeof done);     for (int i = 0; i < n; i++) {       for (auto j : g[i]) {         if (done[j.first]) continue;         cout << i <<     << j.first <<     << cost[j.second] <<   n ;       }       done[i] = true;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int pre = INT_MIN;     int cur;     int state = 0;     for (int i = 0; i < n; i++) {       cin >> cur;       if (cur > pre) {         if (state == 0) {           pre = cur;           continue;         } else {           cout <<  NO  << endl;           return 0;         }       } else if (cur == pre) {         if (state == 1) {           pre = cur;           continue;         }         if (state == 0) {           pre = cur;           state = 1;           continue;         }         cout <<  NO  << endl;         return 0;       } else {         if (state == 2) {           pre = cur;           continue;         }         if (state < 2) {           pre = cur;           state = 2;           continue;         }         cout <<  NO  << endl;         return 0;       }     }     cout <<  YES  << endl;     return 0;   }
#include <bits/stdc++.h>   int main(int argc, const char* argv[]) {     int n;     std::cin >> n;     std::string s;     std::cin >> s;     std::vector<int> v0(n);     for (int i = 0; i < n; i++) v0[i] = s[i] -  0 ;     bool add = true;     std::vector<int> v1(n);     for (int i = 0; i < n; i++) {       if (add)         v1[i] = v0[i] + 1;       else         v1[i] = v0[i];       if (v1[i] == 2) {         add = true;         v1[i] = 0;       } else         add = false;     }     int count = 0;     for (int i = 0; i < n; i++)       if (v0[i] != v1[i]) count++;     std::cout << count << std::endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mod = 1e9 + 7;   struct node {     long long x, l, r;   } a[10005];   long long b[20005];   int is[20005][4], ed[20005][4];   int l = 2;   struct Matrix {     long long v[3][3];     Matrix() { memset(v, 0, sizeof(v)); }     Matrix operator*(const Matrix B) {       Matrix C;       for (int i = 0; i <= l; i++)         for (int j = 0; j <= l; j++)           for (int k = 0; k <= l; k++) {             C.v[i][j] = (C.v[i][j] + v[i][k] * B.v[k][j]) % mod;           }       return C;     }   };   Matrix mtpow(Matrix A, long long k) {     int i;     Matrix B;     for (int i = 0; i <= l; i++) B.v[i][i] = 1;     while (k) {       if (k & 1) B = B * A;       A = A * A;       k >>= 1;     }     return B;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     long long n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) {       cin >> a[i].x >> a[i].l >> a[i].r;       b[++b[0]] = a[i].l;       b[++b[0]] = a[i].r;     }     b[++b[0]] = 1, b[++b[0]] = m;     sort(b + 1, b + b[0] + 1);     b[0] = unique(b + 1, b + b[0] + 1) - b - 1;     for (int i = 1; i <= n; i++) {       a[i].l = lower_bound(b + 1, b + b[0] + 1, a[i].l) - b;       a[i].r = lower_bound(b + 1, b + b[0] + 1, a[i].r) - b;       is[a[i].l][a[i].x]++, is[a[i].r + 1][a[i].x]--;       ed[a[i].r][a[i].x]++;     }     long long x1 = 0, x2 = 1, x3 = 0;     long long x11, x22, x33;     Matrix B;     for (int i = 0; i <= l; i++) {       for (int j = 0; j <= l; j++) {         if ((i == 0 && j == 2) || (i == 2 && j == 0))           B.v[i][j] = 0;         else           B.v[i][j] = 1;       }     }     for (int i = 2; i <= b[0]; i++) {       for (int j = 1; j <= 3; j++) is[i][j] += is[i - 1][j];       long long c = b[i] - b[i - 1] - 1;       Matrix temp = B;       for (int j = 1; j <= 3; j++) {         if (is[i - 1][j] - ed[i - 1][j] >= 1)           for (int k = 0; k <= 2; k++) temp.v[j - 1][k] = 0;       }       temp = mtpow(temp, c);       x11 = (temp.v[0][0] * x1 + temp.v[0][1] * x2 + temp.v[0][2] * x3) % mod;       x22 = (temp.v[1][0] * x1 + temp.v[1][1] * x2 + temp.v[1][2] * x3) % mod;       x33 = (temp.v[2][0] * x1 + temp.v[2][1] * x2 + temp.v[2][2] * x3) % mod;       x1 = (x11 + x22) % mod, x2 = (x11 + x22 + x33) % mod,       x3 = (x33 + x22) % mod;       if (is[i][1]) x1 = 0;       if (is[i][2]) x2 = 0;       if (is[i][3]) x3 = 0;     }     cout << x2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n;     cin >> n;     int x = 1;     while (x <= n) {       if (x == n || x + 1 == n) {         cout << 1 <<   n ;         return 0;       }       if (x & 1) {         x = x * 2 + 2;       } else {         x = x * 2 + 1;       }     }     cout << 0 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 6;   vector<pair<int, int> > G[maxn];   int out, m, d[maxn], ans[maxn][3], leaf[maxn][2];   void add_m(int u, int v, int d) {     ans[++m][0] = u, ans[m][1] = v, ans[m][2] = d;   }   void add_link(int u, int l, int d) {     if (u == out) {       add_m(u, l, d);       return;     }     int a = l, b = leaf[u][0] == l ? leaf[u][1] : leaf[u][0], c = out;     add_m(a, c, d / 2), add_m(a, b, d / 2), add_m(b, c, -d / 2);   }   void dfs(int u, int f, int l) {     if (G[u].size() == 1 && f) {       leaf[u][0] = u;       return;     }     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i].first;       if (v != f) {         dfs(v, u, l);         if (leaf[u][0])           leaf[u][1] = leaf[v][0];         else           leaf[u][0] = leaf[v][0];       }     }     for (int i = 0; i < G[u].size(); ++i) {       int v = G[u][i].first;       if (v != f) {         int d = G[u][i].second;         if (G[v].size() == 1)           add_link(u, v, G[u][i].second);         else {           add_link(u, leaf[v][0], G[u][i].second);           add_link(v, leaf[v][0], -G[u][i].second);         }       }     }   }   int main() {     int n;     cin >> n;     for (int i = 1; i < n; ++i) {       int u, v, c;       cin >> u >> v >> c;       G[u].push_back(make_pair(v, c));       G[v].push_back(make_pair(u, c));       ++d[u], ++d[v];     }     for (int i = 1; i <= n; ++i)       if (d[i] == 2) {         cout <<  NO  << endl;         return 0;       }     for (int i = 1; i <= n; ++i)       if (G[i].size() == 1) {         out = i, dfs(i, 0, i);         break;       }     cout <<  YES  << endl;     cout << m << endl;     for (int i = 1; i <= m; ++i)       cout << ans[i][0] <<     << ans[i][1] <<     << ans[i][2] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char *argv[]) {     int n, k, j, i, a[10001], s[1002], n1, n2, num[1002], h1, h2;     double x, sum1, sum2, l, r, m;     scanf( %d %d , &n, &k);     h1 = 1000;     h2 = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       if (h1 > a[i]) h1 = a[i];       if (h2 < a[i]) h2 = a[i];     }     for (i = 0; i <= h2; i++) {       s[i] = 0;       num[i] = 0;     }     for (i = 0; i < n; i++) {       for (j = a[i]; j <= h2; j++) {         s[j] += a[i];         num[j]++;       }     }     l = h1;     r = h2;     while (r - l >= 1e-9) {       m = (l + r) / 2;       sum1 = ((double)num[(int)m]) * m - (double)s[(int)m];       sum2 =           (double)(s[h2] - s[(int)m]) - (((double)(num[h2] - num[(int)m])) * m);       if (sum2 * (1 - k / 100.0) > sum1) {         l = m;       } else {         r = m;       }     }     cout.precision(6);     cout.setf(ios::fixed, ios::floatfield);     cout << (s[h2] - sum2 * (double)k / 100.0) / (double)n << endl;     return EXIT_SUCCESS;   }