malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = (int)1e5 + 5, INF = (int)1e9;   const long double EPS = 1e-9;   int t[N], h[N], m[N];   bool used[N];   int main() {     int n, cur, ans = 0, ans1 = 0, tp, v = -1, first;     cin >> n >> first;     cur = first;     for (int i = 0; i < n; i++) cin >> t[i] >> h[i] >> m[i];     for (int i = 0; i < n; i++)       if (t[i] == 0 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i;     tp = 0;     if (v != -1) {       used[v] = 1;       cur += m[v];       ans++;     }     for (int i = 0; i < n; i++) {       v = -1;       for (int j = 0; j < n; j++)         if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v]))           v = j;       if (v == -1)         break;       else {         tp = 1 - tp;         used[v] = 1;         cur += m[v];         ans++;       }     }     tp = 1;     v = -1;     cur = first;     for (int i = 0; i < n; i++) used[i] = 0;     for (int i = 0; i < n; i++)       if (t[i] == 1 && h[i] <= cur && (v == -1 || m[i] > m[v])) v = i;     if (v != -1) {       used[v] = 1;       cur += m[v];       ans1++;     }     for (int i = 0; i < n; i++) {       v = -1;       for (int j = 0; j < n; j++)         if (!used[j] && t[j] != tp && h[j] <= cur && (v == -1 || m[j] > m[v]))           v = j;       if (v == -1)         break;       else {         tp = 1 - tp;         used[v] = 1;         cur += m[v];         ans1++;       }     }     cout << max(ans, ans1) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 7;   long long arr[maxn];   string s;   int main() {     std::ios::sync_with_stdio(false);     int n;     cin >> n;     long long tot = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       arr[i] *= 2;       tot += arr[i];     }     cin >> s;     long long W = 0, G = 0, flag = 5;     for (int i = 0; i < n; i++) {       if (s[i] ==  G )         G += arr[i];       else if (s[i] ==  W )         W += arr[i], flag = 3;       long long cur = arr[i], sta;       sta = min(cur / 2, W), tot += sta * 2, cur -= sta * 2, W -= sta;       sta = min(cur / 2, G), tot += sta * 4, cur -= sta * 2, G -= sta;       tot += flag * cur;     }     cout << tot / 2 << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s, A( a );     cin >> s;     vector<vector<int> > a(26);     for (int i = 0; i < k; i++) a[s[i] - A[0]].push_back(i);     for (int i = 0; i < n; i++) {       cin >> s;       long long ans = 0;       for (int j = 0; j < s.size(); j++) {         int b = (int)s[j] - A[0];         int r = (int)a[b].size();         if (r == 0)           ans += s.size();         else {           r--;           int l = 0;           while (r - l > 1) {             int m = (l + r) / 2;             if (a[b][m] >= j)               r = m;             else               l = m;           }           ans += min(abs(a[b][l] - j), abs(a[b][r] - j));         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());   void print_time() {}   template <typename T>   void update_max(T& x, T y) {     x = max(x, y);   }   template <typename T>   void update_min(T& x, T y) {     x = min(x, y);   }   template <class T1, class T2>   ostream& operator<<(ostream& out, pair<T1, T2> pair) {     return out <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, vector<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class T>   ostream& operator<<(ostream& out, set<T> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   template <class L, class R>   ostream& operator<<(ostream& out, map<L, R> vec) {     out <<  ( ;     for (auto& v : vec) out << v <<  ,  ;     return out <<  ) ;   }   long long ask(long long t, long long i, long long j, long long k) {     ++i, ++j, ++k;     cout << t <<     << i <<     << j <<     << k << endl;     long long res;     cin >> res;     return res;   }   void ans(vector<long long> p) {     cout <<  0  ;     for (long long pp : p) {       cout << pp + 1 <<    ;     }     cout << endl;   }   int main() {     cout << fixed << setprecision(20);     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n;     cin >> n;     vector<long long> area(n);     vector<long long> sign(n);     for (long long i = 2; i < n; ++i) {       area[i] = ask(1, 0, 1, i);       sign[i] = ask(2, 0, 1, i);     }     vector<long long> cnt_sign(2);     vector<set<pair<long long, long long>>> pos(2);     for (long long i = 2; i < n; ++i) {       pos[(sign[i] + 1) / 2].insert({area[i], i});       ++cnt_sign[(sign[i] + 1) / 2];     }     vector<vector<long long>> sorted(2);     for (long long kek = 0; kek < 2; ++kek) {       sorted[kek] = vector<long long>(cnt_sign[kek]);       long long l = 0;       long long r = cnt_sign[kek] - 1;       while (!pos[kek].empty()) {         pair<long long, long long> curr = *pos[kek].begin();         pos[kek].erase(pos[kek].begin());         long long i = 0;         long long j = curr.second;         if (pos[kek].empty()) {           sorted[kek][l] = j;           break;         }         long long k = pos[kek].begin()->second;         long long q = ask(2, i, j, k);         if (q > 0) {           sorted[kek][l++] = j;         } else {           sorted[kek][r--] = j;         }       }     }     vector<long long> p;     p.push_back(0);     for (long long v : sorted[0]) p.push_back(v);     p.push_back(1);     for (long long v : sorted[1]) p.push_back(v);     ans(p);     print_time();     return 0;   }
#include<bits/stdc++.h>   using namespace std;   int main()   {    ios_base::sync_with_stdio(false);       cin.tie(NULL);    long long t;    cin >> t;    while(t--)    {     long long n;     cin >> n;     string a[n];     for(long long i=0;i<n;i++)     {      cin >> a[i];     }     for(long long i=0;i<10;i++)     {      long long ans=0;      std::vector<pair<long long,long long> > x,y;      for(long long j=0;j<n;j++)      {       for(long long k=0;k<n;k++)       {        if(a[j][k]==((char)i+ 0 ))        {         x.push_back(make_pair(j,k) );         y.push_back(make_pair(k,j) );        }       }      }      sort(x.begin(), x.end());      sort(y.begin(), y.end());      for(long long k=0;k<x.size();k++)       {        long long x1=x[0].first,y1=x[0].second,x2=x[k].first,y2=x[k].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      for(long long k=0;k<x.size();k++)       {        long long x1=x[k].first,y1=x[k].second,x2=x[x.size()-1].first,y2=x[x.size()-1].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      for(long long k=0;k<y.size();k++)       {        long long y1=y[0].first,x1=y[0].second,y2=y[k].first,x2=y[k].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      for(long long k=0;k<y.size();k++)       {        long long y1=y[k].first,x1=y[k].second,y2=y[y.size()-1].first,x2=y[y.size()-1].second;        ans=max(ans,abs(x1-x2)*max(max(y1,n-y1-1),max(y2,n-y2-1)));        ans=max(ans,abs(y1-y2)*max(max(x1,n-x1-1),max(x2,n-x2-1)));       }      //}      cout << ans <<    ;     }     cout << endl;    }   }
#include <bits/stdc++.h>   using namespace std;   string t;   vector<string> query(3);   void ask(string &q) {     cout <<  ?   << q <<   n ;     fflush(stdout);     cin >> q;   }   int main() {     ios_base::sync_with_stdio(false);     ;     cin >> t;     for (int i = 0; i < t.length(); i++) {       query[0] += (char)( a  + (i % 26));       query[1] += (char)( a  + ((i % (26 * 26)) / (26)));       query[2] += (char)( a  + (i % (26 * 26 * 26)) / (26 * 26));     }     ask(query[0]);     ask(query[1]);     ask(query[2]);     string ans(t.length(),    );     for (int i = 0; i < t.length(); i++) {       int pos = (query[0][i] -  a ) + (query[1][i] -  a ) * 26 +                 (query[2][i] -  a ) * 26 * 26;       ans[pos] = t[i];     }     cout <<  !   << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 500010, INF = MAXN + 1;   struct Query {     int pos, l, r;   };   struct AddEvent {     int pos, value, start_valid;   };   int n, m;   int as[MAXN];   int close[MAXN];   Query queries[MAXN];   AddEvent add_events[MAXN];   int results[MAXN];   int st[4 * MAXN];   void update(int v, int l, int r, int ind, int val) {     if (l == r) {       assert(st[v] == INF);       st[v] = val;     } else {       int m = (l + r) >> 1;       if (ind <= m)         update(v + v, l, m, ind, val);       else         update(v + v + 1, m + 1, r, ind, val);       st[v] = min(st[v + v], st[v + v + 1]);     }   }   int get(int v, int l, int r, int tl, int tr) {     assert(l <= tl && tr <= r && tl <= tr);     if (l == tl && r == tr) return st[v];     int res = INF, m = (l + r) >> 1;     if (tl <= m) res = get(v + v, l, m, tl, min(tr, m));     if (tr > m) res = min(res, get(v + v + 1, m + 1, r, max(m + 1, tl), tr));     return res;   }   int main() {     for (int i = 0; i < int(4 * MAXN); ++i) st[i] = INF;     scanf( %d%d , &n, &m);     for (int i = 0; i < int(n); ++i) scanf( %d , &as[i]);     for (int i = 0; i < int(m); ++i) {       scanf( %d%d , &queries[i].l, &queries[i].r);       --queries[i].l, --queries[i].r;       queries[i].pos = i;     }     sort(queries, queries + m, [](Query a, Query b) { return a.r < b.r; });     map<int, int> last;     for (int i = n - 1; i >= 0; i--) {       auto it = last.find(as[i]);       if (it == last.end()) {         close[i] = INF;       } else {         close[i] = it->second - i;       }       last[as[i]] = i;     }     for (int i = 0; i < int(n); ++i) {       add_events[i] = {i, close[i], i + close[i]};     }     sort(add_events, add_events + n,          [](AddEvent a, AddEvent b) { return a.start_valid < b.start_valid; });     int qp = 0, ap = 0;     for (int i = 0; i < n; i++) {       while (ap < n && add_events[ap].start_valid == i) {         update(1, 0, n - 1, add_events[ap].pos, add_events[ap].value);         ++ap;       }       while (qp < m && queries[qp].r == i) {         results[queries[qp].pos] = get(1, 0, n - 1, queries[qp].l, queries[qp].r);         ++qp;       }     }     for (int i = 0; i < int(m); ++i) {       if (results[i] == INF) results[i] = -1;       printf( %d n , results[i]);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 11;   int a[N], b[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= m; i++) {       cin >> a[i] >> b[i];     }     vector<int> v;     for (int p = 1; p <= 200; p++) {       int x = 0;       for (int i = 1; i <= m; i++) {         int d = (a[i] / p);         if (a[i] % p != 0) d++;         if (b[i] != d) {           x = 1;           break;         }       }       if (x == 0) {         int d = (n / p);         if (n % p != 0) d++;         v.push_back(d);       }     }     sort(v.begin(), v.end());     if (v[0] != v[v.size() - 1]) {       cout << -1 << endl;     } else       cout << v[0] << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> sieve(int n) {     vector<bool> prime(n + 1, true);     prime[0] = false;     prime[1] = false;     int m = sqrt(n);     vector<int> ans;     for (int p = 2; p <= m; p++) {       if (prime[p]) {         for (int i = p * 2; i <= n; i += p) prime[i] = false;       }     }     for (int i = 0; i < n; i++)       if (prime[i]) ans.push_back(i);     return ans;   }   int gcd(int a, int b) {     if (b == 0) return a;     return gcd(b, a % b);   }   int mod = 1e9 + 7;   int power(int a, long long b) {     int res = 1;     while (b) {       if (b & 1) res = 1LL * res * a % mod;       a = 1LL * a * a % mod;       b >>= 1;     }     return res;   }   long long min(int a, long long b) {     if (a > b) return b;     return a;   }   long long max(int a, long long b) {     if (a > b) return a;     return b;   }   void solve() {     long long n, m;     cin >> n >> m;     vector<pair<int, int>> p;     for (int i = 0; i < m; i++) {       int x, y;       cin >> x >> y;       p.push_back({x, y});     }     long long ans =         max(p[0].first + p[0].second - 1, p[m - 1].second + (n - p[m - 1].first));     for (int i = 1; i < m; i++) {       if (abs(p[i].second - p[i - 1].second) > p[i].first - p[i - 1].first) {         cout <<  IMPOSSIBLE ;         return;       }       ans = max(ans, max(p[i].second, p[i - 1].second) +                          (p[i].first - p[i - 1].first -                           abs(p[i].second - p[i - 1].second)) /                              2);     }     cout << ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int mul = 0;     if (mul == 1) {       int t;       cin >> t;       while (t--) {         solve();         cout <<   n ;       }     } else {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e5 + 10;   const int MOD = 1e9 + 7;   int n;   long long int a[MAXN], minn;   bool have[MAXN], flag;   int main() {     while (scanf( %d , &n) != EOF) {       a[1] = 0;       minn = 0;       memset(have, false, sizeof(have));       flag = true;       for (int i = 1; i < n; ++i) {         int num;         scanf( %I64d , &num);         a[i + 1] = a[i] + num;         minn = min(minn, a[i + 1]);       }       for (int i = 1; i <= n; ++i) {         a[i] += -minn + 1;         if (a[i] > n || have[a[i]]) {           printf( -1 n );           flag = false;           break;         }         have[a[i]] = true;       }       if (flag) {         for (int i = 1; i <= n; ++i) {           i == n ? printf( %I64d n , a[i]) : printf( %I64d  , a[i]);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T, typename S>   ostream &operator<<(ostream &os, const pair<T, S> &v) {     os <<  ( ;     os << v.first <<  ,  << v.second <<  ) ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const vector<T> &v) {     os <<  [ ;     long long sz = v.size();     for (long long i = 0; i < sz; ++i) {       os << v[i];       if (i != sz - 1) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T>   ostream &operator<<(ostream &os, const set<T> &v) {     T last = *v.rbegin();     os <<  [ ;     for (auto it : v) {       os << it;       if (it != last) os <<  , ;     }     os <<  ] n ;     return os;   }   template <typename T, typename S>   ostream &operator<<(ostream &os, const map<T, S> &v) {     for (auto it : v) {       os << it.first <<   :   << it.second <<   n ;     }     return os;   }   long long power(long long a, long long b) {     long long res = 1;     while (b) {       if (b % 2) {         res = (res * a) % 1000000007;       }       b /= 2;       a = (a * a) % 1000000007;     }     return res;   }   template <typename Arg1>   void __f(const char *name, Arg1 &&arg1) {     cerr << name <<   :   << arg1 << std::endl;   }   template <typename Arg1, typename... Args>   void __f(const char *names, Arg1 &&arg1, Args &&...args) {     const char *comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   :   << arg1 <<   |  ;     __f(comma + 1, args...);   }   const long long N = 1005;   long long arr[N];   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     for (__typeof(1) i = 1; i <= n; i++) cin >> arr[i];     long long res = 0;     for (__typeof(2) i = 2; i <= n - 1; i++) {       if ((arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) ||           (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]))         ++res;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e6 + 7;   int A[N], B[N], n, ans, pos[N], s1[N], s2[N], cnt;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) cin >> A[i], pos[A[i]] = i;     for (int i = 1; i <= n; ++i) cin >> B[i], A[pos[B[i]]] = i;     for (int i = 1; i <= n; ++i) pos[A[i]] = i;   ZXY:;     int st = 1;     while (A[st] == st) st++;     for (int i = st; i <= n; ++i)       if (A[i] > i) {         for (int j = i + 1; j <= n; ++j)           if (A[j] <= i && j <= A[i]) {             ans += j - i;             s1[++cnt] = i, s2[cnt] = j;             swap(A[i], A[j]);             goto ZXY;           }       }     cout << ans << endl << cnt << endl;     for (int i = 1; i <= cnt; ++i) cout << s1[i] <<     << s2[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, res = 0, a, b;     cin >> n;     vector<pair<long long, long long>> nums;     for (int i = 0; i < n; i++) {       cin >> a >> b;       nums.push_back({a, b});     }     for (int i = 0; i < n; i++) {       bool l = false, r = false, u = false, d = false;       for (int j = 0; j < n; j++)         if (i != j) {           if (nums[j].second == nums[i].second && nums[j].first > nums[i].first)             r = true;           if (nums[j].second == nums[i].second && nums[j].first < nums[i].first)             l = true;           if (nums[j].second > nums[i].second && nums[j].first == nums[i].first)             u = true;           if (nums[j].second < nums[i].second && nums[j].first == nums[i].first)             d = true;         }       res += (bool)(l && r && u && d);     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   int main() {     int a, b, c, d;     while (scanf( %d%d%d%d , &a, &b, &c, &d) == 4) {       if (c >= b - 1 && c <= 2 * (b + 1)) {         printf( YES n );         continue;       }       if (d >= a - 1 && d <= 2 * (a + 1)) {         printf( YES n );         continue;       }       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[1000001];   int main() {     ios::sync_with_stdio(false);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> A[i];     }     map<int, int> change_v;     int above = 0, below = 0;     long long sum = 0;     long long best_i = 0;     for (int i = 0; i < n; i++) {       int xs = A[i] - i - 1;       int x = (xs > 0) ? xs : -1 * xs;       if (xs < 0) {         change_v[x]++;       }       if (xs < 0) {         below++;       } else {         above++;       }       sum += x;     }     long long best_sum = sum;     for (int i = 0; i < n - 1; i++) {       long long xs = A[i] - n;       long long x = (xs > 0) ? xs : -1 * xs;       long long cnt = change_v[i + 1];       if (xs < 0) {         change_v[x + i + 1]++;       }       int cur_below_d = (A[i] - 1 < 0) ? 1 : 0;       int cur_above_d = (A[i] - 1 >= 0) ? 1 : 0;       sum -= below - cur_below_d;       sum += above - cur_above_d;       sum -= (A[i] - 1 > 0) ? A[i] - 1 : 1 - A[i];       sum += x;       above += cnt;       below -= cnt;       if (xs < 0 && A[i] - 1 >= 0) {         below++;         above--;       }       if (sum < best_sum) {         best_i = i + 1;         best_sum = sum;       }     }     if (best_i != 0) {       best_i = n - best_i;     }     cout << best_sum <<     << best_i;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T power(T a, T b) {     T x;     if (b == 0)       x = 1;     else       x = a;     for (size_t i = 1; i < b; i++) x *= a;     return x;   }   long long int gcd(long long int a, long long int b) {     return b == 0 ? a : gcd(b, a % b);   }   long long int n, m, a, b, c, ab, ba, x, y, z, avg, total, ans, sum;   long long int arr2[300001], arr3[100001], arr4[100001], arr5[100001];   char c1, c2;   vector<pair<string, long long int> > vec;   vector<long long int> v;   bool f, f1, f2, found;   string str, s1, s2, s3, s4;   map<long long int, long long int> mp, mp1;   set<int> seto;   double d, d1;   long long int x1, x2, y11, y2;   long long int mini = 10000000000, maxi = 0;   set<string> sets;   int main() {     cin >> n >> str;     for (long long int i = 0; i < str.size(); i++) {       if (str[i] ==  > )         f1 = 1;       else         f = 1;     }     if (f && f1) {       for (long long int i = 0; i < str.size(); i++)         if (str[i] ==  < )           sum++;         else           break;       reverse(str.rbegin(), str.rend());       for (long long int i = 0; i < str.size(); i++)         if (str[i] ==  > )           sum++;         else           break;     } else       sum = str.size();     cout << sum;   }
#include <bits/stdc++.h>   using namespace std;   const int nm = 2e5 + 3;   const long long mod = 1e9 + 7;   int n;   int pos[nm];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     while (cin >> n) {       for (int i = 0; i < n; i++) cin >> pos[i];       sort(pos, pos + n);       int step = n / 2 - 1;       int res = pos[n - 1] - pos[0];       pair<double, int> loc;       for (int i = 0; i <= step; i++) {         if (pos[i + n - step - 1] - pos[i] < res) {           res = pos[i + n - step - 1] - pos[i];           loc.first = i, loc.second = i + n - step - 1;         }       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 150;   int n, dp[N][N * N], sum, cnt[N], x, u[N][N * N], res;   int main() {     cin >> n;     for (int i = 1; i <= n; i++) scanf( %d , &x), sum += x, cnt[x]++;     dp[0][0] = 1;     for (int i = 1; i <= 100; i++) {       res += (cnt[i] > 0);       for (int j = n; j >= 1; j--) {         for (int cn = 1; cn <= min(j, cnt[i]); cn++) {           for (int l = i * cn; l <= sum; l++) {             dp[j][l] += dp[j - cn][l - i * cn];           }         }       }     }     if (res == 1 || res == 2) {       cout << n << endl;       return 0;     }     for (int i = 1; i <= 100; i++)       for (int cn = 1; cn <= cnt[i]; cn++) u[cn][i * cn] = 1;     for (int i = n; i >= 1; i--) {       for (int j = 0; j <= sum; j++) {         if (dp[i][j] == 1 && u[i][j] == 1) {           cout << i << endl;           return 0;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long t, xiaoyud, dayu, n, x, pos, ans1, mo = 1e9 + 7, ans2, ans;   int main() {     cin >> n >> x >> pos;     long long l = 0, r = n;     while (l < r) {       long long mid = (l + r) / 2;       if (mid <= pos) {         l = mid + 1;         if (mid != pos) xiaoyud++;       } else {         r = mid;         dayu++;       }     }     ans1 = 1;     for (long long i = 1; i <= xiaoyud; i++) {       ans1 = (ans1 * (x - 1 - i + 1)) % mo;     }     ans2 = 1;     for (long long i = 1; i <= dayu; i++) {       ans2 = (ans2 * (n - x - i + 1)) % mo;     }     ans = (ans1 * ans2) % mo;     for (long long i = 1; i <= n - xiaoyud - dayu - 1; i++) {       ans = (ans * (n - xiaoyud - dayu - i)) % mo;     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a, od = 0, ev = 0, ans = 0;     cin >> n;     vector<int> vec;     vector<int>::iterator it;     while (n--) {       cin >> a;       vec.push_back(a);       if (a % 2 == 0)         ev++;       else         od++;     }     for (it = vec.begin(); it != vec.end(); it++) {       if (ev > od) {         if (*it % 2 != 0) ans = distance(vec.begin(), it);       } else if (od > ev) {         if (*it % 2 == 0) ans = distance(vec.begin(), it);       }     }     cout << ans + 1;   }