import java.io.*; import java.math.*; import java.util.*; public class Main { static int[] vy = {1,0,-1,0}; static int[] vx = {0,1,0,-1}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); long A = sc.nextLong(); long B = sc.nextLong(); long C = sc.nextLong(); long D = sc.nextLong(); System.out.println((((A%D)*(B%D)%D)*(C%D))%D); } }