#coding: utf-8 #yuki373 a,b,c,d=map(int,raw_input().split()) res=((a%d)*(b%d)*(c%d))%d print res