Skip to content

Instantly share code, notes, and snippets.

@Archenoth
Last active December 19, 2021 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Archenoth/4256a377c186b702e046f57130ae8ee9 to your computer and use it in GitHub Desktop.
Save Archenoth/4256a377c186b702e046f57130ae8ee9 to your computer and use it in GitHub Desktop.

Advent of Code 2021

(require '[clojure.string :as str])

— Day 1: Sonar Sweep —

You’re minding your own business on a ship at sea when the overboard alarm goes off! You rush to see if you can help. Apparently, one of the Elves tripped and accidentally sent the sleigh keys flying into the ocean!

Before you know it, you’re inside a submarine the Elves keep ready for situations like this. It’s covered in Christmas lights (because of course it is), and it even has an experimental antenna that should be able to track the keys if you can boost its signal strength high enough; there’s a little meter that indicates the antenna’s signal strength by displaying 0-50 stars.

Your instincts tell you that in order to save Christmas, you’ll need to get all fifty stars by December 25th.

Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!

As the submarine drops below the surface of the ocean, it automatically performs a sonar sweep of the nearby sea floor. On a small screen, the sonar sweep report (your puzzle input) appears: each line is a measurement of the sea floor depth as the sweep looks further and further away from the submarine.

For example, suppose you had the following report:

199 200 208 210 200 207 240 269 260 263

This report indicates that, scanning outward from the submarine, the sonar sweep found depths of 199, 200, 208, 210, and so on.

The first order of business is to figure out how quickly the depth increases, just so you know what you’re dealing with - you never know if the keys will get carried into deeper water by an ocean current or a fish or something.

To do this, count the number of times a depth measurement increases from the previous measurement. (There is no measurement before the first measurement.) In the example above, the changes are as follows:

199 (N/A - no previous measurement) 200 (increased) 208 (increased) 210 (increased) 200 (decreased) 207 (increased) 240 (increased) 269 (increased) 260 (decreased) 263 (increased)

In this example, there are 7 measurements that are larger than the previous measurement.

How many measurements are larger than the previous measurement?

IO.read("input-1").split.map(&:to_i)
(loop [[num & rest] input
       increases 0]
  (if-not rest
    increases
    (recur rest (if (< num (first rest)) (+ 1 increases) increases))))

— Part Two —

Considering every single measurement isn’t as useful as you expected: there’s just too much noise in the data.

Instead, consider sums of a three-measurement sliding window. Again considering the above example:

199 A 200 A B 208 A B C 210 B C D 200 E C D 207 E F D 240 E F G 269 F G H 260 G H 263 H

Start by comparing the first and second three-measurement windows. The measurements in the first window are marked A (199, 200, 208); their sum is 199 + 200 + 208 = 607. The second window is marked B (200, 208, 210); its sum is 618. The sum of measurements in the second window is larger than the sum of the first, so this first comparison increased.

Your goal now is to count the number of times the sum of measurements in this sliding window increases from the previous sum. So, compare A with B, then compare B with C, then C with D, and so on. Stop when there aren’t enough measurements left to create a new three-measurement sum.

In the above example, the sum of each three-measurement window is as follows:

A: 607 (N/A - no previous sum) B: 618 (increased) C: 618 (no change) D: 617 (decreased) E: 647 (increased) F: 716 (increased) G: 769 (increased) H: 792 (increased)

In this example, there are 5 sums that are larger than the previous sum.

Consider sums of a three-measurement sliding window. How many sums are larger than the previous sum?

(loop [[a b c & _ :as all] input
       last-sum ##Inf
       increases 0]
  (if-not c
    increases
    (let [sum (+ a b c)]
      (if (< last-sum sum)
        (recur (rest all) sum (+ increases 1))
        (recur (rest all) sum increases)))))

— Day 2: Dive! —

Now, you need to figure out how to pilot this thing.

It seems like the submarine can take a series of commands like forward 1, down 2, or up 3:

forward X increases the horizontal position by X units. down X increases the depth by X units. up X decreases the depth by X units.

Note that since you’re on a submarine, down and up affect your depth, and so they have the opposite result of what you might expect.

The submarine seems to already have a planned course (your puzzle input). You should probably figure out where it’s going. For example:

forward 5 down 5 forward 8 up 3 down 8 forward 2

Your horizontal position and depth both start at 0. The steps above would then modify them as follows:

forward 5 adds 5 to your horizontal position, a total of 5. down 5 adds 5 to your depth, resulting in a value of 5. forward 8 adds 8 to your horizontal position, a total of 13. up 3 decreases your depth by 3, resulting in a value of 2. down 8 adds 8 to your depth, resulting in a value of 10. forward 2 adds 2 to your horizontal position, a total of 15.

After following these instructions, you would have a horizontal position of 15 and a depth of 10. (Multiplying these together produces 150.)

Calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth?

(def input
  (for [line (str/split (slurp "input-2") #"\n")
        :let [[dir dist] (str/split line #" ")]]
    [dir (Integer/parseInt dist)]))
(loop [[[dir dist] & rem] input
       horiz 0
       depth 0]
  (if-not dir
    (* horiz depth)
    (case dir
      "forward" (recur rem (+ horiz dist) depth)
      "down" (recur rem horiz (+ depth dist))
      "up" (recur rem horiz (- depth dist)))))

— Part Two —

Based on your calculations, the planned course doesn’t seem to make any sense. You find the submarine manual and discover that the process is actually slightly more complicated.

In addition to horizontal position and depth, you’ll also need to track a third value, aim, which also starts at 0. The commands also mean something entirely different than you first thought:

down X increases your aim by X units. up X decreases your aim by X units. forward X does two things: It increases your horizontal position by X units. It increases your depth by your aim multiplied by X.

Again note that since you’re on a submarine, down and up do the opposite of what you might expect: “down” means aiming in the positive direction.

Now, the above example does something different:

forward 5 adds 5 to your horizontal position, a total of 5. Because your aim is 0, your depth does not change. down 5 adds 5 to your aim, resulting in a value of 5. forward 8 adds 8 to your horizontal position, a total of 13. Because your aim is 5, your depth increases by 8*5=40. up 3 decreases your aim by 3, resulting in a value of 2. down 8 adds 8 to your aim, resulting in a value of 10. forward 2 adds 2 to your horizontal position, a total of 15. Because your aim is 10, your depth increases by 2*10=20 to a total of 60.

After following these new instructions, you would have a horizontal position of 15 and a depth of 60. (Multiplying these produces 900.)

Using this new interpretation of the commands, calculate the horizontal position and depth you would have after following the planned course. What do you get if you multiply your final horizontal position by your final depth?

(loop [[[dir dist] & rem] input
       aim 0
       horiz 0
       depth 0]
  (if-not dir
    (* horiz depth)
    (case dir
      "forward" (recur rem aim (+ horiz dist) (+ depth (* aim dist)))
      "down" (recur rem (+ aim dist) horiz depth)
      "up" (recur rem (- aim dist) horiz depth))))

— Day 3: Binary Diagnostic —

The submarine has been making some odd creaking noises, so you ask it to produce a diagnostic report just in case.

The diagnostic report (your puzzle input) consists of a list of binary numbers which, when decoded properly, can tell you many useful things about the conditions of the submarine. The first parameter to check is the power consumption.

You need to use the binary numbers in the diagnostic report to generate two new binary numbers (called the gamma rate and the epsilon rate). The power consumption can then be found by multiplying the gamma rate by the epsilon rate.

Each bit in the gamma rate can be determined by finding the most common bit in the corresponding position of all numbers in the diagnostic report. For example, given the following diagnostic report:

00100 11110 10110 10111 10101 01111 00111 11100 10000 11001 00010 01010

Considering only the first bit of each number, there are five 0 bits and seven 1 bits. Since the most common bit is 1, the first bit of the gamma rate is 1.

The most common second bit of the numbers in the diagnostic report is 0, so the second bit of the gamma rate is 0.

The most common value of the third, fourth, and fifth bits are 1, 1, and 0, respectively, and so the final three bits of the gamma rate are 110.

So, the gamma rate is the binary number 10110, or 22 in decimal.

The epsilon rate is calculated in a similar way; rather than use the most common bit, the least common bit from each position is used. So, the epsilon rate is 01001, or 9 in decimal. Multiplying the gamma rate (22) by the epsilon rate (9) produces the power consumption, 198.

Use the binary numbers in your diagnostic report to calculate the gamma rate and epsilon rate, then multiply them together. What is the power consumption of the submarine? (Be sure to represent your answer in decimal, not binary.)

(def input
  (for [line (str/split (slurp "input-3") #"\n")]
    (map #(if (= \0 %) 0 1) line)))
(loop [[more? & rem] (first input)
       col 0
       gamma ""
       epsilon ""]
  (if-not more?
    (* (Integer/parseInt gamma 2) (Integer/parseInt epsilon 2))
    (let [[[e] [g]] (sort-by second (frequencies (map #(nth % col) input)))]
      (recur rem (+ 1 col) (str gamma g) (str epsilon e)))))

— Part Two —

Next, you should verify the life support rating, which can be determined by multiplying the oxygen generator rating by the CO2 scrubber rating.

Both the oxygen generator rating and the CO2 scrubber rating are values that can be found in your diagnostic report - finding them is the tricky part. Both values are located using a similar process that involves filtering out values until only one remains. Before searching for either rating value, start with the full list of binary numbers from your diagnostic report and consider just the first bit of those numbers. Then:

Keep only numbers selected by the bit criteria for the type of rating value for which you are searching. Discard numbers which do not match the bit criteria. If you only have one number left, stop; this is the rating value for which you are searching. Otherwise, repeat the process, considering the next bit to the right.

The bit criteria depends on which type of rating value you want to find:

To find oxygen generator rating, determine the most common value (0 or 1) in the current bit position, and keep only numbers with that bit in that position. If 0 and 1 are equally common, keep values with a 1 in the position being considered. To find CO2 scrubber rating, determine the least common value (0 or 1) in the current bit position, and keep only numbers with that bit in that position. If 0 and 1 are equally common, keep values with a 0 in the position being considered.

For example, to determine the oxygen generator rating value using the same example diagnostic report from above:

Start with all 12 numbers and consider only the first bit of each number. There are more 1 bits (7) than 0 bits (5), so keep only the 7 numbers with a 1 in the first position: 11110, 10110, 10111, 10101, 11100, 10000, and 11001. Then, consider the second bit of the 7 remaining numbers: there are more 0 bits (4) than 1 bits (3), so keep only the 4 numbers with a 0 in the second position: 10110, 10111, 10101, and 10000. In the third position, three of the four numbers have a 1, so keep those three: 10110, 10111, and 10101. In the fourth position, two of the three numbers have a 1, so keep those two: 10110 and 10111. In the fifth position, there are an equal number of 0 bits and 1 bits (one each). So, to find the oxygen generator rating, keep the number with a 1 in that position: 10111. As there is only one number left, stop; the oxygen generator rating is 10111, or 23 in decimal.

Then, to determine the CO2 scrubber rating value from the same example above:

Start again with all 12 numbers and consider only the first bit of each number. There are fewer 0 bits (5) than 1 bits (7), so keep only the 5 numbers with a 0 in the first position: 00100, 01111, 00111, 00010, and 01010. Then, consider the second bit of the 5 remaining numbers: there are fewer 1 bits (2) than 0 bits (3), so keep only the 2 numbers with a 1 in the second position: 01111 and 01010. In the third position, there are an equal number of 0 bits and 1 bits (one each). So, to find the CO2 scrubber rating, keep the number with a 0 in that position: 01010. As there is only one number left, stop; the CO2 scrubber rating is 01010, or 10 in decimal.

Finally, to find the life support rating, multiply the oxygen generator rating (23) by the CO2 scrubber rating (10) to get 230.

Use the binary numbers in your diagnostic report to calculate the oxygen generator rating and CO2 scrubber rating, then multiply them together. What is the life support rating of the submarine? (Be sure to represent your answer in decimal, not binary.)

(defn magic [col values default]
  (let [colvals (map #(nth % col) values)
        [[lc lcc] [mc mcc]] (sort-by second (frequencies colvals))
        look-for (if (= lcc mcc) default (if (= default 1) mc lc))]
    (filter #(= look-for (nth % col)) values)))

(loop [col 0
       omatches input
       cmatches input]
  (if (and (= 1 (count omatches)) (= 1 (count cmatches)))
    (let [oxygen (apply str (first omatches))
           coscrub (apply str (first cmatches))]
      (* (Integer/parseInt oxygen 2) (Integer/parseInt coscrub 2)))
    (recur (+ 1 col) (magic col omatches 1) (magic col cmatches 0))))

— Day 4: Giant Squid —

You’re already almost 1.5km (almost a mile) below the surface of the ocean, already so deep that you can’t see any sunlight. What you can see, however, is a giant squid that has attached itself to the outside of your submarine.

Maybe it wants to play bingo?

Bingo is played on a set of boards each consisting of a 5x5 grid of numbers. Numbers are chosen at random, and the chosen number is marked on all boards on which it appears. (Numbers may not appear on all boards.) If all numbers in any row or any column of a board are marked, that board wins. (Diagonals don’t count.)

The submarine has a bingo subsystem to help passengers (currently, you and the giant squid) pass the time. It automatically generates a random order in which to draw numbers and a random set of boards (your puzzle input). For example:

7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1

22 13 17 11 0 8 2 23 4 24 21 9 14 16 7 6 10 3 18 5 1 12 20 15 19

3 15 0 2 22 9 18 13 17 5 19 8 7 25 23 20 11 10 24 4 14 21 16 12 6

14 21 17 24 4 10 16 15 9 19 18 8 23 26 20 22 11 13 6 5 2 0 12 3 7

After the first five numbers are drawn (7, 4, 9, 5, and 11), there are no winners, but the boards are marked as follows (shown here adjacent to each other to save space):

22 13 17 11 0 3 15 0 2 22 14 21 17 24 4 8 2 23 4 24 9 18 13 17 5 10 16 15 9 19 21 9 14 16 7 19 8 7 25 23 18 8 23 26 20 6 10 3 18 5 20 11 10 24 4 22 11 13 6 5 1 12 20 15 19 14 21 16 12 6 2 0 12 3 7

After the next six numbers are drawn (17, 23, 2, 0, 14, and 21), there are still no winners:

22 13 17 11 0 3 15 0 2 22 14 21 17 24 4 8 2 23 4 24 9 18 13 17 5 10 16 15 9 19 21 9 14 16 7 19 8 7 25 23 18 8 23 26 20 6 10 3 18 5 20 11 10 24 4 22 11 13 6 5 1 12 20 15 19 14 21 16 12 6 2 0 12 3 7

Finally, 24 is drawn:

22 13 17 11 0 3 15 0 2 22 14 21 17 24 4 8 2 23 4 24 9 18 13 17 5 10 16 15 9 19 21 9 14 16 7 19 8 7 25 23 18 8 23 26 20 6 10 3 18 5 20 11 10 24 4 22 11 13 6 5 1 12 20 15 19 14 21 16 12 6 2 0 12 3 7

At this point, the third board wins because it has at least one complete row or column of marked numbers (in this case, the entire top row is marked: 14 21 17 24 4).

The score of the winning board can now be calculated. Start by finding the sum of all unmarked numbers on that board; in this case, the sum is 188. Then, multiply that sum by the number that was just called when the board won, 24, to get the final score, 188 * 24 = 4512.

To guarantee victory against the giant squid, figure out which board will win first. What will your final score be if you choose that board?

(let [[numbers _ & sheets] (str/split (slurp "input-4") #"\n")]
  (def numbers (map #(Integer/parseInt %) (str/split numbers #",")))
  (def sheets
    (loop [[line & rem] sheets
            sheets []
            curr []]
      (if-not line
        sheets
        (if (empty? line)
          (recur rem (conj sheets curr) [])
          (->> (str/split (str/trim line) #" +")
            (map #(Integer/parseInt %))
            (conj curr)
            (recur rem sheets)))))))
(defn mark-sheet [num sheet]
  (for [line sheet]
    (map #(if (= num %) :marked %) line)))

(defn winner? [sheet]
  (as-> (map-indexed (fn [i _] (map #(nth % i) sheet)) (first sheet)) $
    (into sheet $)
    (some #(every? (partial = :marked) %) $)
    (when $ sheet)))

(loop [[num & rem] numbers
        sheets sheets]
  (let [sheets (map (partial mark-sheet num) sheets)]
    (if-let [winner (some winner? sheets)]
      (->> winner (reduce concat) (remove #(= :marked %)) (reduce +) (* num))
      (recur rem sheets))))

— Part Two —

On the other hand, it might be wise to try a different strategy: let the giant squid win.

You aren’t sure how many bingo boards a giant squid could play at once, so rather than waste time counting its arms, the safe thing to do is to figure out which board will win last and choose that one. That way, no matter which boards it picks, it will win for sure.

In the above example, the second board is the last to win, which happens after 13 is eventually called and its middle column is completely marked. If you were to keep playing until this point, the second board would have a sum of unmarked numbers equal to 148 for a final score of 148 * 13 = 1924.

Figure out which board will win last. Once it wins, what would its final score be?

(loop [[num & rem] numbers
       sheets sheets]
  (let [[last more? :as sheets] (map (partial mark-sheet num) sheets)]
    (if-not more?
      (->> last (reduce concat) (remove #(= :marked %)) (reduce +) (* num))
      (recur rem (remove winner? sheets)))))

— Day 5: Hydrothermal Venture —

You come across a field of hydrothermal vents on the ocean floor! These vents constantly produce large, opaque clouds, so it would be best to avoid them if possible.

They tend to form in lines; the submarine helpfully produces a list of nearby lines of vents (your puzzle input) for you to review. For example:

0,9 -> 5,9 8,0 -> 0,8 9,4 -> 3,4 2,2 -> 2,1 7,0 -> 7,4 6,4 -> 2,0 0,9 -> 2,9 3,4 -> 1,4 0,0 -> 8,8 5,5 -> 8,2

Each line of vents is given as a line segment in the format x1,y1 -> x2,y2 where x1,y1 are the coordinates of one end the line segment and x2,y2 are the coordinates of the other end. These line segments include the points at both ends. In other words:

An entry like 1,1 -> 1,3 covers points 1,1, 1,2, and 1,3. An entry like 9,7 -> 7,7 covers points 9,7, 8,7, and 7,7.

For now, only consider horizontal and vertical lines: lines where either x1 = x2 or y1 = y2.

So, the horizontal and vertical lines from the above list would produce the following diagram:

…….1.. ..1….1.. ..1….1.. …….1.. .112111211 ………. ………. ………. ………. 222111….

In this diagram, the top left corner is 0,0 and the bottom right corner is 9,9. Each position is shown as the number of lines which cover that point or . if no line covers that point. The top-left pair of 1s, for example, comes from 2,2 -> 2,1; the very bottom row is formed by the overlapping lines 0,9 -> 5,9 and 0,9 -> 2,9.

To avoid the most dangerous areas, you need to determine the number of points where at least two lines overlap. In the above example, this is anywhere in the diagram with a 2 or larger - a total of 5 points.

Consider only horizontal and vertical lines. At how many points do at least two lines overlap?

(def lines
  (for [line (str/split (slurp "input-5") #"\n")
        :let [[_ x1 y1 x2 y2] (re-find #"(\d+),(\d+) -> (\d+),(\d+)" line)]]
    {:x1 (Integer/parseInt x1) :y1 (Integer/parseInt y1)
     :x2 (Integer/parseInt x2) :y2 (Integer/parseInt y2)}))
(defn draw [grid {:keys [x1 y1 x2 y2]}]
  (let [dx (- x2 x1)
        dy (- y2 y1)
        cx (if (> (Math/abs dx) (Math/abs dy)) 1 (/ dx dy))
        cy (if (> (Math/abs dx) (Math/abs dy)) (/ dy dx) 1)
        cx (if (< (* cx dx) 0) (* -1 cx) cx)
        cy (if (< (* cy dy) 0) (* -1 cy) cy)]
    (loop [x x1
           y y1
           grid grid]
      (let [coord [(int x) (int y)]
            grid (assoc grid coord (+ 1 (grid coord 0)))]
        (if (and (= x x2) (= y y2))
          grid
          (recur (+ cx x) (+ cy y) grid))))))

(loop [[{:keys [x1 y1 x2 y2] :as line} & rem] lines
       grid {}]
  (if-not x1
    (count (filter (fn [[_ count]] (> count 1)) grid))
    (if (or (= y1 y2) (= x1 x2))
      (recur rem (draw grid line))
      (recur rem grid))))

– Part Two —

Unfortunately, considering only horizontal and vertical lines doesn’t give you the full picture; you need to also consider diagonal lines.

Because of the limits of the hydrothermal vent mapping system, the lines in your list will only ever be horizontal, vertical, or a diagonal line at exactly 45 degrees. In other words:

An entry like 1,1 -> 3,3 covers points 1,1, 2,2, and 3,3. An entry like 9,7 -> 7,9 covers points 9,7, 8,8, and 7,9.

Considering all lines from the above example would now produce the following diagram:

1.1….11. .111…2.. ..2.1.111. …1.2.2.. .112313211 …1.2…. ..1…1… .1…..1.. 1…….1. 222111….

You still need to determine the number of points where at least two lines overlap. In the above example, this is still anywhere in the diagram with a 2 or larger - now a total of 12 points.

Consider all of the lines. At how many points do at least two lines overlap?

(->> (reduce draw {} lines)
  (filter (fn [[_ count]] (> count 1)))
  count)

— Day 6: Lanternfish —

The sea floor is getting steeper. Maybe the sleigh keys got carried this way?

A massive school of glowing lanternfish swims past. They must spawn quickly to reach such large numbers - maybe exponentially quickly? You should model their growth rate to be sure.

Although you know nothing about this specific species of lanternfish, you make some guesses about their attributes. Surely, each lanternfish creates a new lanternfish once every 7 days.

However, this process isn’t necessarily synchronized between every lanternfish - one lanternfish might have 2 days left until it creates another lanternfish, while another might have 4. So, you can model each fish as a single number that represents the number of days until it creates a new lanternfish.

Furthermore, you reason, a new lanternfish would surely need slightly longer before it’s capable of producing more lanternfish: two more days for its first cycle.

So, suppose you have a lanternfish with an internal timer value of 3:

After one day, its internal timer would become 2. After another day, its internal timer would become 1. After another day, its internal timer would become 0. After another day, its internal timer would reset to 6, and it would create a new lanternfish with an internal timer of 8. After another day, the first lanternfish would have an internal timer of 5, and the second lanternfish would have an internal timer of 7.

A lanternfish that creates a new fish resets its timer to 6, not 7 (because 0 is included as a valid timer value). The new lanternfish starts with an internal timer of 8 and does not start counting down until the next day.

Realizing what you’re trying to do, the submarine automatically produces a list of the ages of several hundred nearby lanternfish (your puzzle input). For example, suppose you were given the following list:

3,4,3,1,2

This list means that the first fish has an internal timer of 3, the second fish has an internal timer of 4, and so on until the fifth fish, which has an internal timer of 2. Simulating these fish over several days would proceed as follows:

Initial state: 3,4,3,1,2 After 1 day: 2,3,2,0,1 After 2 days: 1,2,1,6,0,8 After 3 days: 0,1,0,5,6,7,8 After 4 days: 6,0,6,4,5,6,7,8,8 After 5 days: 5,6,5,3,4,5,6,7,7,8 After 6 days: 4,5,4,2,3,4,5,6,6,7 After 7 days: 3,4,3,1,2,3,4,5,5,6 After 8 days: 2,3,2,0,1,2,3,4,4,5 After 9 days: 1,2,1,6,0,1,2,3,3,4,8 After 10 days: 0,1,0,5,6,0,1,2,2,3,7,8 After 11 days: 6,0,6,4,5,6,0,1,1,2,6,7,8,8,8 After 12 days: 5,6,5,3,4,5,6,0,0,1,5,6,7,7,7,8,8 After 13 days: 4,5,4,2,3,4,5,6,6,0,4,5,6,6,6,7,7,8,8 After 14 days: 3,4,3,1,2,3,4,5,5,6,3,4,5,5,5,6,6,7,7,8 After 15 days: 2,3,2,0,1,2,3,4,4,5,2,3,4,4,4,5,5,6,6,7 After 16 days: 1,2,1,6,0,1,2,3,3,4,1,2,3,3,3,4,4,5,5,6,8 After 17 days: 0,1,0,5,6,0,1,2,2,3,0,1,2,2,2,3,3,4,4,5,7,8 After 18 days: 6,0,6,4,5,6,0,1,1,2,6,0,1,1,1,2,2,3,3,4,6,7,8,8,8,8

Each day, a 0 becomes a 6 and adds a new 8 to the end of the list, while each other number decreases by 1 if it was present at the start of the day.

In this example, after 18 days, there are a total of 26 fish. After 80 days, there would be a total of 5934.

Find a way to simulate lanternfish. How many lanternfish would there be after 80 days?

(def lanternfish
  (map #(Integer/parseInt %) (str/split (slurp "input-6") #",")))
(loop [lf lanternfish
       days 80]
  (if (zero? days)
    (count lf)
    (recur (mapcat #(if (zero? %) [6 8] [(dec %)]) lf) (- days 1))))

— Part Two —

Suppose the lanternfish live forever and have unlimited food and space. Would they take over the entire ocean?

After 256 days in the example above, there would be a total of 26984457539 lanternfish!

(loop [lf (frequencies lanternfish)
       days 256]
  (if (zero? days)
    (reduce + (map second lf))
    (let [zeros (or (lf 0) 0)
          rem (into {} (pmap (fn [[n c]] [(dec n) c]) (dissoc lf 0)))]
      (recur
        (assoc rem
          6 (+ zeros (rem 6 0))
          8 (+ zeros (rem 8 0)))
        (- days 1)))))

— Day 7: The Treachery of Whales —

A giant whale has decided your submarine is its next meal, and it’s much faster than you are. There’s nowhere to run!

Suddenly, a swarm of crabs (each in its own tiny submarine - it’s too deep for them otherwise) zooms in to rescue you! They seem to be preparing to blast a hole in the ocean floor; sensors indicate a massive underground cave system just beyond where they’re aiming!

The crab submarines all need to be aligned before they’ll have enough power to blast a large enough hole for your submarine to get through. However, it doesn’t look like they’ll be aligned before the whale catches you! Maybe you can help?

There’s one major catch - crab submarines can only move horizontally.

You quickly make a list of the horizontal position of each crab (your puzzle input). Crab submarines have limited fuel, so you need to find a way to make all of their horizontal positions match while requiring them to spend as little fuel as possible.

For example, consider the following horizontal positions:

16,1,2,0,4,2,7,1,2,14

This means there’s a crab with horizontal position 16, a crab with horizontal position 1, and so on.

Each change of 1 step in horizontal position of a single crab costs 1 fuel. You could choose any horizontal position to align them all on, but the one that costs the least fuel is horizontal position 2:

Move from 16 to 2: 14 fuel Move from 1 to 2: 1 fuel Move from 2 to 2: 0 fuel Move from 0 to 2: 2 fuel Move from 4 to 2: 2 fuel Move from 2 to 2: 0 fuel Move from 7 to 2: 5 fuel Move from 1 to 2: 1 fuel Move from 2 to 2: 0 fuel Move from 14 to 2: 12 fuel

This costs a total of 37 fuel. This is the cheapest possible outcome; more expensive outcomes include aligning at position 1 (41 fuel), position 3 (39 fuel), or position 10 (71 fuel).

Determine the horizontal position that the crabs can align to using the least fuel possible. How much fuel must they spend to align to that position?

(def crab-heights
  (map #(Integer/parseInt %) (str/split (slurp "input-7") #",")))
(let [min (apply min crab-heights)
      max (apply max crab-heights)]
  (loop [height min
         fuel {}]
    (if (> height max)
      (first (sort-by second fuel))
      (let [usage (reduce #(+ %1 (Math/abs (- %2 height))) 0 crab-heights)]
        (recur (inc height) (assoc fuel height usage))))))

— Part Two —

The crabs don’t seem interested in your proposed solution. Perhaps you misunderstand crab engineering?

As it turns out, crab submarine engines don’t burn fuel at a constant rate. Instead, each change of 1 step in horizontal position costs 1 more unit of fuel than the last: the first step costs 1, the second step costs 2, the third step costs 3, and so on.

As each crab moves, moving further becomes more expensive. This changes the best horizontal position to align them all on; in the example above, this becomes 5:

Move from 16 to 5: 66 fuel Move from 1 to 5: 10 fuel Move from 2 to 5: 6 fuel Move from 0 to 5: 15 fuel Move from 4 to 5: 1 fuel Move from 2 to 5: 6 fuel Move from 7 to 5: 3 fuel Move from 1 to 5: 10 fuel Move from 2 to 5: 6 fuel Move from 14 to 5: 45 fuel

This costs a total of 168 fuel. This is the new cheapest possible outcome; the old alignment position (2) now costs 206 fuel instead.

Determine the horizontal position that the crabs can align to using the least fuel possible so they can make you an escape route! How much fuel must they spend to align to that position?

(let [min (apply min crab-heights)
      max (apply max crab-heights)
      costs (reductions + (range))]
  (loop [height min
         fuel {}]
    (if (> height max)
      (first (sort-by second fuel))
      (let [usage (reduce #(+ %1 (nth costs (Math/abs (- %2 height)))) 0 crab-heights)]
        (recur (inc height) (assoc fuel height usage))))))
189
190
199
197
200
201
199
216
224
239
243
236
235
236
238
246
245
249
252
256
260
263
280
290
300
299
298
297
309
315
351
356
374
376
399
400
396
398
401
398
416
423
432
433
446
459
462
447
458
455
442
443
442
446
447
455
472
475
486
492
520
518
526
519
528
529
553
547
572
558
559
548
560
538
574
549
577
568
569
581
576
577
576
578
579
581
580
583
579
580
581
583
590
600
604
619
611
608
609
610
624
625
624
631
637
647
645
666
672
673
672
669
671
680
691
695
696
697
699
700
696
697
700
699
702
722
723
711
716
721
722
723
721
729
730
732
740
742
764
768
765
768
769
770
766
784
778
777
780
811
838
839
840
843
849
856
861
875
890
889
890
894
893
885
883
894
902
904
905
901
902
906
910
898
906
904
902
904
868
871
857
842
841
843
852
853
863
864
882
889
886
888
889
888
889
875
883
901
902
903
902
898
906
903
914
916
936
937
927
926
932
933
940
941
942
944
965
966
965
978
973
976
994
988
987
1011
1010
1013
1022
1021
1025
1027
1037
1068
1074
1073
1088
1095
1096
1101
1127
1128
1139
1154
1150
1189
1183
1186
1212
1220
1226
1225
1228
1229
1233
1237
1238
1234
1236
1234
1224
1225
1236
1235
1257
1272
1295
1312
1307
1350
1364
1365
1367
1363
1369
1365
1367
1380
1381
1382
1398
1399
1400
1401
1409
1424
1429
1430
1411
1379
1380
1382
1383
1398
1399
1396
1405
1404
1401
1394
1395
1404
1409
1410
1412
1391
1392
1398
1401
1404
1413
1416
1420
1428
1460
1469
1464
1466
1464
1472
1479
1475
1482
1477
1481
1480
1481
1521
1509
1512
1515
1531
1526
1524
1543
1542
1545
1557
1554
1551
1557
1567
1569
1574
1569
1570
1572
1568
1567
1589
1594
1607
1608
1605
1614
1617
1607
1643
1648
1654
1661
1676
1664
1663
1670
1686
1711
1712
1736
1738
1737
1739
1726
1736
1725
1708
1707
1715
1720
1714
1724
1727
1728
1730
1729
1730
1732
1736
1731
1732
1763
1764
1763
1764
1765
1769
1772
1798
1799
1817
1826
1827
1825
1824
1822
1795
1785
1782
1783
1774
1788
1792
1794
1803
1810
1815
1828
1829
1846
1857
1854
1853
1862
1864
1839
1840
1841
1845
1862
1881
1888
1894
1880
1879
1888
1894
1907
1908
1911
1903
1902
1904
1906
1907
1908
1907
1905
1908
1910
1928
1942
1948
1946
1947
1952
1953
1954
1963
1986
1984
1981
1982
1987
1990
1997
1996
2027
2041
2053
2054
2071
2088
2061
2064
2065
2053
2092
2097
2103
2104
2100
2089
2068
2070
2081
2083
2063
2062
2061
2057
2063
2044
2049
2050
2041
2049
2031
2039
2035
2028
2024
2036
2037
2045
2056
2061
2064
2068
2048
2047
2043
2046
2058
2071
2070
2071
2080
2085
2079
2092
2093
2094
2099
2109
2105
2109
2110
2111
2119
2131
2132
2133
2126
2125
2126
2124
2125
2127
2128
2142
2173
2189
2187
2188
2189
2197
2198
2199
2210
2214
2215
2216
2215
2247
2252
2250
2261
2278
2280
2277
2276
2280
2300
2299
2301
2297
2307
2319
2343
2344
2347
2353
2347
2356
2354
2351
2358
2380
2381
2385
2381
2385
2386
2387
2386
2409
2407
2410
2413
2416
2423
2425
2415
2419
2423
2409
2391
2370
2371
2373
2374
2368
2379
2386
2391
2400
2399
2415
2410
2406
2410
2419
2420
2423
2419
2413
2403
2411
2413
2421
2442
2443
2416
2421
2426
2435
2443
2445
2442
2445
2443
2444
2447
2467
2484
2457
2467
2465
2473
2477
2476
2461
2460
2443
2419
2416
2417
2415
2416
2417
2420
2421
2425
2423
2425
2428
2431
2407
2408
2385
2386
2388
2407
2398
2400
2395
2396
2431
2424
2427
2430
2442
2468
2469
2471
2442
2453
2458
2469
2470
2488
2489
2491
2477
2480
2484
2474
2471
2473
2476
2480
2484
2486
2488
2492
2502
2492
2494
2522
2523
2522
2520
2521
2534
2553
2548
2559
2591
2600
2598
2596
2598
2580
2582
2584
2577
2574
2573
2579
2580
2577
2586
2588
2589
2594
2596
2590
2606
2598
2599
2612
2641
2644
2649
2650
2644
2666
2669
2670
2665
2667
2676
2679
2703
2684
2683
2681
2698
2731
2754
2755
2747
2741
2742
2738
2743
2718
2719
2720
2728
2731
2733
2739
2740
2739
2760
2759
2740
2735
2737
2742
2747
2758
2753
2744
2737
2742
2762
2775
2779
2788
2803
2802
2823
2827
2828
2829
2828
2831
2843
2847
2822
2825
2828
2847
2837
2854
2847
2843
2841
2831
2832
2845
2855
2842
2847
2848
2858
2850
2848
2849
2853
2865
2868
2873
2878
2880
2881
2880
2877
2875
2847
2855
2868
2869
2870
2872
2874
2889
2886
2875
2877
2889
2902
2904
2898
2900
2894
2893
2928
2941
2942
2926
2922
2936
2940
2924
2905
2920
2924
2933
2936
2935
2931
2947
2957
2978
2979
2977
2973
2971
2973
2991
2990
2989
2992
3004
3023
3009
3026
3037
3041
3065
3098
3101
3122
3123
3118
3119
3122
3148
3149
3150
3155
3147
3146
3165
3157
3161
3162
3158
3160
3163
3164
3169
3170
3197
3195
3194
3196
3201
3200
3208
3202
3204
3219
3221
3226
3239
3262
3263
3252
3293
3294
3296
3297
3308
3299
3309
3292
3266
3274
3276
3284
3285
3286
3297
3304
3312
3313
3308
3325
3319
3322
3323
3328
3335
3337
3348
3350
3351
3353
3364
3365
3387
3406
3415
3414
3410
3411
3405
3421
3426
3441
3442
3446
3413
3414
3416
3417
3411
3412
3417
3422
3428
3430
3425
3436
3432
3436
3450
3448
3451
3452
3466
3482
3477
3475
3471
3473
3472
3473
3474
3472
3488
3493
3499
3500
3502
3518
3493
3518
3522
3523
3525
3529
3535
3532
3543
3554
3546
3531
3535
3540
3541
3542
3540
3570
3575
3576
3579
3577
3578
3589
3582
3580
3585
3584
3580
3581
3582
3584
3566
3558
3567
3590
3591
3592
3594
3593
3594
3623
3616
3640
3642
3645
3635
3637
3635
3627
3625
3621
3620
3613
3605
3606
3607
3608
3609
3610
3616
3617
3621
3617
3619
3620
3622
3655
3652
3655
3656
3668
3671
3673
3682
3687
3688
3687
3689
3692
3696
3698
3700
3699
3719
3716
3729
3736
3722
3740
3738
3744
3752
3756
3760
3778
3754
3763
3756
3773
3777
3763
3764
3766
3781
3776
3763
3747
3754
3764
3759
3766
3767
3769
3771
3766
3769
3771
3764
3805
3804
3803
3808
3799
3831
3833
3814
3815
3829
3836
3854
3861
3865
3879
3876
3877
3859
3858
3860
3863
3862
3890
3891
3909
3907
3886
3880
3882
3885
3886
3887
3888
3891
3901
3909
3894
3885
3901
3921
3922
3909
3913
3920
3918
3919
3926
3918
3920
3921
3929
3944
3927
3926
3925
3940
3956
3937
3939
3940
3941
3933
3956
3957
3971
3976
3978
3977
3983
3984
3985
3986
3989
3988
3990
3997
4002
4005
4014
4019
4038
4044
4050
4054
4055
4064
4082
4084
4087
4100
4109
4117
4118
4150
4147
4141
4142
4138
4146
4138
4144
4141
4148
4192
4214
4223
4218
4220
4219
4224
4220
4221
4228
4230
4241
4249
4248
4278
4279
4235
4220
4222
4220
4235
4226
4243
4244
4238
4253
4254
4232
4226
4221
4220
4219
4204
4200
4201
4192
4191
4198
4202
4220
4235
4233
4258
4242
4244
4241
4242
4247
4233
4234
4247
4258
4259
4258
4288
4292
4295
4294
4305
4295
4296
4299
4303
4314
4330
4347
4349
4376
4384
4396
4395
4399
4381
4402
4420
4418
4423
4426
4428
4427
4429
4430
4453
4454
4461
4481
4492
4496
4498
4499
4498
4499
4504
4516
4524
4525
4528
4529
4528
4526
4527
4532
4534
4514
4544
4546
4548
4549
4557
4563
4566
4573
4583
4584
4580
4596
4606
4608
4615
4620
4614
4609
4621
4637
4645
4629
4633
4627
4631
4617
4645
4656
4657
4658
4689
4704
4705
4707
4706
4704
4705
4708
4709
4722
4724
4699
4696
4693
4692
4695
4694
4700
4701
4686
4688
4698
4700
4697
4706
4709
4721
4728
4729
4731
4726
4739
4740
4746
4740
4741
4747
4745
4746
4749
4750
4752
4753
4754
4766
4764
4762
4748
4747
4743
4746
4747
4754
4720
4721
4724
4725
4738
4739
4740
4745
4750
4747
4742
4740
4757
4765
4780
4783
4785
4795
4799
4800
4823
4826
4824
4827
4830
4829
4828
4823
4825
4827
4849
4853
4837
4848
4849
4844
4845
4858
4861
4865
4866
4874
4875
4876
4877
4882
4883
4885
4890
4891
4893
4894
4901
4905
4926
4925
4934
4935
4933
4916
4947
4942
4937
4968
4958
4957
4958
4959
4957
4955
4927
4928
4926
4934
4933
4934
4916
4917
4918
4919
4920
4963
4985
4979
4976
4968
4973
4969
4961
4963
4960
4964
4963
4967
4969
4967
4972
4977
4976
4979
4975
4981
5005
5008
4984
4983
4991
4992
4993
4994
4995
5014
5046
5069
5068
5066
5073
5074
5072
5073
5083
5079
5111
5110
5111
5139
5136
5138
5124
5127
5126
5138
5137
5138
5154
5149
5152
5173
5191
5192
5193
5198
5195
5194
5221
5229
5245
5248
5246
5266
5267
5293
5294
5303
5325
5328
5327
5328
5334
5341
5327
5326
5337
5353
5354
5356
5360
5342
5356
5367
5363
5364
5363
5365
5398
5400
5404
5407
5402
5399
5404
5430
5439
5441
5446
5445
5448
5449
5472
5490
5494
5498
5484
5483
5497
5498
5491
5488
5517
5518
5513
5516
5507
5508
5507
5508
5521
5520
5518
5519
5523
5524
5523
5526
5506
5508
5522
5507
5508
5509
5492
5529
5531
5567
5552
5549
5547
5542
5544
5550
5523
5561
5556
5539
5540
5573
5575
5569
5568
5572
5569
5587
5586
5585
5582
5583
5578
5580
5598
5604
5603
5610
5604
5603
5604
5607
5632
5633
5644
5645
5660
5662
5672
5685
5684
5687
5733
5735
5743
5745
5772
5774
5773
5777
5781
5784
5769
5777
5788
5789
5790
5793
5767
5788
5787
5789
5791
5795
5820
5821
5804
5808
5824
5821
5825
5847
5849
5850
5844
5833
5834
5842
5826
5855
5856
5858
5871
5860
5862
5872
5875
5885
5883
5874
5871
5865
5878
5887
5897
5918
5913
5908
5925
5926
5934
5937
5940
5944
5942
5962
5963
5976
5977
5966
5971
5970
5976
5978
5967
5979
5962
5983
5988
5989
6004
6003
6002
6009
6020
6037
6039
6041
6042
6040
6039
6041
6042
6043
6046
6051
6067
6069
6070
6083
6085
6083
6084
6082
6110
6100
6102
6100
6102
6106
6109
6094
6095
6102
6103
6116
6114
6119
6129
6130
6134
6135
6132
6131
6134
6169
6168
6199
6200
6202
6204
6205
6210
6216
6221
6214
6215
6225
6224
6230
6226
6238
6237
6246
6244
6247
6245
6246
6249
6250
6242
6243
6241
6220
6215
6216
6215
6216
6214
6186
6180
6182
6183
6186
6192
6174
6175
6172
6202
6206
6194
6202
6219
6222
6193
6192
6196
6214
6222
6225
6240
6238
6224
6225
6223
6224
6237
6240
6239
6242
6241
6230
6229
6222
6221
6234
6237
6238
6239
6240
6241
6254
6267
6272
6273
6271
6272
6283
6282
6281
6280
6282
6283
6281
6285
6287
6286
6287
6283
6306
6312
6349
6352
6350
6332
6317
6311
6324
6337
6339
6340
6351
6359
6363
6334
6338
6339
6342
6335
6336
6342
6343
6344
6329
6341
6347
6359
6335
6351
6353
6348
6347
6357
6360
6361
6362
6375
6366
6365
6363
6360
6386
6402
6423
6428
6429
6435
6434
6435
6437
6460
6461
6457
6465
6466
6470
6462
6464
6466
6468
6461
6468
6469
6507
6506
6532
6531
6538
6536
6552
6580
6585
6595
6597
6583
6570
6569
6568
6570
6569
6571
6541
6542
6548
6542
6538
6543
6534
6538
6560
6566
6567
6576
6578
6597
6602
6606
6600
6598
6601
6614
6611
6610
6613
6605
6611
6610
6609
6608
6609
6610
6615
6614
6619
6627
6629
6624
forward 8
down 6
down 8
forward 7
down 5
up 2
down 3
down 7
down 8
down 8
down 8
down 2
up 1
down 3
up 2
down 4
down 2
forward 6
forward 4
down 3
down 2
forward 2
forward 1
forward 4
forward 5
forward 8
down 1
down 4
up 5
up 2
forward 3
down 9
forward 7
forward 9
forward 9
forward 8
down 1
down 2
forward 7
down 3
forward 6
down 4
forward 7
down 1
up 8
forward 3
down 1
forward 7
up 1
forward 8
up 6
up 2
down 6
forward 1
up 6
forward 5
down 9
up 5
forward 7
forward 9
down 9
down 3
forward 7
forward 8
forward 3
forward 9
forward 7
down 3
down 7
down 4
forward 2
down 7
down 3
down 5
up 1
down 9
up 4
forward 1
up 9
down 2
forward 8
down 8
down 6
forward 7
down 9
down 3
forward 8
forward 3
down 6
down 7
down 4
forward 3
down 3
down 9
forward 8
forward 9
up 5
forward 1
down 3
down 3
down 3
down 9
down 2
down 9
forward 5
up 3
up 5
up 7
down 2
down 7
down 9
down 5
down 4
down 8
forward 1
up 8
up 3
forward 1
forward 5
forward 3
up 7
down 9
down 9
forward 7
down 1
forward 1
forward 8
forward 6
down 1
down 7
forward 9
up 4
forward 8
up 6
forward 3
down 3
down 9
forward 5
up 3
down 7
forward 9
forward 2
up 1
forward 7
up 8
forward 7
forward 1
up 3
up 7
down 1
forward 5
up 8
down 2
up 2
up 3
down 5
forward 6
up 8
down 7
up 8
up 4
down 8
forward 9
down 8
down 2
up 7
down 5
forward 1
up 1
down 1
forward 1
forward 1
forward 3
forward 8
down 4
down 5
forward 9
up 6
up 7
down 8
forward 8
down 2
forward 6
down 3
forward 9
forward 5
up 7
down 2
up 6
up 6
down 9
forward 3
up 1
up 2
forward 9
down 1
up 3
forward 4
forward 9
down 3
down 4
forward 4
up 6
up 5
forward 2
down 5
down 1
forward 9
down 7
up 6
up 5
forward 4
forward 9
down 6
forward 1
up 6
down 1
forward 4
up 9
down 6
forward 5
down 2
forward 8
forward 9
down 7
down 4
down 1
forward 1
down 4
down 6
forward 5
forward 2
forward 8
forward 5
down 6
up 9
forward 2
down 1
forward 6
forward 6
down 5
forward 5
down 8
forward 3
down 5
up 1
forward 4
down 5
down 4
forward 4
down 3
down 5
down 7
forward 5
forward 2
up 2
up 4
forward 7
down 3
down 1
down 7
up 8
forward 6
forward 3
forward 7
forward 5
up 5
down 3
down 6
forward 7
up 9
up 5
forward 2
down 9
forward 8
forward 6
forward 5
up 5
down 9
down 8
up 2
up 4
forward 5
forward 2
up 4
forward 3
down 7
forward 8
forward 1
forward 9
forward 6
up 7
up 2
forward 1
down 5
forward 9
down 8
down 4
down 7
up 2
down 5
forward 7
up 3
forward 6
down 2
forward 8
forward 8
up 3
forward 6
forward 9
forward 8
forward 3
up 9
forward 9
down 6
forward 5
forward 8
up 1
forward 2
forward 6
forward 8
up 6
down 3
down 9
down 6
up 7
forward 6
forward 1
forward 1
forward 7
down 5
down 9
down 3
up 3
forward 3
forward 2
down 5
up 4
forward 1
down 9
forward 9
forward 1
forward 1
down 9
down 2
forward 4
forward 9
down 5
up 5
down 6
forward 8
down 4
down 1
up 5
up 3
down 2
down 3
forward 8
forward 5
forward 9
down 4
up 9
down 1
forward 2
down 8
up 2
down 8
up 6
forward 7
down 1
up 7
down 9
forward 9
down 9
forward 7
forward 4
down 5
up 3
down 3
forward 8
down 3
down 4
down 9
forward 4
up 4
forward 6
down 1
forward 5
down 2
forward 6
down 4
down 1
forward 3
up 3
up 3
forward 8
forward 6
forward 6
down 9
forward 5
down 9
forward 6
forward 3
up 4
forward 6
down 8
up 3
down 9
down 3
forward 6
down 4
down 8
down 6
down 5
forward 1
down 3
forward 9
down 9
down 3
forward 9
down 2
forward 3
up 6
forward 2
forward 1
forward 8
down 2
down 2
down 7
up 7
forward 3
up 2
up 6
up 6
down 2
forward 2
forward 2
down 6
down 2
up 6
forward 4
down 9
up 3
down 4
forward 7
up 6
forward 3
forward 1
down 1
down 8
down 8
down 1
forward 2
down 6
down 6
forward 2
up 6
down 2
up 4
down 1
up 8
up 5
down 4
forward 2
forward 2
down 2
forward 9
down 5
down 9
forward 6
down 9
down 5
down 7
down 3
up 9
down 6
up 6
up 8
forward 8
forward 8
down 3
up 9
forward 9
forward 8
forward 6
down 4
down 6
up 9
down 9
down 5
up 2
up 2
forward 2
forward 1
down 5
down 8
up 3
forward 2
down 1
down 9
forward 7
forward 5
up 3
up 6
down 5
up 1
down 2
up 7
forward 1
down 6
up 6
up 1
up 2
forward 2
down 4
up 1
up 3
up 9
up 7
forward 4
down 5
down 9
down 8
forward 1
down 4
forward 4
forward 8
up 4
down 8
down 1
down 9
down 5
forward 3
forward 8
up 2
down 6
up 6
forward 5
down 6
down 8
forward 6
down 6
up 5
down 2
up 5
down 7
down 9
forward 3
down 8
forward 1
forward 5
forward 2
down 4
forward 2
forward 7
up 7
up 3
down 2
forward 7
up 6
forward 6
forward 1
down 4
down 2
down 6
down 1
forward 1
forward 8
down 1
up 2
down 2
down 1
down 6
forward 7
forward 6
forward 5
down 1
down 8
down 1
up 5
forward 6
forward 5
up 5
forward 5
up 8
down 3
forward 1
forward 6
up 8
up 9
down 7
down 1
forward 2
forward 1
forward 9
forward 3
forward 7
forward 8
down 6
up 5
down 1
forward 1
forward 8
down 6
forward 7
forward 8
down 7
down 5
down 7
up 7
down 5
forward 5
down 4
down 7
forward 6
forward 5
forward 6
forward 7
up 9
down 2
down 2
down 4
down 8
up 3
down 7
down 5
forward 6
down 9
down 5
down 9
down 1
forward 6
up 7
down 2
down 2
forward 8
forward 1
down 3
down 4
forward 3
forward 4
down 1
forward 9
up 7
forward 8
down 9
forward 7
forward 6
forward 2
down 8
up 9
down 2
forward 8
up 7
down 5
down 9
down 3
down 6
down 4
up 2
down 3
down 1
up 1
up 6
forward 4
down 1
forward 1
up 4
forward 4
forward 3
forward 8
forward 9
forward 9
down 2
down 5
up 8
up 1
down 9
forward 5
down 1
up 5
down 4
up 3
forward 9
up 7
forward 9
up 1
forward 4
forward 8
up 6
down 6
down 8
down 8
down 9
down 2
up 7
forward 9
up 8
down 9
up 6
forward 4
up 7
down 6
up 7
down 4
forward 2
forward 9
down 6
down 8
forward 6
forward 3
down 3
forward 3
forward 7
up 2
down 8
forward 7
down 5
down 1
down 6
down 5
down 2
up 6
forward 7
forward 6
down 1
down 5
forward 7
forward 3
down 9
down 8
forward 5
up 7
forward 1
up 5
down 7
forward 8
forward 6
forward 2
down 1
down 9
up 1
down 2
down 2
down 7
down 4
forward 1
down 3
down 5
up 8
forward 7
up 5
down 8
down 6
down 3
down 3
down 9
down 7
forward 4
up 5
forward 3
forward 7
down 3
up 6
forward 4
forward 4
down 4
down 2
up 1
forward 8
forward 3
up 1
forward 1
down 9
down 6
up 1
down 4
down 8
up 9
forward 2
down 3
forward 8
down 6
down 5
down 4
up 5
down 9
up 3
forward 4
down 9
down 7
forward 6
forward 6
forward 8
forward 6
down 9
down 1
forward 3
forward 9
forward 4
up 8
up 5
up 2
down 9
forward 9
forward 3
forward 5
up 8
down 2
down 1
forward 9
forward 7
down 7
forward 1
down 5
down 8
down 4
down 7
down 1
down 4
down 7
forward 2
down 5
forward 1
down 4
down 5
down 2
up 5
forward 9
down 5
forward 1
down 7
down 4
down 7
down 6
forward 5
down 3
down 1
up 2
forward 2
forward 2
forward 1
down 1
forward 3
forward 5
forward 4
down 7
forward 7
down 1
forward 7
forward 5
down 8
forward 6
forward 6
forward 6
forward 7
up 9
down 4
down 1
down 8
forward 7
up 4
forward 4
down 6
up 1
forward 5
forward 2
down 1
forward 7
forward 6
forward 5
forward 2
down 5
down 6
down 9
up 4
forward 6
forward 2
down 5
down 3
up 4
down 6
up 8
forward 8
up 9
forward 6
forward 6
up 5
down 7
forward 9
forward 6
down 9
down 9
up 1
forward 7
down 6
up 4
down 8
down 3
forward 9
forward 5
forward 9
down 2
forward 3
down 1
forward 9
up 4
up 8
forward 6
down 1
forward 9
forward 4
down 5
forward 2
up 3
forward 5
up 8
up 7
down 8
forward 4
down 6
forward 7
up 2
down 2
forward 4
down 9
down 8
forward 2
forward 2
down 2
down 3
forward 3
down 1
forward 8
down 7
up 9
down 4
down 2
down 5
up 7
down 8
down 2
down 4
down 4
down 8
forward 7
forward 7
down 8
up 2
up 3
forward 8
up 1
down 7
forward 7
down 6
down 8
up 6
forward 5
forward 3
down 6
forward 9
up 4
up 7
forward 4
down 1
down 8
down 1
forward 9
down 3
forward 8
forward 6
forward 4
down 9
forward 3
up 5
up 8
down 9
down 5
down 1
up 8
forward 8
up 6
forward 2
down 8
up 4
up 7
forward 7
forward 5
forward 9
forward 2
up 4
down 9
forward 7
down 6
down 6
forward 7
down 5
up 6
down 9
forward 3
101011111001
100100110111
101010101011
010100010000
001101101101
110001101010
001001011001
101111101111
110001001000
111111000000
111100110001
101100010100
000010000011
000110000011
101010100101
000111001010
100101101110
111111010101
110010001100
000011001101
001001111110
100101001100
000011100100
000100110011
000101101000
101010011011
101011110000
010010110011
110110101110
001110000110
001110111101
110111100101
000010101010
101010101010
011011001101
110110000111
011010011000
000111000101
100000101011
010010101100
110000101110
000010001001
101010001100
101111110101
101111011110
110011100001
011011100100
111100011010
110110101001
101011100010
111000110110
111011100101
111000001111
101110110011
111101000000
101111100110
011111101101
100111110111
000111011011
001001001111
100010110000
001101010000
100101101001
100001010000
110101110001
100111111111
101101000101
001110100110
101010110000
101111010010
101011100101
001110010100
011110110100
100011000000
001000000100
010000010001
101101111011
111010001011
101010100000
101001000000
001000010101
010011000111
101010111100
111101000101
111111100010
100010011101
101001111101
010111001111
111111110110
100111101010
010101000101
100101010010
010110010001
011101000111
011110011010
100000111100
011111111000
001111010001
110110100111
111000001011
110010010011
101010110010
110000110111
101111010000
110111010000
110011100011
010000100111
001010110001
011101011010
110111010010
011001001101
101101001111
011101110100
001101101110
011011101101
111001010001
001100101000
010011100000
011000010100
111000111111
001001100001
010011001010
001110101100
010010111010
000111111011
010010000110
110001100100
001110110111
000010001111
100011100001
100001101110
100001110111
010110100000
100101101111
001100000111
101100111001
100100001100
100000101100
010101000110
101110001000
101110000110
101110011100
001001010001
110111101011
101001000001
111100111110
001100010100
010001111111
110011000011
100110011101
011010100100
011111000011
000110001000
010010111111
010011111011
001000111110
000111101011
100010111100
010110001111
011011000000
010111000011
010001011111
111000101100
010110110000
001100111011
011110100101
100011100011
001000101000
101011001011
101111001111
111000100101
111101100111
111010101000
001110000111
010101011110
001111010100
101011011101
000111101010
000011001011
111000010001
011001011011
011011011001
011110111000
000010001100
011110010000
010000101001
101011011111
100111001100
101000011100
111000000100
011100110000
011100101010
010001110011
100100100010
011110010010
011000100111
110101000101
111011000001
011000010111
010011110011
011001000001
000100101110
100111110001
010010011010
111101011001
100110101111
100010001100
010010000111
100011100100
111001111011
110000010111
101001010001
011111001010
110111111100
000101111101
101011000111
000100010000
111100001111
100000110010
110001110100
000001001100
000101000001
100111101011
011000110110
101111000000
010100101100
101111100011
100111001101
100000010010
100101001111
011110100010
110110100110
100000100001
110100001110
010011001111
011010010000
000000010101
111111011100
000011100000
011110111101
110000011100
011011011000
010100111010
010010100101
001110100011
000110000100
100111000101
000010001000
110110110000
010011000100
011001100010
110000011110
000110100111
010111111011
011100000011
100011101110
001100011010
000010100100
000011110000
000000101000
101001101001
101111010101
101100101101
110000000000
111011001110
001100101110
100101111000
010001000111
111100111010
000100011101
010001000011
100000101001
111111101101
000000011101
001101110110
001100000101
010110011110
001011100100
110001100101
001011110011
011101111000
001001100110
000001011000
001011010000
110001010100
000100011011
010101101010
101000101010
101111011000
110001010111
111100110011
101011101000
000100010110
111010000110
000100000001
101011110101
010010010011
100101011001
100101001010
110100110101
010011100111
100110010101
111010000011
011011110110
111000101110
001011101100
010110100010
011001101011
011000101101
011011111110
011011111001
100001001101
101110011011
001111011100
111110010011
000010101011
001111101010
100001101000
111100100000
010011100100
011101101100
000001101011
001100001110
000011000111
100110001000
101101101011
001011011110
101010111101
101110100110
011111000100
111101111000
001011110111
010010011001
111110110001
100101000100
011011010101
100010010000
100010101000
110010000100
000001001111
101110011010
010000111111
111101010001
100000000000
011101100110
001110101101
001001110010
110011101001
101101011001
000000110101
011101100011
010100000011
101011110010
100101000010
100110001100
000111111010
111100011001
111110101001
010000111000
100110000011
100011001110
000100010010
001101100100
000000001100
011101001001
100001001000
101100111000
110011011111
111110101110
101101001010
111000011001
111110011001
110111010100
011001111011
101101111000
010010010100
100000110110
011110010100
010010101010
001111100100
100000011101
110100010010
101101100000
111001111010
010001100110
011000110101
011110010011
011111100000
001000101100
000100010111
011000101010
011000010110
010001101011
110101010000
000100100100
011011001100
010100011101
100111110110
111010000001
001001111111
010100001111
011111101011
011000011011
111010000100
110001001111
111011011010
001110001110
100100101001
101101101001
001100001001
001000001110
101111000010
000110001110
101111110010
110011001011
000000010100
110100110001
111000011111
100000001110
100100011011
101100100011
011101000010
001100100101
111110101101
011100001001
101100000110
101011010011
000101101100
001011101001
110000000101
011111011110
000001100110
100110011011
111010100100
011001101001
010111110011
110111000000
011100101011
010110100111
110011001001
000010111011
101110010110
000001011001
100101000111
110110111011
000101110001
100000111101
011110001011
000101010101
101011110011
000110011001
101010000001
100001011110
010000000111
000011100110
100111100010
110101000111
001010101110
111000100000
001100101101
000111010111
101110000000
011111000010
111000001110
001100110101
101001000100
010111011101
000100000100
111111000111
111011001111
101000011110
110011101101
111101000011
101101111001
010010010101
110000100010
000100100111
000110111111
000011001000
011011100001
101100111101
011111000001
000110101100
010010111001
111100101110
100111010100
011111000000
001011001000
101111000011
000100001010
110100010000
110001000011
010010101111
001010001010
010001110001
011000001101
101001010111
000000011100
010011111000
110010011011
001110100111
011101000011
111110011101
100111000000
101011101110
111000010111
101001000011
011110011001
000100010001
101110000100
111101101101
000100100110
010011010001
000101100110
010111110001
001110111100
100000111111
101100000011
110011000100
100000001011
010101100000
101010000101
010110101101
010011100001
001101001111
101100100111
100000001101
100100101100
101111010111
010101001100
011001111111
010111110000
010100110101
101111010001
111101111100
011010011011
111100110100
111110001010
011110011111
000110001100
011001010111
000010010111
011100101111
111110111000
110010110010
000101111010
001010010100
100110110001
101101010001
100001111011
010101001001
000001000010
100101100011
010100101010
001001001100
101000110110
111110001000
100101110010
001000111011
100111010111
000000110000
110101111000
011000101110
110101001111
101000010010
101011000010
100110000111
110101011001
110010010100
010000001111
110011011001
111010110100
010000101010
101100111011
000000011010
110110001000
001011011011
101110100001
010100011011
111101001101
010000011001
110010100100
101101011010
110000100001
010101111000
101000111010
011011010100
011110011101
010000100100
001111101001
010011110000
111000100111
010101010101
000001001010
010001001100
111011111100
001110000011
110101101000
111010011110
110011010011
001010101101
001111110001
110001011110
011110010001
010010000100
111010111001
000100111111
000001010101
001010110111
000110010011
000010011111
011110100001
011111010110
001110010110
001001000011
101111011101
011100110111
010000001101
010010100111
010000110011
011110110111
010000110110
011101011011
000010100001
001100011111
011110110000
111011011011
101011101111
010001000101
010100001000
010100101110
001000000101
001001011011
111001000101
110101110100
111111010111
101010100111
110000011010
000100100000
011101000001
000011000001
010101010001
010010011100
010001110101
010110110111
010011110010
011011100110
000110100011
100010100011
101111110011
001011100101
011101110000
110001110000
111010010000
111111000011
010010001100
010111101010
010010101000
111001010111
010110110011
001101110010
011111001111
010100110100
010010100100
101011101100
000111101001
000001011010
101010111000
100011111111
100100011111
111000010010
011011100010
000111010010
101010101111
010000100101
100110110101
011011100011
011011110011
111011000100
100010001010
110000010000
100101011111
101100001100
111110101111
100111000100
011101001110
100011011101
111101011010
110101111001
001000110101
111110101100
001010010111
100110000000
110101010100
110110001101
011110101101
100110101110
000000000010
011010111001
000001101111
000100000101
110000100011
001010000101
100111011010
000001101001
001011000001
000111100110
111111110011
000101000000
111000110000
000010000111
000101010001
000011110001
101100110100
100001111110
001111111111
100011000110
011100011001
101011110100
001010001111
100010100001
001111100110
010110110010
110010110101
011000110011
000101011110
101000100100
010110010110
001000000110
110000100100
011101101011
100100000111
000111010101
110111000100
001010110000
101001110001
001001101011
101000100101
111111000010
000010110101
110000000110
000100110000
111111011011
101101100101
011001010010
111111101111
000111101101
100110110011
110000001000
111000001101
110011010010
110110111110
000001011111
001100001010
111101011100
010010100010
110100011011
110001101011
010111111010
011111100100
001010010110
001010111111
111110111110
011010000110
111111111001
011011011110
001010011101
001110010111
001001111100
110010111000
000111000100
001100001000
110110110100
101001010000
000101000101
010101101100
101010110110
111101011000
101010011100
110010110011
111110001110
100100101110
001010000000
001000110010
101000111111
111110111101
000110010110
101100100110
100010011001
100110100010
111101100110
111100111111
010111011011
111100011111
001010010011
111101010010
110111001010
010110000000
011111011001
101011100011
011100110011
111100011110
101001001001
100101100110
000100110010
010011101110
000011110111
000000011111
110011011100
111110100100
101110101111
001101011000
101101110001
101011000100
111001101100
110111111001
011010101001
000000000000
111100000101
110010111001
000100001110
110101111100
110010011111
001001110111
111111111111
000110011100
110101111010
011010111011
111000000101
011110100111
001010101111
001011011001
101010001011
100001000000
111110111010
001110111110
000000110100
111110111001
111000010101
110011110111
110111001101
111011010010
110100000110
100111111100
010001100010
111100010000
100111011101
101001000111
111110110011
010101010100
101000110111
000111101100
100001011001
010000011111
000100101011
011011011010
001111000010
111001101011
100011010111
110111100111
100001010110
100001110101
100110110111
011111111011
111111101110
111111001000
101010000110
110010010110
100110100111
011101011100
011010011101
101111101101
110111010110
110000000100
110000110100
001100000110
001011001101
001010011111
011001110000
100111100100
001111000000
110100011001
110000110011
000000101101
111101111111
111111010010
011101101110
111101101100
100000110000
110101010001
101001110100
010010110110
111011000111
101100000100
010011010101
111101000001
101001111000
101110000011
001011011101
111010000010
001001110100
111111001001
001001010000
001110000001
111100000000
010101110100
000101011011
001100011001
001110001100
001110100010
000000100111
000100111000
110100101100
110100111010
111001101101
111100101011
011101100000
100000100011
010111110010
010011001000
101001100110
100110001111
000110110101
111001110110
000101010110
011000011010
010100110110
110100111111
111000110011
001011111000
001000000000
111111010100
111111100110
000000001111
110001000001
010000101000
101111111010
100100001101
111011110100
110101110011
010111111110
001000101111
100110101100
110010010010
010010001000
011111101100
111100100011
110111101000
100000111001
001011100011
001010111100
000100001100
010111000110
001111000101
001110000010
110100101000
001110000101
101000110000
001001011101
101001011001
011110100011
101010010110
101000001101
110111111111
010010001101
011100010110
000100100001
001111111101
001001111000
001100101111
111010111100
110100010111
000000010011
100110110000
101100101111
100011010100
001001101110
110001101000
110101101110
010011110101
010000110001
100011111000
111110000010
100111100000
100001100110
110111000110
000101100011
010110001100
100000100010
001011000000
110101000010
101110101001
011010100110
111111110000
001010110010
010000001011
100000010011
010111010111
101111100010
010100010011
74,79,46,2,19,27,31,90,21,83,94,77,0,29,38,72,42,23,6,62,45,95,41,55,93,69,39,17,12,1,20,53,49,71,61,13,88,25,87,26,50,58,28,51,89,64,3,80,36,65,57,92,52,86,98,78,9,33,44,63,16,34,97,60,40,66,75,4,7,84,22,43,11,85,91,32,48,14,18,76,8,47,24,81,35,30,82,67,37,70,15,5,73,59,54,68,56,96,99,10
61 96 92 39 0
35 25 50 22 60
3 88 69 48 62
75 24 97 51 67
87 74 94 77 83
1 70 59 40 55
42 88 10 17 80
27 24 82 45 23
5 19 48 51 11
75 72 97 74 7
58 40 78 83 74
4 94 17 63 62
55 61 5 27 69
99 84 89 81 59
64 28 91 49 97
92 88 51 12 22
0 5 65 32 77
80 40 3 10 90
91 47 58 57 14
86 71 94 36 75
71 24 16 66 29
8 47 93 68 36
42 67 69 55 15
75 6 34 60 70
95 92 14 0 81
52 49 37 41 67
9 8 2 13 17
92 89 38 16 53
63 46 60 4 87
57 96 77 85 39
84 98 52 95 89
81 67 99 85 50
88 11 76 49 8
4 30 51 78 20
70 64 74 40 79
45 65 87 79 14
11 26 98 70 28
46 85 54 55 48
97 59 62 57 16
30 40 95 7 18
97 25 38 1 26
20 86 7 68 39
2 55 29 33 65
46 14 72 47 18
60 48 41 9 50
71 81 15 49 50
72 28 51 11 35
20 7 36 84 65
93 33 14 47 45
89 0 75 60 16
98 90 47 94 55
69 41 81 1 43
73 95 65 15 80
85 99 60 92 0
13 33 82 51 22
47 58 82 67 30
88 23 64 4 39
94 52 61 1 75
3 8 34 87 49
13 38 60 54 35
91 62 88 29 33
84 27 6 18 11
47 87 58 42 34
69 46 75 40 43
63 97 53 49 66
80 57 73 65 44
95 55 27 46 10
82 24 90 97 75
33 41 31 84 9
5 48 18 49 12
92 63 91 14 13
32 12 66 87 79
44 60 7 96 84
58 41 42 3 27
16 59 43 77 11
80 36 53 56 62
26 8 4 79 51
22 91 69 78 2
59 13 23 81 93
30 16 49 33 65
52 88 12 67 85
74 78 75 72 79
81 26 82 5 0
23 56 41 3 32
31 69 15 66 87
22 71 80 0 63
94 31 13 60 42
41 77 90 92 91
64 95 5 23 73
85 15 3 88 10
72 75 88 52 38
17 86 54 79 87
66 61 51 3 26
68 47 89 11 41
50 33 92 7 81
82 80 9 65 34
3 49 42 36 76
95 94 61 32 43
72 67 56 45 54
77 48 14 6 25
44 75 99 62 11
43 73 2 87 83
96 63 85 14 30
32 70 18 29 55
1 88 15 27 24
2 38 46 61 7
45 19 97 31 54
88 40 14 81 87
69 39 32 16 21
22 5 0 29 92
78 57 85 4 70
82 43 12 69 79
60 34 15 63 45
90 77 93 31 47
27 49 25 71 19
49 10 40 51 45
9 44 86 26 27
93 98 22 63 95
88 66 33 74 57
81 24 28 91 72
14 83 60 54 57
18 15 41 4 47
39 98 62 33 5
30 70 6 91 90
86 21 28 84 81
91 46 49 9 32
85 33 87 83 76
17 14 37 94 6
31 13 92 89 78
15 66 47 74 63
55 6 83 19 96
71 22 88 99 50
89 84 26 45 38
57 77 87 93 25
44 49 16 64 34
79 76 46 19 51
85 90 58 29 3
34 2 81 62 99
84 60 78 91 96
4 27 43 47 98
66 2 38 39 37
35 25 51 10 82
91 62 1 12 93
83 29 47 32 56
74 19 50 95 49
59 57 35 50 51
27 38 62 76 3
52 49 83 75 4
64 16 93 7 91
40 17 65 41 97
18 37 45 44 4
72 7 28 0 75
9 2 95 90 38
24 79 93 22 88
94 70 57 6 20
11 61 65 50 23
74 51 80 91 22
5 32 27 57 14
59 86 70 17 10
21 62 20 18 67
98 9 88 79 78
99 56 91 41 67
17 39 65 16 38
75 84 11 21 61
22 81 52 55 87
45 36 74 47 19
15 22 88 85 32
38 63 54 16 13
29 7 48 90 43
68 3 24 17 30
72 77 68 75 57
43 74 32 61 34
37 2 47 25 85
56 12 95 98 0
80 36 39 22 11
77 58 24 57 99
70 16 33 41 94
54 61 20 90 30
29 17 55 0 83
13 37 42 49 38
86 58 13 11 6
73 26 25 0 67
56 44 87 5 49
4 91 51 66 22
28 8 1 15 57
61 24 50 25 66
92 42 98 55 96
46 79 22 33 91
97 0 69 90 54
17 38 34 39 52
68 28 67 45 87
8 80 52 41 54
34 47 4 78 59
10 29 32 11 26
17 33 7 93 35
10 15 33 46 14
6 56 52 16 92
47 36 17 8 69
77 45 73 84 9
55 60 80 44 64
58 18 25 11 83
75 7 53 42 68
48 52 6 0 43
80 97 16 60 1
29 67 15 5 17
77 55 54 24 66
58 2 4 39 12
57 86 69 91 8
67 84 65 13 20
87 59 40 34 27
39 7 40 77 91
13 76 32 92 56
34 17 81 27 66
37 80 83 85 15
43 36 30 26 63
11 50 72 85 34
3 92 58 53 7
98 10 49 97 12
26 42 14 24 56
28 20 59 54 4
55 56 29 80 96
63 68 44 22 12
65 4 95 6 26
21 35 14 87 8
17 92 86 30 53
9 42 20 37 19
65 46 11 54 92
52 4 56 80 99
41 55 43 90 17
60 87 13 50 3
3 29 4 41 95
14 9 11 23 10
7 63 68 58 66
13 46 67 86 51
28 36 0 73 84
45 1 19 74 36
58 64 30 86 83
99 42 70 97 54
17 75 56 80 81
93 41 90 10 88
24 25 0 94 22
70 1 50 10 14
89 77 76 63 46
33 72 81 28 60
68 40 12 31 20
79 33 30 55 71
31 91 54 0 82
10 78 9 49 14
85 72 5 3 24
86 38 97 46 61
20 84 97 52 79
45 73 11 18 58
63 86 21 9 87
48 90 13 77 49
44 85 56 71 55
16 1 54 13 83
38 32 69 28 43
5 50 57 95 47
34 76 45 74 89
46 91 71 39 17
82 45 14 28 57
27 21 17 29 51
95 32 31 80 91
89 74 67 76 79
6 0 4 43 94
52 66 44 74 95
85 51 79 76 54
89 34 59 10 27
45 6 69 98 48
88 19 3 65 94
61 9 67 72 71
93 48 64 52 11
74 85 12 13 23
41 4 94 16 57
63 88 28 89 40
68 23 54 56 44
13 77 26 2 46
28 81 15 16 62
82 51 71 86 72
99 0 52 41 32
99 38 7 87 9
69 96 22 57 24
64 81 29 67 14
48 52 6 88 92
90 44 51 40 8
41 1 23 24 73
10 4 66 60 22
17 9 69 53 63
42 34 99 86 56
75 82 81 18 79
58 64 12 59 30
21 94 28 77 53
88 90 97 62 83
35 70 27 98 26
65 34 25 73 75
81 7 90 91 74
23 34 67 31 50
60 87 5 40 77
69 93 27 49 53
39 62 68 16 89
82 13 28 65 35
5 42 90 12 51
15 85 64 86 25
87 22 88 37 98
39 10 46 56 49
62 25 93 75 34
42 89 27 36 18
32 54 59 26 6
51 19 47 85 95
33 39 73 29 79
15 27 0 79 69
13 73 25 19 43
30 8 46 34 58
4 86 66 74 18
83 33 92 11 47
45 25 22 14 4
83 3 65 17 85
91 26 5 19 87
66 89 29 49 64
52 20 58 93 53
30 64 52 14 34
63 16 97 9 15
2 72 65 45 17
47 98 77 23 0
50 20 38 60 26
46 67 84 66 55
7 32 31 75 19
71 85 37 12 52
39 27 8 81 44
89 47 42 16 58
74 99 81 86 89
92 20 7 58 30
63 96 25 45 2
97 50 94 33 87
38 6 51 21 62
52 27 20 32 19
17 80 70 92 96
49 44 62 60 94
40 28 86 4 7
38 91 3 77 29
8 28 89 99 6
46 54 34 95 3
88 60 29 91 10
42 13 62 94 76
56 52 72 85 59
85 50 42 5 91
67 7 21 6 56
14 8 70 10 78
77 80 57 29 96
17 23 73 16 38
59 61 47 43 13
7 93 11 72 83
0 96 67 27 2
42 5 41 65 94
40 34 33 50 3
25 79 52 11 94
73 14 7 99 19
92 40 2 28 45
55 34 87 24 96
36 16 66 78 35
11 27 90 50 55
68 84 63 57 89
35 14 29 77 24
92 81 7 1 85
99 64 20 2 49
20 66 85 88 57
49 17 78 1 80
18 24 11 31 65
30 34 45 99 19
69 40 94 2 58
49 2 55 54 61
48 19 34 5 83
80 52 67 24 96
51 91 20 45 68
87 79 59 9 3
47 12 71 88 74
28 5 79 58 26
93 67 62 86 23
66 13 96 46 17
94 59 19 54 15
21 89 98 54 53
49 44 79 10 93
64 24 25 9 56
57 70 55 65 23
14 36 31 13 4
62 60 30 89 94
88 19 59 41 75
25 45 74 17 47
5 16 76 33 58
53 68 65 39 67
55 2 76 32 26
37 25 5 27 24
61 88 33 45 46
20 96 51 42 49
66 3 15 11 36
60 21 80 9 96
91 39 24 28 13
52 11 34 41 82
66 85 72 38 76
69 25 67 64 81
67 75 42 79 74
36 26 85 30 25
50 19 3 33 28
12 95 54 71 91
0 17 87 92 40
51 85 12 86 40
28 36 35 50 97
55 16 20 14 73
7 5 4 68 22
47 3 67 93 2
48 33 92 35 31
73 40 71 75 62
19 54 49 20 38
23 37 9 11 10
80 63 39 52 56
59 70 61 65 62
42 73 99 39 66
67 8 93 30 97
53 37 51 55 11
48 26 94 44 63
99 5 21 8 13
0 35 25 19 6
93 83 40 98 43
84 18 66 50 62
86 94 32 52 11
55 15 85 39 4
95 83 27 46 45
19 47 61 9 66
82 32 72 77 16
50 96 14 60 35
66 13 84 74 97
85 67 20 43 34
95 0 3 58 38
48 69 93 28 7
91 98 56 94 35
11 15 73 51 77
13 7 22 53 10
2 40 98 79 50
71 83 49 45 56
0 1 68 99 24
34 84 37 31 93
55 7 18 15 65
80 40 29 44 36
51 26 99 59 2
57 45 67 1 41
79 90 56 76 58
78 70 20 26 48
87 82 46 59 98
51 81 91 52 44
21 86 68 64 7
12 26 73 30 87
99 58 45 25 38
95 97 27 22 37
98 72 10 6 79
4 61 20 85 67
9 26 5 68 2
97 4 31 11 69
75 64 0 6 17
25 95 89 59 38
16 99 27 53 10
89 71 42 70 90
12 38 8 63 23
95 77 0 29 43
81 93 56 2 34
46 44 55 13 41
72 21 50 1 81
67 44 88 90 82
98 19 30 48 85
66 20 79 13 28
29 62 38 74 89
1 62 20 28 0
59 52 11 6 74
32 16 50 34 76
79 91 31 24 56
26 37 87 53 57
47 79 55 45 9
63 2 1 60 75
18 39 97 7 44
33 29 91 31 23
50 80 32 49 71
41 52 85 2 83
28 27 49 14 44
20 1 34 19 17
62 59 68 86 82
89 31 37 95 80
67 70 59 17 91
3 60 12 6 93
99 44 34 9 21
31 26 61 20 25
23 15 43 53 42
52 19 16 91 35
65 29 4 2 48
90 44 77 38 60
49 62 53 47 74
61 15 30 28 70
14 97 34 88 55
50 28 80 36 64
93 40 60 90 22
29 77 1 26 56
33 9 4 67 68
561,579 -> 965,175
735,73 -> 316,73
981,566 -> 981,11
631,588 -> 631,910
919,964 -> 70,115
122,463 -> 261,602
502,248 -> 774,248
636,797 -> 797,958
444,815 -> 444,554
734,97 -> 734,210
871,692 -> 368,692
842,261 -> 606,261
332,43 -> 206,43
371,220 -> 18,573
594,782 -> 127,782
952,953 -> 72,73
13,143 -> 755,885
827,741 -> 827,168
65,84 -> 839,858
299,598 -> 299,588
478,76 -> 607,76
656,748 -> 61,153
566,447 -> 857,447
497,19 -> 310,206
354,721 -> 538,721
124,17 -> 124,339
105,595 -> 843,595
686,902 -> 919,669
683,183 -> 776,183
415,45 -> 415,942
16,852 -> 843,25
945,954 -> 23,32
935,174 -> 485,624
712,297 -> 792,297
495,90 -> 497,90
836,259 -> 836,988
12,59 -> 916,963
72,648 -> 72,185
625,400 -> 507,282
809,206 -> 809,538
472,909 -> 472,213
847,162 -> 189,162
178,233 -> 178,777
404,276 -> 404,516
943,178 -> 400,721
882,429 -> 882,920
12,976 -> 900,88
33,53 -> 958,53
104,37 -> 609,542
207,736 -> 800,143
331,454 -> 331,715
956,52 -> 26,982
189,544 -> 189,368
194,258 -> 451,258
75,383 -> 75,642
770,861 -> 915,716
300,330 -> 300,683
649,175 -> 344,175
948,25 -> 42,931
245,313 -> 748,816
677,126 -> 677,204
507,948 -> 507,88
343,229 -> 343,677
946,933 -> 472,459
830,403 -> 830,660
626,651 -> 626,213
828,932 -> 828,487
792,101 -> 216,101
870,111 -> 50,931
770,464 -> 290,944
264,700 -> 941,23
894,846 -> 630,846
19,40 -> 957,978
911,425 -> 393,425
26,594 -> 26,475
754,287 -> 754,302
105,483 -> 807,483
25,902 -> 684,243
300,164 -> 532,396
79,346 -> 79,423
649,234 -> 649,331
113,115 -> 962,964
251,50 -> 531,330
908,177 -> 908,817
905,106 -> 905,570
958,55 -> 41,972
985,984 -> 62,61
794,802 -> 328,802
984,273 -> 370,887
271,758 -> 237,792
443,534 -> 835,926
367,762 -> 367,521
527,737 -> 717,737
89,921 -> 89,299
521,279 -> 108,279
810,344 -> 760,394
292,944 -> 292,941
265,471 -> 265,949
923,378 -> 415,886
125,656 -> 434,656
51,460 -> 51,542
297,178 -> 297,587
432,122 -> 241,122
916,855 -> 451,390
48,838 -> 636,838
802,659 -> 784,641
316,961 -> 417,961
342,675 -> 568,675
345,60 -> 352,60
495,595 -> 284,806
111,975 -> 815,271
315,239 -> 315,333
14,16 -> 930,932
380,373 -> 380,346
212,141 -> 212,691
415,555 -> 651,319
497,565 -> 96,164
902,451 -> 735,451
118,751 -> 521,751
923,680 -> 613,370
641,897 -> 233,489
804,447 -> 259,447
556,751 -> 968,751
409,638 -> 409,65
512,50 -> 432,130
28,25 -> 988,985
563,888 -> 563,502
912,691 -> 950,691
592,934 -> 592,433
465,886 -> 408,886
928,547 -> 671,290
486,953 -> 496,943
942,943 -> 42,43
672,759 -> 266,759
587,195 -> 763,371
95,354 -> 687,946
890,280 -> 734,124
945,906 -> 945,168
306,952 -> 306,257
143,160 -> 810,827
988,407 -> 167,407
274,472 -> 817,472
252,113 -> 430,291
294,767 -> 176,767
456,142 -> 423,142
908,107 -> 176,839
255,278 -> 447,86
100,44 -> 969,913
899,184 -> 899,986
872,877 -> 47,52
122,786 -> 228,786
132,777 -> 312,777
242,86 -> 36,86
726,671 -> 690,635
386,859 -> 790,455
468,62 -> 636,62
920,869 -> 920,790
610,66 -> 633,43
428,962 -> 428,717
935,881 -> 278,224
314,204 -> 458,204
906,515 -> 712,515
332,223 -> 744,223
707,802 -> 842,802
775,36 -> 946,207
906,206 -> 142,970
534,312 -> 534,622
26,687 -> 26,417
758,258 -> 688,188
830,591 -> 830,286
856,182 -> 924,182
78,755 -> 78,880
157,726 -> 157,904
316,30 -> 752,30
958,977 -> 10,29
831,813 -> 284,813
472,843 -> 989,326
133,99 -> 133,537
161,540 -> 846,540
176,739 -> 78,739
28,33 -> 969,974
65,160 -> 879,974
355,943 -> 355,685
893,512 -> 225,512
789,565 -> 789,81
253,832 -> 943,832
372,716 -> 372,605
781,293 -> 702,293
469,497 -> 469,149
692,499 -> 933,258
477,548 -> 477,849
131,894 -> 131,483
934,765 -> 13,765
830,55 -> 436,449
615,496 -> 531,412
78,634 -> 78,115
205,586 -> 205,661
871,742 -> 871,590
218,223 -> 218,741
56,897 -> 872,81
30,886 -> 728,188
369,877 -> 369,963
202,55 -> 930,783
251,131 -> 251,749
498,313 -> 498,126
688,876 -> 188,876
147,968 -> 607,508
400,693 -> 235,693
206,853 -> 206,211
401,158 -> 187,158
35,957 -> 973,19
517,822 -> 517,282
836,492 -> 433,895
751,114 -> 100,114
80,359 -> 710,359
302,871 -> 812,871
853,159 -> 853,548
351,663 -> 451,763
895,260 -> 307,848
369,455 -> 812,455
936,594 -> 393,51
55,696 -> 972,696
422,804 -> 192,804
110,893 -> 120,883
747,645 -> 747,181
636,344 -> 636,88
15,949 -> 543,421
985,948 -> 51,14
164,435 -> 164,27
30,966 -> 965,31
600,472 -> 985,472
119,161 -> 91,161
180,521 -> 180,802
98,70 -> 449,70
157,190 -> 613,190
816,501 -> 338,23
387,219 -> 387,75
115,579 -> 115,734
26,153 -> 26,450
733,783 -> 462,783
19,893 -> 759,893
646,726 -> 286,726
631,139 -> 631,664
490,668 -> 490,231
282,958 -> 282,816
338,55 -> 898,55
891,420 -> 443,420
222,917 -> 222,759
302,430 -> 465,430
946,49 -> 946,753
101,971 -> 879,193
329,122 -> 888,122
524,714 -> 154,344
89,769 -> 552,306
749,680 -> 749,536
161,510 -> 161,317
143,608 -> 543,608
677,526 -> 658,526
348,956 -> 512,956
851,973 -> 358,480
850,247 -> 56,247
284,274 -> 381,274
855,944 -> 101,190
338,102 -> 467,102
225,875 -> 225,303
120,944 -> 945,119
485,386 -> 305,386
321,866 -> 627,866
44,207 -> 44,244
514,763 -> 514,578
617,930 -> 617,371
963,838 -> 451,326
813,904 -> 174,265
901,983 -> 512,594
979,929 -> 527,477
533,383 -> 59,857
871,724 -> 828,767
174,133 -> 174,75
686,911 -> 15,911
361,406 -> 440,327
759,284 -> 275,284
231,431 -> 203,431
759,673 -> 839,673
914,897 -> 914,937
598,643 -> 598,722
697,297 -> 697,55
735,918 -> 735,81
375,538 -> 375,403
868,86 -> 170,784
390,142 -> 390,553
569,564 -> 569,800
514,276 -> 717,73
756,768 -> 182,768
349,428 -> 349,364
370,386 -> 370,621
191,224 -> 191,447
672,983 -> 209,983
281,854 -> 872,854
898,959 -> 898,207
961,597 -> 561,197
965,837 -> 338,210
120,675 -> 914,675
401,661 -> 401,167
706,536 -> 706,598
856,337 -> 283,910
980,535 -> 156,535
941,888 -> 179,126
585,47 -> 933,395
481,435 -> 481,818
989,978 -> 45,34
693,332 -> 693,528
863,605 -> 507,961
586,429 -> 252,429
37,61 -> 962,986
952,26 -> 16,962
926,492 -> 863,492
661,110 -> 279,110
524,879 -> 176,879
298,424 -> 858,984
498,627 -> 498,963
468,608 -> 256,820
61,491 -> 472,491
38,922 -> 938,22
361,938 -> 361,46
567,981 -> 567,973
399,575 -> 902,72
618,740 -> 818,540
79,115 -> 929,965
612,972 -> 612,698
217,626 -> 474,369
961,593 -> 961,70
287,450 -> 287,676
703,45 -> 871,45
756,778 -> 410,778
960,970 -> 42,52
254,513 -> 554,813
620,339 -> 601,320
650,344 -> 650,33
597,349 -> 597,491
761,106 -> 891,236
323,846 -> 883,846
678,190 -> 134,190
400,848 -> 400,271
198,68 -> 463,68
522,805 -> 522,445
979,134 -> 719,134
584,493 -> 584,471
635,10 -> 635,768
867,795 -> 31,795
157,824 -> 939,42
354,381 -> 653,381
45,628 -> 45,860
959,870 -> 808,719
587,810 -> 291,810
248,34 -> 83,199
656,505 -> 656,388
966,90 -> 966,934
957,834 -> 267,144
690,367 -> 447,367
153,948 -> 153,510
467,260 -> 467,332
69,43 -> 931,905
913,92 -> 913,827
226,504 -> 226,615
21,737 -> 21,819
391,289 -> 391,341
566,639 -> 723,639
160,824 -> 167,824
77,69 -> 379,371
756,864 -> 756,960
315,569 -> 927,569
964,864 -> 964,167
136,277 -> 136,184
524,450 -> 898,450
971,903 -> 222,903
962,958 -> 70,66
525,570 -> 45,90
164,352 -> 164,433
703,61 -> 668,61
289,136 -> 768,136
50,65 -> 861,876
676,199 -> 676,411
294,370 -> 56,132
299,840 -> 620,840
845,776 -> 845,66
61,18 -> 909,866
738,670 -> 738,438
974,618 -> 974,169
669,800 -> 607,800
935,427 -> 537,427
441,898 -> 441,462
490,768 -> 490,239
275,788 -> 947,116
650,412 -> 493,255
382,89 -> 950,89
865,194 -> 865,266
977,677 -> 459,677
128,18 -> 985,875
199,646 -> 199,611
666,149 -> 666,504
129,539 -> 129,266
332,364 -> 332,211
619,132 -> 619,580
426,69 -> 426,236
123,334 -> 22,334
792,57 -> 449,57
33,976 -> 987,22
221,614 -> 809,614
245,379 -> 280,379
895,238 -> 895,500
957,423 -> 119,423
917,50 -> 346,621
183,263 -> 708,263
452,174 -> 452,216
404,681 -> 287,798
931,54 -> 474,54
815,264 -> 151,928
736,507 -> 295,66
200,160 -> 901,861
709,975 -> 100,366
126,468 -> 393,201
822,627 -> 287,92
101,285 -> 176,285
250,581 -> 250,799
257,446 -> 257,927
436,423 -> 640,219
468,229 -> 987,748
394,245 -> 501,245
37,931 -> 684,931
123,54 -> 123,453
75,364 -> 758,364
256,62 -> 143,62
933,299 -> 933,410
313,887 -> 313,34
453,833 -> 457,833
614,87 -> 614,816
48,113 -> 48,646
977,571 -> 977,967
982,989 -> 32,39
773,749 -> 239,215
983,989 -> 218,224
885,606 -> 169,606
63,53 -> 63,29
96,870 -> 820,870
544,895 -> 389,740
61,246 -> 296,246
812,82 -> 53,841
749,399 -> 749,935
882,168 -> 274,168
566,673 -> 499,606
572,558 -> 806,792
923,79 -> 923,844
875,416 -> 875,112
393,18 -> 393,149
389,844 -> 147,844
207,157 -> 207,949
467,644 -> 728,644
36,29 -> 587,29
448,370 -> 448,247
43,283 -> 43,122
709,837 -> 709,265
294,273 -> 98,273
625,869 -> 26,270
156,26 -> 145,26
393,544 -> 393,456
708,536 -> 64,536
324,519 -> 324,950
138,788 -> 533,788
117,818 -> 254,681
953,766 -> 306,119
669,325 -> 669,940
421,416 -> 715,416
886,101 -> 886,371
786,656 -> 786,169
123,641 -> 622,142
658,504 -> 985,177
440,505 -> 74,139
300,616 -> 300,473
265,729 -> 983,11
501,396 -> 274,396
877,123 -> 113,887
544,78 -> 544,604
287,944 -> 287,391
766,854 -> 97,185
959,49 -> 127,881
715,727 -> 715,647
339,557 -> 339,610
19,133 -> 87,133
872,94 -> 932,94
966,935 -> 95,64
137,942 -> 918,161
162,718 -> 598,282
256,18 -> 256,47
597,658 -> 314,941
817,685 -> 137,685
20,14 -> 988,982
970,916 -> 100,46
672,152 -> 672,842
468,825 -> 468,911
673,731 -> 267,325
1,3,1,5,5,1,1,1,5,1,1,1,3,1,1,4,3,1,1,2,2,4,2,1,3,3,2,4,4,4,1,3,1,1,4,3,1,5,5,1,1,3,4,2,1,5,3,4,5,5,2,5,5,1,5,5,2,1,5,1,1,2,1,1,1,4,4,1,3,3,1,5,4,4,3,4,3,3,1,1,3,4,1,5,5,2,5,2,2,4,1,2,5,2,1,2,5,4,1,1,1,1,1,4,1,1,3,1,5,2,5,1,3,1,5,3,3,2,2,1,5,1,1,1,2,1,1,2,1,1,2,1,5,3,5,2,5,2,2,2,1,1,1,5,5,2,2,1,1,3,4,1,1,3,1,3,5,1,4,1,4,1,3,1,4,1,1,1,1,2,1,4,5,4,5,5,2,1,3,1,4,2,5,1,1,3,5,2,1,2,2,5,1,2,2,4,5,2,1,1,1,1,2,2,3,1,5,5,5,3,2,4,2,4,1,5,3,1,4,4,2,4,2,2,4,4,4,4,1,3,4,3,2,1,3,5,3,1,5,5,4,1,5,1,2,4,2,5,4,1,3,3,1,4,1,3,3,3,1,3,1,1,1,1,4,1,2,3,1,3,3,5,2,3,1,1,1,5,5,4,1,2,3,1,3,1,1,4,1,3,2,2,1,1,1,3,4,3,1,3
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,121,295,1276,124,523,395,987,355,1668,754,139,217,433,1,836,467,1384,66,390,1278,113,114,355,434,396,1050,1552,612,793,532,26,1340,150,455,83,320,587,701,429,596,154,4,1247,55,1376,507,205,1760,774,980,485,10,161,524,213,156,36,56,550,429,337,76,53,276,475,1220,1539,10,53,87,32,1280,757,447,948,983,504,998,1220,27,6,1410,118,172,467,53,351,813,304,708,455,1227,1081,161,1077,36,196,289,371,1354,278,367,992,1,1002,428,535,124,341,318,455,783,916,139,559,71,86,248,71,26,237,99,1064,387,305,454,21,85,202,1156,1410,46,125,217,651,341,15,858,39,248,1677,1792,7,866,781,479,277,1331,92,297,573,112,778,772,388,384,34,335,755,442,1157,537,44,1050,1302,375,136,1017,824,188,362,1359,541,598,43,14,66,1168,43,129,85,71,176,182,1252,336,451,1083,408,761,1327,129,1055,136,770,1489,463,66,685,864,857,150,40,72,807,1017,253,38,659,843,1125,660,891,674,635,113,474,1087,545,196,231,200,865,446,269,739,66,1074,590,5,60,717,170,109,133,243,16,97,393,454,49,597,1355,58,1665,1432,41,251,648,742,87,1172,19,1445,243,728,246,764,206,773,620,866,500,127,91,773,521,47,53,150,828,408,1096,178,567,1356,132,792,6,392,205,894,362,5,554,1287,706,46,800,8,114,152,669,367,640,776,1274,321,1853,308,545,597,28,999,352,29,810,86,106,602,106,121,1467,252,1450,322,267,779,722,57,0,367,39,28,119,99,655,30,723,254,175,921,158,27,879,864,979,436,188,247,96,1109,1033,768,53,175,228,621,134,398,349,270,666,603,818,88,858,310,283,370,517,636,689,114,186,156,306,1044,296,251,1102,1921,34,804,314,298,262,1240,86,227,385,145,54,43,229,15,1034,200,408,1408,13,725,180,597,168,152,961,200,560,288,479,90,157,135,1051,412,1073,132,635,117,597,1448,445,95,278,327,179,1029,18,257,1406,159,1368,359,23,427,225,120,1763,1230,733,110,40,195,870,509,407,881,826,209,106,130,1227,848,336,430,1490,326,377,461,197,70,574,841,497,141,15,83,347,312,555,756,61,1041,171,723,395,632,9,699,365,353,122,620,144,229,12,361,726,0,254,275,28,197,76,387,510,65,771,192,11,345,1317,37,415,286,1,610,378,82,131,94,65,444,455,1146,1319,8,167,79,575,190,351,53,251,352,366,1085,1122,519,5,230,685,388,1476,516,107,365,380,642,1316,400,72,168,178,112,850,264,143,29,605,149,4,216,1327,667,783,40,64,446,580,1280,47,1,322,592,6,560,648,49,116,418,236,620,166,1198,801,362,278,230,417,162,55,535,245,360,73,13,459,505,124,125,325,1126,132,193,374,320,569,842,74,902,210,1199,346,593,912,110,20,482,201,564,248,6,653,208,401,126,248,300,817,581,11,27,924,400,1118,55,1445,6,1024,770,707,510,166,0,435,1188,43,278,338,84,829,1603,55,1255,155,592,420,513,928,1163,51,342,15,499,357,431,1701,54,1521,214,831,199,43,433,1326,1120,803,1154,72,40,181,124,424,464,825,446,500,149,559,355,495,997,87,322,335,701,64,13,978,373,157,1376,1640,255,727,902,86,1230,1517,98,860,797,210,178,1195,493,1007,305,1219,1255,1078,460,712,118,1252,1029,1423,116,41,907,304,651,414,881,162,151,464,265,430,217,1353,315,122,1020,540,8,591,3,50,401,324,1212,143,869,608,706,128,202,25,1118,780,267,305,685,60,92,980,868,1458,446,635,374,565,741,474,367,723,119,70,683,471,651,155,23,158,91,287,8,516,560,434,236,572,320,16,100,140,171,380,672,699,731,621,1346,531,376,182,484,2,198,489,382,388,1200,58,4,885,1575,1320,540,32,1293,217,281,18,212,1240,634,29,153,258,472,501,743,109,55,577,1518,173,308,369,1365,587,260,98,1038,6,1187,278,582,115,1539,282,224,40,306,1447,942,1732,131,320,243,14,559,991,308,7,111,1072,566,42,103,69,1857,1556,229,300,540,183,243,1312,546,19,1287,1597,421,391,169,520,267,591,195,1076,590,917,1018,556,410,498,488,352,590,814,23,299,1254,123,1228,722,745,96,644,288,252,253,1010,26,255,568,783,147,57,63,696,619,1362,1575,1525,696,80,746,294,447,183,320,176,544,278,1757,204,362,13,412,173,438,285,468,3,47,1020,347,640,1442
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment