const INF: isize = 1isize << 60; fn main() { let mut t = String::new(); std::io::stdin().read_line(&mut t).ok(); let t: isize = t.trim().parse().unwrap(); let mut xa = String::new(); std::io::stdin().read_line(&mut xa).ok(); let xa: Vec = xa.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let x = xa[0]; let a = xa[1]; let mut ya = String::new(); std::io::stdin().read_line(&mut ya).ok(); let yb: Vec = ya.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let y = yb[0]; let b = yb[1]; let mut result = INF; let offset = if t < 0 { t.abs() / b + if t % b != 0 { 1 } else { 0 } } else { 0 }; let offset_dates = offset * y; let t = t + offset * b; for i in 0..=10000000 { let mut cost = offset_dates + i*y; let t = t + i*b; cost += t / a * x; let t = t % a; cost += t; result = result.min(cost); } println!("{}", result); }