fn main() { let ref mut buf = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), buf).ok(); let mut iter = buf.split_whitespace(); macro_rules! scan { ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::>()); (($($t:tt),*)) => (($(scan!($t)),*)); (Usize1) => (scan!(usize) - 1); (Bytes) => (scan!(String).into_bytes()); ($t:ty) => (iter.next().unwrap().parse::<$t>().unwrap()); } let (a, b, c, d, e) = scan!((u64, u64, u64, u64, u64)); let v = vec![ vec![1; a as usize], vec![0; b as usize], vec![1; c as usize], vec![0; d as usize], ]; let k = (a + b) * (c + d); let mut r1 = v[0].iter().chain(v[1].iter()).cycle(); let mut r2 = v[2].iter().chain(v[3].iter()).cycle(); let mut x = 0; for _ in 0..k { x += (r1.next().unwrap() & r2.next().unwrap()) as u64; } let mut r1 = v[0].iter().chain(v[1].iter()).cycle(); let mut r2 = v[2].iter().chain(v[3].iter()).cycle(); let mut y = 0; for _ in 0..e % k { y += (r1.next().unwrap() & r2.next().unwrap()) as u64; } let ans = e / k * x + y; println!("{}", ans); }