// https://leetcode.com/problems/permutations-ii
fun permuteUnique(nums: IntArray): List<List<Int>> {
    nums.sort()
    return mutableListOf<List<Int>>().also {
        buildPermutations(nums, 0, it)
    }
}

private fun buildPermutations(nums: IntArray, startIndex: Int, permutations: MutableList<List<Int>>) {
    if (startIndex == nums.lastIndex) {
        permutations.add(nums.toList())
        return
    }
    val swapped = mutableSetOf<Int>()
    var index = startIndex
    while (index <= nums.lastIndex) {
        swapped.add(nums[index])
        nums.swap(startIndex, index)
        buildPermutations(nums = nums, startIndex = startIndex + 1, permutations = permutations)
        nums.swap(startIndex, index)
        index++
        while (nums.getOrNull(index) == nums[startIndex] || swapped.contains(nums.getOrNull(index))) index++
    }
}

private fun IntArray.swap(i: Int, j: Int) {
    if (i == j) return
    val temp = this[i]
    this[i] = this[j]
    this[j] = temp
}

Compiled from "_0047_PermutationsII.kt"
public final class _0047_PermutationsIIKt {
  public static final java.util.List<java.util.List<java.lang.Integer>> permuteUnique(int[]);
    Code:
       0: aload_0
       1: ldc           #10                 // String nums
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #22                 // Method kotlin/collections/ArraysKt.sort:([I)V
      10: new           #24                 // class java/util/ArrayList
      13: dup
      14: invokespecial #28                 // Method java/util/ArrayList."<init>":()V
      17: checkcast     #30                 // class java/util/List
      20: astore_1
      21: aload_1
      22: astore_2
      23: iconst_0
      24: istore_3
      25: aload_0
      26: iconst_0
      27: aload_2
      28: invokestatic  #34                 // Method buildPermutations:([IILjava/util/List;)V
      31: nop
      32: aload_1
      33: areturn

  private static final void buildPermutations(int[], int, java.util.List<java.util.List<java.lang.Integer>>);
    Code:
       0: iload_1
       1: aload_0
       2: invokestatic  #44                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
       5: if_icmpne     20
       8: aload_2
       9: aload_0
      10: invokestatic  #47                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
      13: invokeinterface #51,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      18: pop
      19: return
      20: new           #53                 // class java/util/LinkedHashSet
      23: dup
      24: invokespecial #54                 // Method java/util/LinkedHashSet."<init>":()V
      27: checkcast     #56                 // class java/util/Set
      30: astore_3
      31: iload_1
      32: istore        4
      34: iload         4
      36: aload_0
      37: invokestatic  #44                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      40: if_icmpgt     131
      43: aload_3
      44: aload_0
      45: iload         4
      47: iaload
      48: invokestatic  #62                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: invokeinterface #63,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      56: pop
      57: aload_0
      58: iload_1
      59: iload         4
      61: invokestatic  #67                 // Method swap:([III)V
      64: aload_0
      65: iload_1
      66: iconst_1
      67: iadd
      68: aload_2
      69: invokestatic  #34                 // Method buildPermutations:([IILjava/util/List;)V
      72: aload_0
      73: iload_1
      74: iload         4
      76: invokestatic  #67                 // Method swap:([III)V
      79: iinc          4, 1
      82: aload_0
      83: iload         4
      85: invokestatic  #71                 // Method kotlin/collections/ArraysKt.getOrNull:([II)Ljava/lang/Integer;
      88: aload_0
      89: iload_1
      90: iaload
      91: istore        5
      93: dup
      94: ifnonnull     101
      97: pop
      98: goto          109
     101: invokevirtual #75                 // Method java/lang/Integer.intValue:()I
     104: iload         5
     106: if_icmpeq     125
     109: aload_3
     110: checkcast     #77                 // class java/lang/Iterable
     113: aload_0
     114: iload         4
     116: invokestatic  #71                 // Method kotlin/collections/ArraysKt.getOrNull:([II)Ljava/lang/Integer;
     119: invokestatic  #83                 // Method kotlin/collections/CollectionsKt.contains:(Ljava/lang/Iterable;Ljava/lang/Object;)Z
     122: ifeq          34
     125: iinc          4, 1
     128: goto          82
     131: return

  private static final void swap(int[], int, int);
    Code:
       0: iload_1
       1: iload_2
       2: if_icmpne     6
       5: return
       6: aload_0
       7: iload_1
       8: iaload
       9: istore_3
      10: aload_0
      11: iload_1
      12: aload_0
      13: iload_2
      14: iaload
      15: iastore
      16: aload_0
      17: iload_2
      18: iload_3
      19: iastore
      20: return
}


// https://leetcode.com/problems/permutations
fun permute(nums: IntArray): List<List<Int>> {
    return mutableListOf<List<Int>>().also {
        buildPermutations(
            nums = nums,
            usedNums = BooleanArray(nums.size),
            permutation = mutableListOf(),
            permutations = it
        )
    }
}

private fun buildPermutations(
    nums: IntArray,
    usedNums: BooleanArray,
    permutation: MutableList<Int>,
    permutations: MutableList<List<Int>>
) {
    if (permutation.size == nums.size) {
        permutations.add(permutation.toList())
        return
    }
    for ((index, num) in nums.withIndex()) {
        if (usedNums[index]) continue
        usedNums[index] = true
        permutation.add(num)
        buildPermutations(nums = nums, usedNums = usedNums, permutation = permutation, permutations = permutations)
        permutation.remove(num)
        usedNums[index] = false
    }
}

Compiled from "_0046_Permutations.kt"
public final class _0046_PermutationsKt {
  public static final java.util.List<java.util.List<java.lang.Integer>> permute(int[]);
    Code:
       0: aload_0
       1: ldc           #10                 // String nums
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/ArrayList
       9: dup
      10: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #24                 // class java/util/List
      16: astore_1
      17: aload_1
      18: astore_2
      19: iconst_0
      20: istore_3
      21: aload_0
      22: aload_0
      23: arraylength
      24: newarray       boolean
      26: new           #18                 // class java/util/ArrayList
      29: dup
      30: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      33: checkcast     #24                 // class java/util/List
      36: aload_2
      37: invokestatic  #28                 // Method buildPermutations:([I[ZLjava/util/List;Ljava/util/List;)V
      40: nop
      41: aload_1
      42: areturn

  private static final void buildPermutations(int[], boolean[], java.util.List<java.lang.Integer>, java.util.List<java.util.List<java.lang.Integer>>);
    Code:
       0: aload_2
       1: invokeinterface #38,  1           // InterfaceMethod java/util/List.size:()I
       6: aload_0
       7: arraylength
       8: if_icmpne     26
      11: aload_3
      12: aload_2
      13: checkcast     #40                 // class java/lang/Iterable
      16: invokestatic  #46                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      19: invokeinterface #50,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      24: pop
      25: return
      26: iconst_0
      27: istore        4
      29: aload_0
      30: arraylength
      31: istore        5
      33: iload         4
      35: iload         5
      37: if_icmpge     104
      40: iload         4
      42: istore        6
      44: aload_0
      45: iload         4
      47: iaload
      48: istore        7
      50: aload_1
      51: iload         6
      53: baload
      54: ifne          98
      57: aload_1
      58: iload         6
      60: iconst_1
      61: bastore
      62: aload_2
      63: iload         7
      65: invokestatic  #56                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      68: invokeinterface #50,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      73: pop
      74: aload_0
      75: aload_1
      76: aload_2
      77: aload_3
      78: invokestatic  #28                 // Method buildPermutations:([I[ZLjava/util/List;Ljava/util/List;)V
      81: aload_2
      82: iload         7
      84: invokestatic  #56                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      87: invokeinterface #59,  2           // InterfaceMethod java/util/List.remove:(Ljava/lang/Object;)Z
      92: pop
      93: aload_1
      94: iload         6
      96: iconst_0
      97: bastore
      98: iinc          4, 1
     101: goto          33
     104: return
}


