A, B, C, D = map(int, raw_input().split()) mlt = long(A)*long(B)*long(C) ans = int(mlt%long(D)) print ans