malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0) return a;     return gcd(b, a % b);   }   long long fac(long long n) {     if (n == 1) return 1;     return n * fac(n - 1);   }   long long power(long long x, long long y) {     long long res = 1;     for (long long i = 1; i <= y; i++) res = (res * x) % 1000000007;     return res % 1000000007;   }   int32_t main() {     long long T = 1;     while (T--) {       long long n;       cin >> n;       long long a[n];       long long e = 0, o = 0;       for (long long i = 0; i < n; i++) {         cin >> a[i];         if (i % 2 == 0)           e += a[i];         else           o += a[i];       }       long long ans = 0;       for (long long i = 0; i < n; i++) {         if (i % 2 == 0) {           if (e - a[i] == o) ans++;           e -= a[i];           o += a[i];         } else {           if (o - a[i] == e) ans++;           e += a[i];           o -= a[i];         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, k, a, b, ans;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> k >> a >> b;     if (k == 1) {       cout << (n - 1) * a;       return 0;     }     while (n > 1) {       if (n % k != 0 && n < k) {         ans += (n - 1) * a;         n = 1;       } else if (n % k != 0) {         ans += (n % k) * a;         n -= (n % k);       } else {         long long temp, temp2, val;         val = n / k;         temp = (n - val) * a;         ans += min(temp, b);         n = val;       }     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265358979323846L;   const long double E = 2.71828182845904523536L;   const int INF = (1 << 30) - 1;   const long long LINF = 1e18;   const long double eps = 1e-7;   const long long mod = 1e9 + 7;   unordered_map<long long, long long> u[65][10];   vector<pair<int, int> > v;   long long ans[65];   int k, n;   unordered_map<long long, int> match;   unordered_set<long long> skip;   long long solve(long long idx, int lvl, int c) {     if (u[lvl][c].count(idx)) {       return u[lvl][c][idx];     }     long long& r = u[lvl][c][idx];     if (match.count(idx)) {       if (match[idx] != c) {         r = 0;         return r;       }     }     if (lvl == k) {       r = 1;       return 1;     }     if (!skip.count(idx)) {       r = ans[lvl];       return r;     }     long long m1 = 0, m2 = 0;     for (int j = 0; j < 6; j++) {       if (j == c || j == (c ^ 1)) {         continue;       }       m1 += solve(idx * 2, lvl + 1, j);       m2 += solve(idx * 2 + 1, lvl + 1, j);     }     m1 %= mod;     m2 %= mod;     r = m1 * m2 % mod;     return r;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     std::cout << std::fixed << std::setprecision(20);     cin >> k >> n;     unordered_map<string, int> g;     g[ white ] = 0;     g[ yellow ] = 1;     g[ green ] = 2;     g[ blue ] = 3;     g[ red ] = 4;     g[ orange ] = 5;     for (int i = 0; i < n; i++) {       long long x;       string s;       cin >> x >> s;       match[x] = g[s];       while (x) {         skip.insert(x);         x /= 2;       }     }     ans[k] = 1;     for (int i = k - 1; i >= 1; i--) {       ans[i] = (4 * ans[i + 1]) % mod;       ans[i] = (ans[i] * ans[i]) % mod;     }     long long r = 0;     for (int i = 0; i < 6; i++) {       r += solve(1, 1, i);     }     cout << r % mod <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   bool isPrime(long long n) {     if (n <= 1) return false;     for (int i = 2; i <= sqrt(n); i++)       if (n % i == 0) return false;     return true;   }   long long mod = 1000000007;   int main() {     long long i, j, k = 0, n, m = 0, a[300001], b[300001], t = 0, ans = 0, i1 = 0,                     i2, h, p1, p2 = 0, q, l, f, c[2], mi;     char c1, c2, d[1001][1001];     string s;     double j1;     string e, dz;     std::vector<pair<long long, long long>> vect;     vector<long long> v;     map<string, long long> m1;     map<string, long long>::iterator itr;     cin >> n;     for (i = 0; i < n; i++) {       cin >> a[i];     }     sort(a, a + n);     j = 1;     for (i = 0; i < n; i++) {       if (a[i] >= j) {         t++;         j++;       }     }     cout << t;   }
#include <bits/stdc++.h>   using namespace std;   int lim = 1e6;   int inf = 1e9 + 7;   bool ispal(string s) {     int n = s.size();     bool ans = true;     for (int i = 0; i < n / 2; i++) {       if (s[i] != s[n - i - 1]) {         ans = false;         break;       }     }     return ans;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       if (!ispal(s)) {         cout << s <<   n ;         ;       } else {         char x = s[0];         bool check = false;         string ans = s;         for (int i = 1; i < s.size(); i++) {           if (x != s[i]) {             check = true;             ans[0] = ans[i];             ans[i] = x;             break;           }         }         if (check) {           cout << ans <<   n ;           ;         } else {           cout << -1 <<   n ;           ;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   long long int n;   int main() {     scanf( %lld , &n);     if (n == 1 || n == 3 || n == 4 || n == 6 || n == 9 || n == 12) {       cout << 0 << endl;       return 0;     }     int mod = n % 3, mx;     if (mod == 2) {       for (long long i = 1e7; i >= 1; i -= 3) {         if (i * i * 3 + i <= n * 2) {           mx = i;           break;         }       }     } else if (mod == 1) {       for (long long i = 1e7 + 1; i >= 1; i -= 3) {         if (i * i * 3 + i <= n * 2) {           mx = i;           break;         }       }     } else if (mod == 0) {       for (long long i = 1e7 + 5; i >= 1; i -= 3) {         if (i * i * 3 + i <= n * 2) {           mx = i;           break;         }       }     }     cout << (int)ceil((double)mx / 3) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> P[2];   int n;   int mark[100011];   int cnt[100011];   int cor(int p, int n) { return 2 * n + p; }   int main() {     int k, x;     cin >> n;     for (int i = 0; i < 2; i++) {       cin >> k;       for (int j = 0; j < k; j++) {         cin >> x;         P[i].push_back(x);       }     }     mark[cor(0, 0)] = mark[cor(1, 0)] = 2;     queue<int> Q;     Q.push(cor(0, 0));     Q.push(cor(1, 0));     while (Q.size()) {       int v = Q.front();       Q.pop();       if (mark[v] == 2) {         int p = v % 2;         v /= 2;         int val;         for (auto x : P[1 - p]) {           val = (v - x + 2 * n) % n;           x = cor(1 - p, val);           if (!mark[x]) {             mark[x] = 1;             Q.push(x);           }         }         continue;       }       int p = v % 2;       v /= 2;       int val;       for (auto x : P[1 - p]) {         val = (v - x + 2 * n) % n;         x = cor(1 - p, val);         cnt[x]++;         if (mark[x] == 0 and cnt[x] == P[x % 2].size()) {           Q.push(x);           mark[x] = 2;         }       }     }     for (int i = 1; i < n; i++) {       x = mark[cor(0, i)];       if (x == 1) {         cout <<  Win  ;       } else if (x == 2) {         cout <<  Lose  ;       } else {         cout <<  Loop  ;       }     }     cout <<   n ;     for (int i = 1; i < n; i++) {       x = mark[cor(1, i)];       if (x == 1) {         cout <<  Win  ;       } else if (x == 2) {         cout <<  Lose  ;       } else {         cout <<  Loop  ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   struct custom_hash {     static uint64_t splitmix64(uint64_t x) {       x += 0x9e3779b97f4a7c15;       x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;       x = (x ^ (x >> 27)) * 0x94d049bb133111eb;       return x ^ (x >> 31);     }     size_t operator()(uint64_t x) const {       static const uint64_t FIXED_RANDOM =           chrono::steady_clock::now().time_since_epoch().count();       return splitmix64(x + FIXED_RANDOM);     }   };   template <typename T>   istream& operator>>(istream& is, vector<T>& v) {     for (auto& i : v) is >> i;     return is;   }   template <typename T>   ostream& operator<<(ostream& os, vector<T>& v) {     for (auto& i : v) os << i <<    ;     return os;   }   long long mystoi(string str) {     stringstream ss(str);     long long ans = 0;     ss >> ans;     return ans;   }   long long exp(long long x, long long ex) {     long long ans = 1ll;     while (ex > 0) {       if (ex & 1ll) ans = (ans * x);       ex >>= 1ll;       x = (x * x);     }     return ans;   }   bool sort_cond(const pair<long long, long long>& a,                  const pair<long long, long long>& b) {     if (a.first == b.first) return a.second < b.second;     return a.first < b.first;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     long long lo;     while (t--) {       long long n;       cin >> n;       vector<long long> a(2 * n);       cin >> a;       vector<long long> o, e;       for (long long i = (0); i < (long long)(2 * n); i++) {         if (a[i] % 2)           o.push_back(i + 1);         else           e.push_back(i + 1);       }       long long cnt = 0;       if (o.size() % 2) o.pop_back();       if (e.size() % 2) e.pop_back();       if (o.size() > e.size()) {         for (long long i = (0); i < (long long)(o.size()); i++) {           if (cnt == n - 1) break;           cout << o[i] <<     << o[i + 1] << endl;           cnt++;           i++;         }         for (long long i = (0); i < (long long)(e.size()); i++) {           if (cnt == n - 1) break;           cout << e[i] <<     << e[i + 1] << endl;           cnt++;           i++;         }       } else {         for (long long i = (0); i < (long long)(e.size()); i++) {           if (cnt == n - 1) break;           cout << e[i] <<     << e[i + 1] << endl;           cnt++;           i++;         }         for (long long i = (0); i < (long long)(o.size()); i++) {           if (cnt == n - 1) break;           cout << o[i] <<     << o[i + 1] << endl;           cnt++;           i++;         }       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     char last, f;     cin >> last;     int ans = 0;     f = last;     for (int i = 1; i < n; i++) {       char a;       cin >> a;       if (a != last) ans++;       last = a;     }     if (f ==  F )       cout <<  NO n ;     else       cout << ((ans & 1) ?  YES n  :  NO n );   }
#include <bits/stdc++.h>   using namespace std;   deque<int> a[355];   int n, m, S, Q, z, L, R, k, l, r, x, c[355][100005];   int ans;   void deal(int &x) { x = (x + ans - 1) % n + 1; }   int main() {     scanf( %d , &n);     S = int(sqrt(n)), m = n / S + 1;     for (int i = 0; i < n; i++) {       scanf( %d , &x);       a[i / S].push_back(x);       c[i / S][x]++;     }     scanf( %d , &Q);     while (Q--) {       scanf( %d%d%d , &z, &L, &R);       deal(L), deal(R);       if (L > R) swap(L, R);       L--, l = L / S, r = R / S;       if (z == 2) {         scanf( %d , &k);         deal(k);         ans = 0;         if (l == r) {           for (int i = L % S, _ = R % S; i < _; i++) ans += a[l][i] == k;         } else {           for (int i = l + 1; i < r; i++) ans += c[i][k];           for (int i = L % S, _ = a[l].size(); i < _; i++) ans += a[l][i] == k;           for (int i = 0, _ = R % S; i < _; i++) ans += a[r][i] == k;         }         printf( %d n , ans);       } else {         if (l == r) {           R = R % S - 1, x = a[r][R], a[r].erase(a[r].begin() + R);           a[l].insert(a[l].begin() + L % S, x);         } else {           for (int i = l; i < r;) {             x = a[i].back(), a[i].pop_back(), c[i][x]--, i++;             a[i].push_front(x), c[i][x]++;           }           R %= S, x = a[r][R], a[r].erase(a[r].begin() + R), c[r][x]--;           a[l].insert(a[l].begin() + L % S, x), c[l][x]++;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int a[500001], pref[500001], valv[500001];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int t, i, j, k, l, m = 0, n, o, p, q, r, s, x;     cin >> n >> x;     pref[0] = 0;     valv[0] = 0;     for (i = 0; i < n; i++) {       cin >> a[i];       valv[i + 1] = valv[i] + (a[i] * (a[i] + 1)) / 2;       a[i + n] = a[i];       pref[i + 1] = pref[i] + a[i];       m = max(m, a[i]);     }     for (i = n; i < 2 * n; i++) {       pref[i + 1] = pref[i] + a[i];       valv[i + 1] = valv[i] + (a[i] * (a[i] + 1)) / 2;     }     long long int ans = 0;     if (m >= x) {       while (x > 0) {         ans += m;         m--;         x--;       }       cout << ans <<   n ;       return 0;     }     for (i = 0; i < 2 * n; i++) {       long long int start = 0;       long long int end = i, index = 0;       while (start <= end) {         long long int mid = (start + end) / 2;         if (pref[i + 1] - pref[mid] >= x) {           index = mid;           start = mid + 1;         } else {           end = mid - 1;         }       }       long long int ss = pref[i + 1] - pref[index + 1], ans1, s1, s2;       ans1 = valv[i + 1] - valv[index + 1];       long long int sum = x - ss;       s1 = a[index];       ans1 += (s1 * (s1 + 1)) / 2;       long long int z = max(0LL, s1 - sum);       ans1 -= (z * (z + 1)) / 2;       ans = max(ans1, ans);     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 10;   const long long mod = 998244353;   long long qpow(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % mod;       a = a * a % mod;       b /= 2;     }     return ans;   }   long long b[maxn], inv[maxn];   long long C(long long n, long long m) {     if (m > n) return 0;     return b[n] * inv[m] % mod * inv[n - m] % mod;   }   long long Lucas(long long n, long long m) {     if (m == 0) return 1;     return C(n % mod, m % mod) * Lucas(n / mod, m / mod) % mod;   }   long long S(long long n, long long m) {     long long ans = 0;     for (int k = 0; k <= m; k++) {       if (k & 1)         ans = (ans - C(m, k) * qpow(m - k, n) % mod + mod) % mod;       else         ans = (ans + C(m, k) * qpow(m - k, n) % mod) % mod;     }     return ans;   }   int main() {     int n, m;     cin >> n >> m;     if (m >= n)       cout << 0 << endl;     else {       b[0] = 1;       inv[0] = 1;       for (int i = 1; i <= n; i++)         b[i] = b[i - 1] * i % mod, inv[i] = qpow(b[i], mod - 2) % mod;       long long ans = S(n, n - m) * C(n, n - m) % mod;       if (m == 0)         cout << ans << endl;       else         cout << ans * 2 % mod << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   int q, x_1, y_1, x_2, y_2, k, len, a[35], b[35], c[35];   pair<int, int> dp[35][2][2][2];   int Add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }   int Minus(int a, int b) { return a < b ? a - b + mod : a - b; }   pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {     return make_pair(Add(a.first, b.first), Add(a.second, b.second));   }   pair<int, int> dfs(int now, int f1, int f2, int f3) {     if (now == -1) return make_pair(1, 0);     if (~dp[now][f1][f2][f3].first) return dp[now][f1][f2][f3];     pair<int, int> ret = make_pair(0, 0);     for (int i = 0; i <= (f1 ? a[now] : 1); i++)       for (int j = 0; j <= (f2 ? b[now] : 1); j++)         if ((i ^ j) <= (f3 ? c[now] : 1)) {           pair<int, int> tmp = dfs(now - 1, f1 && i == a[now], f2 && j == b[now],                                    f3 && (i ^ j) == c[now]);           ret = ret + tmp;           if (i ^ j) ret.second = (ret.second + (1ll << now) * tmp.first) % mod;         }     dp[now][f1][f2][f3] = ret;     return ret;   }   int calc(int x, int y, int k) {     if (x < 0 || y < 0) return 0;     memset(dp, -1, sizeof(dp));     len = 0;     while (x || y || k) {       a[len] = (x & 1);       b[len] = (y & 1);       c[len++] = (k & 1);       x >>= 1;       y >>= 1;       k >>= 1;     }     pair<int, int> ret = dfs(len - 1, 1, 1, 1);     return Add(ret.first, ret.second);   }   int main() {     scanf( %d , &q);     while (q--) {       scanf( %d%d%d%d%d , &x_1, &y_1, &x_2, &y_2, &k);       printf(            %d n ,           Minus(               Add(calc(x_2 - 1, y_2 - 1, k - 1), calc(x_1 - 2, y_1 - 2, k - 1)),               Add(calc(x_1 - 2, y_2 - 1, k - 1), calc(x_2 - 1, y_1 - 2, k - 1))));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool visited[100005];   vector<long long> arr[100005];   int main() {     std::ios::sync_with_stdio(false);     long long n, x;     cin >> n;     vector<pair<long long, long long> > ans;     for (long long i = 0; i < n; i++) {       cin >> x;       arr[x].push_back(i);     }     for (long long i = 0; i < 100005; i++) {       if (arr[i].size() == 1) {         ans.push_back(make_pair(i, 0));       } else if (arr[i].size() >= 2) {         bool good = 1;         long long dif = arr[i][1] - arr[i][0];         for (long long j = 1; j < arr[i].size(); j++) {           if (arr[i][j] != arr[i][j - 1] + dif) good = 0;         }         if (good) {           ans.push_back(make_pair(i, dif));         }       }     }     cout << ans.size() << endl;     for (long long i = 0; i < ans.size(); i++)       cout << ans[i].first <<     << ans[i].second << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long modI(long long a, long long m);   long long gcd(long long a, long long b);   long long powM(long long x, long long y, long long m);   long long swap(long long a, long long b);   void swap(long long& a, long long& b) {     long long tp = a;     a = b;     b = tp;   }   long long gcd(long long x, long long y) {     if (x == 0) return y;     return gcd(y % x, x);   }   long long powM(long long x, long long y, long long m) {     long long ans = 1, r = 1;     x %= m;     while (r > 0 && r <= y) {       if (r & y) {         ans *= x;         ans %= m;       }       r <<= 1;       x *= x;       x %= m;     }     return ans;   }   long long modI(long long a, long long m) {     long long m0 = m, y = 0, x = 1;     if (m == 1) return 0;     while (a > 1) {       long long q = a / m;       long long t = m;       m = a % m;       a = t;       t = y;       y = x - q * y;       x = t;     }     if (x < 0) x += m0;     return x;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(0);     long long tt = 1;     while (tt--) {       long long n;       cin >> n;       long long a[n];       for (long long i = 0; i < n; i++) cin >> a[i];       long long ans = 0;       for (long long mx = 1; mx < 31; mx++) {         long long dp = 0;         long long tmp = 0;         for (long long i = 0; i < n; i++) {           if (a[i] <= mx) {             dp = max((long long)0, dp + a[i]);           }           tmp = max(dp, tmp);         }         ans = max(ans, tmp - mx);       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<long long> a(n + 1);     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     int m;     cin >> m;     long long ans = 0;     long long wt = 0, ht = 0;     while (m--) {       long long w, h;       cin >> w >> h;       ans = max(ans + ht, a[w]);       wt = w;       ht = h;       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     cin.tie(0);     ios_base::sync_with_stdio(0);     string x, y;     cin >> x >> y;     char ans[200];     for (int i = 0; i < x.size(); i++) {       if (y[i] == x[i]) {         ans[i] = x[i];       } else if (y[i] < x[i]) {         ans[i] = y[i];       } else {         cout << -1 <<   n ;         return 0;       }     }     for (int i = 0; i < x.size(); i++) {       cout << ans[i];     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, a[4] = {};     cin >> n;     for (int i = 0; i < n; i++) {       char c;       cin >> c;       a[0] += c ==  U ;       a[1] += c ==  D ;       a[2] += c ==  L ;       a[3] += c ==  R ;     }     long res = min(a[0], a[1]) * 2 + min(a[2], a[3]) * 2;     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = LLONG_MAX;   bool check(char a, char b) { return a ==  _  || a == b; }   long long foo(string s, string tail) {     if (!check(s[s.size() - 2], tail[0]) || !check(s.back(), tail[1])) return 0;     s[s.size() - 2] = tail[0];     s[s.size() - 1] = tail[1];     if (s[0] ==  0 ) return 0;     long long res = 1;     for (long long i = 0; i + 2 < s.size(); i++) {       if (s[i] ==  _ ) {         res *= i > 0 ? 10 : 9;       }     }     return res;   }   string x(string s, long long val) {     for (auto &i : s) {       if (i ==  X ) {         i =  0  + val;       }     }     return s;   }   int main() {     ios_base::sync_with_stdio(0);     string s;     cin >> s;     long long res = 0;     if (s.size() == 1) {       res = (long long)(s[0] ==  _  || s[0] ==  X  || s[0] ==  0 );     } else {       if (count(s.begin(), s.end(),  X )) {         for (long long i = 0; i < 10; i++) {           string temp = x(s, i);           res += foo(temp,  25 ) + foo(temp,  50 ) + foo(temp,  75 ) +                  foo(temp,  00 );         }       } else {         res += foo(s,  25 ) + foo(s,  50 ) + foo(s,  00 ) + foo(s,  75 );       }     }     cout << res;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200;   int n, a[N], m;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (int i = 0; i < m; i++) {       int x, y;       scanf( %d%d , &x, &y);       x--;       if (x - 1 >= 0) a[x - 1] += y - 1;       if (x + 1 < n) a[x + 1] += a[x] - y;       a[x] = 0;     }     for (int i = 0; i < n; i++) printf( %d n , a[i]);     return 0;   }
#include <bits/stdc++.h>   bool sev(int h, int m);   using namespace std;   int main() {     int snooze;     cin >> snooze;     int h;     int m;     int n = 0;     cin >> h >> m;     if (sev(h, m)) {       cout <<  0  << endl;     } else {       while (sev(h, m) == false) {         if (m >= snooze) {           m = m - snooze;         } else {           if (h == 0) h = 24;           int x = snooze;           x = x - m;           h = h - 1;           m = 60;           m = m - (x);         }         n++;       }       cout << n;     }     return 0;   }   bool sev(int h, int m) {     if (h % 10 == 7 || h / 10 % 10 == 7 || m % 10 == 7 || m / 10 % 10 == 7)       return true;     else       return false;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, ans, sum = 0;     cin >> x;     x = abs(x);     for (int i = 0;; i++) {       sum += i;       if (sum >= x && (sum - x) % 2 == 0) {         ans = i;         break;       }     }     cout << ans << endl;     return 0;   }