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 yb = String::new(); std::io::stdin().read_line(&mut yb).ok(); let yb: Vec = yb.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let y = yb[0]; let b = yb[1]; let (start_cost, start_date) = if t < 0 { let unit = t.abs() / b + if t.abs() % b != 0 { 1 } else { 0 }; (unit * y, unit * b) } else { (0, 0) }; let mut result = 1isize << 60; for i in 0..=a { let diff = t + start_date + i*b; result = result.min(start_cost + i * y + diff / a * x + diff % a); } println!("{}", result); }