using System; using System.Linq; class E { static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse); static (int, int) Read2() { var a = Read(); return (a[0], a[1]); } static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse); static void Main() => Console.WriteLine(Solve()); static object Solve() { var h = ReadL(); return (h[0] * h[1] + h[2] - h[3]) % h[4]; } }