malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   int n, S, L;   int a[300005];   int dp[300005];   void solve() {     deque<pair<int, int> > dqmin, dqmax, dqdp;     int pos = 0;     for (int i = 1; i <= n; i++) {       if (i >= L) {         while (dqdp.size() && dqdp.back().first >= dp[i - L]) dqdp.pop_back();         dqdp.push_back(make_pair(dp[i - L], i - L));       }       while (dqmax.size() && dqmax.back().first <= a[i]) dqmax.pop_back();       dqmax.push_back(make_pair(a[i], i));       while (dqmin.size() && dqmin.back().first >= a[i]) dqmin.pop_back();       dqmin.push_back(make_pair(a[i], i));       while (dqmax.size() && dqmax.front().first - dqmin.front().first > S) {         pos++;         if (dqmax.front().second < pos) dqmax.pop_front();         if (dqmin.front().second < pos) dqmin.pop_front();       }       while (dqdp.size() && dqdp.front().second < pos - 1) dqdp.pop_front();       if (dqdp.size()) dp[i] = dqdp.front().first + 1;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n;     cin >> S >> L;     for (int i = 1; i <= n; i++) {       cin >> a[i];       dp[i] = n + 1;     }     solve();     if (dp[n] <= n)       cout << dp[n];     else       cout << -1;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void printvec(vector<T>& vec) {     for (long long int i = 0; i < vec.size(); i++) {       cout << vec[i] <<    ;     }     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     long long int n;     cin >> n;     vector<pair<long long int, long long int> > inp;     for (long long int i = 0; i < n; i++) {       long long int a, b, c, d;       cin >> a >> b >> c >> d;       a = a + b + c + d;       inp.push_back(make_pair(-a, i));     }     sort(inp.begin(), inp.end());     for (long long int i = 0; i < n; i++) {       if (inp[i].second == 0) {         cout << i + 1 <<   n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int s = 1000000;   int a[1000001];   bool belongs[1000001];   bool used[1000001];   vector<int> ans;   int main() {     int n;     cin >> n;     for (int i = 0; i <= s; i++) belongs[i] = used[i] = false;     for (int i = 0; i < n; i++) {       scanf( %i , &a[i]);       belongs[a[i]] = true;     }     int u = 1;     for (int i = 0; i < n; i++)       if (!used[a[i]]) {         if (belongs[a[i]] && !belongs[s - a[i] + 1] && !used[s - a[i] + 1]) {           ans.push_back(s - a[i] + 1);           used[s - a[i] + 1] = true;           used[a[i]] = true;         } else if (belongs[a[i]] && belongs[s - a[i] + 1]) {           while (u <= s &&                  (belongs[u] || belongs[s - u + 1] || used[u] || used[s - u + 1]))             u++;           used[u] = true;           used[s - u + 1] = true;           used[s - a[i] + 1] = true;           used[a[i]] = true;           ans.push_back(u);           ans.push_back(s - u + 1);           u++;         } else           assert(false);       }     cout << int(ans.size()) << endl;     for (int i = 0; i < int(ans.size()); i++) printf( %i  , ans[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   string n;   int sz;   long long mul;   long long ans;   long long powe(long long a, long long b) {     if (!b) return 1;     long long tmp = powe(a, b / 2);     tmp = (tmp * tmp) % 1000000007;     if (b % 2 == 1)       return (tmp * a) % 1000000007;     else       return tmp;   }   int main() {     cin >> n;     sz = ((int)n.size());     mul = powe(2, sz - 1);     long long tp = 1;     for (int i = sz - 1; i >= 0; i--) {       if (n[i] ==  1 ) {         ans = (ans + ((tp * mul) % 1000000007)) % 1000000007;       }       tp = (tp * 2) % 1000000007;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const double pi = acos(-1);   const int o = 524288;   int a[1111111];   double x[1111111], y[1111111];   int z[1111111];   int main() {     double tx, ty;     int i, j, k, n, m, tz;     scanf( %d%d , &n, &m);     for (i = 0; i < n; i++) a[i + o] = x[i + o] = 1;     for (i = o - 1; i >= 0; i--) x[i] = x[i << 1] + x[i << 1 | 1];     while (m--) {       scanf( %d%d%d , &i, &j, &k);       j += o - 1;       if (i == 1)         a[j] += k;       else         z[j] = (z[j] + k) % 360;       x[j] = a[j] * cos(z[j] * pi / 180);       y[j] = a[j] * sin(-z[j] * pi / 180);       while (j >>= 1) {         x[j] = x[j << 1] + x[j << 1 | 1] * cos(-z[j << 1] * pi / 180) -                y[j << 1 | 1] * sin(-z[j << 1] * pi / 180);         y[j] = y[j << 1] + x[j << 1 | 1] * sin(-z[j << 1] * pi / 180) +                y[j << 1 | 1] * cos(-z[j << 1] * pi / 180);         z[j] = (z[j << 1] + z[j << 1 | 1]) % 360;       }       printf( %.10f %.10f n , x[1], y[1]);     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long MOD = 998244353;   double eps = 1e-12;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int n;     cin >> n;     string s;     cin >> s;     int coins = 0;     int x, y;     if (s[0] ==  U ) {       x = 0;       y = 1;     } else {       x = 1;       y = 0;     }     for (int i = 1; i < n; i++) {       if (s[i] ==  U ) {         if (x == y) {           if (s[i - 1] ==  U ) coins++;         }         y++;       } else {         if (x == y) {           if (s[i - 1] ==  R ) coins++;         }         x++;       }     }     cout << coins;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const int maxn = 1000100;   int cnt_neg = 0, cnt_pos = 0;   int arr[maxn << 1];   int main() {     int n;     scanf( %d , &n);     for (int e = 1; e <= n; e++) scanf( %d , arr + e), arr[e + n] = arr[e];     int hi = 2 * n, lo = n + 1, nowlo = n;     long long sum = 0;     set<pair<int, int> > go;     unordered_set<int> removido;     for (int cur = hi; cur >= lo; cur--) {       if (arr[cur] <= nowlo)         cnt_pos++;       else         cnt_neg++, go.insert(make_pair(arr[cur] - nowlo, cur));       sum += abs(arr[cur] - nowlo);       nowlo--;     }     long long ans = sum, shift = 0, state = 0;     for (; lo > 1;) {       if (arr[hi] <= n)         cnt_pos--;       else         cnt_neg--;       sum -= abs(arr[hi] - n);       removido.insert(hi);       shift++;       sum += -cnt_neg + cnt_pos;       sum += abs(arr[lo - 1] - 1);       if (sum < ans) ans = sum, state = shift;       if (arr[lo - 1] > 1)         cnt_neg++, go.insert(make_pair(shift + arr[lo - 1] - 1, lo - 1));       else         cnt_pos++;       while (!go.empty()) {         int shi, val;         tie(shi, val) = *go.begin();         int removal = removido.count(val);         if (!(removal || shi == shift)) break;         if (!removal)           cnt_neg--, cnt_pos++;         else           removido.erase(go.begin()->second);         go.erase(go.begin());       }       lo--;       hi--;     }     printf( %lld %lld n , ans, state);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mod(long long v, long long k, long long p) {     long long res = 1;     for (long long i = 0; i < 4; i++) res *= v, res %= p;     res -= ((k * v) % p);     if (res < 0) res += p;     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long n, p, k;     cin >> n >> p >> k;     long long Array[n];     for (long long i = 0; i < n; i++) cin >> Array[i];     long long B[n];     for (long long i = 0; i < n; i++) B[i] = mod(Array[i], k, p);     vector<long long> out;     sort(B, B + n);     long long cnt = 1;     for (long long i = 0; i < n - 1; i++) {       if (B[i + 1] != B[i] and cnt != 1)         out.push_back(cnt), cnt = 1;       else if (B[i + 1] == B[i])         cnt++;     }     if (cnt != 1) out.push_back(cnt);     long long sum = 0;     for (long long i = 0; i < out.size(); i++)       sum += ((out[i] * (out[i] - 1)) / 2);     cout << sum <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 200000000 + 1;   const int N = 300006, M = 80;   int dp[2][101][10005], a[105], cnt[105];   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= n; i++) {       int cnt1 = 0;       for (int j = 1; j <= n; j++) {         if (a[i] == a[j]) cnt1++;       }       cnt[a[i]] = cnt1;     }     sort(a + 1, a + n + 1);     vector<int> v;     v.push_back(a[1]);     for (int i = 2; i <= n; i++)       if (a[i] != a[i - 1]) v.push_back(a[i]);     dp[0][0][0] = 1;     for (int i = 1; i <= v.size(); i++) {       for (int j = 0; j <= n; j++) {         for (int k = 0; k <= 100 * n; k++) {           dp[i % 2][j][k] = dp[1 - i % 2][j][k];           for (int l = 1; l <= cnt[v[i - 1]] && l <= j; l++) {             int z = l * v[i - 1];             if (k >= z)               dp[i % 2][j][k] = dp[i % 2][j][k] + dp[1 - i % 2][j - l][k - z];             if (dp[i % 2][j][k] > 10) dp[i % 2][j][k] = 10;           }         }       }     }     int ans = 1;     for (int i = 1; i <= n; i++) {       for (int j = i; j <= n; j++) {         if (a[j] != a[i]) break;         int sum = a[j] * (j - i + 1);         int z = j - i + 1;         if (dp[v.size() % 2][z][sum] == 1) ans = max(ans, z);       }     }     if (v.size() == 2) {       cout << n <<   n ;       return 0;     }     cout << ans <<   n ;   }
#include <bits/stdc++.h>   const int MAXN = 1e6 + 5;   int n, m, k;   char str[21];   int x[MAXN], y[MAXN];   int s[MAXN], t[MAXN];   int p[21];   int f[(1 << 20) + 3], g[(1 << 20) + 3];   inline void presum() {     for (int i = 0; i <= k - 1; ++i) {       for (int S = 0; S <= (1 << k) - 1; ++S) {         if ((S >> i) & 1) continue;         f[S] = std::min(f[S ^ (1 << i)], f[S]);         g[S] = std::max(g[S ^ (1 << i)], g[S]);       }     }   }   int main() {     scanf( %d%d%d , &n, &m, &k);     scanf( %s , str);     for (int i = 0; i <= k - 1; ++i)       if (str[i] ==  1 ) s[0] |= (1 << i);     scanf( %s , str);     for (int i = 0; i <= k - 1; ++i)       if (str[i] ==  1 ) t[0] |= (1 << i);     for (int i = 1; i <= n; ++i) scanf( %d%d , x + i, y + i);     for (int i = 1; i <= k; ++i) p[i] = i;     for (int i = 1; i <= n; ++i) {       int p1 = -1, p2 = -1;       for (int j = 1; j <= k; ++j) {         if (p[j] == x[i]) p1 = j;         if (p[j] == y[i]) p2 = j;       }       std::swap(p[p1], p[p2]);       for (int j = 0; j <= k - 1; ++j)         if ((s[0] >> (p[j + 1] - 1)) & 1) s[i] |= 1 << j;       for (int j = 0; j <= k - 1; ++j)         if ((t[0] >> (p[j + 1] - 1)) & 1) t[i] |= 1 << j;     }     for (int i = 0; i <= (1 << k) - 1; ++i) f[i] = 1e9, g[i] = -1e9;     for (int i = 0; i <= n; ++i)       f[s[i]] = std::min(f[s[i]], i), g[t[i]] = std::max(g[t[i]], i);     presum();     int ans = -1e9, ansl = -1, ansr = -1;     for (int S = 0; S <= (1 << k) - 1; ++S) {       if (g[S] - f[S] >= m && __builtin_popcount(S) > ans) {         ans = __builtin_popcount(S);         ansl = f[S] + 1;         ansr = g[S];       }     }     ans = 2 * ans + k - __builtin_popcount(s[0]) - __builtin_popcount(t[0]);     printf( %d n%d %d n , ans, ansl, ansr);     return 0;   }
//頑張って   #include <bits/stdc++.h>   #define ff first   #define ss second   #define ll long long   #define rep(i, n) for (int i = 0; i < n; i++)   using namespace std;   #define all(x) x.begin(), x.end()   void solve() {      int n;      cin >> n;      vector <int> a(n);      for (auto &i : a)         cin >> i;      int mxn = accumulate(all(a), 0);      vector <bool> dp(mxn + 1);      dp[0] = true;      for (int i = 0; i < n; i++) {         for (int j = mxn - a[i]; j >= 0; j--) {            if (dp[j] == true)               dp[a[i] + j] = true;         }      }      if ((mxn % 2 == 0 && !dp[mxn / 2]) || mxn % 2) {         cout <<  0 n ;         return;      }      while (true) {         for (int i = 0; i < n; i++) {            if (a[i] % 2 != 0) {               cout <<  1 n  << i + 1 <<   n ;               return;            }            a[i] /= 2;         }      }   }   int main() {   #ifndef ONLINE_JUDGE      freopen( inp.in ,  r , stdin);      freopen( outp.in ,  w , stdout);   #endif      ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);      solve();      return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = (long long)1e18;   const int N = 1234567;   long long a[N], b[N];   int main() {     int n, k;     scanf( %d %d , &n, &k);     n++;     for (int i = 0; i < n; i++) {       int foo;       scanf( %d , &foo);       a[i] = foo;     }     long long z = 0;     int up = 0;     for (int i = 0; i < n; i++) {       z += a[i];       b[i] = z;       if (z % 2 != 0) {         break;       }       up++;       z /= 2;     }     long long value = 0;     int ans = 0;     for (int i = n - 1; i >= 0; i--) {       if (i <= up) {         long long tmp = value * 2 + b[i];         long long z = a[i] - tmp;         if (-k <= z && z <= k && (i != n - 1 || z != 0)) {           ans++;         }       }       value = value * 2 + a[i];       if (value < -inf || value > inf) {         break;       }     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int di[] = {-1, 0, 1, 0};   const int dj[] = {0, 1, 0, -1};   const long long MOD = 1e9 + 7;   const long long INF = 1e9;   const double EPS = 1e-11;   class UnionFind {    private:     vector<long long> p, rank, setSize;     int numSets;       public:     UnionFind(int N) {       setSize.assign(N, 1);       numSets = N;       rank.assign(N, 0);       p.assign(N, 0);       for (int i = 0; i < N; i++) p[i] = i;     }     int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }     bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }     void unionSet(int i, int j) {       if (!isSameSet(i, j)) {         numSets--;         int x = findSet(i), y = findSet(j);         if (rank[x] > rank[y]) {           p[y] = x;           setSize[x] += setSize[y];         } else {           p[x] = y;           setSize[y] += setSize[x];           if (rank[x] == rank[y]) rank[y]++;         }       }     }     int numDisjointSets() { return numSets; }     int sizeOfSet(int i) { return setSize[findSet(i)]; }   };   int main() {     ios::sync_with_stdio(false), cin.tie(0);     int n;     cin >> n;     vector<long long> num(n);     map<int, int> idx, vis;     for (int i = 0; i < n; ++i) cin >> num[i], idx[num[i]] = i;     vector<long long> num2 = num;     sort(num2.begin(), num2.end());     UnionFind dsu(n);     for (int i = 0; i < n; ++i) {       swap(num[i], num[idx[num2[i]]]);       dsu.unionSet(i, idx[num2[i]]);     }     for (int i = 0; i < n; ++i) num[i] = dsu.findSet(i);     map<int, vector<long long> > r;     for (int i = 0; i < n; ++i) r[num[i]].push_back(i + 1);     cout << r.size() << endl;     for (map<int, vector<long long> >::iterator i = r.begin(); i != r.end();          ++i) {       cout << i->second.size() <<    ;       for (int j = 0; j < i->second.size(); ++j)         cout << i->second[j] <<    n [j == i->second.size() - 1];     }   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   using minheap = priority_queue<T, vector<T>, greater<T>>;   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     while (t--) {       long long w, h;       cin >> w >> h;       vector<vector<long long>> a(4);       for (int i = 0; i < 4; i++) {         int k, temp;         cin >> k;         for (int j = 0; j < k; j++) {           cin >> temp;           a[i].push_back(temp);         }       }       long long ans = 0;       ans = max(ans, (a[0].back() - a[0][0]) * h);       ans = max(ans, (a[1].back() - a[1][0]) * h);       ans = max(ans, (a[2].back() - a[2][0]) * w);       ans = max(ans, (a[3].back() - a[3][0]) * w);       cout << ans <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   char a[5][6] = { aabb ,  abab ,  abba ,  aaaa };   char s[5][10005];   bool f[5];   int find(char s[], int k) {     int p1 = -1;     int len = strlen(s);     int cnt = 0;     for (int i = len - 1; i >= 0; i--) {       if (s[i] ==  a  || s[i] ==  e  || s[i] ==  i  || s[i] ==  o  || s[i] ==  u )         cnt++;       if (cnt == k) return i;     }     return -1;   }   bool check(char s[], char t[], int k) {     int p = find(s, k), q = find(t, k);     if (p == -1) return false;     if (q == -1) return false;     int l1 = strlen(s), l2 = strlen(t);     if (l1 - p != l2 - q) return false;     int j = q;     for (int i = p; i < l1; i++) {       if (s[i] == t[j])         j++;       else         return false;     }     return true;   }   int main() {     int n, k;     while (scanf( %d%d , &n, &k) > 0) {       memset(f, false, sizeof(f));       for (int i = 1; i <= n; i++) {         for (int j = 0; j < 4; j++) scanf( %s , s[j]);         if (!check(s[0], s[1], k)) {           f[0] = true;           f[3] = true;         }         if (!check(s[2], s[3], k)) {           f[0] = true;           f[3] = true;         }         if (!check(s[0], s[2], k)) {           f[1] = true;           f[3] = true;         }         if (!check(s[1], s[3], k)) {           f[1] = true;           f[3] = true;         }         if (!check(s[0], s[3], k)) {           f[2] = true;           f[3] = true;         }         if (!check(s[2], s[1], k)) {           f[2] = true;           f[3] = true;         }       }       bool sol = false;       if (!f[0] && !f[1] && !f[2]) {         puts( aaaa );         continue;       }       for (int i = 2; i >= 0; i--) {         if (!f[i]) {           puts(a[i]);           sol = true;           break;         }       }       if (!sol) puts( NO );     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100005;   struct edge {     int to, index;     edge(int t = 0, int i = 0) {       to = t;       index = i;     }   };   vector<edge> g[N];   int num[N], ans[N], dep[N], fa[18][N], n, m;   void add(int from, int to, int index) { g[from].push_back(edge(to, index)); }   void dfs(int x, int ffa, int d) {     fa[0][x] = ffa;     dep[x] = d;     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i].to;       if (y == ffa) continue;       dfs(y, x, d + 1);     }   }   void init() {     m = 0;     while (n >= (1 << m)) m++;     for (int i = 1; i <= m; i++) {       for (int j = 1; j <= n; j++) {         if (fa[i - 1][j] < 0)           fa[i][j] = -1;         else {           fa[i][j] = fa[i - 1][fa[i - 1][j]];         }       }     }   }   int LCA(int x, int y) {     if (dep[x] < dep[y]) swap(x, y);     for (int i = m; i >= 0; i--) {       if ((dep[x] - dep[y]) & (1 << i)) x = fa[i][x];     }     if (x == y) return x;     for (int i = m; i >= 0; i--) {       if (fa[i][x] != fa[i][y]) {         x = fa[i][x];         y = fa[i][y];       }     }     return fa[0][x];   }   void dfs2(int x, int fa, int z) {     for (int i = 0; i < g[x].size(); i++) {       int y = g[x][i].to;       if (y == fa) continue;       dfs2(y, x, g[x][i].index);       num[x] += num[y];     }     ans[z] = num[x];   }   int main() {     int x, y, rt;     scanf( %d , &n);     for (int i = 1; i < n; i++) {       scanf( %d%d , &x, &y);       add(x, y, i);       add(y, x, i);     }     dfs(1, -1, 0);     init();     int TA;     scanf( %d , &TA);     while (TA--) {       scanf( %d%d , &x, &y);       rt = LCA(x, y);       num[x]++;       num[y]++;       num[rt] -= 2;     }     dfs2(1, -1, 0);     for (int i = 1; i < n; i++) printf( %d  , ans[i]);     printf(  n );   }
#include <bits/stdc++.h>   using namespace std;   int n, a[2 * 100004], b[2 * 100004], c[2 * 100004], poz, x;   int main() {     ios::sync_with_stdio(false);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];       c[a[i]] = 1;     }     poz = 1;     for (int i = 1; i <= n; ++i) {       cin >> b[i];       if (c[b[i]] == 0) {         cout <<  0  ;         continue;       }       for (int j = poz; j <= n; ++j) {         c[a[j]] = 0;         if (a[j] == b[i]) {           cout << j - poz + 1 <<    ;           poz = j + 1;           break;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, cou = 0;     cin >> n;     string s;     cin >> s;     int res = n + 1;     for (int i = 0; i < n; i++) {       if (s[i] ==  H ) cou++;     }     for (int i = 0; i < n; i++) {       int cnt = 0;       for (int j = 0; j < cou; j++) {         if (s[(i + j) % n] ==  T ) cnt++;       }       res = min(res, cnt);     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   int x[55], y[55];   int main(int argc, char** argv) {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d , &x[i]);     for (int i = 1; i <= n; i++) scanf( %d , &y[i]);     int sum = 0;     for (int i = 1; i <= n; i++) {       sum += x[i] - y[i];     }     if (sum >= 0)       cout <<  Yes ;     else       cout <<  No ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(T &x) {     T res = 0, f = 1;     char c = getchar();     while (!isdigit(c)) {       if (c ==  - ) f = -1;       c = getchar();     }     while (isdigit(c)) {       res = (res << 3) + (res << 1) + c -  0 ;       c = getchar();     }     x = res * f;   }   const long long N = 200000 + 10;   long long w, a[N], n, mn = 1e13, mx = -1e13, sum;   int main() {     read(n), read(w);     for (int i = 1; i <= n; i++) {       read(a[i]);       sum += a[i];       mn = min(mn, sum);       mx = max(mx, sum);     }     if (abs(mx) > w || abs(mn) > w) {       printf( 0 );       return 0;     }     long long l = 0, r = w;     if (mn < 0) {       l = 0 - mn;     }     if (mx > 0) {       r = w - mx;     }     long long ans = r - l + 1;     if (ans > 0)       printf( %lld , r - l + 1);     else       printf( 0 );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline long long getint() {     long long _x = 0, _tmp = 1;     char _tc = getchar();     while ((_tc <  0  || _tc >  9 ) && _tc !=  - ) _tc = getchar();     if (_tc ==  - ) _tc = getchar(), _tmp = -1;     while (_tc >=  0  && _tc <=  9 ) _x *= 10, _x += (_tc -  0 ), _tc = getchar();     return _x * _tmp;   }   inline long long add(long long _x, long long _y,                        long long _mod = 1000000007ll) {     long long _ = _x + _y;     if (_ >= _mod) _ -= _mod;     return _;   }   inline long long sub(long long _x, long long _y,                        long long _mod = 1000000007ll) {     long long _ = _x - _y;     if (_ < 0) _ += _mod;     return _;   }   inline long long mul(long long _x, long long _y,                        long long _mod = 1000000007ll) {     long long _ = _x * _y;     if (_ >= _mod) _ %= _mod;     return _;   }   long long mypow(long long _a, long long _x, long long _mod) {     if (_x == 0) return 1ll;     long long _tmp = mypow(_a, _x / 2, _mod);     _tmp = mul(_tmp, _tmp, _mod);     if (_x & 1) _tmp = mul(_tmp, _a, _mod);     return _tmp;   }   long long mymul(long long _a, long long _x, long long _mod) {     if (_x == 0) return 0ll;     long long _tmp = mymul(_a, _x / 2, _mod);     _tmp = add(_tmp, _tmp, _mod);     if (_x & 1) _tmp = add(_tmp, _a, _mod);     return _tmp;   }   inline bool equal(double _x, double _y) {     return _x > _y - 1e-9 && _x < _y + 1e-9;   }   int __ = 1, _cs;   void build() {}   long long n, m, a, b;   void init() {     n = getint();     m = getint();     a = getint() - 1;     b = getint() - 1;   }   void solve() {     long long ai = a / m, aj = a % m;     long long bi = b / m, bj = b % m;     if (ai == bi || (a == 0 && b == n - 1) || m == 1) {       puts( 1 );       exit(0);     }     if (aj == 0 && (bj == m - 1 || b == n - 1)) {       puts( 1 );       exit(0);     }     if (aj == 0 || bj == m - 1 || bi == ai + 1 || bj + 1 == aj || b == n - 1) {       puts( 2 );       exit(0);     }     puts( 3 );   }   int main() {     build();     while (__--) {       init();       solve();     }   }