object A extends App {
  val n = scala.io.StdIn.readInt()
  val a = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val t = a.foldLeft((0, 0))((t, i) => {
    if (i < 0 ) (t._1, t._2 + i)
    else if (i > 0) (t._1 + i, t._2)
    else t
  })

  println(t._1 - t._2)
}

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

  override def apply(io: IO): io.type = {
    val a = io.read[Seq[Int]]
    val (b, c) = a.partition(_ > 0)
    io.write(b.sum - c.sum)
  }
}
/****************************[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()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  type Point = java.awt.geom.Point2D.Double
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p._1, ev(p._2))
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    //def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def getBit(i: Int): Int = (x >> i) & 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def getBit(i: Int): Long = (x >> i) & 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative.getOrElse(f)   //e.g. students.indexOf("Greg").whenNegative(Int.MaxValue)
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new Point(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def isPrime(n: Int): Boolean = BigInt(n).isProbablePrime(31)
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of 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 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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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
      }
    }
  }
}

object CF946A extends App {
  import scala.io.StdIn._
  readLine()

  val nums: List[Int] = readLine().split(" ").map(Integer.parseInt(_)).toList

  val (pos, neg) = nums.partition(_ > 0)

  val res = pos.sum - neg.sum

  println(res)

}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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)) }

  val Array(n) = readInts(1)
  val xs = readInts(n)
  val sum = xs.sum
  var max = Int.MinValue

  for (d <- -101 to 101) {
    max = Math.max(max, Math.abs(xs.filter(_ <= d).sum - xs.filter(_ > d).sum))
  }

  println(max)

  Console.flush
}

object APartition extends App {
  val n = scala.io.StdIn.readInt()
  val a = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val t = a.foldLeft(0)(_ + _.abs)

  println(t)
}

object A extends App {
  val n = scala.io.StdIn.readInt()
  val a = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  val t = a.reduce(_.abs + _.abs)

  println(t)
}


object A80 {

  import IO._
  import collection.{mutable => cu}

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val primes = genPrimes(100)
    if(primes.contains(n) && primes.contains(m)) {
      val nPos = primes.indexOf(n)
      val mPos = primes.indexOf(m)
      if(mPos == nPos+1) {
        out.println("YES")
      } else {
        out.println("NO")
      }
    } else {
      out.println("NO")
    }
    out.close()
  }

  def genPrimes(till: Int): Array[Int] = {
    val isPrime = Array.fill[Boolean](till+1)(true)
    isPrime(0) = false
    isPrime(1) = true // not composite
    for(i <- 4 to till by 2) {
      isPrime(i) = false
    }
    for(i <- 3 to till by 2 if isPrime(i)) {
      for(j <- i+i to till by i) isPrime(j) = false
    }
    isPrime.zipWithIndex.filter(_._1).map(_._2)
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P80A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextPrime(n: Int): Int = {
    def isPrime(x: Int): Boolean = (2 until x).forall(x % _ > 0)

    @tailrec
    def loop(i: Int): Int =
      if (isPrime(i)) i
      else loop(i + 1)

    loop(n + 1)
  }

  val N, M = sc.nextInt
  val answer = if (M == nextPrime(N)) "YES" else "NO"

  out.println(answer)
  out.close
}

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

  lazy val primes: Stream[Int] =
    2 #:: Stream.iterate(3)(_ + 2).filter(isPrime)

  def isPrime(number: Int): Boolean =
    primes.takeWhile(prime => prime * prime <= number).forall(number % _ != 0)

  val Array(n, m) = readLine().split(" ").map(_.toInt)

  val ans = isPrime(m) && primes.indexOf(n) + 1 == primes.indexOf(m) match {
    case true => "YES"
    case _    => "NO"
  }

  println(ans)
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInt = reader.readLine().toInt
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readLongs = reader.readLine().split(" ").map(_.toLong)

  def sqStream(current: Int, ceil: Int): Stream[Int] = if(current * current > ceil) Stream.Empty else current #:: sqStream(current + 1, ceil)
  def isPrime(x: Int) = sqStream(2, x).filter(x % _ == 0).isEmpty
  @tailrec
  def nextPrime(n: Int): Int = if(isPrime(n)) n else nextPrime(n + 1)
  val Array(m, n) = readInts
  def ans = nextPrime(m + 1) == n
  val yesNoAns = Map(true -> "YES", false -> "NO")

  def main(a: Array[String]) {
    println(yesNoAns(ans))
  }
}

object Main {
  def sieve(n: Int) = {
    val primes = scala.collection.mutable.BitSet.empty ++ (2 to n)
    for {
      candidate <- 2 until Math.sqrt(n).ceil.toInt
      if primes contains candidate
    } primes --= candidate * candidate to n by candidate
    primes
  }

  val primes = sieve(51).zipWithIndex

  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val i = primes.find(_._1 == n).get._2
    val j = primes.find(_._1 == m).map(_._2)
    if (j.map(_ - i).getOrElse(0) == 1) println("YES")
    else println("NO")
  }
}

object Panoramix extends App {

  val Array(n, m) = readLine.split(' ').map(_.toInt)

  val primes: Array[Int] = Array(
    2, 3, 5, 7, 11, 13,
    17, 19, 23, 29, 31,
    37, 41, 43, 47
  )

  val result: Boolean =
    primes.contains(n) && primes.contains(m) &&
      primes.indexOf(m) - primes.indexOf(n) == 1
  println(if (result) "YES" else "NO")

}

object Flask {

  def isPrime(n: Int): Boolean = List.range(2, n / 2 + 1).forall(n % _ != 0)

  def main(args: Array[String]): Unit = {
    var input = Console.readLine.split(" ").map(_.toInt)
    var n = input(0); var m = input(1)
    var result = isPrime(m) && List.range(n + 1, m).forall(x => !isPrime(x))
    println(if (result) "YES" else "NO")
  }
}

import scala.io.Source

object a11 {
  def main(args: Array[String]): Unit = {
    val a =  Seq.iterate((List[Int](),(2 to 50).toArray),5)(a=>(((a._2.head)::a._1), a._2.filter(b => b % (a._2.head) != 0))).last
    val primes = a._1.reverse.toArray ++ a._2
    val line = Source.stdin.getLines().take(1).map(_.split(' ').map(_.toInt)).toArray.head
    val (b,c) = (line(0), line(1))
    println(if (!primes.contains(c) || primes(primes.indexOf(b)+1) != c)
      "NO"
    else
      "YES")
  }
}

object Solution extends App {
  def simple(a: Int) =
    a % 2 != 0 && (3 to Math.sqrt(a).toInt by 2).forall(a % _ != 0) || a == 2

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  if (simple(m) && (n + 1 until m).forall(t => !simple(t)))
    println("YES")
  else
    println("NO")
}

object Solution extends App {
  def simple(a: Int) = {
    a % 2 == 0 && (a == 2 || (3 to Math.sqrt(a).toInt).forall(a % _ != 0))
  }

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  if (simple(m) && (n + 1 until m).forall(t => !simple(t)))
    println("YES")
  else
    println("NO")
}

object Main {
  def sieve(n: Int) = {
    val primes = scala.collection.mutable.BitSet.empty ++ (2 to n)
    for {
      candidate <- 2 until Math.sqrt(n).toInt
      if primes contains candidate
    } primes --= candidate * candidate to n by candidate
    primes
  }

  val primes = sieve(50).zipWithIndex

  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val i = primes.find(_._1 == n).get._2
    val j = primes.find(_._1 == m).map(_._2)
    if (j.map(_ - i).getOrElse(0) == 1) println("YES")
    else println("NO")
  }
}

object Main {
  def sieve(n: Int) = {
    val primes = scala.collection.mutable.BitSet.empty ++ (2 to n)
    for {
      candidate <- 2 until Math.sqrt(n).ceil.toInt
      if primes contains candidate
    } primes --= candidate * candidate to n by candidate
    primes
  }

  val primes = sieve(51).zipWithIndex

  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val i = primes.find(_._1 == n).get._2
    val j = primes.find(_._1 == m).map(_._2)
    println("i = " + i)
    println("j = " + j)
    if (j.map(_ - i).getOrElse(0) == 1) println("YES")
    else println("NO")
  }
}


import java.util.Scanner

object R273_RandomTeams {
  def main(args: Array[String]) = {
    val in = new Scanner(System.in).nextLine().split(" ").map(_.toInt)
    val (n, m) = (in(0), in(1))
    val (p, q) = (n / m, n % m)

    val min = combination2(p) * (m - q) + combination2(p + 1) * q
    val max = combination2(n - m + 1)
    println(min + " " + max)
   }

  def combination2(n: Long): Long = {
    (n * (n - 1)) / 2
  }
}

import java.util.Scanner

object Solution {
    def countPairs(n: Long): Long = n * (n - 1) / 2

    def main(args: Array[String]) = {
	val in = new Scanner(System.in)
	val people = in.nextLong()
	val teams = in.nextLong()
	val max = countPairs(people - teams + 1)
	val size = people / teams
	val bigCount = people - size * teams
	val smallCount = teams - bigCount
	val min = countPairs(size + 1) * bigCount + countPairs(size) * smallCount
	println(min + " " + max)
    }
}

import java.util.Scanner

object Main extends App {
  val in = (new Scanner(System.in)).nextLine().split(" ").map(_.toInt)
  val n = in(0)
  val m = in(1)

  def nC2(n: Int): Long = {
    if(n == 1) 0
    else
      n.toLong * (n-1) / 2
  }

  val mi = n/m
  val mi2_count = if( mi*m != n ) n - mi*m else 0
  val mi_count = m - mi2_count
  val ans1 = (nC2(mi)*mi_count + nC2(mi+1)*mi2_count)

  val mx = n - (m-1)
  val ans2 = nC2(mx)

  println(ans1.toString + " " + ans2.toString)
}

import java.util.StringTokenizer

object _478B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toLong
  val m = next.toLong
  def choose(a: Long) = a * (a - 1) / 2
  val max = choose(n - (m - 1))
  val min = (m - n % m) * choose(n / m) + (n % m) * choose(n / m + 1)
  println(min + " " + max)
}

object Solution extends App {
  def f(n: Long) = n * (n - 1) / 2

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toLong)
  val c = n / m
  val min = (n % m) * f(c + 1) + (m - n % m) * f(c)
  val max = f(n - m + 1)
  println(min + " " + max)
}

object B478 {
  @inline def read = scala.io.StdIn.readLine

  @inline def tokenizeLine = new java.util.StringTokenizer(read)

  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, m) = readLongs(2)
    val min = {
      val mod = n%m
      mod * ((n/m + 1) *(n/m)) /2 + (m-mod) * ((n/m) * (n/m -1 )) / 2
    }
    val max = ((n-m+1) * (n-m))/2
    println(s"$min $max")
  }
}

object P478B {
	def edges(n: Int) : BigInt = ((BigInt(n) * n) - n) / 2

	def main(args: Array[String]) {
		val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		val min = (n % m) * edges((n / m) + 1) + (m - (n % m)) * edges(n / m)
		val max = edges(n - m + 1)
		println(List(min, max).mkString(" "))
	}
}

import java.util.StringTokenizer

object _478B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toLong
  val m = next.toLong
  def choose(a: Long) = a * (a - 1) / 2
  val max = choose(n - (m - 1))
  val min = {
    if (n % m == 0) m * choose(n / m)
    else (m - 1) * choose(n / m) + choose(n - n / m * (m - 1))
  }
  println(min + " " + max)
}

object Solution extends App {
  def f(n: Int) = n * (n - 1) / 2

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val c = n / m
  val min = (n % m) * f(c + 1) + (m - n % m) * f(c)
  val max = f(n - m + 1)
  println(max + " " + min)
}

object Solution extends App {
  def f(n: Int) = n * (n - 1) / 2

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val c = n / m
  val min = (n % m) * f(c + 1) + (m - n % m) * f(c)
  val max = f(n - m + 1)
  println(min + " " + max)
}

object Solution extends App {
  def f(n: Int) = n * (n + 1) / 2

  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val c = n / m
  val min = (n % m) * f(c + 1) + (m - n % m) * f(c)
  val max = f(n - m)
  println(max + " " + min)
}

import java.util.Scanner

object R273_RandomTeams {
  def main(args: Array[String]) = {
    val in = new Scanner(System.in).nextLine().split(" ").map(_.toInt)
    val (n, m) = (in(0), in(1))
    val (p, q) = (n / m, n % m)

    val min = combination2(p) * (m - q) + (combination2(p) + 1) * q
    val max = combination2(n - m + 1)
    println(min + " " + max)
   }

  def combination2(n: Long): Long = {
    (n * (n - 1)) / 2
  }
}

import java.util.Scanner

object R273_RandomTeams {
  def main(args: Array[String]) = {
    val in = new Scanner(System.in).nextLine().split(" ").map(_.toInt)
    val n = in(0)
    val m = in(1)
    val p = n / m
    val q = n % m

    val min = combination2(p) * (m - q) + (combination2(p) + 1) * q
    val max = combination2(n - m + 1)
    println(min + " " + max)
   }

  def combination2(n: Int): Int = {
    (n / 2) * (n - 1)
  }

  def fact(n: Int): Int = {
    Range(1, n + 1).toList.product
  }
}

import java.util.Scanner

object R273_RandomTeams {
  def main(args: Array[String]) = {
    val in = new Scanner(System.in).nextLine().split(" ").map(_.toInt)
    val n = in(0)
    val m = in(1)
    val p = n / m
    val q = n % m

    val min = combination2(p) * (m - q) + (combination2(p) + 1) * q
    val max = combination2(n - m + 1)
    println(min + " " + max)
   }

  def combination2(n: Int): Int = {
    (n * (n - 1)) / 2
  }

  def fact(n: Int): Int = {
    Range(1, n + 1).toList.product
  }
}

object P478B {
	def edges(n: Int) : BigInt = ((BigInt(n) * n) - n) / 2

	def main(args: Array[String]) {
		val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		val min = (n % m) * edges((n / m) + 1) + (m - (n % m)) * edges(n / m)
		val max = edges(n - m + 1)
		println(min, max)
	}
}

import java.util.Scanner

object Solution {
    def countPairs(n: Long): Long = n * (n - 1) / 2

    def main(args: Array[String]) = {
	val in = new Scanner(System.in)
	val people = in.nextLong()
	val teams = in.nextLong()
	val max = countPairs(people - teams + 1) + teams - 1
	val size = people / teams
	val bigCount = people - size * teams
	val smallCount = teams - bigCount
	val min = countPairs(size + 1) * bigCount + countPairs(size) * smallCount
	println(min + " " + max)
    }
}

import java.util.Scanner

object Main extends App {
  val in = (new Scanner(System.in)).nextLine().split(" ").map(_.toInt)
  val n = in(0)
  val m = in(1)

  def nCm(n: Int, m: Int): Long = {
    if(n == 1) 0
    else {
      val nt = (1 to n).reverse.take(m).product
      val mt = (1 to m).reverse.product
      (nt / mt).toLong
    }
  }

  val mi = n/m
  val mi2_count = if( mi*m != n ) n - mi*m else 0
  val mi_count = m - mi2_count
  val ans1 = (nCm(mi,2)*mi_count + nCm(mi+1,2)*mi2_count)

  val mx = n - (m-1)
  val ans2 = nCm(mx,2)

  print(Math.min(ans1, ans2))
  print(" ")
  println(Math.max(ans1, ans2))
}

import java.util.Scanner

object Main extends App {
  val in = (new Scanner(System.in)).nextLine().split(" ").map(_.toInt)
  val n = in(0)
  val m = in(1)

  def nCm(n: Int, m: Int): Long = {
    if(n == 1) 1
    else {
      val nt = (1 to n).reverse.take(m).product
      val mt = (1 to m).reverse.product
      (nt / mt).toLong
    }
  }

  val mi = n/m
  val mi2_count = if( mi*m != n ) n - mi*m else 0
  val mi_count = m - mi2_count
  val ans1 = (nCm(mi,2)*mi_count + nCm(mi+1,2)*mi2_count)

  val mx = n - (m-1)
  val ans2 = nCm(mx,2)

  print(Math.min(ans1, ans2))
  print(" ")
  println(Math.max(ans1, ans2))
}


object Solution extends App {
  val in = io.Source.stdin.getLines()
  val first = in.next() match {
    case "monday" => 0
    case "tuesday" => 1
    case "wednesday" => 2
    case "thursday" => 3
    case "friday" => 4
    case "saturday" => 5
    case "sunday" => 6
  }
  val second = in.next() match {
    case "monday" => 0
    case "tuesday" => 1
    case "wednesday" => 2
    case "thursday" => 3
    case "friday" => 4
    case "saturday" => 5
    case "sunday" => 6
  }
  val candidates = List(first + 28, first + 30, first + 31).map(_ % 7)
  if (candidates.contains(second))
    println("YES")
  else
    println("NO")
}

import java.io._

object ProblemA {
  def main(args: Array[String]): Unit = processStdInOut()

  def processStdInOut(): Unit = {
    val src = io.Source.fromInputStream(System.in)
    try {
      val bw = new BufferedWriter(new OutputStreamWriter(System.out));
      try {
        val lines = src.getLines()
        processLines(lines, bw)
      } finally {
        bw.flush()
        bw.close()
      }
    } finally {
      src.close();
    }
  }

  // Standard code above, custom code below

  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {
    val day1 = lines.next()
    val day2 = lines.next()
    val hasSolution = solve(day1, day2)
    if (hasSolution) { bw.write("YES") } else {bw.write("NO") };
    bw.newLine()
  }

  def solve(day1: String, day2: String): Boolean = {
    val dayNames = List("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")
    def getDayIndex(dayName: String): Int = dayNames.indexOf(dayName)
    val day1Index = getDayIndex(day1)
    val day2Index = getDayIndex(day2)
    val dayOffset = (7 + day2Index - day1Index) % 7  // Add 7 to prevent negative remainders
    val monthLengths = List(28, 30, 31)
    monthLengths.exists(dayOffset == _ % 7)
  }
}

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(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) }

  val dows = Array("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")
  val ms = Array(28, 30, 31)

  val s1, s2 = readLine

  val d1 = dows.indexWhere(_ == s1)
  val d2 = dows.indexWhere(_ == s2)

  val can = ms.exists(d => (d1 + d) % 7 == d2)

  println(if (can) "YES" else "NO")
}

import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._

object _724A extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll, writeLine}
    val d1, d2 = read[String]

    val months = Seq(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
    val firstDayOfMonth = months.init.scanLeft(0)(_ + _)

    val days = IndexedSeq("monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday")

    val ans = days.zipWithIndex exists {case (start, k) =>
      val calendar = Seq.tabulate(365)(i => days((i + k)%days.length))
      firstDayOfMonth.sliding(2) exists {
        case Seq(m1, m2) => calendar(m1) == d1 && calendar(m2) == d2
      }
    }

    write(ans.toEnglish)
  }
}
/****************************[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()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

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

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

  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 writeAll(obj: Traversable[Any], separator: String = "\n"): 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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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
      }
    }
  }
}

//package me.code4fun

import scala.io.StdIn

object A {

  def dayOfWeek(dayStr: String): Int =
    dayStr match {
      case "monday" => 0
      case "tuesday" => 1
      case "wednesday" => 2
      case "thursday" => 3
      case "friday" => 4
      case "saturday" => 5
      case "sunday" => 6
      case _ => throw new IllegalArgumentException(s"$dayStr is not a day of week")
    }

  val nbDaysInWeek = 7

  val possibleOffsets = Seq(28, 30, 31).map(_ % nbDaysInWeek)

  def posMod(a: Int, b: Int): Int = {
    val mod = a % b
    if (mod >= 0) mod else (mod + b)
  }

  def areConsecutiveDays(firstDay: String, secondDay: String): Boolean = {
    val fst = dayOfWeek(firstDay)
    val snd = dayOfWeek(secondDay)
    val diff = posMod(snd - fst, nbDaysInWeek)
    possibleOffsets.contains(diff)
  }

  def main(args: Array[String]): Unit = {
    val fst = StdIn.readLine()
    val snd = StdIn.readLine()
    if (areConsecutiveDays(fst, snd))
      Console.out.println("YES")
    else
      Console.out.println("NO")
  }
}


//package me.jetblack.cf

import java.util.Scanner

object TreesCount extends App {

  val s = new Scanner(System.in)

  val maxn = s.nextInt()
  val maxh = s.nextInt()

  val dp = Array.ofDim[Long](maxn + 1, maxn + 1)
  dp(0)(0) = 1
  for {
    h <- (1 until maxn + 1)
    i <- (1 until maxn + 1)
    j <- (1 to i)
  } yield {
    val left1 = dp(h - 1)(j - 1)
    val right1 = (0 until h).map(h1 => dp(h1)(i - j)).sum
    val left2 = (0 until h - 1).map(h1 => dp(h1)(j - 1)).sum
    val right2 = dp(h - 1)(i - j)
    dp(h)(i) += (left1 * right1) + left2 * right2
  }

  val result = (maxh to maxn).map(dp(_)(maxn)).sum
  println(result)

}

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

object D {

  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)
    }
    return st.nextToken
  }

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

  def sumOfTrees(dp: Array[Array[Long]], h: Int, n: Int): Long = {
    var temp: Long = 0
    for (i <- 0 to h) {
      temp += dp(i)(n)
    }
    temp
  }

  def solve = {
    val n = nextInt
    val h = nextInt
    val dp = new Array[Array[scala.Long]](36)
    for (i <- 0 to 35) {
      dp(i) = new Array[scala.Long](36)
      Arrays.fill(dp(i), 0)
    }
    dp(0)(0) = 1L
    for (i <- 1 to h) {
      dp(i)(0) = 0L
    }
    for (i <- 1 to n) {
      dp(0)(i) = 0L
    }
    for (i <- 1 to 35) {
      for (j <- 1 to 35) {
        var temp: Long = 0
        for (m <- 1 to j) {
          temp += dp(i - 1)(m - 1) * sumOfTrees(dp, i - 1, j - m) + dp(i - 1)(j - m) * sumOfTrees(dp, i - 2, m - 1)
        }
        dp(i)(j) = temp
      }
    }
    var ans: Long = 0
    for (i <- h to n) {
      ans += dp(i)(n)
    }
    out.println(ans)
  }

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

//package me.jetblack.cf

import java.util.Scanner

object TreesCount extends App {

  val s = new Scanner(System.in)

  val maxn = s.nextInt()
  val maxh = s.nextInt()

  val dp = Array.ofDim[Int](maxn + 1, maxn + 1)
  dp(0)(0) = 1
  for {
    h <- (1 until maxn + 1)
    i <- (1 until maxn + 1)
    j <- (1 to i)
  } yield {
    val left1 = dp(h - 1)(j - 1)
    val right1 = (0 until h).map(h1 => dp(h1)(i - j)).sum
    val left2 = (0 until h - 1).map(h1 => dp(h1)(j - 1)).sum
    val right2 = dp(h - 1)(i - j)
    dp(h)(i) += (left1 * right1) + left2 * right2
  }

  val result = (maxh to maxn).map(dp(_)(maxn)).sum
  println(result)

}


import scala.io.StdIn._

object Main extends App {
  val a =
    (for (_ <- 0 until 10)
      yield readLine()).toArray

  if (check((0, 1)) || check((1, 0)) || check((1, 1)) || check((1, -1)))
    println("YES")
  else
    println("NO")

  def good(x: Int): Boolean = x >= 0 && x < 10

  def check(diff: (Int, Int)): Boolean = {
    for (i <- 0 until 10; j <- 0 until 10) {
      var (x, y, cnt, free) = (j, i, 0, 0)
      for (z <- 0 until 5) {
        if (good(x) && good(y))
          if (a(y)(x) == 'X')
            cnt += 1
          else if (a(y)(x) == '.')
            free += 1
        y += diff._1
        x += diff._2
      }
      if (cnt == 4 && free == 1)
        return true
    }
    false
  }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._

object Main extends App {
  val a = ArrayBuffer[ArrayBuffer[Char]]()
  for (i <- 0 until 10) {
    a.append(readLine().toCharArray.to[ArrayBuffer])
  }

  if (check(a, (0, 1)) || check(a, (1, 0)) || check(a, (1, 1)) || check(a, (1, -1)))
    println("YES")
  else
    println("NO")

  def good(x: Int): Boolean = x >= 0 && x < 10

  def check(a: ArrayBuffer[ArrayBuffer[Char]], diff: (Int, Int)): Boolean = {
    for (i <- 0 until 10) {
      for (j <- 0 until 10) {
        var x = j
        var y = i
        var cnt = 0
        var free = 0
        for (z <- 0 until 5) {
          if (good(x) && good(y))
            if (a(y)(x) == 'X')
              cnt += 1
            else if (a(y)(x) == '.')
              free += 1
          y += diff._1
          x += diff._2
        }
        if (cnt == 4 && free == 1)
          return true
      }
    }
    false
  }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._

object Main extends App {
  val a = ArrayBuffer[ArrayBuffer[Char]]()
  for (i <- 0 until 10) {
    a.append(readLine().toCharArray.to[ArrayBuffer])
  }

  if (check(a) || check(a.transpose) || check2(a, (1, 1)) || check2(a, (1, -1)))
    println("YES")
  else
    println("NO")

  def check(a: ArrayBuffer[ArrayBuffer[Char]]): Boolean = {
    for (i <- 0 until 10) {
      for (j <- 0 to 5) {
        var cnt = 0
        for (z <- j until j + 5) {
          if (a(i)(z) == 'X')
            cnt += 1
          else if (a(i)(z) == 'O')
            cnt = -5
        }
        if (cnt == 4)
          return true
      }
    }
    false
  }

  def good(x: Int): Boolean = x >= 0 && x < 10

  def check2(a: ArrayBuffer[ArrayBuffer[Char]], diff: (Int, Int)): Boolean = {
    for (i <- 0 until 10) {
      for (j <- 0 until 10) {
        var x = j
        var y = i
        var cnt = 0
        for (z <- 0 until 5) {
          y += diff._1
          x += diff._2
          if (good(x) && good(y))
            if (a(y)(x) == 'X')
              cnt += 1
            else if (a(y)(x) == 'O')
              cnt = -5
        }
        if (cnt == 4)
          return true
      }
    }
    false
  }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._

object Main extends App {
  val a = ArrayBuffer[ArrayBuffer[Char]]()
  for (i <- 0 until 10) {
    a.append(readLine().toCharArray.to[ArrayBuffer])
  }

  if (check(a, (0, 1)) || check(a, (1, 0)) || check(a, (1, 1)) || check(a, (1, -1)))
    println("YES")
  else
    println("NO")

  def good(x: Int): Boolean = x >= 0 && x < 10

  def check(a: ArrayBuffer[ArrayBuffer[Char]], diff: (Int, Int)): Boolean = {
    for (i <- 0 until 10) {
      for (j <- 0 until 10) {
        var x = j
        var y = i
        var cnt = 0
        var free = 0
        for (z <- 0 until 5) {
          y += diff._1
          x += diff._2
          if (good(x) && good(y))
            if (a(y)(x) == 'X')
              cnt += 1
            else if (a(y)(x) == '.')
              free += 1
        }
        if (cnt == 4 && free == 1)
          return true
      }
    }
    false
  }
}


import Array._
import scala.io.StdIn.readLine
object problem {
  def main(args: Array[String]) {
  val n = readLine.toInt
    var A = ofDim[Int](n + 1, n + 1)
      for(i <- 1 to n) A(1)(i) = 1
    for(i <- 2 to n){
      for(j <- 1 to n) A(i)(j) = A(i - 1)(j) + A(i)(j - 1)
    }
//    for(i <- 1 to n){
//      for(j <- 1 to n) print(A(i)(j) + " "); println()
//    }
        for(i <- n to n){
          for(j <- n to n) print(A(i)(j) + " "); println()
        }
  }
}

object S509A {
    def main(args: Array[String]) {
        var i: Int = 0
        var j: Int = 0
        var n = readInt()
        val a = Array.ofDim[Int](n, n)
        for (i <- 0 until n) {
            a(i)(0) = 1
            a(0)(i) = 1
        }
        for (i <- 1 until n) {
            for (j <- 1 until n)
                a(i)(j) = a(i - 1)(j) + a(i)(j - 1)
        }
        println(a(n - 1)(n - 1))
    }
}

object A509 {
  @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) = readInts(1)
    val res = Array.ofDim[Int](n, n)
    for(i <- 0 until n; j <- 0 until n) {
      if(i == 0 || j == 0) {
        res(i)(j) = 1
      } else {
        res(i)(j) = res(i-1)(j) + res(i)(j-1)
      }
    }
    println(res(n-1)(n-1))
  }
}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object MaximumInTable {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def readLongs() : Array[Long] =
      readLine.split(' ').map(_.toLong)

   def readTuple() : (Int,Int) = {
     val line = readInts
     (line(0),line(1))
   }
   def readTupleLong() : (Long,Long) = {
     val line = readLongs
     (line(0),line(1))
   }

   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }
   def readQuad() : (Int,Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2),line(3))
   }

   def solve(n : Int) : Int = {
     def go(r: Int, c: Int) : Int = {
       if (r == 1 || c == 1) 1
       else go(r-1,c)+go(r,c-1)
     }
     go(n,n)
   }

   def main(args: Array[String]) {
     val n = readInt
     println(solve(n))
   }

}

object main extends App with fastIO {

  def C(n: Int, m: Int): Int = {
    (n, m) match {
      case (1, m) => 1
      case (n, 1) => 1
      case (n, m) => C(n - 1, m) + C(n, m - 1)
    }
  }

  val n = nextInt

  println(C(n, n))
  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
  }

  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 scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val n = StdIn.readInt()
    val A = Array.ofDim[Array[Int]](n)
    for (i <- 0 to n - 1) {
      A(i) = new Array[Int](n)
      A(i)(0) = 1
      A(0)(i) = 1
    }

    for (i <- 1 to n - 1) {
      for (j <- 1 to n - 1) {
        A(i)(j) = A(i-1)(j) + A(i)(j-1)
      }
    }

    println(A(n-1)(n-1))
  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  var n = in.next().toInt
  var previous = Array.fill(n){1}
  Range(0, n - 1).foreach { i =>
    val current = Array.ofDim[Int](n)
    current(0) = 1
    Range(1, n).foreach {
      i => current(i) = current(i - 1) + previous(i)
    }
    previous = current
  }
  print(previous.max)
}


object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toLong

  def findK(n: Long): Long = {
    var k = 3l
    while (n % k == 0) {
      k *= 3
    }
    k
  }

  val k = findK(n)
  println( n / k + (if (n % k != 0) 1 else 0))

}

object CF333A {
    def main(argv: Array[String]) {
        def calc(n: Long): Long = {
            if (n % 3 == 0) calc(n / 3)
            else (n + 2) / 3
        }
        println(calc(readLine.toLong))
    }
}

/**
 * User: Oleg Nizhnik
 * Date: 29.07.13
 * Time: 1:49
 */
