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