// 2. Check words with jumbled letters :
// Our brain can read texts even if letters are jumbled, like the following sentence: “Yuo
// cna porbalby raed tihs esaliy desptie teh msispeillgns.” Given two strings, write a
// method to decide if one is a partialpermutation of the other. Consider a
// partialpermutation only if:
// The first letter hasn’t changed place
// If word has more than 3 letters, up to 2/3 of the letters have changed place
// Examples:
// you, yuo > true
// probably, porbalby > true
// despite, desptie > true
// moon, nmoo > false
// misspellings, mpeissngslli > false

fun main(args: Array<String>) {

    println(partialPermutation("you", "yuo"))
    println(partialPermutation("probably", "porbalby"))
    println(partialPermutation("despite", "desptie"))
    println(partialPermutation("moon", "nmoo"))
    println(partialPermutation("misspellings", "mpeissngslli"))
}

fun partialPermutation(source: String, dest: String): Boolean{
    // The first letter hasn’t changed place
    if(source[0] != dest[0]){
        return false
    }

    // If the size of the arrays are different
    if(source.length != dest.length){
        return false
    }

    var jumbled = 0
    for ((index, value) in source.withIndex()){

        val indexDest = dest.indexOf(value)

        if ( indexDest != index ){
            jumbled ++
        }

        // If the character does not exist
        if ( indexDest == -1 ){
            return false
        }
    }

    // If word has more than 3 letters, up to 2/3 of the letters have changed place
    val len = source.length
    if (len > 3){
        if(jumbled > (len * 2/3)){
            return false
        }else{
            return true
        }
    } else {
        return jumbled > 0
    }
}

Compiled from "question2.kt"
public final class Question2Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String you
       8: ldc           #19                 // String yuo
      10: invokestatic  #23                 // Method partialPermutation:(Ljava/lang/String;Ljava/lang/String;)Z
      13: istore_1
      14: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      17: iload_1
      18: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      21: ldc           #37                 // String probably
      23: ldc           #39                 // String porbalby
      25: invokestatic  #23                 // Method partialPermutation:(Ljava/lang/String;Ljava/lang/String;)Z
      28: istore_1
      29: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: iload_1
      33: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      36: ldc           #41                 // String despite
      38: ldc           #43                 // String desptie
      40: invokestatic  #23                 // Method partialPermutation:(Ljava/lang/String;Ljava/lang/String;)Z
      43: istore_1
      44: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      47: iload_1
      48: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      51: ldc           #45                 // String moon
      53: ldc           #47                 // String nmoo
      55: invokestatic  #23                 // Method partialPermutation:(Ljava/lang/String;Ljava/lang/String;)Z
      58: istore_1
      59: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: iload_1
      63: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      66: ldc           #49                 // String misspellings
      68: ldc           #51                 // String mpeissngslli
      70: invokestatic  #23                 // Method partialPermutation:(Ljava/lang/String;Ljava/lang/String;)Z
      73: istore_1
      74: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: iload_1
      78: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      81: return

  public static final boolean partialPermutation(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #54                 // String source
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #56                 // String dest
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_0
      14: invokevirtual #62                 // Method java/lang/String.charAt:(I)C
      17: aload_1
      18: iconst_0
      19: invokevirtual #62                 // Method java/lang/String.charAt:(I)C
      22: if_icmpeq     27
      25: iconst_0
      26: ireturn
      27: aload_0
      28: invokevirtual #66                 // Method java/lang/String.length:()I
      31: aload_1
      32: invokevirtual #66                 // Method java/lang/String.length:()I
      35: if_icmpeq     40
      38: iconst_0
      39: ireturn
      40: iconst_0
      41: istore_2
      42: iconst_0
      43: istore_3
      44: aload_0
      45: invokevirtual #66                 // Method java/lang/String.length:()I
      48: istore        4
      50: iload_3
      51: iload         4
      53: if_icmpge     106
      56: iload_3
      57: istore        5
      59: aload_0
      60: iload_3
      61: invokevirtual #62                 // Method java/lang/String.charAt:(I)C
      64: istore        6
      66: aload_1
      67: checkcast     #68                 // class java/lang/CharSequence
      70: iload         6
      72: iconst_0
      73: iconst_0
      74: bipush        6
      76: aconst_null
      77: invokestatic  #74                 // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;CIZILjava/lang/Object;)I
      80: istore        7
      82: iload         7
      84: iload         5
      86: if_icmpeq     92
      89: iinc          2, 1
      92: iload         7
      94: iconst_m1
      95: if_icmpne     100
      98: iconst_0
      99: ireturn
     100: iinc          3, 1
     103: goto          50
     106: aload_0
     107: invokevirtual #66                 // Method java/lang/String.length:()I
     110: istore_3
     111: iload_3
     112: iconst_3
     113: if_icmple     129
     116: iload_2
     117: iload_3
     118: iconst_2
     119: imul
     120: iconst_3
     121: idiv
     122: if_icmple     127
     125: iconst_0
     126: ireturn
     127: iconst_1
     128: ireturn
     129: iload_2
     130: ifle          137
     133: iconst_1
     134: goto          138
     137: iconst_0
     138: ireturn
}


// 3. Check words with typos:
// There are three types of typos that can be performed on strings: insert a character,
// remove a character, or replace a character. Given two strings, write a function to
// check if they are one typo (or zero typos) away.
// Examples:
// pale, ple > true
// pales, pale > true
// pale, bale > true
// pale, bake > false

// https://www.cuelogic.com/blog/the-levenshtein-algorithm
fun main(args: Array<String>) {

    println(checkTypos("pale", "ple")) //true
    println(checkTypos("pales", "pale")) //true
    println(checkTypos("pale", "bale")) //true
    println(checkTypos("pale", "bake")) //false
    println(checkTypos("HONDA", "HYUNDAI")) //false

}

fun checkTypos(s: String, t: String): Boolean {
    // degenerate cases
    if (s == t)  return true
    if (s == "") return false
    if (t == "") return false

    // create two integer arrays of distances and initialize the first one
    val v0 = IntArray(t.length + 1) { it }  // previous
    val v1 = IntArray(t.length + 1)         // current

    var cost: Int
    for (i in 0 until s.length) {
        // calculate v1 from v0
        v1[0] = i + 1
        for (j in 0 until t.length) {
            cost = if (s[i] == t[j]) 0 else 1
            v1[j + 1] = Math.min(v1[j] + 1, Math.min(v0[j + 1] + 1, v0[j] + cost))
        }
        // copy v1 to v0 for next iteration
        for (j in 0 .. t.length) v0[j] = v1[j]
    }

    if(v1[t.length]>1){
        return false
    }else{
        return true
    }
}

