import std.stdio, std.string, std.conv, std.algorithm, std.array; void main(){ auto arr = readln.strip.split.map!(to!ulong); writeln(arr[0] % arr[3] * arr[1] % arr[3] * arr[2] % arr[3]); }