object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val stones = in.take(n).map(_.split(' ').map(_.toInt).sorted.reverse).toArray
  val map = stones.indices.foldLeft(Map.empty[(Int, Int), List[(Int, Int)]]) {
    case (map, i) =>
      val Array(a, b, c) = stones(i)
      if (a != b && b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((a, c) -> ((b -> i) :: map.getOrElse((a, c), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (a != b)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil)))
  }.map(i => i._1 -> i._2.sortBy(_._1).reverse)

  val oneStoneSolution = stones.indices.maxBy(i => stones(i).last)
  val twoStoneSolution = stones.indices.flatMap{ i =>
    val Array(a, b, c) = stones(i)
    List((a, b, c), (b, c, a), (a, c, b))
      .flatMap(pair => map((pair._1, pair._2)).find(j => j._2 != i).map(el => Math.min(pair._2, pair._3 + el._1) -> (i, el._2)))
  }

  if (twoStoneSolution.nonEmpty) {
    val twoStoneS = twoStoneSolution.maxBy(_._1)
    if (twoStoneS._1 > stones(oneStoneSolution).min) {
      println(2)
      println(s"${twoStoneS._2._1 + 1} ${twoStoneS._2._2 + 1}")
    }
    else {
      println(1)
      println(s"${oneStoneSolution + 1}")
    }
  }
  else {
    println(1)
    println(s"${oneStoneSolution + 1}")
  }

}

import java.io._

import scala.util._

object Main {

  def main(args: Array[String]) = {

    var debug: Object => Unit = null

    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST =
        """
          |7
          |10 7 8
          |5 10 3
          |4 2 6
          |5 5 5
          |10 2 8
          |4 2 1
          |7 7 7
          |""".stripMargin.trim

      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }

    val input = scala.io.Source.stdin.getLines()

    input.next()
    val ps = input.toSeq.map(_.split(' ').map(_.toInt).toSeq.sorted)

    val hash = scala.collection.mutable.HashMap.empty[(Int, Int), Seq[Int]]

    def put(k: (Int, Int), p: Int) = {
      hash.get(k) match {
        case None => hash.put(k, Seq(p))
        case Some(a) =>
          if (a.length >= 2) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else if (a(1) < p) hash.put(k, Seq(a(0), p))
          } else if (a.length == 1) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else hash.put(k, Seq(a(0), p))
          }
      }
    }
    for (p <- ps) {
      val k1 = (p(0), p(1))
      val p1 = p(2)
      val k2 = (p(0), p(2))
      val p2 = p(1)
      val k3 = (p(1), p(2))
      val p3 = p(0)
      put(k1, p1)
      if (k2 != k1) put(k2, p2)
      if (k3 != k1 && k3 != k2) put(k3, p3)
    }

    val pair = hash.maxBy(e=> Seq(e._1._1, e._1._2, e._2.sum).min)

    val first = ps.indexOf(Seq(pair._1._1, pair._1._2, pair._2(0)).sorted)

    debug(pair)
    debug(Seq(pair._1._1, pair._1._2, pair._2(0)).mkString)
    debug(first + "")

    val sol = if (pair._2.size == 2) {
      val second = ps.zipWithIndex.find(p => p._1 == Seq(pair._1._1, pair._1._2, pair._2(1)).sorted && p._2 != first).get._2
      "2\n" + (first + 1) + " " + (second + 1)
    } else {
      "1\n" + (first + 1)
    }

    println(sol)
  }
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val stones = in.take(n).map(_.split(' ').map(_.toInt).sorted).toArray
  val map = stones.indices.foldLeft(Map.empty[(Int, Int), List[(Int, Int)]]) {
    case (map, i) =>
      val Array(a, b, c) = stones(i)
      if (a != b && b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((a, c) -> ((b -> i) :: map.getOrElse((a, c), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (a != b)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil)))
  }.map(i => i._1 -> i._2.sortBy(_._1).reverse)

  val oneStoneSolution = stones.indices.maxBy(i => stones(i).last)
  val twoStoneSolution = stones.indices.flatMap{ i =>
    val Array(a, b, c) = stones(i)
    List((a, b, c), (b, c, a), (a, c, b))
      .flatMap(pair => map((pair._1, pair._2)).find(j => j._2 != i).map(el => Math.min(pair._2, pair._3 + el._1) -> (i, el._2)))
  }

  if (twoStoneSolution.nonEmpty) {
    val twoStoneS = twoStoneSolution.maxBy(_._1)
    if (twoStoneS._1 > stones(oneStoneSolution).min) {
      println(2)
      println(s"${twoStoneS._2._1 + 1} ${twoStoneS._2._2 + 1}")
    }
    else {
      println(1)
      println(s"${oneStoneSolution + 1}")
    }
  }
  else {
    println(1)
    println(s"${oneStoneSolution + 1}")
  }

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val stones = in.take(n).map(_.split(' ').map(_.toInt).sorted).toArray
  val map = stones.indices.foldLeft(Map.empty[(Int, Int), List[(Int, Int)]]) {
    case (map, i) =>
      val Array(a, b, c) = stones(i)
      if (a != b && b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((a, c) -> ((b -> i) :: map.getOrElse((a, c), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (a != b)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil)))
  }.map(i => i._1 -> i._2.sortBy(_._1))

  val oneStoneSolution = stones.indices.maxBy(i => stones(i).last)
  val twoStoneSolution = stones.indices.flatMap{ i =>
    val Array(a, b, c) = stones(i)
    List((a, b, c), (b, c, a), (a, c, b))
      .flatMap(pair => map((pair._1, pair._2)).find(j => j._2 != i).map(el => Math.min(pair._2, pair._2 + el._1) -> (i, el._2)))
  }

  if (twoStoneSolution.nonEmpty) {
    val twoStoneS = twoStoneSolution.maxBy(_._1)
    if (twoStoneS._1 > stones(oneStoneSolution).min) {
      println(2)
      println(s"${twoStoneS._2._1 + 1} ${twoStoneS._2._2 + 1}")
    }
    else {
      println(1)
      println(s"${oneStoneSolution + 1}")
    }
  }
  else {
    println(1)
    println(s"${oneStoneSolution + 1}")
  }

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val stones = in.take(n).map(_.split(' ').map(_.toInt).sorted).toArray
  val map = stones.indices.foldLeft(Map.empty[(Int, Int), List[(Int, Int)]]) {
    case (map, i) =>
      val Array(a, b, c) = stones(i)
      if (a != b && b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((a, c) -> ((b -> i) :: map.getOrElse((a, c), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (a != b)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else if (b != c)
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil))) +
          ((b, c) -> ((a -> i) :: map.getOrElse((b, c), Nil)))
      else
        map +
          ((a, b) -> ((c -> i) :: map.getOrElse((a, b), Nil)))
  }.map(i => i._1 -> i._2.sortBy(_._1).reverse)

  val oneStoneSolution = stones.indices.maxBy(i => stones(i).last)
  val twoStoneSolution = stones.indices.flatMap{ i =>
    val Array(a, b, c) = stones(i)
    List((a, b, c), (b, c, a), (a, c, b))
      .flatMap(pair => map((pair._1, pair._2)).find(j => j._2 != i).map(el => Math.min(pair._2, pair._2 + el._1) -> (i, el._2)))
  }

  if (twoStoneSolution.nonEmpty) {
    val twoStoneS = twoStoneSolution.maxBy(_._1)
    if (twoStoneS._1 > stones(oneStoneSolution).min) {
      println(2)
      println(s"${twoStoneS._2._1 + 1} ${twoStoneS._2._2 + 1}")
    }
    else {
      println(1)
      println(s"${oneStoneSolution + 1}")
    }
  }
  else {
    println(1)
    println(s"${oneStoneSolution + 1}")
  }

}

import java.io._

import scala.util._

object Main {

  def main(args: Array[String]) = {

    var debug: Object => Unit = null

    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST =
        """
          |7
          |10 7 8
          |5 10 3
          |4 2 6
          |5 5 5
          |10 2 8
          |4 2 1
          |7 7 7
          |""".stripMargin.trim

      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }

    val input = scala.io.Source.stdin.getLines()

    input.next()
    val ps = input.toSeq.map(_.split(' ').map(_.toInt).toSeq.sorted)

    val hash = scala.collection.mutable.HashMap.empty[(Int, Int), Seq[Int]]

    def put(k: (Int, Int), p: Int) = {
      hash.get(k) match {
        case None => hash.put(k, Seq(p))
        case Some(a) =>
          if (a.length >= 2) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else if (a(1) < p) hash.put(k, Seq(a(0), p))
          } else if (a.length == 1) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else hash.put(k, Seq(a(0), p))
          }
      }
    }
    for (p <- ps) {
      val k1 = (p(0), p(1))
      val p1 = p(2)
      val k2 = (p(0), p(2))
      val p2 = p(1)
      val k3 = (p(1), p(2))
      val p3 = p(0)
      put(k1, p1)
      if (k2 != k1) put(k2, p2)
      if (k3 != k1 && k3 != k2) put(k3, p3)
    }

    val pair = hash.maxBy(e=> e._1._1 * e._1._2 * (e._2.sum))

    val first = ps.indexOf(Seq(pair._1._1, pair._1._2, pair._2(0)).sorted)

    debug(pair)
    debug(Seq(pair._1._1, pair._1._2, pair._2(0)).mkString)
    debug(first + "")

    val sol = if (pair._2.size == 2) {
      val second = ps.zipWithIndex.find(p => p._1 == Seq(pair._1._1, pair._1._2, pair._2(1)).sorted && p._2 != first).get._2
      "2\n" + (first + 1) + " " + (second + 1)
    } else {
      "1\n" + (first + 1)
    }

    println(sol)
  }
}

