import java.io._
import java.util.StringTokenizer
import scala.+:
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object Main extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class fenwick(n: Int) {
        val tree = new Array[Long](n+1)
        def query(ind: Int): Long = {
            var idx = ind
            var ans = 0L
            while (idx > 0) {
                ans += tree(idx)
                idx -= (idx & -idx)
            }
            return ans
        }
        def update(ind: Int, value: Long): Unit = {
            var idx = ind
            while (idx <= n) {
                tree(idx) += value
                idx += (idx & -idx)
            }
        }
    }

    case class pair(val a: Int, val b:  Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return a.compareTo(that.a)
        }
    }

    def gcd(a: Int, b: Int): Int = b match {
        case 0 => a
        case n => gcd(b, a % b)
    }
    val rem = 1000000007
    val mp = mutable.Map[Char, Int]()

    val t = readInt()
    for (tt <- 1 to t) {
        val a = readInt()
        val b = readInt()
        val c = readInt()
        val k = a + c - 2 * b
        if (k % 3 == 0)
            writer.println(0)
        else
            writer.println(1)
    }
    writer.flush()
}

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

  override def solve(io: IO) = io.repeat {
    val a1, a2, a3 = io.read[Int]
    val ans = (a1 + a3 - 2*a2) % 3
    io.write(if (ans == 0) 0 else 1)
  }
}
/****************************[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 solve(io: IO): Any
  def main(args: Array[String]): Unit = {
    val io = new IO(System.in, System.out)
    try solve(io) finally io.close()
  }
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None

  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    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)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    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 {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[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
}
/***********************************[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")

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

  def write(obj: Any*): this.type = writeAll(obj)
  def writeLine(obj: Any*): this.type = {if (obj.isEmpty) printer.println() else obj.foreach(printer.println); this}
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = {printer.print(obj.mkString(separator)); this}
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  def repeat(f: => Unit): Unit = Utils.repeat(read[Int]){f; writeLine()}

  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
      }
    }
  }
}

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

  override def solve(io: IO) = io.repeat {
    val a1, a2, a3 = io.read[Int]
    val ans = (a1 + a3 - 2*a2) mod 3
    io.write(ans)
  }

  implicit class IntegralExtensions[A](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
  }
}
/****************************[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 solve(io: IO): Any
  def main(args: Array[String]): Unit = {
    val io = new IO(System.in, System.out)
    try solve(io) finally io.close()
  }
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None

  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    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)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    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 {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[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
}
/***********************************[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")

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

  def write(obj: Any*): this.type = writeAll(obj)
  def writeLine(obj: Any*): this.type = {if (obj.isEmpty) printer.println() else obj.foreach(printer.println); this}
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = {printer.print(obj.mkString(separator)); this}
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  def repeat(f: => Unit): Unit = Utils.repeat(read[Int]){f; writeLine()}

  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
      }
    }
  }
}


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, B = ns(N)

    def test(a0: Int, a1: Int, b0: Int, b1: Int) = {
      val cnt = mutable.Map[Int, Int]().withDefaultValue(0)
      def add(c: Int) { cnt(c) = cnt(c) + 1 }
      add(a0)
      add(a1)
      add(b0)
      add(b1)
      cnt.forall(_._2 % 2 == 0)
    }

    var ans = 0
    REP(N / 2) { i =>
      var ms = 2
      val zip = mutable.Set(A(i), A(N - 1 - i), B(i), B(N - 1 - i)).toSeq.zipWithIndex.toMap

      REP(4) { a0 =>
        REP(4) { a1 =>
          if (test(a0, a1, zip(B(i)), zip(B(N - 1 - i)))) {
            var cnt = 0
            if (a0 != zip(A(i))) cnt += 1
            if (a1 != zip(A(N - 1 - i))) cnt += 1
            ms = min(ms, cnt)
          }
        }
      }
      ans += ms
    }

    if (N % 2 > 0) {
      val i = N / 2
      if (A(i) != B(i)) ans += 1
    }

    out.println(ans)
  }

  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 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
  }
}

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, B = ns(N)

    val memo = Array.fill[Int](26, 26, 26, 26)(-1)
    def test(a0: Char, a1: Char, b0: Char, b1: Char) = {
      if (memo(a0-'a')(a1-'a')(b0-'a')(b1-'a') == -1) {
        val cnt = mutable.Map[Char, Int]().withDefaultValue(0)
        def add(c: Char) { cnt(c) = cnt(c) + 1 }
        add(a0)
        add(a1)
        add(b0)
        add(b1)
        memo(a0-'a')(a1-'a')(b0-'a')(b1-'a')  = if (cnt.forall(_._2 % 2 == 0)) 1 else 0
      }
      memo(a0-'a')(a1-'a')(b0-'a')(b1-'a') == 1
    }

    var ans = 0
    REP(N / 2) { i =>
      var ms = 2
      REP(26, 'a') { a0 =>
        REP(26, 'a') { a1 =>
          if (test(a0.toChar, a1.toChar, B(i), B(N - 1 - i))) {
            var cnt = 0
            if (a0 != A(i)) cnt += 1
            if (a1 != A(N - 1 - i)) cnt += 1
            ms = min(ms, cnt)
          }
        }
      }
      ans += ms
    }

    if (N % 2 > 0) {
      val i = N / 2
      if (A(i) != B(i)) ans += 1
    }

    out.println(ans)
  }

  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 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
  }
}

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, B = ns(N)

    val memo = Array.fill[Int](4, 4, 4, 4)(-1)
    def test(a0: Int, a1: Int, b0: Int, b1: Int) = {
      if (memo(a0)(a1)(b0)(b1) == -1) {
        val cnt = mutable.Map[Int, Int]().withDefaultValue(0)
        def add(c: Int) { cnt(c) = cnt(c) + 1 }

        add(a0)
        add(a1)
        add(b0)
        add(b1)
        memo(a0)(a1)(b0)(b1) = if (cnt.forall(_._2 % 2 == 0)) 1 else 0
      }
      memo(a0)(a1)(b0)(b1) == 1
    }

    var ans = 0
    REP(N / 2) { i =>
      var ms = 2
      val zip = mutable.Set(A(i), A(N - 1 - i), B(i), B(N - 1 - i)).toSeq.zipWithIndex.toMap

      REP(4) { a0 =>
        REP(4) { a1 =>
          if (test(a0, a1, zip(B(i)), zip(B(N - 1 - i)))) {
            var cnt = 0
            if (a0 != zip(A(i))) cnt += 1
            if (a1 != zip(A(N - 1 - i))) cnt += 1
            ms = min(ms, cnt)
          }
        }
      }
      ans += ms
    }

    if (N % 2 > 0) {
      val i = N / 2
      if (A(i) != B(i)) ans += 1
    }

    out.println(ans)
  }

  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 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
  }
}

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, B = ns(N)

    var ans = 0
    REP(N / 2) { i =>
      val cnt = mutable.Map[Char, Int]().withDefaultValue(0)
      def add(c: Char){ cnt(c) = cnt(c) + 1 }
      add(A(i))
      add(A(N - 1 - i))
      add(B(i))
      add(B(N - 1 - i))
      if (cnt.exists(_._2 % 2 > 0)) {
        if (B(i) == B(N - 1 - i)) ans += 1
        else {
          val bs = ArrayBuffer(B(i), B(N - 1 - i))
          bs -= A(i)
          bs -= A(N - 1 - i)
          ans += bs.size
        }
      }
    }

    if (N % 2 > 0) {
      val i = N / 2
      if (A(i) != B(i)) ans += 1
    }

    out.println(ans)
  }

  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 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
  }
}

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, B = ns(N)

    var ans = 0
    REP(N / 2) { i =>
      val cnt = mutable.Map[Char, Int]().withDefaultValue(0)
      def add(c: Char){ cnt(c) = cnt(c) + 1 }
      add(A(i))
      add(A(N - 1 - i))
      add(B(i))
      add(B(N - 1 - i))
      if (!(cnt.size == 1 || cnt.size == 2 && cnt.forall(_._2 == 2))) {
        val bs = ArrayBuffer(B(i), B(N - 1 - i))
        bs -= A(i)
        bs -= A(N - 1 - i)
        ans += bs.size
      }
    }

    if (N % 2 > 0) {
      val i = N / 2
      if (A(i) != B(i)) ans += 1
    }

    out.println(ans)
  }

  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 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
  }
}

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, B = ns(N)

    var ans = 0
    REP(N / 2) { i =>
      val cnt = mutable.Map[Char, Int]().withDefaultValue(0)
      def add(c: Char){ cnt(c) = cnt(c) + 1 }
      add(A(i))
      add(A(N - 1 - i))
      add(B(i))
      add(B(N - 1 - i))
      if (cnt.exists(_._2 % 2 > 0)) {
        val bs = ArrayBuffer(B(i), B(N - 1 - i))
        bs -= A(i)
        bs -= A(N - 1 - i)
        ans += bs.size
      }
    }

    if (N % 2 > 0) {
      val i = N / 2
      if (A(i) != B(i)) ans += 1
    }

    out.println(ans)
  }

  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 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.collection.mutable

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF263_3 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }
  val Array(n) = readInts(1)
  val arr  = readInts(n)

  val sortedArr = arr.sortBy(identity)
  var result = 0L
  var i = 0
  var multiplier = if(n==1) 1L else 2L
  while(i<n){
    result += (sortedArr(i).toLong * multiplier)
    multiplier = (multiplier + 1) min n
    i+=1
  }
  println(result)
}

//package solutions

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

/**
  * @author traff
  */