Compiled from "question3.kt"
public final class Question3Kt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #17                 // String pale
       8: ldc           #19                 // String ple
      10: invokestatic  #23                 // Method checkTypos:(Ljava/lang/String;Ljava/lang/String;)Z
      13: istore_1
      14: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      17: iload_1
      18: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      21: ldc           #37                 // String pales
      23: ldc           #17                 // String pale
      25: invokestatic  #23                 // Method checkTypos:(Ljava/lang/String;Ljava/lang/String;)Z
      28: istore_1
      29: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      32: iload_1
      33: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      36: ldc           #17                 // String pale
      38: ldc           #39                 // String bale
      40: invokestatic  #23                 // Method checkTypos:(Ljava/lang/String;Ljava/lang/String;)Z
      43: istore_1
      44: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      47: iload_1
      48: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      51: ldc           #17                 // String pale
      53: ldc           #41                 // String bake
      55: invokestatic  #23                 // Method checkTypos:(Ljava/lang/String;Ljava/lang/String;)Z
      58: istore_1
      59: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: iload_1
      63: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      66: ldc           #43                 // String HONDA
      68: ldc           #45                 // String HYUNDAI
      70: invokestatic  #23                 // Method checkTypos:(Ljava/lang/String;Ljava/lang/String;)Z
      73: istore_1
      74: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: iload_1
      78: invokevirtual #35                 // Method java/io/PrintStream.println:(Z)V
      81: return

  public static final boolean checkTypos(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #48                 // String s
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #50                 // String t
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      17: ifeq          22
      20: iconst_1
      21: ireturn
      22: aload_0
      23: ldc           #56                 // String
      25: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      28: ifeq          33
      31: iconst_0
      32: ireturn
      33: aload_1
      34: ldc           #56                 // String
      36: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      39: ifeq          44
      42: iconst_0
      43: ireturn
      44: iconst_0
      45: istore_3
      46: aload_1
      47: invokevirtual #62                 // Method java/lang/String.length:()I
      50: iconst_1
      51: iadd
      52: istore        4
      54: iload         4
      56: newarray       int
      58: astore        5
      60: iload_3
      61: iload         4
      63: if_icmpge     82
      66: iload_3
      67: istore        6
      69: aload         5
      71: iload         6
      73: iload         6
      75: iastore
      76: iinc          3, 1
      79: goto          60
      82: aload         5
      84: astore_2
      85: aload_1
      86: invokevirtual #62                 // Method java/lang/String.length:()I
      89: iconst_1
      90: iadd
      91: newarray       int
      93: astore_3
      94: iconst_0
      95: istore        4
      97: iconst_0
      98: istore        5
     100: aload_0
     101: invokevirtual #62                 // Method java/lang/String.length:()I
     104: istore        6
     106: iload         5
     108: iload         6
     110: if_icmpge     240
     113: aload_3
     114: iconst_0
     115: iload         5
     117: iconst_1
     118: iadd
     119: iastore
     120: iconst_0
     121: istore        7
     123: aload_1
     124: invokevirtual #62                 // Method java/lang/String.length:()I
     127: istore        8
     129: iload         7
     131: iload         8
     133: if_icmpge     197
     136: aload_0
     137: iload         5
     139: invokevirtual #66                 // Method java/lang/String.charAt:(I)C
     142: aload_1
     143: iload         7
     145: invokevirtual #66                 // Method java/lang/String.charAt:(I)C
     148: if_icmpne     155
     151: iconst_0
     152: goto          156
     155: iconst_1
     156: istore        4
     158: aload_3
     159: iload         7
     161: iconst_1
     162: iadd
     163: aload_3
     164: iload         7
     166: iaload
     167: iconst_1
     168: iadd
     169: aload_2
     170: iload         7
     172: iconst_1
     173: iadd
     174: iaload
     175: iconst_1
     176: iadd
     177: aload_2
     178: iload         7
     180: iaload
     181: iload         4
     183: iadd
     184: invokestatic  #72                 // Method java/lang/Math.min:(II)I
     187: invokestatic  #72                 // Method java/lang/Math.min:(II)I
     190: iastore
     191: iinc          7, 1
     194: goto          129
     197: iconst_0
     198: istore        7
     200: aload_1
     201: invokevirtual #62                 // Method java/lang/String.length:()I
     204: istore        8
     206: iload         7
     208: iload         8
     210: if_icmpgt     234
     213: aload_2
     214: iload         7
     216: aload_3
     217: iload         7
     219: iaload
     220: iastore
     221: iload         7
     223: iload         8
     225: if_icmpeq     234
     228: iinc          7, 1
     231: goto          213
     234: iinc          5, 1
     237: goto          106
     240: aload_3
     241: aload_1
     242: invokevirtual #62                 // Method java/lang/String.length:()I
     245: iaload
     246: iconst_1
     247: if_icmple     252
     250: iconst_0
     251: ireturn
     252: iconst_1
     253: ireturn
}


val di = listOf(-1, 0, 1, 0);
val dj = listOf(0, 1, 0, -1);

val dirMap: Map<String, Int> = mapOf("U" to 0, "R" to 1, "D" to 2, "L" to 3);

fun dist(a: Pair<Int, Int>, b: Pair<Int, Int>): Int {
    return Math.max(Math.abs(a.first - b.first), Math.abs(a.second - b.second));
}

fun dist2(a: Pair<Int, Int>, b: Pair<Int, Int>): Int {
    return Math.abs(a.first - b.first) + Math.abs(a.second - b.second);
}

fun newPos(oldPos: Pair<Int, Int>, leader: Pair<Int, Int>, dir: Int): Pair<Int, Int> {
    if (dist(oldPos, leader) <= 1) {
        return oldPos;
    }

    if (dir != -1) {
        val candidate = Pair(oldPos.first + di[dir], oldPos.second + dj[dir]);
        if (dist2(leader, candidate) == 1) {
            return candidate;
        }
    }

    var best = oldPos;
    for(dii in -1..1) {
        for(djj in -1..1) {
            val candidate = Pair(oldPos.first + dii, oldPos.second + djj);
            if (dist2(leader, candidate) == 1) {
                best = candidate;
            }
        }
    }
    if (dist2(leader, best) == 1) return best;

    for(dii in -1..1) {
        for(djj in -1..1) {
            val candidate = Pair(oldPos.first + dii, oldPos.second + djj);
            if (dist(leader, candidate) == 1) {
                best = candidate;
            }
        }
    }
    return best;
}

fun main() {
    val input = ""
    val st: MutableSet<Pair<Int, Int>> = mutableSetOf(Pair(0, 0));
    var snake: MutableList<Pair<Int, Int>> = mutableListOf();
    val knots = 10;
    for(i in 1..knots) {
        snake.add(Pair(0, 0));
    }

    for(s in input.split("\n")) {
        val dir = dirMap[s.split(" ")[0]]!!;
        val num = Integer.parseInt(s.split(" ")[1]);
        for(k in 1..num) {
	        val newSnake: MutableList<Pair<Int, Int>> = mutableListOf();
            newSnake.add(Pair(snake[0].first + di[dir], snake[0].second + dj[dir]));
            for(knot in 1 until knots) {
                newSnake.add(newPos(snake[knot], newSnake[knot - 1], dir));
            }
			st.add(newSnake[knots - 1]);
            snake = newSnake;
            //println(snake);
        }
    }
    println(st.size);
}

Compiled from "day9.kt"
public final class Day9Kt {
  private static final java.util.List<java.lang.Integer> di;

  private static final java.util.List<java.lang.Integer> dj;

  private static final java.util.Map<java.lang.String, java.lang.Integer> dirMap;

  public static final java.util.List<java.lang.Integer> getDi();
    Code:
       0: getstatic     #12                 // Field di:Ljava/util/List;
       3: areturn

  public static final java.util.List<java.lang.Integer> getDj();
    Code:
       0: getstatic     #16                 // Field dj:Ljava/util/List;
       3: areturn

  public static final java.util.Map<java.lang.String, java.lang.Integer> getDirMap();
    Code:
       0: getstatic     #23                 // Field dirMap:Ljava/util/Map;
       3: areturn

