package asaad

import java.io.File

private const val MAX_STORAGE = 70000000
private const val REQUIRED_STORAGE = 30000000
private const val PART1 = 100000

class DaySeven(filePath: String) {
    private val file = File(filePath)
    private val input = readInput(file)
    private var lineNumber = 0
    private fun readInput(file: File) = file.bufferedReader().readLines()

    fun result() {
        val head = Node(name = "head")
        val root = Node(name = "/")
        head.children.add(root)
        createFileTree(head)
        val dirSizes = mutableListOf<Int>()
        getDirsSizes(root, sizes = dirSizes)
        dirSizes.sort()

        println("\tpart 1: ${solve1(dirSizes)}")
        println("\tpart 2: ${solve2(root, dirSizes)}")
    }

    /**
     * Time complexity: O(Log(N)) where N is the number of directories
     */
    private fun solve2(root: Node, sizes: MutableList<Int>): Int {
        val used = root.dirSize
        val available = MAX_STORAGE - used

        if (available >= REQUIRED_STORAGE)
            return 0

        var answer = 0
        var (left, right) = listOf(0, sizes.size - 1)
        while (left <= right) {
            val mid = left + (right - left) / 2
            val current = sizes[mid]
            if (available >= REQUIRED_STORAGE - current) {
                answer = current
                right = mid - 1
            } else {
                left = mid + 1
            }
        }

        return answer
    }

    /**
     * @param sizes: the list where the directory sizes will be appended
     * gets the list of directory sizes
     * Space Complexity : O(N) where N is the number of directories
     */
    private fun getDirsSizes(node: Node, sizes: MutableList<Int>) {
        sizes.add(node.dirSize)
        for (child in node.children)
            getDirsSizes(child, sizes)
    }

    /**
     * Time Complexity: O(N) where N is the number of directories
     */
    private fun solve1(dirSizes: List<Int>) = dirSizes.takeWhile { it <= PART1 }.sum()

    /**
     * Creates a dir tree, and computes the size of each directory
     * Time Complexity: O(M) where M is the number of lines
     */
    private fun createFileTree(current: Node): Int {
        var nextLine = input.readNext()
        val nodes = HashMap<String, Node>()
        while (nextLine != null) {
            when {
                nextLine.startsWith("$") -> {
                    val command = parseCommand(nextLine)
                    when (command.first) {
                        Command.LS -> {}

                        Command.GOTO -> {
                            val dirNode = command.second!!
                            if (dirNode == "/")
                                nodes[dirNode] = current.children.first()
                            current.dirSize += createFileTree(nodes[dirNode]!!)
                        }

                        Command.BACK -> return current.dirSize
                    }
                }

                nextLine.startsWith("dir") -> {
                    val dirName = nextLine.split(" ")[1]
                    val dirNode = Node(name = dirName)
                    nodes[dirName] = dirNode
                    current.children.add(dirNode)
                }

                nextLine[0].isDigit() -> {
                    val fileSize = nextLine.split(" ")[0].toInt()
                    current.dirSize += fileSize
                }

                else -> {
                    throw Exception("unable to parse line $nextLine")
                }
            }

            nextLine = input.readNext()
        }

        return current.dirSize
    }

    private fun parseCommand(line: String): Pair<Command, String?> {
        val split = line.split(" ")
        return when {
            split.size > 1 && split[1] == "ls" -> Command.LS to null
            split.size > 2 && split[1] == "cd" && split[2] == ".." -> Command.BACK to null
            split.size > 2 && split[1] == "cd" -> Command.GOTO to split[2]
            else -> throw Exception("unknown command $line")
        }
    }

    enum class Command {
        GOTO,
        BACK,
        LS
    }

    data class Node(
        var name: String,
        var dirSize: Int = 0,
        var children: MutableList<Node> = mutableListOf(),
    )

    private fun <E> List<E>.readNext(): String? {
        if (lineNumber > size - 1)
            return null

        return input[lineNumber].also { lineNumber++ }
    }
}

Compiled from "DaySeven.kt"
public final class asaad.DaySeven$Command extends java.lang.Enum<asaad.DaySeven$Command> {
  public static final asaad.DaySeven$Command GOTO;

  public static final asaad.DaySeven$Command BACK;

  public static final asaad.DaySeven$Command LS;

  private static final asaad.DaySeven$Command[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

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

  public static asaad.DaySeven$Command[] values();
    Code:
       0: getstatic     #22                 // Field $VALUES:[Lasaad/DaySeven$Command;
       3: invokevirtual #28                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #29                 // class "[Lasaad/DaySeven$Command;"
       9: areturn

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

  public static kotlin.enums.EnumEntries<asaad.DaySeven$Command> getEntries();
    Code:
       0: getstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final asaad.DaySeven$Command[] $values();
    Code:
       0: iconst_3
       1: anewarray     #2                  // class asaad/DaySeven$Command
       4: astore_0
       5: aload_0
       6: iconst_0
       7: getstatic     #47                 // Field GOTO:Lasaad/DaySeven$Command;
      10: aastore
      11: aload_0
      12: iconst_1
      13: getstatic     #50                 // Field BACK:Lasaad/DaySeven$Command;
      16: aastore
      17: aload_0
      18: iconst_2
      19: getstatic     #53                 // Field LS:Lasaad/DaySeven$Command;
      22: aastore
      23: aload_0
      24: areturn

  static {};
    Code:
       0: new           #2                  // class asaad/DaySeven$Command
       3: dup
       4: ldc           #55                 // String GOTO
       6: iconst_0
       7: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      10: putstatic     #47                 // Field GOTO:Lasaad/DaySeven$Command;
      13: new           #2                  // class asaad/DaySeven$Command
      16: dup
      17: ldc           #57                 // String BACK
      19: iconst_1
      20: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      23: putstatic     #50                 // Field BACK:Lasaad/DaySeven$Command;
      26: new           #2                  // class asaad/DaySeven$Command
      29: dup
      30: ldc           #58                 // String LS
      32: iconst_2
      33: invokespecial #56                 // Method "<init>":(Ljava/lang/String;I)V
      36: putstatic     #53                 // Field LS:Lasaad/DaySeven$Command;
      39: invokestatic  #60                 // Method $values:()[Lasaad/DaySeven$Command;
      42: putstatic     #22                 // Field $VALUES:[Lasaad/DaySeven$Command;
      45: getstatic     #22                 // Field $VALUES:[Lasaad/DaySeven$Command;
      48: checkcast     #62                 // class "[Ljava/lang/Enum;"
      51: invokestatic  #68                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
      54: putstatic     #43                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
      57: return
}

Compiled from "DaySeven.kt"
public final class asaad.DaySevenKt {
  private static final int MAX_STORAGE;