object C_Secrets extends App {
  def find(n: Long, k: Long = 1): Long = if (n % k == 0) find(n, k * 3) else (n + k - 1) / k
  println(find(readLine().toLong))

}

/**
 * User: Oleg Nizhnik
 * Date: 29.07.13
 * Time: 1:49
 */
object C_Secrets {
  def find(n: Long, k: Long = 1): Long = if (n % k == 0) find(n, k * 3) else (n + k - 1) / k
  def main(args: Array[String]) = println(find(readLine().toLong))
}

import scala.collection.mutable._
import scala.math._
import scala.util._
import scala.util.control.Breaks.break
import scala.util.control.Breaks.breakable
import java.util._
import java.math.BigInteger
object Main extends App {
  val sc = new Scanner(System.in)
  def count3(n: BigInt): BigInt = {
    if(n % 3 != 0) return 0
    return 1 + count3(n / 3)
  }
  def pow(a: BigInt, b: BigInt): BigInt = {
    if(b == 0) return 1
    else return a * pow(a, b-1)
  }
  val n = new BigInt(sc.nextBigInteger)
  val m = pow(3, count3(n)+1)
  println(n / m + (if((n % m) == 0) 0 else 1))
}

/**
 * Created by Notebook on 14.02.2015.
 */
object AplusB extends App{
      var a =readLong()
      while(a%3==0) a /= 3
      println(a/3+1)
}

