import java.util.Comparator

fun main() {
    class TreeNode(
        val value: Int?,
        val parent: TreeNode?,
        val str: String?,
        var children: MutableList<TreeNode> = mutableListOf()
    )

    class TreeNodeComparator(val f: (o1: TreeNode?, o2: TreeNode?) -> Int) : Comparator<TreeNode> {
        override fun compare(o1: TreeNode?, o2: TreeNode?): Int {
            return f(o1, o2)
        }
    }

    fun parseTree(input: String): TreeNode {
        val root = TreeNode(null, null, input)

        var currentNode = root
        var level = 0

        val size = input.length
        var i = 0
        while (i < size) {
            var c = input[i]
            when (c) {
                '[' -> {
                    val child = TreeNode(null, currentNode, null)
                    currentNode.children.add(child)
                    currentNode = child
                    level++
                }
                ']' -> {
                    currentNode = currentNode.parent!!
                    level--
                }
                ',' -> {
                }
                in '0'..'9' -> {
                    var number = ""
                    while (c in '0'..'9') {
                        number += c
                        ++i
                        c = input[i]
                    }
                    --i
                    val child = TreeNode(number.toInt(), currentNode, null)
                    currentNode.children.add(child)
                }
            }
            ++i
        }

        return root
    }

    fun parse(input: List<String>): List<Pair<TreeNode, TreeNode>> {
        return input
            .chunked(3)
            .map { chunk ->
                parseTree(chunk[0]) to parseTree(chunk[1])
            }
    }

    fun compare(left: Int, right: Int): Boolean? {
        if (left == right) {
            return null
        }

        return left < right
    }

    fun compare(left: TreeNode, right: TreeNode): Boolean? {
        if (left.value != null && right.value != null) {
            return compare(left.value, right.value)
        }

        if (left.value == null && right.value == null) {
            var i = 0
            while (i < left.children.size || i < right.children.size) {
                if (left.children.size < right.children.size && i >= left.children.size) {
                    return true
                }

                if (left.children.size > right.children.size && i >= right.children.size) {
                    return false
                }

                val leftChild = left.children[i]
                val rightChild = right.children[i]
                val result = compare(leftChild, rightChild)
                if (result != null) {
                    return result
                }

                ++i
            }
        }

        if (left.value != null) {
            val subNode = TreeNode(null, left.parent, null)
            val subChild = TreeNode(left.value, subNode, null)
            subNode.children.add(subChild)
            return compare(subNode, right)
        }

        if (right.value != null) {
            val subNode = TreeNode(null, right.parent, null)
            val subChild = TreeNode(right.value, subNode, null)
            subNode.children.add(subChild)
            return compare(left, subNode)
        }

        return null
    }

    fun part1(input: List<String>): Int {
        val pairs = parse(input)
        return pairs
            .map { item -> compare(item.first, item.second) }
            .mapIndexed { index, r -> if (r == true) index + 1 else 0 }
            .sum()
    }

    fun part2(input: List<String>): Int {
        val input1 = input.toMutableList()
        input1.add("\n")
        input1.add("[[2]]")
        input1.add("[[6]]")
        input1.add("\n")
        val pairs = parse(input1)
        val comparator = TreeNodeComparator { o1, o2 ->
            when (compare(o1!!, o2!!)) {
                true -> -1
                false -> 1
                else -> 0
            }
        }

        return pairs
            .flatMap { item -> listOf(item.first, item.second) }
            .sortedWith(comparator)
            .mapIndexed { index, treeNode ->
                if (treeNode.str == "[[2]]" || treeNode.str == "[[6]]") {
                    index + 1
                } else {
                    1
                }
            }
            .reduce { acc, i -> acc * i }
    }

    val testInput = readInput("Day13_test")
    assert(part1(testInput), 13)
    assert(part2(testInput), 140)

    val input = readInput("Day13")
    println(part1(input))
    println(part2(input))
}

Compiled from "Day13.kt"
public final class Day13Kt$main$TreeNodeComparator implements java.util.Comparator<Day13Kt$main$TreeNode> {
  private final kotlin.jvm.functions.Function2<Day13Kt$main$TreeNode, Day13Kt$main$TreeNode, java.lang.Integer> f;

