#include #include #include #define INPUT(str) do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0) int main() { char str[10*4+3]; long a,b,c,d; INPUT( str ); sscanf( str,"%ld %ld %ld %ld", &a, &b, &c, &d ); a %= d; b %= d; c %= d; a = ( a * b )% d; a = ( a * c ) % d; printf("%ld\n", a); }