object A extends App {

  def readString = Console.readLine

  val n = BigInt(readString)

  var i = BigInt(3)

  while (i <= n && n % i == 0) i *= 3

  println(n / i + 1)
}

object Main extends App {

        def calc(n: Long): Long = {
            if (n % 3 == 0) calc(n / 3)
            else (n + 2) / 3
        }
        println(calc(readLine.toLong))
    }

import scala.collection.mutable._
import scala.math._
import scala.util._
import scala.util.control.Breaks.break
import scala.util.control.Breaks.breakable
import java.util._
import java.math.BigInteger
object Main extends App {
  val sc = new Scanner(System.in)
  val v = new BigInt(sc.nextBigInteger)
  println(v / 3 + (if((v % 3) == 0) 0 else 1))
}

import scala.collection.mutable._
import scala.math._
import scala.util._
import scala.util.control.Breaks.break
import scala.util.control.Breaks.breakable
import java.util._
object Main extends App {
  val sc = new Scanner(System.in)
  println(ceil(readLong/3.0).toLong)
}

import scala.collection.mutable._
import scala.math._
import scala.util._
import scala.util.control.Breaks.break
import scala.util.control.Breaks.breakable
import java.util._
import java.math.BigInteger
object Main extends App {
  val sc = new Scanner(System.in)
  val v = new BigInt(sc.nextBigInteger)
  println(v / 3 + ceil((v % 3).toInt * 0.1).toInt)
}

