package aoc07

import java.nio.file.Paths
import kotlin.math.abs

class Node(val parent: Node?, val name: String, val type: String, val size: Int = 0) {
    val children = mutableListOf<Node>()

    override fun toString(): String {
        return "$name ($type)"
    }
}
fun main() {
    val lines = Paths.get("src/main/resources/aoc_07.txt").toFile().useLines { it.toList() }

    println(solution1(lines))
    println(solution2(lines))
}

fun solution1(lines: List<String>): Int {
    return solve(lines).filter { it <= 100000 }.sum()
}

fun solution2(lines: List<String>): Int {
    val fileList = solve(lines)

    val maxSpace = 70000000
    val installSpace = 30000000
    val usedSpace = fileList.max()
    val freeSpace = maxSpace - usedSpace
    val requiredSpace = installSpace - freeSpace

    return fileList.filter { requiredSpace - it < 0 }.maxBy { requiredSpace - it }
}
fun solve(lines: List<String>): List<Int> {
    val shellLines = lines
        .filterNot { it.contains("$ ls") }
        .map { it.split(" ") }
        .map { if (it.size == 2)  Pair(it[0], it[1]) else Pair(it[1], it[2]) }

    val rootNode = Node(null, "/", "dir")
    var currentNode: Node? = null

    for (shellLine in shellLines) {
        if (shellLine.first == "cd") {
            currentNode = if (shellLine.second == "..") {
                currentNode?.parent
            } else {
                if (currentNode == null) {
                    rootNode
                } else {
                    currentNode.children.add(Node(currentNode, currentNode.name + "/" + shellLine.second, "dir"))
                    currentNode.children.last()
                }
            }
        } else if (shellLine.first.toIntOrNull() !== null) {
            currentNode?.children?.add(Node(currentNode, shellLine.second, "file", shellLine.first.toInt()))
        }
    }

    val sizeMap = mutableMapOf<String, Int>()
    calculate(rootNode, sizeMap)
    return sizeMap.toList().map { it.second }.sortedDescending()
}

fun calculate(node: Node, sizeMap: MutableMap<String, Int>): Int {
    return if (node.type == "dir") {
        val size =  node.children.filter { it.type == "dir" }.sumOf { calculate(it, sizeMap) } + calcFileSize(node)
        sizeMap[node.name] = size;
        size
    } else {
        calcFileSize(node)
    }
}

fun calcFileSize(node: Node): Int {
    return node.children.filter { it.type == "file" }.sumOf { it.size }
}

Compiled from "Solution07.kt"
public final class aoc07.Solution07Kt {
  public static final void main();
    Code:
       0: ldc           #10                 // String src/main/resources/aoc_07.txt
       2: iconst_0
       3: anewarray     #12                 // class java/lang/String
       6: invokestatic  #18                 // Method java/nio/file/Paths.get:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
       9: invokeinterface #24,  1           // InterfaceMethod java/nio/file/Path.toFile:()Ljava/io/File;
      14: dup
      15: ldc           #26                 // String toFile(...)
      17: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      20: astore_1
      21: getstatic     #38                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      24: astore_2
      25: iconst_0
      26: istore_3
      27: aload_1
      28: astore        4
      30: sipush        8192
      33: istore        5
      35: aload         4
      37: astore        6
      39: new           #40                 // class java/io/InputStreamReader
      42: dup
      43: new           #42                 // class java/io/FileInputStream
      46: dup
      47: aload         6
      49: invokespecial #46                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      52: checkcast     #48                 // class java/io/InputStream
      55: aload_2
      56: invokespecial #51                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      59: checkcast     #53                 // class java/io/Reader
      62: astore        6
      64: aload         6
      66: instanceof    #55                 // class java/io/BufferedReader
      69: ifeq          80
      72: aload         6
      74: checkcast     #55                 // class java/io/BufferedReader
      77: goto          91
      80: new           #55                 // class java/io/BufferedReader
      83: dup
      84: aload         6
      86: iload         5
      88: invokespecial #58                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      91: checkcast     #60                 // class java/io/Closeable
      94: astore        4
      96: aconst_null
      97: astore        5
      99: nop
     100: aload         4
     102: checkcast     #55                 // class java/io/BufferedReader
     105: astore        6
     107: iconst_0
     108: istore        7
     110: aload         6
     112: invokestatic  #66                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     115: astore        8
     117: iconst_0
     118: istore        9
     120: aload         8
     122: invokestatic  #72                 // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     125: astore        6
     127: aload         4
     129: aload         5
     131: invokestatic  #78                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     134: aload         6
     136: goto          160
     139: astore        7
     141: aload         7
     143: astore        5
     145: aload         7
     147: athrow
     148: astore        7
     150: aload         4
     152: aload         5
     154: invokestatic  #78                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     157: aload         7
     159: athrow
     160: nop
     161: astore_0
     162: aload_0
     163: invokestatic  #82                 // Method solution1:(Ljava/util/List;)I
     166: istore_1
     167: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     170: iload_1
     171: invokevirtual #94                 // Method java/io/PrintStream.println:(I)V
     174: aload_0
     175: invokestatic  #97                 // Method solution2:(Ljava/util/List;)I
     178: istore_1
     179: getstatic     #88                 // Field java/lang/System.out:Ljava/io/PrintStream;
     182: iload_1
     183: invokevirtual #94                 // Method java/io/PrintStream.println:(I)V
     186: return
    Exception table:
       from    to  target type
          99   127   139   Class java/lang/Throwable
          99   127   148   any
         139   148   148   any
         148   150   148   any

  public static final int solution1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #121                // String lines
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #128                // Method solve:(Ljava/util/List;)Ljava/util/List;
      10: checkcast     #130                // class java/lang/Iterable
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_1
      17: astore_3
      18: new           #132                // class java/util/ArrayList
      21: dup
      22: invokespecial #134                // Method java/util/ArrayList."<init>":()V
      25: checkcast     #136                // class java/util/Collection
      28: astore        4
      30: iconst_0
      31: istore        5
      33: aload_3
      34: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        6
      41: aload         6
      43: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          101
      51: aload         6
      53: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        7
      60: aload         7
      62: checkcast     #152                // class java/lang/Number
      65: invokevirtual #156                // Method java/lang/Number.intValue:()I
      68: istore        8
      70: iconst_0
      71: istore        9
      73: iload         8
      75: ldc           #157                // int 100000
      77: if_icmpgt     84
      80: iconst_1
      81: goto          85
      84: iconst_0
      85: ifeq          41
      88: aload         4
      90: aload         7
      92: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: goto          41
     101: aload         4
     103: checkcast     #116                // class java/util/List
     106: nop
     107: checkcast     #130                // class java/lang/Iterable
     110: invokestatic  #167                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     113: ireturn

