a,b,c,d = map(int, raw_input().split()) print a%d*b%d*c%d