/**
 * Author: Odomontois
 * Date: 29.07.13
 * Time: 9:53
 * To change this template use File | Settings | File Templates.
 */
object C_Secrets extends App {
  val in = java.lang.Long.toString(readLine().toLong, 3).reverse
  println((in(0) match {
    case '1' => in.drop(1).dropWhile(_ == '2')
    case '0' | '2' => in.dropWhile(_ == '0').dropWhile(_ == '2')
  }).map(Map('0' -> 0, '1' -> 1, '2' -> 2)).sum + 1)
}

/**
 * Author: Odomontois
 * Date: 29.07.13
 * Time: 9:53
 * To change this template use File | Settings | File Templates.
 */
object C_Secrets extends App {
  val in = java.lang.Long.toString(readLine().toLong, 3).reverse.dropWhile(_ == '0')
  println((in(0) match {
    case '1' => in.drop(1)
    case '2' => in
  }).dropWhile(_ == '2').map(Map('0' -> 0, '1' -> 1, '2' -> 2)).sum + 1)
}


import scala.io.StdIn

object BearAndRaspberryMain {
  def main(args: Array[String]): Unit ={
    val nc = StdIn.readLine().split(" ").map(_.toInt)
    val n = nc(0)
    val c = nc(1)
    val elements = StdIn.readLine().split(" ").map(_.toInt)
    var LOL = 0
    for(i <- 0 to n-2){
      val d  =  elements(i) - c - elements(i+1)
      if( LOL < d)
        LOL = d
    }
    print(LOL)
  }
}