  public Day13Kt$main$TreeNodeComparator(kotlin.jvm.functions.Function2<? super Day13Kt$main$TreeNode, ? super Day13Kt$main$TreeNode, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #12                 // String f
       3: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #21                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #24                 // Field f:Lkotlin/jvm/functions/Function2;
      15: return

  public final kotlin.jvm.functions.Function2<Day13Kt$main$TreeNode, Day13Kt$main$TreeNode, java.lang.Integer> getF();
    Code:
       0: aload_0
       1: getfield      #24                 // Field f:Lkotlin/jvm/functions/Function2;
       4: areturn

  public int compare(Day13Kt$main$TreeNode, Day13Kt$main$TreeNode);
    Code:
       0: aload_0
       1: getfield      #24                 // Field f:Lkotlin/jvm/functions/Function2;
       4: aload_1
       5: aload_2
       6: invokeinterface #37,  3           // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      11: checkcast     #39                 // class java/lang/Number
      14: invokevirtual #43                 // Method java/lang/Number.intValue:()I
      17: ireturn

  public int compare(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #49                 // class Day13Kt$main$TreeNode
       5: aload_2
       6: checkcast     #49                 // class Day13Kt$main$TreeNode
       9: invokevirtual #51                 // Method compare:(LDay13Kt$main$TreeNode;LDay13Kt$main$TreeNode;)I
      12: ireturn
}

Compiled from "Day13.kt"
public final class Day13Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day13_test
       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: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: bipush        13
      15: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: invokestatic  #28                 // Method UtilsKt.assert:(Ljava/lang/Object;Ljava/lang/Object;)V
      21: aload_0
      22: invokestatic  #31                 // Method main$part2:(Ljava/util/List;)I
      25: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      28: sipush        140
      31: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: invokestatic  #28                 // Method UtilsKt.assert:(Ljava/lang/Object;Ljava/lang/Object;)V
      37: ldc           #33                 // String Day13
      39: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      42: astore_1
      43: aload_1
      44: invokestatic  #18                 // Method main$part1:(Ljava/util/List;)I
      47: istore_2
      48: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
      51: iload_2
      52: invokevirtual #45                 // Method java/io/PrintStream.println:(I)V
      55: aload_1
      56: invokestatic  #31                 // Method main$part2:(Ljava/util/List;)I
      59: istore_2
      60: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
      63: iload_2
      64: invokevirtual #45                 // Method java/io/PrintStream.println:(I)V
      67: return

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

  private static final Day13Kt$main$TreeNode main$parseTree(java.lang.String);
    Code:
       0: new           #57                 // class Day13Kt$main$TreeNode
       3: dup
       4: aconst_null
       5: aconst_null
       6: aload_0
       7: aconst_null
       8: bipush        8
      10: aconst_null
      11: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      14: astore_1
      15: aload_1
      16: astore_2
      17: iconst_0
      18: istore_3
      19: aload_0
      20: invokevirtual #67                 // Method java/lang/String.length:()I
      23: istore        4
      25: iconst_0
      26: istore        5
      28: iload         5
      30: iload         4
      32: if_icmpge     256
      35: aload_0
      36: iload         5
      38: invokevirtual #71                 // Method java/lang/String.charAt:(I)C
      41: istore        6
      43: iload         6
      45: istore        7
      47: iload         7
      49: bipush        91
      51: if_icmpne     91
      54: new           #57                 // class Day13Kt$main$TreeNode
      57: dup
      58: aconst_null
      59: aload_2
      60: aconst_null
      61: aconst_null
      62: bipush        8
      64: aconst_null
      65: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      68: astore        8
      70: aload_2
      71: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
      74: aload         8
      76: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      81: pop
      82: aload         8
      84: astore_2
      85: iinc          3, 1
      88: goto          250
      91: iload         7
      93: bipush        93
      95: if_icmpne     113
      98: aload_2
      99: invokevirtual #85                 // Method Day13Kt$main$TreeNode.getParent:()LDay13Kt$main$TreeNode;
     102: dup
     103: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     106: astore_2
     107: iinc          3, -1
     110: goto          250
     113: iload         7
     115: bipush        44
     117: if_icmpeq     250
     120: bipush        48
     122: iload         7
     124: if_icmpgt     142
     127: iload         7
     129: bipush        58
     131: if_icmpge     138
     134: iconst_1
     135: goto          143
     138: iconst_0
     139: goto          143
     142: iconst_0
     143: ifeq          250
     146: ldc           #93                 // String
     148: astore        8
     150: bipush        48
     152: iload         6
     154: if_icmpgt     172
     157: iload         6
     159: bipush        58
     161: if_icmpge     168
     164: iconst_1
     165: goto          173
     168: iconst_0
     169: goto          173
     172: iconst_0
     173: ifeq          212
     176: new           #95                 // class java/lang/StringBuilder
     179: dup
     180: invokespecial #97                 // Method java/lang/StringBuilder."<init>":()V
     183: aload         8
     185: invokevirtual #101                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     188: iload         6
     190: invokevirtual #104                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     193: invokevirtual #108                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     196: astore        8
     198: iinc          5, 1
     201: aload_0
     202: iload         5
     204: invokevirtual #71                 // Method java/lang/String.charAt:(I)C
     207: istore        6
     209: goto          150
     212: iinc          5, -1
     215: new           #57                 // class Day13Kt$main$TreeNode
     218: dup
     219: aload         8
     221: invokestatic  #112                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     224: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     227: aload_2
     228: aconst_null
     229: aconst_null
     230: bipush        8
     232: aconst_null
     233: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     236: astore        9
     238: aload_2
     239: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     242: aload         9
     244: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     249: pop
     250: iinc          5, 1
     253: goto          28
     256: aload_1
     257: areturn

  private static final java.util.List<kotlin.Pair<Day13Kt$main$TreeNode, Day13Kt$main$TreeNode>> main$parse(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #129                // class java/lang/Iterable
       4: iconst_3
       5: invokestatic  #135                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
       8: checkcast     #129                // class java/lang/Iterable
      11: astore_1
      12: nop
      13: iconst_0
      14: istore_2
      15: aload_1
      16: astore_3
      17: new           #137                // class java/util/ArrayList
      20: dup
      21: aload_1
      22: bipush        10
      24: invokestatic  #141                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #143                // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #145                // class java/util/Collection
      33: astore        4
      35: iconst_0
      36: istore        5
      38: aload_3
      39: invokeinterface #149,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        6
      46: aload         6
      48: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          122
      56: aload         6
      58: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        7
      65: aload         4
      67: aload         7
      69: checkcast     #77                 // class java/util/List
      72: astore        8
      74: astore        10
      76: iconst_0
      77: istore        9
      79: aload         8
      81: iconst_0
      82: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      87: checkcast     #63                 // class java/lang/String
      90: invokestatic  #165                // Method main$parseTree:(Ljava/lang/String;)LDay13Kt$main$TreeNode;
      93: aload         8
      95: iconst_1
      96: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     101: checkcast     #63                 // class java/lang/String
     104: invokestatic  #165                // Method main$parseTree:(Ljava/lang/String;)LDay13Kt$main$TreeNode;
     107: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     110: aload         10
     112: swap
     113: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     118: pop
     119: goto          46
     122: aload         4
     124: checkcast     #77                 // class java/util/List
     127: nop
     128: areturn

  private static final java.lang.Boolean main$compare(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpne     7
       5: aconst_null
       6: areturn
       7: iload_0
       8: iload_1
       9: if_icmpge     16
      12: iconst_1
      13: goto          17
      16: iconst_0
      17: invokestatic  #190                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      20: areturn

  private static final java.lang.Boolean main$compare$1(Day13Kt$main$TreeNode, Day13Kt$main$TreeNode);
    Code:
       0: aload_0
       1: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
       4: ifnull        32
       7: aload_1
       8: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
      11: ifnull        32
      14: aload_0
      15: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
      18: invokevirtual #201                // Method java/lang/Integer.intValue:()I
      21: aload_1
      22: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
      25: invokevirtual #201                // Method java/lang/Integer.intValue:()I
      28: invokestatic  #203                // Method main$compare:(II)Ljava/lang/Boolean;
      31: areturn
      32: aload_0
      33: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
      36: ifnonnull     203
      39: aload_1
      40: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
      43: ifnonnull     203
      46: iconst_0
      47: istore_2
      48: iload_2
      49: aload_0
      50: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
      53: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
      58: if_icmplt     74
      61: iload_2
      62: aload_1
      63: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
      66: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
      71: if_icmpge     203
      74: aload_0
      75: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
      78: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
      83: aload_1
      84: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
      87: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
      92: if_icmpge     113
      95: iload_2
      96: aload_0
      97: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     100: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
     105: if_icmplt     113
     108: iconst_1
     109: invokestatic  #190                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     112: areturn
     113: aload_0
     114: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     117: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
     122: aload_1
     123: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     126: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
     131: if_icmple     152
     134: iload_2
     135: aload_1
     136: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     139: invokeinterface #205,  1          // InterfaceMethod java/util/List.size:()I
     144: if_icmplt     152
     147: iconst_0
     148: invokestatic  #190                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     151: areturn
     152: aload_0
     153: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     156: iload_2
     157: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     162: checkcast     #57                 // class Day13Kt$main$TreeNode
     165: astore_3
     166: aload_1
     167: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     170: iload_2
     171: invokeinterface #163,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     176: checkcast     #57                 // class Day13Kt$main$TreeNode
     179: astore        4
     181: aload_3
     182: aload         4
     184: invokestatic  #207                // Method main$compare$1:(LDay13Kt$main$TreeNode;LDay13Kt$main$TreeNode;)Ljava/lang/Boolean;
     187: astore        5
     189: aload         5
     191: ifnull        197
     194: aload         5
     196: areturn
     197: iinc          2, 1
     200: goto          48
     203: aload_0
     204: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
     207: ifnull        263
     210: new           #57                 // class Day13Kt$main$TreeNode
     213: dup
     214: aconst_null
     215: aload_0
     216: invokevirtual #85                 // Method Day13Kt$main$TreeNode.getParent:()LDay13Kt$main$TreeNode;
     219: aconst_null
     220: aconst_null
     221: bipush        8
     223: aconst_null
     224: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     227: astore_2
     228: new           #57                 // class Day13Kt$main$TreeNode
     231: dup
     232: aload_0
     233: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
     236: aload_2
     237: aconst_null
     238: aconst_null
     239: bipush        8
     241: aconst_null
     242: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     245: astore_3
     246: aload_2
     247: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     250: aload_3
     251: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     256: pop
     257: aload_2
     258: aload_1
     259: invokestatic  #207                // Method main$compare$1:(LDay13Kt$main$TreeNode;LDay13Kt$main$TreeNode;)Ljava/lang/Boolean;
     262: areturn
     263: aload_1
     264: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
     267: ifnull        323
     270: new           #57                 // class Day13Kt$main$TreeNode
     273: dup
     274: aconst_null
     275: aload_1
     276: invokevirtual #85                 // Method Day13Kt$main$TreeNode.getParent:()LDay13Kt$main$TreeNode;
     279: aconst_null
     280: aconst_null
     281: bipush        8
     283: aconst_null
     284: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     287: astore_2
     288: new           #57                 // class Day13Kt$main$TreeNode
     291: dup
     292: aload_1
     293: invokevirtual #198                // Method Day13Kt$main$TreeNode.getValue:()Ljava/lang/Integer;
     296: aload_2
     297: aconst_null
     298: aconst_null
     299: bipush        8
     301: aconst_null
     302: invokespecial #61                 // Method Day13Kt$main$TreeNode."<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     305: astore_3
     306: aload_2
     307: invokevirtual #75                 // Method Day13Kt$main$TreeNode.getChildren:()Ljava/util/List;
     310: aload_3
     311: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     316: pop
     317: aload_0
     318: aload_2
     319: invokestatic  #207                // Method main$compare$1:(LDay13Kt$main$TreeNode;LDay13Kt$main$TreeNode;)Ljava/lang/Boolean;
     322: areturn
     323: aconst_null
     324: areturn

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #216                // Method main$parse:(Ljava/util/List;)Ljava/util/List;
       4: astore_1
       5: aload_1
       6: checkcast     #129                // class java/lang/Iterable
       9: astore_2
      10: nop
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #137                // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #141                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #143                // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #145                // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #149,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          110
      56: aload         7
      58: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #218                // class kotlin/Pair
      72: astore        9
      74: astore        14
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokevirtual #221                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      84: checkcast     #57                 // class Day13Kt$main$TreeNode
      87: aload         9
      89: invokevirtual #224                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      92: checkcast     #57                 // class Day13Kt$main$TreeNode
      95: invokestatic  #207                // Method main$compare$1:(LDay13Kt$main$TreeNode;LDay13Kt$main$TreeNode;)Ljava/lang/Boolean;
      98: aload         14
     100: swap
     101: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: goto          46
     110: aload         5
     112: checkcast     #77                 // class java/util/List
     115: nop
     116: checkcast     #129                // class java/lang/Iterable
     119: astore_2
     120: nop
     121: iconst_0
     122: istore_3
     123: aload_2
     124: astore        4
     126: new           #137                // class java/util/ArrayList
     129: dup
     130: aload_2
     131: bipush        10
     133: invokestatic  #141                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     136: invokespecial #143                // Method java/util/ArrayList."<init>":(I)V
     139: checkcast     #145                // class java/util/Collection
     142: astore        5
     144: iconst_0
     145: istore        6
     147: iconst_0
     148: istore        7
     150: aload         4
     152: invokeinterface #149,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     157: astore        8
     159: aload         8
     161: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     166: ifeq          246
     169: aload         8
     171: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     176: astore        9
     178: aload         5
     180: iload         7
     182: iinc          7, 1
     185: istore        10
     187: iload         10
     189: ifge          195
     192: invokestatic  #227                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     195: iload         10
     197: aload         9
     199: checkcast     #187                // class java/lang/Boolean
     202: astore        11
     204: istore        12
     206: astore        14
     208: iconst_0
     209: istore        13
     211: aload         11
     213: iconst_1
     214: invokestatic  #190                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     217: invokestatic  #231                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     220: ifeq          230
     223: iload         12
     225: iconst_1
     226: iadd
     227: goto          231
     230: iconst_0
     231: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     234: aload         14
     236: swap
     237: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     242: pop
     243: goto          159
     246: aload         5
     248: checkcast     #77                 // class java/util/List
     251: nop
     252: checkcast     #129                // class java/lang/Iterable
     255: invokestatic  #235                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     258: ireturn

  private static final int main$part2$lambda$4(Day13Kt$main$TreeNode, Day13Kt$main$TreeNode);
    Code:
       0: aload_0
       1: dup
       2: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       5: aload_1
       6: dup
       7: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      10: invokestatic  #207                // Method main$compare$1:(LDay13Kt$main$TreeNode;LDay13Kt$main$TreeNode;)Ljava/lang/Boolean;
      13: astore_2
      14: aload_2
      15: iconst_1
      16: invokestatic  #190                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      19: invokestatic  #231                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      22: ifeq          29
      25: iconst_m1
      26: goto          45
      29: aload_2
      30: iconst_0
      31: invokestatic  #190                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      34: invokestatic  #231                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      37: ifeq          44
      40: iconst_1
      41: goto          45
      44: iconst_0
      45: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #145                // class java/util/Collection
       4: invokestatic  #255                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
       7: astore_1
       8: aload_1
       9: ldc_w         #257                // String \n
      12: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      17: pop
      18: aload_1
      19: ldc_w         #259                // String [[2]]
      22: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      27: pop
      28: aload_1
      29: ldc_w         #261                // String [[6]]
      32: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      37: pop
      38: aload_1
      39: ldc_w         #257                // String \n
      42: invokeinterface #81,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      47: pop
      48: aload_1
      49: invokestatic  #216                // Method main$parse:(Ljava/util/List;)Ljava/util/List;
      52: astore_2
      53: new           #263                // class Day13Kt$main$TreeNodeComparator
      56: dup
      57: invokedynamic #281,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      62: invokespecial #284                // Method Day13Kt$main$TreeNodeComparator."<init>":(Lkotlin/jvm/functions/Function2;)V
      65: astore_3
      66: aload_2
      67: checkcast     #129                // class java/lang/Iterable
      70: astore        4
      72: nop
      73: iconst_0
      74: istore        5
      76: aload         4
      78: astore        6
      80: new           #137                // class java/util/ArrayList
      83: dup
      84: invokespecial #285                // Method java/util/ArrayList."<init>":()V
      87: checkcast     #145                // class java/util/Collection
      90: astore        7
      92: iconst_0
      93: istore        8
      95: aload         6
      97: invokeinterface #149,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     102: astore        9
     104: aload         9
     106: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     111: ifeq          178
     114: aload         9
     116: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     121: astore        10
     123: aload         10
     125: checkcast     #218                // class kotlin/Pair
     128: astore        11
     130: iconst_0
     131: istore        12
     133: iconst_2
     134: anewarray     #57                 // class Day13Kt$main$TreeNode
     137: astore        13
     139: aload         13
     141: iconst_0
     142: aload         11
     144: invokevirtual #221                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     147: aastore
     148: aload         13
     150: iconst_1
     151: aload         11
     153: invokevirtual #224                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     156: aastore
     157: aload         13
     159: invokestatic  #289                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     162: checkcast     #129                // class java/lang/Iterable
     165: astore        11
     167: aload         7
     169: aload         11
     171: invokestatic  #293                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     174: pop
     175: goto          104
     178: aload         7
     180: checkcast     #77                 // class java/util/List
     183: nop
     184: checkcast     #129                // class java/lang/Iterable
     187: aload_3
     188: checkcast     #295                // class java/util/Comparator
     191: invokestatic  #299                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     194: checkcast     #129                // class java/lang/Iterable
     197: astore        4
     199: nop
     200: iconst_0
     201: istore        5
     203: aload         4
     205: astore        6
     207: new           #137                // class java/util/ArrayList
     210: dup
     211: aload         4
     213: bipush        10
     215: invokestatic  #141                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     218: invokespecial #143                // Method java/util/ArrayList."<init>":(I)V
     221: checkcast     #145                // class java/util/Collection
     224: astore        7
     226: iconst_0
     227: istore        8
     229: iconst_0
     230: istore        9
     232: aload         6
     234: invokeinterface #149,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     239: astore        10
     241: aload         10
     243: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     248: ifeq          345
     251: aload         10
     253: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     258: astore        11
     260: aload         7
     262: iload         9
     264: iinc          9, 1
     267: istore        12
     269: iload         12
     271: ifge          277
     274: invokestatic  #227                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     277: iload         12
     279: aload         11
     281: checkcast     #57                 // class Day13Kt$main$TreeNode
     284: astore        13
     286: istore        14
     288: astore        16
     290: iconst_0
     291: istore        15
     293: aload         13
     295: invokevirtual #302                // Method Day13Kt$main$TreeNode.getStr:()Ljava/lang/String;
     298: ldc_w         #259                // String [[2]]
     301: invokestatic  #231                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     304: ifne          321
     307: aload         13
     309: invokevirtual #302                // Method Day13Kt$main$TreeNode.getStr:()Ljava/lang/String;
     312: ldc_w         #261                // String [[6]]
     315: invokestatic  #231                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     318: ifeq          328
     321: iload         14
     323: iconst_1
     324: iadd
     325: goto          329
     328: iconst_1
     329: nop
     330: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     333: aload         16
     335: swap
     336: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     341: pop
     342: goto          241
     345: aload         7
     347: checkcast     #77                 // class java/util/List
     350: nop
     351: checkcast     #129                // class java/lang/Iterable
     354: astore        4
     356: nop
     357: iconst_0
     358: istore        5
     360: aload         4
     362: invokeinterface #149,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     367: astore        6
     369: aload         6
     371: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     376: ifne          390
     379: new           #304                // class java/lang/UnsupportedOperationException
     382: dup
     383: ldc_w         #306                // String Empty collection can\'t be reduced.
     386: invokespecial #309                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     389: athrow
     390: aload         6
     392: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     397: astore        7
     399: aload         6
     401: invokeinterface #155,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     406: ifeq          450
     409: aload         7
     411: aload         6
     413: invokeinterface #159,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     418: checkcast     #311                // class java/lang/Number
     421: invokevirtual #312                // Method java/lang/Number.intValue:()I
     424: istore        8
     426: checkcast     #311                // class java/lang/Number
     429: invokevirtual #312                // Method java/lang/Number.intValue:()I
     432: istore        9
     434: iconst_0
     435: istore        10
     437: iload         9
     439: iload         8
     441: imul
     442: invokestatic  #24                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     445: astore        7
     447: goto          399
     450: aload         7
     452: checkcast     #311                // class java/lang/Number
     455: invokevirtual #312                // Method java/lang/Number.intValue:()I
     458: ireturn
}

Compiled from "Day13.kt"
public final class Day13Kt$main$TreeNode {
  private final java.lang.Integer value;

  private final Day13Kt$main$TreeNode parent;

  private final java.lang.String str;

  private java.util.List<Day13Kt$main$TreeNode> children;

  public Day13Kt$main$TreeNode(java.lang.Integer, Day13Kt$main$TreeNode, java.lang.String, java.util.List<Day13Kt$main$TreeNode>);
    Code:
       0: aload         4
       2: ldc           #9                  // String children
       4: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokespecial #18                 // Method java/lang/Object."<init>":()V
      11: aload_0
      12: aload_1
      13: putfield      #22                 // Field value:Ljava/lang/Integer;
      16: aload_0
      17: aload_2
      18: putfield      #26                 // Field parent:LDay13Kt$main$TreeNode;
      21: aload_0
      22: aload_3
      23: putfield      #30                 // Field str:Ljava/lang/String;
      26: aload_0
      27: aload         4
      29: putfield      #33                 // Field children:Ljava/util/List;
      32: return

  public Day13Kt$main$TreeNode(java.lang.Integer, Day13Kt$main$TreeNode, java.lang.String, java.util.List, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         5
       2: bipush        8
       4: iand
       5: ifeq          20
       8: new           #37                 // class java/util/ArrayList
      11: dup
      12: invokespecial #38                 // Method java/util/ArrayList."<init>":()V
      15: checkcast     #40                 // class java/util/List
      18: astore        4
      20: aload_0
      21: aload_1
      22: aload_2
      23: aload_3
      24: aload         4
      26: invokespecial #42                 // Method "<init>":(Ljava/lang/Integer;LDay13Kt$main$TreeNode;Ljava/lang/String;Ljava/util/List;)V
      29: return

  public final java.lang.Integer getValue();
    Code:
       0: aload_0
       1: getfield      #22                 // Field value:Ljava/lang/Integer;
       4: areturn

  public final Day13Kt$main$TreeNode getParent();
    Code:
       0: aload_0
       1: getfield      #26                 // Field parent:LDay13Kt$main$TreeNode;
       4: areturn

  public final java.lang.String getStr();
    Code:
       0: aload_0
       1: getfield      #30                 // Field str:Ljava/lang/String;
       4: areturn

  public final java.util.List<Day13Kt$main$TreeNode> getChildren();
    Code:
       0: aload_0
       1: getfield      #33                 // Field children:Ljava/util/List;
       4: areturn

  public final void setChildren(java.util.List<Day13Kt$main$TreeNode>);
    Code:
       0: aload_1
       1: ldc           #56                 // String <set-?>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #33                 // Field children:Ljava/util/List;
      11: return
}


import java.util.Stack

class CrateStack(val crates: Stack<Char>)
class Move(val quantity: Int, val startIdx: Int, val endIdx: Int)
class State(val stacks: Array<CrateStack>, val moves: Array<Move>) {
    fun applyMoves() {
        for (move in moves) {
            for (i in 1..move.quantity) {
                val crate = stacks[move.startIdx].crates.pop()
                stacks[move.endIdx].crates.push(crate)
            }
        }
    }

    fun applyMoves2() {
        for (move in moves) {
            val batch = mutableListOf<Char>()
            for (i in 1..move.quantity) {
                val crate = stacks[move.startIdx].crates.pop()
                batch.add(crate)
            }

            batch.asReversed().forEach { crate ->
                stacks[move.endIdx].crates.push(crate)
            }
        }
    }

    fun getTops(): String {
        return String(stacks.map { it.crates.peek() }.toCharArray())
    }
}

fun main() {
    fun parseStacks(input: List<String>): Array<CrateStack> {
        val idxs = mutableListOf<Int>()

        val idxInput = input.last()
        for ((index, item) in idxInput.toCharArray().withIndex()) {
            if (item != ' ') {
                idxs.add(index)
            }
        }

        val result = Array(idxs.size) { _ -> CrateStack(Stack<Char>()) }
        val cratesInput = input.asReversed().slice(1 until input.size)
        for (line in cratesInput) {
            for ((localIdx, idx) in idxs.withIndex()) {
                if (line.length > idx && line[idx] != ' ') {
                    result[localIdx].crates.push(line[idx])
                }
            }
        }

        return result
    }

    fun parseMoves(input: List<String>): Array<Move> {
        return input
            .map { line ->
                val parts = line.split(' ')
                Move(parts[1].toInt(), parts[3].toInt() - 1, parts[5].toInt() - 1)
            }.toTypedArray()
    }

    fun parse(input: List<String>): State {
        val separatorIdx = input.lastIndexOf("")
        val stacksInput = input.slice(0 until separatorIdx)
        val movesInput = input.slice(separatorIdx + 1 until input.size)

        return State(parseStacks(stacksInput), parseMoves(movesInput))
    }

    fun part1(input: List<String>): String {
        val state = parse(input)
        state.applyMoves()
        return state.getTops()
    }

    fun part2(input: List<String>): String {
        val state = parse(input)
        state.applyMoves2()
        return state.getTops()
    }

    val testInput = readInput("Day05_test")
    assert(part1(testInput), "CMZ")
    assert(part2(testInput), "MCD")

    val input = readInput("Day05")
    println(part1(input))
    println(part2(input))
}

Compiled from "Day05.kt"
public final class Day05Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day05_test
       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: ldc           #20                 // String CMZ
      12: invokestatic  #24                 // Method UtilsKt.assert:(Ljava/lang/Object;Ljava/lang/Object;)V
      15: aload_0
      16: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)Ljava/lang/String;
      19: ldc           #29                 // String MCD
      21: invokestatic  #24                 // Method UtilsKt.assert:(Ljava/lang/Object;Ljava/lang/Object;)V
      24: ldc           #31                 // String Day05
      26: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      29: astore_1
      30: aload_1
      31: invokestatic  #18                 // Method main$part1:(Ljava/util/List;)Ljava/lang/String;
      34: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
      37: swap
      38: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      41: aload_1
      42: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)Ljava/lang/String;
      45: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
      48: swap
      49: invokevirtual #43                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      52: return

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

  private static final CrateStack[] main$parseStacks(java.util.List<java.lang.String>);
    Code:
       0: new           #56                 // class java/util/ArrayList
       3: dup
       4: invokespecial #59                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #61                 // class java/util/List
      10: astore_1
      11: aload_0
      12: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      15: checkcast     #69                 // class java/lang/String
      18: astore_2
      19: aload_2
      20: invokevirtual #73                 // Method java/lang/String.toCharArray:()[C
      23: dup
      24: ldc           #75                 // String toCharArray(...)
      26: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      29: astore_3
      30: iconst_0
      31: istore        4
      33: aload_3
      34: arraylength
      35: istore        5
      37: iload         4
      39: iload         5
      41: if_icmpge     79
      44: iload         4
      46: istore        6
      48: aload_3
      49: iload         4
      51: caload
      52: istore        7
      54: iload         7
      56: bipush        32
      58: if_icmpeq     73
      61: aload_1
      62: iload         6
      64: invokestatic  #87                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: invokeinterface #91,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      72: pop
      73: iinc          4, 1
      76: goto          37
      79: iconst_0
      80: istore        4
      82: aload_1
      83: invokeinterface #95,  1           // InterfaceMethod java/util/List.size:()I
      88: istore        5
      90: iload         5
      92: anewarray     #97                 // class CrateStack
      95: astore        6
      97: iload         4
      99: iload         5
     101: if_icmpge     133
     104: iload         4
     106: istore        7
     108: aload         6
     110: iload         7
     112: new           #97                 // class CrateStack
     115: dup
     116: new           #99                 // class java/util/Stack
     119: dup
     120: invokespecial #100                // Method java/util/Stack."<init>":()V
     123: invokespecial #103                // Method CrateStack."<init>":(Ljava/util/Stack;)V
     126: aastore
     127: iinc          4, 1
     130: goto          97
     133: aload         6
     135: astore_3
     136: aload_0
     137: invokestatic  #107                // Method kotlin/collections/CollectionsKt.asReversed:(Ljava/util/List;)Ljava/util/List;
     140: iconst_1
     141: aload_0
     142: invokeinterface #95,  1           // InterfaceMethod java/util/List.size:()I
     147: invokestatic  #113                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     150: invokestatic  #117                // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     153: astore        4
     155: aload         4
     157: invokeinterface #121,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     162: astore        5
     164: aload         5
     166: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     171: ifeq          281
     174: aload         5
     176: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     181: checkcast     #69                 // class java/lang/String
     184: astore        6
     186: aload_1
     187: checkcast     #133                // class java/lang/Iterable
     190: invokeinterface #134,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     195: astore        7
     197: iconst_0
     198: istore        8
     200: aload         7
     202: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     207: ifeq          164
     210: iload         8
     212: istore        9
     214: iload         8
     216: iconst_1
     217: iadd
     218: istore        8
     220: aload         7
     222: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     227: checkcast     #136                // class java/lang/Number
     230: invokevirtual #139                // Method java/lang/Number.intValue:()I
     233: istore        10
     235: aload         6
     237: invokevirtual #142                // Method java/lang/String.length:()I
     240: iload         10
     242: if_icmple     200
     245: aload         6
     247: iload         10
     249: invokevirtual #146                // Method java/lang/String.charAt:(I)C
     252: bipush        32
     254: if_icmpeq     200
     257: aload_3
     258: iload         9
     260: aaload
     261: invokevirtual #150                // Method CrateStack.getCrates:()Ljava/util/Stack;
     264: aload         6
     266: iload         10
     268: invokevirtual #146                // Method java/lang/String.charAt:(I)C
     271: invokestatic  #155                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     274: invokevirtual #159                // Method java/util/Stack.push:(Ljava/lang/Object;)Ljava/lang/Object;
     277: pop
     278: goto          200
     281: aload_3
     282: areturn

  private static final Move[] main$parseMoves(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #133                // class java/lang/Iterable
       4: astore_1
       5: nop
       6: iconst_0
       7: istore_2
       8: aload_1
       9: astore_3
      10: new           #56                 // class java/util/ArrayList
      13: dup
      14: aload_1
      15: bipush        10
      17: invokestatic  #182                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #185                // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #187                // class java/util/Collection
      26: astore        4
      28: iconst_0
      29: istore        5
      31: aload_3
      32: invokeinterface #134,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        6
      39: aload         6
      41: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          165
      49: aload         6
      51: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        7
      58: aload         4
      60: aload         7
      62: checkcast     #69                 // class java/lang/String
      65: astore        8
      67: astore        12
      69: iconst_0
      70: istore        9
      72: aload         8
      74: checkcast     #189                // class java/lang/CharSequence
      77: iconst_1
      78: newarray       char
      80: astore        10
      82: aload         10
      84: iconst_0
      85: bipush        32
      87: castore
      88: aload         10
      90: iconst_0
      91: iconst_0
      92: bipush        6
      94: aconst_null
      95: invokestatic  #195                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      98: astore        11
     100: new           #197                // class Move
     103: dup
     104: aload         11
     106: iconst_1
     107: invokeinterface #201,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #69                 // class java/lang/String
     115: invokestatic  #205                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     118: aload         11
     120: iconst_3
     121: invokeinterface #201,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     126: checkcast     #69                 // class java/lang/String
     129: invokestatic  #205                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     132: iconst_1
     133: isub
     134: aload         11
     136: iconst_5
     137: invokeinterface #201,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     142: checkcast     #69                 // class java/lang/String
     145: invokestatic  #205                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     148: iconst_1
     149: isub
     150: invokespecial #208                // Method Move."<init>":(III)V
     153: aload         12
     155: swap
     156: invokeinterface #209,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     161: pop
     162: goto          39
     165: aload         4
     167: checkcast     #61                 // class java/util/List
     170: nop
     171: checkcast     #187                // class java/util/Collection
     174: astore_1
     175: nop
     176: iconst_0
     177: istore_2
     178: aload_1
     179: astore_3
     180: aload_3
     181: iconst_0
     182: anewarray     #197                // class Move
     185: invokeinterface #213,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     190: checkcast     #215                // class "[LMove;"
     193: areturn

  private static final State main$parse(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #234                // String
       3: invokeinterface #238,  2          // InterfaceMethod java/util/List.lastIndexOf:(Ljava/lang/Object;)I
       8: istore_1
       9: aload_0
      10: iconst_0
      11: iload_1
      12: invokestatic  #113                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      15: invokestatic  #117                // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
      18: astore_2
      19: aload_0
      20: iload_1
      21: iconst_1
      22: iadd
      23: aload_0
      24: invokeinterface #95,  1           // InterfaceMethod java/util/List.size:()I
      29: invokestatic  #113                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      32: invokestatic  #117                // Method kotlin/collections/CollectionsKt.slice:(Ljava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
      35: astore_3
      36: new           #240                // class State
      39: dup
      40: aload_2
      41: invokestatic  #242                // Method main$parseStacks:(Ljava/util/List;)[LCrateStack;
      44: aload_3
      45: invokestatic  #244                // Method main$parseMoves:(Ljava/util/List;)[LMove;
      48: invokespecial #247                // Method State."<init>":([LCrateStack;[LMove;)V
      51: areturn

  private static final java.lang.String main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #253                // Method main$parse:(Ljava/util/List;)LState;
       4: astore_1
       5: aload_1
       6: invokevirtual #256                // Method State.applyMoves:()V
       9: aload_1
      10: invokevirtual #260                // Method State.getTops:()Ljava/lang/String;
      13: areturn

  private static final java.lang.String main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #253                // Method main$parse:(Ljava/util/List;)LState;
       4: astore_1
       5: aload_1
       6: invokevirtual #265                // Method State.applyMoves2:()V
       9: aload_1
      10: invokevirtual #260                // Method State.getTops:()Ljava/lang/String;
      13: areturn
}


import kotlin.math.abs

fun main() {
    data class Signal(val sensor: Point, val beacon: Point) {
        fun getDistance(): Int {
            return abs(sensor.x - beacon.x) + abs(sensor.y - beacon.y)
        }
    }

    fun parse(input: List<String>): List<Signal> {
        val regex = """Sensor at x=(-?\d+), y=(-?\d+): closest beacon is at x=(-?\d+), y=(-?\d+)""".toRegex()

        return input.map { line ->
            val (sensorX, sensorY, beaconX, beaconY) = regex
                .matchEntire(line)
                ?.destructured
                ?: throw IllegalArgumentException("Incorrect input line $line")

            Signal(Point(sensorX.toInt(), sensorY.toInt()), Point(beaconX.toInt(), beaconY.toInt()))
        }
    }

    fun getIntervals(
        signals: List<Signal>,
        row: Int
    ): List<Interval> {
        val intervals = mutableListOf<Interval>()
        for (signal in signals) {
            val distance = signal.getDistance()
            val diff = abs(signal.sensor.y - row)
            if (diff <= distance) {
                val delta = distance - diff
                val interval = Interval(signal.sensor.x - delta, signal.sensor.x + delta)
                // println("$signal diff: $diff delta: $delta distance: $distance interval: $interval")
                intervals.add(interval)
            }
        }

        val merged = Interval.merge(intervals)
        // println("Merged: $merged")
        return merged
    }

    fun part1(signals: List<Signal>, row: Int): Int {
        val merged = getIntervals(signals, row)

        val points = signals
            .flatMap { s -> listOf(s.beacon, s.sensor) }
            .filter { p -> p.y == row }
            .map { p -> p.x }
            .toSet()

        return merged.sumOf { i -> i.countPoints(points) }
    }

    fun part2(signals: List<Signal>, limit: Int): Long {
        for (row in 0..limit) {
            val intervals = getIntervals(signals, row)
            if (intervals.size == 2) {
                val left = intervals[0]
                val right = intervals[1]

                if (left.end + 1 == right.start - 1) {
                    return (left.end + 1) * 4000000L + row
                } else {
                    println("Error: $left $right $row")
                    throw RuntimeException()
                }
            }

            if (intervals.size != 1) {
                println("Error: ${intervals.size} $row")
                throw RuntimeException()
            }
        }

        return -1
    }

    val testInput = readInput("Day15_test")
    assert(part1(parse(testInput), 10), 26)
    assert(part2(parse(testInput), 20), 56000011L)

    val input = readInput("Day15")
    println(part1(parse(input), 2000000))
    println(part2(parse(input), 4000000))
}

Compiled from "Day15.kt"
public final class Day15Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day15_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method main$parse:(Ljava/util/List;)Ljava/util/List;
      10: bipush        10
      12: invokestatic  #22                 // Method main$part1:(Ljava/util/List;I)I
      15: invokestatic  #28                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: bipush        26
      20: invokestatic  #28                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokestatic  #32                 // Method UtilsKt.assert:(Ljava/lang/Object;Ljava/lang/Object;)V
      26: aload_0
      27: invokestatic  #18                 // Method main$parse:(Ljava/util/List;)Ljava/util/List;
      30: bipush        20
      32: invokestatic  #36                 // Method main$part2:(Ljava/util/List;I)J
      35: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      38: ldc2_w        #42                 // long 56000011l
      41: invokestatic  #41                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      44: invokestatic  #32                 // Method UtilsKt.assert:(Ljava/lang/Object;Ljava/lang/Object;)V
      47: ldc           #45                 // String Day15
      49: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      52: astore_1
      53: aload_1
      54: invokestatic  #18                 // Method main$parse:(Ljava/util/List;)Ljava/util/List;
      57: ldc           #46                 // int 2000000
      59: invokestatic  #22                 // Method main$part1:(Ljava/util/List;I)I
      62: istore_2
      63: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      66: iload_2
      67: invokevirtual #58                 // Method java/io/PrintStream.println:(I)V
      70: aload_1
      71: invokestatic  #18                 // Method main$parse:(Ljava/util/List;)Ljava/util/List;
      74: ldc           #59                 // int 4000000
      76: invokestatic  #36                 // Method main$part2:(Ljava/util/List;I)J
      79: lstore_2
      80: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
      83: lload_2
      84: invokevirtual #62                 // Method java/io/PrintStream.println:(J)V
      87: return

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

  private static final java.util.List<Day15Kt$main$Signal> main$parse(java.util.List<java.lang.String>);
    Code:
       0: new           #73                 // class kotlin/text/Regex
       3: dup
       4: ldc           #75                 // String Sensor at x=(-?\\d+), y=(-?\\d+): closest beacon is at x=(-?\\d+), y=(-?\\d+)
       6: invokespecial #79                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: aload_0
      11: checkcast     #81                 // class java/lang/Iterable
      14: astore_2
      15: iconst_0
      16: istore_3
      17: aload_2
      18: astore        4
      20: new           #83                 // class java/util/ArrayList
      23: dup
      24: aload_2
      25: bipush        10
      27: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      30: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #93                 // class java/util/Collection
      36: astore        5
      38: iconst_0
      39: istore        6
      41: aload         4
      43: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        7
      50: aload         7
      52: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          285
      60: aload         7
      62: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        8
      69: aload         5
      71: aload         8
      73: checkcast     #109                // class java/lang/String
      76: astore        9
      78: astore        16
      80: iconst_0
      81: istore        10
      83: aload_1
      84: aload         9
      86: checkcast     #111                // class java/lang/CharSequence
      89: invokevirtual #115                // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
      92: astore        11
      94: aload         11
      96: ifnull        118
      99: aload         11
     101: invokeinterface #121,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     106: astore        12
     108: aload         12
     110: ifnull        118
     113: aload         12
     115: goto          146
     118: new           #123                // class java/lang/IllegalArgumentException
     121: dup
     122: new           #125                // class java/lang/StringBuilder
     125: dup
     126: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
     129: ldc           #129                // String Incorrect input line
     131: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     134: aload         9
     136: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     139: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     142: invokespecial #138                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     145: athrow
     146: astore        13
     148: aload         13
     150: invokevirtual #144                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     153: invokeinterface #148,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     158: iconst_1
     159: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     164: checkcast     #109                // class java/lang/String
     167: astore        11
     169: aload         13
     171: invokevirtual #144                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     174: invokeinterface #148,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     179: iconst_2
     180: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     185: checkcast     #109                // class java/lang/String
     188: astore        12
     190: aload         13
     192: invokevirtual #144                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     195: invokeinterface #148,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     200: iconst_3
     201: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     206: checkcast     #109                // class java/lang/String
     209: astore        14
     211: aload         13
     213: invokevirtual #144                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     216: invokeinterface #148,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     221: iconst_4
     222: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     227: checkcast     #109                // class java/lang/String
     230: astore        15
     232: new           #156                // class Day15Kt$main$Signal
     235: dup
     236: new           #158                // class Point
     239: dup
     240: aload         11
     242: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     245: aload         12
     247: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     250: invokespecial #165                // Method Point."<init>":(II)V
     253: new           #158                // class Point
     256: dup
     257: aload         14
     259: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     262: aload         15
     264: invokestatic  #162                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     267: invokespecial #165                // Method Point."<init>":(II)V
     270: invokespecial #168                // Method Day15Kt$main$Signal."<init>":(LPoint;LPoint;)V
     273: aload         16
     275: swap
     276: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     281: pop
     282: goto          50
     285: aload         5
     287: checkcast     #150                // class java/util/List
     290: nop
     291: areturn

  private static final java.util.List<Interval> main$getIntervals(java.util.List<Day15Kt$main$Signal>, int);
    Code:
       0: new           #83                 // class java/util/ArrayList
       3: dup
       4: invokespecial #195                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #150                // class java/util/List
      10: astore_2
      11: aload_0
      12: invokeinterface #196,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      17: astore_3
      18: aload_3
      19: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          117
      27: aload_3
      28: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #156                // class Day15Kt$main$Signal
      36: astore        4
      38: aload         4
      40: invokevirtual #200                // Method Day15Kt$main$Signal.getDistance:()I
      43: istore        5
      45: aload         4
      47: invokevirtual #204                // Method Day15Kt$main$Signal.getSensor:()LPoint;
      50: invokevirtual #207                // Method Point.getY:()I
      53: iload_1
      54: isub
      55: invokestatic  #213                // Method java/lang/Math.abs:(I)I
      58: istore        6
      60: iload         6
      62: iload         5
      64: if_icmpgt     18
      67: iload         5
      69: iload         6
      71: isub
      72: istore        7
      74: new           #215                // class Interval
      77: dup
      78: aload         4
      80: invokevirtual #204                // Method Day15Kt$main$Signal.getSensor:()LPoint;
      83: invokevirtual #218                // Method Point.getX:()I
      86: iload         7
      88: isub
      89: aload         4
      91: invokevirtual #204                // Method Day15Kt$main$Signal.getSensor:()LPoint;
      94: invokevirtual #218                // Method Point.getX:()I
      97: iload         7
      99: iadd
     100: invokespecial #219                // Method Interval."<init>":(II)V
     103: astore        8
     105: aload_2
     106: aload         8
     108: invokeinterface #220,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     113: pop
     114: goto          18
     117: getstatic     #224                // Field Interval.Companion:LInterval$Companion;
     120: aload_2
     121: invokevirtual #229                // Method Interval$Companion.merge:(Ljava/util/List;)Ljava/util/List;
     124: astore_3
     125: aload_3
     126: areturn

  private static final int main$part1(java.util.List<Day15Kt$main$Signal>, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokestatic  #243                // Method main$getIntervals:(Ljava/util/List;I)Ljava/util/List;
       5: astore_2
       6: aload_0
       7: checkcast     #81                 // class java/lang/Iterable
      10: astore        4
      12: nop
      13: iconst_0
      14: istore        5
      16: aload         4
      18: astore        6
      20: new           #83                 // class java/util/ArrayList
      23: dup
      24: invokespecial #195                // Method java/util/ArrayList."<init>":()V
      27: checkcast     #93                 // class java/util/Collection
      30: astore        7
      32: iconst_0
      33: istore        8
      35: aload         6
      37: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        9
      44: aload         9
      46: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          118
      54: aload         9
      56: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        10
      63: aload         10
      65: checkcast     #156                // class Day15Kt$main$Signal
      68: astore        11
      70: iconst_0
      71: istore        12
      73: iconst_2
      74: anewarray     #158                // class Point
      77: astore        13
      79: aload         13
      81: iconst_0
      82: aload         11
      84: invokevirtual #246                // Method Day15Kt$main$Signal.getBeacon:()LPoint;
      87: aastore
      88: aload         13
      90: iconst_1
      91: aload         11
      93: invokevirtual #204                // Method Day15Kt$main$Signal.getSensor:()LPoint;
      96: aastore
      97: aload         13
      99: invokestatic  #250                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     102: checkcast     #81                 // class java/lang/Iterable
     105: astore        11
     107: aload         7
     109: aload         11
     111: invokestatic  #254                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     114: pop
     115: goto          44
     118: aload         7
     120: checkcast     #150                // class java/util/List
     123: nop
     124: checkcast     #81                 // class java/lang/Iterable
     127: astore        4
     129: nop
     130: iconst_0
     131: istore        5
     133: aload         4
     135: astore        6
     137: new           #83                 // class java/util/ArrayList
     140: dup
     141: invokespecial #195                // Method java/util/ArrayList."<init>":()V
     144: checkcast     #93                 // class java/util/Collection
     147: astore        7
     149: iconst_0
     150: istore        8
     152: aload         6
     154: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     159: astore        9
     161: aload         9
     163: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     168: ifeq          220
     171: aload         9
     173: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     178: astore        10
     180: aload         10
     182: checkcast     #158                // class Point
     185: astore        11
     187: iconst_0
     188: istore        12
     190: aload         11
     192: invokevirtual #207                // Method Point.getY:()I
     195: iload_1
     196: if_icmpne     203
     199: iconst_1
     200: goto          204
     203: iconst_0
     204: ifeq          161
     207: aload         7
     209: aload         10
     211: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     216: pop
     217: goto          161
     220: aload         7
     222: checkcast     #150                // class java/util/List
     225: nop
     226: checkcast     #81                 // class java/lang/Iterable
     229: astore        4
     231: nop
     232: iconst_0
     233: istore        5
     235: aload         4
     237: astore        6
     239: new           #83                 // class java/util/ArrayList
     242: dup
     243: aload         4
     245: bipush        10
     247: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     250: invokespecial #91                 // Method java/util/ArrayList."<init>":(I)V
     253: checkcast     #93                 // class java/util/Collection
     256: astore        7
     258: iconst_0
     259: istore        8
     261: aload         6
     263: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     268: astore        9
     270: aload         9
     272: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     277: ifeq          323
     280: aload         9
     282: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     287: astore        10
     289: aload         7
     291: aload         10
     293: checkcast     #158                // class Point
     296: astore        11
     298: astore        14
     300: iconst_0
     301: istore        12
     303: aload         11
     305: invokevirtual #218                // Method Point.getX:()I
     308: invokestatic  #28                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     311: aload         14
     313: swap
     314: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     319: pop
     320: goto          270
     323: aload         7
     325: checkcast     #150                // class java/util/List
     328: nop
     329: checkcast     #81                 // class java/lang/Iterable
     332: invokestatic  #258                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     335: astore_3
     336: aload_2
     337: checkcast     #81                 // class java/lang/Iterable
     340: astore        4
     342: iconst_0
     343: istore        5
     345: aload         4
     347: invokeinterface #97,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     352: astore        6
     354: aload         6
     356: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     361: ifeq          405
     364: aload         6
     366: invokeinterface #107,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     371: astore        7
     373: iload         5
     375: aload         7
     377: checkcast     #215                // class Interval
     380: astore        8
     382: istore        14
     384: iconst_0
     385: istore        9
     387: aload         8
     389: aload_3
     390: invokevirtual #262                // Method Interval.countPoints:(Ljava/util/Set;)I
     393: istore        15
     395: iload         14
     397: iload         15
     399: iadd
     400: istore        5
     402: goto          354
     405: iload         5
     407: ireturn

  private static final long main$part2(java.util.List<Day15Kt$main$Signal>, int);
    Code:
       0: iconst_0
       1: istore_2
       2: iload_2
       3: iload_1
       4: if_icmpgt     205
       7: aload_0
       8: iload_2
       9: invokestatic  #243                // Method main$getIntervals:(Ljava/util/List;I)Ljava/util/List;
      12: astore_3
      13: aload_3
      14: invokeinterface #288,  1          // InterfaceMethod java/util/List.size:()I
      19: iconst_2
      20: if_icmpne     135
      23: aload_3
      24: iconst_0
      25: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      30: checkcast     #215                // class Interval
      33: astore        4
      35: aload_3
      36: iconst_1
      37: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      42: checkcast     #215                // class Interval
      45: astore        5
      47: aload         4
      49: invokevirtual #291                // Method Interval.getEnd:()I
      52: iconst_1
      53: iadd
      54: aload         5
      56: invokevirtual #294                // Method Interval.getStart:()I
      59: iconst_1
      60: isub
      61: if_icmpne     80
      64: aload         4
      66: invokevirtual #291                // Method Interval.getEnd:()I
      69: iconst_1
      70: iadd
      71: i2l
      72: ldc2_w        #295                // long 4000000l
      75: lmul
      76: iload_2
      77: i2l
      78: ladd
      79: lreturn
      80: new           #125                // class java/lang/StringBuilder
      83: dup
      84: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
      87: ldc_w         #298                // String Error:
      90: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: aload         4
      95: invokevirtual #301                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      98: bipush        32
     100: invokevirtual #304                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     103: aload         5
     105: invokevirtual #301                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     108: bipush        32
     110: invokevirtual #304                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     113: iload_2
     114: invokevirtual #307                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     117: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     120: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
     123: swap
     124: invokevirtual #310                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     127: new           #312                // class java/lang/RuntimeException
     130: dup
     131: invokespecial #313                // Method java/lang/RuntimeException."<init>":()V
     134: athrow
     135: aload_3
     136: invokeinterface #288,  1          // InterfaceMethod java/util/List.size:()I
     141: iconst_1
     142: if_icmpeq     194
     145: new           #125                // class java/lang/StringBuilder
     148: dup
     149: invokespecial #127                // Method java/lang/StringBuilder."<init>":()V
     152: ldc_w         #298                // String Error:
     155: invokevirtual #133                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     158: aload_3
     159: invokeinterface #288,  1          // InterfaceMethod java/util/List.size:()I
     164: invokevirtual #307                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     167: bipush        32
     169: invokevirtual #304                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     172: iload_2
     173: invokevirtual #307                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     176: invokevirtual #137                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     179: getstatic     #52                 // Field java/lang/System.out:Ljava/io/PrintStream;
     182: swap
     183: invokevirtual #310                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     186: new           #312                // class java/lang/RuntimeException
     189: dup
     190: invokespecial #313                // Method java/lang/RuntimeException."<init>":()V
     193: athrow
     194: iload_2
     195: iload_1
     196: if_icmpeq     205
     199: iinc          2, 1
     202: goto          7
     205: ldc2_w        #314                // long -1l
     208: lreturn
}

Compiled from "Day15.kt"
public final class Day15Kt$main$Signal {
  private final Point sensor;

  private final Point beacon;

  public Day15Kt$main$Signal(Point, Point);
    Code:
       0: aload_1
       1: ldc           #8                  // String sensor
       3: invokestatic  #14                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #16                 // String beacon
       9: invokestatic  #14                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #19                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #22                 // Field sensor:LPoint;
      21: aload_0
      22: aload_2
      23: putfield      #24                 // Field beacon:LPoint;
      26: return

  public final Point getSensor();
    Code:
       0: aload_0
       1: getfield      #22                 // Field sensor:LPoint;
       4: areturn

  public final Point getBeacon();
    Code:
       0: aload_0
       1: getfield      #24                 // Field beacon:LPoint;
       4: areturn

  public final int getDistance();
    Code:
       0: aload_0
       1: getfield      #22                 // Field sensor:LPoint;
       4: invokevirtual #36                 // Method Point.getX:()I
       7: aload_0
       8: getfield      #24                 // Field beacon:LPoint;
      11: invokevirtual #36                 // Method Point.getX:()I
      14: isub
      15: invokestatic  #42                 // Method java/lang/Math.abs:(I)I
      18: aload_0
      19: getfield      #22                 // Field sensor:LPoint;
      22: invokevirtual #45                 // Method Point.getY:()I
      25: aload_0
      26: getfield      #24                 // Field beacon:LPoint;
      29: invokevirtual #45                 // Method Point.getY:()I
      32: isub
      33: invokestatic  #42                 // Method java/lang/Math.abs:(I)I
      36: iadd
      37: ireturn

  public final Point component1();
    Code:
       0: aload_0
       1: getfield      #22                 // Field sensor:LPoint;
       4: areturn

  public final Point component2();
    Code:
       0: aload_0
       1: getfield      #24                 // Field beacon:LPoint;
       4: areturn

  public final Day15Kt$main$Signal copy(Point, Point);
    Code:
       0: aload_1
       1: ldc           #8                  // String sensor
       3: invokestatic  #14                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #16                 // String beacon
       9: invokestatic  #14                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class Day15Kt$main$Signal
      15: dup
      16: aload_1
      17: aload_2
      18: invokespecial #51                 // Method "<init>":(LPoint;LPoint;)V
      21: areturn

  public static Day15Kt$main$Signal copy$default(Day15Kt$main$Signal, Point, Point, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #22                 // Field sensor:LPoint;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #24                 // Field beacon:LPoint;
      21: astore_2
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokevirtual #55                 // Method copy:(LPoint;LPoint;)LDay15Kt$main$Signal;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #59                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #60                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #62                 // String Signal(sensor=
       9: invokevirtual #66                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #22                 // Field sensor:LPoint;
      16: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #71                 // String , beacon=
      21: invokevirtual #66                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #24                 // Field beacon:LPoint;
      28: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #74                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #76                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #22                 // Field sensor:LPoint;
       4: invokevirtual #79                 // Method Point.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #24                 // Field beacon:LPoint;
      16: invokevirtual #79                 // Method Point.hashCode:()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$Signal
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day15Kt$main$Signal
      20: astore_2
      21: aload_0
      22: getfield      #22                 // Field sensor:LPoint;
      25: aload_2
      26: getfield      #22                 // Field sensor:LPoint;
      29: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #24                 // Field beacon:LPoint;
      41: aload_2
      42: getfield      #24                 // Field beacon:LPoint;
      45: invokestatic  #87                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: iconst_1
      54: ireturn
}