object Solution_TaskA extends App {
  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(scanner: Scanner, writer: PrintWriter): Unit = {
    val n = scanner.nextInt()
    var a = new Array[Int](n)
    for (i <- 1 to n) {
      a(i-1) = scanner.nextInt()
    }

    a = a.sortWith(_ < _)

    var sum: Long  = a.foldLeft(0:Long)((b: Long, i: Int) => b + i)
    var res = sum

    for (i <- 1 until n) {
      res += sum
      sum -= a(i-1)
    }

    writer.println(res)
  }
}

object A461 {
  @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) = readInts(1)
    val input = readLongs(n).sortBy(identity).reverse

    var res = 0L
    for(i <- input.indices) {
      if(i == 0 || i == 1) {
        res += input(i) * n
      } else {
        res += input(i) * (n-i+1)
      }
    }
    println(res)
  }
}

import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

/**
 * Created by Kuang.Ru on 14-9-18.
 */
object A461 extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  var a = new ArrayBuffer[Long]()
  var j = 0

  while (j < n) {
    a += sc.nextInt()
    j += 1
  }

  val newA = a.sortWith(_ > _)
  var score: Long = 0

  if (n >= 2) {
    score += newA(0) * n + newA(1) * n
    var i = 2

    while (i < n) {
      score += newA(i) * (n - i + 1)
      i += 1
    }
  } else {
    score += newA(0)
  }

  println(score)
}

object main extends App with fastIO {

  val n = nextInt

  var (ans, cnt) = (0l, 1l)
  var a = Array.fill(n)(nextInt) sortBy((i) => i)
  a foreach { (i) => cnt += 1; ans += i * cnt }

  println(ans - a.max)
  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.io.StdIn.readLine

object Main {
  def main(args: Array[String]): Unit = {
    readLine()
    val a = readLine().split(" ").map(_.toLong)
    val ans = if (a.length == 1) {
      a.head.toLong
    } else {
      a.sorted.zipWithIndex.map { case
        (x, i) => x * (i + 2)
      }.sum - a.max
    }
    println(ans)
  }
}

//package solutions

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

/**
  * @author traff
  */

object Solution_TaskA extends App {
  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(scanner: Scanner, writer: PrintWriter): Unit = {
    val n = scanner.nextInt()
    var a = new Array[Int](n)
    for (i <- 1 to n) {
      a(i-1) = scanner.nextInt()
    }

    a = a.sortWith(_ < _)

    var sum: Long  = a.sum
    var res = sum

    for (i <- 1 until n) {
      res += sum
      sum -= a(i-1)
    }

    writer.println(res)
  }
}

//package solutions

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

/**
  * @author traff
  */

object Solution_TaskA extends App {
  override def main(args: Array[String]): Unit = {
    val out = new PrintWriter(System.out)

    run(new Scanner(System.in), out)

    out.close()
  }

  def run(scanner: Scanner, writer: PrintWriter): Unit = {
    val n = scanner.nextInt()
    var a = new Array[Int](n)
    for (i <- 1 to n) {
      a(i-1) = scanner.nextInt()
    }

    a = a.sortWith(_ < _)

    var sum = a.sum
    var res = sum

    for (i <- 1 until n) {
      res += sum
      sum -= a(i-1)
    }

    writer.println(res)
  }
}

import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

/**
 * Created by Kuang.Ru on 14-9-18.
 */
object A461 extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  var a = new ArrayBuffer[Int]()
  var j = 0

  while (j < n) {
    a += sc.nextInt()
    j += 1
  }

  val newA = a.sortWith(_ > _)
  var score: Long = 0