import java.util.StringTokenizer

object _385A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val c = next.toInt
  val a = (1 to n).map(i => next.toInt)
  val b = (1 until n).map(i => a(i - 1) - a(i)).max
  val ans = (b - c) max 0
  println(ans)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, c) = in.next().split(" ").map(_.toInt)
  val ans = Math.max(0, in.next().split(" ").map(_.toInt).sliding(2).map(t => t.head - t.last - c).max)
  println(ans)
}

import java.util.Scanner

object P385A {
    def main(args: Array[String]) {
        val scanner = new Scanner(System.in)
        val n = scanner.nextInt()
        val c = scanner.nextInt()
        val prices = for (i <- 1 to n) yield scanner.nextInt()
        val gains = for ((prev, next) <- prices.init zip prices.tail) yield prev - next - c
        val ans = if (gains.max > 0) gains.max else 0
        println(ans)
    }
}

object A385 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, c) = readInts(2)
    val in = readInts(n)
    var res = 0
    for(i <- 0 until n-1) {
      val cal = in(i) - in(i+1) - c
      res = math.max(res, cal)
    }
    println(res)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

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

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

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

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P385A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, C = sc.nextInt
  val X = List.fill(N)(sc.nextInt)

  val gain = (X, X.tail).zipped.map(_ - _).max - C
  val answer = if (gain > 0) gain
               else 0

  out.println(answer)
  out.close
}

