#include int main() { int A,B,C,D; scanf("%d",&A); scanf("%d",&B); scanf("%d",&C); scanf("%d",&D); printf("%d\n", ((A%D)*(B%D)*(C%D))%D); return 0; }