import java.io._

import scala.util._

object Main {

  def main(args: Array[String]) = {

    var debug: Object => Unit = null

    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST =
        """
          |7
          |10 7 8
          |5 10 3
          |4 2 6
          |5 5 5
          |10 2 8
          |4 2 1
          |7 7 7
          |""".stripMargin.trim

      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }

    val input = scala.io.Source.stdin.getLines()

    input.next()
    val ps = input.toSeq.map(_.split(' ').map(_.toInt).toSeq.sorted)

    if (ps.length > 72483) {
      println(ps(26990))
      println(ps(72482))
      println(ps(57878))
      println(ps(17744))
    }

    val hash = scala.collection.mutable.HashMap.empty[(Int, Int), Seq[Int]]

    def put(k: (Int, Int), p: Int) = {
      hash.get(k) match {
        case None => hash.put(k, Seq(p))
        case Some(a) =>
          if (a.length >= 2) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else if (a(1) < p) hash.put(k, Seq(a(0), p))
          } else if (a.length == 1) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else hash.put(k, Seq(a(0), p))
          }
      }
    }
    for (p <- ps) {
      val k1 = (p(0), p(1))
      val p1 = p(2)
      val k2 = (p(0), p(2))
      val p2 = p(1)
      val k3 = (p(1), p(2))
      val p3 = p(0)
      put(k1, p1)
      if (k2 != k1) put(k2, p2)
      if (k3 != k1 && k3 != k2) put(k3, p3)
    }

    val pair = hash.maxBy(e=> e._1._1 * e._1._2 * (e._2.sum))

    val first = ps.indexOf(Seq(pair._1._1, pair._1._2, pair._2(0)).sorted)

    debug(pair)
    debug(Seq(pair._1._1, pair._1._2, pair._2(0)).mkString)
    debug(first + "")

    val sol = if (pair._2.size == 2) {
      val second = ps.zipWithIndex.find(p => p._1 == Seq(pair._1._1, pair._1._2, pair._2(1)).sorted && p._2 != first).get._2
      "2\n" + (first + 1) + " " + (second + 1)
    } else {
      "1\n" + (first + 1)
    }

    println(sol)
  }
}

import java.io._

import scala.util._

object Main {

  def main(args: Array[String]) = {

    var debug: Object => Unit = null

    if (!args.isEmpty && args.head == "test") {
      debug = println
      val TEST =
        """
          |7
          |10 7 8
          |5 10 3
          |4 2 6
          |5 5 5
          |10 2 8
          |4 2 1
          |7 7 7
          |""".stripMargin.trim

      System.setIn(new ByteArrayInputStream(TEST.getBytes))
    } else {
      debug = a => Unit
    }

    val input = scala.io.Source.stdin.getLines()

    input.next()
    val ps = input.toSeq.map(_.split(' ').map(_.toInt).toSeq.sorted)

    if (ps.length > 72483) {
      println(ps(26990))
      println(ps(72482))
    }

    val hash = scala.collection.mutable.HashMap.empty[(Int, Int), Seq[Int]]

    def put(k: (Int, Int), p: Int) = {
      hash.get(k) match {
        case None => hash.put(k, Seq(p))
        case Some(a) =>
          if (a.length >= 2) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else if (a(1) < p) hash.put(k, Seq(a(0), p))
          } else if (a.length == 1) {
            if (a(0) < p) hash.put(k, Seq(p, a(0)))
            else hash.put(k, Seq(a(0), p))
          }
      }
    }
    for (p <- ps) {
      val k1 = (p(0), p(1))
      val p1 = p(2)
      val k2 = (p(0), p(2))
      val p2 = p(1)
      val k3 = (p(1), p(2))
      val p3 = p(0)
      put(k1, p1)
      if (k2 != k1) put(k2, p2)
      if (k3 != k1 && k3 != k2) put(k3, p3)
    }

    val pair = hash.maxBy(e=> e._1._1 * e._1._2 * (e._2.sum))

    val first = ps.indexOf(Seq(pair._1._1, pair._1._2, pair._2(0)).sorted)

    debug(pair)
    debug(Seq(pair._1._1, pair._1._2, pair._2(0)).mkString)
    debug(first + "")

    val sol = if (pair._2.size == 2) {
      val second = ps.zipWithIndex.find(p => p._1 == Seq(pair._1._1, pair._1._2, pair._2(1)).sorted && p._2 != first).get._2
      "2\n" + (first + 1) + " " + (second + 1)
    } else {
      "1\n" + (first + 1)
    }

    println(sol)
  }
}


object main extends App with fastIO {

  val Array(n, k) = readLine split(" ") map(_.toInt)
  println(readLine.split(" ").map(_.toInt).count( x => 5 - x >= k) / 3)

  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt).filter(_ <= 5 - k)
  println(data.length / 3)
}

import java.util.Scanner
import java.io._

object A {

  val TEST = false

  val in = new java.util.Scanner(System.in)

  def nextInt = in.next().toInt

  def main(args: Array[String]) {
    val n = nextInt
    val k = nextInt

    val arr = Array.ofDim[Int](n)

    for (i <- 0 until n) {
      arr(i) = nextInt
    }

    val limit = 5 - k
    val eligible = arr.filter(_ <= limit).length / 3
    println(eligible)
  }

}

import java.util.StringTokenizer

object _432A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val k = next.toInt
  val a = (1 to n).map(i => next.toInt).filter(i => i <= 5 - k)
  val ans = a.length / 3
  println(ans)
}

/**
 * Created by andrew on 15.5.14.
 */
import io.Source
import java.io.PrintWriter

object cf432a {

  def solve(in: In, out: PrintWriter) {
    val n = in().toInt
    val k = in().toInt
    var sum = 0
    for (i <- 1 to n) {
      val x = in().toInt
      if (5 - x >= k) sum += 1
    }
    out.print(sum / 3)
  }

  def main(args: Array[String]) {
    new Thread(null, new Runnable {
      override def run(): Unit = {
        val in = new In(Source.fromInputStream(System.in))
        val out = new PrintWriter(System.out)
        solve(in, out)
        out.close()
      }
    }, "cf432a", 64000000).run()
  }

  class TokenIterator(iter: BufferedIterator[Char], delim: String) extends Iterator[String] {
    private val sb = new StringBuilder

    def hasNext: Boolean = {
      skipDelims()
      iter.hasNext
    }

    def skipDelims() = {
      while (iter.hasNext && delim.indexOf(iter.head) != -1) {
        iter.next()
      }
    }

    def next() = {
      skipDelims()

      while (iter.hasNext && delim.indexOf(iter.head) == -1) {
        sb.append(iter.next)
      }

      val ret = sb.toString()
      sb.clear()

      ret
    }
  }

  class In(source: Source) {
    val iter = source.buffered

    val tokenIter = new TokenIterator(iter, " \n\r");

    def apply() = tokenIter.next()
  }
}

/**
 * Created by andrew on 15.5.14.
 */
