import java.util.Scanner; public class TGMain { public static void main(String[] args){ int a, b, c, N; int ans = 0; Scanner sc = new Scanner(System.in); a = sc.nextInt(); b = sc.nextInt(); c = sc.nextInt(); N = sc.nextInt(); ans = a*b*c; ans = ans%N; System.out.println(ans); } }