  if (n >= 2) {
    score += newA(0) * n + newA(1) * n
    var i = 2

    while (i < n) {
      score += newA(i) * (n - i + 1)
      i += 1
    }
  } else {
    score += newA(0)
  }

  println(score)
}

object main extends App with fastIO {

  val n = nextInt

  var (ans, cnt) = (0, 1)
  var a = Array.fill(n)(nextInt) sortBy((i) => i)
  a foreach { (i) => cnt += 1; ans += i * cnt }

  println(ans - a.max)
  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()
}

object main extends App with fastIO {

  val n = nextInt

  var (ans, cnt) = (0l, 1)
  var a = Array.fill(n)(nextInt) sortBy((i) => i)
  a foreach { (i) => cnt += 1; ans += i * cnt }

  println(ans - a.max)
  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.collection.mutable

/**
 * Created by lurker on 2014. 8. 15..
 */
object CF263_3 extends App {
  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = {
    val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt)
  }
  val Array(n) = readInts(1)
  val arr  = readInts(n)

  val sortedArr = arr.sortBy(identity)
  var result = 0L
  var i = 0
  var multiplier = if(n==1) 1 else 2
  while(i<n){
    result += sortedArr(i) * multiplier
    multiplier = (multiplier + 1) min n
    i+=1
  }
  println(result)
}


object Main {
  def main(args: Array[String]) {
    val a = readLine().split(" ").map(_.toInt)
    val min = a.min

    println(min + 1)
    for(i <- 0 to min) println(i + " " + (min - i))
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val squares = (0 to n + m).foldLeft(Set.empty[Int]) {
    case (set, el) => set + el * el
  }
  val min = Math.min(m, n)
  println(min + 1)
  println((0 to min).map(i => s"$i ${min - i}").mkString("\n"))

}

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

object test5 extends App {
    val Array(n,m)=readLine.split(" ").map(_.toInt)
    val min=math.min(n,m)

    println(min+1)
    for(i<-0 to min) println(min-i+" "+i)
}

import scala.Math._;
import scala.collection.mutable.LinkedList

object App {
	def readInts:Array[Int] = (readLine split " ") map (_.toInt)
                                                  //> readInts: => Array[Int]                              //> solve: (n: Int, m: Int, prev: Int, a: Int, b: Int)(Int, Int)

	def solve(deep: Int, n: Int):Long = {
	  if (deep == n) n
	  else solve(deep + 1, n) + (deep * (n - deep))
	}

	def f1_io() = {
	    val Array(n, m) = readInts
		val a = min(n, m)
		println(a + 1)
		for(i <- 0 to a) {
		  println(i + " " + (m - i))
		}

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

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val squares = (0 to n + m).foldLeft(Set.empty[Int]) {
    case (set, el) => set + el * el
  }
  val fx = 0
  val fy = 0
  val result1 = (0 to n).foldLeft(List.empty[(Int, Int)]) {
    case(list, i) => (0 to m).foldLeft(list) {
      case (l, el) if el + i == 0 => l
      case (l, el) if l.forall{
        case(x, y) => !squares.contains((x - i)* (x - i) + (y - el) * (y - el))
      } => (i, el) :: l
      case (l, el) => l
    }
  }
  val result2 = (0 to m).foldLeft(List.empty[(Int, Int)]) {
    case(list, i) => (0 to n).foldLeft(list) {
      case (l, el) if el + i == 0 => l
      case (l, el) if l.forall{
        case(x, y) => !squares.contains((x - i)* (x - i) + (y - el) * (y - el))
      } => (el, i) :: l
      case (l, el) => l
    }
  }
  val result = if (result1.length > result2.length) result1 else result2
  println(result.length)
  println(result.map(i => s"${i._1} ${i._2}").mkString("\n"))
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val squares = (0 to n + m).foldLeft(Set.empty[Int]) {
    case (set, el) => set + el * el
  }
  val min = Math.min(m, n)
  println(min)
  println((0 to min).map(i => s"$i ${min - i}").mkString("\n"))

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val squares = (0 to n + m).foldLeft(Set.empty[Int]) {
    case (set, el) => set + el * el
  }
  val min = Math.min(m, n)
  println((0 to min).map(i => s"$i ${min - i}").mkString("\n"))

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val squares = (0 to n + m).foldLeft(Set.empty[Int]) {
    case (set, el) => set + el * el
  }
  val fx = 0
  val fy = 0
  val result = (0 to n).foldLeft(List.empty[(Int, Int)]) {
    case(list, i) => (0 to m).foldLeft(list) {
      case (l, el) if l.forall{
        case(x, y) => !squares.contains((x - i)* (x - i) + (y - el) * (y - el))
      } => (i, el) :: l
      case (l, el) => l
    }
  }

  println(result.length)
  println(result.map(i => s"${i._1} ${i._2}").mkString("\n"))
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  var Array(n, m) = in.next().split(' ').map(_.toInt)
  val squares = (0 to n + m).foldLeft(Set.empty[Int]) {
    case (set, el) => set + el * el
  }
  val result1 = (0 to n).foldLeft(List.empty[(Int, Int)]) {
    case(list, i) => (0 to m).foldLeft(list) {
      case (l, el) if el + i == 0 => l
      case (l, el) if l.forall{
        case(x, y) => !squares.contains((x - i)* (x - i) + (y - el) * (y - el))
      } => (i, el) :: l
      case (l, el) => l
    }
  }
  val result2 = (0 to m).foldLeft(List.empty[(Int, Int)]) {
    case(list, i) => (0 to n).foldLeft(list) {
      case (l, el) if el + i == 0 => l
      case (l, el) if l.forall{
        case(x, y) => !squares.contains((x - el)* (x - el) + (y - i) * (y - i))
      } => (el, i) :: l
      case (l, el) => l
    }
  }
  val result = if (result1.length > result2.length) result1 else result2
  println(result.length)
  println(result.map(i => s"${i._1} ${i._2}").mkString("\n"))
}

import scala.Math._;
import scala.collection.mutable.LinkedList

object App {
	def readInts:Array[Int] = (readLine split " ") map (_.toInt)
                                                  //> readInts: => Array[Int]                              //> solve: (n: Int, m: Int, prev: Int, a: Int, b: Int)(Int, Int)

	def solve(deep: Int, n: Int):Long = {
	  if (deep == n) n
	  else solve(deep + 1, n) + (deep * (n - deep))
	}