import io.Source
import java.io.PrintWriter

object cf432a {

  def solve(in: In, out: PrintWriter) {
    val n = in().toInt
    val k = in().toInt
    val ans = in(n).map(x => x.toInt).filter(x => 5 - x >= k).size / 3
    out.print(ans)
  }

  def main(args: Array[String]) {
    new Thread(null, new Runnable {
      override def run(): Unit = {
        val in = new In(Source.fromInputStream(System.in))
        val out = new PrintWriter(System.out)
        solve(in, out)
        out.close()
      }
    }, "cf432a", 64000000).run()
  }

  class TokenIterator(iter: BufferedIterator[Char], delim: String) extends Iterator[String] {
    private val sb = new StringBuilder

    def hasNext: Boolean = {
      skipDelims()
      iter.hasNext
    }

    def skipDelims() = {
      while (iter.hasNext && delim.indexOf(iter.head) != -1) {
        iter.next()
      }
    }

    def next() = {
      skipDelims()

      while (iter.hasNext && delim.indexOf(iter.head) == -1) {
        sb.append(iter.next)
      }

      val ret = sb.toString()
      sb.clear()

      ret
    }
  }

  class In(source: Source) {
    val iter = source.buffered

    val tokenIter = new TokenIterator(iter, " \n\r");

    def apply() = tokenIter.next()

    def apply(n: Int) = tokenIter.take(n)
  }
}

/**
 * Created by andrew on 15.5.14.
 */
import io.Source
import java.io.PrintWriter

object cf432a {

  def solve(in: In, out: PrintWriter) {
    val n = in().toInt
    val k = in().toInt
    var sum = 0
    for (i <- 1 to n) {
      val x = in().toInt
      if (5 - x >= k) sum += 1
    }
    out.print(sum / 3)
  }

  def main(args: Array[String]) {
    /*new Thread(null, new Runnable {
      override def run(): Unit = {
        val in = new In(Source.fromInputStream(System.in))
        val out = new PrintWriter(System.out)
        solve(in, out)
        out.close()
      }
    }, "cf432a", 64000000).run()*/
    val in = new In(Source.fromInputStream(System.in))
    val out = new PrintWriter(System.out)
    solve(in, out)
    out.close()
  }

  class TokenIterator(iter: BufferedIterator[Char], delim: String) extends Iterator[String] {
    private val sb = new StringBuilder

    def hasNext: Boolean = {
      skipDelims()
      iter.hasNext
    }

    def skipDelims() = {
      while (iter.hasNext && delim.indexOf(iter.head) != -1) {
        iter.next()
      }
    }

    def next() = {
      skipDelims()

      while (iter.hasNext && delim.indexOf(iter.head) == -1) {
        sb.append(iter.next)
      }

      val ret = sb.toString()
      sb.clear()

      ret
    }
  }

  class In(source: Source) {
    val iter = source.buffered

    val tokenIter = new TokenIterator(iter, " \n\r");

    def apply() = tokenIter.next()
  }
}

object Bla {

  def main(args: Array[String]): Unit = {
     val Array(n, k) = readLine.split(" ").map(_.toLong)
//    		 def roundUp(x: Long) = x / a + (if (x % a > 0) 1 else 0)
//    		 println(n * m)
     var a = readLine.split(" ").map(_.toLong)
     var count = 0
     for (i <- a)
    	 if (5-i>=k)
    	 	{count = count + 1}
    print(count / 3)
  }

}

object A432 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)

  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }

  def readLongs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong)
  }

  def readBigs(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken))
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    val input = readInts(n).map(5-_).count(_ >= k)
    println(input/3)
  }
}

import java.util.Scanner

/**
 * Created by hama_du on 2014/05/18.
 */
object ProblemA extends App {
  val in = new Scanner(System.in)
  val n, k = in.nextInt()
  val a = (0 until n).map(_ => in.nextInt()).filter(x => (x+k <= 5))
  println(a.size / 3)
}

// http://codeforces.com/contest/432/problem/A
object A extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val p = Array.fill(n)(sc.nextInt()).count(_ <= 5-k)
  println(p / 3)
}

object Main extends App{
  val in = readLine
  val Array(n, k) = in.split(" ").map(_.toInt)
  val data = in.split(" ").map(_.toInt).filter(_ <= 5 - k)
  println(data.length / 3)
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt).filter(_ < 5 - k)
  println(data.length / 3)
}


import scala.io.StdIn._
object Solution {
  def main(args: Array[String]): Unit = {
    val tcases = readInt
    for (tcase <- 1 to tcases) {
      val n = readInt
      val a = readLine.split(" ").map(_.toInt)
      val m = readInt
//      println(readLine.split(" ").map(_.toInt).reduce((x, y) => x + y) % n)
      println(a(readLine.split(" ").map(_.toInt).reduce((x, y) => (x + y) % n) % n))
    }
  }
  /**/

  /*
  * 3 1 4 2
  * 1 4 2 3
  * 3 1 4 2
  * 2 1 5 4 3 (0)
  *
  * 4 3 2 1 5 (3)
  * 2 1 5 4 3
  *
  *
  * 4 3 2 1 5 (3)
  * 2 1 5 4 3 (2)
  * 1 5 4 3 2 (1)
  * 4 3 2 1 5 (2)
  * 3 2 1 5 4 (1)
  *
  * */
}

import scala.collection.mutable
import scala.io.StdIn

object Main extends App {
  var sb = new mutable.StringBuilder()
  val t = StdIn.readLine().toInt
  for (_ <- 0 until t) {
    val n = StdIn.readLine().toInt
    val a = StdIn.readLine().split(" ").map(_.toInt)
    val m = StdIn.readLine().toInt
    val b = StdIn.readLine().split(" ").map(_.toInt)
    var index = 0
    for (bb <- b) index = (index + bb) % a.length
    println(a(index))
  }
}


// To execute Scala code, please define an object named Solution that extends App
import scala.io.StdIn._
object Solution extends App {

  private def solve(): Unit = {
    val line = readLine().split(" ").map(_.toInt)
    val (n, x, y) = (line(0), line(1), line(2))

    def printResult(streak: Int): Unit = {
      var currentWinner = 1
      for(i <- 2 to n) {
        print(s"$currentWinner ")
        if((i - 1) % streak == 0)
          currentWinner = i + 1

      }
      println()
    }

    if(y != 0 && x == 0 && (n - 1) % y == 0)
      printResult(y)
    else if(x != 0 && y == 0 && (n - 1) % x == 0)
      printResult(x)
    else
      println("-1")
  }

  val test_cases: Int = readInt()
  for(i <- 0 until test_cases)
    solve()
}

object _1733B extends CodeForcesApp {
  override def solve(io: IO) = io.repeat() {
    val n, x, y = io.nextInt()
    val ans = (x max y, x min y) match {
      case (a, 0) if a > 0 && (n-1)%a == 0 =>
        Seq.tabulate(n-1)(i => 2 + a*(i/a))
      case _ => Nil
    }
    io.printLine(if (ans.isEmpty) -1 else ans.mkString(" "))
  }
}
/**************************** [Ignore Template Below] **************************************/
trait CodeForcesApp {
  def debug(x: => Any): Unit = if (!sys.props.contains("ONLINE_JUDGE")) println(s">>> DEBUG: $x")
  def run(io: IO): Unit = try solve(io) finally io.close()
  def main(args: Array[String]): Unit = run(new IO(in = System.in, out = System.out))
  def solve(io: IO): Any
}
// Java I/O wrapper
import java.io._
class IO(in: BufferedReader, out: PrintWriter) extends AutoCloseable {
  def this(in: InputStream, out: OutputStream) = this(in = new BufferedReader(new InputStreamReader(in)), out = new PrintWriter(out))

  val tokens = Iterator.continually(nextLine()).takeWhile(_ != null).flatMap(_.split(' '))

  def nextLine(): String = in.readLine()
  def nextStr(): String = tokens.next()
  def nextInt(): Int = nextStr().toInt
  def nextLong(): Long = nextStr().toLong
  def nextDouble(): Double = nextStr().toDouble
  def nextN[A](r: => A): Iterator[A] = Iterator.fill(nextInt())(r)
  def repeat[U](n: Int = nextInt())(f: => U): Unit = (1 to n).foreach(_ => f)
  def query[A](query: Any)(res: => A): A = { printLine(query); out.flush(); res }

