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); System.out.println(sc.nextLong() * sc.nextLong() * sc.nextLong() % sc.nextLong()); } }