using System; using System.Collections.Generic; using System.Linq; namespace Test { class Program { static void Main(string[] args) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); long ret = x[0] * x[1]; ret %= x[3]; ret *= x[2]; ret %= x[3]; Console.WriteLine(ret); } } }