malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) {       int n;       cin >> n;       long long arr[n], c4 = 0, c2 = 0;       long long i;       map<long long, long long> make_pair;       for (i = 0; i < n; i++) {         cin >> arr[i];         c4 -= make_pair[arr[i]] / 4;         c2 -= make_pair[arr[i]] / 2;         make_pair[arr[i]]++;         c4 += make_pair[arr[i]] / 4;         c2 += make_pair[arr[i]] / 2;       }       long long q;       cin >> q;       for (i = 0; i < q; i++) {         char c;         long long x;         cin >> c >> x;         c4 -= make_pair[x] / 4;         c2 -= make_pair[x] / 2;         if (c ==  + ) {           make_pair[x]++;         } else {           make_pair[x]--;         }         c4 += make_pair[x] / 4;         c2 += make_pair[x] / 2;         if (c4 >= 1 && c2 >= 4) {           cout <<  YES  << endl;         } else {           cout <<  NO  << endl;         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 505;   int l[MAXN], r[MAXN], s[MAXN], w[MAXN], v[MAXN];   int dp[2 * MAXN][MAXN];   vector<int> wr[2 * MAXN];   int calc(int str, int i) {     if (dp[str][i] != -1) return dp[str][i];     int L = l[i], R = r[i];     vector<int> prf(2 * MAXN);     prf[L] = 0;     for (int x = L + 1; x <= R; x++) {       prf[x] = prf[x - 1];       for (auto j : wr[x]) {         if (l[j] == L && r[j] == R) continue;         if (l[j] < L || w[j] > str) continue;         prf[x] = max(prf[x], calc(min(str - w[j], s[j]), j) + prf[l[j]]);       }     }     return dp[str][i] = v[i] + prf[R];   }   int main() {     int n, S;     cin >> n >> S;     l[0] = 0;     r[0] = 2 * n;     s[0] = S;     w[0] = 0;     v[0] = 0;     for (int i = 1; i <= n; i++) {       cin >> l[i] >> r[i] >> w[i] >> s[i] >> v[i];       wr[r[i]].push_back(i);     }     for (int i = 0; i < 2 * MAXN; i++)       for (int j = 0; j < MAXN; j++) dp[i][j] = -1;     cout << calc(S, 0) << endl;   }
#include <bits/stdc++.h>   using namespace std;   void read(long long &x) {     x = 0;     long long f = 1;     char ch = getchar();     for (; !isdigit(ch); ch = getchar())       if (ch ==  - ) f = -f;     for (; isdigit(ch); ch = getchar()) x = x * 10 + ch -  0 ;     x *= f;   }   void print(long long x) {     if (x < 0) putchar( - ), x = -x;     if (!x) return;     print(x / 10), putchar(x % 10 + 48);   }   void write(long long x) {     if (!x)       putchar( 0 );     else       print(x);     putchar(  n );   }   const long long maxn = 2e5 + 10;   const long long inf = 1e9;   const long double eps = 1e-12;   const long long mod = 1e9 + 7;   long long add(long long x, long long y) {     return x + y >= mod ? x + y - mod : x + y;   }   long long del(long long x, long long y) {     return x - y < 0 ? x - y + mod : x - y;   }   long long mul(long long x, long long y) {     return 1ll * x * y - 1ll * x * y / mod * mod;   }   void inc(long long &x, long long y) {     x += y;     x %= mod;   }   long long n, k, a[maxn], res, c;   long long qpow(long long a, long long x) {     long long res = 1;     for (; x; x >>= 1, a = 1ll * a * a % mod)       if (x & 1) res = 1ll * res * a % mod;     return res;   }   struct Matrix {     long long a, b, r[110][110];     Matrix() { a = b = 0, memset(r, 0, sizeof r); }     Matrix operator*(const Matrix &t) const {       Matrix res;       res.a = a, res.b = t.b;       for (long long i = 0; i <= a; i++)         for (long long j = 0; j <= t.b; j++)           for (long long k = 0; k <= b; k++)             res.r[i][j] = add(res.r[i][j], mul(r[i][k], t.r[k][j]));       return res;     }   } tr, ans;   signed main() {     read(n), read(k);     for (long long i = 1; i <= n; i++) read(a[i]), res += !(a[i] & 1);     for (long long i = 1; i <= res; i++) c += !a[i];     ans.a = 0, ans.b = res;     ans.r[0][c] = 1;     tr.a = tr.b = res;     for (long long i = 0; i <= res; i++) {       long long lw = i, lb = res - i, rw = res - lw, rb = n - res - lb;       if (i != res) inc(tr.r[i][i + 1], lb * rw % mod);       if (i != 0) inc(tr.r[i][i - 1], lw * rb % mod);       inc(tr.r[i][i], (res * (res - 1) + (n - res) * (n - res - 1)) % mod *                           qpow(2, mod - 2) % mod);       inc(tr.r[i][i], (lw * lb + rw * rb) % mod);     }     long long x = k, f = 0;     for (; x; x >>= 1, tr = tr * tr)       if (x & 1) ans = ans * tr;     for (long long i = 0, i_r = res; i <= i_r; i++) f = (f + ans.r[0][i]) % mod;     write(ans.r[0][res] * qpow(f, mod - 2) % mod);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 998244353;   const long long INF = 1e17;   vector<vector<long long>> g;   vector<long long> used;   void dfs(long long v) {     used[v] = 1;     for (auto u : g[v]) {       if (!used[u]) {         dfs(u);       }     }   }   void solve() {     long long n, m;     cin >> n >> m;     long long q;     cin >> q;     long long N = n + m;     g.resize(N);     used.resize(N);     while (q--) {       long long x, y;       cin >> x >> y;       --x, --y;       x += m;       g[x].push_back(y);       g[y].push_back(x);     }     long long ans = -1;     for (long long i = 0; i < N; ++i) {       if (!used[i]) {         dfs(i);         ans++;       }     }     cout << ans;   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long tt = 1;     while (tt--) {       solve();       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int t;     cin >> t;     for (int z = 0; z < t; ++z) {       int n;       string s;       cin >> n >> s;       string ans =   ;       for (int i = 0; i < n; ++i) {         if ((s[i] -  0 ) % 2 == 1) ans += s[i];         if (ans.size() == 2) break;       }       if (ans.size() < 2) {         cout <<  -1 n ;       } else {         cout << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = (int)1e5 + 100;   vector<int> g[maxn], G[maxn];   int type[maxn];   int cntIn[maxn];   void no() {     printf( No );     exit(0);   }   void yes() {     printf( Yes );     exit(0);   }   void dfsG(int v, int par = -1) {     if ((int)G[v].size() > 2) no();     type[v] = 3;     for (int i = 0; i < (int)G[v].size(); i++) {       int nv = G[v][i];       if (nv == par) continue;       dfsG(nv, v);       break;     }   }   void solve() {     int n;     scanf( %d , &n);     if (n <= 2) yes();     for (int i = 0; i < n - 1; i++) {       int a, b;       scanf( %d%d , &a, &b);       a--;       b--;       g[a].push_back(b);       g[b].push_back(a);     }     bool fnd = false;     for (int i = 0; i < n; i++)       if ((int)g[i].size() >= 3) fnd = true;     if (!fnd) yes();     for (int i = 0; i < n; i++)       if ((int)g[i].size() == 1 && type[i] == 0) {         type[i] = 1;         int pv = i;         int v = g[i][0];         while ((int)g[v].size() == 2) {           type[v] = 1;           int nv = g[v][0] + g[v][1] - pv;           pv = v;           v = nv;         }         cntIn[v]++;       }     for (int i = 0; i < n; i++)       if ((int)g[i].size() == 3 && cntIn[i] == 2) {         type[i] = 2;       }     for (int i = 0; i < n; i++)       for (int j = 0; j < (int)g[i].size(); j++) {         int ni = g[i][j];         if (type[i] == 0 && type[ni] == 0) G[i].push_back(ni);       }     int st = -1;     for (int i = 0; i < n; i++)       if (type[i] == 0 && (int)G[i].size() <= 2) st = i;     if (st != -1) {       type[st] = 3;       for (int i = 0; i < (int)G[st].size(); i++) dfsG(G[st][i], st);     }     for (int i = 0; i < n; i++)       if (type[i] == 0) no();     yes();   }   int main(int, char **) {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 77;   int main() {     int a, b;     cin >> a >> b;     int ans = 0;     while (1) {       if (a <= 0 || b <= 0) break;       if (a < b) {         a++;         b -= 2;       } else {         b++;         a -= 2;       }       if (a < 0 || b < 0) break;       ++ans;     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1000005];   int main() {     int n, q, a, b, x = 0, xPar = 0;     scanf( %d %d , &n, &q);     while (q--) {       scanf( %d , &a);       if (a == 1) {         scanf( %d , &b);         x += b;         if (x >= n) {           x = x % n;         } else if (x < 0) {           x = n - ((x * -1) % n);         }       } else {         if ((x + xPar) % 2 == 1) {           xPar = ((xPar + 1) % n);         } else {           if (--xPar < 0) {             xPar += n;           }         }       }     }     for (int i = 1; i <= n; i++) {       int nTemp = i + x;       if (i % 2) {         nTemp -= xPar;       } else {         nTemp += xPar;       }       while (nTemp <= 0) {         nTemp += n;       }       while (nTemp > n) {         nTemp -= n;       }       arr[nTemp] = i;     }     for (int i = 1; i <= n; i++) {       cout << arr[i];       if (i != n) {         cout <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   struct query {     long long k, pos, ind;   };   struct fenwick {     long long n;     vector<long long> f;     fenwick(long long _n) {       n = _n;       f.resize(n, 0);     }     void add(long long val, long long i) {       for (; i < n; i |= (i + 1)) f[i] += val;     }     long long sum(long long i) {       long long ans = 0;       for (; i >= 0; i &= (i + 1), --i) ans += f[i];       return ans;     }   };   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n;     cin >> n;     vector<pair<long long, long long> > a(n);     vector<long long> start(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i].first;       start[i] = a[i].first;       a[i].second = i;     }     sort(a.begin(), a.end(),          [](pair<long long, long long> a, pair<long long, long long> b) {            if (a.first == b.first) return a.second > b.second;            return a.first < b.first;          });     reverse(a.begin(), a.end());     long long q;     cin >> q;     vector<query> qs(q);     for (long long t = 0; t < q; ++t) {       cin >> qs[t].k >> qs[t].pos;       qs[t].k--;       qs[t].pos--;       qs[t].ind = t;     }     sort(qs.begin(), qs.end(), [](query a, query b) { return a.k < b.k; });     fenwick f(n);     long long l = -1;     vector<long long> ans(q);     for (long long i = 0; i < q; ++i) {       while (l < qs[i].k) {         ++l;         f.add(1, a[l].second);       }       long long L = 0, R = n - 1;       while (R - L > 1) {         long long m = (R + L) / 2;         if (f.sum(m) <= qs[i].pos) {           L = m;         } else           R = m;       }       if (f.sum(L) < qs[i].pos + 1) swap(L, R);       ans[qs[i].ind] = start[L];     }     for (auto x : ans) cout << x <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string x, y;     cin >> x >> y;     int n, m;     n = x.size(), m = y.size();     if (n != m) {       cout <<  NO ;       return 0;     }     if (n == 1) {       if (x == y)         cout <<  YES ;       else         cout <<  NO ;       return 0;     }     if (x == y) {       cout <<  YES ;       return 0;     }     int cnt = count(x.begin(), x.end(),  0 );     int cnt1 = count(y.begin(), y.end(),  0 );     if (cnt == n || cnt1 == n)       cout <<  NO ;     else       cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int dp[2][316 + 1][316 + 2];   int addmod(int x, int y) {     int sum = x + y;     if (sum >= 1000000007) sum -= 1000000007;     return sum;   }   int mulmod(int x, int y, int p) {     long long prod = x;     prod = (prod * y) % p;     return (int)prod;   }   void add_to_mod(int &x, int y) { x = addmod(x, y); }   int run_dp(int n, int m, int x) {     int result = 0;     if (n > m) return result;     int next = 0;     dp[next][0][0] = 1;     for (int i = 1; i <= m; i++) {       int prev = next;       next ^= 1;       for (int j = n; j > 0; j--)         for (int k = j; k >= 0; k--) {           dp[next][j][k] = addmod(dp[prev][j - 1][k], dp[next][j][k + 1]);           if (m - i != x - k) {             int s = dp[prev][j][k];             if (k > 0) add_to_mod(s, dp[next][j - 1][k - 1]);             add_to_mod(dp[next][j][k], s);           }         }       dp[next][0][0] = (m - i) > x;     }     result = dp[next][n][0];     for (int i = 2; i <= n; i++) result = mulmod(result, i, 1000000007);     return result;   }   int solve_problem() {     int n, m, x;     if (scanf( %d %d %d , &n, &m, &x) != 3) return 1;     --x;     int result = run_dp(n, m, x);     printf( %d n , result);     return 0;   }   int main() {     solve_problem();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     vector<int> data(n + 1);     int ans = 1e9;     for (int i = 1; i <= n; i++) {       cin >> data[i];       ans = min(ans, data[i] / max(i - 1, n - i));     }     cout << ans << endl;   }   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     solve();   }
#include <bits/stdc++.h>   int n, k, m, t, l;   int a, b;   int main() {     scanf( %d %d %d %d , &n, &k, &m, &t);     l = n;     for (int i = 1; i <= t; i++) {       scanf( %d %d , &a, &b);       if (a == 1) {         if (b <= k)           l++, k++;         else           l++;       } else {         if (b < k)           l -= b, k -= b;         else           l = b;       }       printf( %d %d n , l, k);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k;   int Graph[1025][1025], f[1025][1025];   int Tj(int x) {     int tot = 0;     while (x) tot++, x -= x & (-x);     return tot;   }   void read(int &x) {     x = 0;     char c = getchar();     int f = 1;     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -f;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       x = (x << 3) + (x << 1) + c -  0 ;       c = getchar();     }     x *= f;     return;   }   void write(int x) {     if (x < 0) {       x = -x;       putchar( - );     }     if (x > 9) write(x / 10);     putchar(x % 10 +  0 );   }   signed main() {     read(n), read(m), read(k);     for (register int i = 1; i <= m; ++i) {       int u, v;       read(u), read(v);       u--, v--;       Graph[u][v] = Graph[v][u] = f[(1 << u) | (1 << v)][(1 << u) | (1 << v)] = 1;     }     for (register int i = 0; i < (1 << n); ++i)       for (register int j = 0; j < (1 << n); ++j)         if ((i & j) == j && f[i][j])           for (register int k1 = 0; k1 < n; ++k1)             for (register int k2 = 0; k2 < n; ++k2) {               if (Graph[k1][k2] && (i & (1 << k1)) && (~i & (1 << k2)) &&                   !(((j & (~(1 << k1))) | (1 << k2)) >> (k2 + 1)))                 f[i | (1 << k2)][j & (~(1 << k1)) | (1 << k2)] += f[i][j];             }     int ans = 0;     for (register int i = 0; i < (1 << n); ++i)       if (Tj(i) == k) ans += f[(1 << n) - 1][i];     write(ans), putchar(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gl, gr, bl, br;   bool check(int g, int b) {     if (g - 1 <= b && b <= 2 * (g + 1))       return true;     else       return false;   }   int main() {     scanf( %d %d %d %d , &gl, &gr, &bl, &br);     if (check(gl, br) || check(gr, bl))       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[4] = {-1, 1, 0, 0};   int dy[4] = {0, 0, -1, 1};   const int inf = 0x7f7f7f7f;   const int mod = 1000000007;   const double eps = 1e-8;   int n, m;   set<int> v;   vector<pair<int, int> > ans;   vector<int> vc[100007];   bool isok(int u, int v) {     for (size_t i = 0; i < vc[u].size(); ++i) {       if (vc[u][i] == v) return false;     }     return true;   }   bool dfs(int u) {     if ((int)ans.size() == min(n - 1, m)) return true;     v.erase(u);     for (set<int>::iterator it = v.begin(); it != v.end(); ++it) {       if (!isok(u, *it)) continue;       ans.push_back(make_pair(u, *it));       if (dfs(*it))         return true;       else {         ans.pop_back();         it = v.find(*it);       }     }     v.insert(u);     return false;   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 0; i <= n; ++i) vc[i].clear();     int x, y;     for (int i = 0; i < m; ++i) {       scanf( %d%d , &x, &y);       vc[x].push_back(y);       vc[y].push_back(x);     }     for (int i = 1; i <= n; ++i) v.insert(i);     ans.clear();     for (int i = 1; i <= n; ++i) {       if (dfs(i)) {         if (m == n) ans.push_back(make_pair(ans[0].first, ans.back().second));         for (int i = 0; i < m; ++i)           printf( %d %d n , ans[i].first, ans[i].second);         return 0;       }     }     printf( -1 n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long b, c, d, e, f, g, h, i, j = 0, k = 2, l, o = 0, m = 0, n = 0, q = 1,                                       r = 1, s, t, u, v, x = 1, y = 1,                                       z = 1111111;     string a;     cin >> a;     b = a.size();     for (i = 0; i < b; i++) {       if (a[i] ==  4 ) n++;       if (a[i] ==  7 ) m++;     }     if (n == 0 && m == 0) {       cout << -1;       return 0;     }     if (m > n)       cout << 7;     else       cout << 4;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   vector<vector<int> > pre;   vector<int> starts;   vector<int> coproc;   vector<int> cnts;   vector<int> nexts;   void dfs(int v, int co) {     for (int p : pre[v]) {       cnts[p]--;       if (cnts[p] == 0) {         if (coproc[p] == co) {           nexts.push_back(p);         } else {           dfs(p, co);         }       }     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     int n, m;     cin >> n >> m;     coproc.resize(n);     for (int i = 0; i < n; i++) {       cin >> coproc[i];     }     pre.resize(n);     cnts.assign(n, 0);     for (int i = 0; i < m; i++) {       int u, v;       cin >> u >> v;       pre[v].push_back(u);       cnts[u]++;     }     for (int i = 0; i < n; i++) {       if (cnts[i] == 0) {         if (coproc[i])           nexts.push_back(i);         else           starts.push_back(i);       }     }     int cnt = 0;     while (starts.size() + nexts.size()) {       for (auto v : starts) {         dfs(v, 1);       }       starts.swap(nexts);       nexts.clear();       if (starts.size()) {         cnt++;       }       for (auto v : starts) {         dfs(v, 0);       }       starts.swap(nexts);       nexts.clear();     }     cout << cnt <<   n ;     return false;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> z_function(string s) {     long long n = (long long)s.length();     vector<long long> z(n);     for (long long i = 1, l = 0, r = 0; i < n; ++i) {       if (i <= r) z[i] = min(r - i + 1, z[i - l]);       while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];       if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;     }     return z;   }   signed main() {     ios_base::sync_with_stdio(false);     string s, t;     cin >> s >> t;     string str = t +  #  + s;     auto z = z_function(str);     long long n = s.size(), m = t.size();     long long dp[n], pre1[n], pre2[n];     for (long long i = 0; i < n; i++) dp[i] = 0, pre1[i] = 0, pre2[i] = 0;     for (long long i = m - 1; i < n; i++) {       if (z[i + 2] != m) {         if (i) dp[i] = dp[i - 1] % 1000000007;       } else {         long long pre;         if (i == m - 1)           pre = 0;         else           pre = pre2[i - m];         dp[i] = pre + i - m + 2;         dp[i] %= 1000000007;       }       if (i == 0)         pre1[i] = dp[i];       else         pre1[i] = pre1[i - 1] + dp[i];       if (i == 0)         pre2[i] = pre1[i];       else         pre2[i] = pre2[i - 1] + pre1[i];       pre1[i] %= 1000000007;       pre2[i] %= 1000000007;     }     long long ans = 0;     for (long long i = 0; i < n; i++) {       ans += dp[i];       ans %= 1000000007;     }     cout << ans % 1000000007;   }
#include <bits/stdc++.h>   using namespace std;   vector<vector<int> > g;   vector<char> used;   vector<long long> distArr, fArr, sArr;   long long A, B, diameter;   long long answer = 0;   struct step {     int a, b, d;     friend ostream& operator<<(ostream& s, const step& v);   };   ostream& operator<<(ostream& s, const step& v) {     s << v.a <<     << v.b <<     << v.d;     return s;   }   vector<step> arr;   void dfs(int v, long long dist, vector<long long>& dArr, long long& cur) {     dArr[v] = dist;     if (dArr[cur] < dist) cur = v;     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (!used[to]) {         used[to] = true;         dfs(to, dist + 1, dArr, cur);       }     }   }   void dfs2(int v, long long dist, bool flag) {     if (!flag) {       sArr[v] = dist;     }     for (int i = 0; i < (int)g[v].size(); i++) {       int to = g[v][i];       if (!used[to]) {         used[to] = true;         dfs2(to, dist + 1, flag);       }     }     if (fArr[v] + sArr[v] > diameter) {       step temp;       if (fArr[v] > sArr[v]) {         temp.a = A + 1;         answer += fArr[v];       } else {         temp.a = B + 1;         answer += sArr[v];       }       temp.b = v + 1;       temp.d = v + 1;       arr.push_back(temp);     }     if (fArr[v] + sArr[v] == diameter && flag && v != A) {       step temp;       temp.a = A + 1;       temp.d = v + 1;       temp.b = v + 1;       answer += fArr[v];       arr.push_back(temp);     } else if (fArr[v] + sArr[v] == diameter)       used[v] = false;   }   int main() {     int n;     cin >> n;     g.assign(n, vector<int>());     for (int i = 0; i < n - 1; i++) {       int from, to;       cin >> from >> to;       g[from - 1].push_back(to - 1);       g[to - 1].push_back(from - 1);     }     used.assign(n, false);     used[0] = true;     distArr.assign(n, 0);     A = 0;     B = 0;     dfs(0, 0, distArr, A);     used.assign(n, false);     used[A] = true;     fArr.assign(n, 0);     sArr.assign(n, 0);     dfs(A, 0, fArr, B);     diameter = fArr[B];     used.assign(n, false);     used[B] = true;     dfs2(B, 0, false);     dfs2(A, 0, true);     cout << answer << endl;     for (int i = 0; i < (int)arr.size(); i++) cout << arr[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<long long> v;   long long a, b, f, k;   int cnt() {     int c = 0;     int n = v.size();     long long now = 0;     for (int i = 0; i < n; i++) {       if (now + b < v[i]) return -1;       while (i < n && now + b >= v[i]) i++;       i--;       c++;       now = v[i];     }     return c - 1;   }   int main() {     scanf( %I64d%I64d%I64d%I64d , &a, &b, &f, &k);     v.push_back(f);     for (long long i = 1; i < k; i++) {       if (i & 1)         v.push_back(v[i - 1] + 2 * (a - f));       else         v.push_back(v[i - 1] + 2 * f);     }     v.push_back(a * k);     printf( %d , cnt());   }