import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long a, b, c, d, e; a = sc.nextLong(); b = sc.nextLong(); c = sc.nextLong(); d = sc.nextLong(); a %= d; b %= d; c %= d; a *= b; a %= d; a *= c; a %= d; System.out.println(a); } }