	def f1_io() : Int = {
	    val Array(n, m) = readInts
		//for(i <- 1 to 100; j <- i to 100; if (ceil(sqrt(i*i + j*j)) == floor(sqrt(i*i + j*j)))) println(i + " " + j + " " + sqrt(i*i + j*j))
	  	//val badPoint = for(i <- 1 to 100; j <- i to 100; if (ceil(sqrt(i*i + j*j)) == floor(sqrt(i*i + j*j)))) yield (i, j)
	  	if (n < m) {
	    val s1 = (for(i <- 1 to n; if ((i - 1) <= m)) yield (i, i - 1)).toList
	  	val s2 = (for(i <- 0 to n; if ((i + 1) <= m)) yield (i, i + 1)).toList
	  	if (s2.length > s1.length) {
	  	  println(s2.length)
	  	  s2.foreach {case (x, y) => println(x + " " + y)}
	  	  return 0;
	  	} else {
	  	  for(i <- 1 to m) {
	  	    var f = true
	  	    s1.foreach {
	  	      case (x, y) => {
	  	        val t = sqrt(x*x + (y-i)*(y-i))
	  	        if (ceil(t) == floor(t)) {
	  	          f = false
	  	        }
	  	      }
	  	    }
	  	    if (f) {
	  	      println(s1.length + 1)
	  	      println(0 + " " + i)
	  	      s1.foreach {case (x, y) => println(x + " " + y)}
	  	      return 0
	  	    }
	  	  }
	  	}
	    println(s2.length)
	  	s2.foreach {case (x, y) => println(x + " " + y)}
	  	}
	  	else {
	  	  println(m + 1)
	  	  for(i <- 0 to m) {
	  	    println(i + " " + (n - i))
	  	  }
	  	}
	    0
	}
  def main(args: Array[String]): Unit = {
	f1_io
  }

}

import scala.Math._;
import scala.collection.mutable.LinkedList

object App {
	def readInts:Array[Int] = (readLine split " ") map (_.toInt)
                                                  //> readInts: => Array[Int]                              //> solve: (n: Int, m: Int, prev: Int, a: Int, b: Int)(Int, Int)

	def solve(deep: Int, n: Int):Long = {
	  if (deep == n) n
	  else solve(deep + 1, n) + (deep * (n - deep))
	}

	def f1_io() = {
	    val Array(n, m) = readInts
		val a = min(n, m)
		println(a + 1)
		for(i <- 0 to a) {
		  println(i + " " + (n - i))
		}

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

}


import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
      val t = readInt()
      for (_ <- 1 to t) {
          val Array(n, m): Array[Int] = readLine().split(" ").map(_.toInt)
          val A: Array[Int] = readLine().split(" ").map(_.toInt)
          val B: Array[String] = Array.fill(m)("B")
          for (i <- 0 until n) {
              val a_i: Int = A(i)-1
              val a_i_rev: Int = m-(a_i+1)
              if (a_i < a_i_rev) {
                  if (B(a_i) == "B") {
                      B(a_i) = "A"
                  } else {
                      B(a_i_rev) = "A"
                  }
              }
              else {
                  if (B(a_i_rev) == "B") {
                      B(a_i_rev) = "A"
                  } else {
                      B(a_i) = "A"
                  }
              }
          }
          println(B.mkString(""))
      }
  }
}

object prob2 {
  def main(args: Array[String]) = {
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {

  import java.util.StringTokenizer
  import scala.collection.mutable
  import scala.collection.mutable._
  import scala.math.{abs,pow,min,max}
  import scala.collection.mutable.ListBuffer

  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val q = tokenizer.nextToken().toInt
    for (sss <- 0 until q) {
      tokenizer = new StringTokenizer(input.readLine())
      val n = tokenizer.nextToken().toInt
      val m = tokenizer.nextToken().toInt
      val A = new Array[String](m)
      for (i <- 0 until m){
        A(i)="B"
      }
      tokenizer = new StringTokenizer(input.readLine())
      for (i <- 1 to n){
        val p = tokenizer.nextToken().toInt
        if (p > m / 2) {
          if (A(m-p) == "A") {
            A(p-1) = "A"
          }
          else A(m-p) = "A"
        }
        else {
          if (A(p-1) == "A") {
            A(m-p) = "A"
          }
          else A(p-1) = "A"
        }
      }
      println(A.mkString)
    }
  }
}


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

/**
 * Created by arseny on 27.07.14.
 */
object B extends App {
  val home = true
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val n = nextDouble
    val m = nextDouble
    if (n == 0.0 || m == 0.0) {
      if (n == 0) {
        out.println(s"0 ${1}")
        out.println(s"0 ${m.toInt}")
        out.println(s"0 ${0}")
        out.println(s"0 ${(m - 1).toInt}")
      }
      if (m == 0) {
        out.println(s"${1} 0")
        out.println(s"${n.toInt} 0")
        out.println(s"${0} 0")
        out.println(s"${(n - 1).toInt} 0")
      }
    } else {

      def length(x: (Double, Double), y: (Double, Double)) = {
        Math.sqrt((x._1 - y._1) * (x._1 - y._1) + (x._2 - y._2) * (x._2 - y._2))
      }

      var X = (0.0, 0.0)
      var Y = (0.0, 0.0)
      var p = (0.0, 0.0)
      var q = (0.0, 0.0)
      var best = 0.0

      def chooseBest(x: (Double, Double), y: (Double, Double)) = {
        for (i <- 0 to n.toInt) {
          for (j <- 0 to m.toInt) {
            val z = i.toDouble
            val t = j.toDouble
            if (length(x, (z, 0.0)) + length((z, 0.0), (0.0, t)) + length((0.0, t), y) >= best) {
              if (x != (z, 0.0) && x != (0.0, t) && y != (z, 0.0) && y != (0.0, t)) {
                p = (z, 0.0)
                q = (0.0, t)
                X = x
                Y = y
                best = length(x, (z, 0.0)) + length((z, 0.0), (0.0, t)) + length((0.0, t), y)
              }
            }
            if (length(x, (z, m)) + length((z, m), (0.0, t)) + length((0.0, t), y) >= best) {
              if (x != (z, m) && x != (0.0, t) && y != (z, m) && y != (0.0, t)) {
                p = (z, m)
                q = (0.0, t)
                X = x
                Y = y
                best = length(x, (z, m)) + length((z, m), (0.0, t)) + length((0.0, t), y)
              }
            }
            if (length(x, (z, 0.0)) + length((z, 0.0), (n, t)) + length((n, t), y) >= best) {
              if (x != (z, 0.0) && x != (n, t) && y != (z, 0.0) && y != (n, t)) {
                p = (z, 0.0)
                q = (n, t)
                X = x
                Y = y
                best = length(x, (z, 0.0)) + length((z, 0.0), (n, t)) + length((n, t), y)
              }
            }
            if (length(x, (z, m)) + length((z, m), (n, t)) + length((n, t), y) >= best) {
              if (x != (z, m) && x != (n, t) && y != (z, m) && y != (n, t)) {
                p = (z, m)
                q = (n, t)
                X = x
                Y = y
                best = length(x, (z, m)) + length((z, m), (n, t)) + length((n, t), y)
              }
            }
          }
        }
      }

      chooseBest((0.0, 0.0), (n, m))
      chooseBest((0.0, 0.0), (n, 0))
      chooseBest((0.0, 0.0), (0, m))

      chooseBest((1, 0), (n - 1, m))
      chooseBest((0, 1), (n, m - 1))

      out.println(s"${X._1.toInt} ${X._2.toInt}")
      out.println(s"${p._1.toInt} ${p._2.toInt}")
      out.println(s"${q._1.toInt} ${q._2.toInt}")
      out.println(s"${Y._1.toInt} ${Y._2.toInt}")

      //out.println(best)
    }
  }