  public static final int dist(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #28                 // String a
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #36                 // String b
       9: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #44                 // class java/lang/Number
      19: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      22: aload_1
      23: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: checkcast     #44                 // class java/lang/Number
      29: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      32: isub
      33: invokestatic  #54                 // Method java/lang/Math.abs:(I)I
      36: aload_0
      37: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      40: checkcast     #44                 // class java/lang/Number
      43: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      46: aload_1
      47: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      50: checkcast     #44                 // class java/lang/Number
      53: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      56: isub
      57: invokestatic  #54                 // Method java/lang/Math.abs:(I)I
      60: invokestatic  #61                 // Method java/lang/Math.max:(II)I
      63: ireturn

  public static final int dist2(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #28                 // String a
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #36                 // String b
       9: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #44                 // class java/lang/Number
      19: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      22: aload_1
      23: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: checkcast     #44                 // class java/lang/Number
      29: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      32: isub
      33: invokestatic  #54                 // Method java/lang/Math.abs:(I)I
      36: aload_0
      37: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      40: checkcast     #44                 // class java/lang/Number
      43: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      46: aload_1
      47: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      50: checkcast     #44                 // class java/lang/Number
      53: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      56: isub
      57: invokestatic  #54                 // Method java/lang/Math.abs:(I)I
      60: iadd
      61: ireturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> newPos(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: aload_0
       1: ldc           #68                 // String oldPos
       3: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #70                 // String leader
       9: invokestatic  #34                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #72                 // Method dist:(Lkotlin/Pair;Lkotlin/Pair;)I
      17: iconst_1
      18: if_icmpgt     23
      21: aload_0
      22: areturn
      23: iload_2
      24: iconst_m1
      25: if_icmpeq     105
      28: new           #38                 // class kotlin/Pair
      31: dup
      32: aload_0
      33: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      36: checkcast     #44                 // class java/lang/Number
      39: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      42: getstatic     #12                 // Field di:Ljava/util/List;
      45: iload_2
      46: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      51: checkcast     #44                 // class java/lang/Number
      54: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      57: iadd
      58: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      61: aload_0
      62: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      65: checkcast     #44                 // class java/lang/Number
      68: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      71: getstatic     #16                 // Field dj:Ljava/util/List;
      74: iload_2
      75: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      80: checkcast     #44                 // class java/lang/Number
      83: invokevirtual #48                 // Method java/lang/Number.intValue:()I
      86: iadd
      87: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      93: astore_3
      94: aload_1
      95: aload_3
      96: invokestatic  #90                 // Method dist2:(Lkotlin/Pair;Lkotlin/Pair;)I
      99: iconst_1
     100: if_icmpne     105
     103: aload_3
     104: areturn
     105: aload_0
     106: astore_3
     107: iconst_m1
     108: istore        4
     110: iload         4
     112: iconst_2
     113: if_icmpge     191
     116: iconst_m1
     117: istore        5
     119: iload         5
     121: iconst_2
     122: if_icmpge     185
     125: new           #38                 // class kotlin/Pair
     128: dup
     129: aload_0
     130: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     133: checkcast     #44                 // class java/lang/Number
     136: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     139: iload         4
     141: iadd
     142: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     145: aload_0
     146: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     149: checkcast     #44                 // class java/lang/Number
     152: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     155: iload         5
     157: iadd
     158: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     161: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     164: astore        6
     166: aload_1
     167: aload         6
     169: invokestatic  #90                 // Method dist2:(Lkotlin/Pair;Lkotlin/Pair;)I
     172: iconst_1
     173: if_icmpne     179
     176: aload         6
     178: astore_3
     179: iinc          5, 1
     182: goto          119
     185: iinc          4, 1
     188: goto          110
     191: aload_1
     192: aload_3
     193: invokestatic  #90                 // Method dist2:(Lkotlin/Pair;Lkotlin/Pair;)I
     196: iconst_1
     197: if_icmpne     202
     200: aload_3
     201: areturn
     202: iconst_m1
     203: istore        4
     205: iload         4
     207: iconst_2
     208: if_icmpge     286
     211: iconst_m1
     212: istore        5
     214: iload         5
     216: iconst_2
     217: if_icmpge     280
     220: new           #38                 // class kotlin/Pair
     223: dup
     224: aload_0
     225: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     228: checkcast     #44                 // class java/lang/Number
     231: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     234: iload         4
     236: iadd
     237: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     240: aload_0
     241: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     244: checkcast     #44                 // class java/lang/Number
     247: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     250: iload         5
     252: iadd
     253: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     256: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     259: astore        6
     261: aload_1
     262: aload         6
     264: invokestatic  #72                 // Method dist:(Lkotlin/Pair;Lkotlin/Pair;)I
     267: iconst_1
     268: if_icmpne     274
     271: aload         6
     273: astore_3
     274: iinc          5, 1
     277: goto          214
     280: iinc          4, 1
     283: goto          205
     286: aload_3
     287: areturn

  public static final void main();
    Code:
       0: ldc           #100                // String
       2: astore_0
       3: iconst_1
       4: anewarray     #38                 // class kotlin/Pair
       7: astore_2
       8: aload_2
       9: iconst_0
      10: new           #38                 // class kotlin/Pair
      13: dup
      14: iconst_0
      15: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: iconst_0
      19: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      22: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      25: aastore
      26: aload_2
      27: invokestatic  #106                // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
      30: astore_1
      31: new           #108                // class java/util/ArrayList
      34: dup
      35: invokespecial #110                // Method java/util/ArrayList."<init>":()V
      38: checkcast     #74                 // class java/util/List
      41: astore_2
      42: bipush        10
      44: istore_3
      45: iconst_1
      46: istore        4
      48: aload_2
      49: new           #38                 // class kotlin/Pair
      52: dup
      53: iconst_0
      54: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      57: iconst_0
      58: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      61: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      64: invokeinterface #114,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      69: pop
      70: iload         4
      72: iload_3
      73: if_icmpeq     82
      76: iinc          4, 1
      79: goto          48
      82: aload_0
      83: checkcast     #116                // class java/lang/CharSequence
      86: iconst_1
      87: anewarray     #118                // class java/lang/String
      90: astore        5
      92: aload         5
      94: iconst_0
      95: ldc           #120                // String \n
      97: aastore
      98: aload         5
     100: iconst_0
     101: iconst_0
     102: bipush        6
     104: aconst_null
     105: invokestatic  #126                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     108: invokeinterface #130,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     113: astore        4
     115: aload         4
     117: invokeinterface #136,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     122: ifeq          432
     125: aload         4
     127: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     132: checkcast     #118                // class java/lang/String
     135: astore        5
     137: getstatic     #23                 // Field dirMap:Ljava/util/Map;
     140: aload         5
     142: checkcast     #116                // class java/lang/CharSequence
     145: iconst_1
     146: anewarray     #118                // class java/lang/String
     149: astore        7
     151: aload         7
     153: iconst_0
     154: ldc           #141                // String
     156: aastore
     157: aload         7
     159: iconst_0
     160: iconst_0
     161: bipush        6
     163: aconst_null
     164: invokestatic  #126                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     167: iconst_0
     168: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     173: invokeinterface #146,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     178: dup
     179: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     182: checkcast     #44                 // class java/lang/Number
     185: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     188: istore        6
     190: aload         5
     192: checkcast     #116                // class java/lang/CharSequence
     195: iconst_1
     196: anewarray     #118                // class java/lang/String
     199: astore        8
     201: aload         8
     203: iconst_0
     204: ldc           #141                // String
     206: aastore
     207: aload         8
     209: iconst_0
     210: iconst_0
     211: bipush        6
     213: aconst_null
     214: invokestatic  #126                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     217: iconst_1
     218: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     223: checkcast     #118                // class java/lang/String
     226: invokestatic  #154                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     229: istore        7
     231: iconst_1
     232: istore        8
     234: iload         8
     236: iload         7
     238: if_icmpgt     115
     241: new           #108                // class java/util/ArrayList
     244: dup
     245: invokespecial #110                // Method java/util/ArrayList."<init>":()V
     248: checkcast     #74                 // class java/util/List
     251: astore        9
     253: aload         9
     255: new           #38                 // class kotlin/Pair
     258: dup
     259: aload_2
     260: iconst_0
     261: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     266: checkcast     #38                 // class kotlin/Pair
     269: invokevirtual #42                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     272: checkcast     #44                 // class java/lang/Number
     275: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     278: getstatic     #12                 // Field di:Ljava/util/List;
     281: iload         6
     283: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     288: checkcast     #44                 // class java/lang/Number
     291: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     294: iadd
     295: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     298: aload_2
     299: iconst_0
     300: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     305: checkcast     #38                 // class kotlin/Pair
     308: invokevirtual #57                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     311: checkcast     #44                 // class java/lang/Number
     314: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     317: getstatic     #16                 // Field dj:Ljava/util/List;
     320: iload         6
     322: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     327: checkcast     #44                 // class java/lang/Number
     330: invokevirtual #48                 // Method java/lang/Number.intValue:()I
     333: iadd
     334: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     337: invokespecial #88                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     340: invokeinterface #114,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     345: pop
     346: iconst_1
     347: istore        10
     349: iload         10
     351: iload_3
     352: if_icmpge     399
     355: aload         9
     357: aload_2
     358: iload         10
     360: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     365: checkcast     #38                 // class kotlin/Pair
     368: aload         9
     370: iload         10
     372: iconst_1
     373: isub
     374: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     379: checkcast     #38                 // class kotlin/Pair
     382: iload         6
     384: invokestatic  #156                // Method newPos:(Lkotlin/Pair;Lkotlin/Pair;I)Lkotlin/Pair;
     387: invokeinterface #114,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     392: pop
     393: iinc          10, 1
     396: goto          349
     399: aload_1
     400: aload         9
     402: iload_3
     403: iconst_1
     404: isub
     405: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     410: invokeinterface #159,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     415: pop
     416: aload         9
     418: astore_2
     419: iload         8
     421: iload         7
     423: if_icmpeq     115
     426: iinc          8, 1
     429: goto          241
     432: aload_1
     433: invokeinterface #162,  1          // InterfaceMethod java/util/Set.size:()I
     438: istore        4
     440: getstatic     #168                // Field java/lang/System.out:Ljava/io/PrintStream;
     443: iload         4
     445: invokevirtual #174                // Method java/io/PrintStream.println:(I)V
     448: return

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

  static {};
    Code:
       0: iconst_4
       1: anewarray     #80                 // class java/lang/Integer
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_m1
       8: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      11: aastore
      12: aload_0
      13: iconst_1
      14: iconst_0
      15: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: aastore
      19: aload_0
      20: iconst_2
      21: iconst_1
      22: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: aastore
      26: aload_0
      27: iconst_3
      28: iconst_0
      29: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: aastore
      33: aload_0
      34: invokestatic  #198                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      37: putstatic     #12                 // Field di:Ljava/util/List;
      40: iconst_4
      41: anewarray     #80                 // class java/lang/Integer
      44: astore_0
      45: aload_0
      46: iconst_0
      47: iconst_0
      48: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: aastore
      52: aload_0
      53: iconst_1
      54: iconst_1
      55: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: aastore
      59: aload_0
      60: iconst_2
      61: iconst_0
      62: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      65: aastore
      66: aload_0
      67: iconst_3
      68: iconst_m1
      69: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: aastore
      73: aload_0
      74: invokestatic  #198                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      77: putstatic     #16                 // Field dj:Ljava/util/List;
      80: iconst_4
      81: anewarray     #38                 // class kotlin/Pair
      84: astore_0
      85: aload_0
      86: iconst_0
      87: ldc           #200                // String U
      89: iconst_0
      90: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: invokestatic  #206                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      96: aastore
      97: aload_0
      98: iconst_1
      99: ldc           #208                // String R
     101: iconst_1
     102: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: invokestatic  #206                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     108: aastore
     109: aload_0
     110: iconst_2
     111: ldc           #210                // String D
     113: iconst_2
     114: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     117: invokestatic  #206                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     120: aastore
     121: aload_0
     122: iconst_3
     123: ldc           #212                // String L
     125: iconst_3
     126: invokestatic  #84                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     129: invokestatic  #206                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     132: aastore
     133: aload_0
     134: invokestatic  #218                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     137: putstatic     #23                 // Field dirMap:Ljava/util/Map;
     140: return
}


import kotlin.math.max

fun main() {
    data class State(
        val oreRobots: Int, val clayRobots: Int, val obsidianRobots: Int, val geodeRobots: Int,
        val clay: Int, val obsidian: Int, val geode: Int
    ) {
        fun next(): State {
            return State(
                oreRobots, clayRobots, obsidianRobots, geodeRobots,
                clay + clayRobots, obsidian + obsidianRobots, geode + geodeRobots
            )
        }
    }
    fun solve(time: Int, oreOreCost: Int, clayOreCost: Int, obsidianOreCost: Int, obsidianClayCost: Int, geodeOreCost: Int, geodeObsidianCost: Int): Int {
        val best = Array(time + 1) { mutableMapOf<State, Int>() }
        best[0][State(1, 0, 0, 0, 0, 0, 0)] = 0
        var ret = 0

        fun put(t: Int, state: State, value: Int) {
            if (!best[t + 1].contains(state) || best[t + 1].getValue(state) < value) {
                best[t + 1][state] = value
            }
        }

        for(t in 0 until time) {
            for(entry in best[t]) {
                val state = entry.key
                ret = max(ret, state.next().geode)
                if (t == time - 1) continue;

                // don't build anything
                put(t, state.next(), entry.value + state.oreRobots);
                // build ore robot
                if (entry.value >= oreOreCost) {
                    val newState = state.next().copy(oreRobots = state.oreRobots + 1)
                    val newOre = entry.value - oreOreCost + state.oreRobots
                    put(t, newState, newOre)
                }
                // build clay robot
                if (entry.value >= clayOreCost) {
                    val newState = state.next().copy(clayRobots = state.clayRobots + 1)
                    val newOre = entry.value - clayOreCost + state.oreRobots
                    put(t, newState, newOre)
                }
                // build obsidian robot
                if (entry.value >= obsidianOreCost && state.clay >= obsidianClayCost) {
                    val newState = state.next().copy(obsidianRobots = state.obsidianRobots + 1, clay = state.clay - obsidianClayCost + state.clayRobots)
                    val newOre = entry.value - obsidianOreCost + state.oreRobots
                    put(t, newState, newOre)
                }
                // build geode robot
                if (entry.value >= geodeOreCost && state.obsidian >= geodeObsidianCost) {
                    val newState = state.next().copy(geodeRobots = state.geodeRobots + 1, obsidian = state.obsidian - geodeObsidianCost + state.obsidianRobots)
                    val newOre = entry.value - geodeOreCost + state.oreRobots
                    put(t, newState, newOre)
                }
            }
        }
        return ret
    }

//    val test = """Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 2 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 2 ore and 7 obsidian.
//Blueprint 2: Each ore robot costs 2 ore. Each clay robot costs 3 ore. Each obsidian robot costs 3 ore and 8 clay. Each geode robot costs 3 ore and 12 obsidian."""
    val test = """Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 4 ore and 16 obsidian.
Blueprint 2: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 4 ore and 8 obsidian.
Blueprint 3: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 18 clay. Each geode robot costs 4 ore and 16 obsidian."""
    val regex = Regex("Blueprint ([0-9]+): Each ore robot costs ([0-9]+) ore. Each clay robot costs ([0-9]+) ore. Each obsidian robot costs ([0-9]+) ore and ([0-9]+) clay. Each geode robot costs ([0-9]+) ore and ([0-9]+) obsidian.")
    var ans = 0;
    for(s in test.split("\n")) {
        val list = regex.find(s)!!.groupValues
        println("Test " + list[1])
        val geodes = solve(
            32,
            Integer.parseInt(list[2]),
            Integer.parseInt(list[3]),
            Integer.parseInt(list[4]),
            Integer.parseInt(list[5]),
            Integer.parseInt(list[6]),
            Integer.parseInt(list[7]),
        )
        println(geodes)
        ans += Integer.parseInt(list[1]) * geodes
    }
    println(ans)
}

Compiled from "day19.kt"
public final class Day19Kt$main$State {
  private final int oreRobots;

  private final int clayRobots;

  private final int obsidianRobots;

  private final int geodeRobots;

  private final int clay;

  private final int obsidian;

  private final int geode;

  public Day19Kt$main$State(int, int, int, int, int, int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field oreRobots:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field clayRobots:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field obsidianRobots:I
      19: aload_0
      20: iload         4
      22: putfield      #22                 // Field geodeRobots:I
      25: aload_0
      26: iload         5
      28: putfield      #25                 // Field clay:I
      31: aload_0
      32: iload         6
      34: putfield      #28                 // Field obsidian:I
      37: aload_0
      38: iload         7
      40: putfield      #31                 // Field geode:I
      43: return

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

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

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

  public final int getGeodeRobots();
    Code:
       0: aload_0
       1: getfield      #22                 // Field geodeRobots:I
       4: ireturn

  public final int getClay();
    Code:
       0: aload_0
       1: getfield      #25                 // Field clay:I
       4: ireturn

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

  public final int getGeode();
    Code:
       0: aload_0
       1: getfield      #31                 // Field geode:I
       4: ireturn

  public final Day19Kt$main$State next();
    Code:
       0: new           #2                  // class Day19Kt$main$State
       3: dup
       4: aload_0
       5: getfield      #13                 // Field oreRobots:I
       8: aload_0
       9: getfield      #16                 // Field clayRobots:I
      12: aload_0
      13: getfield      #19                 // Field obsidianRobots:I
      16: aload_0
      17: getfield      #22                 // Field geodeRobots:I
      20: aload_0
      21: getfield      #25                 // Field clay:I
      24: aload_0
      25: getfield      #16                 // Field clayRobots:I
      28: iadd
      29: aload_0
      30: getfield      #28                 // Field obsidian:I
      33: aload_0
      34: getfield      #19                 // Field obsidianRobots:I
      37: iadd
      38: aload_0
      39: getfield      #31                 // Field geode:I
      42: aload_0
      43: getfield      #22                 // Field geodeRobots:I
      46: iadd
      47: invokespecial #45                 // Method "<init>":(IIIIIII)V
      50: areturn

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

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

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

  public final int component4();
    Code:
       0: aload_0
       1: getfield      #22                 // Field geodeRobots:I
       4: ireturn

  public final int component5();
    Code:
       0: aload_0
       1: getfield      #25                 // Field clay:I
       4: ireturn

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

  public final int component7();
    Code:
       0: aload_0
       1: getfield      #31                 // Field geode:I
       4: ireturn

  public final Day19Kt$main$State copy(int, int, int, int, int, int, int);
    Code:
       0: new           #2                  // class Day19Kt$main$State
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: iload         4
       9: iload         5
      11: iload         6
      13: iload         7
      15: invokespecial #45                 // Method "<init>":(IIIIIII)V
      18: areturn

  public static Day19Kt$main$State copy$default(Day19Kt$main$State, int, int, int, int, int, int, int, int, java.lang.Object);
    Code:
       0: iload         8
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field oreRobots:I
      11: istore_1
      12: iload         8
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field clayRobots:I
      23: istore_2
      24: iload         8
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field obsidianRobots:I
      35: istore_3
      36: iload         8
      38: bipush        8
      40: iand
      41: ifeq          50
      44: aload_0
      45: getfield      #22                 // Field geodeRobots:I
      48: istore        4
      50: iload         8
      52: bipush        16
      54: iand
      55: ifeq          64
      58: aload_0
      59: getfield      #25                 // Field clay:I
      62: istore        5
      64: iload         8
      66: bipush        32
      68: iand
      69: ifeq          78
      72: aload_0
      73: getfield      #28                 // Field obsidian:I
      76: istore        6
      78: iload         8
      80: bipush        64
      82: iand
      83: ifeq          92
      86: aload_0
      87: getfield      #31                 // Field geode:I
      90: istore        7
      92: aload_0
      93: iload_1
      94: iload_2
      95: iload_3
      96: iload         4
      98: iload         5
     100: iload         6
     102: iload         7
     104: invokevirtual #58                 // Method copy:(IIIIIII)LDay19Kt$main$State;
     107: areturn

  public java.lang.String toString();
    Code:
       0: new           #62                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #65                 // String State(oreRobots=
       9: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field oreRobots:I
      16: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #74                 // String , clayRobots=
      21: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field clayRobots:I
      28: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #76                 // String , obsidianRobots=
      33: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field obsidianRobots:I
      40: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: ldc           #78                 // String , geodeRobots=
      45: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      48: aload_0
      49: getfield      #22                 // Field geodeRobots:I
      52: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      55: ldc           #80                 // String , clay=
      57: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      60: aload_0
      61: getfield      #25                 // Field clay:I
      64: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      67: ldc           #82                 // String , obsidian=
      69: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      72: aload_0
      73: getfield      #28                 // Field obsidian:I
      76: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      79: ldc           #84                 // String , geode=
      81: invokevirtual #69                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      84: aload_0
      85: getfield      #31                 // Field geode:I
      88: invokevirtual #72                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      91: bipush        41
      93: invokevirtual #87                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      96: invokevirtual #89                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      99: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field oreRobots:I
       4: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field clayRobots:I
      16: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #19                 // Field obsidianRobots:I
      29: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: bipush        31
      37: imul
      38: aload_0
      39: getfield      #22                 // Field geodeRobots:I
      42: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
      45: iadd
      46: istore_1
      47: iload_1
      48: bipush        31
      50: imul
      51: aload_0
      52: getfield      #25                 // Field clay:I
      55: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
      58: iadd
      59: istore_1
      60: iload_1
      61: bipush        31
      63: imul
      64: aload_0
      65: getfield      #28                 // Field obsidian:I
      68: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
      71: iadd
      72: istore_1
      73: iload_1
      74: bipush        31
      76: imul
      77: aload_0
      78: getfield      #31                 // Field geode:I
      81: invokestatic  #95                 // Method java/lang/Integer.hashCode:(I)I
      84: iadd
      85: istore_1
      86: iload_1
      87: 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 Day19Kt$main$State
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day19Kt$main$State
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field oreRobots:I
      25: aload_2
      26: getfield      #13                 // Field oreRobots:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field clayRobots:I
      38: aload_2
      39: getfield      #16                 // Field clayRobots:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field obsidianRobots:I
      51: aload_2
      52: getfield      #19                 // Field obsidianRobots:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: aload_0
      61: getfield      #22                 // Field geodeRobots:I
      64: aload_2
      65: getfield      #22                 // Field geodeRobots:I
      68: if_icmpeq     73
      71: iconst_0
      72: ireturn
      73: aload_0
      74: getfield      #25                 // Field clay:I
      77: aload_2
      78: getfield      #25                 // Field clay:I
      81: if_icmpeq     86
      84: iconst_0
      85: ireturn
      86: aload_0
      87: getfield      #28                 // Field obsidian:I
      90: aload_2
      91: getfield      #28                 // Field obsidian:I
      94: if_icmpeq     99
      97: iconst_0
      98: ireturn
      99: aload_0
     100: getfield      #31                 // Field geode:I
     103: aload_2
     104: getfield      #31                 // Field geode:I
     107: if_icmpeq     112
     110: iconst_0
     111: ireturn
     112: iconst_1
     113: ireturn
}

Compiled from "day19.kt"
public final class Day19Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Blueprint 1: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 2 ore and 16 clay. Each geode robot costs 4 ore and 16 obsidian.\nBlueprint 2: Each ore robot costs 4 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 14 clay. Each geode robot costs 4 ore and 8 obsidian.\nBlueprint 3: Each ore robot costs 3 ore. Each clay robot costs 4 ore. Each obsidian robot costs 3 ore and 18 clay. Each geode robot costs 4 ore and 16 obsidian.
       2: astore_0
       3: new           #10                 // class kotlin/text/Regex
       6: dup
       7: ldc           #12                 // String Blueprint ([0-9]+): Each ore robot costs ([0-9]+) ore. Each clay robot costs ([0-9]+) ore. Each obsidian robot costs ([0-9]+) ore and ([0-9]+) clay. Each geode robot costs ([0-9]+) ore and ([0-9]+) obsidian.
       9: invokespecial #16                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      12: astore_1
      13: iconst_0
      14: istore_2
      15: aload_0
      16: checkcast     #18                 // class java/lang/CharSequence
      19: iconst_1
      20: anewarray     #20                 // class java/lang/String
      23: astore        4
      25: aload         4
      27: iconst_0
      28: ldc           #22                 // String \n
      30: aastore
      31: aload         4
      33: iconst_0
      34: iconst_0
      35: bipush        6
      37: aconst_null
      38: invokestatic  #28                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      41: invokeinterface #34,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      46: astore_3
      47: aload_3
      48: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          250
      56: aload_3
      57: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: checkcast     #20                 // class java/lang/String
      65: astore        4
      67: aload_1
      68: aload         4
      70: checkcast     #18                 // class java/lang/CharSequence
      73: iconst_0
      74: iconst_2
      75: aconst_null
      76: invokestatic  #48                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      79: dup
      80: invokestatic  #54                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      83: invokeinterface #60,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      88: astore        5
      90: new           #62                 // class java/lang/StringBuilder
      93: dup
      94: invokespecial #64                 // Method java/lang/StringBuilder."<init>":()V
      97: ldc           #66                 // String Test
      99: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     102: aload         5
     104: iconst_1
     105: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: checkcast     #20                 // class java/lang/String
     113: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     116: invokevirtual #78                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     119: getstatic     #84                 // Field java/lang/System.out:Ljava/io/PrintStream;
     122: swap
     123: invokevirtual #89                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     126: bipush        32
     128: aload         5
     130: iconst_2
     131: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     136: checkcast     #20                 // class java/lang/String
     139: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     142: aload         5
     144: iconst_3
     145: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     150: checkcast     #20                 // class java/lang/String
     153: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     156: aload         5
     158: iconst_4
     159: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     164: checkcast     #20                 // class java/lang/String
     167: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     170: aload         5
     172: iconst_5
     173: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     178: checkcast     #20                 // class java/lang/String
     181: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     184: aload         5
     186: bipush        6
     188: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     193: checkcast     #20                 // class java/lang/String
     196: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     199: aload         5
     201: bipush        7
     203: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     208: checkcast     #20                 // class java/lang/String
     211: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     214: invokestatic  #99                 // Method main$solve:(IIIIIII)I
     217: istore        6
     219: getstatic     #84                 // Field java/lang/System.out:Ljava/io/PrintStream;
     222: iload         6
     224: invokevirtual #102                // Method java/io/PrintStream.println:(I)V
     227: iload_2
     228: aload         5
     230: iconst_1
     231: invokeinterface #74,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     236: checkcast     #20                 // class java/lang/String
     239: invokestatic  #95                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     242: iload         6
     244: imul
     245: iadd
     246: istore_2
     247: goto          47
     250: getstatic     #84                 // Field java/lang/System.out:Ljava/io/PrintStream;
     253: iload_2
     254: invokevirtual #102                // Method java/io/PrintStream.println:(I)V
     257: return

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

  private static final void main$solve$put(java.util.Map<Day19Kt$main$State, java.lang.Integer>[], int, Day19Kt$main$State, int);
    Code:
       0: aload_0
       1: iload_1
       2: iconst_1
       3: iadd
       4: aaload
       5: aload_2
       6: invokeinterface #126,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
      11: ifeq          33
      14: aload_0
      15: iload_1
      16: iconst_1
      17: iadd
      18: aaload
      19: aload_2
      20: invokestatic  #132                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      23: checkcast     #134                // class java/lang/Number
      26: invokevirtual #138                // Method java/lang/Number.intValue:()I
      29: iload_3
      30: if_icmpge     53
      33: iload_3
      34: invokestatic  #142                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: astore        4
      39: aload_0
      40: iload_1
      41: iconst_1
      42: iadd
      43: aaload
      44: aload_2
      45: aload         4
      47: invokeinterface #146,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      52: pop
      53: return

  private static final int main$solve(int, int, int, int, int, int, int);
    Code:
       0: iconst_0
       1: istore        8
       3: iload_0
       4: iconst_1
       5: iadd
       6: istore        9
       8: iload         9
      10: anewarray     #122                // class java/util/Map
      13: astore        10
      15: iload         8
      17: iload         9
      19: if_icmpge     47
      22: iload         8
      24: istore        11
      26: aload         10
      28: iload         11
      30: new           #154                // class java/util/LinkedHashMap
      33: dup
      34: invokespecial #155                // Method java/util/LinkedHashMap."<init>":()V
      37: checkcast     #122                // class java/util/Map
      40: aastore
      41: iinc          8, 1
      44: goto          15
      47: aload         10
      49: astore        7
      51: aload         7
      53: iconst_0
      54: aaload
      55: new           #157                // class Day19Kt$main$State
      58: dup
      59: iconst_1
      60: iconst_0
      61: iconst_0
      62: iconst_0
      63: iconst_0
      64: iconst_0
      65: iconst_0
      66: invokespecial #160                // Method Day19Kt$main$State."<init>":(IIIIIII)V
      69: iconst_0
      70: invokestatic  #142                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: invokeinterface #146,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      78: pop
      79: iconst_0
      80: istore        8
      82: iconst_0
      83: istore        9
      85: iload         9
      87: iload_0
      88: if_icmpge     561
      91: aload         7
      93: iload         9
      95: aaload
      96: invokeinterface #164,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     101: invokeinterface #167,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     106: astore        10
     108: aload         10
     110: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     115: ifeq          555
     118: aload         10
     120: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     125: checkcast     #169                // class java/util/Map$Entry
     128: astore        11
     130: aload         11
     132: invokeinterface #172,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     137: checkcast     #157                // class Day19Kt$main$State
     140: astore        12
     142: iload         8
     144: aload         12
     146: invokevirtual #175                // Method Day19Kt$main$State.next:()LDay19Kt$main$State;
     149: invokevirtual #178                // Method Day19Kt$main$State.getGeode:()I
     152: invokestatic  #184                // Method java/lang/Math.max:(II)I
     155: istore        8
     157: iload         9
     159: iload_0
     160: iconst_1
     161: isub
     162: if_icmpeq     108
     165: aload         7
     167: iload         9
     169: aload         12
     171: invokevirtual #175                // Method Day19Kt$main$State.next:()LDay19Kt$main$State;
     174: aload         11
     176: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     181: checkcast     #134                // class java/lang/Number
     184: invokevirtual #138                // Method java/lang/Number.intValue:()I
     187: aload         12
     189: invokevirtual #189                // Method Day19Kt$main$State.getOreRobots:()I
     192: iadd
     193: invokestatic  #191                // Method main$solve$put:([Ljava/util/Map;ILDay19Kt$main$State;I)V
     196: aload         11
     198: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     203: checkcast     #134                // class java/lang/Number
     206: invokevirtual #138                // Method java/lang/Number.intValue:()I
     209: iload_1
     210: if_icmplt     273
     213: aload         12
     215: invokevirtual #175                // Method Day19Kt$main$State.next:()LDay19Kt$main$State;
     218: aload         12
     220: invokevirtual #189                // Method Day19Kt$main$State.getOreRobots:()I
     223: iconst_1
     224: iadd
     225: iconst_0
     226: iconst_0
     227: iconst_0
     228: iconst_0
     229: iconst_0
     230: iconst_0
     231: bipush        126
     233: aconst_null
     234: invokestatic  #195                // Method Day19Kt$main$State.copy$default:(LDay19Kt$main$State;IIIIIIIILjava/lang/Object;)LDay19Kt$main$State;
     237: astore        13
     239: aload         11
     241: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     246: checkcast     #134                // class java/lang/Number
     249: invokevirtual #138                // Method java/lang/Number.intValue:()I
     252: iload_1
     253: isub
     254: aload         12
     256: invokevirtual #189                // Method Day19Kt$main$State.getOreRobots:()I
     259: iadd
     260: istore        14
     262: aload         7
     264: iload         9
     266: aload         13
     268: iload         14
     270: invokestatic  #191                // Method main$solve$put:([Ljava/util/Map;ILDay19Kt$main$State;I)V
     273: aload         11
     275: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     280: checkcast     #134                // class java/lang/Number
     283: invokevirtual #138                // Method java/lang/Number.intValue:()I
     286: iload_2
     287: if_icmplt     350
     290: aload         12
     292: invokevirtual #175                // Method Day19Kt$main$State.next:()LDay19Kt$main$State;
     295: iconst_0
     296: aload         12
     298: invokevirtual #198                // Method Day19Kt$main$State.getClayRobots:()I
     301: iconst_1
     302: iadd
     303: iconst_0
     304: iconst_0
     305: iconst_0
     306: iconst_0
     307: iconst_0
     308: bipush        125
     310: aconst_null
     311: invokestatic  #195                // Method Day19Kt$main$State.copy$default:(LDay19Kt$main$State;IIIIIIIILjava/lang/Object;)LDay19Kt$main$State;
     314: astore        13
     316: aload         11
     318: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     323: checkcast     #134                // class java/lang/Number
     326: invokevirtual #138                // Method java/lang/Number.intValue:()I
     329: iload_2
     330: isub
     331: aload         12
     333: invokevirtual #189                // Method Day19Kt$main$State.getOreRobots:()I
     336: iadd
     337: istore        14
     339: aload         7
     341: iload         9
     343: aload         13
     345: iload         14
     347: invokestatic  #191                // Method main$solve$put:([Ljava/util/Map;ILDay19Kt$main$State;I)V
     350: aload         11
     352: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     357: checkcast     #134                // class java/lang/Number
     360: invokevirtual #138                // Method java/lang/Number.intValue:()I
     363: iload_3
     364: if_icmplt     450
     367: aload         12
     369: invokevirtual #201                // Method Day19Kt$main$State.getClay:()I
     372: iload         4
     374: if_icmplt     450
     377: aload         12
     379: invokevirtual #175                // Method Day19Kt$main$State.next:()LDay19Kt$main$State;
     382: iconst_0
     383: iconst_0
     384: aload         12
     386: invokevirtual #204                // Method Day19Kt$main$State.getObsidianRobots:()I
     389: iconst_1
     390: iadd
     391: iconst_0
     392: aload         12
     394: invokevirtual #201                // Method Day19Kt$main$State.getClay:()I
     397: iload         4
     399: isub
     400: aload         12
     402: invokevirtual #198                // Method Day19Kt$main$State.getClayRobots:()I
     405: iadd
     406: iconst_0
     407: iconst_0
     408: bipush        107
     410: aconst_null
     411: invokestatic  #195                // Method Day19Kt$main$State.copy$default:(LDay19Kt$main$State;IIIIIIIILjava/lang/Object;)LDay19Kt$main$State;
     414: astore        13
     416: aload         11
     418: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     423: checkcast     #134                // class java/lang/Number
     426: invokevirtual #138                // Method java/lang/Number.intValue:()I
     429: iload_3
     430: isub
     431: aload         12
     433: invokevirtual #189                // Method Day19Kt$main$State.getOreRobots:()I
     436: iadd
     437: istore        14
     439: aload         7
     441: iload         9
     443: aload         13
     445: iload         14
     447: invokestatic  #191                // Method main$solve$put:([Ljava/util/Map;ILDay19Kt$main$State;I)V
     450: aload         11
     452: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     457: checkcast     #134                // class java/lang/Number
     460: invokevirtual #138                // Method java/lang/Number.intValue:()I
     463: iload         5
     465: if_icmplt     108
     468: aload         12
     470: invokevirtual #207                // Method Day19Kt$main$State.getObsidian:()I
     473: iload         6
     475: if_icmplt     108
     478: aload         12
     480: invokevirtual #175                // Method Day19Kt$main$State.next:()LDay19Kt$main$State;
     483: iconst_0
     484: iconst_0
     485: iconst_0
     486: aload         12
     488: invokevirtual #210                // Method Day19Kt$main$State.getGeodeRobots:()I
     491: iconst_1
     492: iadd
     493: iconst_0
     494: aload         12
     496: invokevirtual #207                // Method Day19Kt$main$State.getObsidian:()I
     499: iload         6
     501: isub
     502: aload         12
     504: invokevirtual #204                // Method Day19Kt$main$State.getObsidianRobots:()I
     507: iadd
     508: iconst_0
     509: bipush        87
     511: aconst_null
     512: invokestatic  #195                // Method Day19Kt$main$State.copy$default:(LDay19Kt$main$State;IIIIIIIILjava/lang/Object;)LDay19Kt$main$State;
     515: astore        13
     517: aload         11
     519: invokeinterface #186,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     524: checkcast     #134                // class java/lang/Number
     527: invokevirtual #138                // Method java/lang/Number.intValue:()I
     530: iload         5
     532: isub
     533: aload         12
     535: invokevirtual #189                // Method Day19Kt$main$State.getOreRobots:()I
     538: iadd
     539: istore        14
     541: aload         7
     543: iload         9
     545: aload         13
     547: iload         14
     549: invokestatic  #191                // Method main$solve$put:([Ljava/util/Map;ILDay19Kt$main$State;I)V
     552: goto          108
     555: iinc          9, 1
     558: goto          85
     561: iload         8
     563: ireturn
}