fn main() { let mut input = String::new(); std::io::stdin().read_line(&mut input).ok(); let input: Vec = input .split_whitespace() .map(|n| n.parse().unwrap()) .collect(); let mut answer = input[0]; answer %= input[3]; answer *= input[1]; answer %= input[3]; answer *= input[2]; answer %= input[3]; println!("{}", answer); }