import scala.annotation.tailrec

object Main extends App {

  override def main(args: Array[String]): Unit = {
    val answerMap = Solver.solveAll
    import scala.io.{StdIn => in}
    Iterator.continually(in.readLine()).takeWhile(str => !(str startsWith "0 0 0")).map(_.split(" ")).map(arr => new Solver(arr(0).toInt, arr(1).toInt, arr(2).toInt))
      .map(solver => solver.solve(answerMap)).foreach(println)
  }

}


sealed trait Coordination {
  val x: Int
  val y: Int
}

object Coordination {
  def apply(x: Int, y: Int): Coordination =
    if (((x + y) & 1) == 1) OddCoordination(x, y)
    else EvenCoordination(x, y)

}

case class OddCoordination(x: Int, y: Int) extends Coordination {}

case class EvenCoordination(x: Int, y: Int) extends Coordination {}

case class Face(bottom: Int, southOrNorth: Int)

sealed trait CoordinationAndFace {
  val coordination: Coordination
  val face: Face

  def next: Seq[CoordinationAndFace]

  val toKeySring: String = List(coordination.x, coordination.y, face.bottom, face.southOrNorth).mkString(",")
}

object CoordinationAndFace {
  def apply(coordination: Coordination, face: Face): CoordinationAndFace = {
    coordination match {
      case e: EvenCoordination => EvenCoordinationAndFace(e, face)
      case o: OddCoordination => OddCoordinationAndFace(o, face)
    }
  }
}

case class EvenCoordinationAndFace(coordination: EvenCoordination, face: Face) extends CoordinationAndFace {
  override def next = Seq(toNorth, toSouthEast, toSouthWest)

  val now = IcosahedronFaces(face.bottom)(face.southOrNorth)

  def toNorth: CoordinationAndFace = {
    val newCoordination = Coordination(coordination.x, coordination.y + 1)
    val nextFace = IcosahedronFaces(now.top)(now.n)
    val newFace = Face(nextFace.n, nextFace.top)
    CoordinationAndFace(newCoordination, newFace)
  }

  def toSouthWest: CoordinationAndFace = {
    val newCoordination = Coordination(coordination.x - 1, coordination.y)
    val nextFace = IcosahedronFaces(now.right)(now.n)
    val newFace = Face(nextFace.n, nextFace.left)
    CoordinationAndFace(newCoordination, newFace)
  }

  def toSouthEast: CoordinationAndFace = {
    val newCoordination = Coordination(coordination.x + 1, coordination.y)
    val nextFace = IcosahedronFaces(now.left)(now.n)
    val newFace = Face(nextFace.n, nextFace.right)
    CoordinationAndFace(newCoordination, newFace)
  }
}

case class OddCoordinationAndFace(coordination: OddCoordination, face: Face) extends CoordinationAndFace {
  override def next = Seq(toSouth, toNorthEast, toNorthWest)

  val now = IcosahedronFaces(face.bottom)(face.southOrNorth)

  def toSouth: CoordinationAndFace = {
    val newCoordination = Coordination(coordination.x, coordination.y - 1)
    val nextFace = IcosahedronFaces(now.top)(now.n)
    val newFace = Face(nextFace.n, nextFace.top)
    CoordinationAndFace(newCoordination, newFace)
  }

  def toNorthWest: CoordinationAndFace = {
    val newCoordination = Coordination(coordination.x - 1, coordination.y)
    val nextFace = IcosahedronFaces(now.left)(now.n)
    val newFace = Face(nextFace.n, nextFace.right)
    CoordinationAndFace(newCoordination, newFace)
  }

  def toNorthEast: CoordinationAndFace = {
    val newCoordination = Coordination(coordination.x + 1, coordination.y)
    val nextFace = IcosahedronFaces(now.right)(now.n)
    val newFace = Face(nextFace.n, nextFace.left)
    CoordinationAndFace(newCoordination, newFace)
  }

}

sealed case class IcosahedronFace(n: Int, top: Int, left: Int, right: Int) {
  def apply(asTop: Int): IcosahedronFace = {
    asTop match {
      case `top` => this
      case `left` => IcosahedronFace(n, left, right, top)
      case `right` => IcosahedronFace(n, right, top, left)
    }
  }
}

