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