using System; using System.Collections.Generic; using System.Linq; class prog { static void Main() { var a=Console.ReadLine().Split().Select(int.Parse).ToArray().ValidateArray(x=>1<=x&&x<=1000000000); a.Validate(x=>x.Length==4); Console.ReadLine().Validate(x=>x==null); var v=a[0]; v*=a[1]; v%=a[3]; v*=a[2]; v%=a[3]; Console.WriteLine(v); } } static public class Validator { static public T Validate(this T input, Func f) { if (!f(input)) throw new Exception("invalid input"); return input; } static public T[] ValidateArray(this T[] input, Func f) { foreach (var x in input) if (!f(x)) throw new Exception("invalid input"); return input; } }