import kotlin.math.abs

fun main() {

    data class Interval(var start: Int, var end: Int) {
        fun limit(minStart: Int, maxEnd: Int) {
            start = maxOf(minStart, start)
            end = minOf(maxEnd, end)
        }

        fun size(): Int {
            return 1 + end - start
        }
    }

    fun List<Interval>.maxReduce(): List<Interval> {
        if (isEmpty()) return emptyList()
        val iterator = this.sortedWith(compareBy({ it.start }, { it.end })).listIterator()

        var last = iterator.next()
        val reduced = mutableListOf(last)
        while (iterator.hasNext()) {
            val next = iterator.next()
            if (next.start <= last.end) {
                last.end = maxOf(next.end, last.end)
            } else {
                reduced.add(next)
                last = next
            }
        }
        return reduced
    }

    fun parseSensorsBeacons(input: List<String>): Map<Vector2D, Vector2D> {
        return input.associate { line ->
            val split = line.split("=", ",", ":")
            Vector2D(split[1].toInt(), split[3].toInt()) to Vector2D(split[5].toInt(), split[7].toInt())
        }
    }

    fun rangeAtY(sensor: Vector2D, distance: Int, y: Int): Interval? {
        val yDist = abs(sensor.y - y)
        if (yDist > distance) return null
        val restDist = distance - yDist
        return Interval(sensor.x - restDist, sensor.x + restDist)
    }

    fun part1(input: List<String>): Int {
        val sensorToBeacons = parseSensorsBeacons(input)
        val beaconsCount = sensorToBeacons.values.filter { it.y == 2_000_000 }.toSet().size
        val sensorToDistances = sensorToBeacons.mapValues { (s, b) -> s.manhattenDistance(b) }
        return sensorToDistances
            .mapNotNull { (s, d) -> rangeAtY(s, d, 2_000_000) }
            .maxReduce()
            .sumOf { it.size() } - beaconsCount
    }

    fun part2(input: List<String>): Long {
        val sensorToDistances = parseSensorsBeacons(input).mapValues { (s, b) -> s.manhattenDistance(b) }
        for (y in 0..4_000_000) {
            val intervals = sensorToDistances
                .mapNotNull { (s, d) -> rangeAtY(s, d, y) }
                .maxReduce()
                .onEach { it.limit(0, 4_000_000) }
            if (intervals.size > 1) {
                return 4_000_000L * (intervals.first().end + 1) + y
            }
        }
        return -1L
    }

    val input = readInput("Day15")

    println(part1(input))
    println(part2(input))
}

Compiled from "Day15.kt"
public final class Day15Kt$main$Interval {
  private int start;

  private int end;

