#!/usr/bin/env python a,b,c,d = map(int,raw_input().split()) calc1 = a * b * c calc2 = calc1 % d print calc2