  def print(xs: Any*): this.type = { out.print(xs.mkString(" ")); this }
  def printLine(xs: Any*): this.type = { out.println(xs.mkString(" ")); this }
  def printLines(xs: Any*): this.type = { if (xs.isEmpty) out.println() else xs.foreach(out.println); this }

  override def close() = out.close()
}

object _1733B extends CodeForcesApp {
  override def solve(io: IO) = io.repeat() {
    val n, x, y = io.nextInt()
    val ans = (x max y, x min y) partialMatch {
      case (a, 0) if a > 0 && (n-1)%a == 0 =>
        var victories = 0
        var winner = 1
        var loser = 2

        Seq.fill(n-1) {
          if (victories == a) {
            victories = 0
            winner = loser
          }
          victories += 1
          loser += 1
          winner
        }
    }

    io.printLine(ans.map(_.mkString(" ")).getOrElse(-1))
  }

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
}
/**************************** [Ignore Template Below] **************************************/
trait CodeForcesApp {
  def debug(x: => Any): Unit = if (!sys.props.contains("ONLINE_JUDGE")) println(s">>> DEBUG: $x")
  def run(io: IO): Unit = try solve(io) finally io.close()
  def main(args: Array[String]): Unit = run(new IO(in = System.in, out = System.out))
  def solve(io: IO): Any
}
// Java I/O wrapper
import java.io._
class IO(in: BufferedReader, out: PrintWriter) extends AutoCloseable {
  def this(in: InputStream, out: OutputStream) = this(in = new BufferedReader(new InputStreamReader(in)), out = new PrintWriter(out))

  val tokens = Iterator.continually(nextLine()).takeWhile(_ != null).flatMap(_.split(' '))

  def nextLine(): String = in.readLine()
  def nextStr(): String = tokens.next()
  def nextInt(): Int = nextStr().toInt
  def nextLong(): Long = nextStr().toLong
  def nextDouble(): Double = nextStr().toDouble
  def nextN[A](r: => A): Iterator[A] = Iterator.fill(nextInt())(r)
  def repeat[U](n: Int = nextInt())(f: => U): Unit = (1 to n).foreach(_ => f)
  def query[A](query: Any)(res: => A): A = { printLine(query); out.flush(); res }

  def print(xs: Any*): this.type = { out.print(xs.mkString(" ")); this }
  def printLine(xs: Any*): this.type = { out.println(xs.mkString(" ")); this }
  def printLines(xs: Any*): this.type = { if (xs.isEmpty) out.println() else xs.foreach(out.println); this }

  override def close() = out.close()
}

// To execute Scala code, please define an object named Solution that extends App
import scala.io.StdIn._
object Solution extends App {

  private def solve(): Unit = {
    val line = readLine().split(" ").map(_.toInt)
    val (n, x, y) = (line(0), line(1), line(2))

    def printResult(streak: Int): Unit = {
      var currentWinner = 1
      for(i <- 1 until n) {
        print(s"$currentWinner ")
        if(i % streak == 0)
          currentWinner += streak + 1

      }
      println()
    }

    if(y != 0 && x == 0 && (n - 1) % y == 0)
      printResult(y)
    else if(x != 0 && y == 0 && (n - 1) % x == 0)
      printResult(x)
    else
      println("-1")
  }

  val test_cases: Int = readInt()
  for(i <- 0 until test_cases)
    solve()
}

// To execute Scala code, please define an object named Solution that extends App
import scala.io.StdIn._
object Solution extends App {

  private def solve(): Unit = {
    val line = readLine().split(" ").map(_.toInt)
    val (n, x, y) = (line(0), line(1), line(2))

    def printResult(streak: Int): Unit = {
      var currentWinner = 1
      for(i <- 2 to n) {
        print(s"$currentWinner ")
        if(i % streak == 1)
          currentWinner = i + 1

      }
      println()
    }

    if(y != 0 && x == 0 && (n - 1) % y == 0)
      printResult(y)
    else if(x != 0 && y == 0 && (n - 1) % x == 0)
      printResult(x)
    else
      println("-1")
  }

  val test_cases: Int = readInt()
  for(i <- 0 until test_cases)
    solve()
}

// To execute Scala code, please define an object named Solution that extends App
import scala.io.StdIn._
object Solution extends App {

  private def solve(): Unit = {
    val line = readLine().split(" ").map(_.toInt)
    val (n, x, y) = (line(0), line(1), line(2))

    def printResult(streak: Int): Unit = {
      var currentWinner = 1
      for(i <- 1 to (n - 1)) {
        print(s"$currentWinner ")
        if(i % streak == 0)
          currentWinner = i + 1
      }
      println()
    }

    if(y != 0 && x == 0 && (n - 1) % y == 0)
      printResult(y)
    else if(x != 0 && y == 0 && (n - 1) % x == 0)
      printResult(x)
    else
      println("-1")
  }

  val test_cases: Int = readInt()
  for(i <- 0 until test_cases)
    solve()
}


object ThreeEightSevenB {

	def main(args: Array[String]): Unit = {
		var Array(n,m)=readLine.split(' ').map(_.toInt)
		var a=readLine.split(' ').map(_.toInt)
		var b=readLine.split(' ').map(_.toInt)
		var total=n;
		var i,j=0;
		while(i<n && j<m){
			if(a(i)<=b(j)){
				i+=1
				j+=1
				total-=1
			}else{
				j+=1
			}
		}
		println(total)
	}
}

object Solution extends App {

  def count(a: List[Int], b: List[Int], soFar: Int): Int =
    (a, b) match {
      case(Nil, _) => soFar
      case(first, Nil) => soFar + first.length
      case(x :: xs, y :: ys) if y >= x => count(xs, ys, soFar)
      case(x :: xs, y) => count(xs, y, soFar + 1)
    }

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val a = in.next().split(' ').map(_.toInt).sorted.toList.reverse
  val b = in.next().split(' ').map(_.toInt).sorted.toList.reverse
  println(count(a, b, 0))
}


import scala.annotation.tailrec
import scala.io.StdIn.readLine
import scala.collection.immutable.TreeSet

// object Main {
//   case class Range(s: Long, l: Long) extends Ordered[Range] {
//     def compare(that: Range) = {
//       val t  = s + l
//       val tt = that.s + that.l
//       if((s <= that.s && tt <= t) || (that.s <= s && t <= tt))
//         0
//       else
//         (s - that.s).toInt
//     }
//   }
//   case class State(ts: TreeSet[Range], size: Long)
//   def howMany(r: Range, a: Long) : Long =
//     r match {
//       case Range(s, l) => {
//         val h = l / (a+1)
//         val r = l % (a+1)
//         h + (if(r == a) 1 else 0)
//       }
//     }
//   def split(r: Range, i: Long) : List[Range] =
//     if(r.l == 1)
//       List()
//     else if(r.s == i)
//       List(Range(i+1,r.l-1))
//     else if(r.s+r.l-1 == i)
//       List(Range(r.s,r.l-1))
//     else
//       List(Range(r.s,i-r.s), Range(i+1,r.l-(i-r.s+1)))

//   // Document: http://www.scala-lang.org/api/current/#package
//   // -----------------------------------------------------------------------------
//   def main(args: Array[String]) : Unit = {
//     val (n,k,a) = {
//       val nka = readLine().split(" ").map(_.toLong)
//       (nka(0), nka(1), nka(2))
//     }
//     val m = readLine().toLong
//     val x = readLine().split(" ").map(_.toLong-1)
//     val ini = Range(0,n)
//     var index = 0
//     var kotae = -1
//     val ans = x.foldLeft(State(TreeSet[Range](ini), howMany(ini,a)))(
//         (state,x) => state match {
//           case State(ts, size) => {
//             index += 1
//             val r   = ts.iteratorFrom(Range(x,1)).next()
//             val sub = howMany(r,a)
//             val add_range = split(r,x)
//             val add_cnt = add_range.map(howMany(_,a)).sum
//             val new_ts = add_range.foldLeft(ts-r)((t,a) => t+a)
//             val cnt = size - sub + add_cnt
//             if(cnt < k && kotae == -1){
//               kotae = index
//             }
//             State(new_ts, cnt)
//           }})
//     println(kotae)
//   }
// }

