import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); 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 bi = new BigInteger("0"); bi = bi.add(a); bi = bi.multiply(b); bi = bi.multiply(c); bi = bi.remainder(d); System.out.println(bi.toString()); } }