import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import static java.lang.System.in; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String[] inputs = reader.readLine().split(" "); long A = Long.parseLong(inputs[0]); long B = Long.parseLong(inputs[1]); long C = Long.parseLong(inputs[2]); long D = Long.parseLong(inputs[3]); System.out.println((((A%D) * (B%D))%D * (C%D))%D); } }