Compare commits

..

2 Commits

Author SHA1 Message Date
Christian
4e20f541f9 Day 20 slooooow 2024-12-20 13:24:10 +01:00
Christian
57852ccfc1 Cleanup 2024-12-19 10:14:53 +01:00
8 changed files with 202 additions and 33 deletions

View File

@@ -10,6 +10,7 @@ case class Point(x: Int, y: Int):
def -(o: Point): Point = Point(x - o.x, y - o.y) def -(o: Point): Point = Point(x - o.x, y - o.y)
def *(n: Int): Point = Point(n * x, n * y) def *(n: Int): Point = Point(n * x, n * y)
def reduce: Point = { val g = gcd(x.abs, y.abs); Point(x / g, y / g) } def reduce: Point = { val g = gcd(x.abs, y.abs); Point(x / g, y / g) }
def manhattan: Int = x.abs + y.abs
val DIRS = Seq(Direction.Up, Direction.Right, Direction.Down, Direction.Left) val DIRS = Seq(Direction.Up, Direction.Right, Direction.Down, Direction.Left)

View File

@@ -21,7 +21,8 @@ val solvers = Map[Int, Solver](
16 -> Day16, 16 -> Day16,
17 -> Day17, 17 -> Day17,
18 -> Day18, 18 -> Day18,
19 -> Day19 19 -> Day19,
20 -> Day20
) )
def runSolver(solver: Solver, input: os.Path): Unit = def runSolver(solver: Solver, input: os.Path): Unit =

View File

@@ -4,15 +4,8 @@ import scala.collection.mutable
object Memo: object Memo:
def Y[I, O](f: (I, I => O) => O): I => O = def Y[I, O](f: (I, I => O) => O): I => O =
var yf: I => O = null lazy val yf: I => O = Memo(f(_, yf(_))); yf
yf = Memo(f(_, yf(_)))
yf
class Memo[-I, +O](f: I => O) extends (I => O): class Memo[-I, +O](f: I => O) extends (I => O):
private[this] val memo = mutable.Map.empty[I, O] private[this] val memo = mutable.Map.empty[I, O]
def apply(i: I): O = { lazy val o = f(i); memo.getOrElseUpdate(i, o) }
def apply(i: I): O =
if memo.contains(i) then memo(i)
else {
val o = f(i); memo(i) = o; o
}

View File

@@ -51,7 +51,6 @@ object Day16 extends Solver(16):
val all = mutable.Set(endPose) val all = mutable.Set(endPose)
var cur = Set(endPose) var cur = Set(endPose)
println(start)
while cur.nonEmpty do while cur.nonEmpty do
cur = cur.filter(_ != Pose(start, Direction.Right)).flatMap(ancestor(_)) cur = cur.filter(_ != Pose(start, Direction.Right)).flatMap(ancestor(_))
all.addAll(cur) all.addAll(cur)

View File

