import java.util.Scanner; public class Main{ static Scanner s=new Scanner(System.in); public static void main(String __[]){ input(); solve(); } private static void input(){ } private static void solve(){ long a=s.nextLong()*s.nextLong(),c=s.nextLong(),d=s.nextLong(); a%=d; a*=c; a%=d; System.out.println(a); } }