import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); long A = scan.nextLong(); long B = scan.nextLong(); long C = scan.nextLong(); long D = scan.nextLong(); scan.close(); long ans = (((A % D) * (B % D)) % D * (C % D)) % D; System.out.println(ans); } }