private const val TOTAL_DISK_SPACE = 70000000L
private const val SPACE_NEEDED_FOR_UPDATE = 30000000L
fun main() {
    fun part1(fileTree: TreeNode): Long {
        return fileTree.getAllSubdirectories().filter { it.totalSize <= 100_000 }.sumOf { it.totalSize }
    }

    fun part2(fileTree: TreeNode): Long {
        val spaceAvailable = TOTAL_DISK_SPACE - fileTree.totalSize
        val spaceToBeFreed = SPACE_NEEDED_FOR_UPDATE - spaceAvailable
        return fileTree.getAllSubdirectories().sortedBy { it.totalSize }
            .firstOrNull { it.totalSize > spaceToBeFreed }?.totalSize ?: 0L
    }

    val testInput = readInput("Day07_test")
    val testInputFileTree = buildFileTree(testInput)
    check(part1(testInputFileTree) == 95_437L)
    check(part2(testInputFileTree) == 24_933_642L)

    val input = readInput("Day07")
    val inputFileTree = buildFileTree(input)
    println(part1(inputFileTree))
    println(part2(inputFileTree))
}

private fun buildFileTree(consoleLog: List<String>): TreeNode {
    val rootNode = DirNode("/", null)
    var currentNode = rootNode as TreeNode
    consoleLog.forEach { line ->
        when {
            line.isCdCommand() -> {
                val (_, _, name) = line.splitWords()
                currentNode = when (name) {
                    ".." -> currentNode.parent ?: return@forEach
                    "/" -> rootNode
                    else -> currentNode.getChildByName(name)
                }
            }
            line.isDir() -> {
                val (_, name) = line.splitWords()
                currentNode.addChild(DirNode(name))
            }
            line.isFile() -> {
                val (size, name) = line.splitWords()
                currentNode.addChild(FileNode(name, size.toLong()))
            }
        }
    }
    return rootNode
}

private fun String.isDir() = startsWith("dir")
private fun String.isFile() = "\\d+ [\\w.]+".toRegex().matches(this)
private fun String.isCdCommand() = startsWith("$ cd")

private abstract class TreeNode(private val name: String, var parent: TreeNode?, val children: MutableList<TreeNode>?) {
    open val totalSize: Long
        get() {
            return children?.sumOf { it.totalSize } ?: 0
        }

    fun addChild(node: TreeNode) {
        node.parent = this
        children?.add(node)
    }

    fun getChildByName(name: String): TreeNode {
        return children?.firstOrNull { it.name == name } ?: this
    }

    fun getAllSubdirectories(): List<DirNode> {
        return getAllSubNodes().filterIsInstance<DirNode>()
    }

    private fun getAllSubNodes(): List<TreeNode> {
        val result = mutableListOf<TreeNode>()
        if (children != null) {
            for (child in children) {
                result.addAll(child.getAllSubNodes())
                result.add(child)
            }
        }
        return result
    }
}

private class DirNode(name: String, parent: TreeNode? = null, children: MutableList<TreeNode> = mutableListOf()) :
    TreeNode(name, parent, children)

private class FileNode(name: String, override val totalSize: Long, parent: DirNode? = null) :
    TreeNode(name, parent, null)

Compiled from "Comparisons.kt"
public final class Day07Kt$main$part2$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public Day07Kt$main$part2$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class DirNode
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method DirNode.getTotalSize:()J
      12: invokestatic  #33                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class DirNode
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method DirNode.getTotalSize:()J
      32: invokestatic  #33                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "Day07.kt"
public final class Day07Kt {
  private static final long TOTAL_DISK_SPACE;

  private static final long SPACE_NEEDED_FOR_UPDATE;

  public static final void main();
    Code:
       0: ldc           #8                  // String Day07_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method buildFileTree:(Ljava/util/List;)LTreeNode;
      10: astore_1
      11: aload_1
      12: invokestatic  #22                 // Method main$part1:(LTreeNode;)J
      15: ldc2_w        #23                 // long 95437l
      18: lcmp
      19: ifne          26
      22: iconst_1
      23: goto          27
      26: iconst_0
      27: ifne          40
      30: new           #26                 // class java/lang/IllegalStateException
      33: dup
      34: ldc           #28                 // String Check failed.
      36: invokespecial #32                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      39: athrow
      40: aload_1
      41: invokestatic  #35                 // Method main$part2:(LTreeNode;)J
      44: ldc2_w        #36                 // long 24933642l
      47: lcmp
      48: ifne          55
      51: iconst_1
      52: goto          56
      55: iconst_0
      56: ifne          69
      59: new           #26                 // class java/lang/IllegalStateException
      62: dup
      63: ldc           #28                 // String Check failed.
      65: invokespecial #32                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      68: athrow
      69: ldc           #39                 // String Day07
      71: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      74: astore_2
      75: aload_2
      76: invokestatic  #18                 // Method buildFileTree:(Ljava/util/List;)LTreeNode;
      79: astore_3
      80: aload_3
      81: invokestatic  #22                 // Method main$part1:(LTreeNode;)J
      84: lstore        4
      86: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      89: lload         4
      91: invokevirtual #51                 // Method java/io/PrintStream.println:(J)V
      94: aload_3
      95: invokestatic  #35                 // Method main$part2:(LTreeNode;)J
      98: lstore        4
     100: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: lload         4
     105: invokevirtual #51                 // Method java/io/PrintStream.println:(J)V
     108: return

  private static final TreeNode buildFileTree(java.util.List<java.lang.String>);
    Code:
       0: new           #64                 // class DirNode
       3: dup
       4: ldc           #66                 // String /
       6: aconst_null
       7: aconst_null
       8: iconst_4
       9: aconst_null
      10: invokespecial #69                 // Method DirNode."<init>":(Ljava/lang/String;LTreeNode;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      13: astore_1
      14: aconst_null
      15: astore_2
      16: aload_1
      17: checkcast     #61                 // class TreeNode
      20: astore_2
      21: aload_0
      22: checkcast     #71                 // class java/lang/Iterable
      25: astore_3
      26: iconst_0
      27: istore        4
      29: aload_3
      30: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        5
      37: aload         5
      39: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          262
      47: aload         5
      49: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        6
      56: aload         6
      58: checkcast     #87                 // class java/lang/String
      61: astore        7
      63: iconst_0
      64: istore        8
      66: nop
      67: aload         7
      69: invokestatic  #91                 // Method isCdCommand:(Ljava/lang/String;)Z
      72: ifeq          144
      75: aload         7
      77: invokestatic  #94                 // Method UtilsKt.splitWords:(Ljava/lang/String;)Ljava/util/List;
      80: iconst_2
      81: invokeinterface #98,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      86: checkcast     #87                 // class java/lang/String
      89: astore        9
      91: aload         9
      93: astore        10
      95: aload         10
      97: ldc           #100                // String ..
      99: invokestatic  #106                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     102: ifeq          117
     105: aload_2
     106: invokevirtual #110                // Method TreeNode.getParent:()LTreeNode;
     109: dup
     110: ifnonnull     140
     113: pop
     114: goto          258
     117: aload         10
     119: ldc           #66                 // String /
     121: invokestatic  #106                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     124: ifeq          134
     127: aload_1
     128: checkcast     #61                 // class TreeNode
     131: goto          140
     134: aload_2
     135: aload         9
     137: invokevirtual #114                // Method TreeNode.getChildByName:(Ljava/lang/String;)LTreeNode;
     140: astore_2
     141: goto          257
     144: aload         7
     146: invokestatic  #117                // Method isDir:(Ljava/lang/String;)Z
     149: ifeq          192
     152: aload         7
     154: invokestatic  #94                 // Method UtilsKt.splitWords:(Ljava/lang/String;)Ljava/util/List;
     157: iconst_1
     158: invokeinterface #98,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     163: checkcast     #87                 // class java/lang/String
     166: astore        9
     168: aload_2
     169: new           #64                 // class DirNode
     172: dup
     173: aload         9
     175: aconst_null
     176: aconst_null
     177: bipush        6
     179: aconst_null
     180: invokespecial #69                 // Method DirNode."<init>":(Ljava/lang/String;LTreeNode;Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     183: checkcast     #61                 // class TreeNode
     186: invokevirtual #121                // Method TreeNode.addChild:(LTreeNode;)V
     189: goto          257
     192: aload         7
     194: invokestatic  #124                // Method isFile:(Ljava/lang/String;)Z
     197: ifeq          257
     200: aload         7
     202: invokestatic  #94                 // Method UtilsKt.splitWords:(Ljava/lang/String;)Ljava/util/List;
     205: astore        11
     207: aload         11
     209: iconst_0
     210: invokeinterface #98,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     215: checkcast     #87                 // class java/lang/String
     218: astore        9
     220: aload         11
     222: iconst_1
     223: invokeinterface #98,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     228: checkcast     #87                 // class java/lang/String
     231: astore        10
     233: aload_2
     234: new           #126                // class FileNode
     237: dup
     238: aload         10
     240: aload         9
     242: invokestatic  #132                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     245: aconst_null
     246: iconst_4
     247: aconst_null
     248: invokespecial #135                // Method FileNode."<init>":(Ljava/lang/String;JLDirNode;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     251: checkcast     #61                 // class TreeNode
     254: invokevirtual #121                // Method TreeNode.addChild:(LTreeNode;)V
     257: nop
     258: nop
     259: goto          37
     262: nop
     263: aload_1
     264: checkcast     #61                 // class TreeNode
     267: areturn

