import scala.annotation.tailrec
import scala.collection.mutable

object Main extends App {

  val mod = 1000000007L
  import scala.io.StdIn._
  readLine.trim.toList match {
    case e Expression t ⇒ println(e.patternOfTrue)
    case _ ⇒ ???
  }
  object Expression{
    def unapply(arg: List[Char]): Option[(BoolExpression, List[Char])] = {
      arg match {
        case t Term r ⇒ Some(takeAll(r, List(t)))
        case _ ⇒ None
      }
    }
    private[this] def construct(array: Array[BoolExpression], from: Int, until: Int): BoolExpression = {
      if (from + 1 == until) array(from)
      else Or(construct(array, from, (from + until) / 2), construct(array, (from + until) / 2, until))
    }
    @tailrec
    private[this] def takeAll(arg: List[Char], result: List[BoolExpression]): (BoolExpression, List[Char]) = {
      arg match {
        case '|'::(f Term t) ⇒ takeAll(t, f::result)
        case _ ⇒ val array = result.toArray
          (construct(array, 0, array.length), arg)
      }
    }
  }
  object Term {
    def unapply(arg: List[Char]): Option[(BoolExpression, List[Char])] = {
      arg match {
        case f Factor t ⇒ Some(takeAll(t, List(f)))
        case _ ⇒ None
      }
    }
    private[this] def construct(array: Array[BoolExpression], from: Int, until: Int): BoolExpression = {
      if (from + 1 == until) array(from)
      else And(construct(array, from, (from + until) / 2), construct(array, (from + until) / 2, until))
    }
    @tailrec
    private[this] def takeAll(arg: List[Char], result: List[BoolExpression]): (BoolExpression, List[Char]) = {
      arg match {
        case '&'::(f Factor t) ⇒ takeAll(t, f::result)
        case _ ⇒ val array = result.toArray
          (construct(array, 0, array.length), arg)
      }
    }
  }
  object Factor {
    def unapply(arg: List[Char]): Option[(BoolExpression, List[Char])] = {
      arg match {
        case v Variable t ⇒ Some(v, t)
        case '~'::(v Factor t) ⇒ Some(Negate(v), t)
        case '('::(e Expression ')'::t) ⇒ Some(e, t)
        case _ ⇒ None
      }
    }
  }
  object Variable {
    def unapply(arg: List[Char]): Option[(BoolExpression, List[Char])] = {
      arg match {
        case 'x'::t ⇒ Some(BoolVariable, t.dropWhile(_.isDigit))
        case _ ⇒ None
      }
    }
  }
  sealed trait BoolExpression {
    val wholePattern: Long
    val patternOfTrue: Long
    val patternOfFalse: Long
  }
  case class And(left: BoolExpression, right: BoolExpression) extends BoolExpression {
    override val wholePattern: Long = left.wholePattern * right.wholePattern % mod
    override val patternOfTrue: Long = left.patternOfTrue * right.patternOfTrue % mod
    override val patternOfFalse: Long = (wholePattern - patternOfTrue + mod) % mod
  }
  case class Or(left: BoolExpression, right: BoolExpression) extends BoolExpression {
    override val wholePattern: Long = left.wholePattern * right.wholePattern % mod
    override val patternOfFalse: Long = left.patternOfFalse * right.patternOfFalse % mod
    override val patternOfTrue: Long = (wholePattern - patternOfFalse + mod) % mod
  }
  case class Negate(factor: BoolExpression) extends BoolExpression {
    override val wholePattern: Long = factor.wholePattern
    override val patternOfTrue: Long = factor.patternOfFalse
    override val patternOfFalse: Long = factor.patternOfTrue
  }
  object BoolVariable extends BoolExpression {
    override val wholePattern: Long = 2
    override val patternOfTrue: Long = 1
    override val patternOfFalse: Long = 1
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}
