#include int main(void) { long long a, b, c, d, k; scanf("%lld%lld%lld%lld%lld", &a, &b, &c, &d, &k); printf("%lld\n", (a * b + c - d) % k); }