  private static final boolean isDir(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #152                // String dir
       3: iconst_0
       4: iconst_2
       5: aconst_null
       6: invokestatic  #158                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
       9: ireturn

  private static final boolean isFile(java.lang.String);
    Code:
       0: new           #161                // class kotlin/text/Regex
       3: dup
       4: ldc           #163                // String \\d+ [\\w.]+
       6: invokespecial #164                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: aload_0
      10: checkcast     #166                // class java/lang/CharSequence
      13: invokevirtual #170                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
      16: ireturn

  private static final boolean isCdCommand(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #173                // String $ cd
       3: iconst_0
       4: iconst_2
       5: aconst_null
       6: invokestatic  #158                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
       9: ireturn

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

  private static final long main$part1(TreeNode);
    Code:
       0: aload_0
       1: invokevirtual #183                // Method TreeNode.getAllSubdirectories:()Ljava/util/List;
       4: checkcast     #71                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #185                // class java/util/ArrayList
      15: dup
      16: invokespecial #187                // Method java/util/ArrayList."<init>":()V
      19: checkcast     #189                // class java/util/Collection
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload_3
      28: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        6
      35: aload         6
      37: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          97
      45: aload         6
      47: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        7
      54: aload         7
      56: checkcast     #64                 // class DirNode
      59: astore        8
      61: iconst_0
      62: istore        9
      64: aload         8
      66: invokevirtual #193                // Method DirNode.getTotalSize:()J
      69: ldc2_w        #194                // long 100000l
      72: lcmp
      73: ifgt          80
      76: iconst_1
      77: goto          81
      80: iconst_0
      81: ifeq          35
      84: aload         4
      86: aload         7
      88: invokeinterface #199,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: goto          35
      97: aload         4
      99: checkcast     #59                 // class java/util/List
     102: nop
     103: checkcast     #71                 // class java/lang/Iterable
     106: astore_1
     107: lconst_0
     108: lstore_2
     109: aload_1
     110: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     115: astore        4
     117: aload         4
     119: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     124: ifeq          165
     127: aload         4
     129: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     134: astore        5
     136: lload_2
     137: aload         5
     139: checkcast     #64                 // class DirNode
     142: astore        6
     144: lstore        10
     146: iconst_0
     147: istore        7
     149: aload         6
     151: invokevirtual #193                // Method DirNode.getTotalSize:()J
     154: lstore        12
     156: lload         10
     158: lload         12
     160: ladd
     161: lstore_2
     162: goto          117
     165: lload_2
     166: lreturn

  private static final long main$part2(TreeNode);
    Code:
       0: ldc2_w        #211                // long 70000000l
       3: aload_0
       4: invokevirtual #213                // Method TreeNode.getTotalSize:()J
       7: lsub
       8: lstore_1
       9: ldc2_w        #214                // long 30000000l
      12: lload_1
      13: lsub
      14: lstore_3
      15: aload_0
      16: invokevirtual #183                // Method TreeNode.getAllSubdirectories:()Ljava/util/List;
      19: checkcast     #71                 // class java/lang/Iterable
      22: astore        6
      24: iconst_0
      25: istore        7
      27: aload         6
      29: new           #217                // class Day07Kt$main$part2$$inlined$sortedBy$1
      32: dup
      33: invokespecial #218                // Method Day07Kt$main$part2$$inlined$sortedBy$1."<init>":()V
      36: checkcast     #220                // class java/util/Comparator
      39: invokestatic  #226                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      42: checkcast     #71                 // class java/lang/Iterable
      45: astore        6
      47: nop
      48: iconst_0
      49: istore        7
      51: aload         6
      53: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        8
      60: aload         8
      62: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          112
      70: aload         8
      72: invokeinterface #85,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        9
      79: aload         9
      81: checkcast     #64                 // class DirNode
      84: astore        10
      86: iconst_0
      87: istore        11
      89: aload         10
      91: invokevirtual #193                // Method DirNode.getTotalSize:()J
      94: lload_3
      95: lcmp
      96: ifle          103
      99: iconst_1
     100: goto          104
     103: iconst_0
     104: ifeq          60
     107: aload         9
     109: goto          113
     112: aconst_null
     113: checkcast     #64                 // class DirNode
     116: astore        5
     118: aload         5
     120: ifnull        131
     123: aload         5
     125: invokevirtual #193                // Method DirNode.getTotalSize:()J
     128: goto          132
     131: lconst_0
     132: lreturn
}


typealias Stack = List<Char>

fun main() {

    fun solve(input: Pair<MutableList<Stack>, List<StackMove>>, inputModifier: (List<Char>) -> List<Char>): String {
        val (stacks, moves) = input
        moves.forEach { move ->
            stacks[move.to] = stacks[move.from].take(move.amount).let { inputModifier.invoke(it) } + stacks[move.to]
            stacks[move.from] = stacks[move.from].drop(move.amount)
        }
        return stacks.filter { it.isNotEmpty() }.map { it.first() }.joinToString("")
    }

    fun part1(input: Pair<MutableList<Stack>, List<StackMove>>) = solve(input) { it.reversed() }

    fun part2(input: Pair<MutableList<Stack>, List<StackMove>>) = solve(input) { it }

    check(part1(parseInput("Day05_test")) == "CMZ")
    check(part2(parseInput("Day05_test")) == "MCD")

    println(part1(parseInput("Day05")))
    println(part2(parseInput("Day05")))
}

private fun parseInput(name: String): Pair<MutableList<Stack>, List<StackMove>> {

    fun parseStacks(inputString: String): MutableList<Stack> {
        val stackValues = inputString.lines().dropLast(1)
            .map { line ->
                line.replace("    ", "[-]")
                    .remove("[^\\w-]".toRegex())
                    .toList()
            }
            .transpose()
            .map { stack -> stack.filter { it != '-' }.toMutableList() }

        return stackValues.toMutableList()
    }

    fun parseMoves(inputString: String): List<StackMove> {
        val lineRegex = "(\\d+)".toRegex()
        return inputString.lines()
            .map { line -> lineRegex.findAll(line).map { it.value.toInt() }.toList() }
            .map { (amount, from, to) -> StackMove(amount, from - 1, to - 1) }
    }

    val (stacks, moves) = readGroupedInput(name)
    return Pair(parseStacks(stacks), parseMoves(moves))
}

private data class StackMove(
    val amount: Int,
    val from: Int,
    val to: Int
)

Compiled from "Day05.kt"
public final class Day05Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day05_test
       2: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lkotlin/Pair;
       5: invokestatic  #16                 // Method main$part1:(Lkotlin/Pair;)Ljava/lang/String;
       8: ldc           #18                 // String CMZ
      10: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      13: ifne          26
      16: new           #26                 // class java/lang/IllegalStateException
      19: dup
      20: ldc           #28                 // String Check failed.
      22: invokespecial #32                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      25: athrow
      26: ldc           #8                  // String Day05_test
      28: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lkotlin/Pair;
      31: invokestatic  #35                 // Method main$part2:(Lkotlin/Pair;)Ljava/lang/String;
      34: ldc           #37                 // String MCD
      36: invokestatic  #24                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      39: ifne          52
      42: new           #26                 // class java/lang/IllegalStateException
      45: dup
      46: ldc           #28                 // String Check failed.
      48: invokespecial #32                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      51: athrow
      52: ldc           #39                 // String Day05
      54: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lkotlin/Pair;
      57: invokestatic  #16                 // Method main$part1:(Lkotlin/Pair;)Ljava/lang/String;
      60: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      63: swap
      64: invokevirtual #51                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      67: ldc           #39                 // String Day05
      69: invokestatic  #12                 // Method parseInput:(Ljava/lang/String;)Lkotlin/Pair;
      72: invokestatic  #35                 // Method main$part2:(Lkotlin/Pair;)Ljava/lang/String;
      75: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      78: swap
      79: invokevirtual #51                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      82: return

  private static final kotlin.Pair<java.util.List<java.util.List<java.lang.Character>>, java.util.List<StackMove>> parseInput(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #58                 // Method UtilsKt.readGroupedInput:(Ljava/lang/String;)Ljava/util/List;
       4: astore_1
       5: aload_1
       6: iconst_0
       7: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      12: checkcast     #66                 // class java/lang/String
      15: astore_2
      16: aload_1
      17: iconst_1
      18: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      23: checkcast     #66                 // class java/lang/String
      26: astore_3
      27: new           #68                 // class kotlin/Pair
      30: dup
      31: aload_2
      32: invokestatic  #71                 // Method parseInput$parseStacks:(Ljava/lang/String;)Ljava/util/List;
      35: aload_3
      36: invokestatic  #74                 // Method parseInput$parseMoves:(Ljava/lang/String;)Ljava/util/List;
      39: invokespecial #77                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      42: areturn

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

  private static final java.lang.String main$solve(kotlin.Pair<? extends java.util.List<java.util.List<java.lang.Character>>, ? extends java.util.List<StackMove>>, kotlin.jvm.functions.Function1<? super java.util.List<java.lang.Character>, ? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: invokevirtual #93                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
       4: checkcast     #60                 // class java/util/List
       7: astore_2
       8: aload_0
       9: invokevirtual #96                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      12: checkcast     #60                 // class java/util/List
      15: astore_3
      16: aload_3
      17: checkcast     #98                 // class java/lang/Iterable
      20: astore        4
      22: iconst_0
      23: istore        5
      25: aload         4
      27: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        6
      34: aload         6
      36: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          184
      44: aload         6
      46: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: astore        7
      53: aload         7
      55: checkcast     #113                // class StackMove
      58: astore        8
      60: iconst_0
      61: istore        9
      63: aload_2
      64: aload         8
      66: invokevirtual #117                // Method StackMove.getTo:()I
      69: aload_2
      70: aload         8
      72: invokevirtual #120                // Method StackMove.getFrom:()I
      75: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      80: checkcast     #98                 // class java/lang/Iterable
      83: aload         8
      85: invokevirtual #123                // Method StackMove.getAmount:()I
      88: invokestatic  #129                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      91: astore        10
      93: istore        11
      95: astore        12
      97: iconst_0
      98: istore        13
     100: aload_1
     101: aload         10
     103: invokeinterface #135,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     108: checkcast     #60                 // class java/util/List
     111: astore        14
     113: aload         12
     115: iload         11
     117: aload         14
     119: checkcast     #137                // class java/util/Collection
     122: aload_2
     123: aload         8
     125: invokevirtual #117                // Method StackMove.getTo:()I
     128: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     133: checkcast     #98                 // class java/lang/Iterable
     136: invokestatic  #141                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     139: invokeinterface #145,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     144: pop
     145: aload_2
     146: aload         8
     148: invokevirtual #120                // Method StackMove.getFrom:()I
     151: aload_2
     152: aload         8
     154: invokevirtual #120                // Method StackMove.getFrom:()I
     157: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     162: checkcast     #98                 // class java/lang/Iterable
     165: aload         8
     167: invokevirtual #123                // Method StackMove.getAmount:()I
     170: invokestatic  #148                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     173: invokeinterface #145,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     178: pop
     179: nop
     180: nop
     181: goto          34
     184: nop
     185: aload_2
     186: checkcast     #98                 // class java/lang/Iterable
     189: astore        4
     191: iconst_0
     192: istore        5
     194: aload         4
     196: astore        6
     198: new           #150                // class java/util/ArrayList
     201: dup
     202: invokespecial #152                // Method java/util/ArrayList."<init>":()V
     205: checkcast     #137                // class java/util/Collection
     208: astore        7
     210: iconst_0
     211: istore        8
     213: aload         6
     215: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     220: astore        9
     222: aload         9
     224: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     229: ifeq          286
     232: aload         9
     234: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     239: astore        10
     241: aload         10
     243: checkcast     #60                 // class java/util/List
     246: astore        11
     248: iconst_0
     249: istore        12
     251: aload         11
     253: checkcast     #137                // class java/util/Collection
     256: invokeinterface #155,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     261: ifne          268
     264: iconst_1
     265: goto          269
     268: iconst_0
     269: nop
     270: ifeq          222
     273: aload         7
     275: aload         10
     277: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     282: pop
     283: goto          222
     286: aload         7
     288: checkcast     #60                 // class java/util/List
     291: nop
     292: checkcast     #98                 // class java/lang/Iterable
     295: astore        4
     297: nop
     298: iconst_0
     299: istore        5
     301: aload         4
     303: astore        6
     305: new           #150                // class java/util/ArrayList
     308: dup
     309: aload         4
     311: bipush        10
     313: invokestatic  #163                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     316: invokespecial #166                // Method java/util/ArrayList."<init>":(I)V
     319: checkcast     #137                // class java/util/Collection
     322: astore        7
     324: iconst_0
     325: istore        8
     327: aload         6
     329: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     334: astore        9
     336: aload         9
     338: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     343: ifeq          395
     346: aload         9
     348: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     353: astore        10
     355: aload         7
     357: aload         10
     359: checkcast     #60                 // class java/util/List
     362: astore        11
     364: astore        15
     366: iconst_0
     367: istore        12
     369: aload         11
     371: invokestatic  #170                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     374: checkcast     #172                // class java/lang/Character
     377: invokevirtual #176                // Method java/lang/Character.charValue:()C
     380: invokestatic  #180                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     383: aload         15
     385: swap
     386: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     391: pop
     392: goto          336
     395: aload         7
     397: checkcast     #60                 // class java/util/List
     400: nop
     401: checkcast     #98                 // class java/lang/Iterable
     404: ldc           #182                // String
     406: checkcast     #184                // class java/lang/CharSequence
     409: aconst_null
     410: aconst_null
     411: iconst_0
     412: aconst_null
     413: aconst_null
     414: bipush        62
     416: aconst_null
     417: invokestatic  #188                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     420: areturn

  private static final java.util.List main$part1$lambda$4(java.util.List);
    Code:
       0: aload_0
       1: ldc           #221                // String it
       3: invokestatic  #225                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #98                 // class java/lang/Iterable
      10: invokestatic  #229                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
      13: areturn

  private static final java.lang.String main$part1(kotlin.Pair<? extends java.util.List<java.util.List<java.lang.Character>>, ? extends java.util.List<StackMove>>);
    Code:
       0: aload_0
       1: invokedynamic #245,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       6: invokestatic  #247                // Method main$solve:(Lkotlin/Pair;Lkotlin/jvm/functions/Function1;)Ljava/lang/String;
       9: areturn

  private static final java.util.List main$part2$lambda$5(java.util.List);
    Code:
       0: aload_0
       1: ldc           #221                // String it
       3: invokestatic  #225                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: areturn

  private static final java.lang.String main$part2(kotlin.Pair<? extends java.util.List<java.util.List<java.lang.Character>>, ? extends java.util.List<StackMove>>);
    Code:
       0: aload_0
       1: invokedynamic #252,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
       6: invokestatic  #247                // Method main$solve:(Lkotlin/Pair;Lkotlin/jvm/functions/Function1;)Ljava/lang/String;
       9: areturn

  private static final java.util.List<java.util.List<java.lang.Character>> parseInput$parseStacks(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #184                // class java/lang/CharSequence
       4: invokestatic  #259                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
       7: iconst_1
       8: invokestatic  #263                // Method kotlin/collections/CollectionsKt.dropLast:(Ljava/util/List;I)Ljava/util/List;
      11: checkcast     #98                 // class java/lang/Iterable
      14: astore_2
      15: nop
      16: iconst_0
      17: istore_3
      18: aload_2
      19: astore        4
      21: new           #150                // class java/util/ArrayList
      24: dup
      25: aload_2
      26: bipush        10
      28: invokestatic  #163                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      31: invokespecial #166                // Method java/util/ArrayList."<init>":(I)V
      34: checkcast     #137                // class java/util/Collection
      37: astore        5
      39: iconst_0
      40: istore        6
      42: aload         4
      44: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        7
      51: aload         7
      53: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifeq          129
      61: aload         7
      63: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: astore        8
      70: aload         5
      72: aload         8
      74: checkcast     #66                 // class java/lang/String
      77: astore        9
      79: astore        20
      81: iconst_0
      82: istore        10
      84: aload         9
      86: ldc_w         #265                // String
      89: ldc_w         #267                // String [-]
      92: iconst_0
      93: iconst_4
      94: aconst_null
      95: invokestatic  #271                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      98: new           #273                // class kotlin/text/Regex
     101: dup
     102: ldc_w         #275                // String [^\\w-]
     105: invokespecial #276                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     108: invokestatic  #280                // Method UtilsKt.remove:(Ljava/lang/String;Lkotlin/text/Regex;)Ljava/lang/String;
     111: checkcast     #184                // class java/lang/CharSequence
     114: invokestatic  #283                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
     117: aload         20
     119: swap
     120: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     125: pop
     126: goto          51
     129: aload         5
     131: checkcast     #60                 // class java/util/List
     134: nop
     135: invokestatic  #286                // Method UtilsKt.transpose:(Ljava/util/List;)Ljava/util/List;
     138: checkcast     #98                 // class java/lang/Iterable
     141: astore_2
     142: nop
     143: iconst_0
     144: istore_3
     145: aload_2
     146: astore        4
     148: new           #150                // class java/util/ArrayList
     151: dup
     152: aload_2
     153: bipush        10
     155: invokestatic  #163                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     158: invokespecial #166                // Method java/util/ArrayList."<init>":(I)V
     161: checkcast     #137                // class java/util/Collection
     164: astore        5
     166: iconst_0
     167: istore        6
     169: aload         4
     171: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     176: astore        7
     178: aload         7
     180: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     185: ifeq          333
     188: aload         7
     190: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     195: astore        8
     197: aload         5
     199: aload         8
     201: checkcast     #60                 // class java/util/List
     204: astore        9
     206: astore        20
     208: iconst_0
     209: istore        10
     211: aload         9
     213: checkcast     #98                 // class java/lang/Iterable
     216: astore        11
     218: iconst_0
     219: istore        12
     221: aload         11
     223: astore        13
     225: new           #150                // class java/util/ArrayList
     228: dup
     229: invokespecial #152                // Method java/util/ArrayList."<init>":()V
     232: checkcast     #137                // class java/util/Collection
     235: astore        14
     237: iconst_0
     238: istore        15
     240: aload         13
     242: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     247: astore        16
     249: aload         16
     251: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     256: ifeq          309
     259: aload         16
     261: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     266: astore        17
     268: aload         17
     270: checkcast     #172                // class java/lang/Character
     273: invokevirtual #176                // Method java/lang/Character.charValue:()C
     276: istore        18
     278: iconst_0
     279: istore        19
     281: iload         18
     283: bipush        45
     285: if_icmpeq     292
     288: iconst_1
     289: goto          293
     292: iconst_0
     293: ifeq          249
     296: aload         14
     298: aload         17
     300: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     305: pop
     306: goto          249
     309: aload         14
     311: checkcast     #60                 // class java/util/List
     314: nop
     315: checkcast     #137                // class java/util/Collection
     318: invokestatic  #290                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     321: aload         20
     323: swap
     324: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     329: pop
     330: goto          178
     333: aload         5
     335: checkcast     #60                 // class java/util/List
     338: nop
     339: astore_1
     340: aload_1
     341: checkcast     #137                // class java/util/Collection
     344: invokestatic  #290                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     347: areturn

  private static final int parseInput$parseMoves$lambda$10$lambda$9(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc           #221                // String it
       3: invokestatic  #225                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #306,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      12: invokestatic  #312                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      15: ireturn

  private static final java.util.List<StackMove> parseInput$parseMoves(java.lang.String);
    Code:
       0: new           #273                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #316                // String (\\d+)
       7: invokespecial #276                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: astore_1
      11: aload_0
      12: checkcast     #184                // class java/lang/CharSequence
      15: invokestatic  #259                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      18: checkcast     #98                 // class java/lang/Iterable
      21: astore_2
      22: nop
      23: iconst_0
      24: istore_3
      25: aload_2
      26: astore        4
      28: new           #150                // class java/util/ArrayList
      31: dup
      32: aload_2
      33: bipush        10
      35: invokestatic  #163                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      38: invokespecial #166                // Method java/util/ArrayList."<init>":(I)V
      41: checkcast     #137                // class java/util/Collection
      44: astore        5
      46: iconst_0
      47: istore        6
      49: aload         4
      51: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      56: astore        7
      58: aload         7
      60: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          126
      68: aload         7
      70: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        8
      77: aload         5
      79: aload         8
      81: checkcast     #66                 // class java/lang/String
      84: astore        9
      86: astore        14
      88: iconst_0
      89: istore        10
      91: aload_1
      92: aload         9
      94: checkcast     #184                // class java/lang/CharSequence
      97: iconst_0
      98: iconst_2
      99: aconst_null
     100: invokestatic  #320                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
     103: invokedynamic #326,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     108: invokestatic  #332                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     111: invokestatic  #335                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     114: aload         14
     116: swap
     117: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: goto          58
     126: aload         5
     128: checkcast     #60                 // class java/util/List
     131: nop
     132: checkcast     #98                 // class java/lang/Iterable
     135: astore_2
     136: nop
     137: iconst_0
     138: istore_3
     139: aload_2
     140: astore        4
     142: new           #150                // class java/util/ArrayList
     145: dup
     146: aload_2
     147: bipush        10
     149: invokestatic  #163                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     152: invokespecial #166                // Method java/util/ArrayList."<init>":(I)V
     155: checkcast     #137                // class java/util/Collection
     158: astore        5
     160: iconst_0
     161: istore        6
     163: aload         4
     165: invokeinterface #102,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     170: astore        7
     172: aload         7
     174: invokeinterface #108,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     179: ifeq          282
     182: aload         7
     184: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     189: astore        8
     191: aload         5
     193: aload         8
     195: checkcast     #60                 // class java/util/List
     198: astore        9
     200: astore        14
     202: iconst_0
     203: istore        10
     205: aload         9
     207: iconst_0
     208: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     213: checkcast     #337                // class java/lang/Number
     216: invokevirtual #340                // Method java/lang/Number.intValue:()I
     219: istore        11
     221: aload         9
     223: iconst_1
     224: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     229: checkcast     #337                // class java/lang/Number
     232: invokevirtual #340                // Method java/lang/Number.intValue:()I
     235: istore        12
     237: aload         9
     239: iconst_2
     240: invokeinterface #64,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     245: checkcast     #337                // class java/lang/Number
     248: invokevirtual #340                // Method java/lang/Number.intValue:()I
     251: istore        13
     253: new           #113                // class StackMove
     256: dup
     257: iload         11
     259: iload         12
     261: iconst_1
     262: isub
     263: iload         13
     265: iconst_1
     266: isub
     267: invokespecial #343                // Method StackMove."<init>":(III)V
     270: aload         14
     272: swap
     273: invokeinterface #159,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     278: pop
     279: goto          172
     282: aload         5
     284: checkcast     #60                 // class java/util/List
     287: nop
     288: areturn
}


import kotlin.math.abs

private fun parseInput(name: String) =
    readInput(name).map { line ->
        line.split(":").map { it.getAllInts().pair() }
    }.map { (sensorXY, beaconXY) -> Sensor(sensorXY, beaconXY) }

fun main() {
    fun Position.tuningFrequency() = 4000000L * x + y

    fun coverageRangesForY(y: Int, sensors: List<Sensor>, valueRange: IntRange): List<IntRange> {
        val ranges = mutableListOf<IntRange>()
        sensors.forEach { sensor ->
            val distanceToY = abs(sensor.y - y)
            val radiusForY = (sensor.distanceToClosestBeacon - distanceToY).coerceAtLeast(0)
            if (radiusForY > 0) {
                ranges.add(((sensor.x - radiusForY)..(sensor.x + radiusForY)).limitValuesInRange(valueRange))
            }
        }
        return ranges
    }

    fun part1(sensors: List<Sensor>, y: Int): Int {
        val xPositionsWithSensorsOrBeacons = sensors
            .flatMap { listOf(it.position, it.closestBeacon) }
            .filter { it.y == y }
            .map { it.x }
            .toSet()

        val valueRange = sensors.map { it.closestBeacon.x }.valueRange()
        val xPositionsWithoutBeacon = coverageRangesForY(y, sensors, valueRange)
            .flatMap { it.toList() }
            .toSet()
            .minus(xPositionsWithSensorsOrBeacons)

        return xPositionsWithoutBeacon.size
    }

    fun part2(sensors: List<Sensor>, valueRange: IntRange): Long {
        valueRange.forEach { y ->
            val coverageRanges = coverageRangesForY(y, sensors, valueRange).sortedBy { it.first }
            var rightBoundary = coverageRanges.first().last
            for (i in 1 until coverageRanges.size) {
                val range = coverageRanges[i]
                if (rightBoundary < range.first) {
                    return Position(rightBoundary + 1, y).tuningFrequency()
                }
                rightBoundary = range.last.coerceAtLeast(rightBoundary)
            }
        }
        return 0L
    }

    val testInput = parseInput("Day15_test")
    check(part1(testInput, 10) == 26)
    check(part2(testInput, 0..20) == 56000011L)

    val input = parseInput("Day15")
    println(part1(input, 2000000))
    println(part2(input, 0..4000000))

}

private data class Sensor(val position: Position, val closestBeacon: Position) {
    val x: Int
        get() = position.x
    val y: Int
        get() = position.y

    val distanceToClosestBeacon: Int
        get() = position.manhattanDistanceTo(closestBeacon)
}

Compiled from "Day15.kt"
public final class Day15Kt {
  private static final java.util.List<Sensor> parseInput(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #12                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       4: checkcast     #14                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #16                 // class java/util/ArrayList
      15: dup
      16: aload_1
      17: bipush        10
      19: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      22: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
      25: checkcast     #28                 // class java/util/Collection
      28: astore        4
      30: iconst_0
      31: istore        5
      33: aload_3
      34: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        6
      41: aload         6
      43: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          216
      51: aload         6
      53: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         4
      62: aload         7
      64: checkcast     #44                 // class java/lang/String
      67: astore        8
      69: astore        20
      71: iconst_0
      72: istore        9
      74: aload         8
      76: checkcast     #46                 // class java/lang/CharSequence
      79: iconst_1
      80: anewarray     #44                 // class java/lang/String
      83: astore        10
      85: aload         10
      87: iconst_0
      88: ldc           #48                 // String :
      90: aastore
      91: aload         10
      93: iconst_0
      94: iconst_0
      95: bipush        6
      97: aconst_null
      98: invokestatic  #54                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     101: checkcast     #14                 // class java/lang/Iterable
     104: astore        10
     106: iconst_0
     107: istore        11
     109: aload         10
     111: astore        12
     113: new           #16                 // class java/util/ArrayList
     116: dup
     117: aload         10
     119: bipush        10
     121: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     124: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     127: checkcast     #28                 // class java/util/Collection
     130: astore        13
     132: iconst_0
     133: istore        14
     135: aload         12
     137: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     142: astore        15
     144: aload         15
     146: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifeq          197
     154: aload         15
     156: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     161: astore        16
     163: aload         13
     165: aload         16
     167: checkcast     #44                 // class java/lang/String
     170: astore        17
     172: astore        18
     174: iconst_0
     175: istore        19
     177: aload         17
     179: invokestatic  #57                 // Method UtilsKt.getAllInts:(Ljava/lang/String;)Ljava/util/List;
     182: invokestatic  #61                 // Method UtilsKt.pair:(Ljava/util/List;)Lkotlin/Pair;
     185: aload         18
     187: swap
     188: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     193: pop
     194: goto          144
     197: aload         13
     199: checkcast     #67                 // class java/util/List
     202: nop
     203: nop
     204: aload         20
     206: swap
     207: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     212: pop
     213: goto          41
     216: aload         4
     218: checkcast     #67                 // class java/util/List
     221: nop
     222: checkcast     #14                 // class java/lang/Iterable
     225: astore_1
     226: nop
     227: iconst_0
     228: istore_2
     229: aload_1
     230: astore_3
     231: new           #16                 // class java/util/ArrayList
     234: dup
     235: aload_1
     236: bipush        10
     238: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     241: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     244: checkcast     #28                 // class java/util/Collection
     247: astore        4
     249: iconst_0
     250: istore        5
     252: aload_3
     253: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     258: astore        6
     260: aload         6
     262: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     267: ifeq          342
     270: aload         6
     272: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     277: astore        7
     279: aload         4
     281: aload         7
     283: checkcast     #67                 // class java/util/List
     286: astore        8
     288: astore        20
     290: iconst_0
     291: istore        9
     293: aload         8
     295: iconst_0
     296: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     301: checkcast     #73                 // class kotlin/Pair
     304: astore        10
     306: aload         8
     308: iconst_1
     309: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     314: checkcast     #73                 // class kotlin/Pair
     317: astore        11
     319: new           #75                 // class Sensor
     322: dup
     323: aload         10
     325: aload         11
     327: invokespecial #78                 // Method Sensor."<init>":(Lkotlin/Pair;Lkotlin/Pair;)V
     330: aload         20
     332: swap
     333: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     338: pop
     339: goto          260
     342: aload         4
     344: checkcast     #67                 // class java/util/List
     347: nop
     348: areturn

  public static final void main();
    Code:
       0: ldc           #102                // String Day15_test
       2: invokestatic  #104                // Method parseInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: bipush        10
       9: invokestatic  #108                // Method main$part1:(Ljava/util/List;I)I
      12: bipush        26
      14: if_icmpne     21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ifne          35
      25: new           #110                // class java/lang/IllegalStateException
      28: dup
      29: ldc           #112                // String Check failed.
      31: invokespecial #115                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      34: athrow
      35: aload_0
      36: new           #117                // class kotlin/ranges/IntRange
      39: dup
      40: iconst_0
      41: bipush        20
      43: invokespecial #120                // Method kotlin/ranges/IntRange."<init>":(II)V
      46: invokestatic  #124                // Method main$part2:(Ljava/util/List;Lkotlin/ranges/IntRange;)J
      49: ldc2_w        #125                // long 56000011l
      52: lcmp
      53: ifne          60
      56: iconst_1
      57: goto          61
      60: iconst_0
      61: ifne          74
      64: new           #110                // class java/lang/IllegalStateException
      67: dup
      68: ldc           #112                // String Check failed.
      70: invokespecial #115                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      73: athrow
      74: ldc           #128                // String Day15
      76: invokestatic  #104                // Method parseInput:(Ljava/lang/String;)Ljava/util/List;
      79: astore_1
      80: aload_1
      81: ldc           #129                // int 2000000
      83: invokestatic  #108                // Method main$part1:(Ljava/util/List;I)I
      86: istore_2
      87: getstatic     #135                // Field java/lang/System.out:Ljava/io/PrintStream;
      90: iload_2
      91: invokevirtual #140                // Method java/io/PrintStream.println:(I)V
      94: aload_1
      95: new           #117                // class kotlin/ranges/IntRange
      98: dup
      99: iconst_0
     100: ldc           #141                // int 4000000
     102: invokespecial #120                // Method kotlin/ranges/IntRange."<init>":(II)V
     105: invokestatic  #124                // Method main$part2:(Ljava/util/List;Lkotlin/ranges/IntRange;)J
     108: lstore_2
     109: getstatic     #135                // Field java/lang/System.out:Ljava/io/PrintStream;
     112: lload_2
     113: invokevirtual #144                // Method java/io/PrintStream.println:(J)V
     116: return

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

  private static final long main$tuningFrequency(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: ldc2_w        #156                // long 4000000l
       3: aload_0
       4: invokestatic  #161                // Method UtilsKt.getX:(Lkotlin/Pair;)I
       7: i2l
       8: lmul
       9: aload_0
      10: invokestatic  #164                // Method UtilsKt.getY:(Lkotlin/Pair;)I
      13: i2l
      14: ladd
      15: lreturn

  private static final java.util.List<kotlin.ranges.IntRange> main$coverageRangesForY(int, java.util.List<Sensor>, kotlin.ranges.IntRange);
    Code:
       0: new           #16                 // class java/util/ArrayList
       3: dup
       4: invokespecial #170                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #67                 // class java/util/List
      10: astore_3
      11: aload_1
      12: checkcast     #14                 // class java/lang/Iterable
      15: astore        4
      17: iconst_0
      18: istore        5
      20: aload         4
      22: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      27: astore        6
      29: aload         6
      31: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          128
      39: aload         6
      41: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        7
      48: aload         7
      50: checkcast     #75                 // class Sensor
      53: astore        8
      55: iconst_0
      56: istore        9
      58: aload         8
      60: invokevirtual #173                // Method Sensor.getY:()I
      63: iload_0
      64: isub
      65: invokestatic  #179                // Method java/lang/Math.abs:(I)I
      68: istore        10
      70: aload         8
      72: invokevirtual #182                // Method Sensor.getDistanceToClosestBeacon:()I
      75: iload         10
      77: isub
      78: iconst_0
      79: invokestatic  #188                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      82: istore        11
      84: iload         11
      86: ifle          123
      89: aload_3
      90: new           #117                // class kotlin/ranges/IntRange
      93: dup
      94: aload         8
      96: invokevirtual #190                // Method Sensor.getX:()I
      99: iload         11
     101: isub
     102: aload         8
     104: invokevirtual #190                // Method Sensor.getX:()I
     107: iload         11
     109: iadd
     110: invokespecial #120                // Method kotlin/ranges/IntRange."<init>":(II)V
     113: aload_2
     114: invokestatic  #194                // Method UtilsKt.limitValuesInRange:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Lkotlin/ranges/IntRange;
     117: invokeinterface #195,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     122: pop
     123: nop
     124: nop
     125: goto          29
     128: nop
     129: aload_3
     130: areturn

  private static final int main$part1(java.util.List<Sensor>, int);
    Code:
       0: aload_0
       1: checkcast     #14                 // class java/lang/Iterable
       4: astore_3
       5: nop
       6: iconst_0
       7: istore        4
       9: aload_3
      10: astore        5
      12: new           #16                 // class java/util/ArrayList
      15: dup
      16: invokespecial #170                // Method java/util/ArrayList."<init>":()V
      19: checkcast     #28                 // class java/util/Collection
      22: astore        6
      24: iconst_0
      25: istore        7
      27: aload         5
      29: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      34: astore        8
      36: aload         8
      38: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          110
      46: aload         8
      48: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        9
      55: aload         9
      57: checkcast     #75                 // class Sensor
      60: astore        10
      62: iconst_0
      63: istore        11
      65: iconst_2
      66: anewarray     #73                 // class kotlin/Pair
      69: astore        12
      71: aload         12
      73: iconst_0
      74: aload         10
      76: invokevirtual #213                // Method Sensor.getPosition:()Lkotlin/Pair;
      79: aastore
      80: aload         12
      82: iconst_1
      83: aload         10
      85: invokevirtual #216                // Method Sensor.getClosestBeacon:()Lkotlin/Pair;
      88: aastore
      89: aload         12
      91: invokestatic  #220                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      94: checkcast     #14                 // class java/lang/Iterable
      97: astore        10
      99: aload         6
     101: aload         10
     103: invokestatic  #224                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     106: pop
     107: goto          36
     110: aload         6
     112: checkcast     #67                 // class java/util/List
     115: nop
     116: checkcast     #14                 // class java/lang/Iterable
     119: astore_3
     120: nop
     121: iconst_0
     122: istore        4
     124: aload_3
     125: astore        5
     127: new           #16                 // class java/util/ArrayList
     130: dup
     131: invokespecial #170                // Method java/util/ArrayList."<init>":()V
     134: checkcast     #28                 // class java/util/Collection
     137: astore        6
     139: iconst_0
     140: istore        7
     142: aload         5
     144: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     149: astore        8
     151: aload         8
     153: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     158: ifeq          210
     161: aload         8
     163: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     168: astore        9
     170: aload         9
     172: checkcast     #73                 // class kotlin/Pair
     175: astore        10
     177: iconst_0
     178: istore        11
     180: aload         10
     182: invokestatic  #164                // Method UtilsKt.getY:(Lkotlin/Pair;)I
     185: iload_1
     186: if_icmpne     193
     189: iconst_1
     190: goto          194
     193: iconst_0
     194: ifeq          151
     197: aload         6
     199: aload         9
     201: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     206: pop
     207: goto          151
     210: aload         6
     212: checkcast     #67                 // class java/util/List
     215: nop
     216: checkcast     #14                 // class java/lang/Iterable
     219: astore_3
     220: nop
     221: iconst_0
     222: istore        4
     224: aload_3
     225: astore        5
     227: new           #16                 // class java/util/ArrayList
     230: dup
     231: aload_3
     232: bipush        10
     234: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     237: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     240: checkcast     #28                 // class java/util/Collection
     243: astore        6
     245: iconst_0
     246: istore        7
     248: aload         5
     250: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     255: astore        8
     257: aload         8
     259: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     264: ifeq          310
     267: aload         8
     269: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     274: astore        9
     276: aload         6
     278: aload         9
     280: checkcast     #73                 // class kotlin/Pair
     283: astore        10
     285: astore        14
     287: iconst_0
     288: istore        11
     290: aload         10
     292: invokestatic  #161                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     295: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     298: aload         14
     300: swap
     301: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     306: pop
     307: goto          257
     310: aload         6
     312: checkcast     #67                 // class java/util/List
     315: nop
     316: checkcast     #14                 // class java/lang/Iterable
     319: invokestatic  #234                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     322: astore_2
     323: aload_0
     324: checkcast     #14                 // class java/lang/Iterable
     327: astore        4
     329: iconst_0
     330: istore        5
     332: aload         4
     334: astore        6
     336: new           #16                 // class java/util/ArrayList
     339: dup
     340: aload         4
     342: bipush        10
     344: invokestatic  #22                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     347: invokespecial #26                 // Method java/util/ArrayList."<init>":(I)V
     350: checkcast     #28                 // class java/util/Collection
     353: astore        7
     355: iconst_0
     356: istore        8
     358: aload         6
     360: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     365: astore        9
     367: aload         9
     369: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     374: ifeq          423
     377: aload         9
     379: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     384: astore        10
     386: aload         7
     388: aload         10
     390: checkcast     #75                 // class Sensor
     393: astore        11
     395: astore        14
     397: iconst_0
     398: istore        12
     400: aload         11
     402: invokevirtual #216                // Method Sensor.getClosestBeacon:()Lkotlin/Pair;
     405: invokestatic  #161                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     408: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     411: aload         14
     413: swap
     414: invokeinterface #65,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     419: pop
     420: goto          367
     423: aload         7
     425: checkcast     #67                 // class java/util/List
     428: nop
     429: invokestatic  #237                // Method UtilsKt.valueRange:(Ljava/util/List;)Lkotlin/ranges/IntRange;
     432: astore_3
     433: iload_1
     434: aload_0
     435: aload_3
     436: invokestatic  #239                // Method main$coverageRangesForY:(ILjava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
     439: checkcast     #14                 // class java/lang/Iterable
     442: astore        5
     444: nop
     445: iconst_0
     446: istore        6
     448: aload         5
     450: astore        7
     452: new           #16                 // class java/util/ArrayList
     455: dup
     456: invokespecial #170                // Method java/util/ArrayList."<init>":()V
     459: checkcast     #28                 // class java/util/Collection
     462: astore        8
     464: iconst_0
     465: istore        9
     467: aload         7
     469: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     474: astore        10
     476: aload         10
     478: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     483: ifeq          529
     486: aload         10
     488: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     493: astore        11
     495: aload         11
     497: checkcast     #117                // class kotlin/ranges/IntRange
     500: astore        12
     502: iconst_0
     503: istore        13
     505: aload         12
     507: checkcast     #14                 // class java/lang/Iterable
     510: invokestatic  #243                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     513: checkcast     #14                 // class java/lang/Iterable
     516: astore        12
     518: aload         8
     520: aload         12
     522: invokestatic  #224                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     525: pop
     526: goto          476
     529: aload         8
     531: checkcast     #67                 // class java/util/List
     534: nop
     535: checkcast     #14                 // class java/lang/Iterable
     538: invokestatic  #234                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     541: aload_2
     542: checkcast     #14                 // class java/lang/Iterable
     545: invokestatic  #249                // Method kotlin/collections/SetsKt.minus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     548: astore        4
     550: aload         4
     552: invokeinterface #254,  1          // InterfaceMethod java/util/Set.size:()I
     557: ireturn

  private static final long main$part2(java.util.List<Sensor>, kotlin.ranges.IntRange);
    Code:
       0: aload_1
       1: checkcast     #14                 // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: invokeinterface #32,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      13: astore        4
      15: aload         4
      17: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifeq          176
      25: aload         4
      27: checkcast     #275                // class kotlin/collections/IntIterator
      30: invokevirtual #278                // Method kotlin/collections/IntIterator.nextInt:()I
      33: istore        5
      35: iload         5
      37: istore        6
      39: iconst_0
      40: istore        7
      42: iload         6
      44: aload_0
      45: aload_1
      46: invokestatic  #239                // Method main$coverageRangesForY:(ILjava/util/List;Lkotlin/ranges/IntRange;)Ljava/util/List;
      49: checkcast     #14                 // class java/lang/Iterable
      52: astore        8
      54: iconst_0
      55: istore        9
      57: aload         8
      59: new           #280                // class Day15Kt$main$part2$lambda$10$$inlined$sortedBy$1
      62: dup
      63: invokespecial #281                // Method Day15Kt$main$part2$lambda$10$$inlined$sortedBy$1."<init>":()V
      66: checkcast     #283                // class java/util/Comparator
      69: invokestatic  #287                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      72: astore        10
      74: aload         10
      76: invokestatic  #291                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      79: checkcast     #117                // class kotlin/ranges/IntRange
      82: invokevirtual #294                // Method kotlin/ranges/IntRange.getLast:()I
      85: istore        8
      87: iconst_1
      88: istore        9
      90: aload         10
      92: invokeinterface #295,  1          // InterfaceMethod java/util/List.size:()I
      97: istore        11
      99: iload         9
     101: iload         11
     103: if_icmpge     171
     106: aload         10
     108: iload         9
     110: invokeinterface #71,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     115: checkcast     #117                // class kotlin/ranges/IntRange
     118: astore        12
     120: iload         8
     122: aload         12
     124: invokevirtual #298                // Method kotlin/ranges/IntRange.getFirst:()I
     127: if_icmpge     153
     130: new           #73                 // class kotlin/Pair
     133: dup
     134: iload         8
     136: iconst_1
     137: iadd
     138: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     141: iload         6
     143: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     146: invokespecial #301                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     149: invokestatic  #303                // Method main$tuningFrequency:(Lkotlin/Pair;)J
     152: lreturn
     153: aload         12
     155: invokevirtual #294                // Method kotlin/ranges/IntRange.getLast:()I
     158: iload         8
     160: invokestatic  #188                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     163: istore        8
     165: iinc          9, 1
     168: goto          99
     171: nop
     172: nop
     173: goto          15
     176: nop
     177: lconst_0
     178: lreturn
}

Compiled from "Comparisons.kt"
public final class Day15Kt$main$part2$lambda$10$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public Day15Kt$main$part2$lambda$10$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/ranges/IntRange
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/ranges/IntRange.getFirst:()I
      12: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class kotlin/ranges/IntRange
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/ranges/IntRange.getFirst:()I
      32: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}


fun main() {
    fun solve(input: String, distLength: Int) =
        input.indexOf(input.windowed(distLength).first { it.toList().allDistinct()}) + distLength

    fun part1(input: String) = solve(input, 4)
    fun part2(input: String) = solve(input, 14)

    val testInput = readInput("Day06_test")
    val testResults = listOf(
        7 to 19, // mjqjpqmgbljsphdztnvjfqwrcgsmlb
        5 to 23, // bvwbjplbgvbhsrlpgdmjqwftvncz
        6 to 23, // nppdvjthqldpwncqszvftbrmjlhg
        10 to 29, // nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg
        11 to 26 // zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw
    )
    testInput.zip(testResults).forEach { (input, results) ->
        check(part1(input) == results.first)
        check(part2(input) == results.second)
    }

    val input = readInput("Day06").first()
    println(part1(input))
    println(part2(input))
}

Compiled from "Day06.kt"
public final class Day06Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Day06_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: iconst_5
       7: anewarray     #16                 // class kotlin/Pair
      10: astore_2
      11: aload_2
      12: iconst_0
      13: bipush        7
      15: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: bipush        19
      20: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokestatic  #28                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      26: aastore
      27: aload_2
      28: iconst_1
      29: iconst_5
      30: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: bipush        23
      35: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      38: invokestatic  #28                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      41: aastore
      42: aload_2
      43: iconst_2
      44: bipush        6
      46: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: bipush        23
      51: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokestatic  #28                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      57: aastore
      58: aload_2
      59: iconst_3
      60: bipush        10
      62: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: bipush        29
      67: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      70: invokestatic  #28                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      73: aastore
      74: aload_2
      75: iconst_4
      76: bipush        11
      78: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      81: bipush        26
      83: invokestatic  #22                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: invokestatic  #28                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      89: aastore
      90: aload_2
      91: invokestatic  #34                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      94: astore_1
      95: aload_0
      96: checkcast     #36                 // class java/lang/Iterable
      99: aload_1
     100: checkcast     #36                 // class java/lang/Iterable
     103: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.zip:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/List;
     106: checkcast     #36                 // class java/lang/Iterable
     109: astore_2
     110: iconst_0
     111: istore_3
     112: aload_2
     113: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     118: astore        4
     120: aload         4
     122: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     127: ifeq          248
     130: aload         4
     132: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     137: astore        5
     139: aload         5
     141: checkcast     #16                 // class kotlin/Pair
     144: astore        6
     146: iconst_0
     147: istore        7
     149: aload         6
     151: invokevirtual #57                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     154: checkcast     #59                 // class java/lang/String
     157: astore        8
     159: aload         6
     161: invokevirtual #62                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     164: checkcast     #16                 // class kotlin/Pair
     167: astore        9
     169: aload         8
     171: invokestatic  #66                 // Method main$part1:(Ljava/lang/String;)I
     174: aload         9
     176: invokevirtual #69                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     179: checkcast     #71                 // class java/lang/Number
     182: invokevirtual #75                 // Method java/lang/Number.intValue:()I
     185: if_icmpne     192
     188: iconst_1
     189: goto          193
     192: iconst_0
     193: ifne          206
     196: new           #77                 // class java/lang/IllegalStateException
     199: dup
     200: ldc           #79                 // String Check failed.
     202: invokespecial #83                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     205: athrow
     206: aload         8
     208: invokestatic  #86                 // Method main$part2:(Ljava/lang/String;)I
     211: aload         9
     213: invokevirtual #89                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     216: checkcast     #71                 // class java/lang/Number
     219: invokevirtual #75                 // Method java/lang/Number.intValue:()I
     222: if_icmpne     229
     225: iconst_1
     226: goto          230
     229: iconst_0
     230: ifne          243
     233: new           #77                 // class java/lang/IllegalStateException
     236: dup
     237: ldc           #79                 // String Check failed.
     239: invokespecial #83                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     242: athrow
     243: nop
     244: nop
     245: goto          120
     248: nop
     249: ldc           #91                 // String Day06
     251: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
     254: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     257: checkcast     #59                 // class java/lang/String
     260: astore_2
     261: aload_2
     262: invokestatic  #66                 // Method main$part1:(Ljava/lang/String;)I
     265: istore_3
     266: getstatic     #101                // Field java/lang/System.out:Ljava/io/PrintStream;
     269: iload_3
     270: invokevirtual #107                // Method java/io/PrintStream.println:(I)V
     273: aload_2
     274: invokestatic  #86                 // Method main$part2:(Ljava/lang/String;)I
     277: istore_3
     278: getstatic     #101                // Field java/lang/System.out:Ljava/io/PrintStream;
     281: iload_3
     282: invokevirtual #107                // Method java/io/PrintStream.println:(I)V
     285: return

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

  private static final int main$solve(java.lang.String, int);
    Code:
       0: aload_0
       1: checkcast     #132                // class java/lang/CharSequence
       4: aload_0
       5: checkcast     #132                // class java/lang/CharSequence
       8: iload_1
       9: iconst_0
      10: iconst_0
      11: bipush        6
      13: aconst_null
      14: invokestatic  #138                // Method kotlin/text/StringsKt.windowed$default:(Ljava/lang/CharSequence;IIZILjava/lang/Object;)Ljava/util/List;
      17: checkcast     #36                 // class java/lang/Iterable
      20: astore_2
      21: astore        8
      23: iconst_0
      24: istore_3
      25: aload_2
      26: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      31: astore        4
      33: aload         4
      35: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifeq          81
      43: aload         4
      45: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: astore        5
      52: aload         5
      54: checkcast     #59                 // class java/lang/String
      57: astore        6
      59: iconst_0
      60: istore        7
      62: aload         6
      64: checkcast     #132                // class java/lang/CharSequence
      67: invokestatic  #142                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      70: invokestatic  #146                // Method UtilsKt.allDistinct:(Ljava/util/List;)Z
      73: ifeq          33
      76: aload         5
      78: goto          91
      81: new           #148                // class java/util/NoSuchElementException
      84: dup
      85: ldc           #150                // String Collection contains no element matching the predicate.
      87: invokespecial #151                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      90: athrow
      91: aload         8
      93: swap
      94: checkcast     #59                 // class java/lang/String
      97: iconst_0
      98: iconst_0
      99: bipush        6
     101: aconst_null
     102: invokestatic  #155                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
     105: iload_1
     106: iadd
     107: ireturn

  private static final int main$part1(java.lang.String);
    Code:
       0: aload_0
       1: iconst_4
       2: invokestatic  #162                // Method main$solve:(Ljava/lang/String;I)I
       5: ireturn

  private static final int main$part2(java.lang.String);
    Code:
       0: aload_0
       1: bipush        14
       3: invokestatic  #162                // Method main$solve:(Ljava/lang/String;I)I
       6: ireturn
}