import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  val stripes = Array.tabulate(n){_ ⇒
    readLine.trim.split(' ').tail.map(_.toInt).foldLeft(Stripe.default){case (acc, c) ⇒ acc.addBorder(c)}.toReplace
  }.groupBy(_.loopLength())
  if (stripes.contains(1) || stripes.get(2).exists(_.length > 3) || stripes.get(3).exists(_.length > 2)) {
    println("yes")
  }else {
    println(
      if (stripes.toArray.flatMap(_._2).permutations.exists(a ⇒ a.tail.scan(a.head){case (acc, r) ⇒ acc + r}.exists(_.isId))) "yes" else "no"
    )
  }
  object Stripe {
    def default: Stripe = Stripe(0, 1, 2)
  }
  case class Stripe(left: Int, mid: Int, right: Int) {
    def addBorder(position: Int): Stripe = position match {
      case 0 ⇒ Stripe(mid, left ,right)
      case 1 ⇒ Stripe(left, right, mid)
      case _ ⇒ ???
    }
    def toReplace = Replace(Array(left, mid, right))
  }
  case class Replace(array: Array[Int]) {
    def loopLength(): Int = {
      val isVisit = Array.fill(array.length){false}
      var max = 0
      for (i ← array.indices if !isVisit(i)) {
        var current = i
        var count = 0
        while(!isVisit(current)){
          count += 1
          isVisit(current) = true
          current = array(current)
        }
        if (max < count) max = count
      }
      max
    }
    def +(that: Replace): Replace = Replace(that.array.map(array))
    def isId: Boolean = array.indices.forall(i ⇒ array(i) == i)
  }
}