  try {
    solve()
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }
}

/**
 * I've tried to make this piece of code as readable as possible.
 * Enjoy hacking it!
 */
object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(n, m) = readInts(2)

  if (n == 0) {
    println(s"0 1")
    println(s"0 $m")
    println(s"0 0")
    println(s"0 ${m - 1}")
  } else if (m == 0) {
    println(s"1 0")
    println(s"$n 0")
    println(s"0 0")
    println(s"${n - 1} 0")
  } else if (n <= m) {
    var best = -1d
    var bestI = 0
    var bestJ = 0
    for (i <- 1 to n) {
      val d1 = Math.sqrt(m * m + (n - i) * (n - i))
      for (j <- 0 until n) {
        val d2 = Math.sqrt(m * m + (j - i) * (j - i))
        if (d1 + d2 > best) {
          best = d1 + d2
          bestI = i
          bestJ = j
        }
      }
    }
    val other = 2d * Math.sqrt(m * m + (n - 1) * (n - 1))
    if (best > other) {
      println(s"0 0")
      println(s"$n $m")
      println(s"$bestI 0")
      println(s"$bestJ $m")
    } else {
      println(s"1 0")
      println(s"$n $m")
      println(s"0 0")
      println(s"${n - 1} $m")
    }
  } else {
    var best = -1d
    var bestI = 0
    var bestJ = 0
    for (i <- 1 to m) {
      val d1 = Math.sqrt(n * n + (m - i) * (m - i))
      for (j <- 0 until m) {
        val d2 = Math.sqrt(n * n + (j - i) * (j - i))
        if (d1 + d2 > best) {
          best = d1 + d2
          bestI = i
          bestJ = j
        }
      }
    }
    val other = 2d * Math.sqrt(n * n + (m - 1) * (m - 1))
    if (best > other) {
      println(s"0 0")
      println(s"$n $m")
      println(s"0 $bestI")
      println(s"$n $bestJ")
    } else {
      println(s"0 1")
      println(s"$n $m")
      println(s"0 0")
      println(s"$n ${m - 1}")
    }
  }

}

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

/**
 * Created by arseny on 27.07.14.
 */
object B extends App {
  val home = true
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val n = nextDouble
    val m = nextDouble
    if (n == 0.0 || m == 0.0) {
      if (n == 0) {
        out.println(s"0 ${1}")
        out.println(s"0 ${m.toInt}")
        out.println(s"0 ${0}")
        out.println(s"0 ${(m - 1).toInt}")
      }
      if (m == 0) {
        out.println(s"${1} 0")
        out.println(s"${n.toInt} 0")
        out.println(s"${0} 0")
        out.println(s"${(n - 1).toInt} 0")
      }
    } else {

      def length(x: (Double, Double), y: (Double, Double)) = {
        Math.sqrt((x._1 - y._1) * (x._1 - y._1) + (x._2 - y._2) * (x._2 - y._2))
      }

      var X = (0.0, 0.0)
      var Y = (0.0, 0.0)
      var p = (0.0, 0.0)
      var q = (0.0, 0.0)
      var best = 0.0

      def chooseBest(x: (Double, Double), y: (Double, Double)) = {
        for (i <- 0 to n.toInt) {
          for (j <- 0 to m.toInt) {
            val z = i.toDouble
            val t = j.toDouble
            if (length(x, (z, 0.0)) + length((z, 0.0), (0.0, t)) + length((0.0, t), y) >= best) {
              if (x != (z, 0.0) && x != (0.0, t) && y != (z, 0.0) && y != (0.0, t)) {
                p = (z, 0.0)
                q = (0.0, t)
                X = x
                Y = y
                best = length(x, (z, 0.0)) + length((z, 0.0), (0.0, t)) + length((0.0, t), y)
              }
            }
            if (length(x, (z, m)) + length((z, m), (0.0, t)) + length((0.0, t), y) >= best) {
              if (x != (z, m) && x != (0.0, t) && y != (z, m) && y != (0.0, t)) {
                p = (z, m)
                q = (0.0, t)
                X = x
                Y = y
                best = length(x, (z, m)) + length((z, m), (0.0, t)) + length((0.0, t), y)
              }
            }
            if (length(x, (z, 0.0)) + length((z, 0.0), (n, t)) + length((n, t), y) >= best) {
              if (x != (z, 0.0) && x != (n, t) && y != (z, 0.0) && y != (n, t)) {
                p = (z, 0.0)
                q = (n, t)
                X = x
                Y = y
                best = length(x, (z, 0.0)) + length((z, 0.0), (n, t)) + length((n, t), y)
              }
            }
            if (length(x, (z, m)) + length((z, m), (n, t)) + length((n, t), y) >= best) {
              if (x != (z, m) && x != (n, t) && y != (z, m) && y != (n, t)) {
                p = (z, m)
                q = (n, t)
                X = x
                Y = y
                best = length(x, (z, m)) + length((z, m), (n, t)) + length((n, t), y)
              }
            }
          }
        }
      }

      chooseBest((0.0, 0.0), (n, m))
      chooseBest((0.0, 0.0), (n, 0))
      chooseBest((0.0, 0.0), (0, m))

      out.println(s"${X._1.toInt} ${X._2.toInt}")
      out.println(s"${p._1.toInt} ${p._2.toInt}")
      out.println(s"${q._1.toInt} ${q._2.toInt}")
      out.println(s"${Y._1.toInt} ${Y._2.toInt}")

      //out.println(best)
    }
  }

  try {
    solve()
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }
}

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