  private static final int REQUIRED_STORAGE;

  private static final int PART1;

}

Compiled from "DaySeven.kt"
public final class asaad.DaySeven$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method asaad/DaySeven$Command.values:()[Lasaad/DaySeven$Command;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field asaad/DaySeven$Command.LS:Lasaad/DaySeven$Command;
      12: invokevirtual #22                 // Method asaad/DaySeven$Command.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field asaad/DaySeven$Command.GOTO:Lasaad/DaySeven$Command;
      26: invokevirtual #22                 // Method asaad/DaySeven$Command.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field asaad/DaySeven$Command.BACK:Lasaad/DaySeven$Command;
      40: invokevirtual #22                 // Method asaad/DaySeven$Command.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: aload_0
      50: putstatic     #32                 // Field $EnumSwitchMapping$0:[I
      53: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
}

Compiled from "DaySeven.kt"
public final class asaad.DaySeven {
  private final java.io.File file;

  private final java.util.List<java.lang.String> input;

  private int lineNumber;

  public asaad.DaySeven(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String filePath
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: new           #20                 // class java/io/File
      14: dup
      15: aload_1
      16: invokespecial #22                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      19: putfield      #26                 // Field file:Ljava/io/File;
      22: aload_0
      23: aload_0
      24: aload_0
      25: getfield      #26                 // Field file:Ljava/io/File;
      28: invokespecial #30                 // Method readInput:(Ljava/io/File;)Ljava/util/List;
      31: putfield      #34                 // Field input:Ljava/util/List;
      34: return

  private final java.util.List<java.lang.String> readInput(java.io.File);
    Code:
       0: aload_1
       1: astore_2
       2: getstatic     #44                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       5: astore_3
       6: sipush        8192
       9: istore        4
      11: aload_2
      12: astore        5
      14: new           #46                 // class java/io/InputStreamReader
      17: dup
      18: new           #48                 // class java/io/FileInputStream
      21: dup
      22: aload         5
      24: invokespecial #51                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      27: checkcast     #53                 // class java/io/InputStream
      30: aload_3
      31: invokespecial #56                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      34: checkcast     #58                 // class java/io/Reader
      37: astore        5
      39: aload         5
      41: instanceof    #60                 // class java/io/BufferedReader
      44: ifeq          55
      47: aload         5
      49: checkcast     #60                 // class java/io/BufferedReader
      52: goto          66
      55: new           #60                 // class java/io/BufferedReader
      58: dup
      59: aload         5
      61: iload         4
      63: invokespecial #63                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      66: checkcast     #58                 // class java/io/Reader
      69: invokestatic  #69                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      72: areturn

  public final void result();
    Code:
       0: new           #74                 // class asaad/DaySeven$Node
       3: dup
       4: ldc           #76                 // String head
       6: iconst_0
       7: aconst_null
       8: bipush        6
      10: aconst_null
      11: invokespecial #79                 // Method asaad/DaySeven$Node."<init>":(Ljava/lang/String;ILjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      14: astore_1
      15: new           #74                 // class asaad/DaySeven$Node
      18: dup
      19: ldc           #81                 // String /
      21: iconst_0
      22: aconst_null
      23: bipush        6
      25: aconst_null
      26: invokespecial #79                 // Method asaad/DaySeven$Node."<init>":(Ljava/lang/String;ILjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      29: astore_2
      30: aload_1
      31: invokevirtual #85                 // Method asaad/DaySeven$Node.getChildren:()Ljava/util/List;
      34: aload_2
      35: invokeinterface #91,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      40: pop
      41: aload_0
      42: aload_1
      43: invokespecial #95                 // Method createFileTree:(Lasaad/DaySeven$Node;)I
      46: pop
      47: new           #97                 // class java/util/ArrayList
      50: dup
      51: invokespecial #98                 // Method java/util/ArrayList."<init>":()V
      54: checkcast     #87                 // class java/util/List
      57: astore_3
      58: aload_0
      59: aload_2
      60: aload_3
      61: invokespecial #102                // Method getDirsSizes:(Lasaad/DaySeven$Node;Ljava/util/List;)V
      64: aload_3
      65: invokestatic  #108                // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
      68: new           #110                // class java/lang/StringBuilder
      71: dup
      72: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
      75: ldc           #113                // String \tpart 1:
      77: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      80: aload_0
      81: aload_3
      82: invokespecial #121                // Method solve1:(Ljava/util/List;)I
      85: invokevirtual #124                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      88: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      91: getstatic     #134                // Field java/lang/System.out:Ljava/io/PrintStream;
      94: swap
      95: invokevirtual #140                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      98: new           #110                // class java/lang/StringBuilder
     101: dup
     102: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
     105: ldc           #142                // String \tpart 2:
     107: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     110: aload_0
     111: aload_2
     112: aload_3
     113: invokespecial #146                // Method solve2:(Lasaad/DaySeven$Node;Ljava/util/List;)I
     116: invokevirtual #124                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     119: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     122: getstatic     #134                // Field java/lang/System.out:Ljava/io/PrintStream;
     125: swap
     126: invokevirtual #140                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     129: return

  private final int solve2(asaad.DaySeven$Node, java.util.List<java.lang.Integer>);
    Code:
       0: aload_1
       1: invokevirtual #154                // Method asaad/DaySeven$Node.getDirSize:()I
       4: istore_3
       5: ldc           #155                // int 70000000
       7: iload_3
       8: isub
       9: istore        4
      11: iload         4
      13: ldc           #156                // int 30000000
      15: if_icmplt     20
      18: iconst_0
      19: ireturn
      20: iconst_0
      21: istore        5
      23: iconst_2
      24: anewarray     #158                // class java/lang/Integer
      27: astore        7
      29: aload         7
      31: iconst_0
      32: iconst_0
      33: invokestatic  #162                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: aastore
      37: aload         7
      39: iconst_1
      40: aload_2
      41: invokeinterface #165,  1          // InterfaceMethod java/util/List.size:()I
      46: iconst_1
      47: isub
      48: invokestatic  #162                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: aastore
      52: aload         7
      54: invokestatic  #169                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      57: astore        6
      59: aload         6
      61: iconst_0
      62: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #175                // class java/lang/Number
      70: invokevirtual #178                // Method java/lang/Number.intValue:()I
      73: istore        7
      75: aload         6
      77: iconst_1
      78: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      83: checkcast     #175                // class java/lang/Number
      86: invokevirtual #178                // Method java/lang/Number.intValue:()I
      89: istore        8
      91: iload         7
      93: iload         8
      95: if_icmpgt     158
      98: iload         7
     100: iload         8
     102: iload         7
     104: isub
     105: iconst_2
     106: idiv
     107: iadd
     108: istore        9
     110: aload_2
     111: iload         9
     113: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #175                // class java/lang/Number
     121: invokevirtual #178                // Method java/lang/Number.intValue:()I
     124: istore        10
     126: iload         4
     128: ldc           #156                // int 30000000
     130: iload         10
     132: isub
     133: if_icmplt     149
     136: iload         10
     138: istore        5
     140: iload         9
     142: iconst_1
     143: isub
     144: istore        8
     146: goto          91
     149: iload         9
     151: iconst_1
     152: iadd
     153: istore        7
     155: goto          91
     158: iload         5
     160: ireturn

  private final void getDirsSizes(asaad.DaySeven$Node, java.util.List<java.lang.Integer>);
    Code:
       0: aload_2
       1: aload_1
       2: invokevirtual #154                // Method asaad/DaySeven$Node.getDirSize:()I
       5: invokestatic  #162                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       8: invokeinterface #91,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      13: pop
      14: aload_1
      15: invokevirtual #85                 // Method asaad/DaySeven$Node.getChildren:()Ljava/util/List;
      18: invokeinterface #192,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      23: astore_3
      24: aload_3
      25: invokeinterface #198,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          54
      33: aload_3
      34: invokeinterface #202,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #74                 // class asaad/DaySeven$Node
      42: astore        4
      44: aload_0
      45: aload         4
      47: aload_2
      48: invokespecial #102                // Method getDirsSizes:(Lasaad/DaySeven$Node;Ljava/util/List;)V
      51: goto          24
      54: return

  private final int solve1(java.util.List<java.lang.Integer>);
    Code:
       0: aload_1
       1: checkcast     #207                // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: new           #97                 // class java/util/ArrayList
      10: dup
      11: invokespecial #98                 // Method java/util/ArrayList."<init>":()V
      14: astore        4
      16: aload_2
      17: invokeinterface #208,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        5
      24: aload         5
      26: invokeinterface #198,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifeq          85
      34: aload         5
      36: invokeinterface #202,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      41: astore        6
      43: aload         6
      45: checkcast     #175                // class java/lang/Number
      48: invokevirtual #178                // Method java/lang/Number.intValue:()I
      51: istore        7
      53: iconst_0
      54: istore        8
      56: iload         7
      58: ldc           #209                // int 100000
      60: if_icmpgt     67
      63: iconst_1
      64: goto          68
      67: iconst_0
      68: ifne          74
      71: goto          85
      74: aload         4
      76: aload         6
      78: invokevirtual #210                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      81: pop
      82: goto          24
      85: aload         4
      87: checkcast     #87                 // class java/util/List
      90: checkcast     #207                // class java/lang/Iterable
      93: invokestatic  #214                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
      96: ireturn

  private final int createFileTree(asaad.DaySeven$Node);
    Code:
       0: aload_0
       1: aload_0
       2: getfield      #34                 // Field input:Ljava/util/List;
       5: invokespecial #227                // Method readNext:(Ljava/util/List;)Ljava/lang/String;
       8: astore_2
       9: new           #229                // class java/util/HashMap
      12: dup
      13: invokespecial #230                // Method java/util/HashMap."<init>":()V
      16: astore_3
      17: aload_2
      18: ifnull        374
      21: nop
      22: aload_2
      23: ldc           #232                // String $
      25: iconst_0
      26: iconst_2
      27: aconst_null
      28: invokestatic  #238                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      31: ifeq          172
      34: aload_0
      35: aload_2
      36: invokespecial #242                // Method parseCommand:(Ljava/lang/String;)Lkotlin/Pair;
      39: astore        4
      41: aload         4
      43: invokevirtual #247                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      46: checkcast     #249                // class asaad/DaySeven$Command
      49: getstatic     #255                // Field asaad/DaySeven$WhenMappings.$EnumSwitchMapping$0:[I
      52: swap
      53: invokevirtual #258                // Method asaad/DaySeven$Command.ordinal:()I
      56: iaload
      57: tableswitch   { // 1 to 3
                     1: 84
                     2: 87
                     3: 159
               default: 164
          }
      84: goto          362
      87: aload         4
      89: invokevirtual #261                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      92: dup
      93: invokestatic  #264                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      96: checkcast     #266                // class java/lang/String
      99: astore        6
     101: aload         6
     103: ldc           #81                 // String /
     105: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     108: ifeq          130
     111: aload_3
     112: checkcast     #272                // class java/util/Map
     115: aload         6
     117: aload_1
     118: invokevirtual #85                 // Method asaad/DaySeven$Node.getChildren:()Ljava/util/List;
     121: invokestatic  #276                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     124: invokeinterface #280,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     129: pop
     130: aload_1
     131: aload_1
     132: invokevirtual #154                // Method asaad/DaySeven$Node.getDirSize:()I
     135: aload_0
     136: aload_3
     137: aload         6
     139: invokevirtual #283                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     142: dup
     143: invokestatic  #264                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     146: checkcast     #74                 // class asaad/DaySeven$Node
     149: invokespecial #95                 // Method createFileTree:(Lasaad/DaySeven$Node;)I
     152: iadd
     153: invokevirtual #287                // Method asaad/DaySeven$Node.setDirSize:(I)V
     156: goto          362
     159: aload_1
     160: invokevirtual #154                // Method asaad/DaySeven$Node.getDirSize:()I
     163: ireturn
     164: new           #289                // class kotlin/NoWhenBranchMatchedException
     167: dup
     168: invokespecial #290                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     171: athrow
     172: aload_2
     173: ldc_w         #292                // String dir
     176: iconst_0
     177: iconst_2
     178: aconst_null
     179: invokestatic  #238                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     182: ifeq          268
     185: aload_2
     186: checkcast     #294                // class java/lang/CharSequence
     189: iconst_1
     190: anewarray     #266                // class java/lang/String
     193: astore        5
     195: aload         5
     197: iconst_0
     198: ldc_w         #296                // String
     201: aastore
     202: aload         5
     204: iconst_0
     205: iconst_0
     206: bipush        6
     208: aconst_null
     209: invokestatic  #300                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     212: iconst_1
     213: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     218: checkcast     #266                // class java/lang/String
     221: astore        4
     223: new           #74                 // class asaad/DaySeven$Node
     226: dup
     227: aload         4
     229: iconst_0
     230: aconst_null
     231: bipush        6
     233: aconst_null
     234: invokespecial #79                 // Method asaad/DaySeven$Node."<init>":(Ljava/lang/String;ILjava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     237: astore        5
     239: aload_3
     240: checkcast     #272                // class java/util/Map
     243: aload         4
     245: aload         5
     247: invokeinterface #280,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     252: pop
     253: aload_1
     254: invokevirtual #85                 // Method asaad/DaySeven$Node.getChildren:()Ljava/util/List;
     257: aload         5
     259: invokeinterface #91,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     264: pop
     265: goto          362
     268: aload_2
     269: iconst_0
     270: invokevirtual #304                // Method java/lang/String.charAt:(I)C
     273: invokestatic  #310                // Method java/lang/Character.isDigit:(C)Z
     276: ifeq          334
     279: aload_2
     280: checkcast     #294                // class java/lang/CharSequence
     283: iconst_1
     284: anewarray     #266                // class java/lang/String
     287: astore        5
     289: aload         5
     291: iconst_0
     292: ldc_w         #296                // String
     295: aastore
     296: aload         5
     298: iconst_0
     299: iconst_0
     300: bipush        6
     302: aconst_null
     303: invokestatic  #300                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     306: iconst_0
     307: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     312: checkcast     #266                // class java/lang/String
     315: invokestatic  #314                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     318: istore        4
     320: aload_1
     321: aload_1
     322: invokevirtual #154                // Method asaad/DaySeven$Node.getDirSize:()I
     325: iload         4
     327: iadd
     328: invokevirtual #287                // Method asaad/DaySeven$Node.setDirSize:(I)V
     331: goto          362
     334: new           #316                // class java/lang/Exception
     337: dup
     338: new           #110                // class java/lang/StringBuilder
     341: dup
     342: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
     345: ldc_w         #318                // String unable to parse line
     348: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     351: aload_2
     352: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     355: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     358: invokespecial #319                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     361: athrow
     362: aload_0
     363: aload_0
     364: getfield      #34                 // Field input:Ljava/util/List;
     367: invokespecial #227                // Method readNext:(Ljava/util/List;)Ljava/lang/String;
     370: astore_2
     371: goto          17
     374: aload_1
     375: invokevirtual #154                // Method asaad/DaySeven$Node.getDirSize:()I
     378: ireturn

  private final kotlin.Pair<asaad.DaySeven$Command, java.lang.String> parseCommand(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #294                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #266                // class java/lang/String
       8: astore_3
       9: aload_3
      10: iconst_0
      11: ldc_w         #296                // String
      14: aastore
      15: aload_3
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #300                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: astore_2
      25: nop
      26: aload_2
      27: invokeinterface #165,  1          // InterfaceMethod java/util/List.size:()I
      32: iconst_1
      33: if_icmple     62
      36: aload_2
      37: iconst_1
      38: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      43: ldc_w         #330                // String ls
      46: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      49: ifeq          62
      52: getstatic     #334                // Field asaad/DaySeven$Command.LS:Lasaad/DaySeven$Command;
      55: aconst_null
      56: invokestatic  #340                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      59: goto          184
      62: aload_2
      63: invokeinterface #165,  1          // InterfaceMethod java/util/List.size:()I
      68: iconst_2
      69: if_icmple     114
      72: aload_2
      73: iconst_1
      74: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      79: ldc_w         #342                // String cd
      82: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      85: ifeq          114
      88: aload_2
      89: iconst_2
      90: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      95: ldc_w         #344                // String ..
      98: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     101: ifeq          114
     104: getstatic     #347                // Field asaad/DaySeven$Command.BACK:Lasaad/DaySeven$Command;
     107: aconst_null
     108: invokestatic  #340                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: goto          184
     114: aload_2
     115: invokeinterface #165,  1          // InterfaceMethod java/util/List.size:()I
     120: iconst_2
     121: if_icmple     156
     124: aload_2
     125: iconst_1
     126: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     131: ldc_w         #342                // String cd
     134: invokestatic  #270                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     137: ifeq          156
     140: getstatic     #350                // Field asaad/DaySeven$Command.GOTO:Lasaad/DaySeven$Command;
     143: aload_2
     144: iconst_2
     145: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     150: invokestatic  #340                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     153: goto          184
     156: new           #316                // class java/lang/Exception
     159: dup
     160: new           #110                // class java/lang/StringBuilder
     163: dup
     164: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
     167: ldc_w         #352                // String unknown command
     170: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     173: aload_1
     174: invokevirtual #117                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     177: invokevirtual #128                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     180: invokespecial #319                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     183: athrow
     184: areturn

  private final <E> java.lang.String readNext(java.util.List<? extends E>);
    Code:
       0: aload_0
       1: getfield      #360                // Field lineNumber:I
       4: aload_1
       5: invokeinterface #165,  1          // InterfaceMethod java/util/List.size:()I
      10: iconst_1
      11: isub
      12: if_icmple     17
      15: aconst_null
      16: areturn
      17: aload_0
      18: getfield      #34                 // Field input:Ljava/util/List;
      21: aload_0
      22: getfield      #360                // Field lineNumber:I
      25: invokeinterface #173,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      30: astore_2
      31: aload_2
      32: checkcast     #266                // class java/lang/String
      35: astore_3
      36: iconst_0
      37: istore        4
      39: aload_0
      40: getfield      #360                // Field lineNumber:I
      43: istore        5
      45: aload_0
      46: iload         5
      48: iconst_1
      49: iadd
      50: putfield      #360                // Field lineNumber:I
      53: aload_2
      54: checkcast     #266                // class java/lang/String
      57: areturn
}

Compiled from "DaySeven.kt"
public final class asaad.DaySeven$Node {
  private java.lang.String name;

  private int dirSize;

  private java.util.List<asaad.DaySeven$Node> children;

  public asaad.DaySeven$Node(java.lang.String, int, java.util.List<asaad.DaySeven$Node>);
    Code:
       0: aload_1
       1: ldc           #10                 // String name
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #18                 // String children
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field name:Ljava/lang/String;
      21: aload_0
      22: iload_2
      23: putfield      #28                 // Field dirSize:I
      26: aload_0
      27: aload_3
      28: putfield      #31                 // Field children:Ljava/util/List;
      31: return

  public asaad.DaySeven$Node(java.lang.String, int, java.util.List, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload         4
       2: iconst_2
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_2
       9: iload         4
      11: iconst_4
      12: iand
      13: ifeq          27
      16: new           #36                 // class java/util/ArrayList
      19: dup
      20: invokespecial #37                 // Method java/util/ArrayList."<init>":()V
      23: checkcast     #39                 // class java/util/List
      26: astore_3
      27: aload_0
      28: aload_1
      29: iload_2
      30: aload_3
      31: invokespecial #41                 // Method "<init>":(Ljava/lang/String;ILjava/util/List;)V
      34: return

  public final java.lang.String getName();
    Code:
       0: aload_0
       1: getfield      #24                 // Field name:Ljava/lang/String;
       4: areturn

  public final void setName(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #47                 // String <set-?>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #24                 // Field name:Ljava/lang/String;
      11: return

  public final int getDirSize();
    Code:
       0: aload_0
       1: getfield      #28                 // Field dirSize:I
       4: ireturn

  public final void setDirSize(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #28                 // Field dirSize:I
       5: return

  public final java.util.List<asaad.DaySeven$Node> getChildren();
    Code:
       0: aload_0
       1: getfield      #31                 // Field children:Ljava/util/List;
       4: areturn

  public final void setChildren(java.util.List<asaad.DaySeven$Node>);
    Code:
       0: aload_1
       1: ldc           #47                 // String <set-?>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #31                 // Field children:Ljava/util/List;
      11: return

  public final java.lang.String component1();
    Code:
       0: aload_0
       1: getfield      #24                 // Field name:Ljava/lang/String;
       4: areturn

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

  public final java.util.List<asaad.DaySeven$Node> component3();
    Code:
       0: aload_0
       1: getfield      #31                 // Field children:Ljava/util/List;
       4: areturn

  public final asaad.DaySeven$Node copy(java.lang.String, int, java.util.List<asaad.DaySeven$Node>);
    Code:
       0: aload_1
       1: ldc           #10                 // String name
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #18                 // String children
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class asaad/DaySeven$Node
      15: dup
      16: aload_1
      17: iload_2
      18: aload_3
      19: invokespecial #41                 // Method "<init>":(Ljava/lang/String;ILjava/util/List;)V
      22: areturn

  public static asaad.DaySeven$Node copy$default(asaad.DaySeven$Node, java.lang.String, int, java.util.List, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #24                 // Field name:Ljava/lang/String;
      11: astore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #28                 // Field dirSize:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #31                 // Field children:Ljava/util/List;
      35: astore_3
      36: aload_0
      37: aload_1
      38: iload_2
      39: aload_3
      40: invokevirtual #67                 // Method copy:(Ljava/lang/String;ILjava/util/List;)Lasaad/DaySeven$Node;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #70                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #71                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #73                 // String Node(name=
       9: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #24                 // Field name:Ljava/lang/String;
      16: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      19: ldc           #79                 // String , dirSize=
      21: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #28                 // Field dirSize:I
      28: invokevirtual #82                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #84                 // String , children=
      33: invokevirtual #77                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #31                 // Field children:Ljava/util/List;
      40: invokevirtual #87                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #90                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #92                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #24                 // Field name:Ljava/lang/String;
       4: invokevirtual #97                 // Method java/lang/String.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #28                 // Field dirSize:I
      16: invokestatic  #102                // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #31                 // Field children:Ljava/util/List;
      29: invokevirtual #103                // Method java/lang/Object.hashCode:()I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class asaad/DaySeven$Node
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class asaad/DaySeven$Node
      20: astore_2
      21: aload_0
      22: getfield      #24                 // Field name:Ljava/lang/String;
      25: aload_2
      26: getfield      #24                 // Field name:Ljava/lang/String;
      29: invokestatic  #111                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #28                 // Field dirSize:I
      41: aload_2
      42: getfield      #28                 // Field dirSize:I
      45: if_icmpeq     50
      48: iconst_0
      49: ireturn
      50: aload_0
      51: getfield      #31                 // Field children:Ljava/util/List;
      54: aload_2
      55: getfield      #31                 // Field children:Ljava/util/List;
      58: invokestatic  #111                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      61: ifne          66
      64: iconst_0
      65: ireturn
      66: iconst_1
      67: ireturn
}


package asaad

import java.io.File
import kotlin.math.abs

class DayNine(filePath: String) {
    private val file = File(filePath)
    private val input = readInput(file)
    private fun readInput(file: File) = file.bufferedReader().readLines()

    fun result() {
        println("\tpart1: ${solve(2)}")
        println("\tpart2: ${solve(10)}")
    }

    private fun solve(length: Int): Int {
        val board = Board(length)

        for (line in input) {
            val (direction, steps) = line.split(" ")
            when (direction) {
                "R" -> board.move(1 to 0, steps.toInt())
                "L" -> board.move(-1 to 0, steps.toInt())
                "D" -> board.move(0 to -1, steps.toInt())
                "U" -> board.move(0 to 1, steps.toInt())
                else -> throw Exception("Unknown direction $direction")
            }
        }

        return board.numberOfPositions()
    }

    class Board(length: Int) {

        private var rope = Array(length) { 0 to 0 }
        private val visitedPositions = HashSet<Pair<Int, Int>>()

        private fun distanceBetween(tail: Pair<Int, Int>, head: Pair<Int, Int>) = maxOf(
            abs(head.first - tail.first),
            abs(head.second - tail.second)
        )

        fun numberOfPositions() = visitedPositions.size

        private fun followNode(tail: Pair<Int, Int>, head: Pair<Int, Int>): Pair<Int, Int> {

            if (distanceBetween(head, tail) != 2)
                return tail

            val newX = when {
                head.first - tail.first > 0 -> tail.first + 1
                head.first - tail.first < 0 -> tail.first - 1
                else -> tail.first
            }

            val newY = when {
                head.second - tail.second > 0 -> tail.second + 1
                head.second - tail.second < 0 -> tail.second - 1
                else -> tail.second
            }

            return newX to newY
        }

        fun move(direction: Pair<Int, Int>, steps: Int) {
            for (step in 1..steps) {
                rope[0] = rope[0].first + direction.first to rope[0].second + direction.second
                for (i in 1 until rope.size) {
                    rope[i] = followNode(rope[i], rope[i - 1])
                }
                visitedPositions.add(rope.last())
            }
        }

    }
}

Compiled from "DayNine.kt"
public final class asaad.DayNine {
  private final java.io.File file;

  private final java.util.List<java.lang.String> input;

  public asaad.DayNine(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #9                  // String filePath
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #18                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: new           #20                 // class java/io/File
      14: dup
      15: aload_1
      16: invokespecial #22                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      19: putfield      #26                 // Field file:Ljava/io/File;
      22: aload_0
      23: aload_0
      24: aload_0
      25: getfield      #26                 // Field file:Ljava/io/File;
      28: invokespecial #30                 // Method readInput:(Ljava/io/File;)Ljava/util/List;
      31: putfield      #34                 // Field input:Ljava/util/List;
      34: return

  private final java.util.List<java.lang.String> readInput(java.io.File);
    Code:
       0: aload_1
       1: astore_2
       2: getstatic     #44                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
       5: astore_3
       6: sipush        8192
       9: istore        4
      11: aload_2
      12: astore        5
      14: new           #46                 // class java/io/InputStreamReader
      17: dup
      18: new           #48                 // class java/io/FileInputStream
      21: dup
      22: aload         5
      24: invokespecial #51                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      27: checkcast     #53                 // class java/io/InputStream
      30: aload_3
      31: invokespecial #56                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      34: checkcast     #58                 // class java/io/Reader
      37: astore        5
      39: aload         5
      41: instanceof    #60                 // class java/io/BufferedReader
      44: ifeq          55
      47: aload         5
      49: checkcast     #60                 // class java/io/BufferedReader
      52: goto          66
      55: new           #60                 // class java/io/BufferedReader
      58: dup
      59: aload         5
      61: iload         4
      63: invokespecial #63                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      66: checkcast     #58                 // class java/io/Reader
      69: invokestatic  #69                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      72: areturn

  public final void result();
    Code:
       0: new           #74                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #75                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #77                 // String \tpart1:
       9: invokevirtual #81                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: iconst_2
      14: invokespecial #85                 // Method solve:(I)I
      17: invokevirtual #88                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      20: invokevirtual #92                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      23: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: new           #74                 // class java/lang/StringBuilder
      33: dup
      34: invokespecial #75                 // Method java/lang/StringBuilder."<init>":()V
      37: ldc           #106                // String \tpart2:
      39: invokevirtual #81                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: aload_0
      43: bipush        10
      45: invokespecial #85                 // Method solve:(I)I
      48: invokevirtual #88                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      51: invokevirtual #92                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      54: getstatic     #98                 // Field java/lang/System.out:Ljava/io/PrintStream;
      57: swap
      58: invokevirtual #104                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      61: return

  private final int solve(int);
    Code:
       0: new           #108                // class asaad/DayNine$Board
       3: dup
       4: iload_1
       5: invokespecial #111                // Method asaad/DayNine$Board."<init>":(I)V
       8: astore_2
       9: aload_0
      10: getfield      #34                 // Field input:Ljava/util/List;
      13: invokeinterface #117,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      18: astore_3
      19: aload_3
      20: invokeinterface #123,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          316
      28: aload_3
      29: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: checkcast     #129                // class java/lang/String
      37: astore        4
      39: aload         4
      41: checkcast     #131                // class java/lang/CharSequence
      44: iconst_1
      45: anewarray     #129                // class java/lang/String
      48: astore        6
      50: aload         6
      52: iconst_0
      53: ldc           #133                // String
      55: aastore
      56: aload         6
      58: iconst_0
      59: iconst_0
      60: bipush        6
      62: aconst_null
      63: invokestatic  #139                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      66: astore        5
      68: aload         5
      70: iconst_0
      71: invokeinterface #143,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      76: checkcast     #129                // class java/lang/String
      79: astore        6
      81: aload         5
      83: iconst_1
      84: invokeinterface #143,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      89: checkcast     #129                // class java/lang/String
      92: astore        7
      94: aload         6
      96: astore        8
      98: aload         8
     100: invokevirtual #147                // Method java/lang/String.hashCode:()I
     103: lookupswitch  { // 4
                    68: 157
                    76: 183
                    82: 144
                    85: 170
               default: 288
          }
     144: aload         8
     146: ldc           #149                // String R
     148: invokevirtual #153                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     151: ifne          196
     154: goto          288
     157: aload         8
     159: ldc           #155                // String D
     161: invokevirtual #153                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     164: ifne          242
     167: goto          288
     170: aload         8
     172: ldc           #157                // String U
     174: invokevirtual #153                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     177: ifne          265
     180: goto          288
     183: aload         8
     185: ldc           #159                // String L
     187: invokevirtual #153                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     190: ifne          219
     193: goto          288
     196: aload_2
     197: iconst_1
     198: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     201: iconst_0
     202: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     205: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     208: aload         7
     210: invokestatic  #175                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     213: invokevirtual #179                // Method asaad/DayNine$Board.move:(Lkotlin/Pair;I)V
     216: goto          19
     219: aload_2
     220: iconst_m1
     221: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     224: iconst_0
     225: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     228: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     231: aload         7
     233: invokestatic  #175                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     236: invokevirtual #179                // Method asaad/DayNine$Board.move:(Lkotlin/Pair;I)V
     239: goto          19
     242: aload_2
     243: iconst_0
     244: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     247: iconst_m1
     248: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     251: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     254: aload         7
     256: invokestatic  #175                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     259: invokevirtual #179                // Method asaad/DayNine$Board.move:(Lkotlin/Pair;I)V
     262: goto          19
     265: aload_2
     266: iconst_0
     267: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     270: iconst_1
     271: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     274: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     277: aload         7
     279: invokestatic  #175                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     282: invokevirtual #179                // Method asaad/DayNine$Board.move:(Lkotlin/Pair;I)V
     285: goto          19
     288: new           #181                // class java/lang/Exception
     291: dup
     292: new           #74                 // class java/lang/StringBuilder
     295: dup
     296: invokespecial #75                 // Method java/lang/StringBuilder."<init>":()V
     299: ldc           #183                // String Unknown direction
     301: invokevirtual #81                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     304: aload         6
     306: invokevirtual #81                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     309: invokevirtual #92                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     312: invokespecial #184                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     315: athrow
     316: aload_2
     317: invokevirtual #187                // Method asaad/DayNine$Board.numberOfPositions:()I
     320: ireturn
}

Compiled from "DayNine.kt"
public final class asaad.DayNine$Board {
  private kotlin.Pair<java.lang.Integer, java.lang.Integer>[] rope;

  private final java.util.HashSet<kotlin.Pair<java.lang.Integer, java.lang.Integer>> visitedPositions;

  public asaad.DayNine$Board(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iconst_0
       6: istore_2
       7: iload_1
       8: anewarray     #11                 // class kotlin/Pair
      11: astore_3
      12: astore        5
      14: iload_2
      15: iload_1
      16: if_icmpge     43
      19: iload_2
      20: istore        4
      22: aload_3
      23: iload         4
      25: iconst_0
      26: invokestatic  #17                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: iconst_0
      30: invokestatic  #17                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: invokestatic  #23                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      36: aastore
      37: iinc          2, 1
      40: goto          14
      43: aload         5
      45: aload_3
      46: putfield      #27                 // Field rope:[Lkotlin/Pair;
      49: aload_0
      50: new           #29                 // class java/util/HashSet
      53: dup
      54: invokespecial #30                 // Method java/util/HashSet."<init>":()V
      57: putfield      #34                 // Field visitedPositions:Ljava/util/HashSet;
      60: return

  private final int distanceBetween(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: nop
       1: aload_2
       2: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #48                 // class java/lang/Number
       8: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      11: aload_1
      12: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      15: checkcast     #48                 // class java/lang/Number
      18: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      21: isub
      22: invokestatic  #58                 // Method java/lang/Math.abs:(I)I
      25: aload_2
      26: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      29: checkcast     #48                 // class java/lang/Number
      32: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      35: aload_1
      36: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #48                 // class java/lang/Number
      42: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      45: isub
      46: invokestatic  #58                 // Method java/lang/Math.abs:(I)I
      49: invokestatic  #65                 // Method java/lang/Math.max:(II)I
      52: ireturn

  public final int numberOfPositions();
    Code:
       0: aload_0
       1: getfield      #34                 // Field visitedPositions:Ljava/util/HashSet;
       4: invokevirtual #72                 // Method java/util/HashSet.size:()I
       7: ireturn

  private final kotlin.Pair<java.lang.Integer, java.lang.Integer> followNode(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_2
       2: aload_1
       3: invokespecial #77                 // Method distanceBetween:(Lkotlin/Pair;Lkotlin/Pair;)I
       6: iconst_2
       7: if_icmpeq     12
      10: aload_1
      11: areturn
      12: nop
      13: aload_2
      14: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      17: checkcast     #48                 // class java/lang/Number
      20: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      23: aload_1
      24: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      27: checkcast     #48                 // class java/lang/Number
      30: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      33: isub
      34: ifle          52
      37: aload_1
      38: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      41: checkcast     #48                 // class java/lang/Number
      44: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      47: iconst_1
      48: iadd
      49: goto          101
      52: aload_2
      53: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      56: checkcast     #48                 // class java/lang/Number
      59: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      62: aload_1
      63: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      66: checkcast     #48                 // class java/lang/Number
      69: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      72: isub
      73: ifge          91
      76: aload_1
      77: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      80: checkcast     #48                 // class java/lang/Number
      83: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      86: iconst_1
      87: isub
      88: goto          101
      91: aload_1
      92: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      95: checkcast     #48                 // class java/lang/Number
      98: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     101: istore_3
     102: nop
     103: aload_2
     104: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     107: checkcast     #48                 // class java/lang/Number
     110: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     113: aload_1
     114: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     117: checkcast     #48                 // class java/lang/Number
     120: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     123: isub
     124: ifle          142
     127: aload_1
     128: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     131: checkcast     #48                 // class java/lang/Number
     134: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     137: iconst_1
     138: iadd
     139: goto          191
     142: aload_2
     143: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     146: checkcast     #48                 // class java/lang/Number
     149: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     152: aload_1
     153: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     156: checkcast     #48                 // class java/lang/Number
     159: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     162: isub
     163: ifge          181
     166: aload_1
     167: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     170: checkcast     #48                 // class java/lang/Number
     173: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     176: iconst_1
     177: isub
     178: goto          191
     181: aload_1
     182: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     185: checkcast     #48                 // class java/lang/Number
     188: invokevirtual #52                 // Method java/lang/Number.intValue:()I
     191: istore        4
     193: iload_3
     194: invokestatic  #17                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     197: iload         4
     199: invokestatic  #17                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     202: invokestatic  #23                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     205: areturn

  public final void move(kotlin.Pair<java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: aload_1
       1: ldc           #85                 // String direction
       3: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_1
       7: istore_3
       8: iload_3
       9: iload_2
      10: if_icmpgt     156
      13: aload_0
      14: getfield      #27                 // Field rope:[Lkotlin/Pair;
      17: iconst_0
      18: aload_0
      19: getfield      #27                 // Field rope:[Lkotlin/Pair;
      22: iconst_0
      23: aaload
      24: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      27: checkcast     #48                 // class java/lang/Number
      30: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      33: aload_1
      34: invokevirtual #46                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      37: checkcast     #48                 // class java/lang/Number
      40: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      43: iadd
      44: invokestatic  #17                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aload_0
      48: getfield      #27                 // Field rope:[Lkotlin/Pair;
      51: iconst_0
      52: aaload
      53: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      56: checkcast     #48                 // class java/lang/Number
      59: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      62: aload_1
      63: invokevirtual #61                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      66: checkcast     #48                 // class java/lang/Number
      69: invokevirtual #52                 // Method java/lang/Number.intValue:()I
      72: iadd
      73: invokestatic  #17                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      76: invokestatic  #23                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      79: aastore
      80: iconst_1
      81: istore        4
      83: aload_0
      84: getfield      #27                 // Field rope:[Lkotlin/Pair;
      87: arraylength
      88: istore        5
      90: iload         4
      92: iload         5
      94: if_icmpge     130
      97: aload_0
      98: getfield      #27                 // Field rope:[Lkotlin/Pair;
     101: iload         4
     103: aload_0
     104: aload_0
     105: getfield      #27                 // Field rope:[Lkotlin/Pair;
     108: iload         4
     110: aaload
     111: aload_0
     112: getfield      #27                 // Field rope:[Lkotlin/Pair;
     115: iload         4
     117: iconst_1
     118: isub
     119: aaload
     120: invokespecial #93                 // Method followNode:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
     123: aastore
     124: iinc          4, 1
     127: goto          90
     130: aload_0
     131: getfield      #34                 // Field visitedPositions:Ljava/util/HashSet;
     134: aload_0
     135: getfield      #27                 // Field rope:[Lkotlin/Pair;
     138: invokestatic  #99                 // Method kotlin/collections/ArraysKt.last:([Ljava/lang/Object;)Ljava/lang/Object;
     141: invokevirtual #103                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
     144: pop
     145: iload_3
     146: iload_2
     147: if_icmpeq     156
     150: iinc          3, 1
     153: goto          13
     156: return
}