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