  public Day15Kt$main$Interval(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 start:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field end:I
      14: return

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

  public final void setStart(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #13                 // Field start:I
       5: return

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

  public final void setEnd(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #16                 // Field end:I
       5: return

  public final void limit(int, int);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: getfield      #13                 // Field start:I
       6: invokestatic  #32                 // Method java/lang/Math.max:(II)I
       9: putfield      #13                 // Field start:I
      12: aload_0
      13: iload_2
      14: aload_0
      15: getfield      #16                 // Field end:I
      18: invokestatic  #35                 // Method java/lang/Math.min:(II)I
      21: putfield      #16                 // Field end:I
      24: return

  public final int size();
    Code:
       0: iconst_1
       1: aload_0
       2: getfield      #16                 // Field end:I
       5: iadd
       6: aload_0
       7: getfield      #13                 // Field start:I
      10: isub
      11: ireturn

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

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

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

  public static Day15Kt$main$Interval copy$default(Day15Kt$main$Interval, 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 start:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #16                 // Field end:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #48                 // Method copy:(II)LDay15Kt$main$Interval;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #52                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #55                 // String Interval(start=
       9: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field start:I
      16: invokevirtual #62                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #64                 // String , end=
      21: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field end:I
      28: invokevirtual #62                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #67                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field start:I
       4: invokestatic  #75                 // 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 end:I
      16: invokestatic  #75                 // 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 Day15Kt$main$Interval
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day15Kt$main$Interval
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field start:I
      25: aload_2
      26: getfield      #13                 // Field start:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field end:I
      38: aload_2
      39: getfield      #16                 // Field end:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "Day15.kt"
public final class Day15Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day15
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method main$part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #34                 // Method main$part2:(Ljava/util/List;)J
      22: lstore_1
      23: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: lload_1
      27: invokevirtual #37                 // Method java/io/PrintStream.println:(J)V
      30: return

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

  private static final java.lang.Comparable main$maxReduce$lambda$0(Day15Kt$main$Interval);
    Code:
       0: aload_0
       1: ldc           #48                 // String it
       3: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #60                 // Method Day15Kt$main$Interval.getStart:()I
      10: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: checkcast     #68                 // class java/lang/Comparable
      16: areturn

  private static final java.lang.Comparable main$maxReduce$lambda$1(Day15Kt$main$Interval);
    Code:
       0: aload_0
       1: ldc           #48                 // String it
       3: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #73                 // Method Day15Kt$main$Interval.getEnd:()I
      10: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: checkcast     #68                 // class java/lang/Comparable
      16: areturn

  private static final java.util.List<Day15Kt$main$Interval> main$maxReduce(java.util.List<Day15Kt$main$Interval>);
    Code:
       0: aload_0
       1: invokeinterface #82,  1           // InterfaceMethod java/util/List.isEmpty:()Z
       6: ifeq          13
       9: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      12: areturn
      13: aload_0
      14: checkcast     #90                 // class java/lang/Iterable
      17: iconst_2
      18: anewarray     #92                 // class kotlin/jvm/functions/Function1
      21: astore_2
      22: aload_2
      23: iconst_0
      24: invokedynamic #109,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      29: aastore
      30: aload_2
      31: iconst_1
      32: invokedynamic #113,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      37: aastore
      38: aload_2
      39: invokestatic  #119                // Method kotlin/comparisons/ComparisonsKt.compareBy:([Lkotlin/jvm/functions/Function1;)Ljava/util/Comparator;
      42: invokestatic  #123                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      45: invokeinterface #127,  1          // InterfaceMethod java/util/List.listIterator:()Ljava/util/ListIterator;
      50: astore_1
      51: aload_1
      52: invokeinterface #133,  1          // InterfaceMethod java/util/ListIterator.next:()Ljava/lang/Object;
      57: checkcast     #56                 // class Day15Kt$main$Interval
      60: astore_2
      61: iconst_1
      62: anewarray     #56                 // class Day15Kt$main$Interval
      65: astore        4
      67: aload         4
      69: iconst_0
      70: aload_2
      71: aastore
      72: aload         4
      74: invokestatic  #137                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      77: astore_3
      78: aload_1
      79: invokeinterface #140,  1          // InterfaceMethod java/util/ListIterator.hasNext:()Z
      84: ifeq          144
      87: aload_1
      88: invokeinterface #133,  1          // InterfaceMethod java/util/ListIterator.next:()Ljava/lang/Object;
      93: checkcast     #56                 // class Day15Kt$main$Interval
      96: astore        4
      98: aload         4
     100: invokevirtual #60                 // Method Day15Kt$main$Interval.getStart:()I
     103: aload_2
     104: invokevirtual #73                 // Method Day15Kt$main$Interval.getEnd:()I
     107: if_icmpgt     129
     110: aload_2
     111: aload         4
     113: invokevirtual #73                 // Method Day15Kt$main$Interval.getEnd:()I
     116: aload_2
     117: invokevirtual #73                 // Method Day15Kt$main$Interval.getEnd:()I
     120: invokestatic  #146                // Method java/lang/Math.max:(II)I
     123: invokevirtual #149                // Method Day15Kt$main$Interval.setEnd:(I)V
     126: goto          78
     129: aload_3
     130: aload         4
     132: invokeinterface #153,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     137: pop
     138: aload         4
     140: astore_2
     141: goto          78
     144: aload_3
     145: areturn

  private static final java.util.Map<Coord2D, Coord2D> main$parseSensorsBeacons(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #90                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: bipush        10
      10: invokestatic  #165                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      13: invokestatic  #171                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      16: bipush        16
      18: invokestatic  #176                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      21: istore_3
      22: aload_1
      23: astore        4
      25: new           #178                // class java/util/LinkedHashMap
      28: dup
      29: iload_3
      30: invokespecial #181                // Method java/util/LinkedHashMap."<init>":(I)V
      33: checkcast     #183                // class java/util/Map
      36: astore        5
      38: iconst_0
      39: istore        6
      41: aload         4
      43: invokeinterface #186,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        7
      50: aload         7
      52: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          221
      60: aload         7
      62: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        8
      69: aload         5
      71: astore        9
      73: aload         8
      75: checkcast     #192                // class java/lang/String
      78: astore        10
      80: iconst_0
      81: istore        11
      83: aload         10
      85: checkcast     #194                // class java/lang/CharSequence
      88: iconst_3
      89: anewarray     #192                // class java/lang/String
      92: astore        12
      94: aload         12
      96: iconst_0
      97: ldc           #196                // String =
      99: aastore
     100: aload         12
     102: iconst_1
     103: ldc           #198                // String ,
     105: aastore
     106: aload         12
     108: iconst_2
     109: ldc           #200                // String :
     111: aastore
     112: aload         12
     114: iconst_0
     115: iconst_0
     116: bipush        6
     118: aconst_null
     119: invokestatic  #206                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     122: astore        13
     124: new           #208                // class Coord2D
     127: dup
     128: aload         13
     130: iconst_1
     131: invokeinterface #212,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     136: checkcast     #192                // class java/lang/String
     139: invokestatic  #216                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     142: aload         13
     144: iconst_3
     145: invokeinterface #212,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     150: checkcast     #192                // class java/lang/String
     153: invokestatic  #216                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     156: invokespecial #219                // Method Coord2D."<init>":(II)V
     159: new           #208                // class Coord2D
     162: dup
     163: aload         13
     165: iconst_5
     166: invokeinterface #212,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     171: checkcast     #192                // class java/lang/String
     174: invokestatic  #216                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     177: aload         13
     179: bipush        7
     181: invokeinterface #212,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #192                // class java/lang/String
     189: invokestatic  #216                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     192: invokespecial #219                // Method Coord2D."<init>":(II)V
     195: invokestatic  #225                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     198: astore        10
     200: aload         9
     202: aload         10
     204: invokevirtual #230                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     207: aload         10
     209: invokevirtual #233                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     212: invokeinterface #237,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     217: pop
     218: goto          50
     221: aload         5
     223: nop
     224: areturn

  private static final Day15Kt$main$Interval main$rangeAtY(Coord2D, int, int);
    Code:
       0: aload_0
       1: invokevirtual #257                // Method Coord2D.getY:()I
       4: iload_2
       5: isub
       6: invokestatic  #260                // Method java/lang/Math.abs:(I)I
       9: istore_3
      10: iload_3
      11: iload_1
      12: if_icmple     17
      15: aconst_null
      16: areturn
      17: iload_1
      18: iload_3
      19: isub
      20: istore        4
      22: new           #56                 // class Day15Kt$main$Interval
      25: dup
      26: aload_0
      27: invokevirtual #263                // Method Coord2D.getX:()I
      30: iload         4
      32: isub
      33: aload_0
      34: invokevirtual #263                // Method Coord2D.getX:()I
      37: iload         4
      39: iadd
      40: invokespecial #264                // Method Day15Kt$main$Interval."<init>":(II)V
      43: areturn

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #273                // Method main$parseSensorsBeacons:(Ljava/util/List;)Ljava/util/Map;
       4: astore_1
       5: aload_1
       6: invokeinterface #277,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      11: checkcast     #90                 // class java/lang/Iterable
      14: astore_3
      15: iconst_0
      16: istore        4
      18: aload_3
      19: astore        5
      21: new           #279                // class java/util/ArrayList
      24: dup
      25: invokespecial #281                // Method java/util/ArrayList."<init>":()V
      28: checkcast     #283                // class java/util/Collection
      31: astore        6
      33: iconst_0
      34: istore        7
      36: aload         5
      38: invokeinterface #186,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        8
      45: aload         8
      47: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          106
      55: aload         8
      57: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        9
      64: aload         9
      66: checkcast     #208                // class Coord2D
      69: astore        10
      71: iconst_0
      72: istore        11
      74: aload         10
      76: invokevirtual #257                // Method Coord2D.getY:()I
      79: ldc_w         #284                // int 2000000
      82: if_icmpne     89
      85: iconst_1
      86: goto          90
      89: iconst_0
      90: ifeq          45
      93: aload         6
      95: aload         9
      97: invokeinterface #285,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     102: pop
     103: goto          45
     106: aload         6
     108: checkcast     #78                 // class java/util/List
     111: nop
     112: checkcast     #90                 // class java/lang/Iterable
     115: invokestatic  #289                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     118: invokeinterface #294,  1          // InterfaceMethod java/util/Set.size:()I
     123: istore_2
     124: aload_1
     125: astore        4
     127: iconst_0
     128: istore        5
     130: aload         4
     132: astore        6
     134: new           #178                // class java/util/LinkedHashMap
     137: dup
     138: aload         4
     140: invokeinterface #295,  1          // InterfaceMethod java/util/Map.size:()I
     145: invokestatic  #171                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     148: invokespecial #181                // Method java/util/LinkedHashMap."<init>":(I)V
     151: checkcast     #183                // class java/util/Map
     154: astore        7
     156: iconst_0
     157: istore        8
     159: aload         6
     161: invokeinterface #299,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     166: checkcast     #90                 // class java/lang/Iterable
     169: astore        9
     171: iconst_0
     172: istore        10
     174: aload         9
     176: invokeinterface #186,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     181: astore        11
     183: aload         11
     185: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     190: ifeq          291
     193: aload         11
     195: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     200: astore        12
     202: aload         7
     204: aload         12
     206: checkcast     #301                // class java/util/Map$Entry
     209: astore        13
     211: astore        14
     213: iconst_0
     214: istore        15
     216: aload         13
     218: invokeinterface #304,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     223: aload         14
     225: swap
     226: aload         12
     228: checkcast     #301                // class java/util/Map$Entry
     231: astore        16
     233: astore        22
     235: astore        21
     237: iconst_0
     238: istore        17
     240: aload         16
     242: invokeinterface #304,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     247: checkcast     #208                // class Coord2D
     250: astore        18
     252: aload         16
     254: invokeinterface #307,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     259: checkcast     #208                // class Coord2D
     262: astore        19
     264: aload         18
     266: aload         19
     268: invokevirtual #311                // Method Coord2D.manhattenDistance:(LCoord2D;)I
     271: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     274: astore        23
     276: aload         21
     278: aload         22
     280: aload         23
     282: invokeinterface #237,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     287: pop
     288: goto          183
     291: aload         7
     293: nop
     294: nop
     295: astore_3
     296: aload_3
     297: astore        4
     299: nop
     300: iconst_0
     301: istore        5
     303: aload         4
     305: astore        6
     307: new           #279                // class java/util/ArrayList
     310: dup
     311: invokespecial #281                // Method java/util/ArrayList."<init>":()V
     314: checkcast     #283                // class java/util/Collection
     317: astore        7
     319: iconst_0
     320: istore        8
     322: aload         6
     324: astore        9
     326: iconst_0
     327: istore        10
     329: aload         9
     331: invokeinterface #299,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     336: invokeinterface #312,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     341: astore        11
     343: aload         11
     345: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     350: ifeq          443
     353: aload         11
     355: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     360: checkcast     #301                // class java/util/Map$Entry
     363: astore        12
     365: aload         12
     367: astore        13
     369: iconst_0
     370: istore        14
     372: aload         13
     374: astore        15
     376: iconst_0
     377: istore        16
     379: aload         15
     381: invokeinterface #304,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     386: checkcast     #208                // class Coord2D
     389: astore        17
     391: aload         15
     393: invokeinterface #307,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     398: checkcast     #314                // class java/lang/Number
     401: invokevirtual #317                // Method java/lang/Number.intValue:()I
     404: istore        18
     406: aload         17
     408: iload         18
     410: ldc_w         #284                // int 2000000
     413: invokestatic  #319                // Method main$rangeAtY:(LCoord2D;II)LDay15Kt$main$Interval;
     416: dup
     417: ifnull        438
     420: astore        19
     422: iconst_0
     423: istore        20
     425: aload         7
     427: aload         19
     429: invokeinterface #285,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     434: pop
     435: goto          439
     438: pop
     439: nop
     440: goto          343
     443: nop
     444: aload         7
     446: checkcast     #78                 // class java/util/List
     449: nop
     450: invokestatic  #321                // Method main$maxReduce:(Ljava/util/List;)Ljava/util/List;
     453: checkcast     #90                 // class java/lang/Iterable
     456: astore        4
     458: iconst_0
     459: istore        5
     461: aload         4
     463: invokeinterface #186,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     468: astore        6
     470: aload         6
     472: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     477: ifeq          520
     480: aload         6
     482: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     487: astore        7
     489: iload         5
     491: aload         7
     493: checkcast     #56                 // class Day15Kt$main$Interval
     496: astore        8
     498: istore        21
     500: iconst_0
     501: istore        9
     503: aload         8
     505: invokevirtual #322                // Method Day15Kt$main$Interval.size:()I
     508: istore        22
     510: iload         21
     512: iload         22
     514: iadd
     515: istore        5
     517: goto          470
     520: iload         5
     522: iload_2
     523: isub
     524: ireturn

  private static final long main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #273                // Method main$parseSensorsBeacons:(Ljava/util/List;)Ljava/util/Map;
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #178                // class java/util/LinkedHashMap
      13: dup
      14: aload_2
      15: invokeinterface #295,  1          // InterfaceMethod java/util/Map.size:()I
      20: invokestatic  #171                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      23: invokespecial #181                // Method java/util/LinkedHashMap."<init>":(I)V
      26: checkcast     #183                // class java/util/Map
      29: astore        5
      31: iconst_0
      32: istore        6
      34: aload         4
      36: invokeinterface #299,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      41: checkcast     #90                 // class java/lang/Iterable
      44: astore        7
      46: iconst_0
      47: istore        8
      49: aload         7
      51: invokeinterface #186,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        9
      58: aload         9
      60: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          166
      68: aload         9
      70: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        10
      77: aload         5
      79: aload         10
      81: checkcast     #301                // class java/util/Map$Entry
      84: astore        11
      86: astore        12
      88: iconst_0
      89: istore        13
      91: aload         11
      93: invokeinterface #304,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      98: aload         12
     100: swap
     101: aload         10
     103: checkcast     #301                // class java/util/Map$Entry
     106: astore        14
     108: astore        22
     110: astore        21
     112: iconst_0
     113: istore        15
     115: aload         14
     117: invokeinterface #304,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     122: checkcast     #208                // class Coord2D
     125: astore        16
     127: aload         14
     129: invokeinterface #307,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     134: checkcast     #208                // class Coord2D
     137: astore        17
     139: aload         16
     141: aload         17
     143: invokevirtual #311                // Method Coord2D.manhattenDistance:(LCoord2D;)I
     146: invokestatic  #66                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     149: astore        23
     151: aload         21
     153: aload         22
     155: aload         23
     157: invokeinterface #237,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     162: pop
     163: goto          58
     166: aload         5
     168: nop
     169: nop
     170: astore_1
     171: iconst_0
     172: istore_2
     173: iload_2
     174: ldc_w         #357                // int 4000001
     177: if_icmpge     450
     180: aload_1
     181: astore        4
     183: nop
     184: iconst_0
     185: istore        5
     187: aload         4
     189: astore        6
     191: new           #279                // class java/util/ArrayList
     194: dup
     195: invokespecial #281                // Method java/util/ArrayList."<init>":()V
     198: checkcast     #283                // class java/util/Collection
     201: astore        7
     203: iconst_0
     204: istore        8
     206: aload         6
     208: astore        9
     210: iconst_0
     211: istore        10
     213: aload         9
     215: invokeinterface #299,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     220: invokeinterface #312,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     225: astore        11
     227: aload         11
     229: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     234: ifeq          325
     237: aload         11
     239: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     244: checkcast     #301                // class java/util/Map$Entry
     247: astore        12
     249: aload         12
     251: astore        13
     253: iconst_0
     254: istore        14
     256: aload         13
     258: astore        15
     260: iconst_0
     261: istore        16
     263: aload         15
     265: invokeinterface #304,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     270: checkcast     #208                // class Coord2D
     273: astore        17
     275: aload         15
     277: invokeinterface #307,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     282: checkcast     #314                // class java/lang/Number
     285: invokevirtual #317                // Method java/lang/Number.intValue:()I
     288: istore        18
     290: aload         17
     292: iload         18
     294: iload_2
     295: invokestatic  #319                // Method main$rangeAtY:(LCoord2D;II)LDay15Kt$main$Interval;
     298: dup
     299: ifnull        320
     302: astore        19
     304: iconst_0
     305: istore        20
     307: aload         7
     309: aload         19
     311: invokeinterface #285,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     316: pop
     317: goto          321
     320: pop
     321: nop
     322: goto          227
     325: nop
     326: aload         7
     328: checkcast     #78                 // class java/util/List
     331: nop
     332: invokestatic  #321                // Method main$maxReduce:(Ljava/util/List;)Ljava/util/List;
     335: checkcast     #90                 // class java/lang/Iterable
     338: astore        4
     340: nop
     341: iconst_0
     342: istore        5
     344: aload         4
     346: astore        6
     348: aload         6
     350: astore        7
     352: iconst_0
     353: istore        8
     355: aload         7
     357: invokeinterface #186,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     362: astore        9
     364: aload         9
     366: invokeinterface #189,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     371: ifeq          406
     374: aload         9
     376: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     381: astore        10
     383: aload         10
     385: checkcast     #56                 // class Day15Kt$main$Interval
     388: astore        11
     390: iconst_0
     391: istore        12
     393: aload         11
     395: iconst_0
     396: ldc_w         #358                // int 4000000
     399: invokevirtual #361                // Method Day15Kt$main$Interval.limit:(II)V
     402: nop
     403: goto          364
     406: aload         6
     408: nop
     409: checkcast     #78                 // class java/util/List
     412: astore_3
     413: aload_3
     414: invokeinterface #362,  1          // InterfaceMethod java/util/List.size:()I
     419: iconst_1
     420: if_icmple     444
     423: ldc2_w        #363                // long 4000000l
     426: aload_3
     427: invokestatic  #368                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     430: checkcast     #56                 // class Day15Kt$main$Interval
     433: invokevirtual #73                 // Method Day15Kt$main$Interval.getEnd:()I
     436: iconst_1
     437: iadd
     438: i2l
     439: lmul
     440: iload_2
     441: i2l
     442: ladd
     443: lreturn
     444: iinc          2, 1
     447: goto          173
     450: ldc2_w        #369                // long -1l
     453: lreturn
}


fun main() {
    data class Move(val count: Int, val source: Int, val target: Int)
    class CrateStacks(input: List<String>) {
        val stacks = mutableMapOf<Int, ArrayDeque<Char>>()
        val moves = mutableListOf<Move>()

        init {
            var parseMoves = false
            input.forEach { line ->
                if (line.isBlank()) {
                    parseMoves = true
                    return@forEach
                }
                if (parseMoves) {
                    addMove(line)
                    return@forEach
                }
                parseStacks(line)
            }
        }

        fun addMove(line: String) {
            val (c, s, t) = line.split("move ", " from ", " to ").mapNotNull { it.toIntOrNull() }
            moves.add(Move(c, s, t))
        }

        fun parseStacks(line: String) {
            line.forEachIndexed { index, c ->
                if (index % 4 != 1) return@forEachIndexed
                if (c.isDigit()) return
                if (!c.isUpperCase()) return@forEachIndexed
                val stack = index / 4 + 1
                ArrayDeque<String>()
                stacks.compute(stack) { _, v ->
                    val ad = v ?: ArrayDeque()
                    ad.add(c)
                    return@compute ad
                }
            }
        }

        fun doMovesSingle(): CrateStacks {
            moves.forEach { executeMoveSingle(it) }
            return this
        }

        fun doMovesGrouped(): CrateStacks {
            moves.forEach { executeMoveGrouped(it) }
            return this
        }

        private fun executeMoveSingle(move: Move) {
            repeat(move.count) {
                val crate = stacks[move.source]!!.removeFirst()
                stacks[move.target]!!.addFirst(crate)
            }
        }

        private fun executeMoveGrouped(move: Move) {
            for (i in 0 until move.count) {
                val crate = stacks[move.source]!!.removeFirst()
                stacks[move.target]!!.add(i, crate)
            }
        }

        fun getTop(): String {
            return stacks.keys.sorted().mapNotNull { stacks[it]?.first() }.joinToString("")
        }
    }

    fun part1(input: List<String>): String {
        return CrateStacks(input).doMovesSingle().getTop()
    }

    fun part2(input: List<String>): String {
        return CrateStacks(input).doMovesGrouped().getTop()

    }

    val input = readInput("Day05")

    println(part1(input))
    println(part2(input))
}

Compiled from "Day05.kt"
public final class Day05Kt$main$Move {
  private final int count;

  private final int source;

  private final int target;

  public Day05Kt$main$Move(int, 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 count:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field source:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field target:I
      19: return

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

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

  public final int getTarget();
    Code:
       0: aload_0
       1: getfield      #19                 // Field target:I
       4: ireturn

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

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

  public final int component3();
    Code:
       0: aload_0
       1: getfield      #19                 // Field target:I
       4: ireturn

  public final Day05Kt$main$Move copy(int, int, int);
    Code:
       0: new           #2                  // class Day05Kt$main$Move
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: invokespecial #32                 // Method "<init>":(III)V
      10: areturn

  public static Day05Kt$main$Move copy$default(Day05Kt$main$Move, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field count:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field source:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field target:I
      35: istore_3
      36: aload_0
      37: iload_1
      38: iload_2
      39: iload_3
      40: invokevirtual #36                 // Method copy:(III)LDay05Kt$main$Move;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #40                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #41                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #43                 // String Move(count=
       9: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field count:I
      16: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #52                 // String , source=
      21: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field source:I
      28: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #54                 // String , target=
      33: invokevirtual #47                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field target:I
      40: invokevirtual #50                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #57                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #59                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field count:I
       4: invokestatic  #65                 // 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 source:I
      16: invokestatic  #65                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #19                 // Field target:I
      29: invokestatic  #65                 // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: 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 Day05Kt$main$Move
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day05Kt$main$Move
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field count:I
      25: aload_2
      26: getfield      #13                 // Field count:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field source:I
      38: aload_2
      39: getfield      #16                 // Field source:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field target:I
      51: aload_2
      52: getfield      #19                 // Field target:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: iconst_1
      61: ireturn
}

Compiled from "Day05.kt"
public final class Day05Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day05
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method main$part1:(Ljava/util/List;)Ljava/lang/String;
      10: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      13: swap
      14: invokevirtual #30                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      17: aload_0
      18: invokestatic  #33                 // Method main$part2:(Ljava/util/List;)Ljava/lang/String;
      21: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      24: swap
      25: invokevirtual #30                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      28: return

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

  private static final java.lang.String main$part1(java.util.List<java.lang.String>);
    Code:
       0: new           #43                 // class Day05Kt$main$CrateStacks
       3: dup
       4: aload_0
       5: invokespecial #47                 // Method Day05Kt$main$CrateStacks."<init>":(Ljava/util/List;)V
       8: invokevirtual #51                 // Method Day05Kt$main$CrateStacks.doMovesSingle:()LDay05Kt$main$CrateStacks;
      11: invokevirtual #55                 // Method Day05Kt$main$CrateStacks.getTop:()Ljava/lang/String;
      14: areturn

  private static final java.lang.String main$part2(java.util.List<java.lang.String>);
    Code:
       0: new           #43                 // class Day05Kt$main$CrateStacks
       3: dup
       4: aload_0
       5: invokespecial #47                 // Method Day05Kt$main$CrateStacks."<init>":(Ljava/util/List;)V
       8: invokevirtual #58                 // Method Day05Kt$main$CrateStacks.doMovesGrouped:()LDay05Kt$main$CrateStacks;
      11: invokevirtual #55                 // Method Day05Kt$main$CrateStacks.getTop:()Ljava/lang/String;
      14: areturn
}

Compiled from "Day05.kt"
public final class Day05Kt$main$CrateStacks {
  private final java.util.Map<java.lang.Integer, kotlin.collections.ArrayDeque<java.lang.Character>> stacks;

  private final java.util.List<Day05Kt$main$Move> moves;

  public Day05Kt$main$CrateStacks(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: new           #20                 // class java/util/LinkedHashMap
      14: dup
      15: invokespecial #21                 // Method java/util/LinkedHashMap."<init>":()V
      18: checkcast     #23                 // class java/util/Map
      21: putfield      #27                 // Field stacks:Ljava/util/Map;
      24: aload_0
      25: new           #29                 // class java/util/ArrayList
      28: dup
      29: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
      32: checkcast     #32                 // class java/util/List
      35: putfield      #36                 // Field moves:Ljava/util/List;
      38: nop
      39: iconst_0
      40: istore_2
      41: aload_1
      42: checkcast     #38                 // class java/lang/Iterable
      45: astore_3
      46: iconst_0
      47: istore        4
      49: aload_3
      50: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      55: astore        5
      57: aload         5
      59: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      64: ifeq          126
      67: aload         5
      69: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      74: astore        6
      76: aload         6
      78: checkcast     #54                 // class java/lang/String
      81: astore        7
      83: iconst_0
      84: istore        8
      86: aload         7
      88: checkcast     #56                 // class java/lang/CharSequence
      91: invokestatic  #62                 // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      94: ifeq          102
      97: iconst_1
      98: istore_2
      99: goto          122
     102: iload_2
     103: ifeq          115
     106: aload_0
     107: aload         7
     109: invokevirtual #66                 // Method addMove:(Ljava/lang/String;)V
     112: goto          122
     115: aload_0
     116: aload         7
     118: invokevirtual #69                 // Method parseStacks:(Ljava/lang/String;)V
     121: nop
     122: nop
     123: goto          57
     126: nop
     127: nop
     128: return

  public final java.util.Map<java.lang.Integer, kotlin.collections.ArrayDeque<java.lang.Character>> getStacks();
    Code:
       0: aload_0
       1: getfield      #27                 // Field stacks:Ljava/util/Map;
       4: areturn

  public final java.util.List<Day05Kt$main$Move> getMoves();
    Code:
       0: aload_0
       1: getfield      #36                 // Field moves:Ljava/util/List;
       4: areturn

  public final void addMove(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #89                 // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #56                 // class java/lang/CharSequence
      10: iconst_3
      11: anewarray     #54                 // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #91                 // String move
      19: aastore
      20: aload_3
      21: iconst_1
      22: ldc           #93                 // String  from
      24: aastore
      25: aload_3
      26: iconst_2
      27: ldc           #95                 // String  to
      29: aastore
      30: aload_3
      31: iconst_0
      32: iconst_0
      33: bipush        6
      35: aconst_null
      36: invokestatic  #99                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      39: checkcast     #38                 // class java/lang/Iterable
      42: astore_3
      43: iconst_0
      44: istore        4
      46: aload_3
      47: astore        5
      49: new           #29                 // class java/util/ArrayList
      52: dup
      53: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
      56: checkcast     #101                // class java/util/Collection
      59: astore        6
      61: iconst_0
      62: istore        7
      64: aload         5
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      78: astore        10
      80: aload         10
      82: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          148
      90: aload         10
      92: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      97: astore        11
      99: aload         11
     101: astore        12
     103: iconst_0
     104: istore        13
     106: aload         12
     108: checkcast     #54                 // class java/lang/String
     111: astore        14
     113: iconst_0
     114: istore        15
     116: aload         14
     118: invokestatic  #105                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     121: dup
     122: ifnull        143
     125: astore        16
     127: iconst_0
     128: istore        17
     130: aload         6
     132: aload         16
     134: invokeinterface #109,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     139: pop
     140: goto          144
     143: pop
     144: nop
     145: goto          80
     148: nop
     149: aload         6
     151: checkcast     #32                 // class java/util/List
     154: nop
     155: astore_2
     156: aload_2
     157: iconst_0
     158: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     163: checkcast     #115                // class java/lang/Number
     166: invokevirtual #119                // Method java/lang/Number.intValue:()I
     169: istore_3
     170: aload_2
     171: iconst_1
     172: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     177: checkcast     #115                // class java/lang/Number
     180: invokevirtual #119                // Method java/lang/Number.intValue:()I
     183: istore        4
     185: aload_2
     186: iconst_2
     187: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     192: checkcast     #115                // class java/lang/Number
     195: invokevirtual #119                // Method java/lang/Number.intValue:()I
     198: istore        5
     200: aload_0
     201: getfield      #36                 // Field moves:Ljava/util/List;
     204: new           #121                // class Day05Kt$main$Move
     207: dup
     208: iload_3
     209: iload         4
     211: iload         5
     213: invokespecial #124                // Method Day05Kt$main$Move."<init>":(III)V
     216: invokeinterface #125,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     221: pop
     222: return

  public final void parseStacks(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #89                 // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #56                 // class java/lang/CharSequence
      10: astore_2
      11: iconst_0
      12: istore_3
      13: iconst_0
      14: istore        4
      16: iconst_0
      17: istore        5
      19: iload         5
      21: aload_2
      22: invokeinterface #147,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      27: if_icmpge     130
      30: aload_2
      31: iload         5
      33: invokeinterface #151,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      38: istore        6
      40: iload         4
      42: iinc          4, 1
      45: iload         6
      47: istore        7
      49: istore        8
      51: iconst_0
      52: istore        9
      54: iload         8
      56: iconst_4
      57: irem
      58: iconst_1
      59: if_icmpne     123
      62: iload         7
      64: invokestatic  #157                // Method java/lang/Character.isDigit:(C)Z
      67: ifeq          71
      70: return
      71: iload         7
      73: invokestatic  #160                // Method java/lang/Character.isUpperCase:(C)Z
      76: ifeq          123
      79: iload         8
      81: iconst_4
      82: idiv
      83: iconst_1
      84: iadd
      85: istore        10
      87: new           #162                // class kotlin/collections/ArrayDeque
      90: dup
      91: invokespecial #163                // Method kotlin/collections/ArrayDeque."<init>":()V
      94: pop
      95: aload_0
      96: getfield      #27                 // Field stacks:Ljava/util/Map;
      99: iload         10
     101: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: iload         7
     106: invokedynamic #187,  0            // InvokeDynamic #0:invoke:(C)Lkotlin/jvm/functions/Function2;
     111: invokedynamic #198,  0            // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     116: invokeinterface #202,  3          // InterfaceMethod java/util/Map.compute:(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     121: pop
     122: nop
     123: nop
     124: iinc          5, 1
     127: goto          19
     130: nop
     131: return

  public final Day05Kt$main$CrateStacks doMovesSingle();
    Code:
       0: aload_0
       1: getfield      #36                 // Field moves:Ljava/util/List;
       4: checkcast     #38                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          54
      26: aload_3
      27: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #121                // class Day05Kt$main$Move
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload_0
      45: aload         5
      47: invokespecial #217                // Method executeMoveSingle:(LDay05Kt$main$Move;)V
      50: nop
      51: goto          17
      54: nop
      55: aload_0
      56: areturn

  public final Day05Kt$main$CrateStacks doMovesGrouped();
    Code:
       0: aload_0
       1: getfield      #36                 // Field moves:Ljava/util/List;
       4: checkcast     #38                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      16: astore_3
      17: aload_3
      18: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          54
      26: aload_3
      27: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        4
      34: aload         4
      36: checkcast     #121                // class Day05Kt$main$Move
      39: astore        5
      41: iconst_0
      42: istore        6
      44: aload_0
      45: aload         5
      47: invokespecial #223                // Method executeMoveGrouped:(LDay05Kt$main$Move;)V
      50: nop
      51: goto          17
      54: nop
      55: aload_0
      56: areturn

  private final void executeMoveSingle(Day05Kt$main$Move);
    Code:
       0: aload_1
       1: invokevirtual #227                // Method Day05Kt$main$Move.getCount:()I
       4: istore_2
       5: iconst_0
       6: istore_3
       7: iload_3
       8: iload_2
       9: if_icmpge     90
      12: iload_3
      13: istore        4
      15: iconst_0
      16: istore        5
      18: aload_0
      19: getfield      #27                 // Field stacks:Ljava/util/Map;
      22: aload_1
      23: invokevirtual #230                // Method Day05Kt$main$Move.getSource:()I
      26: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: invokeinterface #233,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      34: dup
      35: invokestatic  #237                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      38: checkcast     #162                // class kotlin/collections/ArrayDeque
      41: invokevirtual #240                // Method kotlin/collections/ArrayDeque.removeFirst:()Ljava/lang/Object;
      44: checkcast     #153                // class java/lang/Character
      47: invokevirtual #244                // Method java/lang/Character.charValue:()C
      50: istore        6
      52: aload_0
      53: getfield      #27                 // Field stacks:Ljava/util/Map;
      56: aload_1
      57: invokevirtual #247                // Method Day05Kt$main$Move.getTarget:()I
      60: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      63: invokeinterface #233,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      68: dup
      69: invokestatic  #237                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      72: checkcast     #162                // class kotlin/collections/ArrayDeque
      75: iload         6
      77: invokestatic  #250                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      80: invokevirtual #253                // Method kotlin/collections/ArrayDeque.addFirst:(Ljava/lang/Object;)V
      83: nop
      84: iinc          3, 1
      87: goto          7
      90: return

  private final void executeMoveGrouped(Day05Kt$main$Move);
    Code:
       0: iconst_0
       1: istore_2
       2: aload_1
       3: invokevirtual #227                // Method Day05Kt$main$Move.getCount:()I
       6: istore_3
       7: iload_2
       8: iload_3
       9: if_icmpge     84
      12: aload_0
      13: getfield      #27                 // Field stacks:Ljava/util/Map;
      16: aload_1
      17: invokevirtual #230                // Method Day05Kt$main$Move.getSource:()I
      20: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokeinterface #233,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      28: dup
      29: invokestatic  #237                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      32: checkcast     #162                // class kotlin/collections/ArrayDeque
      35: invokevirtual #240                // Method kotlin/collections/ArrayDeque.removeFirst:()Ljava/lang/Object;
      38: checkcast     #153                // class java/lang/Character
      41: invokevirtual #244                // Method java/lang/Character.charValue:()C
      44: istore        4
      46: aload_0
      47: getfield      #27                 // Field stacks:Ljava/util/Map;
      50: aload_1
      51: invokevirtual #247                // Method Day05Kt$main$Move.getTarget:()I
      54: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      57: invokeinterface #233,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      62: dup
      63: invokestatic  #237                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      66: checkcast     #162                // class kotlin/collections/ArrayDeque
      69: iload_2
      70: iload         4
      72: invokestatic  #250                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      75: invokevirtual #259                // Method kotlin/collections/ArrayDeque.add:(ILjava/lang/Object;)V
      78: iinc          2, 1
      81: goto          7
      84: return

  public final java.lang.String getTop();
    Code:
       0: aload_0
       1: getfield      #27                 // Field stacks:Ljava/util/Map;
       4: invokeinterface #266,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
       9: checkcast     #38                 // class java/lang/Iterable
      12: invokestatic  #272                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
      15: checkcast     #38                 // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #29                 // class java/util/ArrayList
      26: dup
      27: invokespecial #30                 // Method java/util/ArrayList."<init>":()V
      30: checkcast     #101                // class java/util/Collection
      33: astore        4
      35: iconst_0
      36: istore        5
      38: aload_3
      39: astore        6
      41: iconst_0
      42: istore        7
      44: aload         6
      46: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      51: astore        8
      53: aload         8
      55: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          151
      63: aload         8
      65: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      70: astore        9
      72: aload         9
      74: astore        10
      76: iconst_0
      77: istore        11
      79: aload         10
      81: checkcast     #115                // class java/lang/Number
      84: invokevirtual #119                // Method java/lang/Number.intValue:()I
      87: istore        12
      89: iconst_0
      90: istore        13
      92: aload_0
      93: getfield      #27                 // Field stacks:Ljava/util/Map;
      96: iload         12
      98: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     101: invokeinterface #233,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     106: checkcast     #162                // class kotlin/collections/ArrayDeque
     109: dup
     110: ifnull        122
     113: invokevirtual #275                // Method kotlin/collections/ArrayDeque.first:()Ljava/lang/Object;
     116: checkcast     #153                // class java/lang/Character
     119: goto          124
     122: pop
     123: aconst_null
     124: dup
     125: ifnull        146
     128: astore        14
     130: iconst_0
     131: istore        15
     133: aload         4
     135: aload         14
     137: invokeinterface #109,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     142: pop
     143: goto          147
     146: pop
     147: nop
     148: goto          53
     151: nop
     152: aload         4
     154: checkcast     #32                 // class java/util/List
     157: nop
     158: checkcast     #38                 // class java/lang/Iterable
     161: ldc_w         #277                // String
     164: checkcast     #56                 // class java/lang/CharSequence
     167: aconst_null
     168: aconst_null
     169: iconst_0
     170: aconst_null
     171: aconst_null
     172: bipush        62
     174: aconst_null
     175: invokestatic  #281                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     178: areturn

  private static final kotlin.collections.ArrayDeque parseStacks$lambda$4$lambda$2(char, java.lang.Integer, kotlin.collections.ArrayDeque);
    Code:
       0: aload_1
       1: ldc_w         #284                // String <unused var>
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_2
       8: dup
       9: ifnonnull     20
      12: pop
      13: new           #162                // class kotlin/collections/ArrayDeque
      16: dup
      17: invokespecial #163                // Method kotlin/collections/ArrayDeque."<init>":()V
      20: astore_3
      21: aload_3
      22: iload_0
      23: invokestatic  #250                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      26: invokevirtual #285                // Method kotlin/collections/ArrayDeque.add:(Ljava/lang/Object;)Z
      29: pop
      30: aload_3
      31: areturn

  private static final kotlin.collections.ArrayDeque parseStacks$lambda$4$lambda$3(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #293,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #162                // class kotlin/collections/ArrayDeque
      11: areturn
}


fun main() {
    val oneX = Coord2D(1, 0)
    val oneY = Coord2D(0, 1)

    data class Motion(val dir: Char, val count: Int)

    fun mapToMotions(input: List<String>): List<Motion> {
        return input.map {
            val (d, c) = it.split(" ")
            Motion(d.first(), c.toInt())
        }
    }

    fun moveInDir(coor: Coord2D, dir: Char): Coord2D {
        return when (dir) {
            'L' -> Coord2D(coor.x - 1, coor.y)
            'R' -> Coord2D(coor.x + 1, coor.y)
            'U' -> Coord2D(coor.x, coor.y + 1)
            'D' -> Coord2D(coor.x, coor.y - 1)
            else -> error("bad direction $dir")
        }
    }

    fun follow(head: Coord2D, tail: Coord2D): Coord2D {
        var newTail = tail
        while (head != newTail && !newTail.adjacentTo(head)) {
            when {
                head.x < newTail.x -> newTail -= oneX
                head.x > newTail.x -> newTail += oneX
            }
            when {
                head.y < newTail.y -> newTail -= oneY
                head.y > newTail.y -> newTail += oneY
            }
        }
        return newTail
    }

    fun part1(input: List<Motion>): Int {
        val visited = mutableSetOf<Coord2D>()
        var head = Coord2D(0, 0)
        var tail = Coord2D(0, 0)
        visited.add(tail)
        input.forEach { m ->
            repeat(m.count) {
                head = moveInDir(head, m.dir)
                tail = follow(head, tail)
                visited.add(tail)
            }
        }
        return visited.size
    }

    fun part2(input: List<Motion>): Int {
        val visited = mutableSetOf<Coord2D>()
        val rope = MutableList(10) { Coord2D(0, 0) }
        visited.add(rope.last())
        input.forEach { m ->
            repeat(m.count) {
                rope[0] = moveInDir(rope[0], m.dir)
                for (i in 1..rope.lastIndex) {
                    rope[i] = follow(rope[i - 1], rope[i])
                }
                visited.add(rope.last())
            }
        }
        return visited.size
    }

    val testInput1 = mapToMotions(readInput("Day09test1"))
    check(part1(testInput1) == 13)
    check(part2(testInput1) == 1)
    val testInput2 = mapToMotions(readInput("Day09test2"))
    check(part2(testInput2) == 36)

    val input = mapToMotions(readInput("Day09"))

    println(part1(input))
    println(part2(input))
}

Compiled from "Day09.kt"
public final class Day09Kt$main$Motion {
  private final char dir;

  private final int count;

  public Day09Kt$main$Motion(char, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field dir:C
       9: aload_0
      10: iload_2
      11: putfield      #17                 // Field count:I
      14: return

  public final char getDir();
    Code:
       0: aload_0
       1: getfield      #13                 // Field dir:C
       4: ireturn

  public final int getCount();
    Code:
       0: aload_0
       1: getfield      #17                 // Field count:I
       4: ireturn

  public final char component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field dir:C
       4: ireturn

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

  public final Day09Kt$main$Motion copy(char, int);
    Code:
       0: new           #2                  // class Day09Kt$main$Motion
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #29                 // Method "<init>":(CI)V
       9: areturn

  public static Day09Kt$main$Motion copy$default(Day09Kt$main$Motion, char, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #13                 // Field dir:C
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #17                 // Field count:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #33                 // Method copy:(CI)LDay09Kt$main$Motion;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #37                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #38                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #40                 // String Motion(dir=
       9: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field dir:C
      16: invokevirtual #47                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      19: ldc           #49                 // String , count=
      21: invokevirtual #44                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #17                 // Field count:I
      28: invokevirtual #52                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #47                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #54                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field dir:C
       4: invokestatic  #60                 // Method java/lang/Character.hashCode:(C)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #17                 // Field count:I
      16: invokestatic  #65                 // 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 Day09Kt$main$Motion
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day09Kt$main$Motion
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field dir:C
      25: aload_2
      26: getfield      #13                 // Field dir:C
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #17                 // Field count:I
      38: aload_2
      39: getfield      #17                 // Field count:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "Day09.kt"
public final class Day09Kt {
  public static final void main();
    Code:
       0: new           #8                  // class Coord2D
       3: dup
       4: iconst_1
       5: iconst_0
       6: invokespecial #12                 // Method Coord2D."<init>":(II)V
       9: astore_0
      10: new           #8                  // class Coord2D
      13: dup
      14: iconst_0
      15: iconst_1
      16: invokespecial #12                 // Method Coord2D."<init>":(II)V
      19: astore_1
      20: ldc           #14                 // String Day09test1
      22: invokestatic  #20                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      25: invokestatic  #24                 // Method main$mapToMotions:(Ljava/util/List;)Ljava/util/List;
      28: astore_2
      29: aload_0
      30: aload_1
      31: aload_2
      32: invokestatic  #28                 // Method main$part1:(LCoord2D;LCoord2D;Ljava/util/List;)I
      35: bipush        13
      37: if_icmpne     44
      40: iconst_1
      41: goto          45
      44: iconst_0
      45: ifne          58
      48: new           #30                 // class java/lang/IllegalStateException
      51: dup
      52: ldc           #32                 // String Check failed.
      54: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      57: athrow
      58: aload_0
      59: aload_1
      60: aload_2
      61: invokestatic  #38                 // Method main$part2:(LCoord2D;LCoord2D;Ljava/util/List;)I
      64: iconst_1
      65: if_icmpne     72
      68: iconst_1
      69: goto          73
      72: iconst_0
      73: ifne          86
      76: new           #30                 // class java/lang/IllegalStateException
      79: dup
      80: ldc           #32                 // String Check failed.
      82: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      85: athrow
      86: ldc           #40                 // String Day09test2
      88: invokestatic  #20                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      91: invokestatic  #24                 // Method main$mapToMotions:(Ljava/util/List;)Ljava/util/List;
      94: astore_3
      95: aload_0
      96: aload_1
      97: aload_3
      98: invokestatic  #38                 // Method main$part2:(LCoord2D;LCoord2D;Ljava/util/List;)I
     101: bipush        36
     103: if_icmpne     110
     106: iconst_1
     107: goto          111
     110: iconst_0
     111: ifne          124
     114: new           #30                 // class java/lang/IllegalStateException
     117: dup
     118: ldc           #32                 // String Check failed.
     120: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     123: athrow
     124: ldc           #42                 // String Day09
     126: invokestatic  #20                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
     129: invokestatic  #24                 // Method main$mapToMotions:(Ljava/util/List;)Ljava/util/List;
     132: astore        4
     134: aload_0
     135: aload_1
     136: aload         4
     138: invokestatic  #28                 // Method main$part1:(LCoord2D;LCoord2D;Ljava/util/List;)I
     141: istore        5
     143: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     146: iload         5
     148: invokevirtual #54                 // Method java/io/PrintStream.println:(I)V
     151: aload_0
     152: aload_1
     153: aload         4
     155: invokestatic  #38                 // Method main$part2:(LCoord2D;LCoord2D;Ljava/util/List;)I
     158: istore        5
     160: getstatic     #48                 // Field java/lang/System.out:Ljava/io/PrintStream;
     163: iload         5
     165: invokevirtual #54                 // Method java/io/PrintStream.println:(I)V
     168: return

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

  private static final java.util.List<Day09Kt$main$Motion> main$mapToMotions(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #71                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #73                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #83                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          158
      48: aload         6
      50: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #99                 // class java/lang/String
      64: astore        8
      66: astore        13
      68: iconst_0
      69: istore        9
      71: aload         8
      73: checkcast     #101                // class java/lang/CharSequence
      76: iconst_1
      77: anewarray     #99                 // class java/lang/String
      80: astore        10
      82: aload         10
      84: iconst_0
      85: ldc           #103                // String
      87: aastore
      88: aload         10
      90: iconst_0
      91: iconst_0
      92: bipush        6
      94: aconst_null
      95: invokestatic  #109                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      98: astore        11
     100: aload         11
     102: iconst_0
     103: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     108: checkcast     #99                 // class java/lang/String
     111: astore        10
     113: aload         11
     115: iconst_1
     116: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     121: checkcast     #99                 // class java/lang/String
     124: astore        12
     126: new           #115                // class Day09Kt$main$Motion
     129: dup
     130: aload         10
     132: checkcast     #101                // class java/lang/CharSequence
     135: invokestatic  #119                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     138: aload         12
     140: invokestatic  #125                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     143: invokespecial #128                // Method Day09Kt$main$Motion."<init>":(CI)V
     146: aload         13
     148: swap
     149: invokeinterface #132,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     154: pop
     155: goto          38
     158: aload         4
     160: checkcast     #63                 // class java/util/List
     163: nop
     164: areturn

  private static final Coord2D main$moveInDir(Coord2D, char);
    Code:
       0: iload_1
       1: lookupswitch  { // 4
                    68: 104
                    76: 44
                    82: 64
                    85: 84
               default: 124
          }
      44: new           #8                  // class Coord2D
      47: dup
      48: aload_0
      49: invokevirtual #153                // Method Coord2D.getX:()I
      52: iconst_1
      53: isub
      54: aload_0
      55: invokevirtual #156                // Method Coord2D.getY:()I
      58: invokespecial #12                 // Method Coord2D."<init>":(II)V
      61: goto          154
      64: new           #8                  // class Coord2D
      67: dup
      68: aload_0
      69: invokevirtual #153                // Method Coord2D.getX:()I
      72: iconst_1
      73: iadd
      74: aload_0
      75: invokevirtual #156                // Method Coord2D.getY:()I
      78: invokespecial #12                 // Method Coord2D."<init>":(II)V
      81: goto          154
      84: new           #8                  // class Coord2D
      87: dup
      88: aload_0
      89: invokevirtual #153                // Method Coord2D.getX:()I
      92: aload_0
      93: invokevirtual #156                // Method Coord2D.getY:()I
      96: iconst_1
      97: iadd
      98: invokespecial #12                 // Method Coord2D."<init>":(II)V
     101: goto          154
     104: new           #8                  // class Coord2D
     107: dup
     108: aload_0
     109: invokevirtual #153                // Method Coord2D.getX:()I
     112: aload_0
     113: invokevirtual #156                // Method Coord2D.getY:()I
     116: iconst_1
     117: isub
     118: invokespecial #12                 // Method Coord2D."<init>":(II)V
     121: goto          154
     124: new           #30                 // class java/lang/IllegalStateException
     127: dup
     128: new           #158                // class java/lang/StringBuilder
     131: dup
     132: invokespecial #160                // Method java/lang/StringBuilder."<init>":()V
     135: ldc           #162                // String bad direction
     137: invokevirtual #166                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     140: iload_1
     141: invokevirtual #169                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     144: invokevirtual #173                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     147: invokevirtual #174                // Method java/lang/Object.toString:()Ljava/lang/String;
     150: invokespecial #35                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     153: athrow
     154: areturn

  private static final Coord2D main$follow(Coord2D, Coord2D, Coord2D, Coord2D);
    Code:
       0: aload_3
       1: astore        4
       3: aload_2
       4: aload         4
       6: invokestatic  #185                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       9: ifne          112
      12: aload         4
      14: aload_2
      15: invokevirtual #189                // Method Coord2D.adjacentTo:(LCoord2D;)Z
      18: ifne          112
      21: nop
      22: aload_2
      23: invokevirtual #153                // Method Coord2D.getX:()I
      26: aload         4
      28: invokevirtual #153                // Method Coord2D.getX:()I
      31: if_icmpge     45
      34: aload         4
      36: aload_0
      37: invokevirtual #193                // Method Coord2D.minus:(LCoord2D;)LCoord2D;
      40: astore        4
      42: goto          65
      45: aload_2
      46: invokevirtual #153                // Method Coord2D.getX:()I
      49: aload         4
      51: invokevirtual #153                // Method Coord2D.getX:()I
      54: if_icmple     65
      57: aload         4
      59: aload_0
      60: invokevirtual #196                // Method Coord2D.plus:(LCoord2D;)LCoord2D;
      63: astore        4
      65: nop
      66: aload_2
      67: invokevirtual #156                // Method Coord2D.getY:()I
      70: aload         4
      72: invokevirtual #156                // Method Coord2D.getY:()I
      75: if_icmpge     89
      78: aload         4
      80: aload_1
      81: invokevirtual #193                // Method Coord2D.minus:(LCoord2D;)LCoord2D;
      84: astore        4
      86: goto          3
      89: aload_2
      90: invokevirtual #156                // Method Coord2D.getY:()I
      93: aload         4
      95: invokevirtual #156                // Method Coord2D.getY:()I
      98: if_icmple     3
     101: aload         4
     103: aload_1
     104: invokevirtual #196                // Method Coord2D.plus:(LCoord2D;)LCoord2D;
     107: astore        4
     109: goto          3
     112: aload         4
     114: areturn

  private static final int main$part1(Coord2D, Coord2D, java.util.List<Day09Kt$main$Motion>);
    Code:
       0: new           #202                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #203                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #205                // class java/util/Set
      10: astore_3
      11: aconst_null
      12: astore        4
      14: new           #8                  // class Coord2D
      17: dup
      18: iconst_0
      19: iconst_0
      20: invokespecial #12                 // Method Coord2D."<init>":(II)V
      23: astore        4
      25: aconst_null
      26: astore        5
      28: new           #8                  // class Coord2D
      31: dup
      32: iconst_0
      33: iconst_0
      34: invokespecial #12                 // Method Coord2D."<init>":(II)V
      37: astore        5
      39: aload_3
      40: aload         5
      42: invokeinterface #206,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      47: pop
      48: aload_2
      49: checkcast     #71                 // class java/lang/Iterable
      52: astore        6
      54: iconst_0
      55: istore        7
      57: aload         6
      59: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        8
      66: aload         8
      68: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          163
      76: aload         8
      78: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        9
      85: aload         9
      87: checkcast     #115                // class Day09Kt$main$Motion
      90: astore        10
      92: iconst_0
      93: istore        11
      95: aload         10
      97: invokevirtual #209                // Method Day09Kt$main$Motion.getCount:()I
     100: istore        12
     102: iconst_0
     103: istore        13
     105: iload         13
     107: iload         12
     109: if_icmpge     158
     112: iload         13
     114: istore        14
     116: iconst_0
     117: istore        15
     119: aload         4
     121: aload         10
     123: invokevirtual #213                // Method Day09Kt$main$Motion.getDir:()C
     126: invokestatic  #215                // Method main$moveInDir:(LCoord2D;C)LCoord2D;
     129: astore        4
     131: aload_0
     132: aload_1
     133: aload         4
     135: aload         5
     137: invokestatic  #217                // Method main$follow:(LCoord2D;LCoord2D;LCoord2D;LCoord2D;)LCoord2D;
     140: astore        5
     142: aload_3
     143: aload         5
     145: invokeinterface #206,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     150: pop
     151: nop
     152: iinc          13, 1
     155: goto          105
     158: nop
     159: nop
     160: goto          66
     163: nop
     164: aload_3
     165: invokeinterface #220,  1          // InterfaceMethod java/util/Set.size:()I
     170: ireturn

  private static final int main$part2(Coord2D, Coord2D, java.util.List<Day09Kt$main$Motion>);
    Code:
       0: new           #202                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #203                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #205                // class java/util/Set
      10: astore_3
      11: bipush        10
      13: istore        5
      15: new           #73                 // class java/util/ArrayList
      18: dup
      19: iload         5
      21: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
      24: astore        6
      26: iconst_0
      27: istore        7
      29: iload         7
      31: iload         5
      33: if_icmpge     73
      36: iload         7
      38: istore        8
      40: aload         6
      42: iload         8
      44: istore        9
      46: astore        17
      48: iconst_0
      49: istore        10
      51: new           #8                  // class Coord2D
      54: dup
      55: iconst_0
      56: iconst_0
      57: invokespecial #12                 // Method Coord2D."<init>":(II)V
      60: aload         17
      62: swap
      63: invokevirtual #230                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      66: pop
      67: iinc          7, 1
      70: goto          29
      73: aload         6
      75: checkcast     #63                 // class java/util/List
      78: astore        4
      80: aload_3
      81: aload         4
      83: invokestatic  #234                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      86: invokeinterface #206,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      91: pop
      92: aload_2
      93: checkcast     #71                 // class java/lang/Iterable
      96: astore        5
      98: iconst_0
      99: istore        6
     101: aload         5
     103: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     108: astore        7
     110: aload         7
     112: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     117: ifeq          286
     120: aload         7
     122: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     127: astore        8
     129: aload         8
     131: checkcast     #115                // class Day09Kt$main$Motion
     134: astore        9
     136: iconst_0
     137: istore        10
     139: aload         9
     141: invokevirtual #209                // Method Day09Kt$main$Motion.getCount:()I
     144: istore        11
     146: iconst_0
     147: istore        12
     149: iload         12
     151: iload         11
     153: if_icmpge     281
     156: iload         12
     158: istore        13
     160: iconst_0
     161: istore        14
     163: aload         4
     165: iconst_0
     166: aload         4
     168: iconst_0
     169: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     174: checkcast     #8                  // class Coord2D
     177: aload         9
     179: invokevirtual #213                // Method Day09Kt$main$Motion.getDir:()C
     182: invokestatic  #215                // Method main$moveInDir:(LCoord2D;C)LCoord2D;
     185: invokeinterface #238,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     190: pop
     191: iconst_1
     192: istore        15
     194: aload         4
     196: invokestatic  #242                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     199: istore        16
     201: iload         15
     203: iload         16
     205: if_icmpgt     262
     208: aload         4
     210: iload         15
     212: aload_0
     213: aload_1
     214: aload         4
     216: iload         15
     218: iconst_1
     219: isub
     220: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     225: checkcast     #8                  // class Coord2D
     228: aload         4
     230: iload         15
     232: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     237: checkcast     #8                  // class Coord2D
     240: invokestatic  #217                // Method main$follow:(LCoord2D;LCoord2D;LCoord2D;LCoord2D;)LCoord2D;
     243: invokeinterface #238,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     248: pop
     249: iload         15
     251: iload         16
     253: if_icmpeq     262
     256: iinc          15, 1
     259: goto          208
     262: aload_3
     263: aload         4
     265: invokestatic  #234                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     268: invokeinterface #206,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     273: pop
     274: nop
     275: iinc          12, 1
     278: goto          149
     281: nop
     282: nop
     283: goto          110
     286: nop
     287: aload_3
     288: invokeinterface #220,  1          // InterfaceMethod java/util/Set.size:()I
     293: ireturn
}