malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   double eps = 1e-6;   double pi = acos(0.0) * 2;   double dinf = 1e250;   long long INF = static_cast<long long>(2e18);   long long inf = static_cast<long long>(1e9 + 7);   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T>   void OUT(T a) {     cout << a;     exit(0);   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   long long extgcd(long long a, long long b, long long& x, long long& y) {     if (a == 0) {       x = 0;       y = 1;       return b;     }     long long x1, y1;     long long d = extgcd(b % a, a, x1, y1);     x = y1 - (b / a) * x1;     y = x1;     return d;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n;     cin >> n;     for (long long i = 0; i < n; i++) {       long long x, y, k;       cin >> x >> y >> k;       if (x < 0) x = -x;       if (y < 0) y = -y;       if (x < y) swap(x, y);       if (x > k)         cout << -1 << endl;       else {         if ((x & 1) != (y & 1)) {           k -= 1;           x -= 1;         } else if ((x & 1) != (k & 1)) {           x -= 1;           y -= 1;           k -= 2;         }         cout << k << endl;       }     }     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 n, x, y, a, b, c, t, q;     string s;     while (cin >> n >> q) {       if ((n / q) % 2 == 0) {         cout <<  NO  << endl;       } else         cout <<  YES  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[100001], l = 1;     for (int i = 1; i <= n; i++) {       int c, t;       cin >> c >> t;       int x = c * t;       a[l] = c * t;       l++;     }     int d = 1, s = 0;     for (int i = 0; i < m; i++) {       int k;       cin >> k;       if (s + a[d] >= k) {         cout << d << endl;       } else {         while (1) {           s += a[d];           d++;           if (s + a[d] >= k) {             cout << d << endl;             break;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void OJ() {}   long long n, m, x, k, y;   long long a[200000 + 5], b[200000 + 5];   void imp() { cout << -1 <<   n , exit(0); }   long long remove(long long start, long long end) {     if (start > end) return 0;     long long sz = end - start + 1;     long long maxneb = max(a[start - 1], a[end + 1]);     long long m = *max_element(a + start, a + end + 1);     long long a1 = (sz / k) * x + (sz % k) * y;     if (maxneb > m) return min(a1, y * sz);     if (sz < k) imp();     return min(a1, (sz - k) * y + x);   }   void solve() {     cin >> n >> m >> x >> k >> y;     for (long long i = 1; i <= n; ++i) cin >> a[i];     for (long long i = 1; i <= m; ++i) cin >> b[i];     long long ans = 0;     long long j = 1;     for (long long i = 1; i <= m; ++i) {       long long start = j;       while (j <= n && a[j] != b[i]) j++;       if (j > n) imp();       ans += remove(start, j - 1);       j++;     }     ans += remove(j, n);     cout << ans <<   n ;   }   signed main() {     OJ();     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }   long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }   const int N = 100005;   void solve() {     long long n;     cin >> n;     long long ans = 1;     for (long long i = 2; i <= n; i++) {       ans = ans + 4 * (i - 1);     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int TESTS = 1;     while (TESTS--) {       solve();     }     cerr <<   nTime elapsed:   << 1000 * clock() / CLOCKS_PER_SEC <<  ms n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ton {     vector<pair<long long, long long> > v[1919810 + 3];     long long& operator()(long long a, int b, int c, int d) {       a = ((a * 4000ll + b) * 4000ll + c) * 3ll + (d == 1);       int k = a % 1919810;       for (auto u = v[k].begin(); u != v[k].end(); u++)         if (u->first == a) return u->second;       v[k].push_back(make_pair(a, -1e17));       return v[k].back().second;     }   } f;   long long s[100010];   long long F(int l, int r, int k, int p) {     if (r - l + 1 < k) return 0;     if (r - l + 1 == k) return p * (s[r] - s[l - 1]);     long long& u = f(l, r, k, p);     if (u != -1e17) return u;     if (p == -1)       u = min(F(l, r - k, k, 1) - (s[r] - s[r - k]),               F(l, r - k - 1, k + 1, 1) - (s[r] - s[r - k - 1]));     else       u = max(F(l + k, r, k, -1) + (s[l + k - 1] - s[l - 1]),               F(l + k + 1, r, k + 1, -1) + (s[l + k] - s[l - 1]));     return u;   }   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %lld , &s[i]), s[i] += s[i - 1];     printf( %lld n , F(1, n, 1, 1));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char dirs[100001];   int todo[4];   int main() {     int n, fx, fy, tx, ty;     string wind;     cin >> n >> fx >> fy >> tx >> ty >> wind;     memcpy(dirs, wind.c_str(), n);     memset(todo, 0, sizeof(todo));     if (fx < tx) todo[0] = tx - fx;     if (fy < ty) todo[3] = ty - fy;     if (fx > tx) todo[2] = fx - tx;     if (fy > ty) todo[1] = fy - ty;     for (int i = 0; i < n; i++) {       switch (dirs[i]) {         case  E :           if (todo[0]) todo[0]--;           break;         case  S :           if (todo[1]) todo[1]--;           break;         case  W :           if (todo[2]) todo[2]--;           break;         case  N :           if (todo[3]) todo[3]--;           break;       }       if (todo[0] == 0 && todo[1] == 0 && todo[2] == 0 && todo[3] == 0) {         cout << i + 1 << endl;         return 0;       }     }     cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t, n, p;     cin >> t;     for (; t > 0; t--) {       cin >> n >> p;       int br = 0;       for (int r = 1; r <= n; r++) {         for (int i = 1; i <= n; i++) {           cout << i <<     << (i + r - 1) % n + 1 << endl;           br++;           if (br == 2 * n + p) goto st;         }       }     st:;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int div_floor(const long long int &a, const long long int &b) {     return a / b - (((a ^ b) < 0) and a % b);   }   long long int div_ceil(const long long int &a, const long long int &b) {     return a / b + (((a ^ b) >= 0) and a % b);   }   long long int diff(long long int a, long long int cnt) {     long long int rem = a % cnt;     return a * a - ((a / cnt + 1) * (a / cnt + 1) * rem +                     (a / cnt) * (a / cnt) * (cnt - rem));   }   void solve() {     long long int n, k;     cin >> n >> k;     long long int sum = 0;     multiset<pair<long long int, pair<long long int, long long int> > > mst;     vector<long long int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       sum += a[i] * a[i];       mst.insert({diff(a[i], 2), {a[i], 2}});     }     while (n++ < k) {       auto it = mst.end();       it--;       auto el = *it;       mst.erase(it);       sum -= el.first;       long long int x = el.second.first, ct = el.second.second;       mst.insert({diff(x, ct + 1) - diff(x, ct), {x, ct + 1}});     }     cout << sum <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int n;   int a[111];   int vv(int k) {     int i, j;     j = 0;     for (i = 1; i < k; i++)       if (a[i] == 0) j++;     for (i = k; i <= n; i++)       if (a[i] == 1) j++;     return j;   }   int main() {     cin >> n;     int i, j, k;     for (i = 1; i <= n; i++) cin >> a[i];     a[n + 1] = 1;     int d = 1;     for (i = 0; i <= n + 1; i++) {       d = max(vv(i), d);     }     cout << d;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[30];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     long long now = a[n - 1];     long long ans = 0;     for (int i = n - 1; i >= 0; i--) {       now = min(now, a[i]);       ans += now;       now--;       if (now < 0) break;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string s;   int num_e = 1e9 + 10, num_m, ans, w, q;   string answer;   void read_input() { cin >> s; }   void solve() {     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  e ) num_e = i;       if (s[i] ==  . ) num_m = i;     }     string s2 =   ;     for (int i = 0; i < num_e; i++)       if (s[i] !=  . ) s2 += s[i];     for (int i = num_e + 1; i < s.size(); i++) {       int q = s[i] -  0 ;       w = w * 10 + q;     }     w -= (num_e - num_m - 1);     if (w >= 0) {       answer += s2;       for (int i = 0; i < w; i++) answer +=  0 ;     } else {       for (int i = 0; i < s2.size(); i++) {         if (s2.size() - i == -w) answer +=  . ;         answer += s2[i];       }     }   }   void write_output() {     bool check = false;     for (int i = 0; i < answer.size(); i++)       if (answer[i] !=  .  && answer[i] !=  0 ) check = true;     if (!check)       cout << 0;     else {       int start;       for (int i = 0; i < answer.size(); i++) {         if (answer[i] ==  . ) {           start = i - 1;           break;         }         if (answer[i] !=  0 ) {           start = i;           break;         }       }       int num_m = -1;       for (int i = 0; i < answer.size(); i++)         if (answer[i] ==  . ) num_m = i;       check = false;       for (int i = num_m + 1; i < answer.size(); i++)         if (answer[i] !=  0 ) check = true;       if (check || num_m == -1)         for (int i = start; i < answer.size(); i++) cout << answer[i];       else         for (int i = start; i < num_m; i++) cout << answer[i];     }   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     read_input(), solve(), write_output();   }
#include <bits/stdc++.h>   using namespace std;   long long n, a, b;   long long arr[1000002];   long long dp[1000002][3];   set<int> prime;   int main() {     ios::sync_with_stdio(false);     cin >> n >> a >> b;     for (int i = 0; i < n; ++i) cin >> arr[i];     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < 3; ++j) {         int k = arr[i * (n - 1)] + j - 1;         for (int j = 2; j < 1e9; ++j) {           if (j * j > k) break;           while (k % j == 0) {             prime.insert(j);             k /= j;           }         }         if (k != 1 && k != 0) prime.insert(k);       }     }     long long ans = 1e18;     for (int p : prime) {       for (int i = 0; i < n + 1; ++i)         for (int j = 0; j < 3; ++j) dp[i][j] = 1e18;       dp[0][0] = 0;       dp[0][1] = 0;       dp[0][2] = 0;       for (int i = 0; i < n; ++i) {         if (arr[i] % p == 0) {           dp[i + 1][0] = min(dp[i + 1][0], dp[i][0]);           dp[i + 1][2] = min(dp[i + 1][2], dp[i][2]);         } else {           if ((arr[i] + 1) % p == 0 || (arr[i] - 1) % p == 0) {             dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + b);             dp[i + 1][2] = min(dp[i + 1][2], dp[i][2] + b);           }         }         dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + a);         dp[i + 1][1] = min(dp[i + 1][0], dp[i + 1][1]);         dp[i + 1][2] = min(dp[i + 1][2], dp[i + 1][1]);       }       ans = min(ans, dp[n][2]);     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const bool online_judge = true;   const long long inf = 1LL << 60;   long long toInt(string s) {     long long res;     stringstream ss;     ss << s;     ss >> res;     return res;   }   string toString(long long n) {     stringstream ss;     ss << n;     return ss.str();   }   long long dx[3] = {1, 0, -1};   long long dy[3] = {1, 0, -1};   vector<pair<long long, long long> > statue;   bool valid(long long x, long long y, long long turn) {     if (!(((x) >= (0) && (x) <= (7)) && ((y) >= (0) && (y) <= (7)))) return false;     for (long long i = 0; i < ((long long)((statue).size())); i++) {       long long sx = statue[i].first + turn;       long long sy = statue[i].second;       if ((sx == x && sy == y) || (sx + 1 == x && sy == y)) return false;     }     return true;   }   bool solve(long long x, long long y, long long turn) {     if (turn == 8) return true;     for (long long i = 0; i < 3; i++) {       for (long long j = 0; j < 3; j++) {         long long nx = x + dx[i];         long long ny = y + dy[j];         if (valid(nx, ny, turn) && solve(nx, ny, turn + 1)) {           return true;         }       }     }     return false;   }   void run() {     statue.clear();     for (long long i = 0; i < 8; i++) {       string s;       cin >> s;       for (long long j = 0; j < 8; j++) {         if (s[j] ==  S ) statue.emplace_back(i, j);       }     }     bool ans = solve(7, 0, 0);     if (ans)       cout <<  WIN  << endl;     else       cout <<  LOSE  << endl;   }   int main(int argc, char *argv[]) {     run();     return 0;   }
#include <bits/stdc++.h>   int const M = 1010000;   int const N = 10100;   int n;   int len[N];   int x[N];   int y[N];   int sq[M];   int perm[N];   double angle[N];   int resx[N];   int resy[N];   void filllens() {     std::fill(sq, sq + M, -1);     for (int i = 0; i * i < M; ++i) {       sq[i * i] = i;     }     int last = 0;     int sum = 0;     for (int i = n - 1; i >= 0; --i) {       while (x[i] == 0 && y[i] == 0) {         len[i] = ++last;         x[i] = 0;         y[i] = 0;         for (int q = 0; q * q <= len[i]; ++q) {           if (sq[len[i] - q * q] != -1) {             x[i] = q;             y[i] = sq[len[i] - q * q];             break;           }         }       }       sum += len[i];     }     if (sum % 2 == 1) {       int xx = 0;       int yy = 0;       while (xx == 0 && yy == 0) {         ++last;         for (int q = 0; q * q <= last; ++q) {           if (sq[last - q * q] != -1) {             xx = q;             yy = sq[last - q * q];             break;           }         }       }       int i = 0;       while (len[i] % 2 == last % 2) ++i;       len[i] = last;       x[i] = xx;       y[i] = yy;       for (; i > 0; --i) {         std::swap(len[i], len[i - 1]);         std::swap(x[i], x[i - 1]);         std::swap(y[i], y[i - 1]);       }     }   }   void solve() {     filllens();     int sumx = 0;     int sumy = 0;     std::function<int(int, int)> len2 = [](int x, int y) {       return x * x + y * y;     };     for (int i = 0; i < n; ++i) {       int ax = x[i];       int ay = y[i];       for (int it = 0; it < 2; ++it) {         for (int px : {-1, 1}) {           for (int py : {-1, 1}) {             if (len2(sumx + ax, sumy + ay) >                 len2(sumx + px * x[i], sumy + py * y[i])) {               ax = px * x[i];               ay = py * y[i];             }           }         }         std::swap(x[i], y[i]);       }       x[i] = ax;       y[i] = ay;       sumx += ax;       sumy += ay;     }     assert(sumx == 0 && sumy == 0);     for (int i = 0; i < n; ++i) {       perm[i] = i;       angle[i] = atan2(x[i], y[i]);     }     std::sort(perm, perm + n, [](int i, int j) { return angle[i] > angle[j]; });     sumx = 0;     sumy = 0;     for (int i = 0; i < n; ++i) {       resx[i] = sumx;       resy[i] = sumy;       sumx += x[perm[i]];       sumy += y[perm[i]];     }   }   void out() {     puts( YES );     for (int i = 0; i < n; ++i) {       printf( %d %d n , resx[i], resy[i]);     }   }   int main() {     scanf( %d , &n);     solve();     out();   }
#include <bits/stdc++.h>   using namespace std;   int _;   long long a1, a2, b1, b2, c1, c2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;     if ((c2 - b2) * (c1 - a1) == (c2 - a2) * (c1 - b1)) {       cout <<  No ;     } else if ((a1 - b1) * (a1 - b1) + (a2 - b2) * (a2 - b2) ==                (b1 - c1) * (b1 - c1) + (b2 - c2) * (b2 - c2)) {       cout <<  Yes ;     } else       cout <<  No ;   }
#include <bits/stdc++.h>   using namespace std;   const int oo = ~0u >> 1;   int n, m, a, ans;   int b[100015], p[100015];   bool check(int x) {     int sum = 0;     ans = 0;     for (int i = 0; i < x; i++) {       sum += max(p[x - i - 1] - b[i], 0), ans += p[x - i - 1];       if (sum > a) break;     }     if (sum <= a) return true;     return false;   }   int main() {     scanf( %d %d %d , &n, &m, &a);     for (int i = 0; i < n; i++) scanf( %d , &b[i]);     for (int i = 0; i < m; i++) scanf( %d , &p[i]);     sort(b, b + n, greater<int>());     sort(p, p + m);     int l = 0, r = min(n, m), res = 0, anser = 0;     while (l <= r) {       int mid = l + (r - l) / 2;       if (check(mid)) {         res = mid, anser = ans;         l = mid + 1;       } else         r = mid - 1;     }     printf( %d %d n , res, max(anser - a, 0));     return 0;   }
#if !defined(ONLINE_JUDGE)       #include  prettyprint.hpp         #include  debug.h    #else       #include <bits/stdc++.h>       using namespace std;       #define deb(...) 1729       #define dbg(...) 29       #define cer(x) 13   #endif   const bool testcase = 1;   typedef long long int ll;   const ll mod1 = 1000000007;   const ll mod2 = 998244353;      #define fast ios_base::sync_with_stdio(0);cin.tie(NULL)    #define test int T_T = 1; if(testcase){cin>>T_T;}while(T_T--)   #define all(ve) ve.begin(),ve.end()      const ll N = 1e7 + 7;   std::vector<ll> spf, prime;   std::vector<bool> isp;   void sieve(ll MAXN) {        spf.resize(MAXN);       spf[1] = 1;        for (int i=2; i<MAXN; i++)            spf[i] = i;        for (int i=4; i<MAXN; i+=2)            spf[i] = 2;           for (int i=3; i*i<MAXN; i++)        {            if (spf[i] == i)            {                for (int j=i*i; j<MAXN; j+=i)                {                   if (spf[j]==j)                        spf[j] = i;                }           }        }    }    void linearSieve(ll n) {       spf.resize(n);       isp.resize(n,true);       isp[0] = isp[1] = 0;       isp[2] = 1;       for (int i = 2; i <= n; ++i) {           if(isp[i]) {               prime.push_back(i);               spf[i] = i;           }           for (int j = 0; j < prime.size() && prime[j] <= spf[i] && prime[j] * i <= N; ++j) {               isp[i*prime[j]] = 0;               spf[i*prime[j]] = prime[j];           }       }   }   map<ll,ll> getFactor(ll x) {        map<ll,ll> ret;       while (x != 1) {            ret[spf[x]]++;           x = x / spf[x];        }        return ret;    }    // SOLVE   void solve() {       // cout << N <<   n ;       // dbg(spf);       ll n, k;       cin >> n >> k;       std::vector<ll> a(n);       for (int i = 0; i < n; ++i) {           cin >> a[i];           // dbg(a[i]);           map<ll,ll> pf = getFactor(a[i]);           // dbg(pf);           ll cur = 1;           for(auto [u, v]: pf) {               if(v & 1) {                  cur = cur * u;                }           }           a[i] = cur;       }       set<ll> st;       ll ans = 0;       for (int i = 0; i < n; ++i) {           if(st.find(a[i]) != st.end()) {               ans++;               st.clear();           }           st.insert(a[i]);           // while(!st.count())       }       if(st.size()) {           ans++;       }       cout << ans <<   n ;   }      //MAIN   int main(){          fast;       #ifndef ONLINE_JUDGE           // for getting input from input.txt           freopen( input.txt ,  r , stdin);           // for writing output to output.txt           freopen( output.txt ,  w , stdout);           // for debug in error.txt           freopen( error.txt ,  w , stderr);       #endif          sieve(N);       test {           solve();       }       return 0;   }
#include <bits/stdc++.h>   using namespace std;   int question, r, speed, st, en, len, did;   double lft, rht, middle, dist, p;   inline double euclid_dist(double a, double b) { return sqrt(a * a + b * b); }   inline bool check(double dis) {     p = 1.0 * dis / r;     return r * euclid_dist(1 - cos(p), sin(p)) >= len - dis;   }   int main() {     scanf( %d%d%d , &question, &r, &speed);     for (register int i = 1; i <= question; i++) {       scanf( %d%d , &st, &en);       len = en - st;       lft = 0;       rht = len;       did = 0;       while (lft < rht && did <= 50) {         middle = (lft + rht) / 2.0;         switch (check(middle)) {           case true:             dist = middle;             rht = middle;             break;           case false:             lft = middle;             break;         }         did++;       }       dist /= speed;       printf( %0.12lf n , dist);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXP = 18;   const int MAXN = 1000001;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int n, p;   string cad;   int freq[MAXP];   int val[1 << MAXP];   int vis[1 << MAXP];   vector<pair<int, int> > lista[1 << MAXP];   bool mat[MAXP][MAXP];   bool invalid[1 << MAXP];   bool marked[MAXP][MAXP][1 << MAXP];   int mapea(int i) { return cad[i] -  a ; }   int dfs(int u) {     if (vis[u]) return val[u];     vis[u] = 1;     int ans = 0;     for (int j = 0; j < p; j++) {       if (u & 1 << j) continue;       int v = u | 1 << j;       if (!invalid[v]) ans = max(ans, dfs(v) + freq[j]);     }     return val[u] = ans;   }   void compute(int a, int b) {     int id = 0, last = -1, mask;     while (id < n) {       if (mapea(id) == b && last != -1 && mask) {         lista[mask].push_back(pair<int, int>(a, b));         mask = 0;         last = -1;       }       if (mapea(id) == a) {         last = id;         mask = 0;       }       if (mapea(id) != a && mapea(id) != b) mask |= 1 << mapea(id);       id++;     }   }   void bfs(int mask, int a, int b) {     queue<int> q;     q.push(mask);     invalid[mask] = 1;     marked[a][b][mask] = 1;     while (!q.empty()) {       int u = q.front();       q.pop();       for (int i = 0; i < p; i++) {         if (i == a || i == b) continue;         int v = u | 1 << i;         if (!marked[a][b][v]) {           invalid[v] = 1;           marked[a][b][v] = 1;           q.push(v);         }       }     }     invalid[(1 << p) - 1] = 0;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> p;     cin >> cad;     for (int i = 0; i < n; i++) freq[mapea(i)]++;     for (int i = 0; i < p; i++)       for (int j = 0; j < p; j++) {         cin >> mat[i][j];         if (!mat[i][j]) compute(i, j);       }     for (int i = 0; i < 1 << p; i++)       for (int j = 0; j < lista[i].size(); j++)         bfs(i, lista[i][j].first, lista[i][j].second);     cout << n - dfs(0) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ch[101];   int main() {     int n, pos;     cin >> n;     for (int i = 0; i < n / 2; i++) {       cin >> ch[i];     }     sort(ch, ch + (n / 2));     int black = 0;     pos = 1;     for (int i = 0; i < n / 2; i++) {       black += abs(ch[i] - pos);       pos += 2;     }     int white = 0;     pos = 2;     for (int i = 0; i < n / 2; i++) {       white += abs(ch[i] - pos);       pos += 2;     }     cout << min(white, black) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     char s[200000], c[200000];     cin >> s;     int x = k / 2, r = k / 2;     if (k == n) {       cout << s;       return 0;     }     for (int i = 0, j = 0; i < n; ++i) {       if (s[i] ==  ( ) {         if (x > 0) c[j++] =  ( ;         --x;       } else {         if (r > 0) c[j++] =  ) ;         --r;       }     }     cout << c << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long re() {     long long x;     scanf( %lld , &x);     return x;   }   int main() {     long long y1 = re(), x1 = re(), y2 = re(), x2 = re();     long long h = (x2 - x1) / 2 + 1;     cout << h * (((y2 - y1 + 1) + 1) / 2) + (h - 1) * ((y2 - y1 + 1) / 2) << endl;   }