#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
  long int a, b, c, d;
  scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
  printf("%ld", ((((a%d)*(b%d))%d)*(c%d))%d);
  return 0;
}