import javax.swing.tree.TreeCellEditor

import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val deck = List(Spade, Hart, Clover, Dia).flatMap(s ⇒ (2 to 14).map(n ⇒ new Card(s, n))).toArray
  loop()
  @tailrec def loop(): Unit = {
    readLine.trim match {
      case "#" ⇒ return
      case arg ⇒
        val first = arg.split(' ').map(Card(_)).toList
        val opponent = readLine.trim.split(' ').map(Card(_)).toList
        val community = readLine.trim.split(' ').map(Card(_)).toList
        val rest = deck.indices.filterNot(i ⇒ first.contains(deck(i)) || opponent.contains(deck(i)) || community.contains(deck(i))).toArray
        val firstHand = first:::community
        val firstKind = new Hand(firstHand).kind
        val opponentHand = opponent:::community
        val opponentKind = new Hand(opponentHand).kind
        val useSingleFirst = rest.indices.map{i ⇒ List(firstKind, maxHandUseOne(firstHand, deck(rest(i)))).max}.toArray
        val useSingleOpponent = rest.indices.map{i ⇒ List(opponentKind, maxHandUseOne(opponentHand, deck(rest(i)))).max}
        val winCount = rest.indices.map(i ⇒ (0 until i).count(j ⇒ List(maxHandUseTwo(firstHand, List(deck(rest(i)), deck(rest(j)))), useSingleFirst(i), useSingleFirst(j)).max > List(maxHandUseTwo(opponentHand, List(deck(rest(i)), deck(rest(j)))), useSingleOpponent(i), useSingleOpponent(j)).max)).sum
        println(f"${winCount / 45.0 / 22}%.10f")
        loop()
    }
  }
  def canWin(self: List[Card], opponent: List[Card], community: List[Card]): Boolean = {
    maxHand(self, community) > maxHand(opponent, community)
  }
  def maxHand(hand: List[Card], community: List[Card]): Kind = {
    List(community.combinations(3).map(rest ⇒ new Hand(rest ::: hand).kind).max, community.combinations(4).map(rest ⇒ hand.map(c ⇒ new Hand(c::rest).kind).max).max, new Hand(community).kind).max
  }
  def maxHandUseOne(hand: List[Card], additional: Card): Kind = {
    hand.combinations(4).map(rest ⇒ new Hand(additional :: rest).kind).max
  }
  def maxHandUseTwo(hand: List[Card], additional: List[Card]): Kind = {
    hand.combinations(3).map(rest ⇒ new Hand(additional:::rest).kind).max
  }

  implicit class AnyWrap[T](val value: T) extends AnyVal {
    def pipe(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

sealed trait Suit
case object Spade extends Suit
case object Hart extends Suit
case object Clover extends Suit
case object Dia extends Suit
object Card {
  def apply(expr: String): Card = {
    new Card(parseSuit(expr(0)), parseNumber(expr(1)))
  }
  def parseSuit(char: Char): Suit = {
    char match {
      case 'S' ⇒ Spade
      case 'H' ⇒ Hart
      case 'C' ⇒ Clover
      case 'D' ⇒ Dia
      case _ ⇒ ???
    }
  }
  def parseNumber(char: Char): Int = {
    char match {
      case 'A' ⇒ 14
      case 'T' ⇒ 10
      case 'J' ⇒ 11
      case 'Q' ⇒ 12
      case 'K' ⇒ 13
      case _ ⇒ char.asDigit
    }
  }
}
case class Card(val suit: Suit, val number: Int) {
  override def equals(obj: Any): Boolean = {
    obj match {
      case card: Card ⇒ suit == card.suit && number == card.number
      case _ ⇒ super.equals(obj)
    }
  }
}
abstract sealed class Kind(val rank: Int) extends Ordered[Kind] {
  override def compare(that: Kind): Int = {
    if (rank == that.rank) compareWithSameRank(that)
    else rank.compareTo(that.rank)
  }
  protected def compareWithSameRank(that: Kind): Int
}
object Kind {
  implicit class Wrap[T: Ordering](val list: List[T]) extends Ordered[List[T]] {
    override def compare(that: List[T]): Int = {
      compareRecursive(list.sorted(implicitly[Ordering[T]].reverse), that.sorted(implicitly[Ordering[T]].reverse))
    }
    @tailrec private[this] def compareRecursive(a: List[T], b: List[T]): Int = {
      (a, b) match {
        case (Nil, Nil) ⇒ 0
        case (_, Nil) ⇒ -1
        case (Nil, _) ⇒ 1
        case (ah::at, bh::bt) if implicitly[Ordering[T]].compare(ah, bh) == 0 ⇒ compareRecursive(at, bt)
        case (ah::_, bh::_) ⇒ implicitly[Ordering[T]].compare(ah, bh)
      }
    }
  }
}
case object RoyalStraitFlush extends Kind(9) {
  override protected def compareWithSameRank(that: Kind): Int = 0
}
case class StraightFlush(highest: Int) extends Kind(8) {
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: StraightFlush ⇒ highest.compare(that.highest)
      case _ ⇒ ???
    }
  }
}
case class FourCard(pair: Int, other: Int) extends Kind(7) {
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: FourCard ⇒
        pair.compare(that.pair) match {
          case 0 ⇒ other.compare(that.other)
          case c ⇒ c
        }
      case _ ⇒ ???
    }
  }
}
case class FullHouse(triple: Int, pair: Int) extends Kind(6) {
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: FullHouse ⇒
        triple.compare(that.triple) match {
          case 0 ⇒ pair.compare(that.pair)
          case c ⇒ c
        }
      case _ ⇒ ???
    }
  }
}
case class Flush(cards: List[Int]) extends Kind(5) {
  import Kind._
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: Flush ⇒ cards.compare(that.cards)
      case _ ⇒ ???
    }
  }
}
case class Straight(highest: Int) extends Kind(4) {
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: Straight ⇒ highest.compare(that.highest)
      case _ ⇒ ???
    }
  }
}
case class ThreeCard(triple: Int, others: List[Int]) extends Kind(3) {
  import Kind._
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: ThreeCard ⇒
        triple.compare(that.triple) match {
          case 0 ⇒ others.compare(that.others)
          case c ⇒ c
        }
      case _ ⇒ ???
    }
  }
}
case class TwoPair(pairs: List[Int], other: Int) extends Kind(2) {
  import Kind._
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: TwoPair ⇒ pairs.compare(that.pairs) match {
        case 0 ⇒ other.compare(that.other)
        case c ⇒ c
      }
      case _ ⇒ ???
    }
  }
}
case class OnePair(pair: Int, others: List[Int]) extends Kind(1) {
  import Kind._
  override protected def compareWithSameRank(that: Kind): Int = {
    that match {
      case that: OnePair ⇒ if (pair == that.pair) others.compare(that.others)
        else pair.compare(that.pair)
      case _ ⇒ ???
    }
  }
}
case class HighCard(cards: List[Int]) extends Kind(0) {
  import Kind._
  override protected def compareWithSameRank(that: Kind): Int = cards.compare(that.asInstanceOf[HighCard].cards)
}

