import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim match {
      case "#" ⇒ return
      case Expression(e) ⇒ println(e.calculate.distinct.length)
        loop()
    }
  }
}
object Expression {
  def unapply(arg: String): Option[Expression] = {
    arg.toList match {
      case e Expr Nil ⇒ Some(e)
      case _ ⇒ ???
    }
  }

  object Expr {
    def unapply(arg: List[Char]): Option[(Expression, List[Char])] = {
      arg match {
        case t Term r ⇒
          r match {
            case o Operator (e Expr rest) ⇒ Some(Expression(o::e.operator, t::e.term), rest)
            case _ ⇒ Some(Expression(Nil, List(t)), r)
          }
        case _ ⇒ None
      }
    }
  }
  object Operator{
    def unapply(arg: List[Char]): Option[(Operator, List[Char])] = {
      arg match {
        case '+'::r ⇒ Some(Add, r)
        case '-'::r ⇒ Some(Sub, r)
        case '*'::r ⇒ Some(Mul, r)
        case '/'::r ⇒ Some(Div, r)
        case _ ⇒ None
      }
    }
  }
  object Number {
    def unapply(arg: List[Char]): Option[(Int, List[Char])] = {
      arg.span(_.isDigit) match {
        case (Nil, _) ⇒ None
        case (n, r) ⇒ Some(n.foldLeft(0){case (c, d) ⇒ c * 10 + d.asDigit}, r)
      }
    }
  }
  object Term{
    def unapply(arg: List[Char]): Option[(Term, List[Char])] = {
      arg match {
        case '('::(e Expr ')'::r) ⇒ Some(Bracket(e), r)
        case n Number r ⇒ Some(Num(n), r)
        case _ ⇒ None
      }
    }
  }
}
sealed trait Term {
  def calculate: List[Int]
}
case class Expression(operator: List[Operator], term: List[Term]) extends Term {
  private def calculate(op: List[Operator], te: List[Term], priority: Int): (List[Operator], List[Term]) = {
    (priority, op, te) match {
      case (0, o::or, a::b::tr) ⇒(or, Calculated(o(a, b))::tr)
      case (p, o::or, t::tr) ⇒ calculate(or, tr, p - 1) match {case (orr, brr) ⇒ (o::orr, t::brr)}
      case _ ⇒ ???
    }
  }

  override lazy val calculate: List[Int] = {
    val memo = Array.tabulate(1 << operator.length){i ⇒ Array.fill(term.length - i.toBinaryString.count(_ == '1')){mutable.Set[Int]()}}
    val op = operator.toArray
    memo(0) = term.map{t ⇒ mutable.Set(t.calculate:_*)}.toArray
    for (from ← memo.indices) {
      val rest = op.indices.filter(i ⇒ (from & (1 << i)) == 0)
      for (i ← rest.indices) {
        val to = from | (1 << rest(i))
        for (j ← 0 until i) {
          memo(to)(j) ++= memo(from)(j)
        }
        memo(to)(i) ++= op(rest(i))(memo(from)(i), memo(from)(i + 1))
        for (j ← i + 2 until memo(from).length) {
          memo(to)(j - 1) ++= memo(from)(j)
        }
      }
    }
    memo.last.head.toList
  }
}
case class Bracket(term: Term) extends Term {
  override def calculate :List[Int] = term.calculate
}
case class Num(number: Int) extends Term {
  override def calculate: List[Int] = List(number)
}
case class Calculated(override val calculate: List[Int]) extends Term
sealed trait Operator {
  def apply(left: Term, right: Term): List[Int]
  def apply(left: Iterable[Int], right: Iterable[Int]): Iterable[Int]
}
object Add extends Operator {
  override def apply(left: Term, right: Term): List[Int] = left.calculate.flatMap(l ⇒ right.calculate.map(r ⇒ l + r)).distinct

  override def apply(left: Iterable[Int], right: Iterable[Int]): Iterable[Int] = left.flatMap(l ⇒ right.map(r ⇒ l + r))
}
object Sub extends Operator {
  override def apply(left: Term, right: Term): List[Int] = left.calculate.flatMap(l ⇒ right.calculate.map(r ⇒ l - r)).distinct

  override def apply(left: Iterable[Int], right: Iterable[Int]): Iterable[Int] = left.flatMap(l ⇒ right.map(r ⇒ l - r))
}
object Mul extends Operator {
  override def apply(left: Term, right: Term): List[Int] = left.calculate.flatMap(l ⇒ right.calculate.map(r ⇒ l * r)).distinct

  override def apply(left: Iterable[Int], right: Iterable[Int]): Iterable[Int] = left.flatMap(l ⇒ right.map(r ⇒ l * r))
}
object Div extends Operator {
  override def apply(left: Term, right: Term): List[Int] = left.calculate.flatMap(l ⇒ right.calculate.filterNot(_ == 0).map(r ⇒ l / r)).distinct

  override def apply(left: Iterable[Int], right: Iterable[Int]): Iterable[Int] = left.flatMap(l ⇒ right.filterNot(_ == 0).map(r ⇒ l / r))
}

