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); long[] B = new long[4]; for(i=0;i<4;i++){ B[i] = Long.parseLong(K[i]); } //System.out.println((B[0]*B[1]*B[2])%B[3]); Long a = B[0]*B[1]%B[3]*B[2]; System.out.println(a%B[3]); } }