# coding: utf-8 # yukicoder No.373 かけ算と割った余り A, B, C, D = map(int, input().split()) print((A * B * C) % D)