malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void print(T v) {     cout << v <<   n ;   }   template <typename T>   void print(vector<T> a) {     for (int i = 0; i < a.size(); i++) {       cout << a[i] <<    ;     }     cout <<   n ;   }   long long help(long long a, long long b, long long x, long long y,                  long long n) {     long long da = min(n, a - x);     a -= da;     n -= da;     long long db = min(n, b - y);     b -= db;     return a * b;   }   void solve() {     long long a, b, x, y, n;     cin >> a >> b >> x >> y >> n;     print(min(help(a, b, x, y, n), help(b, a, y, x, n)));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   char ch[201][201];   int main() {     cin >> m >> n;     n *= 2;     m *= 2;     for (int i = 1; i <= n; i += 2)       for (int j = 1; j <= m; j += 2) {         cin >> ch[i][j];         ch[i + 1][j] = ch[i][j + 1] = ch[i + 1][j + 1] = ch[i][j];       }     for (int j = 1; j <= m; j++) {       for (int i = 1; i <= n; i++) cout << ch[i][j];       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     string s;     int n;     int arr[26];     int arr2[26];     cin >> s;     int value;     int sum = 0;     int add;     int length = s.size();     cin >> n;     for (int i = 0; i < 26; i++) {       cin >> arr[i];       arr2[i] = arr[i];     }     sort(arr2, arr2 + 26);     int largest = arr2[25];     for (int i = 0; i < length; i++) {       value = s[i];       int x = abs(97 - value);       sum = sum + ((i + 1) * arr[x]);     }     int last = length + n;     int sum1 = 0;     for (int i = length + 1; i <= last; i++) {       sum1 = sum1 + (i * largest);     }     cout << sum1 + sum;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   vector<pair<int, int>> G[262144];   int d1[26][262144];   pair<int, int> d2[2][262144];   int vis[2][262144];   long long mod = 998244353ll;   long long qpow(long long x, long long y) {     long long a = x, ans = 1;     while (y) {       if (y & 1) ans = (ans * a) % mod;       y >>= 1;       a = (a * a) % mod;     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       G[u].push_back(make_pair(v, 0));       G[v].push_back(make_pair(u, 1));     }     queue<pair<int, int>> q;     q.push(make_pair(0, 1));     for (int i = 1; i <= n; i++)       for (int j = 0; j <= 25; j++) d1[j][i] = -1;     d1[0][1] = 0;     while (!q.empty()) {       pair<int, int> top = q.front();       q.pop();       int flips = top.first, u = top.second;       for (auto i : G[u]) {         int v = i.first, f = i.second;         int flip = ((flips & 1) ^ f);         if (flips + flip > 25) continue;         if (d1[flips + flip][v] == -1) {           d1[flips + flip][v] = d1[flips][u] + 1;           q.push(make_pair(flips + flip, v));         }       }     }     int ans = 2100000000;     for (int j = 0; j <= 25; j++)       if (d1[j][n] != -1) {         ans = min(ans, (1 << j) - 1 + d1[j][n]);       }     if (ans < 2100000000) {       cout << ans << endl;       return 0;     }     priority_queue<pair<pair<int, int>, pair<int, int>>> q2;     q2.push(make_pair(make_pair(0, 0), make_pair(0, 1)));     for (int i = 1; i <= n; i++)       for (int j = 0; j <= 1; j++) d2[j][i] = make_pair(2100000000, 2100000000);     d2[0][1] = make_pair(0, 0);     while (!q2.empty()) {       pair<pair<int, int>, pair<int, int>> top = q2.top();       q2.pop();       int flipsbit = top.second.first, u = top.second.second;       if (vis[flipsbit][u]) continue;       vis[flipsbit][u] = 1;       int flips = d2[flipsbit][u].first, dist = d2[flipsbit][u].second;       for (auto i : G[u]) {         int v = i.first, f = i.second;         int flip = (flipsbit ^ f);         int vflipsbit = ((flips + flip) & 1);         pair<int, int> dv = make_pair(flips + flip, dist + 1);         if (d2[vflipsbit][v] > dv) {           d2[vflipsbit][v] = dv;           q2.push(make_pair(make_pair(-dv.first, -dv.second),                             make_pair(vflipsbit, v)));         }       }     }     int flips = d2[0][n].first, dist = d2[0][n].second;     if (d2[1][n].first < d2[0][n].first) {       flips = d2[1][n].first, dist = d2[1][n].second;     }     long long ans2 = (qpow(2, flips) + dist - 1) % mod;     cout << ans2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     scanf( %d %d , &n, &m);     vector<int> att, def, my(m);     for (int i = 0; i < n; i++) {       char a, b, c;       int s;       scanf(  %c%c%c %d , &a, &b, &c, &s);       if (a ==  A )         att.push_back(s);       else         def.push_back(s);     }     for (int i = 0; i < m; i++) {       scanf( %d , &my[i]);     }     sort(att.begin(), att.end());     sort(def.begin(), def.end());     sort(my.begin(), my.end());     int res = 0;     vector<int> used(m, 0);     int pres = 0;     int cm = 0;     for (int i = 0; i < def.size(); i++) {       while (my[cm] <= def[i] || used[cm]) {         cm++;         if (cm >= m) {           pres = -1023456789;           break;         }       }       if (cm < m) {         used[cm] = 1;       } else         break;     }     if (pres > -1023456789) {       cm = 0;       for (int i = 0; i < att.size(); i++) {         while (my[cm] < att[i] || used[cm]) {           cm++;           if (cm >= m) {             pres = -1023456789;             break;           }         }         if (cm < m) {           used[cm] = 1;           pres += my[cm] - att[i];         } else           break;       }     }     if (pres > -1023456789) {       for (int i = 0; i < m; i++)         if (!used[i]) pres += my[i];     }     res = max(res, pres);     for (int i = 1; i <= min(m, (int)(att.size())); i++) {       int suc = 0;       for (int j = 0; j < i; j++) {         if (my[m - i + j] >= att[j]) {           suc += my[m - i + j] - att[j];         } else           suc = -1023456789;       }       res = max(res, suc);     }     printf( %d n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[1010];   long long ans;   long long vis[1010];   map<long long, long long> mp;   void dfs(long long x, long long y, long long cnt) {     ans = max(cnt, ans);     if (mp[x + y]) {       mp[x + y]--;       dfs(y, x + y, cnt + 1);       mp[x + y]++;     }   }   int main() {     while (cin >> n) {       for (int i = 1; i <= n; i++) cin >> a[i];       for (int i = 1; i <= n; i++) mp[a[i]]++;       long long kk = 0;       for (int i = 1; i <= n; i++)         if (a[i] == 0) kk++;       ans = 0;       for (int i = 0; i <= n; i++) vis[i] = 0;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= n; j++) {           if (i != j) {             if (a[i] == 0 && a[j] == 0) {               ans = max(ans, kk);               continue;             }             mp[a[i]]--;             mp[a[j]]--;             dfs(a[i], a[j], 2);             mp[a[i]]++, mp[a[j]]++;           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int t[24], n;   bool ok(int n) {     set<int> u;     int e = 0;     for (int(i) = (0); (i) < (n); (i)++)       for (int(j) = (0); (j) < (i); (j)++) {         e++;         u.insert(abs(t[i] + t[j]));       }     return (e == u.size());   }   int main() {     scanf( %d , &n);     for (int(i) = (0); (i) < (n); (i)++) {       t[i] = i;       while (!ok(i + 1)) t[i]++;     }     for (int(i) = (0); (i) < (n); (i)++) {       for (int(j) = (0); (j) < (n); (j)++)         printf( %d  , i == j ? 0 : abs(t[i] + t[j]));       puts(  );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int sum;     cin >> sum;     int a, b, c = -1;     for (int i = 0; i * 7 <= sum; i++) {       if ((sum - i * 7) % 4 == 0) {         int j = (sum - i * 7) / 4;         if (c == -1 || i + j < c) {           c = i + j;           a = j;           b = i;         }       }     }     if (c == -1)       cout << -1;     else {       for (int i = 0; i < a; i++) cout <<  4 ;       for (int j = 0; j < b; j++) cout <<  7 ;       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m, l, r;   vector<long long> A[200001];   set<pair<int, int> > se;   void add(long long y) {     for (auto b : A[y]) se.insert({b, y});   }   void del(long long y) {     for (auto b : A[y]) se.erase({b, y});   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m >> l >> r;     for (long long i = 1; i <= 200000; ++i)       for (long long j = i; j <= 200000; j += i)         if (j <= 200000) A[j].push_back(i);     long long L = m + 1;     long long R = m;     for (long long x = 1; x <= n; ++x) {       long long L_ = (l + x - 1) / x;       long long R_ = min(m, r / x);       if (L_ > R_) goto L1;       while (L > L_) add(--L);       while (R > R_) del(R--);       for (long long a : A[x]) {         auto it = se.upper_bound({a + 1, 0});         if (it != se.end()) {           long long b = it->first;           long long y = it->second;           if (x * b <= n * a) {             cout << x <<     << y <<     << x * b / a <<     << y * a / b;             goto L2;           }         } else           goto L1;       }     L1:       cout << -1;     L2:       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     static int vv[100][100], tt[100][100], kk[100];     int n, s, h, i, j, k, t, t_, d1, d2, cnt, lead;     scanf( %d%d , &n, &s);     for (i = 0; i < n; i++) {       scanf( %d , &kk[i]);       for (j = 0; j < kk[i]; j++) scanf( %d%d , &vv[i][j], &tt[i][j]);       for (j = 1; j < kk[i]; j++) tt[i][j] += tt[i][j - 1];     }     cnt = 0;     for (h = 0; h < n; h++)       for (i = 0; i < n; i++)         if (h != i)           for (lead = 1, d1 = d2 = 0, j = k = 0, t = 0; j < kk[h] && k < kk[i];) {             if (tt[h][j] < tt[i][k])               t_ = tt[h][j];             else               t_ = tt[i][k];             if (t != t_) {               if ((d1 < d2 || (d1 == d2 && !lead)) &&                   d1 + vv[h][j] * (t_ - t) > d2 + vv[i][k] * (t_ - t))                 cnt++;               d1 += vv[h][j] * (t_ - t);               d2 += vv[i][k] * (t_ - t);               if (d1 != d2) lead = d1 > d2;             }             if (tt[h][j] < tt[i][k])               j++;             else               k++;             t = t_;           }     printf( %d n , cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-8;   long long ii = 1;   vector<long long> prime;   bitset<1000000> bs;   void sieve() {     bs.set();     bs[0] = bs[1] = 0;     prime.push_back(2);     for (long long i = 3; i <= 1000000; i += 2) {       if (bs[i]) {         for (long long j = i * i; j <= 1000000; j += i) bs[j] = 0;         prime.push_back(i);       }     }   }   void solve() {     long long n;     cin >> n;     long long l = 0;     long long r = prime.size() - 1;     long long p = sqrt(n);     while (l <= r) {       long long mid = (l + r) / 2;       if (prime[mid] <= p)         l = mid + 1;       else         r = mid - 1;     }     long long cn = l - 1;     l = 0;     r = prime.size() - 1;     while (l <= r) {       long long mid = (l + r) / 2;       if (prime[mid] <= n)         l = mid + 1;       else         r = mid - 1;     }     cout << r - cn + 1 <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long TestCase;     sieve();     cin >> TestCase;     while (TestCase--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct Lem {     int m, v, id;     bool operator<(Lem b) const { return m < b.m || (m == b.m && v < b.v); }   };   int n, k, h;   Lem a[(100000 + 10)];   bool can(long double t) {     int j = k;     for (int i(n - 1), _l(0); i >= _l; --i) {       if (j > 0 && (long double)j * h / a[i].v - t <= -1e-7) j--;     }     return j == 0;   }   void putAns(long double t) {     int ans[(100000 + 10)];     int j = k;     for (int i(n - 1), _l(0); i >= _l; --i) {       if (j > 0 && (long double)j * h / a[i].v - t <= -1e-7) ans[--j] = a[i].id;     }     for (int i(0), _n(k - 1); i < _n; ++i) printf( %d  , ans[i]);     printf( %d n , (ans[k - 1]));   }   int main() {     scanf( %d , &(n)), scanf( %d , &(k)), scanf( %d , &(h));     for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].m)), a[i].id = i + 1;     for (int i(0), _n(n); i < _n; ++i) scanf( %d , &(a[i].v));     sort(a, a + n);     long double l = 0, r = 1e10;     int cnt = 100;     while (cnt--) {       long double mid = (l + r) / 2.0;       if (can(mid))         r = mid;       else         l = mid;     }     putAns(r);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, l, r;   int rd() {     int re = 0, f = 1;     char c = getchar();     while ((c <  0 ) || (c >  9 )) {       if (c ==  - ) f = -f;       c = getchar();     }     while ((c >=  0 ) && (c <=  9 )) {       re = re * 10 + c -  0 ;       c = getchar();     }     return re * f;   }   int main() {     cin >> m >> k;     cin >> n;     l = (n > k) ? (n - k) : 0;     r = (m < n) ? m : n;     cout << (r - l + 1) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 130;   int a[MAXN];   int main() {     int N;     cin >> N;     for (int i = 1; i < (N + 1); ++i) cin >> a[i];     bool ok = 0;     if ((a[N] & 1) == 0 || (a[1] & 1) == 0)       ok = 0;     else if (N & 1)       ok = 1;     if (ok)       cout <<  Yes  << endl;     else       cout <<  No  << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct segment_tree {     long long a[1 << 20][5];     int sz[1 << 20];     int N;     void initi(int x) {       N = 1;       while (N < x) N <<= 1;     }     void pushup(int x) {       int pos = x + N - 1;       while (x > 0) {         x = (x - 1) >> 1;         sz[x] = sz[(x << 1) + 1] + sz[(x << 1) + 2];         for (int i = 0; i < 5; i++) a[x][i] = 0;         for (int i = 0; i < 5; i++) {           a[x][i] += a[(x << 1) + 1][i];           a[x][(i + sz[(x << 1) + 1]) % 5] += a[(x << 1) + 2][i];         }       }     }     void ins(int x, int y) {       int pos = x + N - 1;       sz[pos]++;       a[pos][0] = y;       pushup(pos);     }     void del(int x) {       int pos = x + N - 1;       sz[pos]--;       a[pos][0] = 0;       pushup(pos);     }   } tr;   int n;   int s[100010];   vector<int> v;   vector<int> vc;   map<int, int> mp;   int l;   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       string t;       int x;       cin >> t;       if (t ==  add ) {         cin >> x;         v.push_back(x);         vc.push_back(x);       } else if (t ==  del ) {         cin >> x;         v.push_back(-x);       } else {         v.push_back(0);       }     }     sort(vc.begin(), vc.end());     tr.initi((int)vc.size());     for (int i = 0; i < vc.size(); i++) {       mp[vc[i]] = i;     }     for (int i = 0; i < v.size(); i++) {       if (!v[i]) {         printf( %lld n , tr.a[0][2]);       } else if (v[i] < 0) {         tr.del(mp[-v[i]]);       } else {         tr.ins(mp[v[i]], v[i]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100010;   void answer(int u) {     printf( ! %d n , u);     fflush(stdout);   }   int ask(int u) {     printf( ? %d n , u);     fflush(stdout);     int res;     scanf( %d , &res);     return res;   }   bool inside(int u, pair<int, int> v) {     return ((u > v.first) ^ (u >= v.second)) == 1;   }   bool check(pair<int, int> u, pair<int, int> v) {     if (inside(u.first, v) && inside(u.second, v)) {       return 1;     }     if (inside(v.first, u) && inside(v.second, u)) {       return 1;     }     if (inside(u.first, v) && inside(v.first, u)) {       return 1;     }     if (inside(u.second, v) && inside(v.second, u)) {       return 1;     }     return 0;   }   int main() {     int n;     scanf( %d , &n);     if ((n / 2) % 2 != 0) {       answer(-1);       return 0;     }     int x = ask(1);     int y = ask(1 + n / 2);     if (x == y) {       answer(1);       return 0;     }     pair<int, int> u(x, y);     pair<int, int> v(y, x);     int low = 1, high = n / 2 + 1;     while (high - low > 1) {       int mid = (high + low) / 2;       int foo = ask(mid);       int bar = ask(mid + n / 2);       if (foo == bar) {         answer(mid);         return 0;       }       pair<int, int> a(u.first, foo);       pair<int, int> b(v.first, bar);       if (check(a, b)) {         high = mid;         u = a;         v = b;       } else {         low = mid;         u = make_pair(foo, u.second);         v = make_pair(bar, v.second);       }     }     answer(low);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INFL = (int)1e9;   const long long int INFLL = (long long int)1e18;   const double INFD = numeric_limits<double>::infinity();   const double PI = 3.14159265358979323846;   bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }   bool inrange(int x, int t) { return x >= 0 && x < t; }   long long int rndf(double x) {     return (long long int)(x + (x >= 0 ? 0.5 : -0.5));   }   long long int floorsqrt(long long int x) {     long long int m = (long long int)sqrt((double)x);     return m + (m * m <= x ? 0 : -1);   }   long long int ceilsqrt(long long int x) {     long long int m = (long long int)sqrt((double)x);     return m + (x <= m * m ? 0 : 1);   }   long long int rnddiv(long long int a, long long int b) {     return (a / b + (a % b * 2 >= b ? 1 : 0));   }   long long int ceildiv(long long int a, long long int b) {     return (a / b + (a % b == 0 ? 0 : 1));   }   long long int gcd(long long int m, long long int n) {     if (n == 0)       return m;     else       return gcd(n, m % n);   }   long long int lcm(long long int m, long long int n) {     return m * n / gcd(m, n);   }   class Max_Queue {    private:     stack<pair<long long int, long long int> > stk0, stk1;     void rebuffer() {       while (stk1.size()) {         long long int x = stk1.top().first;         long long int y = stk0.size() ? stk0.top().second : LLONG_MIN;         stk0.push({x, max(x, y)});         stk1.pop();       }     }       public:     void push(long long int x) {       long long int y = stk1.size() ? stk1.top().second : LLONG_MIN;       stk1.push({x, max(x, y)});     }     long long int front() {       if (stk0.empty()) rebuffer();       return stk0.top().first;     }     void pop() {       if (stk0.empty()) rebuffer();       stk0.pop();     }     size_t size() { return stk0.size() + stk1.size(); }     void clear() {       while (stk0.size()) stk0.pop();       while (stk1.size()) stk1.pop();     }     long long int get_max() {       long long int x = LLONG_MIN, y = LLONG_MIN;       if (stk0.size()) x = stk0.top().second;       if (stk1.size()) y = stk1.top().second;       return max(x, y);     }   };   long long int dist(long long int s, long long int t, long long int n) {     if (s <= t)       return t - s;     else       return t + n - s;   }   int main() {     int n, m;     cin >> n >> m;     vector<long long int> a(n, LLONG_MAX);     vector<long long int> cnt(n, 0);     for (int i = 0; i < (int)(m); i++) {       long long int s, t;       cin >> s >> t;       s--;       t--;       a[s] = min(a[s], dist(s, t, n));       cnt[s]++;     }     vector<long long int> ans(n, 0);     Max_Queue mq;     for (int j = 0; j < (int)(n); j++) {       long long int buf = -n;       if (cnt[j] > 0) buf = dist(0, j, n) + (cnt[j] - 1) * n + a[j];       mq.push(buf);     }     for (int i = 0; i < (int)(n); i++) {       ans[i] = mq.get_max() - i;       long long int x = mq.front();       mq.pop();       mq.push(x + n);     }     for (int extra_i = 0; extra_i < (int)(ans.size()); extra_i++) {       cout << ans[extra_i] <<    ;     }     cout << endl;     ;   }
#include <bits/stdc++.h>   using namespace std;   void display(vector<int> v1) {     for (long long int i = 0; i < v1.size(); i++) {       cout << v1[i] <<    ;     }     cout << endl;   }   long long int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};   long long int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};   int n, dp[9000][2];   vector<int> v1[2];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n;     memset(dp, -1, sizeof(dp));     for (int p = 0, k; p < 2; p += 1) {       cin >> k;       v1[p].resize(k);       for (long long int i = 0; i < k; i++) {         cin >> v1[p][i];       }     }     dp[1][0] = 0;     dp[1][1] = 0;     bool flag = true;     while (flag) {       flag = false;       for (int i = n; i >= 2; i--)         for (int p = 0; p < 2; p++)           if (dp[i][p] == -1) {             bool can = false;             for (int x : v1[p]) {               int nxt = (i + x) % n + n * !bool((i + x) % n);               if (!dp[nxt][p ^ 1]) {                 dp[i][p] = 1;                 flag = true;                 can = true;                 break;               } else if (dp[nxt][p ^ 1] == -1)                 can = true;             }             if (!can) dp[i][p] = 0, flag = true;           }     }     for (int p = 0; p < 2; p++) {       for (int i = 2; i <= n; i++) {         if (dp[i][p] == -1) {           cout <<  Loop  ;         } else if (dp[i][p] == 1) {           cout <<  Win  ;         } else {           cout <<  Lose  ;         }       }       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353;   const int N = 5e5 + 5;   long long l[N], r[N], x[N], d[N], s[N], pre[N], dp[N];   int n, m;   inline long long solve(int u) {     for (int i = 1; i <= n; i++) d[i] = s[i] = pre[i] = 0;     for (int i = 1; i <= m; i++) {       if (x[i] >> u & 1) {         d[r[i] + 1]--;         d[l[i]]++;       } else {         pre[r[i]] = max(pre[r[i]], l[i]);       }     }     dp[0] = s[0] = 1;     for (int i = 1; i <= n; i++) {       d[i] += d[i - 1];       pre[i] = max(pre[i], pre[i - 1]);       if (d[i] > 0)         dp[i] = 0;       else if (pre[i - 1] > 0)         dp[i] = (s[i - 1] - s[pre[i - 1] - 1]) % mod;       else         dp[i] = s[i - 1];       s[i] = (s[i] + s[i - 1] + dp[i]) % mod;     }     return pre[n] == 0 ? s[n] % mod : (s[n] - s[pre[n] - 1]) % mod;   }   int main() {     int k;     scanf( %d%d%d , &n, &k, &m);     for (int i = 1; i <= m; i++) scanf( %lld%lld%lld , &l[i], &r[i], &x[i]);     long long ans = 1;     for (int i = 0; i < k; i++) ans = ans * solve(i) % mod;     printf( %lld n , (ans + mod) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod = 1e9 + 7;   int inf = 1e9;   double eps = 1e-6;   int main() {     int n, k;     cin >> n >> k;     vector<int> a;     for (int i = 0; i < n; i++) {       int t;       cin >> t;       a.push_back(t);     }     if (k == 1) {       int ans = a[0];       for (int i = 1; i < n; i++) {         ans = min(ans, a[i]);       }       cout << ans;     } else if (k > 2) {       int ans = a[0];       for (int i = 1; i < n; i++) {         ans = max(ans, a[i]);       }       cout << ans;     } else {       int ans = INT_MIN;       multiset<int> p;       multiset<int> q;       p.insert(a[0]);       for (int i = 1; i < n; i++) {         q.insert(a[i]);       }       ans = max(ans, max(*q.begin(), *p.begin()));       for (int i = 1; i < n - 1; i++) {         p.insert(a[i]);         q.erase(q.find(a[i]));         ans = max(ans, max(*q.begin(), *p.begin()));       }       cout << ans;     }     return 0;   }
#include <bits/stdc++.h>   int a[100005] = {};   int p[100005] = {};   int mbuy[100005] = {};   int main() {     std::ios_base::sync_with_stdio(false);     std::cin.tie(NULL);     std::cout.tie(NULL);     int n, currmin = 1000000, buy = 0, last = 0;     std::cin >> n;     for (int i = 0; i < n; i++) std::cin >> a[i] >> p[i];     for (int i = 0; i < n; i++) {       if (p[i] < currmin) {         mbuy[last] = buy;         currmin = p[i];         last = i;         buy = 0;       }       buy += a[i];     }     mbuy[last] = buy;     long long int ans = 0;     for (int i = 0; i < n; i++) {       ans += mbuy[i] * p[i];     }     std::cout << ans <<   n ;   }