a,b,c,d = map(int,input().strip().split(" ")) print(((a % d) * (b % d) * (c % d)) % d)