import java.util.Scanner; class no373{ public static void main(String[] args) { Scanner stdIn=new Scanner(System.in); long a=stdIn.nextLong(),b=stdIn.nextLong(),c=stdIn.nextLong(),d=stdIn.nextLong(); System.out.print((a*b)%d*c%d); } }