@@ -2,38 +2,23 @@ package dev.ctsk.aoc.days
import dev.ctsk.aoc.* import dev.ctsk.aoc.*
import scala.util.boundary
import scala.util.boundary.break
object Day19 extends Solver(19): object Day19 extends Solver(19):
def pre(input: os.ReadablePath): (Trie, Seq[String]) = def pre(input: os.ReadablePath): (Trie, Seq[String]) =
val Array(rules_, words_) = os.read(input).split("\n\n") val Array(rules_, words_) = os.read(input).split("\n\n")
val trie = Trie() val trie = Trie()
for rule <- rules_.split(", ") do trie.insert(rule) for rule <- rules_.split(", ") do trie.insert(rule)
(trie, words_.linesIterator.toSeq) (trie, words_.linesIterator.toSeq)
def part1(trie: Trie, words: Seq[String]): Int = private def arrangements(trie: Trie, word: String): Long =
def valid(word: String, inj: String => Boolean): Boolean = def rec(offset: Int, inj: Int => Long): Long =
if word.isEmpty then return true if offset == word.length then return 1L
boundary: trie.prefixes(word, offset).map(inj).sum
for p <- trie.prefixes(word) do Memo.Y(rec)(0)
if inj(word.slice(p, word.length)) then break(true)
false
words.count(Memo.Y(valid))
def part2(trie: Trie, words: Seq[String]): Long =
def valid(word: String, inj: String => Long): Long =
if word.isEmpty then return 1L
trie.prefixes(word).map(p => inj(word.slice(p, word.length))).sum
words.map(Memo.Y(valid)).sum
override def run(input: os.ReadablePath): (Timings, Solution) = override def run(input: os.ReadablePath): (Timings, Solution) =
val (pre_time, (trie, words)) = timed { pre(input) } val (pre_time, (trie, words)) = timed { pre(input) }
val (p1_time, p1) = timed { part1(trie, words) } val (p1_time, p1) = timed { words.count(arrangements(trie, _) > 0) }
val (p2_time, p2) = timed { part2(trie, words) } val (p2_time, p2) = timed { words.map(arrangements(trie, _)).sum }
( (
Timings(pre_time, p1_time, p2_time), Timings(pre_time, p1_time, p2_time),

View File

@@ -0,0 +1,47 @@
package dev.ctsk.aoc.days
import dev.ctsk.aoc.*
import collection.parallel.CollectionConverters.*
object Day20 extends Solver(20):
private def manhattanBall(dist: Int, center: Point): Array[(Point, Int)] =
(for
x <- -dist to dist
y <- -(dist - x.abs) to (dist - x.abs)
yield (Point(center.x + x, center.y + y), x.abs + y.abs)).toArray
override def run(input: os.ReadablePath): (Timings, Solution) =
val grid = Grid(os.read.lines(input).map(_.toArray).toArray)
val start = grid.findFirst(_ == 'S').get
val end = grid.findFirst(_ == 'E').get
val trace = Iterator
.unfold((end, end))((cur, prev) =>
val n = DIRS.map(_(cur)).filter(_ != prev).find(!grid(_).contains('#'))
n.map(nxt => (cur, (nxt, cur)))
)
.concat(Seq(start))
.toArray
val distance = trace.zipWithIndex.toMap
def cheats(radius: Int): Int =
trace.zipWithIndex.par
.map((from, fromDist) => {
(for
(to, dist) <- manhattanBall(radius, from)
toDist <- distance.get(to)
cheat = fromDist - toDist
if cheat >= 100 + dist
yield ()).length
})
.sum
val p1 = timed { cheats(2) }
val p2 = timed { cheats(20) }
(
Timings(0, p1._1, p2._1),
Solution(Int.box(p1._2), Int.box(p2._2))
)

2
data/20.ans Normal file
View File

@@ -0,0 +1,2 @@
1445
1008040

141
data/20.in Normal file
View File

@@ -0,0 +1,141 @@
#############################################################################################################################################
#.........................#...###...#...#...#.............#...#...#...#.......###...#...#...###...#.....###...#...........#...#.........#...#
#.#######################.#.#.###.#.#.#.#.#.#.###########.#.#.#.#.#.#.#.#####.###.#.#.#.#.#.###.#.#.###.###.#.#.#########.#.#.#.#######.#.#.#
#...#...#...............#.#.#.....#.#.#...#.#.....#.......#.#.#.#...#.#.....#.#...#.#.#...#...#.#.#...#.#...#...#.........#.#...#...#...#.#.#
###.#.#.#.#############.#.#.#######.#.#####.#####.#.#######.#.#.#####.#####.#.#.###.#.#######.#.#.###.#.#.#######.#########.#####.#.#.###.#.#
###...#.#.#.............#.#.......#.#.....#...#...#.....#...#...#.....#...#.#.#...#...#.......#.#...#.#.#.#.......#.........#...#.#...###.#.#
#######.#.#.#############.#######.#.#####.###.#.#######.#.#######.#####.#.#.#.###.#####.#######.###.#.#.#.#.#######.#########.#.#.#######.#.#
#...###...#...#...#.....#.#.......#.#...#.#...#.#.....#.#...#...#.....#.#...#...#.#...#...#...#.#...#.#.#.#.#.......#...#.....#...###...#.#.#
#.#.#########.#.#.#.###.#.#.#######.#.#.#.#.###.#.###.#.###.#.#.#####.#.#######.#.#.#.###.#.#.#.#.###.#.#.#.#.#######.#.#.###########.#.#.#.#
#.#.#...#.....#.#.#.#...#.#.......#.#.#.#.#.#...#...#...###...#...#...#.....#...#...#.#...#.#.#.#...#.#.#.#.#.#.......#.#.....#...#...#.#.#.#
#.#.#.#.#.#####.#.#.#.###.#######.#.#.#.#.#.#.#####.#############.#.#######.#.#######.#.###.#.#.###.#.#.#.#.#.#.#######.#####.#.#.#.###.#.#.#
#.#.#.#.#.......#...#...#...#.....#...#.#.#.#...#...#...#...#.....#...#.....#.#...#...#.#...#.#.#...#.#.#.#...#.......#...#...#.#.#...#...#.#
#.#.#.#.###############.###.#.#########.#.#.###.#.###.#.#.#.#.#######.#.#####.#.#.#.###.#.###.#.#.###.#.#.###########.###.#.###.#.###.#####.#
#.#.#.#.###...#...#.....#...#.........#.#.#.###.#.###.#.#.#.#.....#...#.....#.#.#.#...#.#...#...#...#.#.#.#...........###...###.#...#.#.....#
#.#.#.#.###.#.#.#.#.#####.###########.#.#.#.###.#.###.#.#.#.#####.#.#######.#.#.#.###.#.###.#######.#.#.#.#.###################.###.#.#.#####
#.#...#.#...#.#.#.#.....#.......#...#.#.#.#.#...#.#...#...#...###.#...###...#...#...#.#.#...#.......#.#...#...........#...###...#...#.#.#...#
#.#####.#.###.#.#.#####.#######.#.#.#.#.#.#.#.###.#.#########.###.###.###.#########.#.#.#.###.#######.###############.#.#.###.###.###.#.#.#.#
#.....#...#...#.#.....#.......#.#.#...#...#...#...#...#.....#...#...#...#.......#...#.#.#...#.....#...#...............#.#...#...#.#...#.#.#.#
#####.#####.###.#####.#######.#.#.#############.#####.#.###.###.###.###.#######.#.###.#.###.#####.#.###.###############.###.###.#.#.###.#.#.#
#...#.#...#...#.....#.........#.#.........#.....#.....#...#...#.###...#.#...#...#...#.#.###.#.....#...#.#.........#...#.#...#...#.#.#...#.#.#
#.#.#.#.#.###.#####.###########.#########.#.#####.#######.###.#.#####.#.#.#.#.#####.#.#.###.#.#######.#.#.#######.#.#.#.#.###.###.#.#.###.#.#
#.#.#...#...#.......#.........#.###...###.#.....#.....#...###...#...#.#.#.#.#.....#.#.#...#.#.#...#...#...#.......#.#.#.#.###...#.#.#.....#.#
#.#.#######.#########.#######.#.###.#.###.#####.#####.#.#########.#.#.#.#.#.#####.#.#.###.#.#.#.#.#.#######.#######.#.#.#.#####.#.#.#######.#
#.#...#...#...#...#...###.....#.....#.....#.....#...#.#.......###.#.#.#.#.#...###.#...#...#.#.#.#.#.#.......###...#.#.#.#.#...#.#...#...#...#
#.###.#.#.###.#.#.#.#####.#################.#####.#.#.#######.###.#.#.#.#.###.###.#####.###.#.#.#.#.#.#########.#.#.#.#.#.#.#.#.#####.#.#.###
#...#.#.#...#...#...###...#.........#.....#.#...#.#.#.#.......#...#.#.#.#...#...#.#.....###.#...#...#.....#...#.#.#.#.#.#.#.#.#...#...#...###
###.#.#.###.###########.###.#######.#.###.#.#.#.#.#.#.#.#######.###.#.#.###.###.#.#.#######.#############.#.#.#.#.#.#.#.#.#.#.###.#.#########
#...#.#.#...###.......#.....#...###...#...#...#.#.#.#.#...#...#...#.#.#.#...#...#.#...#...#.#...#...#.....#.#...#.#.#.#.#.#.#...#.#.#...#...#
#.###.#.#.#####.#####.#######.#.#######.#######.#.#.#.###.#.#.###.#.#.#.#.###.###.###.#.#.#.#.#.#.#.#.#####.#####.#.#.#.#.#.###.#.#.#.#.#.#.#
#...#.#.#.#...#.....#.#.......#.......#.#.......#.#...#...#.#...#.#.#.#.#...#.#...#...#.#.#...#...#.#.#...#.#.....#.#...#...#...#.#...#...#.#
###.#.#.#.#.#.#####.#.#.#############.#.#.#######.#####.###.###.#.#.#.#.###.#.#.###.###.#.#########.#.#.#.#.#.#####.#########.###.#########.#
#...#...#.#.#...#...#.#...........#...#.#.#...#...#.....###...#.#.#.#.#...#.#.#...#.#...#...#...#...#...#...#...#...#...#.....#...#.........#
#.#######.#.###.#.###.###########.#.###.#.#.#.#.###.#########.#.#.#.#.###.#.#.###.#.#.#####.#.#.#.#############.#.###.#.#.#####.###.#########
#...#...#...#...#...#.#.......#...#...#.#.#.#.#.#...#...#...#.#.#.#.#...#.#.#.###.#.#...#...#.#.#.....#.........#.#...#...#...#...#.#.......#
###.#.#.#####.#####.#.#.#####.#.#####.#.#.#.#.#.#.###.#.#.#.#.#.#.#.###.#.#.#.###.#.###.#.###.#.#####.#.#########.#.#######.#.###.#.#.#####.#
###...#.....#.#...#.#.#.....#.#.....#.#.#.#.#...#...#.#.#.#.#.#.#.#...#.#.#.#...#.#...#.#...#.#.#...#.#...........#...###...#.###.#.#.#.....#
###########.#.#.#.#.#.#####.#.#####.#.#.#.#.#######.#.#.#.#.#.#.#.###.#.#.#.###.#.###.#.###.#.#.#.#.#.###############.###.###.###.#.#.#.#####
#...........#...#...#.......#.....#.#.#.#.#...#.....#.#.#.#.#.#...#...#.#.#.#...#.###.#...#.#.#...#.#.#.............#...#...#.....#...#...###
#.###############################.#.#.#.#.###.#.#####.#.#.#.#.#####.###.#.#.#.###.###.###.#.#.#####.#.#.###########.###.###.#############.###
#.......#.....#...#.......#.....#.#.#...#...#.#.#...#.#.#.#.#...###...#.#.#.#...#...#.#...#.#.#.....#.#...#...#...#.....###.#...........#...#
#######.#.###.#.#.#.#####.#.###.#.#.#######.#.#.#.#.#.#.#.#.###.#####.#.#.#.###.###.#.#.###.#.#.#####.###.#.#.#.#.#########.#.#########.###.#
#.......#.###...#...###...#.#...#...###...#...#.#.#.#.#.#.#.#...#.....#.#.#...#...#.#.#...#...#...#...###...#...#...###...#.#.........#...#.#
#.#######.#############.###.#.#########.#.#####.#.#.#.#.#.#.#.###.#####.#.###.###.#.#.###.#######.#.###############.###.#.#.#########.###.#.#
#.........#...#...#...#.....#...........#.....#.#.#.#.#.#.#.#.###...#...#...#.###.#.#.#...#.......#.#...............#...#...#.......#...#.#.#
###########.#.#.#.#.#.#######################.#.#.#.#.#.#.#.#.#####.#.#####.#.###.#.#.#.###.#######.#.###############.#######.#####.###.#.#.#
###...#.....#...#...#.....#...................#.#.#.#.#.#.#...#.....#.....#.#.#...#.#...###...#.....#...............#.#.......#.....#...#.#.#
###.#.#.#################.#.###################.#.#.#.#.#.#####.#########.#.#.#.###.#########.#.###################.#.#.#######.#####.###.#.#
#...#.#.#...#...#.......#...#.......#.......#...#.#.#.#.#.....#...#...#...#.#.#...#.........#.#.#...........#.....#...#.......#.....#.###...#
#.###.#.#.#.#.#.#.#####.#####.#####.#.#####.#.###.#.#.#.#####.###.#.#.#.###.#.###.#########.#.#.#.#########.#.###.###########.#####.#.#######
#.#...#...#...#...#...#.......#...#...#.....#.....#.#.#.#...#.#...#.#.#...#...###...#.....#.#.#.#...#.....#.#.###.....#.....#...###.#...#...#
#.#.###############.#.#########.#.#####.###########.#.#.#.#.#.#.###.#.###.#########.#.###.#.#.#.###.#.###.#.#.#######.#.###.###.###.###.#.#.#
#.#...###...###...#.#.#.........#.......###...#...#...#...#...#.#...#...#.....#.....#.###...#...###...#...#...#...###...###...#...#...#...#.#
#.###.###.#.###.#.#.#.#.###################.#.#.#.#############.#.#####.#####.#.#####.#################.#######.#.###########.###.###.#####.#
#...#.....#.....#...#.#.............###...#.#...#...#...#.......#.....#...#...#.....#...#...###.......#.........#...........#...#...#.......#
###.#################.#############.###.#.#.#######.#.#.#.###########.###.#.#######.###.#.#.###.#####.#####################.###.###.#########
###.................#.............#...#.#...#...#...#.#.#...#...#...#.###.#.###...#...#...#...#.....#.#.................#...###...#...#.....#
###################.#############.###.#.#####.#.#.###.#.###.#.#.#.#.#.###.#.###.#.###.#######.#####.#.#.###############.#.#######.###.#.###.#
#...#...............#...........#.#...#.#.....#.#.....#...#...#...#...#...#.#...#.#...#.....#.#.....#.#...#...........#...###...#.....#.#...#
#.#.#.###############.#########.#.#.###.#.#####.#########.#############.###.#.###.#.###.###.#.#.#####.###.#.#########.#######.#.#######.#.###
#.#.#...#...#.......#.###.......#.#.....#.....#.....#...#.....###.......#...#...#.#...#...#...#.....#...#...#.....#...#.......#.........#...#
#.#.###.#.#.#.#####.#.###.#######.###########.#####.#.#.#####.###.#######.#####.#.###.###.#########.###.#####.###.#.###.###################.#
#.#.....#.#.#.#...#...#...#.....#.#.....#...#.#...#...#.......#...#.....#...###.#.###.....###...###...#.....#...#...###.#...............#...#
#.#######.#.#.#.#.#####.###.###.#.#.###.#.#.#.#.#.#############.###.###.###.###.#.###########.#.#####.#####.###.#######.#.#############.#.###
#.....#...#...#.#.#...#...#.#...#...###...#.#...#...#...#...###.....###.....#...#.....#...#...#.#...#.....#...#...#...#.#.............#...###
#####.#.#######.#.#.#.###.#.#.#############.#######.#.#.#.#.#################.#######.#.#.#.###.#.#.#####.###.###.#.#.#.#############.#######
#...#.#.#.......#...#.#...#.#.............#.........#.#.#.#.....#...#####...#.......#.#.#.#...#...#.......###.#...#.#...#.............#.....#
#.#.#.#.#.###########.#.###.#############.###########.#.#.#####.#.#.#####.#.#######.#.#.#.###.###############.#.###.#####.#############.###.#
#.#.#...#...........#.#.....###...........#.........#.#.#.#.....#.#...#...#.#.......#...#.....#...#.........#.#.....#...#.........###...#...#
#.#.###############.#.#########.###########.#######.#.#.#.#.#####.###.#.###.#.#################.#.#.#######.#.#######.#.#########.###.###.###
#.#.#.............#.#.#.......#...........#.#######...#...#.....#.#...#...#...#...#.....#.....#.#.#.#...#...#.....#...#.....#...#...#.#...###
#.#.#.###########.#.#.#.#####.###########.#.###################.#.#.#####.#####.#.#.###.#.###.#.#.#.#.#.#.#######.#.#######.#.#.###.#.#.#####
#.#.#...........#.#.#.#.....#.#...#######...#################E#...#.#...#.....#.#.#.#...#.#...#.#...#.#.#.......#.#.......#...#...#...#.....#
#.#.###########.#.#.#.#####.#.#.#.###########################.#####.#.#.#####.#.#.#.#.###.#.###.#####.#.#######.#.#######.#######.#########.#
#.#.........#...#...#.......#...#..S###############.....#####.#...#...#.#.....#.#...#.#...#.....###...#.....#...#.#...#...#.....#.........#.#
#.#########.#.#####################################.###.#####.#.#.#####.#.#####.#####.#.###########.#######.#.###.#.#.#.###.###.#########.#.#
#.........#...#.......#.....#...#...#...#####.......#...#####.#.#.....#.#.......#...#...#.....#...#.......#...###.#.#.#.....#...###...###...#
#########.#####.#####.#.###.#.#.#.#.#.#.#####.#######.#######.#.#####.#.#########.#.#####.###.#.#.#######.#######.#.#.#######.#####.#.#######
###...#...#...#.#.....#.#...#.#...#...#.....#.....#...###...#.#.#...#...#.....#...#...###...#...#...#...#...#...#...#.........#.....#.......#
###.#.#.###.#.#.#.#####.#.###.#############.#####.#.#####.#.#.#.#.#.#####.###.#.#####.#####.#######.#.#.###.#.#.###############.###########.#
#...#...#...#.#.#...#...#.#...#...........#...#...#.......#.#...#.#.#...#...#.#...#...#...#.......#.#.#.....#.#.#...###.......#.....#.......#
#.#######.###.#.###.#.###.#.###.#########.###.#.###########.#####.#.#.#.###.#.###.#.###.#.#######.#.#.#######.#.#.#.###.#####.#####.#.#######
#.........###...###...###...###.........#.....#.#...........#...#.#.#.#.....#.....#...#.#.......#.#.#.........#...#.....#.....#.....#...#...#
#######################################.#######.#.###########.#.#.#.#.###############.#.#######.#.#.#####################.#####.#######.#.#.#
#.............###...........###.........###...#.#.......###...#.#.#.#.............#...#.......#...#.#...................#.......#.....#...#.#
#.###########.###.#########.###.###########.#.#.#######.###.###.#.#.#############.#.#########.#####.#.#################.#########.###.#####.#
#.......#...#...#.#...#...#.....#...###.....#...#.....#...#.#...#.#.#.....###...#.#.....#...#.....#.#.................#.....#...#...#.......#
#######.#.#.###.#.#.#.#.#.#######.#.###.#########.###.###.#.#.###.#.#.###.###.#.#.#####.#.#.#####.#.#################.#####.#.#.###.#########
###...#...#.#...#...#...#.........#.....#.........###...#.#.#.....#.#...#.....#.#.#...#...#.......#.....#...........#...#...#.#...#.........#
###.#.#####.#.###########################.#############.#.#.#######.###.#######.#.#.#.#################.#.#########.###.#.###.###.#########.#
#...#.....#.#.#...#.....#...............#.........#...#...#...#.....###.#.....#.#.#.#.........#.......#...#...#...#.....#.....###...........#
#.#######.#.#.#.#.#.###.#.#############.#########.#.#.#######.#.#######.#.###.#.#.#.#########.#.#####.#####.#.#.#.###########################
#.#.....#.#.#.#.#.#...#.#.............#.#.........#.#...###...#.......#...###.#.#...#...#.....#.###...#.....#...#.......###.................#
#.#.###.#.#.#.#.#.###.#.#############.#.#.#########.###.###.#########.#######.#.#####.#.#.#####.###.###.###############.###.###############.#
#...#...#...#...#.....#.###...#...#...#.#.#.......#...#...#.....#.....###...#.#.#...#.#.#...#...#...#...#...............#...#...#...#...#...#
#####.#################.###.#.#.#.#.###.#.#.#####.###.###.#####.#.#######.#.#.#.#.#.#.#.###.#.###.###.###.###############.###.#.#.#.#.#.#.###
#.....#.....#...#.....#.....#...#...###...#.#.....###...#.###...#...#...#.#.#.#.#.#.#.#.###...###...#.###.........#...###.#...#...#.#.#.#...#
#.#####.###.#.#.#.###.#####################.#.#########.#.###.#####.#.#.#.#.#.#.#.#.#.#.###########.#.###########.#.#.###.#.#######.#.#.###.#
#...#...###.#.#.#.#...#...................#.#.....#.....#.....#.....#.#...#.#.#.#.#.#.#.....#.....#.#.#.........#.#.#.....#.......#...#...#.#
###.#.#####.#.#.#.#.###.#################.#.#####.#.###########.#####.#####.#.#.#.#.#.#####.#.###.#.#.#.#######.#.#.#############.#######.#.#
###...#.....#.#.#.#...#.#.................#.....#.#...........#.#...#...#...#.#.#.#...#.....#...#.#...#.......#...#.#.............#...###.#.#
#######.#####.#.#.###.#.#.#####################.#.###########.#.#.#.###.#.###.#.#.#####.#######.#.###########.#####.#.#############.#.###.#.#
#.......#...#.#...#...#.#.#.....#.......#...#...#...#...#.....#.#.#...#.#...#.#.#.....#...#...#.#.#...........#...#.#.........#.....#...#.#.#
#.#######.#.#.#####.###.#.#.###.#.#####.#.#.#.#####.#.#.#.#####.#.###.#.###.#.#.#####.###.#.#.#.#.#.###########.#.#.#########.#.#######.#.#.#
#...#...#.#...#.....#...#.#...#.#.#.....#.#.#.....#.#.#.#...#...#.#...#...#.#.#.#...#.#...#.#.#.#.#.............#...#.......#...#...#...#.#.#
###.#.#.#.#####.#####.###.###.#.#.#.#####.#.#####.#.#.#.###.#.###.#.#####.#.#.#.#.#.#.#.###.#.#.#.###################.#####.#####.#.#.###.#.#
###...#.#.....#.....#...#...#.#...#.#...#.#...#...#.#.#...#.#.#...#.....#.#...#.#.#...#...#.#.#.#.#...#.....#.......#.....#.#.....#.#.#...#.#
#######.#####.#####.###.###.#.#####.#.#.#.###.#.###.#.###.#.#.#.#######.#.#####.#.#######.#.#.#.#.#.#.#.###.#.#####.#####.#.#.#####.#.#.###.#
#.....#.......###...#...#...#.#.....#.#...#...#...#.#.#...#.#.#.....#...#...###.#.....#...#.#.#.#.#.#.#...#.#.....#...#...#.#.#...#...#.#...#
#.###.###########.###.###.###.#.#####.#####.#####.#.#.#.###.#.#####.#.#####.###.#####.#.###.#.#.#.#.#.###.#.#####.###.#.###.#.#.#.#####.#.###
#...#.###...#...#.#...###.....#.....#...###.....#.#...#...#.#.#...#.#...#...#...#.....#...#.#...#...#.#...#.#...#.#...#...#.#...#...#...#...#
###.#.###.#.#.#.#.#.###############.###.#######.#.#######.#.#.#.#.#.###.#.###.###.#######.#.#########.#.###.#.#.#.#.#####.#.#######.#.#####.#
#...#.....#...#...#...#.........###.#...#.......#...#.....#.#.#.#...#...#...#...#.#...#...#.......###...###.#.#...#.#.....#.....#...#...#...#
#.###################.#.#######.###.#.###.#########.#.#####.#.#.#####.#####.###.#.#.#.#.#########.#########.#.#####.#.#########.#.#####.#.###
#...#.....#.......#...#...#...#.....#.#...#...#.....#.#.....#.#...#...#.....#...#.#.#...#...#...#.......#...#.....#.#.#...#...#...#.....#...#
###.#.###.#.#####.#.#####.#.#.#######.#.###.#.#.#####.#.#####.###.#.###.#####.###.#.#####.#.#.#.#######.#.#######.#.#.#.#.#.#.#####.#######.#
#...#...#.#.#.....#...###...#.......#.#...#.#.#.....#...#.....#...#...#.....#...#.#.#...#.#.#.#...#...#.#.....#...#.#...#...#.....#.#.......#
#.#####.#.#.#.#######.#############.#.###.#.#.#####.#####.#####.#####.#####.###.#.#.#.#.#.#.#.###.#.#.#.#####.#.###.#############.#.#.#######
#...#...#...#...#.....#.......#...#.#.###.#.#.#...#.....#.#...#.#.....#...#.#...#.#.#.#...#.#...#.#.#.#...#...#...#...#.....#.....#...#...###
###.#.#########.#.#####.#####.#.#.#.#.###.#.#.#.#.#####.#.#.#.#.#.#####.#.#.#.###.#.#.#####.###.#.#.#.###.#.#####.###.#.###.#.#########.#.###
#...#...#.......#.....#.#...#...#.#.#.#...#.#.#.#.#.....#...#.#.#...#...#.#.#.#...#.#.....#.#...#...#.#...#.#.....#...#...#.#...#...#...#...#
#.#####.#.###########.#.#.#.#####.#.#.#.###.#.#.#.#.#########.#.###.#.###.#.#.#.###.#####.#.#.#######.#.###.#.#####.#####.#.###.#.#.#.#####.#
#...#...#.......#.....#...#.....#...#.#...#.#.#.#.#.......#...#...#...###...#.#...#.#.....#.#.......#.#.#...#.....#.....#.#...#...#...#...#.#
###.#.#########.#.#############.#####.###.#.#.#.#.#######.#.#####.###########.###.#.#.#####.#######.#.#.#.#######.#####.#.###.#########.#.#.#
#...#.#.........#...#...#.......#...#...#.#.#.#.#.#...#...#...#...#...........#...#.#.#...#.........#...#...#.....#.....#...#.#.......#.#.#.#
#.###.#.###########.#.#.#.#######.#.###.#.#.#.#.#.#.#.#.#####.#.###.###########.###.#.#.#.#################.#.#####.#######.#.#.#####.#.#.#.#
#.#...#.......#...#.#.#...#.......#.#...#.#.#.#.#...#.#...#...#...#.....#.....#.###.#...#.................#.#.....#.#...#...#.#.....#...#.#.#
#.#.#########.#.#.#.#.#####.#######.#.###.#.#.#.#####.###.#.#####.#####.#.###.#.###.#####################.#.#####.#.#.#.#.###.#####.#####.#.#
#.#.#...###...#.#.#.#...#...#.......#.###.#.#.#.#.....#...#.#...#.#.....#.#...#...#.....#.....#...#.....#.#.#.....#...#...#...#.....#...#.#.#
#.#.#.#.###.###.#.#.###.#.###.#######.###.#.#.#.#.#####.###.#.#.#.#.#####.#.#####.#####.#.###.#.#.#.###.#.#.#.#############.###.#####.#.#.#.#
#.#.#.#.....#...#...###...###.....#...#...#.#...#...#...###...#...#.#.....#.#.....#.....#...#.#.#.#.###...#.#.............#...#.......#.#...#
#.#.#.#######.###################.#.###.###.#######.#.#############.#.#####.#.#####.#######.#.#.#.#.#######.#############.###.#########.#####
#...#.....#...#...#...#...#.......#...#...#...#.....#...........#...#.#.....#.....#...#...#.#...#.#.....###.#...#...#.....###...........#...#
#########.#.###.#.#.#.#.#.#.#########.###.###.#.###############.#.###.#.#########.###.#.#.#.#####.#####.###.#.#.#.#.#.###################.#.#
#...#.....#.###.#...#...#...#...#...#.###.....#...#...#.....#...#.....#...#.......#...#.#.#...###.....#...#...#...#.#.....................#.#
#.#.#.#####.###.#############.#.#.#.#.###########.#.#.#.###.#.###########.#.#######.###.#.###.#######.###.#########.#######################.#
#.#.#.....#...#.#...#...#...#.#.#.#.#.........#...#.#.#...#.#.#...#...#...#.......#...#.#...#.......#...#.........#.#.......#...#.....#...#.#
#.#.#####.###.#.#.#.#.#.#.#.#.#.#.#.#########.#.###.#.###.#.#.#.#.#.#.#.#########.###.#.###.#######.###.#########.#.#.#####.#.#.#.###.#.#.#.#
#.#.......#...#.#.#.#.#.#.#.#.#.#.#...#...#...#...#.#.#...#.#.#.#...#...#...#...#.#...#...#...#...#...#.#.....#...#.#...#...#.#.#...#.#.#.#.#
#.#########.###.#.#.#.#.#.#.#.#.#.###.#.#.#.#####.#.#.#.###.#.#.#########.#.#.#.#.#.#####.###.#.#.###.#.#.###.#.###.###.#.###.#.###.#.#.#.#.#
#...........###...#...#...#...#...###...#...#####...#...###...#...........#...#...#.......###...#.....#...###...###.....#.....#.....#...#...#
#############################################################################################################################################