//package codeforces

/**
 * TODO: describe
 *
 * @author keks
 */
object T385A {
  def main(args: Array[String]) {
    val rent = readArray.last
    print(getRasp(readArray, rent))
  }

  def getRasp(a: Array[Int], rent: Int) = {
    val total = ((0, a.head) /: a.tail)(
      (acc, prev) => (if (acc._1 < acc._2 - prev) acc._2 - prev else acc._1, prev)
    )._1
    if (total > rent) total - rent else 0
  }

  def readArray = readLine().split(' ').map(_.toInt)
}

object A extends App {
  val sc = new java.util.Scanner(System.in)
  val n, c = sc.nextInt()
  val x = Array.fill(n)(sc.nextInt())
  var ans = 0
  for (i <- 0 until n-1) {
    ans = ans.max(x(i)-x(i+1)-c)
  }
  println(ans)
}


object Solver {
    def main(args: Array[String]) {
        val (first, second) = (Console.readLine, Console.readLine)
        val success = first.length == second.length && List.range(0, first.length).forall(i => first(i) == second(first.length - i - 1))

        println(if (success) "YES" else "NO")
    }
}

object Main extends App {
  val str1 = readLine()
  val str2 = readLine()

  if (str1 == str2.reverse) println("YES")
  else println("NO")
}