object Main {
  import scala.collection.mutable.TreeSet
  case class Range(s: Int, l: Int) extends Ordered[Range] {
    def compare(that: Range) = {
      val t  = s + l
      val tt = that.s + that.l
      if((s <= that.s && tt <= t) || (that.s <= s && t <= tt))
        0
      else
        (s - that.s).toInt
    }
  }
  @inline
  def howMany(r: Range, a: Int) : Int =
    r match {
      case Range(s, l) => {
        val h = l / (a+1)
        val r = l % (a+1)
        h + (if(r == a) 1 else 0)
      }
    }
  @inline
  def split(r: Range, i: Int) : List[Range] =
    if(r.l == 1)
      List()
    else if(r.s == i)
      List(Range(i+1,r.l-1))
    else if(r.s+r.l-1 == i)
      List(Range(r.s,r.l-1))
    else
      List(Range(r.s,i-r.s), Range(i+1,r.l-(i-r.s+1)))

  // Document: http://www.scala-lang.org/api/current/#package
  // -----------------------------------------------------------------------------
  def main(args: Array[String]) : Unit = {
    val (n,k,a) = {
      val nka = readLine().split(" ").map(_.toInt)
      (nka(0), nka(1), nka(2))
    }
    val m = readLine().toInt
    val xk = readLine().split(" ").map(_.toInt-1)
    val ini = Range(0,n)
    var index = 0
    var kotae = -1
    val ts   = TreeSet[Range](ini)
    var size = howMany(ini,a)
    for(x <- xk){
      index += 1
      val r = ts.iteratorFrom(Range(x,1)).next()
      ts -= r
      val add_range = split(r,x)
      size -= howMany(r,a)
      add_range.foreach(i => {size += howMany(i,a)})
      add_range.foreach(a => {ts += a})
      if(size < k && kotae == -1){
        kotae = index
      }
    }
    println(kotae)
  }
}

import java.util.Scanner

object CF567D extends App {
  def num(r: Range, s: Int): Int = (r.length + 1) / (s + 1)

  val scanner = new Scanner(System.in)

  //  val Array(n, k, a) = readLine().split(" ").map(_.toInt)
  val n = scanner.nextInt()
  val k = scanner.nextInt()
  val a = scanner.nextInt()

  //  val m = readLong()
  val m = scanner.nextLong()

  //  val seg = mutable.TreeSet.empty(Ordering.fromLessThan[Range](_.start > _.start))
  val seg = new java.util.TreeMap[Int, Int]()
  //  seg += 1 to n
  seg.put(1, n)
  var total = num(1 to n, a)
  var res = -1

  var i = 0
  while (i < m && total >= k) {
    val x = scanner.nextInt()
    //    val x = readf("{0,number}").asInstanceOf[Int]
    val e = seg.floorEntry(x)
    //    val range = seg.find(r => r.contains(x)).get
    val range = e.getKey to e.getValue

    //    seg -= range
    seg.remove(e.getKey)
    total -= num(range, a)

    val r1 = range.start to (x - 1)
    //    seg += r1
    if (r1.length > 0) seg.put(r1.start, r1.end)
    total += num(r1, a)

    val r2 = (x + 1) to range.end
    //    seg += r2
    if (r2.length > 0) seg.put(r2.start, r2.end)
    total += num(r2, a)

    if (total < k) res = i + 1
    i += 1
  }

  println(res)
}

import scala.annotation.tailrec
import scala.io.StdIn.readLine
import scala.collection.immutable.TreeSet

// object Main {
//   case class Range(s: Long, l: Long) extends Ordered[Range] {
//     def compare(that: Range) = {
//       val t  = s + l
//       val tt = that.s + that.l
//       if((s <= that.s && tt <= t) || (that.s <= s && t <= tt))
//         0
//       else
//         (s - that.s).toInt
//     }
//   }
//   case class State(ts: TreeSet[Range], size: Long)
//   def howMany(r: Range, a: Long) : Long =
//     r match {
//       case Range(s, l) => {
//         val h = l / (a+1)
//         val r = l % (a+1)
//         h + (if(r == a) 1 else 0)
//       }
//     }
//   def split(r: Range, i: Long) : List[Range] =
//     if(r.l == 1)
//       List()
//     else if(r.s == i)
//       List(Range(i+1,r.l-1))
//     else if(r.s+r.l-1 == i)
//       List(Range(r.s,r.l-1))
//     else
//       List(Range(r.s,i-r.s), Range(i+1,r.l-(i-r.s+1)))

//   // Document: http://www.scala-lang.org/api/current/#package
//   // -----------------------------------------------------------------------------
//   def main(args: Array[String]) : Unit = {
//     val (n,k,a) = {
//       val nka = readLine().split(" ").map(_.toLong)
//       (nka(0), nka(1), nka(2))
//     }
//     val m = readLine().toLong
//     val x = readLine().split(" ").map(_.toLong-1)
//     val ini = Range(0,n)
//     var index = 0
//     var kotae = -1
//     val ans = x.foldLeft(State(TreeSet[Range](ini), howMany(ini,a)))(
//         (state,x) => state match {
//           case State(ts, size) => {
//             index += 1
//             val r   = ts.iteratorFrom(Range(x,1)).next()
//             val sub = howMany(r,a)
//             val add_range = split(r,x)
//             val add_cnt = add_range.map(howMany(_,a)).sum
//             val new_ts = add_range.foldLeft(ts-r)((t,a) => t+a)
//             val cnt = size - sub + add_cnt
//             if(cnt < k && kotae == -1){
//               kotae = index
//             }
//             State(new_ts, cnt)
//           }})
//     println(kotae)
//   }
// }

object Main {
  import scala.collection.mutable.TreeSet
  case class Range(s: Int, l: Int) extends Ordered[Range] {
    def compare(that: Range) = {
      val t  = s + l
      val tt = that.s + that.l
      if((s <= that.s && tt <= t) || (that.s <= s && t <= tt))
        0
      else
        (s - that.s).toInt
    }
  }
  case class State(ts: TreeSet[Range], size: Int)
  def howMany(r: Range, a: Int) : Int =
    r match {
      case Range(s, l) => {
        val h = l / (a+1)
        val r = l % (a+1)
        h + (if(r == a) 1 else 0)
      }
    }
  def split(r: Range, i: Int) : List[Range] =
    if(r.l == 1)
      List()
    else if(r.s == i)
      List(Range(i+1,r.l-1))
    else if(r.s+r.l-1 == i)
      List(Range(r.s,r.l-1))
    else
      List(Range(r.s,i-r.s), Range(i+1,r.l-(i-r.s+1)))

  // Document: http://www.scala-lang.org/api/current/#package
  // -----------------------------------------------------------------------------
  def main(args: Array[String]) : Unit = {
    val (n,k,a) = {
      val nka = readLine().split(" ").map(_.toInt)
      (nka(0), nka(1), nka(2))
    }
    val m = readLine().toInt
    val xk = readLine().split(" ").map(_.toInt-1)
    val ini = Range(0,n)
    var index = 0
    var kotae = -1

    val ts   = TreeSet[Range](ini)
    var size = howMany(ini,a)
    for(x <- xk){
      index += 1
      val r   = ts.iteratorFrom(Range(x,1)).next()
      val sub = howMany(r,a)
      val add_range = split(r,x)
      val add_cnt = add_range.map(howMany(_,a)).sum
      ts -= r
      add_range.foreach((a) => {ts += a})
      val cnt = size - sub + add_cnt
      if(cnt < k && kotae == -1){
        kotae = index
      }
    }
    println(kotae)
  }
}


import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else if ((r1 == r2 && Math.abs(c1 - c2) == 1) || (c1 == c2 && Math.abs(r1 - r2) == 1)) {
      if (g(r2)(c2) == 0) {
        out.println("YES")
        return 1
      } else {
        var cnt = 0
        for (i <- 0 until 4) {
          val x1 = r2 + dx(i)
          val y1 = c2 + dy(i)
          if (g(x1)(y1) == 1) {
            cnt += 1
          }
        }
        if (cnt >= 1) {
          out.println("YES")
          return 1
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(r2)(c2) == 0) {
              out.println("YES")
              return 1
            } else {
              var cnt = 0
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1) {
                  cnt += 1
                }
              }
              if (cnt >= 2) {
                out.println("YES")
                return 1
              }
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }
}

import annotation.tailrec

object main extends App with fastIO {

