malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int tem;   int main() {     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       int arr[n];       for (int i = 0; i < n; i++) scanf( %d , &arr[i]);       int flag = 1;       for (int i = 0; i < n - 1; i++) {         if (abs(arr[i] - arr[i + 1]) > 1) {           printf( YES n%d %d n , i + 1, i + 2);           flag = 0;           break;         }       }       if (flag) printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   void lire_input() { freopen( input.txt ,  r , stdin); }   void ecrire_output() { freopen( output.txt ,  w , stdout); }   using namespace std;   int main() {     int n;     cin >> n;     if (n % 2 == 1) {       for (int i = 0; i < n; i++) {         printf( %d  , i);       }       printf(  n );       for (int i = 1; i <= n; i++) {         if (i != n)           printf( %d  , i);         else           printf( %d  , 0);       }       printf(  n );       for (int i = 0; i < n; i++) {         if (i != n)           printf( %d  , (2 * i + 1) % n);         else           printf( %d  , i % n);       }     } else       cout <<  -1 ;     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool posible(int a, int b, int a2, int b2) {     if ((a + a2 == b && b == b2) || (a + b2 == b && b == a2) ||         (b + b2 == a && a == a2) || (b + a2 == a && a == b2)) {       return true;     }     return false;   }   int main() {     int t;     cin >> t;     for (int i = 0; i < t; i++) {       int a, b, a2, b2;       cin >> a >> b >> a2 >> b2;       if (posible(a, b, a2, b2)) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, p, last[10];   struct node {     int x, y;   };   int s[10];   char a[1005][1005];   int vis[1005][1005], ans[10], can[10];   queue<node> que[10];   int d[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};   void bfs() {     for (int i = 1; i <= p; i++) {       while (!que[i].empty()) que[i].pop();     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         if (a[i][j] !=  .  && a[i][j] !=  # ) {           que[a[i][j] -  0 ].push({i, j});           vis[i][j] = a[i][j] -  0 ;           last[a[i][j] -  0 ]++;         }       }     }     bool flag = true;     while (flag) {       flag = false;       for (int idx = 1; idx <= p; idx++) {         for (int ss = 1; ss <= s[idx] && can[idx] == 0; ss++) {           int num = last[idx];           last[idx] = 0;           for (int t = 1; t <= num; t++) {             node now = que[idx].front();             que[idx].pop();             ans[idx]++;             for (int i = 0; i < 4; i++) {               int xx = now.x + d[i][0], yy = now.y + d[i][1];               if (xx >= 0 && xx < n && yy >= 0 && yy < m && vis[xx][yy] == 0 &&                   a[xx][yy] ==  . ) {                 que[idx].push({xx, yy});                 vis[xx][yy] = idx;                 last[idx]++;               }             }           }           if (que[idx].empty()) can[idx] = idx;         }       }       for (int i = 1; i <= p; i++)         if (!que[i].empty()) flag = true;     }     for (int i = 1; i <= p; i++) printf( %d  , ans[i]);     printf(  n );   }   int main() {     while (scanf( %d %d %d , &n, &m, &p) != EOF) {       memset(a, 0, sizeof(a));       memset(s, 0, sizeof(s));       memset(ans, 0, sizeof(ans));       memset(vis, 0, sizeof(vis));       memset(last, 0, sizeof(last));       memset(can, 0, sizeof(can));       for (int i = 1; i <= p; i++) scanf( %d , &s[i]);       getchar();       for (int i = 0; i < n; i++) scanf( %s , a[i]);       bfs();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   const int inf = 1e9;   int main() {     long long n, m, grt = 0, eq = 0, less = 0, i;     cin >> n >> m;     for (i = 0; i < n; i++) {       long long temp;       cin >> temp;       if (temp == m)         eq++;       else if (temp < m)         less++;       else         grt++;     }     long long ans = 0, tot;     if (eq == 0) {       eq++;       ans++;     }     tot = less + eq + grt;     long long temp = (tot + 1) / 2;     if (less + eq < temp) {       ans += grt - less - eq;       less += grt - less - eq;     } else if (tot - (grt + eq) > temp) {       ans += less - eq - grt;       grt += less - eq - grt;     }     tot = less + eq + grt;     temp = (tot + 1) / 2;     if (less == temp) ans++;     if (grt == tot - temp + 1) ans++;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool prime(int n) {     for (int i = 2; i * i <= n; i++) {       if (n % i == 0) return false;     }     return true;   }   int main() {     int n;     cin >> n;     if (prime(n)) {       cout << 1 <<   n  << n << endl;       return 0;     }     if (prime(n - 2)) {       cout << 2 <<   n  << 2 <<   n  << n - 2 << endl;       return 0;     }     cout << 3 <<   n  << 3 << endl;     n -= 3;     for (int i = 2; i <= n; i++) {       if (prime(i) and prime(n - i)) {         cout << i <<   n  << n - i << endl;         break;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, a[300];   double p[300], d[202][202][402], ans;   int main() {     scanf( %d%d%d , &n, &m, &k);     for (int i = 1; i <= n; ++i) {       scanf( %lf , &p[i]);       p[i] /= 100;     }     for (int i = 1; i <= n; ++i) {       scanf( %d , &a[i]);     }     if (k >= n) k = n;     d[0][0][k + n] = 1;     for (int i = 0; i < n; ++i) {       for (int j = 0; j < n; ++j) {         for (int l = 0; l <= 2 * n; ++l) {           if (a[i + 1] != -1) {             d[i + 1][j + 1][min(2 * n, l + a[i + 1])] += d[i][j][l] * p[i + 1];             d[i + 1][j][l] += d[i][j][l] * (1 - p[i + 1]);           }           if (a[i + 1] == -1) {             if (l > 0) d[i + 1][j + 1][l - 1] += d[i][j][l] * p[i + 1];             d[i + 1][j][l] += d[i][j][l] * (1 - p[i + 1]);           }         }       }     }     for (int i = n; i <= n; ++i) {       for (int j = m; j <= n; ++j)         for (int l = n; l <= 2 * n; ++l) {           ans += d[i][j][l];         }     }     printf( %.9lf , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using ii = pair<ll, ll>;   using vi = vector<ll>;   using vb = vector<bool>;   using vvi = vector<vi>;   using vii = vector<ii>;   using vvii = vector<vii>;   const int INF = 2000000000;   const ll LLINF = 9000000000000000000;   int main() {     int N;     scanf( %d , &N);     vi A(N, 0LL), B(N, 0LL);     for (int i = 0; i < N; ++i) {       int v;       scanf( %d , &v);       A[i] = ll(v);       B[i] = A[i] + (i > 0 ? B[i - 1] : 0LL);     }     ll mx = 0LL;     for (int i = 0; i < N; ++i) mx += ll(i + 1) * A[i];     vii lns;     vector<ld> start(1, -std::numeric_limits<ld>::infinity());     lns.push_back({0, 0});     for (int i = 0; i < N; ++i) {       while (lns.size() > 1 && start.back() >= ld(-B[i] - lns.back().second) /                                                    ld(lns.back().first - i - 1)) {         lns.pop_back();         start.pop_back();       }       start.push_back(ld(-B[i] - lns.back().second) /                       ld(lns.back().first - i - 1));       lns.push_back({i + 1, -B[i]});     }     ll bestchange = 0LL;     int D = 5;     for (int i = 0; i < N; ++i) {       ll change = B[i] - A[i] * ll(i + 1);       int l = 0, r = int(lns.size()) - 1;       while (l < r) {         int m = (l + r + 1) / 2;         if (start[m] > A[i])           r = m - 1;         else           l = m;       }       for (int j = max(0, l - D); j < min(int(lns.size()), l + D + 1); ++j) {         if (bestchange < change + A[i] * lns[j].first + lns[j].second) {           bestchange = change + A[i] * lns[j].first + lns[j].second;         }       }     }     cout << (mx + bestchange) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(vector<T> &a, long long n) {     T x;     a.clear();     for (long long i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }   }   template <class T>   void write(vector<T> &a) {     for (T x : a) cout << x <<    ;     cout << endl;   }   const int N = 300005;   const int S = 500;   long long sum[S][S];   long long ans[N];   vector<pair<pair<int, int>, int> > q;   int n, m;   int w[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> w[i];     cin >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       q.push_back(make_pair(make_pair(a, b), i));     }     sort(q.begin(), q.end());     reverse(q.begin(), q.end());     int pos = n;     for (int i = 0; i < q.size(); i++) {       int a = q[i].first.first;       int b = q[i].first.second;       int id = q[i].second;       while (pos >= a) {         for (int j = 1; j < S; j++) sum[j][pos % j] += w[pos];         pos--;       }       if (b < S)         ans[id] = sum[b][a % b];       else {         long long res = 0;         for (int j = a; j <= n; j += b) res += w[j];         ans[id] = res;       }     }     for (int i = 0; i < m; i++) cout << ans[i] << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     map<int, int> mp1, mp2;     map<int, int>::iterator it;     for (int i = 0; i < n; i++) {       int a, b;       cin >> a >> b;       mp1[a] = b;     }     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       if (mp1.find(a) != mp1.end()) {         it = mp1.find(a);         if (it->second > b) {           continue;         } else {           mp1.erase(it);           mp2[a] = b;         }       } else {         mp2[a] = b;       }     }     long long sum = 0;     it = mp1.begin();     while (it != mp1.end()) {       sum += it->second;       it++;     }     it = mp2.begin();     while (it != mp2.end()) {       sum += it->second;       it++;     }     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long test(long long k) {     long long a[] = {-1, 1, k + 2};     int c = -1;     long long cur = 0, res = 0;     for (int i = 0; i < 3; i++) {       cur += a[i];       if (cur < 0) {         cur = 0;         c = i;       }       res = max(res, (i - c) * cur);     }     return res;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long k;     cin >> k;     int a = k + 2000;     cout << 2000 << endl << -1 <<    ;     for (int i = 1; i < 2000; i++) {       cout << min(a, (int)1e6) <<    ;       a -= min(a, (int)1e6);     }     return 0;   }
#include <bits/stdc++.h>   #define task  suffixarray    #define ll long long   #define FOR( i, l, r) for(int i = (l), _r = (r); i <= _r; ++i)   #define FOD( i, l, r) for(int i = (l), _r = (r); i >= _r; --i)   #define REP( i, n)    for(int i = 0, _n = (n); i < _n; ++i)   #define pii pair<int,int>   #define fi  first   #define se  second   #define MASK(x)  (1ll << (x))   #define BIT(x,k) (((x) >> (k)) & 1ll)   #define OFF(x,k) ((x) & ~(1ll << (k)))   #define ON(x,k)  ((1ll << (k)) | (x))   #define endl   n    #define __builtin_popcount __builtin_popcountll   /*    Author: Diem Quynh :>> //d_quynh_2811   */   using namespace std;   int const N = 4e5 + 5;   int const mod = 998244353;   int n, k, a[N], idx[N], fact[N], ifact[N];   int num = 1, ans;   void inp()   {       cin >> n >> k;       FOR( i, 1, n)       {           cin >> a[i];           ++a[i];           idx[a[i]] = i;       }   }   int Pow(int a, int b)   {       if(b == 0)           return 1;       int tmp = Pow(a, b / 2);       if(b & 2)           return (1ll * tmp * tmp) % mod * a % mod;       return 1ll * tmp * tmp % mod;   }   int nCk(int n, int k)   {       return 1ll * fact[n] * ifact[k] % mod * ifact[n - k] % mod;   }   void solve()   {       FOR( i, 1, n - 1) k += idx[a[i] + 1] < idx[a[i + 1] + 1];       if(n > k)       {           cout << 0;           return;       }       fact[0] = 1;       FOR( i, 1, k) fact[i] = (1ll * fact[i - 1] * i) % mod;       ifact[k] = Pow(fact[k], mod - 2);       FOD( i, k - 1, 0) ifact[i] = 1ll * (i + 1) * ifact[i + 1] % mod;       cout << nCk(k, n);   }   int main()   {       ios_base::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);   //    freopen(task .inp , r ,stdin);   //    freopen(task .out , w ,stdout);       inp();       solve();       return 0;   }
#include <bits/stdc++.h>   int main() {     int arr[1000], n, i, j, k, counter = 99999999, x, y;     scanf( %d , &n);     for (i = 0; i < n; ++i) {       scanf( %d , &arr[i]);     }     for (j = 1; j < n; ++j) {       for (k = j - 1; k < j; ++k) {         if (abs(arr[j] - arr[k]) < counter) {           counter = abs(arr[j] - arr[k]);           x = j + 1;           y = k + 1;         }       }     }     if (abs(arr[0] - arr[n - 1]) < counter) {       counter = abs(arr[0] - arr[n - 1]);       x = 1;       y = n;     }     printf( %d %d , y, x);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   const int eps = -1e6;   const int MAX = 200010;   long long int n, k, x;   long long int a[MAX], pre[MAX], s[MAX];   long long int expo(long long int a, long long int b) {     long long int x = 1, y = a;     while (b > 0) {       if (b & 1) x = (x * y);       y = (y * y);       b >>= 1;     }     return x;   }   int main() {     ios_base::sync_with_stdio(0);     cin >> n >> k >> x;     for (int i = 0, _n = (n); i < _n; ++i) {       cin >> a[i];       if (i == 0)         pre[i] = a[i];       else         pre[i] = pre[i - 1] | a[i];     }     for (int i = n - 1; i >= 0; i--) {       if (i == n - 1)         s[i] = a[i];       else         s[i] = s[i + 1] | a[i];     }     long long int tmp = expo(x, k);     long long int res = 0;     for (int i = 0, _n = (n); i < _n; ++i) {       long long int z = a[i] * 1ll * tmp;       if (i == 0)         res = max(res, z | s[1]);       else if (i == n - 1)         res = max(res, pre[n - 2] | z);       else         res = max(res, pre[i - 1] | z | s[i + 1]);     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[100000];   int pre[100000];   int leftMax;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     ;     int t;     cin >> t;     while (t--) {       int maxLen = 0;       int n, x;       cin >> n >> x;       for (int i = 0; i < n; i++) cin >> arr[i];       pre[0] = arr[0];       for (int i = 1; i < n; i++) pre[i] = arr[i] + pre[i - 1];       leftMax = -1;       for (int i = 0; i < n; i++) {         pre[i] = pre[i] % x;         if (pre[i] != 0) maxLen = i + 1;         if (pre[i] != 0 && leftMax == -1) leftMax = i;       }       if (maxLen == 0)         cout <<  -1 n ;       else {         int finalLen = maxLen;         for (int i = 0; i < n; i++) {           if (pre[i] == 0)             finalLen = max(finalLen, max(abs(i - leftMax), abs(i - maxLen)));         }         cout << finalLen <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct cmp {     bool operator()(long long a, long long b) { return a > b; }   };   multiset<long long> mex, msy;   multiset<long long, cmp> msx, mey;   int main() {     long long n;     cin >> n;     long long sx[n], ex[n], sy[n], ey[n];     for (long long i = 0; i < n; i++) {       cin >> sx[i] >> ey[i] >> ex[i] >> sy[i];       msx.insert(sx[i]);       mex.insert(ex[i]);       msy.insert(sy[i]);       mey.insert(ey[i]);     }     for (long long i = 0; i < n; i++) {       msx.erase(msx.find(sx[i]));       mex.erase(mex.find(ex[i]));       msy.erase(msy.find(sy[i]));       mey.erase(mey.find(ey[i]));       if (*msx.begin() <= *mex.begin() && *msy.begin() >= *mey.begin()) {         cout << *msx.begin() <<     << *msy.begin() << endl;         return 0;       }       msx.insert(sx[i]);       mex.insert(ex[i]);       msy.insert(sy[i]);       mey.insert(ey[i]);     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     pair<int, int> cc[105];     for (int i = 1; i <= m; i++) {       int a, b, c, d;       cin >> a >> b >> c >> d;       for (int j = a; j <= b; j++) {         if (!cc[j].first || c < cc[j].first) {           cc[j].first = c;           cc[j].second = d;         }       }     }     int ans = 0;     for (int i = 1; i <= n; i++) ans += cc[i].second;     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   long long n, m;   long long q_pow(long long a, long long b, long long c) {     if (b == 0) return 1;     long long ret = q_pow(a, b / 2, c);     ret = (ret * ret) % c;     if (b & 1) ret = (ret * a) % c;     return ret;   }   int main() {     scanf( %d%d , &n, &m);     long long ans = (q_pow(3, n, m) + m - 1) % m;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const char nl =   n ;   const int mod = 1000000007;   const double pi = 4 * atan(1);   const int inf = 2000000000;   const long long linf = (long long)1e18;   const int pr = 37;   const int maxn = 1000001;   const int maxn_big = 1000001;   string s;   vector<int> v;   unsigned long long h[maxn], p[maxn];   unsigned long long get_hash(int l, int r) {     int len = (r - l) + 1;     if (!l) return h[r];     return h[r] - h[l - 1] * p[len];   }   bool check(int pf) {     unsigned long long pref_hash = get_hash(0, pf);     bool has_ans = 0;     for (int i = 1; i < ((int)(s.size())) - 1; ++i) {       int r = i + pf;       if (r >= ((int)(s.size())) - 1) break;       if (get_hash(i, r) == pref_hash) {         has_ans = 1;         break;       }     }     return has_ans;   }   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     srand(time(NULL));     cin >> s;     h[0] = s[0];     p[0] = 1;     for (int i = 1; i < ((int)(s.size())); ++i) {       h[i] = h[i - 1] * pr + s[i];       p[i] = p[i - 1] * pr;     }     for (int i = 0; i < ((int)(s.size())); ++i) {       int l = ((int)(s.size())) - 1 - i;       if (get_hash(0, i) == get_hash(l, ((int)(s.size())) - 1)) v.push_back(i);     }     if (!((int)(v.size()))) {       cout <<  Just a legend ;       return 0;     }     int l = -1, r = ((int)(v.size()));     bool has = 0;     while (r - l > 1) {       int mid = (r + l) / 2;       if (check(v[mid])) {         l = mid;         has = 1;       } else {         r = mid;       }     }     if (!has) {       cout <<  Just a legend ;       return 0;     }     string res =   ;     for (int i = 0; i <= v[l]; ++i) res += s[i];     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 25;   int main(int argc, char *argv[]) {     long long n;     cin >> n;     long long ret1 = (1LL << 60);     long long ret2 = 0;     for (long long x = 1; x * x <= n; ++x) {       if (n % x) continue;       long long m = n / x;       for (long long y = 1; y * y <= m; ++y) {         if ((n / x) % y) continue;         long long z = m / y;         long long a = x + 1;         long long b = y + 2;         long long c = z + 2;         ret1 = min(a * b * c - n, ret1);         ret2 = max(a * b * c - n, ret2);         b = x + 2;         c = z + 2;         a = y + 1;         ret1 = min(a * b * c - n, ret1);         ret2 = max(a * b * c - n, ret2);         a = z + 1;         b = x + 2;         c = y + 2;         ret1 = min(a * b * c - n, ret1);         ret2 = max(a * b * c - n, ret2);       }     }     cout << ret1 <<     << ret2 <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma comment(linker,  /STACK:1000000000 )   using namespace std;   inline void solve();   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     solve();   }   string abc =  abcdefghijklmnopqrstuvwxyz ;   string ABC =  ABCDEFGHIJKLMNOPQRSTUVWXYZ ;   string digits =  0123456789 ;   void solve() {     vector<long long> ind[30];     string s;     cin >> s;     long long n = s.length();     for (long long i = 0; i < n; i++) ind[s[i] -  a ].push_back(i);     double ans = 0;     s = s + s;     long long p[30] = {0};     for (long long i = 0; i < 26; i++) {       for (long long len = 1; len < n; len++) {         long long c[30] = {0};         for (long long l = 0; l < ind[i].size(); l++) {           c[s[ind[i][l] + len] -  a ]++;         }         long long cnt = 0;         for (long long j = 0; j < 30; j++)           if (c[j] == 1) cnt++;         p[i] = max(p[i], cnt);       }       ans += p[i] * 1. / n;     }     cout << setprecision(15) << fixed << ans;   }
#include <bits/stdc++.h>   using namespace std;   void qmax(long long &x, long long y) {     if (x < y) x = y;   }   void qmin(long long &x, long long y) {     if (x > y) x = y;   }   inline long long read() {     char s;     long long k = 0, base = 1;     while ((s = getchar()) !=  -  && s != EOF && !(isdigit(s)))       ;     if (s == EOF) exit(0);     if (s ==  - ) base = -1, s = getchar();     while (isdigit(s)) {       k = k * 10 + (s ^  0 );       s = getchar();     }     return k * base;   }   inline void write(long long x) {     static char cnt, num[15];     cnt = 0;     if (!x) {       putchar( 0 );       return;     }     for (; x; x /= 10) num[++cnt] = x % 10;     for (; cnt; putchar(num[cnt--] + 48))       ;   }   const long long maxn = 100000 + 100;   long long n, d, b, d1;   long long a[maxn];   long long s1[maxn], s2[maxn];   signed main() {     n = read();     d = read();     b = read();     d1 = n / 2 * b;     for (long long i = 1; i <= n; i++) a[i] = read();     for (long long i = 1; i <= n; i++) {       s1[i] = min(a[i], d1) + s1[i - 1];       d1 -= min(d1, a[i]);     }     d1 = n / 2 * b;     for (long long i = n; i >= 1; i--) {       s2[i] = min(a[i], d1) + s2[i + 1];       d1 -= min(d1, a[i]);     }     d1 = 0;     long long R = n / 2, r = 0, ans1 = 0, ans2 = 0;     for (long long i = 1; i <= R; i++) {       r += d + 1;       r = min(n, r);       if (d1 + b <= s1[r])         d1 += b;       else         ans1++;     }     R = (n + 1) / 2 + 1;     d1 = 0;     r = 0;     long long l = n + 1;     for (long long i = n; i >= R; i--) {       l -= d + 1;       l = max(1ll, l);       if (d1 + b <= s2[l])         d1 += b;       else         ans2++;     }     cout << max(ans1, ans2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int t, n, d, x, y, javab1, javab2, ans[1000];     cin >> t;     for (int i = 0; i < t; i++) {       cin >> n >> x >> y >> d;       javab1 = javab2 = n;       if ((y - x) % d == 0) {         ans[i] = ((abs(y - x)) / d);       } else if ((y - 1) % d == 0 || (n - y) % d == 0) {         if ((n - y) % d == 0) {           javab1 = (n - x + d - 1) / d;           javab1 += (n - y) / d;         }         if ((y - 1) % d == 0) {           javab2 = (x - 1 + d - 1) / d;           javab2 += (y - 1) / d;         }         ans[i] = (min(javab2, javab1));       } else {         ans[i] = -1;       }     }     for (int i = 0; i < t; i++) {       cout << ans[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using gg = long long;   constexpr gg MAX = 1e6 + 5;   constexpr gg mod = 1e9 + 7;   constexpr gg INF = 1e10;   constexpr double thre = 1e-7;   gg ti, ni, mi, ki, di, pi, xi, yi;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     ti = 1;     cin >> ti;     while (ti--) {       string a, b;       cin >> ni >> a >> b;       map<char, set<char>> m;       for (gg i = 0; i < ni; ++i) {         if (a[i] != b[i]) {           m[a[i]].insert(b[i]);         }       }       gg ans = 0;       bool f = true;       while (not m.empty()) {         auto& [i, j] = *m.begin();         if (*j.begin() < i) {           f = false;           break;         }         if (j.size() != 1) {           for (auto k = next(j.begin()); k != j.end(); ++k) {             m[*j.begin()].insert(*k);           }         }         m.erase(m.begin());         ans++;       }       cout << (f ? ans : -1) <<   n ;     }     return 0;   }