malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int N = 56;   int n, a[N];   int cnt(int x) {     int ans = 0;     for (int i = 1; i <= n; ++i) ans += (a[i] == x);     return ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cin >> n;     for (int i = 1; i <= n; ++i) cin >> a[i];     int k = *min_element(a + 1, a + n + 1);     cout << (cnt(k) <= n / 2 ?  Alice  :  Bob );   }
#include <bits/stdc++.h>   using namespace std;   long long num[30], pre[100010], cnt;   int main() {     int n, l, lr, ll;     char s[100010];     cin >> n;     for (int i = 0; i < n; i++) {       cin >> s + 1;       l = strlen(s + 1);       for (int j = 0; j < 26; j++)         if (num[j] && j +  a  != s[1] && j +  a  != s[l]) num[j] = 1;       lr = 1;       while (s[lr + 1] == s[lr]) lr++;       ll = l;       while (lr != l && s[ll] == s[ll - 1]) ll--;       ll = l - ll + 1;       if (s[1] == s[l])         if (lr == l)           num[s[1] -  a ] = (l + 1) * num[s[1] -  a ] + l;         else           num[s[1] -  a ] = lr + ll + 1;       else {         num[s[1] -  a ] = num[s[1] -  a ] > 0 ? lr + 1 : lr;         num[s[l] -  a ] = num[s[l] -  a ] > 0 ? ll + 1 : ll;       }       for (int j = lr + 1; j <= l - ll + 1; j++)         if (s[j] == s[j - 1])           pre[j] = pre[j - 1] + 1;         else {           pre[j] = 1;           num[s[j - 1] -  a ] = max(num[s[j - 1] -  a ], pre[j - 1]);         }     }     cnt = 0;     for (int j = 0; j < 26; j++) cnt = max(cnt, num[j]);     cout << cnt;   }
#include <bits/stdc++.h>   using namespace std;   long long sub(long long a, long long b) {     return (a - b + 1000000007) % 1000000007;   }   long long add(long long a, long long b) { return (a + b) % 1000000007; }   long long mul(long long a, long long b) { return (a * b) % 1000000007; }   vector<long long> adj[100005];   bool vis[100005];   long long siz, edges;   void dfs(long long i) {     vis[i] = 1;     for (long long j = 0; j < adj[i].size(); j++) {       edges++;       if (!vis[adj[i][j]]) dfs(adj[i][j]);     }   }   long long mpow(long long base, long long exp) {     base %= 1000000007;     long long result = 1;     while (exp > 0) {       if (exp & 1) result = ((long long)result * base) % 1000000007;       base = ((long long)base * base) % 1000000007;       exp >>= 1;     }     return result;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long n, sum = 0, t = 1, m, ans;     while (t--) {       string s1, s =   ;       cin >> s1;       for (long long i = 0; i < s1.length(); i++)         if (s1[i] ==  a  || s1[i] ==  b ) s += s1[i];       n = s.length();       vector<long long> dp(n + 1, 1);       dp[0] = 1;       ans = 1;       for (long long i = 1; i < n + 1; i++) {         if (s[i - 1] ==  a )           dp[i] = dp[i - 1] + 1;         else {           dp[i] = 1;           ans = (ans * (dp[i - 1])) % 1000000007;         }       }       ans = (ans * dp[n]) % 1000000007;       cout << ans - 1 <<   n ;     }     cerr <<   nTime elapsed:   << 1.0 * clock() / CLOCKS_PER_SEC <<   s. n ;     ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v, v1;     int a, b, c, d, e, f, g, h, i, j, k, l;     cin >> a;     for (i = 0; i < a; i++) {       v.clear();       v1.clear();       cin >> c >> d >> b;       map<int, int> m;       for (j = 0; j < b; j++) {         cin >> e;         m[e]++;         v.push_back(e);       }       f = 0;       g = -1;       h = -1;       int min1 = INT_MAX;       for (j = 0; j < v.size(); j++) {         for (k = d; k <= c; k++) {           if (!m.count(k)) {             min1 = min(k - d, min1);             break;           }         }         for (k = d; k >= 1; k--) {           if (!m.count(k)) {             min1 = min(d - k, min1);             break;           }         }       }       cout << min1 << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   string s;   int main() {     ios_base::sync_with_stdio(false);     cin >> t;     while (t--) {       cin >> s;       int mask = 0;       n = s.size();       int ok100001 = (s[0] ==  1 );       for (int i = 1; i + 1 < n; ++i) ok100001 &= (s[i] ==  0 );       ok100001 &= (s.back() <=  1 );       if (ok100001) {         for (int i = 0; i < n - 2; ++i) cout << 9;         cout <<   n ;         continue;       }       for (int i = 0; i < n; ++i) mask ^= 1 << (s[i] - 48);       for (int i = n - 1; i >= 0; --i) {         mask ^= 1 << (s[i] - 48);         if (s[i] ==  0 ) continue;         int popcnt = __builtin_popcount(mask);         if (popcnt > n - i) continue;         if (popcnt % 2 != (n - i) % 2) continue;         if (popcnt < n - i ||             (popcnt == n - i && __builtin_ctz(mask) < s[i] - 48)) {           int curdigit = s[i] - 48 - 1;           if (popcnt == n - i)             for (; curdigit >= 0; --curdigit)               if (mask & (1 << curdigit)) break;           s[i] = curdigit +  0 ;           mask ^= 1 << curdigit;           for (int j = i + 1; j < n; ++j) {             curdigit = 9;             if (__builtin_popcount(mask) == n - j)               for (; curdigit >= 0; --curdigit)                 if (mask & (1 << curdigit)) break;             s[j] = curdigit +  0 ;             mask ^= 1 << curdigit;           }           break;         }       }       cout << s <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long a[30], b[30], dp[30][30][30];   struct node {     long long dis[30][30];     node operator*(const node &t) const {       node rep;       memset(rep.dis, 0x3f, sizeof rep.dis);       for (int i = 0; i <= n; i++)         for (int j = 0; j <= n; j++)           for (int k = 0; k <= n; k++)             rep.dis[i][j] = min(rep.dis[i][j], dis[i][k] + t.dis[k][j]);       return rep;     }   } key;   node pow(node rep, int n) {     if (n == 1) return rep;     node req = pow(rep, n / 2);     if (n % 2 == 0) return req * req;     return req * req * rep;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %d , &b[i]);     memset(dp, 0x3f, sizeof dp);     for (int i = 0; i <= n; i++) dp[i][i][0] = 0;     for (int k = 1; k <= n; k++)       for (int i = 0; i <= n; i++)         for (int j = 0; j <= n; j++) {           if (j - 1 >= 0)             dp[i][j][k] = min(dp[i][j][k], dp[i][j - 1][k - 1] + a[k]);           if (j + 1 <= n)             dp[i][j][k] = min(dp[i][j][k], dp[i][j + 1][k - 1] + b[k]);         }     for (int i = 0; i <= n; i++)       for (int j = 0; j <= n; j++) key.dis[i][j] = dp[i][j][n];     key = pow(key, m);     printf( %d n , key.dis[0][0]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, p = 0, q = 0;     cin >> n;     string str;     cin >> str;     for (int i = 0; i < n; i++) {       if (str[i] ==  F  && str[i + 1] ==  S ) p = p + 1;       if (str[i] ==  S  && str[i + 1] ==  F ) q = q + 1;     }     if (q > p)       cout <<  YES ;     else       cout <<  NO ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 502;   pair<int, pair<int, int> > dp[N][N];   int a[N];   int b[N];   map<int, int> a_val_to_pos;   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n; ++i) cin >> a[i];     cin >> m;     for (int i = 0; i < m; ++i) cin >> b[i];     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j) {         if (b[j] == a[i]) {           dp[i][j].first = 1;           dp[i][j].second.first = -1;           dp[i][j].second.second = -1;           for (int k = j - 1; k >= 0; --k) {             if (b[k] < b[j]) {               if ((a_val_to_pos.find(b[k]) != a_val_to_pos.end()) &&                   dp[a_val_to_pos[b[k]]][k].first + 1 > dp[i][j].first) {                 dp[i][j].first = dp[a_val_to_pos[b[k]]][k].first + 1;                 dp[i][j].second.first = a_val_to_pos[b[k]];                 dp[i][j].second.second = k;               }             }           }         } else {           dp[i][j].first = 0;           dp[i][j].second.first = -1;           dp[i][j].second.second = -1;         }       }       a_val_to_pos[a[i]] = i;     }     int ans_i = -1, ans_j = -1, mx = 0;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < m; ++j)         if (dp[i][j].first > mx) {           mx = dp[i][j].first;           ans_i = i;           ans_j = j;         }     }     vector<int> ans;     cout << mx << endl;     if (mx > 0) {       for (;;) {         ans.push_back(b[ans_j]);         if (dp[ans_i][ans_j].second.first != -1) {           int tmp = ans_i;           ans_i = dp[tmp][ans_j].second.first;           ans_j = dp[tmp][ans_j].second.second;         } else {           break;         }       }       reverse(ans.begin(), ans.end());       for (int i = 0; i < ans.size(); ++i) cout << ans[i] <<    ;       cout << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using pii = pair<int, int>;   using pll = pair<long long, long long>;   using pcc = pair<char, char>;   using pdd = pair<double, double>;   using vi = vector<int>;   using vs = vector<string>;   using vll = vector<ll>;   using vpii = vector<pii>;   using vc = vector<char>;   using vd = vector<double>;   ll POW(ll a, ll b) {     if (b == 0) return 1;     ll x = POW(a, b / 2);     x = (x * x);     if (b & 1) x = (x * a);     return x;   }   int main(int argc, char* argv[]) {     ll n, a, b;     scanf( %lld%*c , &(n));     while (n--) {       scanf( %lld%*c , &(a)), scanf( %lld%*c , &(b));       int aa[100]{0}, bb[100]{0}, i;       ll ans{0}, bbb = b;       for (i = 0; i < 100; i++) {         aa[i] = a % 2;         a /= 2;         bb[i] = b % 2;         b /= 2;       }       for (i = 99; i >= 0; i--) {         if (bb[i]) {           if (!aa[i]) {             ans += POW(2, i) - 1;             if (ans + POW(2, i) <= bbb) ans += POW(2, i);             break;           } else             ans += POW(2, i);         }       }       printf( %lld , (ans)), printf(  n );     }     return 0;   }
#include <bits/stdc++.h>   int v[1000001];   using namespace std;   int main() {     int a, b, c, d;     scanf( %d%d%d%d , &a, &b, &c, &d);     while (b <= 1000000) {       v[b] = 1;       b += a;     }     while (d <= 1000000) {       if (v[d] == 1) {         printf( %d , d);         return 0;       }       d += c;     }     printf( -1 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     double t = 0;     cin >> n;     int i, a[n], b[n];     for (i = 0; i < n; i++) cin >> a[i];     sort(a, a + n);     for (i = 0; i < n; i++) {       b[i] = a[n - 1 - i];     }     for (i = n - 1; i >= 0; i--) {       if (i % 2 == 0)         t += (b[i] * b[i]);       else         t -= (b[i] * b[i]);     }     t *= 3.141592653589793;     printf( %.15f , t);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5 * 1e5 + 1;   long long n, a[N], sum[N], s, f, ans;   int32_t main() {     ios_base ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (long long i = 0; i < n; i++) {       cin >> a[i];       if (i)         sum[i] = sum[i - 1] + a[i];       else         sum[i] = a[i];     }     if (sum[n - 1] % 3) return cout <<  0 n , 0;     s = sum[n - 1] / 3;     if (!s) {       for (long long i = 0; i < n - 1; i++) {         if (!sum[i]) f++;       }       cout << f * (f - 1) / 2 <<   n ;       return 0;     }     for (long long i = 0; i < n - 1; i++) {       if (sum[i] == s)         f++;       else if (sum[i] == s * 2)         ans += f;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void run() {     long long n;     cin >> n;     long long p[n];     for (long long i = 0; i < n; i++) cin >> p[i];     for (long long i = 0; i < n; i++) {       if (p[i] == 0) p[i] = -1;       if (p[i] != -1) p[i] %= 2;     }     long long ones = 0, zeros = 0;     for (long long i = 1; i <= n; i++) {       if (i % 2)         ones++;       else         zeros++;     }     for (long long i = 0; i < n; i++) {       if (p[i] == 0)         zeros--;       else if (p[i] == 1)         ones--;     }     long long dp[n][zeros + 1][ones + 1][2];     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < zeros + 1; j++) {         for (long long k = 0; k < ones + 1; k++) {           for (long long l = 0; l < 2; l++) dp[i][j][k][l] = 1e9;         }       }     }     if (p[0] != -1)       dp[0][0][0][p[0]] = 0;     else {       dp[0][1][0][0] = 0;       dp[0][0][1][1] = 0;     }     for (long long i = 1; i < n; i++) {       for (long long j = 0; j < zeros + 1; j++) {         for (long long k = 0; k < ones + 1; k++) {           if (p[i] == -1) {             if (j + 1 <= zeros)               dp[i][j + 1][k][0] =                   min(dp[i - 1][j][k][0], dp[i - 1][j][k][1] + 1);             if (k + 1 <= ones)               dp[i][j][k + 1][1] =                   min(dp[i - 1][j][k][1], dp[i - 1][j][k][0] + 1);           } else             dp[i][j][k][p[i]] =                 min(dp[i - 1][j][k][p[i]], dp[i - 1][j][k][1 - p[i]] + 1);         }       }     }     cout << min(dp[n - 1][zeros][ones][0], dp[n - 1][zeros][ones][1]);   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     ;     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void _do(T x) {     cerr << x <<   n ;   }   template <typename T, typename... U>   void _do(T x, U... y) {     cerr << x <<  ,  ;     _do(y...);   }   const int MOD1 = 1e9 + 7;   const int MOD2 = 998244353;   const long long INF = 2e18;   const long double PI = 3.14159265358979323846;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long fpow(long long a, long long b, long long m) {     if (!b) return 1;     long long ans = fpow(a * a % m, b / 2, m);     return (b % 2 ? ans * a % m : ans);   }   long long inv(long long a, long long m) { return fpow(a, m - 2, m); }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     string s;     cin >> s;     long long n = s.size();     string ans(n,  0 );     while (1) {       long long id = -1;       bool x = 0;       for (long long i = 0; i < n; i++) {         if (s[i] ==  0  && id != -1) {           ans[id] =  1 , ans[i] =  0 ;           s[id] = s[i] =  x ;           id = -1, x = 1;         }         if (s[i] ==  1 ) id = i;       }       if (!x) break;     }     cout << ans;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( sse4 )   using namespace std;   const long long MX = 2e5 + 5;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long double PI = acos((long double)-1);   const long long xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};   mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   constexpr long long pct(long long x) { return __builtin_popcount(x); }   constexpr long long bits(long long x) { return 31 - __builtin_clz(x); }   template <class T>   T cdiv(T a, T b) {     return a / b + !(a < 0 || a % b == 0);   }   long long fstTrue(function<bool(long long)> first, long long lo, long long hi) {     hi++;     assert(lo <= hi);     while (lo < hi) {       long long mid = (lo + hi) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   template <class T>   void remDup(vector<T>& v) {     sort(begin(v), end(v));     v.erase(unique(begin(v), end(v)), end(v));   }   void DBG() { cerr <<  ]  << endl; }   template <class H, class... T>   void DBG(H h, T... t) {     cerr << h;     if (sizeof...(t)) cerr <<  ,  ;     DBG(t...);   }   void setIn(string S) { freopen(S.c_str(),  r , stdin); }   void setOut(string S) { freopen(S.c_str(),  w , stdout); }   void setIO(string S =   ) {     ios_base::sync_with_stdio(0);     cin.tie(0);     if ((long long)(S).size()) {       setIn(S +  .in ), setOut(S +  .out );     }   }   int32_t main() {     setIO();     long long n;     cin >> n;     vector<long long> arr(n);     for (auto& x : arr) cin >> x;     if (n == 1) {       for (long long i = (0); i < (3); ++i) {         cout << 1 <<     << 1 <<   n ;         cout << -arr[0] <<   n ;         arr[i] = 0;       }     } else {       cout << 1 <<     << 1 <<   n ;       cout << -arr[0] <<   n ;       cout << 2 <<     << n <<   n ;       for (long long i = (1); i < (n); ++i) cout << arr[i] * (n - 1) <<    ;       cout <<   n ;       cout << 1 <<     << n <<   n ;       cout << 0 <<    ;       for (long long i = (1); i < (n); ++i) cout << -arr[i] * n <<    ;       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double PI = acos(-1.0);   double fRand(double fMin, double fMax) {     double f = (double)rand() / RAND_MAX;     return fMin + f * (fMax - fMin);   }   template <class T>   T min(T a, T b, T c) {     return min(a, min(b, c));   }   template <class T>   T max(T a, T b, T c) {     return max(a, max(b, c));   }   long long power(long long x, int n) {     if (n == 0) return 1;     if (n & 1) return (x * power(x, n - 1)) % 1000000007;     long long p = power(x, n / 2);     return (p * p) % 1000000007;   }   int n, a[1000005];   long long fact[1000005], invFact[1000005];   long long C(long long n, long long k) {     return ((fact[n] * invFact[k] % 1000000007) * invFact[n - k]) % 1000000007;   }   int main() {     scanf( %d , &n);     for (int u = (1); u <= (n); ++u) scanf( %d , &a[u]);     fact[0] = invFact[0] = 1;     for (int i = (1); i <= (1000005 - 1); ++i)       fact[i] = (fact[i - 1] * i) % 1000000007;     invFact[1000005 - 1] = power(fact[1000005 - 1], 1000000007 - 2);     for (int i = (1000005 - 2); i >= (1); --i)       invFact[i] = (invFact[i + 1] * (i + 1)) % 1000000007;     sort(a + 1, a + n + 1);     int j = n, ans = 0;     for (int i = (n); i >= (1); --i) {       while (j > 0 && a[j] >= a[i]) --j;       if (a[i] != a[n]) {         int k = n - j - 1;         long long x =             ((C(n, k + 1) * fact[k]) % 1000000007 * fact[n - k - 1]) % 1000000007;         ans = (ans + a[i] * x) % 1000000007;       }     }     printf( %d , ans);     return 0;   }
#include <bits/stdc++.h>   void _print(int *a, int n) {}   using namespace std;   const int N = 300;   int n, m;   int a[N][N], h[N], v[N];   int ans[N][N];   signed main() {     scanf( %d , &n), scanf( %d , &m);     for (int i = (0); i < (n); ++i)       for (int j = (0); j < (m); ++j) {         scanf( %d , &a[i][j]);         h[i] = max(h[i], a[i][j]);         v[j] = max(v[j], a[i][j]);       }     sort(h, h + n, greater<int>());     sort(v, v + m, greater<int>());     int ph = 0, pv = 0;     queue<pair<int, int> > q;     for (int i = (n * m + 1) - 1; i >= (1); --i) {       if (ph < n && i == h[ph + 1]) ph++;       if (pv < m && i == v[pv + 1]) pv++;       if (i == h[ph] || i == v[pv]) {         ans[ph][pv] = i;         if (i == h[ph])           for (int i = (pv)-1; i >= (0); --i) q.push(make_pair(ph, i));         if (i == v[pv])           for (int i = (ph)-1; i >= (0); --i) q.push(make_pair(i, pv));       } else {         pair<int, int> p = q.front();         q.pop();         ans[p.first][p.second] = i;       }     }     for (int i = (0); i < (n); ++i) {       for (int _ = (0); _ < (m); ++_)         printf( %d%c , ans[i][_],    n [_ == m - 1]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, sum = 0, l = -99999999, r = 99999999;     scanf( %d , &n);     for (int i = 0; i < n; ++i) {       int rat, div;       scanf( %d , &rat), scanf( %d , &div);       if (div == 1)         l = max(l, 1900 - sum);       else         r = min(r, 1899 - sum);       sum += rat;     }     if (r >= 99999999)       cout <<  Infinity n ;     else if (l > r)       cout <<  Impossible n ;     else       cout << sum + r <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int r[105];     int i;     double pi = acos(-1.0);     for (i = 0; i < n; i++) {       cin >> r[i];     }     sort(r, r + n);     int s = 0;     for (i = 0; i < n; i++) {       s = r[i] * r[i] - s;     }     printf( %.6lf n , s * pi);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     int64_t t;     cin >> t;     vector<int64_t> ans;     map<int64_t, int64_t> m;     for (int64_t i = 0; i < t; i++) {       m[0] = 0;       m[1] = 0;       m[2] = 0;       int64_t n;       cin >> n;       for (int64_t j = 0; j < n; j++) {         int64_t u;         cin >> u;         m[u % 3]++;       }       ans.push_back(           max(m[0] + min(m[1], m[2]) + (m[1] - min(m[1], m[2])) / 3 +                   (m[2] - min(m[1], m[2])) / 3,               m[0] + m[1] / 3 + m[2] / 3 +                   min(m[1] % 3, (int64_t)1) * min(m[2] % 3, (int64_t)1)));     }     for (int64_t a : ans) cout << a << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int mxN = 2e5;   const int MOD = 1e9 + 7;   template <typename ForwardIterator, typename T>   ForwardIterator first_less_than(ForwardIterator first, ForwardIterator last,                                   T value) {     auto it = std::lower_bound(first, last, value);     return (it == first ? last : --it);   }   bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {     return (a.second < b.second);   }   bool check(char ch) {     if (ch ==  a  || ch ==  e  || ch ==  i  || ch ==  o  || ch ==  u )       return true;     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long t;     t = 1;     while (t--) {       long long n, i, j, k;       string s, t;       cin >> s >> t;       if (s.size() != t.size()) {         cout <<  NO               <<   n ;         continue;       }       bool ok = true;       for (i = 0; i < s.size(); i++) {         bool f1 = check(s[i]);         bool f2 = check(t[i]);         if (f1 && !f2 || f2 && !f1) ok = false;       }       if (ok)         cout <<  YES               <<   n ;       else         cout <<  NO               <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   const int mn = 1e5 + 1;   ll n, d, a[mn], b[mn], ans = 1, cnt = 1, pos = 1, ansid[mn];   struct pairs {     int val, id;     pairs operator+(pairs A) { return (pairs){val + A.val, id + A.id}; }   } tree[mn * 4], f[mn];   pairs maxp(pairs A, pairs B) {     if (A.val == B.val) {       if (A.id > B.id) return A;       return B;     }     if (A.val < B.val) return B;     return A;   }   void update(int l, int r, int id, int x, pairs p) {     if (l > x || x > r) return;     if (l == r) {       tree[id] = p;       return;     }     int mid = (l + r) / 2;     update(l, mid, id * 2, x, p);     update(mid + 1, r, id * 2 + 1, x, p);     tree[id] = maxp(tree[id * 2], tree[id * 2 + 1]);   }   pairs get(int l, int r, int id, int x, int y) {     if (l > y || x > r) return (pairs){0, 0};     if (x <= l && r <= y) return tree[id];     int mid = (l + r) / 2;     return maxp(get(l, mid, id * 2, x, y), get(mid + 1, r, id * 2 + 1, x, y));   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> d;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; ++i) {       int u = upper_bound(b + 1, b + n + 1, a[i] - d) - b - 1;       int v = lower_bound(b + 1, b + n + 1, a[i] + d) - b;       int k = lower_bound(b + 1, b + n + 1, a[i]) - b;       if (u) f[i] = maxp(f[i], get(1, n, 1, 1, u) + (pairs){1, 0});       if (v <= n) f[i] = maxp(f[i], get(1, n, 1, v, n) + (pairs){1, 0});       f[i] = maxp(f[i], (pairs){1, i});       update(1, n, 1, k, (pairs){f[i].val, i});       if (ans < f[i].val) {         ans = f[i].val;         pos = i;       }     }     cout << ans <<   n ;     ansid[ans] = pos, cnt = ans - 1;     while (cnt) ansid[cnt--] = f[ansid[cnt + 1]].id;     for (int i = 1; i <= ans; ++i) cout << ansid[i] <<    ;     cout <<   n ;     return 0;   }