unsigned long a,b,c,d;main(){scanf("%lu%lu%lu%lu",&a,&b,&c,&d);printf("%d",(a%d)*(b%d)*(c%d)%d);}