import java.io.File
import java.nio.charset.StandardCharsets.UTF_8

object Day13 {

    data class Coord(val x: Int, val y: Int) {
        constructor(coord: Pair<Int, Int>) : this(coord.first, coord.second)
    }

    enum class Direction {
        x {
            override fun extract(c: Coord) = c.x
            override fun adjust(c: Coord, value: Int) = Coord((c.x - (c.x - value) * 2) to c.y)
        },
        y {
            override fun extract(c: Coord) = c.y
            override fun adjust(c: Coord, value: Int) = Coord(c.x to (c.y - (c.y - value) * 2))
        };

        abstract fun extract(coord: Coord): Int
        abstract fun adjust(coord: Coord, value: Int): Coord
    }

    private fun toCoordinates(line: String) = line
        .split(",".toRegex())
        .map(Integer::parseInt)
        .let { Coord(it[0] to it[1]) }

    private fun toInstructions(line: String): Pair<Direction, Int> {
        val (axis, value) = "fold along (.)=(.+)".toRegex().find(line)!!.destructured
        return Direction.valueOf(axis) to Integer.parseInt(value)
    }

    private fun fold(instruction: Pair<Direction, Int>, coordinates: Collection<Coord>): Set<Coord> {
        val (top, bottom) = coordinates.partition { instruction.first.extract(it) > instruction.second }
        val adjusted = top.map { instruction.first.adjust(it, instruction.second) }
        return bottom.toMutableSet() + adjusted
    }

    private fun draw(coordinates: Collection<Coord>) {
        println("\n")
        println("Contains: ${coordinates.size}")
        val maxCols = coordinates.maxOf { it.x }
        val maxRows = coordinates.maxOf { it.y }

        (0..maxRows).forEach { row ->
            (0..maxCols).forEach { col ->
                print(if (coordinates.contains(Coord(col, row))) "#" else ".")
            }
            println()
        }
    }

    object Part1 {

        fun run() {
            val (instr, coords) = File("day13/input-real.txt")
                .readLines(UTF_8)
                .partition { it.startsWith("fold along") }

            val coordinates = coords.filter { it.isNotBlank() }.map(::toCoordinates)
            val instructions = instr.map(::toInstructions)
            val first = fold(instructions.first(), coordinates)

            println(first.size)
        }
    }

    object Part2 {

        fun run() {
            val (instr, coords) = File("day13/input-real.txt")
                .readLines(UTF_8)
                .partition { it.startsWith("fold along") }

            val coordinates: Collection<Coord> = coords.filter { it.isNotBlank() }.map(::toCoordinates)
            val instructions = instr.map(::toInstructions)

            val result = instructions.fold(coordinates) { acc, i  -> fold(i, acc) }

            draw(result)
            // L R G P R E C B
        }
    }
}

fun main() {
    Day13.Part1.run()
    Day13.Part2.run()
}

Compiled from "Day13.kt"
public final class Day13 {
  public static final Day13 INSTANCE;

