#include using namespace std; using ll = long long; #define rep(i, s, e) for (int i = (int)s; i < (int)e; i++) int main() { cin.tie(nullptr); int N, M, P, Q; cin >> N >> M >> P >> Q; int y = M * 12 + Q * M; int ans = (N / y) * 12; N %= y; rep(i, 1, 13) { if (P <= i && i <= P + Q - 1) N -= 2 * M; else N -= M; if (N <= 0) { cout << i + ans << '\n'; return 0; } } }