object CF0041A extends App {

  val f = readLine()
  val s = readLine()

  if( f == s.reverse) {
    println("YES")
  } else {
    println("NO")
  }

}

import java.util.Scanner

object TEST extends App{
    val sc = new Scanner(System.in)
    print (if(readLine.reverse == readLine)"YES" else "NO")
}

import scala.io.StdIn._

object Task extends App{
  val w1 = readLine
  val w2 = readLine

  if(w1.reverse == w2)
    println("YES")
  else
    println("NO")
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    if (StdIn.readLine() == StdIn.readLine().reverse) println("YES") else println("NO")
  }
}

import java.util.Scanner

object HelloWorldMain {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    val str = sc.next()

    val strShouldBeReverse = sc.next()

    if(str.reverse equalsIgnoreCase strShouldBeReverse )println("YES")
    else println("NO")

  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  var str = in.next()
  var str2 = in.next()
  if (str.length != str2.length || str.zip(str2.reverse).exists(t => t._1 != t._2))
    println("NO")
  else
    println("YES")
}

object Main {

  def main(args: Array[String]) {
    val std = scala.io.StdIn

    val areTheSame = std.readLine().equals(std.readLine().reverse)
    if (areTheSame) {
      println("YES")
    }
    else {
      println("NO")
    }
  }
}

object A41 {
  @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 input1 = scala.io.StdIn.readLine
    val input2 = scala.io.StdIn.readLine
    if(input1.reverse.compareTo(input2) == 0) {
      println("YES")
    } else {
      println("NO")
    }
  }
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P41A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val S, T = sc.nextLine
  val answer = if (S == T.reverse) "YES" else "NO"

  out.println(answer)
  out.close
}

object Translation {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val word1 = scanner.nextLine;
		val word2 = scanner.nextLine;
		var leftIndex = 0;
		var rightIndex = word2.length - 1;
		var equal = true;
		while (equal && leftIndex < word1.length() && rightIndex >= 0) {
			equal = word1(leftIndex) == word2(rightIndex)
			leftIndex += 1; rightIndex-=1
		}
		if (equal) {
			println("YES")
		}
		else
			println("NO")
	}
}

import scala.io._
import scala.collection.mutable._
import java.io.FileWriter
import java.io.PrintWriter

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var t = readLine;
    var s = readLine;
    if (t == s.reverse) {
      println("YES");
    } else {
      println("NO");
    }
  }
}

import annotation.tailrec
import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readInt = reader.readLine().toInt

  def ans = if(reader.readLine() == reader.readLine().reverse) "YES" else "NO"

  def main(args: Array[String]) {
    println(ans)
  }
}

object Main {
  def main(args: Array[String]) {
    val s1 = readLine()
    val s2 = readLine()
    if (s1.reverse == s2) println("YES")
    else println("NO")
  }
}

import scala.io.StdIn._

object A_41 extends App {
  val a = readLine()
  val b = readLine()

  println(
    if (a == b.reverse) "YES" else "NO"
  )
}

import scala.io.StdIn.readLine
object problem {
  def main(args: Array[String]) {
  val s = readLine
  val t = readLine
    if(t == s.reverse) println("YES") else println("NO")
  }
}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object Translation {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def main(args: Array[String]) {
     val s = readLine
     val t = readLine
     if (s == t.reverse) println("YES") else println("NO")
   }

}

object P041A extends App {
  val t = readLine()
  val s = readLine()
  println(if (t.reverse == s) "YES" else "NO")
}

object Translation extends App{
    val berlandish = scala.io.StdIn.readLine()
    val birlandish = scala.io.StdIn.readLine()

    if (birlandish.reverse == berlandish) println("YES")
    else println("NO")

}

object P041A extends App {
  val t = readLine()
  val s = readLine()
  println(if (t.reverse == s) "YES" else "No")
}


import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val string = StdIn.readLine()
    val valuesOtherThanOneOrFour = string.exists(char => char != '1' && char != '4')
    val startsWithValueOtherThanOne = !string.startsWith("1")
    val containsThreeConsecutiveFours = string.indexOf("444") != -1
    if (valuesOtherThanOneOrFour || startsWithValueOtherThanOne || containsThreeConsecutiveFours) println("NO") else println("YES")
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val str = in.next()
  if (str.forall(ch => ch == '1' || ch == '4') &&
      str.head != '4' && !str.contains("444"))
    println("YES")
  else
    println("NO")
}

object A320 {

  import IO._

  def main(args: Array[String]): Unit = {
    val num = read
    val dummy = Array.fill[Char](num.length)('x').mkString("")
    val res = num.replaceAll("144", "xxx").replaceAll("14", "xx").replaceAll("1", "x")
    if(res.equals(dummy)) {
      println("YES")
    } else {
      println("NO")
    }
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

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

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

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

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P320A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): String = {

    @tailrec
    def loop(cs: List[Char]): String = cs match {
        case Nil                 => "YES"
        case '1' :: '4' :: '4' :: rest => loop(rest)
        case '1' :: '4' :: rest        => loop(rest)
        case '1' :: rest               => loop(rest)
        case _                         => "NO"
      }

    loop(sc.nextLine.toList)
  }

  out.println(solve)
  out.close
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInt = reader.readLine().toInt
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readLongs = reader.readLine().split(" ").map(_.toLong)

  val ans = reader.readLine().matches("(14{0,2})+")
  val yesNoAns = Map(true -> "YES", false -> "NO")

  def main(a: Array[String]) {
    println(yesNoAns(ans))
  }
}

object Main {
  def main(args: Array[String]) {
    val s = readLine()
    val r = s.replaceAll("144", "a").replaceAll("14", "a").replaceAll("1", "a")
    if (r.matches("a*")) println("YES")
    else println("NO")
  }
}

