import java.util.Scanner; public class Study01 { public static void main(String[] args) { int i; Scanner sc = new Scanner(System.in); String A = sc.nextLine(); String[] K = A.split(" ",0); int[] B = new int[4]; for(i=0;i<4;i++){ B[i] = Integer.parseInt(K[i]); } System.out.println((B[0]*B[1]*B[2])%B[3]); } }