/**
 * Created by arseny on 27.07.14.
 */
object B extends App {
  val home = true
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val n = nextDouble
    val m = nextDouble
    if (n == 0.0 || m == 0.0) {
      if (n == 0) {
        out.println(s"0 ${1}")
        out.println(s"0 ${m.toInt}")
        out.println(s"0 ${0}")
        out.println(s"0 ${(m - 1).toInt}")
      }
      if (m == 0) {
        out.println(s"${1} 0")
        out.println(s"${m.toInt} 0")
        out.println(s"${0} 0")
        out.println(s"${(m - 1).toInt} 0")
      }
    } else {

      def length(x: (Double, Double), y: (Double, Double)) = {
        Math.sqrt((x._1 - y._1) * (x._1 - y._1) + (x._2 - y._2) * (x._2 - y._2))
      }

      var X = (0.0, 0.0)
      var Y = (0.0, 0.0)
      var p = (0.0, 0.0)
      var q = (0.0, 0.0)
      var best = 0.0

      def chooseBest(x: (Double, Double), y: (Double, Double)) = {
        for (i <- 0 to n.toInt) {
          for (j <- 0 to m.toInt) {
            val z = i.toDouble
            val t = j.toDouble
            if (length(x, (z, 0.0)) + length((z, 0.0), (0.0, t)) + length((0.0, t), y) >= best) {
              if (x != (z, 0.0) && x != (0.0, t) && y != (z, 0.0) && y != (0.0, t)) {
                p = (z, 0.0)
                q = (0.0, t)
                X = x
                Y = y
                best = length(x, (z, 0.0)) + length((z, 0.0), (0.0, t)) + length((0.0, t), y)
              }
            }
            if (length(x, (z, m)) + length((z, m), (0.0, t)) + length((0.0, t), y) >= best) {
              if (x != (z, m) && x != (0.0, t) && y != (z, m) && y != (0.0, t)) {
                p = (z, m)
                q = (0.0, t)
                X = x
                Y = y
                best = length(x, (z, m)) + length((z, m), (0.0, t)) + length((0.0, t), y)
              }
            }
            if (length(x, (z, 0.0)) + length((z, 0.0), (n, t)) + length((n, t), y) >= best) {
              if (x != (z, 0.0) && x != (n, t) && y != (z, 0.0) && y != (n, t)) {
                p = (z, 0.0)
                q = (n, t)
                X = x
                Y = y
                best = length(x, (z, 0.0)) + length((z, 0.0), (n, t)) + length((n, t), y)
              }
            }
            if (length(x, (z, m)) + length((z, m), (n, t)) + length((n, t), y) >= best) {
              if (x != (z, m) && x != (n, t) && y != (z, m) && y != (n, t)) {
                p = (z, m)
                q = (n, t)
                X = x
                Y = y
                best = length(x, (z, m)) + length((z, m), (n, t)) + length((n, t), y)
              }
            }
          }
        }
      }

      chooseBest((0.0, 0.0), (n, m))
      chooseBest((0.0, 0.0), (n, 0))
      chooseBest((0.0, 0.0), (0, m))

      out.println(s"${X._1.toInt} ${X._2.toInt}")
      out.println(s"${p._1.toInt} ${p._2.toInt}")
      out.println(s"${q._1.toInt} ${q._2.toInt}")
      out.println(s"${Y._1.toInt} ${Y._2.toInt}")

      //out.println(best)
    }
  }

  try {
    solve()
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }
}

/**
 * I've tried to make this piece of code as readable as possible.
 * Enjoy hacking it!
 */
object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }

  val Array(n, m) = readInts(2)

  if (n == 0) {
    println(s"0 1")
    println(s"0 $m")
    println(s"0 0")
    println(s"0 ${m - 1}")
  } else if (m == 0) {
    println(s"1 0")
    println(s"$n 0")
    println(s"0 0")
    println(s"${n - 1} 0")
  } else if (n <= m) {
    var best = -1d
    var bestI = 0
    var bestJ = 0
    for (i <- 1 to n) {
      val d1 = Math.sqrt(m * m + (n - i) * (n - i))
      for (j <- 0 until n) {
        val d2 = Math.sqrt(m * m + (j - i) * (j - i))
        if (d1 + d2 > best) {
          best = d1 + d2
          bestI = i
          bestJ = j
        }
      }
    }
    val other = 2d * Math.sqrt(m * m + (n - 1) * (n - 1))
    if (best > other) {
      println(s"0 0")
      println(s"$n $m")
      println(s"$bestI 0")
      println(s"$bestJ $m")
    } else {
      println(s"1 0")
      println(s"$n $m")
      println(s"0 0")
      println(s"${n - 1} $m")
    }
  } else {
    var best = -1d
    var bestI = 0
    var bestJ = 0
    for (i <- 1 to m) {
      val d1 = Math.sqrt(n * n + (m - i) * (m - i))
      for (j <- 0 until m) {
        val d2 = Math.sqrt(n * n + (j - i) * (j - i))
        if (d1 + d2 > best) {
          best = d1 + d2
          bestI = i
          bestJ = j
        }
      }
    }
    val other = 2d * Math.sqrt(m * m + (n - 1) * (n - 1))
    if (best > other) {
      println(s"0 0")
      println(s"$n $m")
      println(s"0 $bestI")
      println(s"$n $bestJ")
    } else {
      println(s"0 1")
      println(s"$n $m")
      println(s"0 0")
      println(s"$n ${m - 1}")
    }
  }

}


/**
 * I've tried to make this piece of code as readable as possible.
 * Enjoy hacking it!
 */
import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(a, b) = readInts(2)

  for (x1 <- 1 until a; y1 <- 1 until a) if (x1 * x1 + y1 * y1 == a * a) {
    val x2 = -y1 * b / a
    val y2 = x1 * b / a
    if (x2 * x2 + y2 * y2 == b * b && y2 != y1) {
      println("YES")
      println("0 0")
      println(s"$x1 $y1")
      println(s"$x2 $y2")
      exit
    }
  }

  println("NO")
}

