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