object CF320A extends App {
    override def main(args: Array[String]) {
      val s:String = readLine()
      var i = 0
      while (i < s.length()) {
        if (i+3 <= s.length() && s.substring(i, i+3) == "144")
          i += 3
        else if (i + 2 <= s.length() && s.substring(i, i+2) == "14") i += 2
        else if (s.charAt(i) == '1') i += 1
        else {
          println("NO")
          return
        }
      }
      println("YES")
    }
}

object MagicNumbers {
   def main(args:Array[String]):Unit={
     val str=readLine
     println(solve(str))
   }
  def solve(str:String):String={
//    str.toCharArray.toList match {
//      case("144"::string)=> solve(string)
//      case ("14"::string)=>solve(string)
//      case("1"::string)=>solve(string)
//      case(str.length==0)=>"YES"
//      case(_)=>"NO"
//    }
    if(str.startsWith("144")) solve(str.substring(3))
    else if(str.startsWith("14")) solve(str.substring(2))
    else if(str.startsWith("1")) solve(str.substring(1))
    else if(str.length==0) "YES"
    else "NO"
  }
}

object A320 {

  import IO._

  def main(args: Array[String]): Unit = {
    val num = read
    if(num.replaceAll("144", "").replaceAll("14", "").replaceAll("1", "").isEmpty) {
      println("YES")
    } else {
      println("NO")
    }
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

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

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

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

}

object Main {
  def main(args: Array[String]) {
    val s = readLine()
    val r = s.replaceAll("144", "").replaceAll("14", "").replaceAll("1", "")
    if (r.size == 0) println("YES")
    else println("NO")
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    if (StdIn.readLine.forall(char => char == '4' || char == '1')) print("YES") else print("NO")
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    var string = StdIn.readLine()
    while (string.contains("144")) {
      string = string.replace("144", "")
    }
    while (string.contains("14")) {
      string = string.replace("14", "")
    }
    if (string.forall(_ == '1')) println("YES") else println("NO")
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val string = StdIn.readLine()
    if (string.exists(char => char != '4' && char != '1') || !string.startsWith("1")) print("NO") else print("YES")
  }
}


object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = 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]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)

    val Inf = 1e9.toInt
    var ans = sumL(map(N - 1) { i =>
      (A(i), A(i + 1)) match {
        case (1, 2) => 3
        case (1, 3) => 4
        case (2, 1) => 3
        case (2, 3) => Inf
        case (3, 1) => 4
        case (3, 2) => Inf
      }
    })

    ans += sumL(map(N - 2) { i =>
      (A(i), A(i + 1), A(i + 2)) match {
        case (3, 1, 2) => -1
        case _ => 0
      }
    })

    if (ans >= Inf) out.println("Infinite")
    else {
      out.println("Finite")
      out.println(ans)
    }
  }
}

object Main extends App {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val result = a.foldLeft((0, 0, 0))((acc, next) => {
      if (acc._3 == -1) (0, 0, -1)
      else {
        (acc._1, acc._2,  next) match {
          case (3, 1, 2) => (acc._2, next, acc._3 + 2)
          case (_, 1, 2) => (acc._2, next, acc._3 + 3)
          case (_, 1, 3) => (acc._2, next, acc._3 + 4)
          case (_, 2, 1) => (acc._2, next, acc._3 + 3)
          case (_, 3, 1) => (acc._2, next, acc._3 + 4)
          case (_, 0, _) => (acc._2, next, 0)
          case _ => (0, 0, -1)
        }
      }
    })

    if (result._3 < 0) {
      println("Infinite")
    } else {
      println("Finite")
      println(result._3)
    }
}

import java.util.Scanner

import scala.io.StdIn

object Figures extends App {
  val line = new Scanner(StdIn.readLine())
  val n = line.nextInt()
  val a = StdIn.readLine().split(' ').map(_.toInt)
  var points = 0
  for(i <- 0 until n-1) {
    if (a(i) == 1) {
      if (a(i+1) == 2) {
        points += 3
      }
      if (a(i+1) == 3) {
        points += 4
      }
    }
    if (a(i) == 2) {
      if (a(i+1) == 1) {
        points += 3
      }
      if (a(i+1) == 3) {
        println("Infinite")
        System.exit(0)
      }
    }
    if (a(i) == 3) {
      if (a(i+1) == 1) {
        points += 4
        if (i+2 < n && a(i+2) == 2) {
          points -= 1
        }
      }
      if (a(i+1) == 2) {
        println("Infinite")
        System.exit(0)
      }
    }
  }
  println("Finite")
  println(points)

}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = 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]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def solve(): Unit = {
    val N = ni()
    val A = na(N)

    val Inf = 1e9.toInt
    val ans = sumL(map(N - 1) { i =>
      (A(i), A(i + 1)) match {
        case (1, 2) => 3
        case (1, 3) => 4
        case (2, 1) => 3
        case (2, 3) => Inf
        case (3, 1) => 4
        case (3, 2) => Inf
      }
    })

    if (ans >= Inf) out.println("Infinite")
    else {
      out.println("Finite")
      out.println(ans)
    }
  }
}

object Main extends App {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val result = a.foldLeft((0, 0, 0))((acc, next) => {
      if (acc._3 == -1) (0, 0, -1)
      else {
        (acc._1, acc._2,  next) match {
          case (2, 1, 3) => (acc._2, next, acc._3 + 3)
          case (_, 1, 2) => (acc._2, next, acc._3 + 3)
          case (_, 1, 3) => (acc._2, next, acc._3 + 4)
          case (_, 2, 1) => (acc._2, next, acc._3 + 3)
          case (_, 3, 1) => (acc._2, next, acc._3 + 4)
          case (_, 0, _) => (acc._2, next, 0)
          case _ => (0, 0, -1)
        }
      }
    })

    if (result._3 < 0) {
      println("Infinite")
    } else {
      println("Finite")
      println(result._3)
    }
}

object Main extends App {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val result = a.foldLeft((0, 0))((acc, next) => {
      if (acc._2 == -1) (0, -1)
      else {
        (acc._1, next) match {
          case (1, 2) => (next, acc._2 + 3)
          case (2, 1) => (next, acc._2 + 3)
          case (1, 3) => (next, acc._2 + 4)
          case (3, 1) => (next, acc._2 + 4)
          case (0, _) => (next, 0)
          case (_, _) => (0, -1)
        }
      }
    })

    if (result._2 < 0) {
      println("Infinite")
    } else {
      println("Finite")
      println(result._2)
    }
}