  case class Point(x: Int, y: Int)

  val dx = Vector(-1, 0, 1, 0)
  val dy = Vector(0, -1, 0, 1)

  def ok(x: Int, y: Int) = { x >= 0 && y >= 0 && x < n && y < m }

  def bfs(p: Point) {

    var q = scala.collection.mutable.Queue(p)

    def run(x: Int, y: Int) {
      if (!ok(x, y)) return
      if (a(x)(y) == 1) return
      if (used(x)(y)) return

      used(x)(y) = true
      for (i <- 0 until 4)
        q += Point(x + dx(i), y + dy(i))
    }

    while (!q.isEmpty) {
      val (x, y) = (q.front.x, q.front.y)
      q.dequeue; run(x, y)
    }
  }

  var Array(n, m) = readLine split(" ") map(_.toInt)
  var a = Array.fill(n)(readLine.map(c => if (c == '.') 0 else 1).toArray)
  var (p1, p2) = (Point(nextInt - 1, nextInt - 1), Point(nextInt - 1, nextInt - 1))
  var used = Array.ofDim[Boolean](n, m)

  a(p1.x)(p1.y) = 0
  var cnt = a(p2.x)(p2.y) * 2
  for (i <- 0 until 4) if (ok(p2.x + dx(i), p2.y + dy(i)))
    cnt += 1 - a(p2.x + dx(i))(p2.y + dy(i))
  if (p1 == p2) cnt += 1

  a(p2.x)(p2.y) = 0
  for (i <- 0 until 4) bfs(Point(p1.x + dx(i), p1.y + dy(i)))

  println(if (cnt > 1 && used(p2.x)(p2.y)) "YES" else "NO")
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

import java.io._
import java.util.StringTokenizer

import scala.Ordering.Implicits._
import scala.collection.mutable

object Codeforces {
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    st.nextToken
  }

  def nextInt: Int = {
    Integer.parseInt(next)
  }

