fn main() { let mut xx = String::new(); std::io::stdin().read_line(&mut xx).ok(); let xx: Vec = xx.split_whitespace().flat_map(str::parse).collect(); let (mut n, m, p, q) = (xx[0], xx[1], xx[2], xx[3]); let drop: Vec = (1..=12) .map(|i| if i >= p && i < p + q { 2 * m } else { m }) .scan(0, |acc, x| { *acc += x; Some(*acc) }) .collect(); let yy = n / drop[11]; n %= drop[11]; let mm = drop.iter().position(|&i| n <= i).unwrap() as i64 + 1; println!("{}", 12 * yy + mm); }