import java.util.StringTokenizer;
object Tri {
  var st:StringTokenizer=new StringTokenizer("");
  def newst={st=new StringTokenizer(readLine);}
  def newint:Int={st.nextToken.toInt;}
  def gcd(a:Int,b:Int):Int = {
    if (a<b) {gcd(b,a);} else if (b==0) {a;} else {gcd(b,a%b);}
  }
  def main(args:Array[String]) {
    newst; var a=newint; var b=newint; var g=gcd(a,b);
    for (x<-1 to g; y<-1 to g) {
      var z = x*x + y*y;
      if ((x>y) && (g%(x*x + y*y) == 0)) {
	var m:Int=1;
	if (a*(x*x-y*y)==b*2*x*y) {m=(-1);}
	/* if negativing does not solve the problem, then
	 * we will have a=b. But if a=b, the current angle
	 * should be 45, but the current cos is rational.
	 * cos 45 isn't rational. Contradiction. So negativing
	 * solves the problem, if at all possible.
	 */
	println("YES");
	println("0 0");
	println(a*(x*x - y*y)/z + " " + a*2*x*y/z);
	println(m*b*2*x*y/z + " " + m*b*(y*y-x*x)/z);
	System.exit(0);
      }
    }
    println("NO");
  }
}

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 A, B = ni()
    def pythagorean(x: Int) = {
      val res = ArrayBuffer[(Int, Int)]()
      REP(x, 1) { a =>
        val bSqr = (x + a) * (x - a)
        val b = math.sqrt(bSqr).toInt
        if (b * b == bSqr && b > 0) res += a -> b
      }
      res
    }

    val as = pythagorean(A) // pos-X -> pos-Y の部分
    val bs = pythagorean(B) // neg-Y -> pos-X の部分

    (for {
      (ax, ay) <- as
      (bx, by) <- bs
      if ax * bx + ay * -by == 0 && ax != bx
    } yield (ax -> ay, bx -> by)).headOption match {
      case Some(((ax, ay), (bx, by))) =>
        out.println("YES")
        out.println("0 0")
        out.println(s"$ax $ay")
        out.println(s"$bx -$by")

      case None =>
        out.println("NO")
    }
  }

  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 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[Int](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }

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

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

import java.util.StringTokenizer;
object Tri {
  var st:StringTokenizer=new StringTokenizer("");
  def newst={st=new StringTokenizer(readLine);}
  def newint:Int={st.nextToken.toInt;}
  def gcd(a:Int,b:Int):Int = {
    if (a<b) {gcd(b,a);} else if (b==0) {a;} else {gcd(b,a%b);}
  }
  def main(args:Array[String]) {
    newst; var a=newint; var b=newint; var g=gcd(a,b);
    for (x<-1 to g; y<-1 to g) {
      if ((x>y) && (g%(x*x + y*y) == 0)) {
	var z=x*x + y*y;
	println("YES");
	println("0 0");
	println(a*(x*x - y*y)/z + " " + a*2*x*y/z);
	println(b*2*x*y/z + " " + b*(y*y-x*x)/z);
	System.exit(0);
      }
    }
    println("NO");
  }
}

/**
 * I've tried to make this piece of code as readable as possible.
 * Enjoy hacking it!
 */
import scala.collection._

object A extends App {

  def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toInt) }

  val Array(a, b) = readInts(2)

  for (x1 <- 1 until a; y1 <- 1 until a) if (x1 * x1 + y1 * y1 == a * a) {
    val x2 = -y1 * b / a
    val y2 = x1 * b / a
    if (x2 * x2 + y2 * y2 == b * b) {
      println("YES")
      println("0 0")
      println(s"$x1 $y1")
      println(s"$x2 $y2")
      exit
    }
  }

  println("NO")
}


object A445 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val in = Array.fill(n)(read.toCharArray)
    def isValid(i: Int, j: Int): Boolean = {
      i >= 0 && i < n && j >=0 && j < m
    }
    val delta = Array((1,0), (0,1), (-1,0), (0,-1))
    for(i <- 0 until n; j <- 0 until m if in(i)(j) == '.') {
      if((i+j)%2 == 0)
        in(i)(j) = 'B'
      else
        in(i)(j) = 'W'
    }
    println(in.map(_.mkString("")).mkString("\n"))
  }

  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 scala.collection.mutable.HashMap
import scala.collection.mutable.HashSet

object Main extends App {

  val Array(n,m) = readLine.split(" ").map(_.toInt)
  val board = HashSet((0 to (n-1)).flatMap({ i =>
    val good = readLine.map({ case '.' => true case '-' => false }).zipWithIndex.filter(_._1)
    good.map(_._2).map((i, _))
  }):_*)

  val draw = HashMap[(Int, Int), Boolean]()

  def isValid(pos: (Int,Int)): Boolean = pos match { case (i,j) =>
    (i >= 0) && (i < n) && (j >= 0) && (j < m) && board.contains((i,j))
  }

  def setColor(value: Boolean)(pos: (Int, Int)): Unit = {
    board -= pos
    draw += (pos -> value)
    val (i,j) = pos
    val ns = List((i-1, j), (i+1, j), (i, j-1), (i, j+1)).filter(isValid(_))
    ns foreach setColor(!value)
  }

  while(board.size > 0) {
    setColor(true)(board.head)
  }

  (0 to (n-1)) foreach { i =>
    println((0 to (m-1)).map(j => {
      draw.get((i,j)).map({ case true => "W" case false => "B" }).getOrElse("-")
    }).mkString)
  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  Range(0, n).foreach { i =>
    println(in.next().zipWithIndex.map{
      case('.', index) if (i + index) % 2 == 0 => 'B'
      case('.', index) => 'W'
      case(ch, _) => ch
    }.mkString)
  }

}

object Main extends App {
  val sc = new java.util.Scanner(System.in)

  val n, m = sc.nextInt()
  val board = Array.fill(n)(sc.next)

  println(new A(n, m, board).answer.mkString("\n"))
}

class A(n: Int, m: Int, board: Array[String]) {
  def answer: Array[String] = {
    val cahrs = for{
      (line, y) <- board.zipWithIndex
      (char, x) <- line.zipWithIndex
    } yield char match {
        case '.' => if ((x+y) % 2 == 0) 'B' else 'W'
        case '-' => '-'
      }

    cahrs.grouped(m).map(_.mkString("")).toArray
  }
}

import java.util.StringTokenizer

object _445A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val m = next.toInt
  val a = (1 to n).map(i => next.toArray).toArray
  for (i <- 0 until n)
    for (j <- 0 until m)
      if (a(i)(j) == '.') a(i)(j) = if ((i + j) % 2 == 0) 'W' else 'B'

  a.foreach(i => println(i.mkString))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  Range(0, m).foreach { i =>
    println(in.next().zipWithIndex.map{
      case('.', index) if (i + index) % 2 == 0 => 'B'
      case('.', index) => 'W'
      case(ch, _) => ch
    }.mkString)
  }

}