  def nextLong: Long = {
    java.lang.Long.parseLong(next)
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val dx = Array(0, 0, 1, -1)
  val dy = Array(1, -1, 0, 0)

  def check(n: Int, m: Int, x: Int, y: Int): Boolean = {
    0 <= x && x < n && 0 <= y && y < m
  }

  def reach(matrix: Array[String], startx: Int, starty: Int, endx: Int, endy: Int): Boolean = {
    val n = matrix.length
    val m = matrix(0).length
    val vst = Array.ofDim[Boolean](n, m)
    for (i <- 0 until n; j <- 0 until m) {
      vst(i)(j) = (matrix(i)(j) == 'X')
    }
    var queue = new mutable.Queue[(Int, Int)]()
    queue += Tuple2(startx, starty)
    while (queue.nonEmpty) {
      val front = queue.head
      queue = queue.tail
      for (i <- 0 until dx.length) {
        val nextx = front._1 + dx(i)
        val nexty = front._2 + dy(i)
        if (nextx == endx && nexty == endy) {
          return true
        }
        if (check(n, m, nextx, nexty) && vst(nextx)(nexty) == false) {
          vst(nextx)(nexty) = true
          queue += Tuple2(nextx, nexty)
        }
      }
    }
    return false
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)

    val matrix = Array.ofDim[String](n)
    for (i <- 0 until n) {
      matrix(i) = next
    }
    val (startx, starty) = (nextInt - 1, nextInt - 1)
    val (endx, endy) = (nextInt - 1, nextInt - 1)

    var can_reach = 0
    for (i <- 0 until dx.length) {
      val nextx = endx + dx(i)
      val nexty = endy + dy(i)
      if (check(n, m, nextx, nexty) && matrix(nextx)(nexty) == '.') {
        can_reach += 1
      }
    }
    if (startx == endx && starty == endy) {
      if (can_reach != 0) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else if (matrix(endx)(endy) == 'X') {
      if (reach(matrix, startx, starty, endx, endy)) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else if (math.abs(startx - endx) + math.abs(starty - endy) == 1) {
      if (can_reach > 0) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else {
      if (reach(matrix, startx, starty, endx, endy) && can_reach > 1) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    }
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

import java.io._
import java.util.StringTokenizer

import scala.Ordering.Implicits._
import scala.collection.mutable

object Codeforces {
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    st.nextToken
  }

  def nextInt: Int = {
    Integer.parseInt(next)
  }

  def nextLong: Long = {
    java.lang.Long.parseLong(next)
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val dx = Array(0, 0, 1, -1)
  val dy = Array(1, -1, 0, 0)

  def check(n: Int, m: Int, x: Int, y: Int): Boolean = {
    0 <= x && x < n && 0 <= y && y < m
  }

  def reach(matrix: Array[String], startx: Int, starty: Int, endx: Int, endy: Int): Boolean = {
    val n = matrix.length
    val m = matrix(0).length
    val vst = Array.ofDim[Boolean](n, m)
    for (i <- 0 until n; j <- 0 until m) {
      vst(i)(j) = (matrix(i)(j) == 'X')
    }
    var queue = new mutable.Queue[(Int, Int)]()
    queue += Tuple2(startx, starty)
    while (queue.nonEmpty) {
      val front = queue.head
      queue = queue.tail
      for (i <- 0 until dx.length) {
        val nextx = front._1 + dx(i)
        val nexty = front._2 + dy(i)
        if (nextx == endx && nexty == endy) {
          return true
        }
        if (check(n, m, nextx, nexty) && vst(nextx)(nexty) == '.') {
          vst(nextx)(nexty) = true
          queue += Tuple2(nextx, nexty)
        }
      }
    }
    return false
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)

    val matrix = Array.ofDim[String](n)
    for (i <- 0 until n) {
      matrix(i) = next
    }
    val (startx, starty) = (nextInt - 1, nextInt - 1)
    val (endx, endy) = (nextInt - 1, nextInt - 1)

    var can_reach = 0
    for (i <- 0 until dx.length) {
      val nextx = endx + dx(i)
      val nexty = endy + dy(i)
      if (check(n, m, nextx, nexty) && matrix(nextx)(nexty) == '.') {
        can_reach += 1
      }
    }
    if (startx == endx && starty == endy) {
      if (can_reach != 0) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else if (matrix(endx)(endy) == 'X') {
      if (reach(matrix, startx, starty, endx, endy)) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else {
      if (reach(matrix, startx, starty, endx, endy) && can_reach > 1) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    }
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

import java.io._
import java.util.StringTokenizer

import scala.Ordering.Implicits._
import scala.collection.mutable

object Codeforces {
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    st.nextToken
  }

  def nextInt: Int = {
    Integer.parseInt(next)
  }

  def nextLong: Long = {
    java.lang.Long.parseLong(next)
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val dx = Array(0, 0, 1, -1)
  val dy = Array(1, -1, 0, 0)

  def check(n: Int, m: Int, x: Int, y: Int): Boolean = {
    0 <= x && x < n && 0 <= y && y < m
  }

  def reach(matrix: Array[String], startx: Int, starty: Int, endx: Int, endy: Int): Boolean = {
    val n = matrix.length
    val m = matrix(0).length
    val vst = Array.ofDim[Boolean](n, m)
    for (i <- 0 until n; j <- 0 until m) {
      vst(i)(j) = (matrix(i)(j) == 'X')
    }
    var queue = new mutable.Queue[(Int, Int)]()
    queue += Tuple2(startx, starty)
    while (queue.nonEmpty) {
      val front = queue.head
      queue = queue.tail
      for (i <- 0 until dx.length) {
        val nextx = front._1 + dx(i)
        val nexty = front._2 + dy(i)
        if (nextx == endx && nexty == endy) {
          return true
        }
        if (check(n, m, nextx, nexty) && vst(nextx)(nexty) == false) {
          vst(nextx)(nexty) = true
          queue += Tuple2(nextx, nexty)
        }
      }
    }
    return false
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)

    val matrix = Array.ofDim[String](n)
    for (i <- 0 until n) {
      matrix(i) = next
    }
    val (startx, starty) = (nextInt - 1, nextInt - 1)
    val (endx, endy) = (nextInt - 1, nextInt - 1)

    var can_reach = 0
    for (i <- 0 until dx.length) {
      val nextx = endx + dx(i)
      val nexty = endy + dy(i)
      if (check(n, m, nextx, nexty) && matrix(nextx)(nexty) == '.') {
        can_reach += 1
      }
    }
    if (startx == endx && starty == endy) {
      if (can_reach != 0) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else if (matrix(endx)(endy) == 'X') {
      if (reach(matrix, startx, starty, endx, endy)) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else {
      if (reach(matrix, startx, starty, endx, endy) && can_reach > 1) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    }
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

/**
 *
 * Created by ronaflx on 15-4-3.
 */

import java.io._
import java.util.StringTokenizer

import scala.Ordering.Implicits._
import scala.collection.mutable

object Codeforces {
  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    st.nextToken
  }

  def nextInt: Int = {
    Integer.parseInt(next)
  }

  def nextLong: Long = {
    java.lang.Long.parseLong(next)
  }

  def upperBound[T: Ordering](array: Array[T], value: T) = {
    var low = 0
    var high = array.length
    var res = array.length
    while (low <= high) {
      val mid = (low + high) / 2
      if (value < array(mid)) {
        res = mid
        high = mid - 1
      } else {
        low = mid + 1
      }
    }
    res
  }

  val dx = Array(0, 0, 1, -1)
  val dy = Array(1, -1, 0, 0)

  def check(n: Int, m: Int, x: Int, y: Int): Boolean = {
    0 <= x && x < n && 0 <= y && y < m
  }

  def reach(matrix: Array[String], startx: Int, starty: Int, endx: Int, endy: Int): Boolean = {
    val n = matrix.length
    val m = matrix(0).length
    val vst = Array.ofDim[Boolean](n, m)
    for (i <- 0 until n; j <- 0 until m) {
      vst(i)(j) = (matrix(i)(j) == 'X')
    }
    var queue = new mutable.Queue[(Int, Int)]()
    queue += Tuple2(startx, starty)
    while (queue.nonEmpty) {
      val front = queue.head
      queue = queue.tail
      for (i <- 0 until dx.length) {
        val nextx = front._1 + dx(i)
        val nexty = front._2 + dy(i)
        if (nextx == endx && nexty == endy) {
          return true
        }
        if (check(n, m, nextx, nexty) && vst(nextx)(nexty) == false) {
          vst(nextx)(nexty) = true
          queue += Tuple2(nextx, nexty)
        }
      }
    }
    return false
  }

  def solve(): Unit = {
    val (n, m) = (nextInt, nextInt)

    val matrix = Array.ofDim[String](n)
    for (i <- 0 until n) {
      matrix(i) = next
    }
    val (startx, starty) = (nextInt - 1, nextInt - 1)
    val (endx, endy) = (nextInt - 1, nextInt - 1)

    var can_reach = 0
    for (i <- 0 until dx.length) {
      val nextx = endx + dx(i)
      val nexty = endy + dy(i)
      if (check(n, m, nextx, nexty) && matrix(nextx)(nexty) == '.') {
        can_reach += 1
      }
    }
    if (startx == endx && starty == endy) {
      if (can_reach != 0) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else if (math.abs(startx - endx) + math.abs(starty - endy) == 1) {
      if (can_reach > 0) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else if (matrix(endx)(endy) == 'X') {
      if (reach(matrix, startx, starty, endx, endy)) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else {
      if (reach(matrix, startx, starty, endx, endy) && can_reach > 1) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    }
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else if ((r1 == r2 && Math.abs(c1 - c2) == 1) || (c1 == c2 && Math.abs(r1 - r2) == 1)) {
      if (g(r2)(c2) == 1) {
        out.println("YES")
        return 1
      } else {
        for (i <- 0 until 4) {
          val x1 = r2 + dx(i)
          val y1 = c2 + dy(i)
          if (g(x1)(y1) == 1) {
            out.println("YES")
            return 1
          }
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(x1)(y1) == 0) {
              out.println("YES")
              return 1
            } else {
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
                  out.println("YES")
                  return 1
                }
              }
              out.println("NO")
              return 1
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else if ((r1 == r2 && Math.abs(c1 - c2) == 1) || (c1 == c2 && Math.abs(r1 - r2) == 1)) {
      if (g(r2)(c2) == 0) {
        out.println("YES")
        return 1
      } else {
        for (i <- 0 until 4) {
          val x1 = r2 + dx(i)
          val y1 = c2 + dy(i)
          if (g(x1)(y1) == 1) {
            out.println("YES")
            return 1
          }
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(x1)(y1) == 0) {
              out.println("YES")
              return 1
            } else {
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
                  out.println("YES")
                  return 1
                }
              }
              out.println("NO")
              return 1
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else if (r1 == r2 || c1 == c2) {
      if (g(r2)(c2) == 1) {
        out.println("YES")
        return 1
      } else {
        for (i <- 0 until 4) {
          val x1 = r2 + dx(i)
          val y1 = c2 + dy(i)
          if (g(x1)(y1) == 1) {
            out.println("YES")
            return 1
          }
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(x1)(y1) == 0) {
              out.println("YES")
              return 1
            } else {
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
                  out.println("YES")
                  return 1
                }
              }
              out.println("NO")
              return 1
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else if ((r1 == r2 && Math.abs(c1 - c2) == 1) || (c1 == c2 && Math.abs(r1 - r2) == 1)) {
      if (g(r2)(c2) == 0) {
        out.println("YES")
        return 1
      } else {
        var cnt = 0
        for (i <- 0 until 4) {
          val x1 = r2 + dx(i)
          val y1 = c2 + dy(i)
          if (g(x1)(y1) == 1) {
            cnt += 1
          }
        }
        if (cnt >= 2) {
          out.println("YES")
          return 1
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(x1)(y1) == 0) {
              out.println("YES")
              return 1
            } else {
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1) {
                  out.println("YES")
                  return 1
                }
              }
              out.println("NO")
              return 1
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else if ((r1 == r2 && Math.abs(c1 - c2) == 1) || (c1 == c2 && Math.abs(r1 - r2) == 1)) {
      if (g(r2)(c2) == 0) {
        out.println("YES")
        return 1
      } else {
        var cnt = 0
        for (i <- 0 until 4) {
          val x1 = r2 + dx(i)
          val y1 = c2 + dy(i)
          if (g(x1)(y1) == 1) {
            cnt += 1
          }
        }
        if (cnt >= 2) {
          out.println("YES")
          return 1
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(r2)(c2) == 0) {
              out.println("YES")
              return 1
            } else {
              var cnt = 0
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1) {
                  cnt += 1
                }
              }
              if (cnt >= 2) {
                out.println("YES")
                return 1
              }
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }
}

import java.io._
import java.util._

import scala.collection.mutable

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new Array[Array[Int]](n + 2)
    val d = new Array[Array[Int]](n + 2)
    for (i <- 0 until g.length) {
      g(i) = new Array[Int](m + 2)
      d(i) = new Array[Int](m + 2)
    }
    for (i <- 1 to n) {
      val in = next.toCharArray
      for (j <- 1 to m) {
        if (in(j - 1) == '.') {
          g(i)(j) = 1
        }
      }
    }
    val r1 = nextInt
    val c1 = nextInt
    val r2 = nextInt
    val c2 = nextInt
    val dx = Array(-1, 1, 0, 0)
    val dy = Array(0, 0, -1, 1)
    if (r1 == r2 && c1 == c2) {
      for (i <- 0 until 4) {
        val x1 = r1 + dx(i)
        val y1 = c1 + dy(i)
        if (g(x1)(y1) == 1) {
          out.println("YES")
          return 1
        }
      }
    } else {
      val q = new mutable.Queue[(Int, Int)]()
      q.enqueue((r1, c1))

      while (!q.isEmpty) {
        val x = q.dequeue
        for (i <- 0 until 4) {
          val x1 = x._1 + dx(i)
          val y1 = x._2 + dy(i)
          if (x1 == r2 && y1 == c2) {
            if (g(x1)(y1) == 0) {
              out.println("YES")
              return 1
            } else {
              for (i <- 0 until 4) {
                val x1 = r2 + dx(i)
                val y1 = c2 + dy(i)
                if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
                  out.println("YES")
                  return 1
                }
              }
              out.println("NO")
              return 1
            }
          } else if (g(x1)(y1) == 1 && d(x1)(y1) == 0) {
            q.enqueue((x1, y1))
            d(x1)(y1) = d(x._1)(x._2) + 1
          }
        }
      }
    }
    out.println("NO")
    return 0
  }

}

object main extends App with fastIO {

  case class Point(x: Int, y: Int)

  val dx = Vector(-1, 0, 1, 0)
  val dy = Vector(0, -1, 0, 1)

  def ok(x: Int, y: Int) = { x >= 0 && y >= 0 && x < n && y < m }

  def dfs(x: Int, y: Int) {
    if (!ok(x, y)) return
    if (a(x)(y) == 1) return
    if (used(x)(y)) return

    used(x)(y) = true
    for (i <- 0 until 4)
      dfs(x + dx(i), y + dy(i))
  }

  var Array(n, m) = readLine split(" ") map(_.toInt)
  var a = Array.fill(n)(readLine.map(c => if (c == '.') 0 else 1).toArray)
  var (p1, p2) = (Point(nextInt - 1, nextInt - 1), Point(nextInt - 1, nextInt - 1))
  var used = Array.ofDim[Boolean](n, m)

  var cnt = a(p2.x)(p2.y)
  for (i <- 0 until 4) if (ok(p2.x + dx(i), p2.y + dy(i)))
    cnt += 1 - a(p2.x + dx(i))(p2.y + dy(i))

  a(p1.x)(p1.y) = 0
  a(p2.x)(p2.y) = 0
  dfs(p1.x, p1.y)

  println(if (cnt > 1 && used(p2.x)(p2.y)) "YES" else "NO")
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

object main extends App with fastIO {

  case class Point(x: Int, y: Int)

  val dx = Vector(-1, 0, 1, 0)
  val dy = Vector(0, -1, 0, 1)

  def ok(x: Int, y: Int) = { x >= 0 && y >= 0 && x < n && y < m }

  def dfs(x: Int, y: Int) {
    if (!ok(x, y)) return
    if (a(x)(y) == 1) return
    if (used(x)(y)) return

    used(x)(y) = true
    for (i <- 0 until 4)
      dfs(x + dx(i), y + dy(i))
  }

  var Array(n, m) = readLine split(" ") map(_.toInt)
  var a = Array.fill(n)(readLine.map(c => if (c == '.') 0 else 1).toArray)
  var (p1, p2) = (Point(nextInt - 1, nextInt - 1), Point(nextInt - 1, nextInt - 1))
  var used = Array.ofDim[Boolean](n, m)

  var cnt = a(p2.x)(p2.y) * 2
  for (i <- 0 until 4) if (ok(p2.x + dx(i), p2.y + dy(i)))
    cnt += 1 - a(p2.x + dx(i))(p2.y + dy(i))

  a(p1.x)(p1.y) = 0
  a(p2.x)(p2.y) = 0
  dfs(p1.x, p1.y)

  println(if (cnt > 1 && used(p2.x)(p2.y)) "YES" else "NO")
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}

object main extends App with fastIO {

  case class Point(x: Int, y: Int)

  val dx = Vector(-1, 0, 1, 0)
  val dy = Vector(0, -1, 0, 1)

  def ok(x: Int, y: Int) = { x >= 0 && y >= 0 && x < n && y < m }

  def dfs(x: Int, y: Int) {
    if (!ok(x, y)) return
    if (a(x)(y) == 1) return
    if (used(x)(y)) return

    used(x)(y) = true
    for (i <- 0 until 4)
      dfs(x + dx(i), y + dy(i))
  }

  var Array(n, m) = readLine split(" ") map(_.toInt)
  var a = Array.fill(n)(readLine.map(c => if (c == '.') 0 else 1).toArray)
  var (p1, p2) = (Point(nextInt - 1, nextInt - 1), Point(nextInt - 1, nextInt - 1))
  var used = Array.ofDim[Boolean](n, m)

  var cnt = a(p2.x)(p2.y) * 2
  for (i <- 0 until 4) if (ok(p2.x + dx(i), p2.y + dy(i)))
    cnt += 1 - a(p2.x + dx(i))(p2.y + dy(i))

  a(p2.x)(p2.y) = 0
  for (i <- 0 until 4) dfs(p1.x + dx(i), p1.y + dy(i))

  println(if (cnt > 1 && used(p2.x)(p2.y)) "YES" else "NO")
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile) new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken
    in.sval
  }

  def nextInt: Int = {
    in.nextToken
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken
    in.nval.toDouble
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush = out.flush
}


import java.util.Scanner

object Main {

   def main(args: Array[String]): Unit = {
      val scanner = new Scanner (System.in)
		val str = scanner nextLine () reverse

		println (solve (str) reverse)
   }

	def solve(str: String): String = {
		var prev = 0
		def f(c: Char): Boolean = {
			if (prev <= c) {
				prev = c
				true
			} else false
		}
		str filter f
	}

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val letters = Array.ofDim[Int](26)
  line.foreach {
    i => letters(i - 'a') += 1
  }

  val res = line.foldLeft(List.empty[Char], letters.indices.reverse.find(i => letters(i) > 0)) {
    case ((answer, Some(i)), el) if el - 'a' != i =>
      letters(el - 'a') -= 1
      if (letters(el - 'a') == 0)
        (answer, letters.indices.reverse.find(i => letters(i) > 0))
      else
        (answer, Some(i))
    case ((answer, Some(i)), el) =>
      letters(el- 'a') -= 1
      if (letters(el - 'a') == 0)
        (el :: answer, letters.indices.reverse.find(i => letters(i) > 0))
      else
        (el :: answer, Some(i))
  }
  println(res._1.reverse.mkString)
}


import java.util.Scanner
import java.io.PrintWriter

/**
 * Created by hama_du on 2014/05/18.
 */
object ProblemB extends App {
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val n = in.nextInt()
  val colors = (0 until n).map(_ => (in.nextInt(), in.nextInt()) )
  val homeColor = new Array[Int](100001)
  val awayColor = new Array[Int](100001)
  for (i <- 0 until n) {
    val h = colors(i)._1
    val a = colors(i)._2
    homeColor(h) += 1
    awayColor(a) += 1
  }
  colors.foreach(z => {
    val matches = (n - 1)
    val d = homeColor(z._2)
    out.println((matches+d) + " " + (matches-d))
  })
  out.flush()
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = (1 to n).map{_ => in.next().split(" ").map(_.toInt)}
  val homes = data.map(_.head).groupBy(x => x).map(x => x._1 -> x._2.length)

  val res = data.map{
    el =>
      val guest = el.last
      val x = (n - 1) + homes.getOrElse(guest, 0)
      s"$x ${(n - 1) * 2 - x}"
  }

  println(res.mkString("\n"))
}


import io.Source
import io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    StdIn.readLine()

    val list = StdIn.readLine().split(" ").map(_.toLong).toList
    val list2 = list ::: list
    var max = 0
    var t = 0
    for (a <- list2) {
      if (a == 1) {
        t += 1
      } else {
        max = Math.max(t, max)
        t = 0
      }
    }
    max = Math.max(t, max)
    println(max)
    //println(longs.reverse.map(t => math.sqrt(t)).mkString("\n"))
  }
}
/*

* */

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = na(N).map(_ == 1)
    debug(A)
    var a = 0
    var cnt = 0
    REP(N) { i =>
      if (A(i)) cnt += 1
      else cnt = 0
      a = max(a, cnt)
    }
    val b = A.takeWhile(identity).length + A.reverse.takeWhile(identity).length
    debug(s"a:$a b:$b")
    val ans = max(a, b)
    out.println(ans)
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null

  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }

  def debug(as: Array[Boolean]): Unit = DEBUG {
    debug(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = DEBUG {
    debug(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = DEBUG {
    debug(as.mkString(" "))
  }

  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }

  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    StdIn.readLine()

    val list = StdIn.readLine().split(" ").map(_.toLong).toList
    val list2 = list ::: list
    var max = 0
    var t = 0
    for (a <- list2) {
      if (a == 1) {
        t += 1
      } else {
        max = Math.max(t, max)
        t = 0
      }
    }
    max = Math.max(t, max)
    println(max)
  }
}

object _1141B extends CodeForcesApp {
  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def apply(io: IO): io.type = {
    val input = io.read[Vector[Boolean]]
    val isResting = input ++ input

    var i, ans = 0
    while(i < isResting.length) {
      val j = i
      while (i < isResting.length && isResting(i)) i += 1
      ans = ans max (i - j)
      i += 1
    }

    io.write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    tokenizers.headOption
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}