import java.util.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int d = sc.nextInt(); int ret = mod(mod(a,d)*mod(b,d)*mod(c,d),d); System.out.println(ret); } public static int mod(int a, int b) { return a%b; } }