import java.util.*; import java.math.*; public class Main { private static Scanner sc = new Scanner(System.in); public static void main(String[] args) throws Exception { BigInteger a = new BigInteger(sc.next()); BigInteger b = new BigInteger(sc.next()); BigInteger c = new BigInteger(sc.next()); BigInteger d = new BigInteger(sc.next()); BigInteger ret = mod(mod(mod(a,d).multiply(b),d).multiply(c),d); System.out.println(ret); } public static BigInteger mod(BigInteger a,BigInteger b) { return a.mod(b); } }