object IcosahedronFaces {
  private val list = List(
    IcosahedronFace(0, 5, 1, 4),
    IcosahedronFace(1, 6, 2, 0),
    IcosahedronFace(2, 7, 3, 1),
    IcosahedronFace(3, 8, 4, 2),
    IcosahedronFace(4, 9, 0, 3),
    IcosahedronFace(5, 0, 10, 11),
    IcosahedronFace(6, 1, 11, 12),
    IcosahedronFace(7, 2, 12, 13),
    IcosahedronFace(8, 3, 13, 14),
    IcosahedronFace(9, 4, 14, 10),
    IcosahedronFace(10, 15, 5, 9),
    IcosahedronFace(11, 16, 6, 5),
    IcosahedronFace(12, 17, 7, 6),
    IcosahedronFace(13, 18, 8, 7),
    IcosahedronFace(14, 19, 9, 8),
    IcosahedronFace(15, 10, 19, 16),
    IcosahedronFace(16, 11, 15, 17),
    IcosahedronFace(17, 12, 16, 18),
    IcosahedronFace(18, 13, 17, 19),
    IcosahedronFace(19, 14, 18, 15)
  )

  def apply(n: Int): IcosahedronFace = n match {
    case n: Int if ((0 to 19).contains(n)) => list(n)
  }
}


class Solver(x: Int, y: Int, n: Int) {

  import Solver._

  def solve(answerMap: Array[Int]): Int = {
    if (-100 > x || -100 > y || x >= 100 || y >= 100) {
      val coordination = Coordination(x, y)
      val missing = coordination match {
        case e: EvenCoordination => 100
        case o: OddCoordination => 99
      }
      return missing
    }

    val coordination = Coordination(x, y)
    val missing = coordination match {
      case e: EvenCoordination => 100
      case o: OddCoordination => 99
    }

    val iface = IcosahedronFaces(n)

    val keys = List(
      CoordinationAndFace(coordination, Face(n, iface.top)),
      CoordinationAndFace(coordination, Face(n, iface.left)),
      CoordinationAndFace(coordination, Face(n, iface.right))
    )

    keys.map(cf => answerMap(coordinationAndFaceToInt(cf))).map(v => if (v == 0) missing else v).min
  }

}

object Solver {

  def solveAll: Array[Int] = {
    val init: CoordinationAndFace = CoordinationAndFace(Coordination(0, 0), Face(0, 5))

    import scala.collection.mutable.{Queue => MQueue}

    def solveInner(map: Array[Int], queue: MQueue[(CoordinationAndFace, Int)]): Boolean = {
      val head = queue.dequeue()
      if (head._2 < 98) {
        val candidate = head._1.next
        val nextCost = head._2 + 1
        candidate.filter(cf => map(coordinationAndFaceToInt(cf)) == 0).foreach {
          next =>
            map(coordinationAndFaceToInt(next)) = nextCost
            queue.enqueue((next, nextCost))
        }
        true
      }
      else false
    }

    val map = Array.ofDim[Int](xWidth * xPosition)
    val queue = MQueue(init -> 0)
    while(solveInner(map, queue)){}
    map
  }

  val xOffset = 100
  val yOffset = 100
  val xWidth = 200
  val yWidth = 200
  val bottomWidth = 20
  val southOrNorthWidth = 20

  val southOrNorthPosition = 1
  val bottom = southOrNorthWidth * southOrNorthPosition
  val yPosition = bottomWidth * bottom
  val xPosition = yWidth * yPosition

  def toInt(x: Int, y: Int, buttom: Int, southOrNorth: Int): Int = {
    (x + xOffset) * xPosition + (y + yOffset) * yPosition + (buttom) * bottom + (southOrNorth) * southOrNorthPosition
  }

  def fromInt(int: Int): (Int, Int, Int, Int) = {
    ((int / xPosition) - xOffset, (int / yPosition) % yWidth - yOffset, (int / bottom) % bottomWidth, (int / southOrNorthPosition) % southOrNorthWidth)
  }

  def coordinationAndFaceToInt(coordinationAndFace: CoordinationAndFace): Int = {
    val x = coordinationAndFace.coordination.x
    val y = coordinationAndFace.coordination.y
    val bottom = coordinationAndFace.face.bottom
    val southOrNorth = coordinationAndFace.face.southOrNorth
    toInt(x, y, bottom, southOrNorth)
  }

  def intToCoordinationAndFace(int: Int): CoordinationAndFace = {
    val (x, y, bottom, southOrNorth) = fromInt(int)
    CoordinationAndFace(Coordination(x, y), Face(bottom, southOrNorth))
  }

}