class Hand(val cards: List[Card]) {
  def kind: Kind = {
    asRoyalStraitFlush.orElse{
      asStraightFlush
    }.orElse{
      asFourCard
    }.orElse{
      asFullHouse
    }.orElse{
      asFlush
    }.orElse{
      asStraight
    }.orElse{
      asThreeCard
    }.orElse{
      asTwoPair
    }.orElse{
      asPair
    }.getOrElse{
      asHighCard
    }
  }
  def asRoyalStraitFlush: Option[RoyalStraitFlush.type] = {
    asStraight match {
      case Some(Straight(14)) if asFlush.isDefined ⇒ Some(RoyalStraitFlush)
      case _ ⇒ None
    }
  }
  def asStraightFlush: Option[StraightFlush] = {
    asStraight match {
      case Some(p) if asFlush.isDefined ⇒ Some(StraightFlush(p.highest))
      case _ ⇒ None
    }
  }
  def asFourCard: Option[FourCard] = {
    cards.groupBy(_.number).toList.sortBy(_._2.length) match {
      case a::b::Nil if b._2.length == 4 ⇒ Some(FourCard(b._1, a._1))
      case _ ⇒ None
    }
  }
  def asFullHouse: Option[FullHouse] = {
    cards.groupBy(_.number).toList.sortBy(_._2.length) match {
      case a::b::Nil if a._2.length == 2 ⇒ Some(FullHouse(b._1, a._1))
      case _ ⇒ None
    }
  }
  def asFlush: Option[Flush] = {
    if (cards.forall(_.suit == cards.head.suit)) Some(Flush(cards.map(_.number).sorted(Ordering.Int.reverse)))
    else None
  }
  def asStraight: Option[Straight] = {
    cards.sortBy(_.number) match {
      case sorted@(min::rest) ⇒
        if (sorted.zip(rest).forall(a => a._2.number - a._1.number == 1)) Some(Straight(cards.maxBy(_.number).number))
        else if (min.number == 2 && List(3, 4, 5, 14).forall(a ⇒ rest.map(_.number).contains(a))) Some(Straight(5))
        else None
      case _ ⇒ None
    }
  }
  def asThreeCard: Option[ThreeCard] = {
    cards.groupBy(_.number).toList.sortBy(_._2.length) match {
      case a::b::c::Nil if c._2.length == 3 ⇒ Some(ThreeCard(c._1, List(a._1, b._1).sorted(Ordering.Int.reverse)))
      case _ ⇒ None
    }
  }
  def asTwoPair: Option[TwoPair] = {
    cards.groupBy(_.number).toList.sortBy(_._2.length) match {
      case a::b::c::Nil if b._2.length == 2 && c._2.length == 2 ⇒ Some(TwoPair(List(b._1, c._1).sorted(Ordering.Int.reverse), a._1))
      case _ ⇒ None
    }
  }
  def asPair: Option[OnePair] = {
    cards.groupBy(_.number).toList.sortBy(_._2.length) match {
      case a::b::c::d::Nil if d._2.length == 2 ⇒ Some(OnePair(d._1, List(a._1, b._1, c._1).sorted(Ordering.Int.reverse)))
      case _ ⇒ None
    }
  }
  def asHighCard: HighCard = HighCard(cards.map(_.number).sorted(Ordering.Int.reverse))
}


Measured memory_bytes: 607332