  private Day13();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  private final Day13$Coord toCoordinates(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #14                 // class java/lang/CharSequence
       4: astore_2
       5: new           #16                 // class kotlin/text/Regex
       8: dup
       9: ldc           #18                 // String ,
      11: invokespecial #21                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      14: astore_3
      15: iconst_0
      16: istore        4
      18: aload_3
      19: aload_2
      20: iload         4
      22: invokevirtual #25                 // Method kotlin/text/Regex.split:(Ljava/lang/CharSequence;I)Ljava/util/List;
      25: checkcast     #27                 // class java/lang/Iterable
      28: astore_2
      29: nop
      30: iconst_0
      31: istore_3
      32: aload_2
      33: astore        4
      35: new           #29                 // class java/util/ArrayList
      38: dup
      39: aload_2
      40: bipush        10
      42: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      45: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      48: checkcast     #40                 // class java/util/Collection
      51: astore        5
      53: iconst_0
      54: istore        6
      56: aload         4
      58: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        7
      65: aload         7
      67: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          118
      75: aload         7
      77: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        8
      84: aload         5
      86: aload         8
      88: checkcast     #56                 // class java/lang/String
      91: astore        9
      93: astore        11
      95: iconst_0
      96: istore        10
      98: aload         9
     100: invokestatic  #62                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     103: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aload         11
     108: swap
     109: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          65
     118: aload         5
     120: checkcast     #72                 // class java/util/List
     123: nop
     124: astore_3
     125: iconst_0
     126: istore        4
     128: new           #74                 // class Day13$Coord
     131: dup
     132: aload_3
     133: iconst_0
     134: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     139: aload_3
     140: iconst_1
     141: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     146: invokestatic  #84                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     149: invokespecial #87                 // Method Day13$Coord."<init>":(Lkotlin/Pair;)V
     152: nop
     153: areturn

  private final kotlin.Pair<Day13$Direction, java.lang.Integer> toInstructions(java.lang.String);
    Code:
       0: new           #16                 // class kotlin/text/Regex
       3: dup
       4: ldc           #109                // String fold along (.)=(.+)
       6: invokespecial #21                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: aload_1
      10: checkcast     #14                 // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #113                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      19: dup
      20: invokestatic  #119                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      23: invokeinterface #125,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      28: astore_2
      29: aload_2
      30: invokevirtual #131                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      33: invokeinterface #135,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      38: iconst_1
      39: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      44: checkcast     #56                 // class java/lang/String
      47: astore_3
      48: aload_2
      49: invokevirtual #131                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      52: invokeinterface #135,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      57: iconst_2
      58: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      63: checkcast     #56                 // class java/lang/String
      66: astore        4
      68: aload_3
      69: invokestatic  #140                // Method Day13$Direction.valueOf:(Ljava/lang/String;)LDay13$Direction;
      72: aload         4
      74: invokestatic  #62                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      77: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: invokestatic  #84                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      83: areturn

  private final java.util.Set<Day13$Coord> fold(kotlin.Pair<? extends Day13$Direction, java.lang.Integer>, java.util.Collection<Day13$Coord>);
    Code:
       0: aload_2
       1: checkcast     #27                 // class java/lang/Iterable
       4: astore        4
       6: iconst_0
       7: istore        5
       9: new           #29                 // class java/util/ArrayList
      12: dup
      13: invokespecial #146                // Method java/util/ArrayList."<init>":()V
      16: astore        6
      18: new           #29                 // class java/util/ArrayList
      21: dup
      22: invokespecial #146                // Method java/util/ArrayList."<init>":()V
      25: astore        7
      27: aload         4
      29: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        8
      36: aload         8
      38: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          119
      46: aload         8
      48: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        9
      55: aload         9
      57: checkcast     #74                 // class Day13$Coord
      60: astore        10
      62: iconst_0
      63: istore        11
      65: aload_1
      66: invokevirtual #151                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      69: checkcast     #137                // class Day13$Direction
      72: aload         10
      74: invokevirtual #155                // Method Day13$Direction.extract:(LDay13$Coord;)I
      77: aload_1
      78: invokevirtual #158                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      81: checkcast     #160                // class java/lang/Number
      84: invokevirtual #164                // Method java/lang/Number.intValue:()I
      87: if_icmple     94
      90: iconst_1
      91: goto          95
      94: iconst_0
      95: ifeq          108
      98: aload         6
     100: aload         9
     102: invokevirtual #165                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     105: goto          115
     108: aload         7
     110: aload         9
     112: invokevirtual #165                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          36
     119: new           #148                // class kotlin/Pair
     122: dup
     123: aload         6
     125: aload         7
     127: invokespecial #168                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     130: astore_3
     131: aload_3
     132: invokevirtual #171                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     135: checkcast     #72                 // class java/util/List
     138: astore        4
     140: aload_3
     141: invokevirtual #174                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     144: checkcast     #72                 // class java/util/List
     147: astore        5
     149: aload         4
     151: checkcast     #27                 // class java/lang/Iterable
     154: astore        7
     156: iconst_0
     157: istore        8
     159: aload         7
     161: astore        9
     163: new           #29                 // class java/util/ArrayList
     166: dup
     167: aload         7
     169: bipush        10
     171: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     174: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     177: checkcast     #40                 // class java/util/Collection
     180: astore        10
     182: iconst_0
     183: istore        11
     185: aload         9
     187: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     192: astore        12
     194: aload         12
     196: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     201: ifeq          261
     204: aload         12
     206: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     211: astore        13
     213: aload         10
     215: aload         13
     217: checkcast     #74                 // class Day13$Coord
     220: astore        14
     222: astore        16
     224: iconst_0
     225: istore        15
     227: aload_1
     228: invokevirtual #151                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     231: checkcast     #137                // class Day13$Direction
     234: aload         14
     236: aload_1
     237: invokevirtual #158                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     240: checkcast     #160                // class java/lang/Number
     243: invokevirtual #164                // Method java/lang/Number.intValue:()I
     246: invokevirtual #178                // Method Day13$Direction.adjust:(LDay13$Coord;I)LDay13$Coord;
     249: aload         16
     251: swap
     252: invokeinterface #70,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     257: pop
     258: goto          194
     261: aload         10
     263: checkcast     #72                 // class java/util/List
     266: nop
     267: astore        6
     269: aload         5
     271: checkcast     #27                 // class java/lang/Iterable
     274: invokestatic  #182                // Method kotlin/collections/CollectionsKt.toMutableSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     277: aload         6
     279: checkcast     #27                 // class java/lang/Iterable
     282: invokestatic  #188                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     285: areturn

  private final void draw(java.util.Collection<Day13$Coord>);
    Code:
       0: ldc           #208                // String \n
       2: getstatic     #214                // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #219                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
       9: new           #221                // class java/lang/StringBuilder
      12: dup
      13: invokespecial #222                // Method java/lang/StringBuilder."<init>":()V
      16: ldc           #224                // String Contains:
      18: invokevirtual #228                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      21: aload_1
      22: invokeinterface #231,  1          // InterfaceMethod java/util/Collection.size:()I
      27: invokevirtual #234                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      30: invokevirtual #238                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      33: getstatic     #214                // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #219                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: aload_1
      41: checkcast     #27                 // class java/lang/Iterable
      44: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        4
      51: aload         4
      53: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifne          69
      61: new           #240                // class java/util/NoSuchElementException
      64: dup
      65: invokespecial #241                // Method java/util/NoSuchElementException."<init>":()V
      68: athrow
      69: aload         4
      71: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      76: checkcast     #74                 // class Day13$Coord
      79: astore        5
      81: iconst_0
      82: istore        6
      84: aload         5
      86: invokevirtual #244                // Method Day13$Coord.getX:()I
      89: istore        5
      91: aload         4
      93: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      98: ifeq          137
     101: aload         4
     103: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     108: checkcast     #74                 // class Day13$Coord
     111: astore        6
     113: iconst_0
     114: istore        7
     116: aload         6
     118: invokevirtual #244                // Method Day13$Coord.getX:()I
     121: istore        6
     123: iload         5
     125: iload         6
     127: if_icmpge     91
     130: iload         6
     132: istore        5
     134: goto          91
     137: iload         5
     139: istore_2
     140: aload_1
     141: checkcast     #27                 // class java/lang/Iterable
     144: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     149: astore        5
     151: aload         5
     153: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     158: ifne          169
     161: new           #240                // class java/util/NoSuchElementException
     164: dup
     165: invokespecial #241                // Method java/util/NoSuchElementException."<init>":()V
     168: athrow
     169: aload         5
     171: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     176: checkcast     #74                 // class Day13$Coord
     179: astore        6
     181: iconst_0
     182: istore        7
     184: aload         6
     186: invokevirtual #247                // Method Day13$Coord.getY:()I
     189: istore        6
     191: aload         5
     193: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     198: ifeq          237
     201: aload         5
     203: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     208: checkcast     #74                 // class Day13$Coord
     211: astore        7
     213: iconst_0
     214: istore        8
     216: aload         7
     218: invokevirtual #247                // Method Day13$Coord.getY:()I
     221: istore        7
     223: iload         6
     225: iload         7
     227: if_icmpge     191
     230: iload         7
     232: istore        6
     234: goto          191
     237: iload         6
     239: istore_3
     240: new           #249                // class kotlin/ranges/IntRange
     243: dup
     244: iconst_0
     245: iload_3
     246: invokespecial #252                // Method kotlin/ranges/IntRange."<init>":(II)V
     249: checkcast     #27                 // class java/lang/Iterable
     252: astore        4
     254: iconst_0
     255: istore        5
     257: aload         4
     259: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     264: astore        6
     266: aload         6
     268: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     273: ifeq          399
     276: aload         6
     278: checkcast     #254                // class kotlin/collections/IntIterator
     281: invokevirtual #257                // Method kotlin/collections/IntIterator.nextInt:()I
     284: istore        7
     286: iload         7
     288: istore        8
     290: iconst_0
     291: istore        9
     293: new           #249                // class kotlin/ranges/IntRange
     296: dup
     297: iconst_0
     298: iload_2
     299: invokespecial #252                // Method kotlin/ranges/IntRange."<init>":(II)V
     302: checkcast     #27                 // class java/lang/Iterable
     305: astore        10
     307: iconst_0
     308: istore        11
     310: aload         10
     312: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     317: astore        12
     319: aload         12
     321: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     326: ifeq          387
     329: aload         12
     331: checkcast     #254                // class kotlin/collections/IntIterator
     334: invokevirtual #257                // Method kotlin/collections/IntIterator.nextInt:()I
     337: istore        13
     339: iload         13
     341: istore        14
     343: iconst_0
     344: istore        15
     346: aload_1
     347: new           #74                 // class Day13$Coord
     350: dup
     351: iload         14
     353: iload         8
     355: invokespecial #258                // Method Day13$Coord."<init>":(II)V
     358: invokeinterface #261,  2          // InterfaceMethod java/util/Collection.contains:(Ljava/lang/Object;)Z
     363: ifeq          372
     366: ldc_w         #263                // String #
     369: goto          375
     372: ldc_w         #265                // String .
     375: getstatic     #214                // Field java/lang/System.out:Ljava/io/PrintStream;
     378: swap
     379: invokevirtual #268                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     382: nop
     383: nop
     384: goto          319
     387: nop
     388: getstatic     #214                // Field java/lang/System.out:Ljava/io/PrintStream;
     391: invokevirtual #270                // Method java/io/PrintStream.println:()V
     394: nop
     395: nop
     396: goto          266
     399: nop
     400: return

  public static final java.util.Set access$fold(Day13, kotlin.Pair, java.util.Collection);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokespecial #284                // Method fold:(Lkotlin/Pair;Ljava/util/Collection;)Ljava/util/Set;
       6: areturn

  public static final Day13$Coord access$toCoordinates(Day13, java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #289                // Method toCoordinates:(Ljava/lang/String;)LDay13$Coord;
       5: areturn

  public static final kotlin.Pair access$toInstructions(Day13, java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #293                // Method toInstructions:(Ljava/lang/String;)Lkotlin/Pair;
       5: areturn

  public static final void access$draw(Day13, java.util.Collection);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #297                // Method draw:(Ljava/util/Collection;)V
       5: return

  static {};
    Code:
       0: new           #2                  // class Day13
       3: dup
       4: invokespecial #299                // Method "<init>":()V
       7: putstatic     #302                // Field INSTANCE:LDay13;
      10: return
}

Compiled from "Day13.kt"
public final class Day13Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Day13$Part1.INSTANCE:LDay13$Part1;
       3: invokevirtual #15                 // Method Day13$Part1.run:()V
       6: getstatic     #20                 // Field Day13$Part2.INSTANCE:LDay13$Part2;
       9: invokevirtual #21                 // Method Day13$Part2.run:()V
      12: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #24                 // Method main:()V
       3: return
}

Compiled from "Day13.kt"
final class Day13$Direction$y extends Day13$Direction {
  Day13$Direction$y();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: aconst_null
       4: invokespecial #10                 // Method Day13$Direction."<init>":(Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return

  public int extract(Day13$Coord);
    Code:
       0: aload_1
       1: ldc           #21                 // String c
       3: invokestatic  #27                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #33                 // Method Day13$Coord.getY:()I
      10: ireturn

  public Day13$Coord adjust(Day13$Coord, int);
    Code:
       0: aload_1
       1: ldc           #21                 // String c
       3: invokestatic  #27                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #29                 // class Day13$Coord
       9: dup
      10: aload_1
      11: invokevirtual #39                 // Method Day13$Coord.getX:()I
      14: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: aload_1
      18: invokevirtual #33                 // Method Day13$Coord.getY:()I
      21: aload_1
      22: invokevirtual #33                 // Method Day13$Coord.getY:()I
      25: iload_2
      26: isub
      27: iconst_2
      28: imul
      29: isub
      30: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: invokestatic  #51                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: invokespecial #54                 // Method Day13$Coord."<init>":(Lkotlin/Pair;)V
      39: areturn
}

Compiled from "Day13.kt"
public final class Day13$Coord {
  private final int x;

  private final int y;

  public Day13$Coord(int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field x:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field y:I
      14: return

  public final int getX();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: ireturn

  public final int getY();
    Code:
       0: aload_0
       1: getfield      #16                 // Field y:I
       4: ireturn

  public Day13$Coord(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #26                 // String coord
       3: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokevirtual #38                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      11: checkcast     #40                 // class java/lang/Number
      14: invokevirtual #43                 // Method java/lang/Number.intValue:()I
      17: aload_1
      18: invokevirtual #46                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      21: checkcast     #40                 // class java/lang/Number
      24: invokevirtual #43                 // Method java/lang/Number.intValue:()I
      27: invokespecial #48                 // Method "<init>":(II)V
      30: return

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field y:I
       4: ireturn

  public final Day13$Coord copy(int, int);
    Code:
       0: new           #2                  // class Day13$Coord
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #48                 // Method "<init>":(II)V
       9: areturn

  public static Day13$Coord copy$default(Day13$Coord, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #13                 // Field x:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #16                 // Field y:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #57                 // Method copy:(II)LDay13$Coord;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #61                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #64                 // String Coord(x=
       9: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field x:I
      16: invokevirtual #71                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #73                 // String , y=
      21: invokevirtual #68                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field y:I
      28: invokevirtual #71                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #76                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: invokestatic  #84                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field y:I
      16: invokestatic  #84                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Day13$Coord
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day13$Coord
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field x:I
      25: aload_2
      26: getfield      #13                 // Field x:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field y:I
      38: aload_2
      39: getfield      #16                 // Field y:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "Day13.kt"
public final class Day13$Part2 {
  public static final Day13$Part2 INSTANCE;

  private Day13$Part2();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void run();
    Code:
       0: new           #13                 // class java/io/File
       3: dup
       4: ldc           #15                 // String day13/input-real.txt
       6: invokespecial #18                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: getstatic     #24                 // Field java/nio/charset/StandardCharsets.UTF_8:Ljava/nio/charset/Charset;
      12: dup
      13: ldc           #25                 // String UTF_8
      15: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: invokestatic  #37                 // Method kotlin/io/FilesKt.readLines:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/util/List;
      21: checkcast     #39                 // class java/lang/Iterable
      24: astore_2
      25: nop
      26: iconst_0
      27: istore_3
      28: new           #41                 // class java/util/ArrayList
      31: dup
      32: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
      35: astore        4
      37: new           #41                 // class java/util/ArrayList
      40: dup
      41: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
      44: astore        5
      46: aload_2
      47: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        6
      54: aload         6
      56: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          117
      64: aload         6
      66: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        7
      73: aload         7
      75: checkcast     #58                 // class java/lang/String
      78: astore        8
      80: iconst_0
      81: istore        9
      83: aload         8
      85: ldc           #60                 // String fold along
      87: iconst_0
      88: iconst_2
      89: aconst_null
      90: invokestatic  #66                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      93: ifeq          106
      96: aload         4
      98: aload         7
     100: invokevirtual #70                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     103: goto          113
     106: aload         5
     108: aload         7
     110: invokevirtual #70                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     113: pop
     114: goto          54
     117: new           #72                 // class kotlin/Pair
     120: dup
     121: aload         4
     123: aload         5
     125: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     128: astore_1
     129: aload_1
     130: invokevirtual #78                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     133: checkcast     #80                 // class java/util/List
     136: astore_2
     137: aload_1
     138: invokevirtual #83                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     141: checkcast     #80                 // class java/util/List
     144: astore_3
     145: aload_3
     146: checkcast     #39                 // class java/lang/Iterable
     149: astore        5
     151: iconst_0
     152: istore        6
     154: aload         5
     156: astore        7
     158: new           #41                 // class java/util/ArrayList
     161: dup
     162: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
     165: checkcast     #85                 // class java/util/Collection
     168: astore        8
     170: iconst_0
     171: istore        9
     173: aload         7
     175: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        10
     182: aload         10
     184: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          244
     192: aload         10
     194: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        11
     201: aload         11
     203: checkcast     #58                 // class java/lang/String
     206: astore        12
     208: iconst_0
     209: istore        13
     211: aload         12
     213: checkcast     #87                 // class java/lang/CharSequence
     216: invokestatic  #91                 // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     219: ifne          226
     222: iconst_1
     223: goto          227
     226: iconst_0
     227: nop
     228: ifeq          182
     231: aload         8
     233: aload         11
     235: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     240: pop
     241: goto          182
     244: aload         8
     246: checkcast     #80                 // class java/util/List
     249: nop
     250: checkcast     #39                 // class java/lang/Iterable
     253: astore        5
     255: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     258: astore        6
     260: iconst_0
     261: istore        7
     263: aload         5
     265: astore        8
     267: new           #41                 // class java/util/ArrayList
     270: dup
     271: aload         5
     273: bipush        10
     275: invokestatic  #104                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     278: invokespecial #107                // Method java/util/ArrayList."<init>":(I)V
     281: checkcast     #85                 // class java/util/Collection
     284: astore        9
     286: iconst_0
     287: istore        10
     289: aload         8
     291: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     296: astore        11
     298: aload         11
     300: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     305: ifeq          350
     308: aload         11
     310: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     315: astore        12
     317: aload         9
     319: aload         12
     321: checkcast     #58                 // class java/lang/String
     324: astore        13
     326: astore        16
     328: iconst_0
     329: istore        14
     331: aload         6
     333: aload         13
     335: invokestatic  #111                // Method Day13.access$toCoordinates:(LDay13;Ljava/lang/String;)LDay13$Coord;
     338: aload         16
     340: swap
     341: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     346: pop
     347: goto          298
     350: aload         9
     352: checkcast     #80                 // class java/util/List
     355: nop
     356: checkcast     #85                 // class java/util/Collection
     359: astore        4
     361: aload_2
     362: checkcast     #39                 // class java/lang/Iterable
     365: astore        6
     367: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     370: astore        7
     372: iconst_0
     373: istore        8
     375: aload         6
     377: astore        9
     379: new           #41                 // class java/util/ArrayList
     382: dup
     383: aload         6
     385: bipush        10
     387: invokestatic  #104                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     390: invokespecial #107                // Method java/util/ArrayList."<init>":(I)V
     393: checkcast     #85                 // class java/util/Collection
     396: astore        10
     398: iconst_0
     399: istore        11
     401: aload         9
     403: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     408: astore        12
     410: aload         12
     412: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     417: ifeq          462
     420: aload         12
     422: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     427: astore        13
     429: aload         10
     431: aload         13
     433: checkcast     #58                 // class java/lang/String
     436: astore        14
     438: astore        16
     440: iconst_0
     441: istore        15
     443: aload         7
     445: aload         14
     447: invokestatic  #115                // Method Day13.access$toInstructions:(LDay13;Ljava/lang/String;)Lkotlin/Pair;
     450: aload         16
     452: swap
     453: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     458: pop
     459: goto          410
     462: aload         10
     464: checkcast     #80                 // class java/util/List
     467: nop
     468: astore        5
     470: aload         5
     472: checkcast     #39                 // class java/lang/Iterable
     475: astore        7
     477: iconst_0
     478: istore        8
     480: aload         4
     482: astore        9
     484: aload         7
     486: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     491: astore        10
     493: aload         10
     495: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     500: ifeq          544
     503: aload         10
     505: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     510: astore        11
     512: aload         9
     514: aload         11
     516: checkcast     #72                 // class kotlin/Pair
     519: astore        12
     521: astore        13
     523: iconst_0
     524: istore        14
     526: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     529: aload         12
     531: aload         13
     533: invokestatic  #119                // Method Day13.access$fold:(LDay13;Lkotlin/Pair;Ljava/util/Collection;)Ljava/util/Set;
     536: checkcast     #85                 // class java/util/Collection
     539: astore        9
     541: goto          493
     544: aload         9
     546: astore        6
     548: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     551: aload         6
     553: invokestatic  #123                // Method Day13.access$draw:(LDay13;Ljava/util/Collection;)V
     556: return

  static {};
    Code:
       0: new           #2                  // class Day13$Part2
       3: dup
       4: invokespecial #166                // Method "<init>":()V
       7: putstatic     #168                // Field INSTANCE:LDay13$Part2;
      10: return
}

Compiled from "Day13.kt"
final class Day13$Direction$x extends Day13$Direction {
  Day13$Direction$x();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: aconst_null
       4: invokespecial #10                 // Method Day13$Direction."<init>":(Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return

  public int extract(Day13$Coord);
    Code:
       0: aload_1
       1: ldc           #21                 // String c
       3: invokestatic  #27                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: invokevirtual #33                 // Method Day13$Coord.getX:()I
      10: ireturn

  public Day13$Coord adjust(Day13$Coord, int);
    Code:
       0: aload_1
       1: ldc           #21                 // String c
       3: invokestatic  #27                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #29                 // class Day13$Coord
       9: dup
      10: aload_1
      11: invokevirtual #33                 // Method Day13$Coord.getX:()I
      14: aload_1
      15: invokevirtual #33                 // Method Day13$Coord.getX:()I
      18: iload_2
      19: isub
      20: iconst_2
      21: imul
      22: isub
      23: invokestatic  #42                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      26: aload_1
      27: invokevirtual #45                 // Method Day13$Coord.getY:()I
      30: invokestatic  #42                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: invokestatic  #51                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: invokespecial #54                 // Method Day13$Coord."<init>":(Lkotlin/Pair;)V
      39: areturn
}

Compiled from "Day13.kt"
public abstract class Day13$Direction extends java.lang.Enum<Day13$Direction> {
  public static final Day13$Direction x;

  public static final Day13$Direction y;

  private static final Day13$Direction[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private Day13$Direction();
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #10                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: return

  public abstract int extract(Day13$Coord);

  public abstract Day13$Coord adjust(Day13$Coord, int);

  public static Day13$Direction[] values();
    Code:
       0: getstatic     #27                 // Field $VALUES:[LDay13$Direction;
       3: invokevirtual #33                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #34                 // class "[LDay13$Direction;"
       9: areturn

  public static Day13$Direction valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class Day13$Direction
       2: aload_0
       3: invokestatic  #39                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class Day13$Direction
       9: areturn

  public static kotlin.enums.EnumEntries<Day13$Direction> getEntries();
    Code:
       0: getstatic     #47                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final Day13$Direction[] $values();
    Code:
       0: iconst_2
       1: anewarray     #2                  // class Day13$Direction
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #51                 // Field x:LDay13$Direction;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #54                 // Field y:LDay13$Direction;
      16: aastore
      17: aload_0
      18: areturn

  public Day13$Direction(java.lang.String, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
       6: return

  static {};
    Code:
       0: new           #61                 // class Day13$Direction$x
       3: dup
       4: ldc           #62                 // String x
       6: iconst_0
       7: invokespecial #63                 // Method Day13$Direction$x."<init>":(Ljava/lang/String;I)V
      10: putstatic     #51                 // Field x:LDay13$Direction;
      13: new           #65                 // class Day13$Direction$y
      16: dup
      17: ldc           #66                 // String y
      19: iconst_1
      20: invokespecial #67                 // Method Day13$Direction$y."<init>":(Ljava/lang/String;I)V
      23: putstatic     #54                 // Field y:LDay13$Direction;
      26: invokestatic  #69                 // Method $values:()[LDay13$Direction;
      29: putstatic     #27                 // Field $VALUES:[LDay13$Direction;
      32: getstatic     #27                 // Field $VALUES:[LDay13$Direction;
      35: checkcast     #71                 // class "[Ljava/lang/Enum;"
      38: invokestatic  #77                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      41: putstatic     #47                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      44: return
}

Compiled from "Day13.kt"
public final class Day13$Part1 {
  public static final Day13$Part1 INSTANCE;

  private Day13$Part1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void run();
    Code:
       0: new           #13                 // class java/io/File
       3: dup
       4: ldc           #15                 // String day13/input-real.txt
       6: invokespecial #18                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: getstatic     #24                 // Field java/nio/charset/StandardCharsets.UTF_8:Ljava/nio/charset/Charset;
      12: dup
      13: ldc           #25                 // String UTF_8
      15: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: invokestatic  #37                 // Method kotlin/io/FilesKt.readLines:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/util/List;
      21: checkcast     #39                 // class java/lang/Iterable
      24: astore_2
      25: nop
      26: iconst_0
      27: istore_3
      28: new           #41                 // class java/util/ArrayList
      31: dup
      32: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
      35: astore        4
      37: new           #41                 // class java/util/ArrayList
      40: dup
      41: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
      44: astore        5
      46: aload_2
      47: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      52: astore        6
      54: aload         6
      56: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          117
      64: aload         6
      66: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: astore        7
      73: aload         7
      75: checkcast     #58                 // class java/lang/String
      78: astore        8
      80: iconst_0
      81: istore        9
      83: aload         8
      85: ldc           #60                 // String fold along
      87: iconst_0
      88: iconst_2
      89: aconst_null
      90: invokestatic  #66                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      93: ifeq          106
      96: aload         4
      98: aload         7
     100: invokevirtual #70                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     103: goto          113
     106: aload         5
     108: aload         7
     110: invokevirtual #70                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     113: pop
     114: goto          54
     117: new           #72                 // class kotlin/Pair
     120: dup
     121: aload         4
     123: aload         5
     125: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     128: astore_1
     129: aload_1
     130: invokevirtual #78                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     133: checkcast     #80                 // class java/util/List
     136: astore_2
     137: aload_1
     138: invokevirtual #83                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     141: checkcast     #80                 // class java/util/List
     144: astore_3
     145: aload_3
     146: checkcast     #39                 // class java/lang/Iterable
     149: astore        5
     151: iconst_0
     152: istore        6
     154: aload         5
     156: astore        7
     158: new           #41                 // class java/util/ArrayList
     161: dup
     162: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
     165: checkcast     #85                 // class java/util/Collection
     168: astore        8
     170: iconst_0
     171: istore        9
     173: aload         7
     175: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        10
     182: aload         10
     184: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          244
     192: aload         10
     194: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        11
     201: aload         11
     203: checkcast     #58                 // class java/lang/String
     206: astore        12
     208: iconst_0
     209: istore        13
     211: aload         12
     213: checkcast     #87                 // class java/lang/CharSequence
     216: invokestatic  #91                 // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     219: ifne          226
     222: iconst_1
     223: goto          227
     226: iconst_0
     227: nop
     228: ifeq          182
     231: aload         8
     233: aload         11
     235: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     240: pop
     241: goto          182
     244: aload         8
     246: checkcast     #80                 // class java/util/List
     249: nop
     250: checkcast     #39                 // class java/lang/Iterable
     253: astore        5
     255: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     258: astore        6
     260: iconst_0
     261: istore        7
     263: aload         5
     265: astore        8
     267: new           #41                 // class java/util/ArrayList
     270: dup
     271: aload         5
     273: bipush        10
     275: invokestatic  #104                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     278: invokespecial #107                // Method java/util/ArrayList."<init>":(I)V
     281: checkcast     #85                 // class java/util/Collection
     284: astore        9
     286: iconst_0
     287: istore        10
     289: aload         8
     291: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     296: astore        11
     298: aload         11
     300: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     305: ifeq          350
     308: aload         11
     310: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     315: astore        12
     317: aload         9
     319: aload         12
     321: checkcast     #58                 // class java/lang/String
     324: astore        13
     326: astore        16
     328: iconst_0
     329: istore        14
     331: aload         6
     333: aload         13
     335: invokestatic  #111                // Method Day13.access$toCoordinates:(LDay13;Ljava/lang/String;)LDay13$Coord;
     338: aload         16
     340: swap
     341: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     346: pop
     347: goto          298
     350: aload         9
     352: checkcast     #80                 // class java/util/List
     355: nop
     356: astore        4
     358: aload_2
     359: checkcast     #39                 // class java/lang/Iterable
     362: astore        6
     364: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     367: astore        7
     369: iconst_0
     370: istore        8
     372: aload         6
     374: astore        9
     376: new           #41                 // class java/util/ArrayList
     379: dup
     380: aload         6
     382: bipush        10
     384: invokestatic  #104                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     387: invokespecial #107                // Method java/util/ArrayList."<init>":(I)V
     390: checkcast     #85                 // class java/util/Collection
     393: astore        10
     395: iconst_0
     396: istore        11
     398: aload         9
     400: invokeinterface #46,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     405: astore        12
     407: aload         12
     409: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     414: ifeq          459
     417: aload         12
     419: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     424: astore        13
     426: aload         10
     428: aload         13
     430: checkcast     #58                 // class java/lang/String
     433: astore        14
     435: astore        16
     437: iconst_0
     438: istore        15
     440: aload         7
     442: aload         14
     444: invokestatic  #115                // Method Day13.access$toInstructions:(LDay13;Ljava/lang/String;)Lkotlin/Pair;
     447: aload         16
     449: swap
     450: invokeinterface #92,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     455: pop
     456: goto          407
     459: aload         10
     461: checkcast     #80                 // class java/util/List
     464: nop
     465: astore        5
     467: getstatic     #98                 // Field Day13.INSTANCE:LDay13;
     470: aload         5
     472: invokestatic  #119                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     475: checkcast     #72                 // class kotlin/Pair
     478: aload         4
     480: checkcast     #85                 // class java/util/Collection
     483: invokestatic  #123                // Method Day13.access$fold:(LDay13;Lkotlin/Pair;Ljava/util/Collection;)Ljava/util/Set;
     486: astore        6
     488: aload         6
     490: invokeinterface #129,  1          // InterfaceMethod java/util/Set.size:()I
     495: istore        7
     497: getstatic     #135                // Field java/lang/System.out:Ljava/io/PrintStream;
     500: iload         7
     502: invokevirtual #140                // Method java/io/PrintStream.println:(I)V
     505: return

  static {};
    Code:
       0: new           #2                  // class Day13$Part1
       3: dup
       4: invokespecial #176                // Method "<init>":()V
       7: putstatic     #178                // Field INSTANCE:LDay13$Part1;
      10: return
}


import java.io.File
import java.nio.charset.Charset.defaultCharset
import kotlin.streams.toList

typealias Coordinate = Pair<Int, Int>
typealias Basin = Set<Coordinate>
typealias ValidCells = Set<Coordinate>

object Day09 {
    fun toCoordinates(row: Int, line: String) = line.chars()
        .map(Character::getNumericValue)
        .toList()
        .mapIndexed { col, value -> (row to col) to value }

    fun getSurroundingCoordinates(
        validCells: ValidCells,
        coord: Coordinate,
        seenCoordinates: HashSet<Coordinate>,
        deltas: List<Pair<Int, Int>> = listOf(0 to 1, 1 to 0, 0 to -1, -1 to 0)
    ) = deltas.asSequence()
        .map { (x2, y2) -> coord.first + x2 to coord.second + y2 }
        .filter { validCells.contains(it) }
        .filter { !seenCoordinates.contains(it) }

    fun findBasin(validCells: ValidCells, coordinate: Coordinate, seenCoordinates: HashSet<Coordinate>): Basin? {
        if (seenCoordinates.contains(coordinate)) return null
        seenCoordinates.add(coordinate)
        val basin = mutableSetOf(coordinate)

        getSurroundingCoordinates(validCells, coordinate, seenCoordinates)
            .filter { !seenCoordinates.contains(it) }
            .map { findBasin(validCells, it, seenCoordinates) }
            .filterNotNull()
            .forEach { basin.addAll(it) }

        return basin
    }

    fun run() {
        val file = File("day09/input-real.txt")

        val cells = file.readLines(defaultCharset())
            .mapIndexed(::toCoordinates)
            .flatten()

        val (highs, unseen) = cells.partition { it.second == 9 }
        val validCells = cells.map { it.first }.toSet()

        val seenCoordinates = highs.map { it.first }.toHashSet()
        val toCheck = unseen.map { it.first }

        val basins = toCheck.fold(mutableListOf<Basin>()) { basins, coordinate ->
            findBasin(validCells, coordinate, seenCoordinates)?.let { basins.add(it) }
            basins
        }

        val result = basins.map { it.size }.sortedDescending().take(3).reduce(Int::times)
        println(result)
    }
}

fun main() {
    Day09.run()
}

Compiled from "Day09.kt"
public final class Day09 {
  public static final Day09 INSTANCE;

  private Day09();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.util.List<kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer>> toCoordinates(int, java.lang.String);
    Code:
       0: aload_2
       1: ldc           #16                 // String line
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: invokevirtual #28                 // Method java/lang/String.chars:()Ljava/util/stream/IntStream;
      10: invokedynamic #47,  0             // InvokeDynamic #0:applyAsInt:()Ljava/util/function/IntUnaryOperator;
      15: invokeinterface #53,  2           // InterfaceMethod java/util/stream/IntStream.map:(Ljava/util/function/IntUnaryOperator;)Ljava/util/stream/IntStream;
      20: dup
      21: ldc           #55                 // String map(...)
      23: invokestatic  #58                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      26: invokestatic  #64                 // Method kotlin/streams/jdk8/StreamsKt.toList:(Ljava/util/stream/IntStream;)Ljava/util/List;
      29: checkcast     #66                 // class java/lang/Iterable
      32: astore_3
      33: nop
      34: iconst_0
      35: istore        4
      37: aload_3
      38: astore        5
      40: new           #68                 // class java/util/ArrayList
      43: dup
      44: aload_3
      45: bipush        10
      47: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      50: invokespecial #77                 // Method java/util/ArrayList."<init>":(I)V
      53: checkcast     #79                 // class java/util/Collection
      56: astore        6
      58: iconst_0
      59: istore        7
      61: iconst_0
      62: istore        8
      64: aload         5
      66: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      71: astore        9
      73: aload         9
      75: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      80: ifeq          160
      83: aload         9
      85: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      90: astore        10
      92: aload         6
      94: iload         8
      96: iinc          8, 1
      99: istore        11
     101: iload         11
     103: ifge          109
     106: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     109: iload         11
     111: aload         10
     113: checkcast     #98                 // class java/lang/Number
     116: invokevirtual #102                // Method java/lang/Number.intValue:()I
     119: istore        12
     121: istore        13
     123: astore        15
     125: iconst_0
     126: istore        14
     128: iload_1
     129: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     132: iload         13
     134: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     137: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     140: iload         12
     142: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     145: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     148: aload         15
     150: swap
     151: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          73
     160: aload         6
     162: checkcast     #120                // class java/util/List
     165: nop
     166: areturn

  public final kotlin.sequences.Sequence<kotlin.Pair<java.lang.Integer, java.lang.Integer>> getSurroundingCoordinates(java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.util.HashSet<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_1
       1: ldc           #141                // String validCells
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #143                // String coord
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #145                // String seenCoordinates
      15: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload         4
      20: ldc           #147                // String deltas
      22: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      25: aload         4
      27: checkcast     #66                 // class java/lang/Iterable
      30: invokestatic  #151                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      33: aload_2
      34: invokedynamic #164,  0            // InvokeDynamic #1:invoke:(Lkotlin/Pair;)Lkotlin/jvm/functions/Function1;
      39: invokestatic  #169                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      42: aload_1
      43: invokedynamic #179,  0            // InvokeDynamic #2:invoke:(Ljava/util/Set;)Lkotlin/jvm/functions/Function1;
      48: invokestatic  #182                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      51: aload_3
      52: invokedynamic #190,  0            // InvokeDynamic #3:invoke:(Ljava/util/HashSet;)Lkotlin/jvm/functions/Function1;
      57: invokestatic  #182                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      60: areturn

  public static kotlin.sequences.Sequence getSurroundingCoordinates$default(Day09, java.util.Set, kotlin.Pair, java.util.HashSet, java.util.List, int, java.lang.Object);
    Code:
       0: iload         5
       2: bipush        8
       4: iand
       5: ifeq          81
       8: iconst_4
       9: anewarray     #198                // class kotlin/Pair
      12: astore        7
      14: aload         7
      16: iconst_0
      17: iconst_0
      18: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: iconst_1
      22: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      28: aastore
      29: aload         7
      31: iconst_1
      32: iconst_1
      33: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: iconst_0
      37: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      43: aastore
      44: aload         7
      46: iconst_2
      47: iconst_0
      48: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: iconst_m1
      52: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      58: aastore
      59: aload         7
      61: iconst_3
      62: iconst_m1
      63: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: iconst_0
      67: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      70: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      73: aastore
      74: aload         7
      76: invokestatic  #202                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      79: astore        4
      81: aload_0
      82: aload_1
      83: aload_2
      84: aload_3
      85: aload         4
      87: invokevirtual #204                // Method getSurroundingCoordinates:(Ljava/util/Set;Lkotlin/Pair;Ljava/util/HashSet;Ljava/util/List;)Lkotlin/sequences/Sequence;
      90: areturn

  public final java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>> findBasin(java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.util.HashSet<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_1
       1: ldc           #141                // String validCells
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #210                // String coordinate
       9: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #145                // String seenCoordinates
      15: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: aload_3
      19: aload_2
      20: invokevirtual #215                // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      23: ifeq          28
      26: aconst_null
      27: areturn
      28: aload_3
      29: aload_2
      30: invokevirtual #216                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      33: pop
      34: iconst_1
      35: anewarray     #198                // class kotlin/Pair
      38: astore        5
      40: aload         5
      42: iconst_0
      43: aload_2
      44: aastore
      45: aload         5
      47: invokestatic  #222                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      50: astore        4
      52: aload_0
      53: aload_1
      54: aload_2
      55: aload_3
      56: aconst_null
      57: bipush        8
      59: aconst_null
      60: invokestatic  #224                // Method getSurroundingCoordinates$default:(LDay09;Ljava/util/Set;Lkotlin/Pair;Ljava/util/HashSet;Ljava/util/List;ILjava/lang/Object;)Lkotlin/sequences/Sequence;
      63: aload_3
      64: invokedynamic #229,  0            // InvokeDynamic #4:invoke:(Ljava/util/HashSet;)Lkotlin/jvm/functions/Function1;
      69: invokestatic  #182                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      72: aload_1
      73: aload_3
      74: invokedynamic #239,  0            // InvokeDynamic #5:invoke:(Ljava/util/Set;Ljava/util/HashSet;)Lkotlin/jvm/functions/Function1;
      79: invokestatic  #169                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      82: invokestatic  #243                // Method kotlin/sequences/SequencesKt.filterNotNull:(Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
      85: astore        5
      87: nop
      88: iconst_0
      89: istore        6
      91: aload         5
      93: invokeinterface #246,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      98: astore        7
     100: aload         7
     102: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     107: ifeq          146
     110: aload         7
     112: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     117: astore        8
     119: aload         8
     121: checkcast     #248                // class java/util/Set
     124: astore        9
     126: iconst_0
     127: istore        10
     129: aload         4
     131: aload         9
     133: checkcast     #79                 // class java/util/Collection
     136: invokeinterface #252,  2          // InterfaceMethod java/util/Set.addAll:(Ljava/util/Collection;)Z
     141: pop
     142: nop
     143: goto          100
     146: nop
     147: aload         4
     149: areturn

  public final void run();
    Code:
       0: new           #262                // class java/io/File
       3: dup
       4: ldc_w         #264                // String day09/input-real.txt
       7: invokespecial #267                // Method java/io/File."<init>":(Ljava/lang/String;)V
      10: astore_1
      11: aload_1
      12: invokestatic  #273                // Method java/nio/charset/Charset.defaultCharset:()Ljava/nio/charset/Charset;
      15: dup
      16: ldc_w         #275                // String defaultCharset(...)
      19: invokestatic  #58                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      22: invokestatic  #281                // Method kotlin/io/FilesKt.readLines:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/util/List;
      25: checkcast     #66                 // class java/lang/Iterable
      28: astore_3
      29: nop
      30: iconst_0
      31: istore        4
      33: aload_3
      34: astore        5
      36: new           #68                 // class java/util/ArrayList
      39: dup
      40: aload_3
      41: bipush        10
      43: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      46: invokespecial #77                 // Method java/util/ArrayList."<init>":(I)V
      49: checkcast     #79                 // class java/util/Collection
      52: astore        6
      54: iconst_0
      55: istore        7
      57: iconst_0
      58: istore        8
      60: aload         5
      62: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      67: astore        9
      69: aload         9
      71: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          141
      79: aload         9
      81: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: astore        10
      88: aload         6
      90: iload         8
      92: iinc          8, 1
      95: istore        11
      97: iload         11
      99: ifge          105
     102: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     105: iload         11
     107: aload         10
     109: checkcast     #24                 // class java/lang/String
     112: astore        12
     114: istore        13
     116: astore        21
     118: iconst_0
     119: istore        14
     121: aload_0
     122: iload         13
     124: aload         12
     126: invokevirtual #283                // Method toCoordinates:(ILjava/lang/String;)Ljava/util/List;
     129: aload         21
     131: swap
     132: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     137: pop
     138: goto          69
     141: aload         6
     143: checkcast     #120                // class java/util/List
     146: nop
     147: checkcast     #66                 // class java/lang/Iterable
     150: invokestatic  #287                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     153: astore_2
     154: aload_2
     155: checkcast     #66                 // class java/lang/Iterable
     158: astore        4
     160: iconst_0
     161: istore        5
     163: new           #68                 // class java/util/ArrayList
     166: dup
     167: invokespecial #288                // Method java/util/ArrayList."<init>":()V
     170: astore        6
     172: new           #68                 // class java/util/ArrayList
     175: dup
     176: invokespecial #288                // Method java/util/ArrayList."<init>":()V
     179: astore        7
     181: aload         4
     183: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     188: astore        8
     190: aload         8
     192: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     197: ifeq          264
     200: aload         8
     202: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     207: astore        9
     209: aload         9
     211: checkcast     #198                // class kotlin/Pair
     214: astore        10
     216: iconst_0
     217: istore        11
     219: aload         10
     221: invokevirtual #291                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     224: checkcast     #98                 // class java/lang/Number
     227: invokevirtual #102                // Method java/lang/Number.intValue:()I
     230: bipush        9
     232: if_icmpne     239
     235: iconst_1
     236: goto          240
     239: iconst_0
     240: ifeq          253
     243: aload         6
     245: aload         9
     247: invokevirtual #292                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     250: goto          260
     253: aload         7
     255: aload         9
     257: invokevirtual #292                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     260: pop
     261: goto          190
     264: new           #198                // class kotlin/Pair
     267: dup
     268: aload         6
     270: aload         7
     272: invokespecial #295                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     275: astore_3
     276: aload_3
     277: invokevirtual #298                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     280: checkcast     #120                // class java/util/List
     283: astore        4
     285: aload_3
     286: invokevirtual #301                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     289: checkcast     #120                // class java/util/List
     292: astore        5
     294: aload_2
     295: checkcast     #66                 // class java/lang/Iterable
     298: astore        7
     300: iconst_0
     301: istore        8
     303: aload         7
     305: astore        9
     307: new           #68                 // class java/util/ArrayList
     310: dup
     311: aload         7
     313: bipush        10
     315: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     318: invokespecial #77                 // Method java/util/ArrayList."<init>":(I)V
     321: checkcast     #79                 // class java/util/Collection
     324: astore        10
     326: iconst_0
     327: istore        11
     329: aload         9
     331: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     336: astore        12
     338: aload         12
     340: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     345: ifeq          391
     348: aload         12
     350: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     355: astore        13
     357: aload         10
     359: aload         13
     361: checkcast     #198                // class kotlin/Pair
     364: astore        14
     366: astore        21
     368: iconst_0
     369: istore        15
     371: aload         14
     373: invokevirtual #304                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     376: checkcast     #198                // class kotlin/Pair
     379: aload         21
     381: swap
     382: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     387: pop
     388: goto          338
     391: aload         10
     393: checkcast     #120                // class java/util/List
     396: nop
     397: checkcast     #66                 // class java/lang/Iterable
     400: invokestatic  #308                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     403: astore        6
     405: aload         4
     407: checkcast     #66                 // class java/lang/Iterable
     410: astore        8
     412: iconst_0
     413: istore        9
     415: aload         8
     417: astore        10
     419: new           #68                 // class java/util/ArrayList
     422: dup
     423: aload         8
     425: bipush        10
     427: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     430: invokespecial #77                 // Method java/util/ArrayList."<init>":(I)V
     433: checkcast     #79                 // class java/util/Collection
     436: astore        11
     438: iconst_0
     439: istore        12
     441: aload         10
     443: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     448: astore        13
     450: aload         13
     452: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     457: ifeq          503
     460: aload         13
     462: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     467: astore        14
     469: aload         11
     471: aload         14
     473: checkcast     #198                // class kotlin/Pair
     476: astore        15
     478: astore        21
     480: iconst_0
     481: istore        16
     483: aload         15
     485: invokevirtual #304                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     488: checkcast     #198                // class kotlin/Pair
     491: aload         21
     493: swap
     494: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     499: pop
     500: goto          450
     503: aload         11
     505: checkcast     #120                // class java/util/List
     508: nop
     509: checkcast     #66                 // class java/lang/Iterable
     512: invokestatic  #312                // Method kotlin/collections/CollectionsKt.toHashSet:(Ljava/lang/Iterable;)Ljava/util/HashSet;
     515: astore        7
     517: aload         5
     519: checkcast     #66                 // class java/lang/Iterable
     522: astore        9
     524: iconst_0
     525: istore        10
     527: aload         9
     529: astore        11
     531: new           #68                 // class java/util/ArrayList
     534: dup
     535: aload         9
     537: bipush        10
     539: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     542: invokespecial #77                 // Method java/util/ArrayList."<init>":(I)V
     545: checkcast     #79                 // class java/util/Collection
     548: astore        12
     550: iconst_0
     551: istore        13
     553: aload         11
     555: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     560: astore        14
     562: aload         14
     564: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     569: ifeq          615
     572: aload         14
     574: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     579: astore        15
     581: aload         12
     583: aload         15
     585: checkcast     #198                // class kotlin/Pair
     588: astore        16
     590: astore        21
     592: iconst_0
     593: istore        17
     595: aload         16
     597: invokevirtual #304                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     600: checkcast     #198                // class kotlin/Pair
     603: aload         21
     605: swap
     606: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     611: pop
     612: goto          562
     615: aload         12
     617: checkcast     #120                // class java/util/List
     620: nop
     621: astore        8
     623: aload         8
     625: checkcast     #66                 // class java/lang/Iterable
     628: astore        10
     630: new           #68                 // class java/util/ArrayList
     633: dup
     634: invokespecial #288                // Method java/util/ArrayList."<init>":()V
     637: checkcast     #120                // class java/util/List
     640: astore        11
     642: nop
     643: iconst_0
     644: istore        12
     646: aload         11
     648: astore        13
     650: aload         10
     652: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     657: astore        14
     659: aload         14
     661: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     666: ifeq          735
     669: aload         14
     671: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     676: astore        15
     678: aload         13
     680: aload         15
     682: checkcast     #198                // class kotlin/Pair
     685: astore        16
     687: astore        17
     689: iconst_0
     690: istore        18
     692: getstatic     #315                // Field INSTANCE:LDay09;
     695: aload         6
     697: aload         16
     699: aload         7
     701: invokevirtual #317                // Method findBasin:(Ljava/util/Set;Lkotlin/Pair;Ljava/util/HashSet;)Ljava/util/Set;
     704: dup
     705: ifnull        726
     708: astore        19
     710: iconst_0
     711: istore        20
     713: aload         17
     715: aload         19
     717: invokeinterface #318,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     722: pop
     723: goto          728
     726: pop
     727: nop
     728: aload         17
     730: astore        13
     732: goto          659
     735: aload         13
     737: astore        9
     739: aload         9
     741: checkcast     #66                 // class java/lang/Iterable
     744: astore        11
     746: iconst_0
     747: istore        12
     749: aload         11
     751: astore        13
     753: new           #68                 // class java/util/ArrayList
     756: dup
     757: aload         11
     759: bipush        10
     761: invokestatic  #74                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     764: invokespecial #77                 // Method java/util/ArrayList."<init>":(I)V
     767: checkcast     #79                 // class java/util/Collection
     770: astore        14
     772: iconst_0
     773: istore        15
     775: aload         13
     777: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     782: astore        16
     784: aload         16
     786: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     791: ifeq          839
     794: aload         16
     796: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     801: astore        17
     803: aload         14
     805: aload         17
     807: checkcast     #248                // class java/util/Set
     810: astore        18
     812: astore        21
     814: iconst_0
     815: istore        19
     817: aload         18
     819: invokeinterface #321,  1          // InterfaceMethod java/util/Set.size:()I
     824: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     827: aload         21
     829: swap
     830: invokeinterface #118,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     835: pop
     836: goto          784
     839: aload         14
     841: checkcast     #120                // class java/util/List
     844: nop
     845: checkcast     #66                 // class java/lang/Iterable
     848: invokestatic  #324                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     851: checkcast     #66                 // class java/lang/Iterable
     854: iconst_3
     855: invokestatic  #328                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     858: checkcast     #66                 // class java/lang/Iterable
     861: astore        11
     863: iconst_0
     864: istore        12
     866: aload         11
     868: invokeinterface #83,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     873: astore        13
     875: aload         13
     877: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     882: ifne          896
     885: new           #330                // class java/lang/UnsupportedOperationException
     888: dup
     889: ldc_w         #332                // String Empty collection can\'t be reduced.
     892: invokespecial #333                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     895: athrow
     896: aload         13
     898: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     903: astore        14
     905: aload         13
     907: invokeinterface #89,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     912: ifeq          956
     915: aload         14
     917: aload         13
     919: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     924: checkcast     #98                 // class java/lang/Number
     927: invokevirtual #102                // Method java/lang/Number.intValue:()I
     930: istore        15
     932: checkcast     #98                 // class java/lang/Number
     935: invokevirtual #102                // Method java/lang/Number.intValue:()I
     938: istore        16
     940: iconst_0
     941: istore        17
     943: iload         16
     945: iload         15
     947: imul
     948: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     951: astore        14
     953: goto          905
     956: aload         14
     958: checkcast     #98                 // class java/lang/Number
     961: invokevirtual #102                // Method java/lang/Number.intValue:()I
     964: istore        10
     966: getstatic     #339                // Field java/lang/System.out:Ljava/io/PrintStream;
     969: iload         10
     971: invokevirtual #344                // Method java/io/PrintStream.println:(I)V
     974: return

  private static final kotlin.Pair getSurroundingCoordinates$lambda$1(kotlin.Pair, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #382                // String <destruct>
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #298                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #98                 // class java/lang/Number
      14: invokevirtual #102                // Method java/lang/Number.intValue:()I
      17: istore_2
      18: aload_1
      19: invokevirtual #301                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      22: checkcast     #98                 // class java/lang/Number
      25: invokevirtual #102                // Method java/lang/Number.intValue:()I
      28: istore_3
      29: aload_0
      30: invokevirtual #304                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      33: checkcast     #98                 // class java/lang/Number
      36: invokevirtual #102                // Method java/lang/Number.intValue:()I
      39: iload_2
      40: iadd
      41: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      44: aload_0
      45: invokevirtual #291                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      48: checkcast     #98                 // class java/lang/Number
      51: invokevirtual #102                // Method java/lang/Number.intValue:()I
      54: iload_3
      55: iadd
      56: invokestatic  #108                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: invokestatic  #114                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      62: areturn

  private static final boolean getSurroundingCoordinates$lambda$2(java.util.Set, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #386                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokeinterface #387,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      14: ireturn

  private static final boolean getSurroundingCoordinates$lambda$3(java.util.HashSet, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #386                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokevirtual #215                // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      12: ifne          19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ireturn

  private static final boolean findBasin$lambda$4(java.util.HashSet, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #386                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokevirtual #215                // Method java/util/HashSet.contains:(Ljava/lang/Object;)Z
      12: ifne          19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ireturn

  private static final java.util.Set findBasin$lambda$5(java.util.Set, java.util.HashSet, kotlin.Pair);
    Code:
       0: aload_2
       1: ldc_w         #386                // String it
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: getstatic     #315                // Field INSTANCE:LDay09;
      10: aload_0
      11: aload_2
      12: aload_1
      13: invokevirtual #317                // Method findBasin:(Ljava/util/Set;Lkotlin/Pair;Ljava/util/HashSet;)Ljava/util/Set;
      16: areturn

  static {};
    Code:
       0: new           #2                  // class Day09
       3: dup
       4: invokespecial #391                // Method "<init>":()V
       7: putstatic     #315                // Field INSTANCE:LDay09;
      10: return
}

Compiled from "Day09.kt"
public final class Day09Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Day09.INSTANCE:LDay09;
       3: invokevirtual #15                 // Method Day09.run:()V
       6: return

  public static void main(java.lang.String[]);
    Code:
       0: invokestatic  #18                 // Method main:()V
       3: return
}