object A445 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val in = Array.fill(n)(read.toCharArray)
    def isValid(i: Int, j: Int): Boolean = {
      i >= 0 && i < n && j >=0 && j < m
    }
    val delta = Array((1,0), (0,1), (-1,0), (0,-1))
    for(i <- 0 until n; j <- 0 until m if in(i)(j) == '.') {
      var b = 0
      var w = 0
      delta.foreach {
        case (dx, dy) if isValid(i+dx, j+dy)=>
          if(in(i+dx)(j+dy) == 'B') {
            b += 1
          }
          if(in(i+dx)(j+dy) == 'W') {
            w += 1
          }
        case _ =>
      }
      if(in(i)(j) == '.') {
        if(w > 0)
          in(i)(j) = 'B'
        else
          in(i)(j) = 'W'
      }
    }
    println(in.map(_.mkString("")).mkString("\n"))
  }

  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 scala.collection.mutable.HashMap
import scala.collection.mutable.HashSet

object Main extends App {

  val Array(n,m) = readLine.split(" ").map(_.toInt)
  val board = HashSet((0 to (n-1)).flatMap({ i =>
    val good = readLine.map({ case '.' => true case '-' => false }).zipWithIndex.filter(_._1)
    good.map(_._2).map((i, _))
  }):_*)

  val draw = HashMap[(Int, Int), Boolean]()

  def isValid(i: Int, j: Int): Boolean = {
    (i >= 0) && (i < n) && (j >= 0) && (j < n) && board.contains((i,j))
  }

  def setColor(pos: (Int, Int), value: Boolean): Unit = {
    board -= pos
    draw += (pos -> value)
    val (i,j) = pos
    for {
     di <- (-1 to 1)
     dj <- (-1 to 1)
     if Math.abs(di + dj) == 1
     if isValid(i+di, j+dj)
    } yield setColor((i+di, j+dj), !value)
  }

  while(board.size > 0) {
    setColor(board.head, true)
  }

  (0 to (n-1)) foreach { i =>
    println((0 to (m-1)).map(j => draw.get((i,j)).map({ case true => "W" case false => "B" }).getOrElse("-")).mkString)
  }

}


import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.annotation.switch
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.collection.immutable.TreeSet
import scala.util.Random
import scala.util.control.Breaks._

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

  // two non negative integer top/bottom ... a_i/b_i
  // A_i point and additional opportunity to play b_i additional cards

  def solve(): Int = {
    val N = sc.nextInt
    val C = List.fill(N, 2)(sc.nextInt)

    val C0 = C.filter(_(1) == 0).map(_(0)).sorted(Ordering.Int.reverse)
    val C1 = C.filter(_(1) > 0).map(_(0))

    // # of additional cards for C0
    val n  = C.transpose.toList(1).map { (i: Int) => (i - 1) max 0 }.sum + 1

    C1.sum + C0.take(n).sum
  }

  out.println(solve)
  out.close
}

object B {
  def main(args: Array[String]): Unit = {
   val cards = scala.io.Source.stdin.getLines().toList.tail.map(s => {val a = s.split(" "); (a(0).toInt, a(1).toInt)})
   val good = cards.filter(_._2>0)
   val toplay = good.map(_._2-1).sum+1

   System.out.println(good.map(_._1).sum+cards.filter(_._2==0).map(_._1).sort(_>_).take(toplay).sum)
  }
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = (1 to n).map(_ => readLine().split(" ").map(_.toInt))

    val t = a.filter(_.apply(1) != 0).foldLeft((0, 1)) { (acc, e) =>
      (acc._1 + e(0), acc._2 + e(1) - 1)
    }
    val sum = a.filter(_.apply(1) == 0).map(_.apply(0)).sorted.reverse.take(t._2).sum
    println(t._1 + sum)
  }
}

import java.util.Scanner

/**
 * Created by IntelliJ IDEA.
 * User: User
 * Date: 29.02.12
 * Time: 2:06
 * To change this template use File | Settings | File Templates.
 */

object B {
  val input = new Scanner(System.in)

  def main(args: Array[String]) {
    val count = input.nextInt
    val cards = (1 to count).map(_ => Card(input.nextInt, input.nextInt)).sorted
    def calc():Int = {
      var points = 0
      var steps = 1
      for (Card(value, step) <- cards) {
        steps -= 1
        steps += step
        points += value
        if(steps == 0 ) return points
      }
      return points
    }
    val x = calc()
    println(x)
  }

  case class Card(value: Int, step: Int) extends Comparable[Card] {
    def compareTo(o: Card) = this.step.compareTo(o.step) match {
      case 0 => -this.value.compareTo(o.value)
      case some => -some
    }
  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val r = (1 to n).map(_ => in.next().split(' ').map(_.toInt)).toList
  val (counter, sum) = r.filter(_.last > 0).foldLeft((1, 0)) {
    case ((c, s), e) =>
      (c + e.last - 1, s + e.head)
  }
  println(sum + r.filter(_.last == 0).map(_.head).sorted.takeRight(counter).sum)
}

object Main
{
	def main(args:Array[String])
	{
		val n = readInt
		val lol = (0 until n).map(i => readLine.split(" ").map(j => j.toInt)).toList

		val notzeroarray = lol.filter(i => i(1) > 0).map(i => i(0))
		val b = lol.map(i => i(1)).sum - notzeroarray.length + 1
		val notzeropts = notzeroarray.sum

		val zeroarray = lol.filter(i => i(1) == 0).map(i => i(0)).sort((s, t) => s > t)

		var carts = 0;
		if (b > zeroarray.length)
			carts = zeroarray.length
		else carts = b

		val zeropts = (0 until carts).map(i => zeroarray(i)).sum

		println(notzeropts + zeropts)
	}
}

import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.annotation.switch
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.collection.immutable.TreeSet
import scala.util.Random
import scala.util.control.Breaks._

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

  // two non negative integer top/bottom ... a_i/b_i
  // A_i point and additional opportunity to play b_i additional cards

  def solve(): Int = {
    val N = sc.nextInt
    val C = List.fill(N, 2)(sc.nextInt)

    val n = C.transpose.toList(1).sum + 1 // the number of playable cards
    C.transpose.toList(0).sorted(Ordering.Int.reverse).take(n).sum
  }

  out.println(solve)
  out.close
}

object B {
  def main(args: Array[String]): Unit = {
   val cards = scala.io.Source.stdin.getLines().toList.tail.map(s => {val a = s.split(" "); (a(0).toInt, a(1).toInt)})
   val good = cards.filter(_._2>0)
   val toplay = good.map(_._2).sum+1

   System.out.println(good.map(_._1).sum+cards.filter(_._2==0).map(_._1).sort(_>_).take(toplay).sum)
  }
}