import java.math.BigInteger; /** * Created by nullzine on 2017/01/19. */ public class Main { public static void main(String[] args) { String[] strs = new java.util.Scanner(System.in).nextLine().split(" "); System.out.println(new BigInteger(strs[0]).multiply(new BigInteger(strs[1])).multiply(new BigInteger(strs[2])).mod(new BigInteger(strs[3])).toString()); } }