import java.util.Scanner import scala.util.control.Breaks object Main { def main(args: Array[String]): Unit = { val sc = new Scanner(System.in); var a,b,c,d = sc.nextLong println((a%d * b%d * c%d) %d) } }