using System; using System.Collections.Generic; using System.Linq; class Program { static string ReadLine() { return Console.ReadLine(); } static int ReadInt() { return int.Parse(ReadLine()); } static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); } static string[] ReadStrings() { return ReadLine().Split(); } static void Main() { var xs = ReadLine().Split().Select(long.Parse).ToArray(); long a = xs[0]; long b = xs[1]; long c = xs[2]; long d = xs[3]; long x = (a * b) % d; long y = (x * c) % d; Console.WriteLine(y); } }