  public static final int solution2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #121                // String lines
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #128                // Method solve:(Ljava/util/List;)Ljava/util/List;
      10: astore_1
      11: ldc           #178                // int 70000000
      13: istore_2
      14: ldc           #179                // int 30000000
      16: istore_3
      17: aload_1
      18: checkcast     #130                // class java/lang/Iterable
      21: invokestatic  #183                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      24: checkcast     #152                // class java/lang/Number
      27: invokevirtual #156                // Method java/lang/Number.intValue:()I
      30: istore        4
      32: iload_2
      33: iload         4
      35: isub
      36: istore        5
      38: iload_3
      39: iload         5
      41: isub
      42: istore        6
      44: aload_1
      45: checkcast     #130                // class java/lang/Iterable
      48: astore        7
      50: iconst_0
      51: istore        8
      53: aload         7
      55: astore        9
      57: new           #132                // class java/util/ArrayList
      60: dup
      61: invokespecial #134                // Method java/util/ArrayList."<init>":()V
      64: checkcast     #136                // class java/util/Collection
      67: astore        10
      69: iconst_0
      70: istore        11
      72: aload         9
      74: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      79: astore        12
      81: aload         12
      83: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      88: ifeq          142
      91: aload         12
      93: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      98: astore        13
     100: aload         13
     102: checkcast     #152                // class java/lang/Number
     105: invokevirtual #156                // Method java/lang/Number.intValue:()I
     108: istore        14
     110: iconst_0
     111: istore        15
     113: iload         6
     115: iload         14
     117: isub
     118: ifge          125
     121: iconst_1
     122: goto          126
     125: iconst_0
     126: ifeq          81
     129: aload         10
     131: aload         13
     133: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     138: pop
     139: goto          81
     142: aload         10
     144: checkcast     #116                // class java/util/List
     147: nop
     148: checkcast     #130                // class java/lang/Iterable
     151: astore        7
     153: nop
     154: iconst_0
     155: istore        8
     157: aload         7
     159: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     164: astore        9
     166: aload         9
     168: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     173: ifne          184
     176: new           #185                // class java/util/NoSuchElementException
     179: dup
     180: invokespecial #186                // Method java/util/NoSuchElementException."<init>":()V
     183: athrow
     184: aload         9
     186: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     191: astore        10
     193: aload         9
     195: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     200: ifne          208
     203: aload         10
     205: goto          284
     208: aload         10
     210: checkcast     #152                // class java/lang/Number
     213: invokevirtual #156                // Method java/lang/Number.intValue:()I
     216: istore        11
     218: iconst_0
     219: istore        12
     221: iload         6
     223: iload         11
     225: isub
     226: istore        11
     228: aload         9
     230: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     235: astore        12
     237: aload         12
     239: checkcast     #152                // class java/lang/Number
     242: invokevirtual #156                // Method java/lang/Number.intValue:()I
     245: istore        13
     247: iconst_0
     248: istore        14
     250: iload         6
     252: iload         13
     254: isub
     255: istore        13
     257: iload         11
     259: iload         13
     261: if_icmpge     272
     264: aload         12
     266: astore        10
     268: iload         13
     270: istore        11
     272: aload         9
     274: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     279: ifne          228
     282: aload         10
     284: checkcast     #152                // class java/lang/Number
     287: invokevirtual #156                // Method java/lang/Number.intValue:()I
     290: ireturn

