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