エー,ビー,シー,ディー=[int(_) for _ in input().split()] print((エー*ビー*シー)%ディー)