  public static final java.util.List<java.lang.Integer> solve(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #121                // String lines
       3: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #130                // class java/lang/Iterable
      10: astore_2
      11: nop
      12: iconst_0
      13: istore_3
      14: aload_2
      15: astore        4
      17: new           #132                // class java/util/ArrayList
      20: dup
      21: invokespecial #134                // Method java/util/ArrayList."<init>":()V
      24: checkcast     #136                // class java/util/Collection
      27: astore        5
      29: iconst_0
      30: istore        6
      32: aload         4
      34: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        7
      41: aload         7
      43: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          102
      51: aload         7
      53: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        8
      60: aload         8
      62: checkcast     #12                 // class java/lang/String
      65: astore        9
      67: iconst_0
      68: istore        10
      70: aload         9
      72: checkcast     #205                // class java/lang/CharSequence
      75: ldc           #207                // String $ ls
      77: checkcast     #205                // class java/lang/CharSequence
      80: iconst_0
      81: iconst_2
      82: aconst_null
      83: invokestatic  #213                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
      86: ifne          41
      89: aload         5
      91: aload         8
      93: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          41
     102: aload         5
     104: checkcast     #116                // class java/util/List
     107: nop
     108: checkcast     #130                // class java/lang/Iterable
     111: astore_2
     112: nop
     113: iconst_0
     114: istore_3
     115: aload_2
     116: astore        4
     118: new           #132                // class java/util/ArrayList
     121: dup
     122: aload_2
     123: bipush        10
     125: invokestatic  #217                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     128: invokespecial #219                // Method java/util/ArrayList."<init>":(I)V
     131: checkcast     #136                // class java/util/Collection
     134: astore        5
     136: iconst_0
     137: istore        6
     139: aload         4
     141: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     146: astore        7
     148: aload         7
     150: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifeq          220
     158: aload         7
     160: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     165: astore        8
     167: aload         5
     169: aload         8
     171: checkcast     #12                 // class java/lang/String
     174: astore        9
     176: astore        14
     178: iconst_0
     179: istore        10
     181: aload         9
     183: checkcast     #205                // class java/lang/CharSequence
     186: iconst_1
     187: anewarray     #12                 // class java/lang/String
     190: astore        11
     192: aload         11
     194: iconst_0
     195: ldc           #221                // String
     197: aastore
     198: aload         11
     200: iconst_0
     201: iconst_0
     202: bipush        6
     204: aconst_null
     205: invokestatic  #225                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     208: aload         14
     210: swap
     211: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     216: pop
     217: goto          148
     220: aload         5
     222: checkcast     #116                // class java/util/List
     225: nop
     226: checkcast     #130                // class java/lang/Iterable
     229: astore_2
     230: nop
     231: iconst_0
     232: istore_3
     233: aload_2
     234: astore        4
     236: new           #132                // class java/util/ArrayList
     239: dup
     240: aload_2
     241: bipush        10
     243: invokestatic  #217                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     246: invokespecial #219                // Method java/util/ArrayList."<init>":(I)V
     249: checkcast     #136                // class java/util/Collection
     252: astore        5
     254: iconst_0
     255: istore        6
     257: aload         4
     259: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     264: astore        7
     266: aload         7
     268: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     273: ifeq          371
     276: aload         7
     278: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     283: astore        8
     285: aload         5
     287: aload         8
     289: checkcast     #116                // class java/util/List
     292: astore        9
     294: astore        14
     296: iconst_0
     297: istore        10
     299: aload         9
     301: invokeinterface #228,  1          // InterfaceMethod java/util/List.size:()I
     306: iconst_2
     307: if_icmpne     336
     310: new           #230                // class kotlin/Pair
     313: dup
     314: aload         9
     316: iconst_0
     317: invokeinterface #233,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     322: aload         9
     324: iconst_1
     325: invokeinterface #233,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     330: invokespecial #236                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     333: goto          359
     336: new           #230                // class kotlin/Pair
     339: dup
     340: aload         9
     342: iconst_1
     343: invokeinterface #233,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     348: aload         9
     350: iconst_2
     351: invokeinterface #233,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     356: invokespecial #236                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     359: aload         14
     361: swap
     362: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     367: pop
     368: goto          266
     371: aload         5
     373: checkcast     #116                // class java/util/List
     376: nop
     377: astore_1
     378: new           #238                // class aoc07/Node
     381: dup
     382: aconst_null
     383: ldc           #240                // String /
     385: ldc           #242                // String dir
     387: iconst_0
     388: bipush        8
     390: aconst_null
     391: invokespecial #245                // Method aoc07/Node."<init>":(Laoc07/Node;Ljava/lang/String;Ljava/lang/String;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
     394: astore_2
     395: aconst_null
     396: astore_3
     397: aload_1
     398: invokeinterface #246,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     403: astore        4
     405: aload         4
     407: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     412: ifeq          618
     415: aload         4
     417: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     422: checkcast     #230                // class kotlin/Pair
     425: astore        5
     427: aload         5
     429: invokevirtual #249                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     432: ldc           #251                // String cd
     434: invokestatic  #255                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     437: ifeq          549
     440: aload         5
     442: invokevirtual #258                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     445: ldc_w         #260                // String ..
     448: invokestatic  #255                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     451: ifeq          470
     454: aload_3
     455: dup
     456: ifnull        465
     459: invokevirtual #264                // Method aoc07/Node.getParent:()Laoc07/Node;
     462: goto          545
     465: pop
     466: aconst_null
     467: goto          545
     470: aload_3
     471: ifnonnull     478
     474: aload_2
     475: goto          545
     478: aload_3
     479: invokevirtual #268                // Method aoc07/Node.getChildren:()Ljava/util/List;
     482: new           #238                // class aoc07/Node
     485: dup
     486: aload_3
     487: new           #270                // class java/lang/StringBuilder
     490: dup
     491: invokespecial #271                // Method java/lang/StringBuilder."<init>":()V
     494: aload_3
     495: invokevirtual #275                // Method aoc07/Node.getName:()Ljava/lang/String;
     498: invokevirtual #279                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     501: bipush        47
     503: invokevirtual #282                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     506: aload         5
     508: invokevirtual #258                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     511: checkcast     #12                 // class java/lang/String
     514: invokevirtual #279                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     517: invokevirtual #285                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     520: ldc           #242                // String dir
     522: iconst_0
     523: bipush        8
     525: aconst_null
     526: invokespecial #245                // Method aoc07/Node."<init>":(Laoc07/Node;Ljava/lang/String;Ljava/lang/String;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
     529: invokeinterface #286,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     534: pop
     535: aload_3
     536: invokevirtual #268                // Method aoc07/Node.getChildren:()Ljava/util/List;
     539: invokestatic  #290                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     542: checkcast     #238                // class aoc07/Node
     545: astore_3
     546: goto          405
     549: aload         5
     551: invokevirtual #249                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     554: checkcast     #12                 // class java/lang/String
     557: invokestatic  #294                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     560: ifnull        405
     563: aload_3
     564: dup
     565: ifnull        614
     568: invokevirtual #268                // Method aoc07/Node.getChildren:()Ljava/util/List;
     571: dup
     572: ifnull        614
     575: new           #238                // class aoc07/Node
     578: dup
     579: aload_3
     580: aload         5
     582: invokevirtual #258                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     585: checkcast     #12                 // class java/lang/String
     588: ldc_w         #296                // String file
     591: aload         5
     593: invokevirtual #249                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     596: checkcast     #12                 // class java/lang/String
     599: invokestatic  #302                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     602: invokespecial #305                // Method aoc07/Node."<init>":(Laoc07/Node;Ljava/lang/String;Ljava/lang/String;I)V
     605: invokeinterface #286,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     610: pop
     611: goto          405
     614: pop
     615: goto          405
     618: new           #307                // class java/util/LinkedHashMap
     621: dup
     622: invokespecial #308                // Method java/util/LinkedHashMap."<init>":()V
     625: checkcast     #310                // class java/util/Map
     628: astore        4
     630: aload_2
     631: aload         4
     633: invokestatic  #314                // Method calculate:(Laoc07/Node;Ljava/util/Map;)I
     636: pop
     637: aload         4
     639: invokestatic  #319                // Method kotlin/collections/MapsKt.toList:(Ljava/util/Map;)Ljava/util/List;
     642: checkcast     #130                // class java/lang/Iterable
     645: astore        5
     647: iconst_0
     648: istore        6
     650: aload         5
     652: astore        7
     654: new           #132                // class java/util/ArrayList
     657: dup
     658: aload         5
     660: bipush        10
     662: invokestatic  #217                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     665: invokespecial #219                // Method java/util/ArrayList."<init>":(I)V
     668: checkcast     #136                // class java/util/Collection
     671: astore        8
     673: iconst_0
     674: istore        9
     676: aload         7
     678: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     683: astore        10
     685: aload         10
     687: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     692: ifeq          744
     695: aload         10
     697: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     702: astore        11
     704: aload         8
     706: aload         11
     708: checkcast     #230                // class kotlin/Pair
     711: astore        12
     713: astore        14
     715: iconst_0
     716: istore        13
     718: aload         12
     720: invokevirtual #258                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     723: checkcast     #152                // class java/lang/Number
     726: invokevirtual #156                // Method java/lang/Number.intValue:()I
     729: invokestatic  #323                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     732: aload         14
     734: swap
     735: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     740: pop
     741: goto          685
     744: aload         8
     746: checkcast     #116                // class java/util/List
     749: nop
     750: checkcast     #130                // class java/lang/Iterable
     753: invokestatic  #327                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     756: areturn

  public static final int calculate(aoc07.Node, java.util.Map<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc_w         #352                // String node
       4: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #353                // String sizeMap
      11: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_0
      15: invokevirtual #356                // Method aoc07/Node.getType:()Ljava/lang/String;
      18: ldc           #242                // String dir
      20: invokestatic  #255                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      23: ifeq          222
      26: aload_0
      27: invokevirtual #268                // Method aoc07/Node.getChildren:()Ljava/util/List;
      30: checkcast     #130                // class java/lang/Iterable
      33: astore_3
      34: iconst_0
      35: istore        4
      37: aload_3
      38: astore        5
      40: new           #132                // class java/util/ArrayList
      43: dup
      44: invokespecial #134                // Method java/util/ArrayList."<init>":()V
      47: checkcast     #136                // class java/util/Collection
      50: astore        6
      52: iconst_0
      53: istore        7
      55: aload         5
      57: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      62: astore        8
      64: aload         8
      66: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      71: ifeq          119
      74: aload         8
      76: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      81: astore        9
      83: aload         9
      85: checkcast     #238                // class aoc07/Node
      88: astore        10
      90: iconst_0
      91: istore        11
      93: aload         10
      95: invokevirtual #356                // Method aoc07/Node.getType:()Ljava/lang/String;
      98: ldc           #242                // String dir
     100: invokestatic  #255                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     103: ifeq          64
     106: aload         6
     108: aload         9
     110: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          64
     119: aload         6
     121: checkcast     #116                // class java/util/List
     124: nop
     125: checkcast     #130                // class java/lang/Iterable
     128: astore_3
     129: iconst_0
     130: istore        4
     132: aload_3
     133: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     138: astore        5
     140: aload         5
     142: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     147: ifeq          191
     150: aload         5
     152: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     157: astore        6
     159: iload         4
     161: aload         6
     163: checkcast     #238                // class aoc07/Node
     166: astore        7
     168: istore        12
     170: iconst_0
     171: istore        8
     173: aload         7
     175: aload_1
     176: invokestatic  #314                // Method calculate:(Laoc07/Node;Ljava/util/Map;)I
     179: istore        13
     181: iload         12
     183: iload         13
     185: iadd
     186: istore        4
     188: goto          140
     191: iload         4
     193: aload_0
     194: invokestatic  #360                // Method calcFileSize:(Laoc07/Node;)I
     197: iadd
     198: istore_2
     199: iload_2
     200: invokestatic  #323                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     203: astore        5
     205: aload_1
     206: aload_0
     207: invokevirtual #275                // Method aoc07/Node.getName:()Ljava/lang/String;
     210: aload         5
     212: invokeinterface #364,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     217: pop
     218: iload_2
     219: goto          226
     222: aload_0
     223: invokestatic  #360                // Method calcFileSize:(Laoc07/Node;)I
     226: ireturn

  public static final int calcFileSize(aoc07.Node);
    Code:
       0: aload_0
       1: ldc_w         #352                // String node
       4: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #268                // Method aoc07/Node.getChildren:()Ljava/util/List;
      11: checkcast     #130                // class java/lang/Iterable
      14: astore_1
      15: iconst_0
      16: istore_2
      17: aload_1
      18: astore_3
      19: new           #132                // class java/util/ArrayList
      22: dup
      23: invokespecial #134                // Method java/util/ArrayList."<init>":()V
      26: checkcast     #136                // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          98
      52: aload         6
      54: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         7
      63: checkcast     #238                // class aoc07/Node
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokevirtual #356                // Method aoc07/Node.getType:()Ljava/lang/String;
      76: ldc_w         #296                // String file
      79: invokestatic  #255                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      82: ifeq          42
      85: aload         4
      87: aload         7
      89: invokeinterface #161,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      94: pop
      95: goto          42
      98: aload         4
     100: checkcast     #116                // class java/util/List
     103: nop
     104: checkcast     #130                // class java/lang/Iterable
     107: astore_1
     108: iconst_0
     109: istore_2
     110: aload_1
     111: invokeinterface #140,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore_3
     117: aload_3
     118: invokeinterface #146,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     123: ifeq          163
     126: aload_3
     127: invokeinterface #150,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     132: astore        4
     134: iload_2
     135: aload         4
     137: checkcast     #238                // class aoc07/Node
     140: astore        5
     142: istore        10
     144: iconst_0
     145: istore        6
     147: aload         5
     149: invokevirtual #369                // Method aoc07/Node.getSize:()I
     152: istore        11
     154: iload         10
     156: iload         11
     158: iadd
     159: istore_2
     160: goto          117
     163: iload_2
     164: ireturn

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


package aoc08

import java.nio.file.Paths

inline fun <T> Iterable<T>.takeWhileInclusive(
    predicate: (T) -> Boolean
): List<T> {
    var shouldContinue = true
    return takeWhile {
        val result = shouldContinue
        shouldContinue = predicate(it)
        result
    }
}

fun main() {
    val lines = Paths.get("src/main/resources/aoc_08.txt").toFile().useLines { it.toList() }

    val map = lines
        .map { line -> line.toCharArray().map { it.digitToInt() } }
        .map { it.toIntArray() }
        .toTypedArray()

    val width = map.first().size
    val height = map.size

    println(solution1(map, width, height))
    println(solution2(map, width, height))
}

fun solution1(map: Array<IntArray>, width: Int, height: Int): Int {
    val treeMap = solve(map, width, height)
    return treeMap.asSequence().filter { tree ->
        tree.value.any { edge -> edge.all { it < map[tree.key.second][tree.key.first] } }
    }.count() + (width * 2) + (height * 2) - 4
}

fun solution2(map: Array<IntArray>, width: Int, height: Int): Int {
    val treeMap = solve(map, width, height)
    return treeMap.asSequence().map { tree ->
        tree.value.map { edge ->
            edge.takeWhileInclusive { map[tree.key.second][tree.key.first] > it }.toList()
        }.map { it.size }
    }.maxOf {
        it.reduce { result, value -> result.times(value) }
    }
}

fun solve(map: Array<IntArray>, width: Int, height: Int): Map<Pair<Int, Int>, List<List<Int>>> {
    val treeMap = mutableMapOf<Pair<Int, Int>, List<List<Int>>>()

    // create map of path to edge for all trees except the outer circle
    for (y in 1 until height - 1) {
        for (x in 1 until width - 1) {
            val leftEdgeValues = mutableListOf<Int>()
            val rightEdgeValues = mutableListOf<Int>()
            val topEdgeValues = mutableListOf<Int>()
            val bottomEdgeValues = mutableListOf<Int>()

            for (l in 0 until x) leftEdgeValues.add(map[y][l])
            for (r in x + 1 until width) rightEdgeValues.add(map[y][r])
            for (t in 0 until y) topEdgeValues.add(map[t][x])
            for (b in y + 1 until height) bottomEdgeValues.add(map[b][x])

            treeMap[Pair(x, y)] =
                listOf(leftEdgeValues.reversed(), rightEdgeValues, topEdgeValues.reversed(), bottomEdgeValues)
        }
    }
    return treeMap
}

Compiled from "Solution08.kt"
public final class aoc08.Solution08Kt {
  public static final <T> java.util.List<T> takeWhileInclusive(java.lang.Iterable<? extends T>, kotlin.jvm.functions.Function1<? super T, java.lang.Boolean>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String predicate
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: iconst_0
      15: istore_3
      16: iconst_1
      17: istore_3
      18: aload_0
      19: astore        4
      21: iconst_0
      22: istore        5
      24: new           #20                 // class java/util/ArrayList
      27: dup
      28: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      31: astore        6
      33: aload         4
      35: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        7
      42: aload         7
      44: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          105
      52: aload         7
      54: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        8
      61: aload         8
      63: astore        9
      65: iconst_0
      66: istore        10
      68: iload_3
      69: istore        11
      71: aload_1
      72: aload         9
      74: invokeinterface #46,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      79: checkcast     #48                 // class java/lang/Boolean
      82: invokevirtual #51                 // Method java/lang/Boolean.booleanValue:()Z
      85: istore_3
      86: iload         11
      88: ifne          94
      91: goto          105
      94: aload         6
      96: aload         8
      98: invokevirtual #55                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     101: pop
     102: goto          42
     105: aload         6
     107: checkcast     #57                 // class java/util/List
     110: areturn

  public static final void main();
    Code:
       0: ldc           #78                 // String src/main/resources/aoc_08.txt
       2: iconst_0
       3: anewarray     #80                 // class java/lang/String
       6: invokestatic  #86                 // Method java/nio/file/Paths.get:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
       9: invokeinterface #92,  1           // InterfaceMethod java/nio/file/Path.toFile:()Ljava/io/File;
      14: dup
      15: ldc           #94                 // String toFile(...)
      17: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      20: astore_1
      21: getstatic     #103                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      24: astore_2
      25: iconst_0
      26: istore_3
      27: aload_1
      28: astore        4
      30: sipush        8192
      33: istore        5
      35: aload         4
      37: astore        6
      39: new           #105                // class java/io/InputStreamReader
      42: dup
      43: new           #107                // class java/io/FileInputStream
      46: dup
      47: aload         6
      49: invokespecial #110                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      52: checkcast     #112                // class java/io/InputStream
      55: aload_2
      56: invokespecial #115                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      59: checkcast     #117                // class java/io/Reader
      62: astore        6
      64: aload         6
      66: instanceof    #119                // class java/io/BufferedReader
      69: ifeq          80
      72: aload         6
      74: checkcast     #119                // class java/io/BufferedReader
      77: goto          91
      80: new           #119                // class java/io/BufferedReader
      83: dup
      84: aload         6
      86: iload         5
      88: invokespecial #122                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      91: checkcast     #124                // class java/io/Closeable
      94: astore        4
      96: aconst_null
      97: astore        5
      99: nop
     100: aload         4
     102: checkcast     #119                // class java/io/BufferedReader
     105: astore        6
     107: iconst_0
     108: istore        7
     110: aload         6
     112: invokestatic  #130                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     115: astore        8
     117: iconst_0
     118: istore        9
     120: aload         8
     122: invokestatic  #136                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     125: astore        6
     127: aload         4
     129: aload         5
     131: invokestatic  #142                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     134: aload         6
     136: goto          160
     139: astore        7
     141: aload         7
     143: astore        5
     145: aload         7
     147: athrow
     148: astore        7
     150: aload         4
     152: aload         5
     154: invokestatic  #142                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     157: aload         7
     159: athrow
     160: nop
     161: astore_0
     162: aload_0
     163: checkcast     #26                 // class java/lang/Iterable
     166: astore_2
     167: nop
     168: iconst_0
     169: istore_3
     170: aload_2
     171: astore        4
     173: new           #20                 // class java/util/ArrayList
     176: dup
     177: aload_2
     178: bipush        10
     180: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     183: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
     186: checkcast     #153                // class java/util/Collection
     189: astore        5
     191: iconst_0
     192: istore        6
     194: aload         4
     196: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     201: astore        7
     203: aload         7
     205: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     210: ifeq          350
     213: aload         7
     215: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     220: astore        8
     222: aload         5
     224: aload         8
     226: checkcast     #80                 // class java/lang/String
     229: astore        9
     231: astore        22
     233: iconst_0
     234: istore        10
     236: aload         9
     238: invokevirtual #157                // Method java/lang/String.toCharArray:()[C
     241: dup
     242: ldc           #159                // String toCharArray(...)
     244: invokestatic  #97                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     247: astore        11
     249: nop
     250: iconst_0
     251: istore        12
     253: aload         11
     255: astore        13
     257: new           #20                 // class java/util/ArrayList
     260: dup
     261: aload         11
     263: arraylength
     264: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
     267: checkcast     #153                // class java/util/Collection
     270: astore        14
     272: iconst_0
     273: istore        15
     275: iconst_0
     276: istore        16
     278: aload         13
     280: arraylength
     281: istore        17
     283: iload         16
     285: iload         17
     287: if_icmpge     331
     290: aload         13
     292: iload         16
     294: caload
     295: istore        18
     297: aload         14
     299: iload         18
     301: istore        19
     303: astore        20
     305: iconst_0
     306: istore        21
     308: iload         19
     310: invokestatic  #165                // Method kotlin/text/CharsKt.digitToInt:(C)I
     313: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: aload         20
     318: swap
     319: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     324: pop
     325: iinc          16, 1
     328: goto          283
     331: aload         14
     333: checkcast     #57                 // class java/util/List
     336: nop
     337: nop
     338: aload         22
     340: swap
     341: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     346: pop
     347: goto          203
     350: aload         5
     352: checkcast     #57                 // class java/util/List
     355: nop
     356: checkcast     #26                 // class java/lang/Iterable
     359: astore_2
     360: nop
     361: iconst_0
     362: istore_3
     363: aload_2
     364: astore        4
     366: new           #20                 // class java/util/ArrayList
     369: dup
     370: aload_2
     371: bipush        10
     373: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     376: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
     379: checkcast     #153                // class java/util/Collection
     382: astore        5
     384: iconst_0
     385: istore        6
     387: aload         4
     389: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     394: astore        7
     396: aload         7
     398: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     403: ifeq          449
     406: aload         7
     408: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     413: astore        8
     415: aload         5
     417: aload         8
     419: checkcast     #57                 // class java/util/List
     422: astore        9
     424: astore        22
     426: iconst_0
     427: istore        10
     429: aload         9
     431: checkcast     #153                // class java/util/Collection
     434: invokestatic  #176                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     437: aload         22
     439: swap
     440: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     445: pop
     446: goto          396
     449: aload         5
     451: checkcast     #57                 // class java/util/List
     454: nop
     455: checkcast     #153                // class java/util/Collection
     458: astore_2
     459: nop
     460: iconst_0
     461: istore_3
     462: aload_2
     463: astore        4
     465: aload         4
     467: iconst_0
     468: anewarray     #178                // class "[I"
     471: invokeinterface #182,  2          // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     476: checkcast     #184                // class "[[I"
     479: astore_1
     480: aload_1
     481: checkcast     #186                // class "[Ljava/lang/Object;"
     484: invokestatic  #192                // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
     487: checkcast     #178                // class "[I"
     490: arraylength
     491: istore_2
     492: aload_1
     493: checkcast     #186                // class "[Ljava/lang/Object;"
     496: arraylength
     497: istore_3
     498: aload_1
     499: iload_2
     500: iload_3
     501: invokestatic  #196                // Method solution1:([[III)I
     504: istore        4
     506: getstatic     #202                // Field java/lang/System.out:Ljava/io/PrintStream;
     509: iload         4
     511: invokevirtual #207                // Method java/io/PrintStream.println:(I)V
     514: aload_1
     515: iload_2
     516: iload_3
     517: invokestatic  #210                // Method solution2:([[III)I
     520: istore        4
     522: getstatic     #202                // Field java/lang/System.out:Ljava/io/PrintStream;
     525: iload         4
     527: invokevirtual #207                // Method java/io/PrintStream.println:(I)V
     530: return
    Exception table:
       from    to  target type
          99   127   139   Class java/lang/Throwable
          99   127   148   any
         139   148   148   any
         148   150   148   any

  public static final int solution1(int[][], int, int);
    Code:
       0: aload_0
       1: ldc           #249                // String map
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: iload_2
       9: invokestatic  #253                // Method solve:([[III)Ljava/util/Map;
      12: astore_3
      13: aload_3
      14: invokestatic  #259                // Method kotlin/collections/MapsKt.asSequence:(Ljava/util/Map;)Lkotlin/sequences/Sequence;
      17: aload_0
      18: invokedynamic #277,  0            // InvokeDynamic #0:invoke:([[I)Lkotlin/jvm/functions/Function1;
      23: invokestatic  #281                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      26: invokestatic  #285                // Method kotlin/sequences/SequencesKt.count:(Lkotlin/sequences/Sequence;)I
      29: iload_1
      30: iconst_2
      31: imul
      32: iadd
      33: iload_2
      34: iconst_2
      35: imul
      36: iadd
      37: iconst_4
      38: isub
      39: ireturn

  public static final int solution2(int[][], int, int);
    Code:
       0: aload_0
       1: ldc           #249                // String map
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: iload_2
       9: invokestatic  #253                // Method solve:([[III)Ljava/util/Map;
      12: astore_3
      13: aload_3
      14: invokestatic  #259                // Method kotlin/collections/MapsKt.asSequence:(Ljava/util/Map;)Lkotlin/sequences/Sequence;
      17: aload_0
      18: invokedynamic #295,  0            // InvokeDynamic #1:invoke:([[I)Lkotlin/jvm/functions/Function1;
      23: invokestatic  #297                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      26: invokeinterface #298,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      31: astore        4
      33: aload         4
      35: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      40: ifne          51
      43: new           #300                // class java/util/NoSuchElementException
      46: dup
      47: invokespecial #301                // Method java/util/NoSuchElementException."<init>":()V
      50: athrow
      51: aload         4
      53: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: checkcast     #57                 // class java/util/List
      61: astore        5
      63: iconst_0
      64: istore        6
      66: aload         5
      68: checkcast     #26                 // class java/lang/Iterable
      71: astore        7
      73: iconst_0
      74: istore        8
      76: aload         7
      78: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      83: astore        9
      85: aload         9
      87: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      92: ifne          106
      95: new           #303                // class java/lang/UnsupportedOperationException
      98: dup
      99: ldc_w         #305                // String Empty collection can\'t be reduced.
     102: invokespecial #308                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     105: athrow
     106: aload         9
     108: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     113: astore        10
     115: aload         9
     117: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     122: ifeq          166
     125: aload         10
     127: aload         9
     129: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     134: checkcast     #310                // class java/lang/Number
     137: invokevirtual #314                // Method java/lang/Number.intValue:()I
     140: istore        11
     142: checkcast     #310                // class java/lang/Number
     145: invokevirtual #314                // Method java/lang/Number.intValue:()I
     148: istore        12
     150: iconst_0
     151: istore        13
     153: iload         12
     155: iload         11
     157: imul
     158: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     161: astore        10
     163: goto          115
     166: aload         10
     168: checkcast     #310                // class java/lang/Number
     171: invokevirtual #314                // Method java/lang/Number.intValue:()I
     174: nop
     175: istore        5
     177: aload         4
     179: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     184: ifeq          327
     187: aload         4
     189: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     194: checkcast     #57                 // class java/util/List
     197: astore        6
     199: iconst_0
     200: istore        7
     202: aload         6
     204: checkcast     #26                 // class java/lang/Iterable
     207: astore        8
     209: iconst_0
     210: istore        9
     212: aload         8
     214: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     219: astore        10
     221: aload         10
     223: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     228: ifne          242
     231: new           #303                // class java/lang/UnsupportedOperationException
     234: dup
     235: ldc_w         #305                // String Empty collection can\'t be reduced.
     238: invokespecial #308                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     241: athrow
     242: aload         10
     244: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     249: astore        11
     251: aload         10
     253: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     258: ifeq          302
     261: aload         11
     263: aload         10
     265: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     270: checkcast     #310                // class java/lang/Number
     273: invokevirtual #314                // Method java/lang/Number.intValue:()I
     276: istore        12
     278: checkcast     #310                // class java/lang/Number
     281: invokevirtual #314                // Method java/lang/Number.intValue:()I
     284: istore        13
     286: iconst_0
     287: istore        14
     289: iload         13
     291: iload         12
     293: imul
     294: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     297: astore        11
     299: goto          251
     302: aload         11
     304: checkcast     #310                // class java/lang/Number
     307: invokevirtual #314                // Method java/lang/Number.intValue:()I
     310: nop
     311: istore        6
     313: iload         5
     315: iload         6
     317: if_icmpge     177
     320: iload         6
     322: istore        5
     324: goto          177
     327: iload         5
     329: ireturn

  public static final java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.util.List<java.util.List<java.lang.Integer>>> solve(int[][], int, int);
    Code:
       0: aload_0
       1: ldc           #249                // String map
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #327                // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #328                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #324                // class java/util/Map
      16: astore_3
      17: iconst_1
      18: istore        4
      20: iload_2
      21: iconst_1
      22: isub
      23: istore        5
      25: iload         4
      27: iload         5
      29: if_icmpge     330
      32: iconst_1
      33: istore        6
      35: iload_1
      36: iconst_1
      37: isub
      38: istore        7
      40: iload         6
      42: iload         7
      44: if_icmpge     324
      47: new           #20                 // class java/util/ArrayList
      50: dup
      51: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      54: checkcast     #57                 // class java/util/List
      57: astore        8
      59: new           #20                 // class java/util/ArrayList
      62: dup
      63: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      66: checkcast     #57                 // class java/util/List
      69: astore        9
      71: new           #20                 // class java/util/ArrayList
      74: dup
      75: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      78: checkcast     #57                 // class java/util/List
      81: astore        10
      83: new           #20                 // class java/util/ArrayList
      86: dup
      87: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      90: checkcast     #57                 // class java/util/List
      93: astore        11
      95: iconst_0
      96: istore        12
      98: iload         12
     100: iload         6
     102: if_icmpge     129
     105: aload         8
     107: aload_0
     108: iload         4
     110: aaload
     111: iload         12
     113: iaload
     114: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: invokeinterface #329,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     122: pop
     123: iinc          12, 1
     126: goto          98
     129: iload         6
     131: iconst_1
     132: iadd
     133: istore        12
     135: iload         12
     137: iload_1
     138: if_icmpge     165
     141: aload         9
     143: aload_0
     144: iload         4
     146: aaload
     147: iload         12
     149: iaload
     150: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: invokeinterface #329,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     158: pop
     159: iinc          12, 1
     162: goto          135
     165: iconst_0
     166: istore        12
     168: iload         12
     170: iload         4
     172: if_icmpge     199
     175: aload         10
     177: aload_0
     178: iload         12
     180: aaload
     181: iload         6
     183: iaload
     184: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     187: invokeinterface #329,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     192: pop
     193: iinc          12, 1
     196: goto          168
     199: iload         4
     201: iconst_1
     202: iadd
     203: istore        12
     205: iload         12
     207: iload_2
     208: if_icmpge     235
     211: aload         11
     213: aload_0
     214: iload         12
     216: aaload
     217: iload         6
     219: iaload
     220: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     223: invokeinterface #329,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     228: pop
     229: iinc          12, 1
     232: goto          205
     235: aload_3
     236: astore        12
     238: new           #331                // class kotlin/Pair
     241: dup
     242: iload         6
     244: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     247: iload         4
     249: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     252: invokespecial #334                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     255: astore        13
     257: iconst_4
     258: anewarray     #57                 // class java/util/List
     261: astore        14
     263: aload         14
     265: iconst_0
     266: aload         8
     268: checkcast     #26                 // class java/lang/Iterable
     271: invokestatic  #338                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     274: aastore
     275: aload         14
     277: iconst_1
     278: aload         9
     280: aastore
     281: aload         14
     283: iconst_2
     284: aload         10
     286: checkcast     #26                 // class java/lang/Iterable
     289: invokestatic  #338                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     292: aastore
     293: aload         14
     295: iconst_3
     296: aload         11
     298: aastore
     299: aload         14
     301: invokestatic  #342                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     304: astore        14
     306: aload         12
     308: aload         13
     310: aload         14
     312: invokeinterface #346,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     317: pop
     318: iinc          6, 1
     321: goto          40
     324: iinc          4, 1
     327: goto          25
     330: aload_3
     331: areturn

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

  private static final boolean solution1$lambda$7(int[][], java.util.Map$Entry);
    Code:
       0: aload_1
       1: ldc_w         #363                // String tree
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokeinterface #368,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      13: checkcast     #26                 // class java/lang/Iterable
      16: astore_2
      17: iconst_0
      18: istore_3
      19: aload_2
      20: instanceof    #153                // class java/util/Collection
      23: ifeq          42
      26: aload_2
      27: checkcast     #153                // class java/util/Collection
      30: invokeinterface #371,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      35: ifeq          42
      38: iconst_0
      39: goto          221
      42: aload_2
      43: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        4
      50: aload         4
      52: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          220
      60: aload         4
      62: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        5
      69: aload         5
      71: checkcast     #57                 // class java/util/List
      74: astore        6
      76: iconst_0
      77: istore        7
      79: aload         6
      81: checkcast     #26                 // class java/lang/Iterable
      84: astore        8
      86: iconst_0
      87: istore        9
      89: aload         8
      91: instanceof    #153                // class java/util/Collection
      94: ifeq          114
      97: aload         8
      99: checkcast     #153                // class java/util/Collection
     102: invokeinterface #371,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     107: ifeq          114
     110: iconst_1
     111: goto          212
     114: aload         8
     116: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     121: astore        10
     123: aload         10
     125: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          211
     133: aload         10
     135: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     140: astore        11
     142: aload         11
     144: checkcast     #310                // class java/lang/Number
     147: invokevirtual #314                // Method java/lang/Number.intValue:()I
     150: istore        12
     152: iconst_0
     153: istore        13
     155: iload         12
     157: aload_0
     158: aload_1
     159: invokeinterface #374,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     164: checkcast     #331                // class kotlin/Pair
     167: invokevirtual #377                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     170: checkcast     #310                // class java/lang/Number
     173: invokevirtual #314                // Method java/lang/Number.intValue:()I
     176: aaload
     177: aload_1
     178: invokeinterface #374,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     183: checkcast     #331                // class kotlin/Pair
     186: invokevirtual #380                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     189: checkcast     #310                // class java/lang/Number
     192: invokevirtual #314                // Method java/lang/Number.intValue:()I
     195: iaload
     196: if_icmpge     203
     199: iconst_1
     200: goto          204
     203: iconst_0
     204: ifne          123
     207: iconst_0
     208: goto          212
     211: iconst_1
     212: nop
     213: ifeq          50
     216: iconst_1
     217: goto          221
     220: iconst_0
     221: ireturn

  private static final java.util.List solution2$lambda$11(int[][], java.util.Map$Entry);
    Code:
       0: aload_1
       1: ldc_w         #363                // String tree
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokeinterface #368,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      13: checkcast     #26                 // class java/lang/Iterable
      16: astore_2
      17: iconst_0
      18: istore_3
      19: aload_2
      20: astore        4
      22: new           #20                 // class java/util/ArrayList
      25: dup
      26: aload_2
      27: bipush        10
      29: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #153                // class java/util/Collection
      38: astore        5
      40: iconst_0
      41: istore        6
      43: aload         4
      45: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        7
      52: aload         7
      54: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          289
      62: aload         7
      64: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        8
      71: aload         5
      73: aload         8
      75: checkcast     #57                 // class java/util/List
      78: astore        9
      80: astore        25
      82: iconst_0
      83: istore        10
      85: aload         9
      87: checkcast     #26                 // class java/lang/Iterable
      90: astore        11
      92: iconst_0
      93: istore        12
      95: new           #392                // class kotlin/jvm/internal/Ref$BooleanRef
      98: dup
      99: invokespecial #393                // Method kotlin/jvm/internal/Ref$BooleanRef."<init>":()V
     102: astore        13
     104: aload         13
     106: iconst_1
     107: putfield      #396                // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
     110: aload         11
     112: astore        14
     114: iconst_0
     115: istore        15
     117: new           #20                 // class java/util/ArrayList
     120: dup
     121: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
     124: astore        16
     126: aload         14
     128: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        17
     135: aload         17
     137: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          265
     145: aload         17
     147: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        18
     154: aload         18
     156: astore        19
     158: iconst_0
     159: istore        20
     161: aload         13
     163: getfield      #396                // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
     166: istore        21
     168: aload         13
     170: aload         19
     172: checkcast     #310                // class java/lang/Number
     175: invokevirtual #314                // Method java/lang/Number.intValue:()I
     178: istore        22
     180: astore        23
     182: iconst_0
     183: istore        24
     185: aload_0
     186: aload_1
     187: invokeinterface #374,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     192: checkcast     #331                // class kotlin/Pair
     195: invokevirtual #377                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     198: checkcast     #310                // class java/lang/Number
     201: invokevirtual #314                // Method java/lang/Number.intValue:()I
     204: aaload
     205: aload_1
     206: invokeinterface #374,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     211: checkcast     #331                // class kotlin/Pair
     214: invokevirtual #380                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     217: checkcast     #310                // class java/lang/Number
     220: invokevirtual #314                // Method java/lang/Number.intValue:()I
     223: iaload
     224: iload         22
     226: if_icmple     233
     229: iconst_1
     230: goto          234
     233: iconst_0
     234: invokestatic  #399                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     237: aload         23
     239: swap
     240: invokevirtual #51                 // Method java/lang/Boolean.booleanValue:()Z
     243: putfield      #396                // Field kotlin/jvm/internal/Ref$BooleanRef.element:Z
     246: iload         21
     248: ifne          254
     251: goto          265
     254: aload         16
     256: aload         18
     258: invokevirtual #55                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     261: pop
     262: goto          135
     265: aload         16
     267: checkcast     #57                 // class java/util/List
     270: nop
     271: checkcast     #26                 // class java/lang/Iterable
     274: invokestatic  #401                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     277: aload         25
     279: swap
     280: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     285: pop
     286: goto          52
     289: aload         5
     291: checkcast     #57                 // class java/util/List
     294: nop
     295: checkcast     #26                 // class java/lang/Iterable
     298: astore_2
     299: nop
     300: iconst_0
     301: istore_3
     302: aload_2
     303: astore        4
     305: new           #20                 // class java/util/ArrayList
     308: dup
     309: aload_2
     310: bipush        10
     312: invokestatic  #148                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     315: invokespecial #151                // Method java/util/ArrayList."<init>":(I)V
     318: checkcast     #153                // class java/util/Collection
     321: astore        5
     323: iconst_0
     324: istore        6
     326: aload         4
     328: invokeinterface #30,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     333: astore        7
     335: aload         7
     337: invokeinterface #36,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     342: ifeq          390
     345: aload         7
     347: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     352: astore        8
     354: aload         5
     356: aload         8
     358: checkcast     #57                 // class java/util/List
     361: astore        9
     363: astore        25
     365: iconst_0
     366: istore        10
     368: aload         9
     370: invokeinterface #404,  1          // InterfaceMethod java/util/List.size:()I
     375: invokestatic  #171                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     378: aload         25
     380: swap
     381: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     386: pop
     387: goto          335
     390: aload         5
     392: checkcast     #57                 // class java/util/List
     395: nop
     396: areturn
}


package day01

import java.io.File
import java.util.PriorityQueue

fun main() {
    fun parseInput(input: String) = input.split("\n\n").map { str ->
        str.lines().map { it.toInt() }
    }

    fun List<List<Int>>.topNElves(n: Int): Int {
        val best = PriorityQueue<Int>()
        for (calories in map { it.sum() }) {
            best.add(calories)
            if (best.size > n) {
                best.poll()
            }
        }
        return best.sum()
    }

    fun part1(input: String): Int {
        val data = parseInput(input)
        return data.topNElves(1)
    }

    fun part2(input: String): Int {
        val data = parseInput(input)
        return data.topNElves(3)
    }

    // test if implementation meets criteria from the description, like:
    val testInput = File("src/day01//Day01_test.txt").readText()
    check(part1(testInput) == 24000)
    println(part1(testInput))
    println(part2(testInput))

    val input = File("src/day01/Day01.txt").readText()
    println(part1(input))
    println(part2(input))
}

Compiled from "Day01.kt"
public final class day01.Day01Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day01//Day01_test.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: astore_0
      16: aload_0
      17: invokestatic  #24                 // Method main$part1:(Ljava/lang/String;)I
      20: sipush        24000
      23: if_icmpne     30
      26: iconst_1
      27: goto          31
      30: iconst_0
      31: ifne          44
      34: new           #26                 // class java/lang/IllegalStateException
      37: dup
      38: ldc           #28                 // String Check failed.
      40: invokespecial #29                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      43: athrow
      44: aload_0
      45: invokestatic  #24                 // Method main$part1:(Ljava/lang/String;)I
      48: istore_1
      49: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      52: iload_1
      53: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
      56: aload_0
      57: invokestatic  #44                 // Method main$part2:(Ljava/lang/String;)I
      60: istore_1
      61: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      64: iload_1
      65: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
      68: new           #8                  // class java/io/File
      71: dup
      72: ldc           #46                 // String src/day01/Day01.txt
      74: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      77: aconst_null
      78: iconst_1
      79: aconst_null
      80: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      83: astore_1
      84: aload_1
      85: invokestatic  #24                 // Method main$part1:(Ljava/lang/String;)I
      88: istore_2
      89: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: iload_2
      93: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
      96: aload_1
      97: invokestatic  #44                 // Method main$part2:(Ljava/lang/String;)I
     100: istore_2
     101: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
     104: iload_2
     105: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
     108: return

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

  private static final java.util.List<java.util.List<java.lang.Integer>> main$parseInput(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #61                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #51                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #63                 // String \n\n
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #69                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #71                 // class java/lang/Iterable
      26: astore_1
      27: iconst_0
      28: istore_2
      29: aload_1
      30: astore_3
      31: new           #73                 // class java/util/ArrayList
      34: dup
      35: aload_1
      36: bipush        10
      38: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
      44: checkcast     #83                 // class java/util/Collection
      47: astore        4
      49: iconst_0
      50: istore        5
      52: aload_3
      53: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        6
      60: aload         6
      62: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          217
      70: aload         6
      72: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        7
      79: aload         4
      81: aload         7
      83: checkcast     #51                 // class java/lang/String
      86: astore        8
      88: astore        20
      90: iconst_0
      91: istore        9
      93: aload         8
      95: checkcast     #61                 // class java/lang/CharSequence
      98: invokestatic  #101                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
     101: checkcast     #71                 // class java/lang/Iterable
     104: astore        10
     106: iconst_0
     107: istore        11
     109: aload         10
     111: astore        12
     113: new           #73                 // class java/util/ArrayList
     116: dup
     117: aload         10
     119: bipush        10
     121: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     124: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
     127: checkcast     #83                 // class java/util/Collection
     130: astore        13
     132: iconst_0
     133: istore        14
     135: aload         12
     137: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     142: astore        15
     144: aload         15
     146: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifeq          198
     154: aload         15
     156: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     161: astore        16
     163: aload         13
     165: aload         16
     167: checkcast     #51                 // class java/lang/String
     170: astore        17
     172: astore        18
     174: iconst_0
     175: istore        19
     177: aload         17
     179: invokestatic  #106                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     182: nop
     183: invokestatic  #110                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     186: aload         18
     188: swap
     189: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     194: pop
     195: goto          144
     198: aload         13
     200: checkcast     #116                // class java/util/List
     203: nop
     204: nop
     205: aload         20
     207: swap
     208: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     213: pop
     214: goto          60
     217: aload         4
     219: checkcast     #116                // class java/util/List
     222: nop
     223: areturn

  private static final int main$topNElves(java.util.List<? extends java.util.List<java.lang.Integer>>, int);
    Code:
       0: new           #135                // class java/util/PriorityQueue
       3: dup
       4: invokespecial #137                // Method java/util/PriorityQueue."<init>":()V
       7: astore_2
       8: aload_0
       9: checkcast     #71                 // class java/lang/Iterable
      12: astore        4
      14: iconst_0
      15: istore        5
      17: aload         4
      19: astore        6
      21: new           #73                 // class java/util/ArrayList
      24: dup
      25: aload         4
      27: bipush        10
      29: invokestatic  #79                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #83                 // class java/util/Collection
      38: astore        7
      40: iconst_0
      41: istore        8
      43: aload         6
      45: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        9
      52: aload         9
      54: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          108
      62: aload         9
      64: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        10
      71: aload         7
      73: aload         10
      75: checkcast     #116                // class java/util/List
      78: astore        11
      80: astore        13
      82: iconst_0
      83: istore        12
      85: aload         11
      87: checkcast     #71                 // class java/lang/Iterable
      90: invokestatic  #141                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      93: invokestatic  #110                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      96: aload         13
      98: swap
      99: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     104: pop
     105: goto          52
     108: aload         7
     110: checkcast     #116                // class java/util/List
     113: nop
     114: invokeinterface #142,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     119: astore_3
     120: aload_3
     121: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     126: ifeq          169
     129: aload_3
     130: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: checkcast     #144                // class java/lang/Number
     138: invokevirtual #148                // Method java/lang/Number.intValue:()I
     141: istore        4
     143: aload_2
     144: iload         4
     146: invokestatic  #110                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     149: invokevirtual #149                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     152: pop
     153: aload_2
     154: invokevirtual #152                // Method java/util/PriorityQueue.size:()I
     157: iload_1
     158: if_icmple     120
     161: aload_2
     162: invokevirtual #155                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     165: pop
     166: goto          120
     169: aload_2
     170: checkcast     #71                 // class java/lang/Iterable
     173: invokestatic  #141                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     176: ireturn

  private static final int main$part1(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #164                // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
       4: astore_1
       5: aload_1
       6: iconst_1
       7: invokestatic  #166                // Method main$topNElves:(Ljava/util/List;I)I
      10: ireturn

  private static final int main$part2(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #164                // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
       4: astore_1
       5: aload_1
       6: iconst_3
       7: invokestatic  #166                // Method main$topNElves:(Ljava/util/List;I)I
      10: ireturn
}