package yukicoder; import java.util.Scanner; public class Main{ public static void main(String[] args){ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); long a,b,c,d; a=sc.nextLong();b=sc.nextLong();c=sc.nextLong();d=sc.nextLong(); long ans=1; ans=a%d; ans=ans*b%d; ans=ans*c%d; System.out.println(ans); } }