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