import scala.annotation.tailrec import scala.io.StdIn.* def isPrime(value: Long): Boolean = @tailrec def isPrimeInner(p: Long): Boolean = if p * p > value then true else value % p != 0 && isPrimeInner(p + 1) if value <= 2 then value == 2 else isPrimeInner(2) def countExpression(digits: List[Int])(predicate: Long => Boolean): Int = def enumerate(rest: List[Int], confirmed: Long = 0, last: Long = 0): Int = rest match case Nil => if predicate(confirmed + last) then 1 else 0 case h::Nil => enumerate(Nil, confirmed, last * 10 + h) case h::t => enumerate(t, confirmed, last * 10 + h) + enumerate(t, confirmed + last * 10 + h, 0) enumerate(digits) @main def main = val expr = readLine().map(_.asDigit).toList val result = countExpression(expr){isPrime} println(result)