package com.gitlab.lae.intellij.jump

data class TreePath<out K>(val keys: List<K>)

operator fun <K> TreePath<K>.plus(key: K) = TreePath(keys + key)

sealed class Tree<out K, out V>

data class TreeLeaf<out V>(val value: V) : Tree<Nothing, V>() {
  override fun toString() = "TreeLeaf($value)"
}

data class TreeNode<out K, out V>(val nodes: List<Pair<K, Tree<K, V>>>) : Tree<K, V>() {

  constructor(vararg nodes: Pair<K, Tree<K, V>>) : this(nodes.toList())

  override fun toString() = "TreeNode(\n  ${nodes.joinToString(",\n").replace("\n", "\n  ")}\n)"
}

val emptyPath = TreePath<Nothing>(emptyList())
val emptyTree = TreeNode<Nothing, Nothing>(emptyList())

fun <V> treeOf(items: Collection<V>, nodeSize: Int): Tree<Int, V> =
    join(items.map(::TreeLeaf).toList(), nodeSize)

private fun <V> join(nodes: Collection<Tree<Int, V>>, nodeSize: Int): Tree<Int, V> =
    when {
      nodeSize < 1 -> throw IllegalArgumentException("nodeSize=$nodeSize")
      nodes.size <= 1 -> nodes.firstOrNull() ?: emptyTree
      nodes.size <= nodeSize ->
          nodes.withIndex().map { (index, value) -> index to value }.let(::TreeNode)
      else ->
          nodes
              .asSequence()
              .chunked(nodeSize)
              .map { join(it, nodeSize) }
              .let { join(it.toList(), nodeSize) }
    }

fun <K, V, R> Tree<K, V>.mapKey(mapper: (K) -> R): Tree<R, V> =
    when (this) {
      is TreeLeaf -> this
      is TreeNode ->
          nodes.map { (key, value) -> mapper(key) to value.mapKey(mapper) }.let(::TreeNode)
    }

fun <K, V> Tree<K, V>.asSequence(path: TreePath<K> = emptyPath): Sequence<Pair<TreePath<K>, V>> =
    when (this) {
      is TreeLeaf -> sequenceOf(path to value)
      is TreeNode -> nodes.asSequence().flatMap { (key, value) -> value.asSequence(path + key) }
    }

operator fun <K, V> Tree<K, V>.get(key: K): Tree<K, V>? =
    when (this) {
      is TreeNode -> nodes.firstOrNull { (k) -> k == key }?.second
      else -> null
    }

Compiled from "Tree.kt"
public final class com.gitlab.lae.intellij.jump.TreeKt {
  private static final com.gitlab.lae.intellij.jump.TreePath emptyPath;

  private static final com.gitlab.lae.intellij.jump.TreeNode emptyTree;

  public static final <K> com.gitlab.lae.intellij.jump.TreePath<K> plus(com.gitlab.lae.intellij.jump.TreePath<? extends K>, K);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class com/gitlab/lae/intellij/jump/TreePath
       9: dup
      10: aload_0
      11: invokevirtual #22                 // Method com/gitlab/lae/intellij/jump/TreePath.getKeys:()Ljava/util/List;
      14: checkcast     #24                 // class java/util/Collection
      17: aload_1
      18: invokestatic  #29                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
      21: invokespecial #33                 // Method com/gitlab/lae/intellij/jump/TreePath."<init>":(Ljava/util/List;)V
      24: areturn

  public static final com.gitlab.lae.intellij.jump.TreePath getEmptyPath();
    Code:
       0: getstatic     #42                 // Field emptyPath:Lcom/gitlab/lae/intellij/jump/TreePath;
       3: areturn

  public static final com.gitlab.lae.intellij.jump.TreeNode getEmptyTree();
    Code:
       0: getstatic     #48                 // Field emptyTree:Lcom/gitlab/lae/intellij/jump/TreeNode;
       3: areturn

  public static final <V> com.gitlab.lae.intellij.jump.Tree<java.lang.Integer, V> treeOf(java.util.Collection<? extends V>, int);
    Code:
       0: aload_0
       1: ldc           #53                 // String items
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #55                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #57                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #64                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #24                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          97
      56: aload         7
      58: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: astore        9
      71: astore        11
      73: iconst_0
      74: istore        10
      76: new           #80                 // class com/gitlab/lae/intellij/jump/TreeLeaf
      79: dup
      80: aload         9
      82: invokespecial #83                 // Method com/gitlab/lae/intellij/jump/TreeLeaf."<init>":(Ljava/lang/Object;)V
      85: aload         11
      87: swap
      88: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      93: pop
      94: goto          46
      97: aload         5
      99: checkcast     #89                 // class java/util/List
     102: nop
     103: checkcast     #55                 // class java/lang/Iterable
     106: invokestatic  #93                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     109: checkcast     #24                 // class java/util/Collection
     112: iload_1
     113: invokestatic  #96                 // Method join:(Ljava/util/Collection;I)Lcom/gitlab/lae/intellij/jump/Tree;
     116: areturn

  private static final <V> com.gitlab.lae.intellij.jump.Tree<java.lang.Integer, V> join(java.util.Collection<? extends com.gitlab.lae.intellij.jump.Tree<java.lang.Integer, ? extends V>>, int);
    Code:
       0: nop
       1: iload_1
       2: iconst_1
       3: if_icmpge     33
       6: new           #111                // class java/lang/IllegalArgumentException
       9: dup
      10: new           #113                // class java/lang/StringBuilder
      13: dup
      14: invokespecial #116                // Method java/lang/StringBuilder."<init>":()V
      17: ldc           #118                // String nodeSize=
      19: invokevirtual #122                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      22: iload_1
      23: invokevirtual #125                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      26: invokevirtual #129                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      29: invokespecial #132                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      32: athrow
      33: aload_0
      34: invokeinterface #136,  1          // InterfaceMethod java/util/Collection.size:()I
      39: iconst_1
      40: if_icmpgt     67
      43: aload_0
      44: checkcast     #55                 // class java/lang/Iterable
      47: invokestatic  #140                // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/lang/Iterable;)Ljava/lang/Object;
      50: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
      53: dup
      54: ifnonnull     252
      57: pop
      58: getstatic     #48                 // Field emptyTree:Lcom/gitlab/lae/intellij/jump/TreeNode;
      61: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
      64: goto          252
      67: aload_0
      68: invokeinterface #136,  1          // InterfaceMethod java/util/Collection.size:()I
      73: iload_1
      74: if_icmpgt     216
      77: aload_0
      78: checkcast     #55                 // class java/lang/Iterable
      81: invokestatic  #146                // Method kotlin/collections/CollectionsKt.withIndex:(Ljava/lang/Iterable;)Ljava/lang/Iterable;
      84: astore_2
      85: iconst_0
      86: istore_3
      87: aload_2
      88: astore        4
      90: new           #57                 // class java/util/ArrayList
      93: dup
      94: aload_2
      95: bipush        10
      97: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     100: invokespecial #64                 // Method java/util/ArrayList."<init>":(I)V
     103: checkcast     #24                 // class java/util/Collection
     106: astore        5
     108: iconst_0
     109: istore        6
     111: aload         4
     113: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     118: astore        7
     120: aload         7
     122: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     127: ifeq          192
     130: aload         7
     132: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     137: astore        8
     139: aload         5
     141: aload         8
     143: checkcast     #148                // class kotlin/collections/IndexedValue
     146: astore        9
     148: astore        13
     150: iconst_0
     151: istore        10
     153: aload         9
     155: invokevirtual #151                // Method kotlin/collections/IndexedValue.component1:()I
     158: istore        11
     160: aload         9
     162: invokevirtual #154                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     165: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
     168: astore        12
     170: iload         11
     172: invokestatic  #160                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     175: aload         12
     177: invokestatic  #166                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     180: aload         13
     182: swap
     183: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     188: pop
     189: goto          120
     192: aload         5
     194: checkcast     #89                 // class java/util/List
     197: nop
     198: astore_3
     199: iconst_0
     200: istore        4
     202: new           #168                // class com/gitlab/lae/intellij/jump/TreeNode
     205: dup
     206: aload_3
     207: invokespecial #169                // Method com/gitlab/lae/intellij/jump/TreeNode."<init>":(Ljava/util/List;)V
     210: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
     213: goto          252
     216: aload_0
     217: checkcast     #55                 // class java/lang/Iterable
     220: invokestatic  #173                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     223: iload_1
     224: invokestatic  #179                // Method kotlin/sequences/SequencesKt.chunked:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     227: iload_1
     228: invokedynamic #199,  0            // InvokeDynamic #0:invoke:(I)Lkotlin/jvm/functions/Function1;
     233: invokestatic  #203                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     236: astore_3
     237: iconst_0
     238: istore        4
     240: aload_3
     241: invokestatic  #206                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     244: checkcast     #24                 // class java/util/Collection
     247: iload_1
     248: invokestatic  #96                 // Method join:(Ljava/util/Collection;I)Lcom/gitlab/lae/intellij/jump/Tree;
     251: nop
     252: areturn

  public static final <K, V, R> com.gitlab.lae.intellij.jump.Tree<R, V> mapKey(com.gitlab.lae.intellij.jump.Tree<? extends K, ? extends V>, kotlin.jvm.functions.Function1<? super K, ? extends R>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #221                // String mapper
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: astore_2
      14: aload_2
      15: instanceof    #80                 // class com/gitlab/lae/intellij/jump/TreeLeaf
      18: ifeq          25
      21: aload_0
      22: goto          192
      25: aload_2
      26: instanceof    #168                // class com/gitlab/lae/intellij/jump/TreeNode
      29: ifeq          184
      32: aload_0
      33: checkcast     #168                // class com/gitlab/lae/intellij/jump/TreeNode
      36: invokevirtual #224                // Method com/gitlab/lae/intellij/jump/TreeNode.getNodes:()Ljava/util/List;
      39: checkcast     #55                 // class java/lang/Iterable
      42: astore_3
      43: iconst_0
      44: istore        4
      46: aload_3
      47: astore        5
      49: new           #57                 // class java/util/ArrayList
      52: dup
      53: aload_3
      54: bipush        10
      56: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      59: invokespecial #64                 // Method java/util/ArrayList."<init>":(I)V
      62: checkcast     #24                 // class java/util/Collection
      65: astore        6
      67: iconst_0
      68: istore        7
      70: aload         5
      72: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      77: astore        8
      79: aload         8
      81: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      86: ifeq          158
      89: aload         8
      91: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      96: astore        9
      98: aload         6
     100: aload         9
     102: checkcast     #226                // class kotlin/Pair
     105: astore        10
     107: astore        14
     109: iconst_0
     110: istore        11
     112: aload         10
     114: invokevirtual #228                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     117: astore        12
     119: aload         10
     121: invokevirtual #229                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     124: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
     127: astore        13
     129: aload_1
     130: aload         12
     132: invokeinterface #233,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
     137: aload         13
     139: aload_1
     140: invokestatic  #235                // Method mapKey:(Lcom/gitlab/lae/intellij/jump/Tree;Lkotlin/jvm/functions/Function1;)Lcom/gitlab/lae/intellij/jump/Tree;
     143: invokestatic  #166                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     146: aload         14
     148: swap
     149: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     154: pop
     155: goto          79
     158: aload         6
     160: checkcast     #89                 // class java/util/List
     163: nop
     164: astore        4
     166: iconst_0
     167: istore        5
     169: new           #168                // class com/gitlab/lae/intellij/jump/TreeNode
     172: dup
     173: aload         4
     175: invokespecial #169                // Method com/gitlab/lae/intellij/jump/TreeNode."<init>":(Ljava/util/List;)V
     178: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
     181: goto          192
     184: new           #237                // class kotlin/NoWhenBranchMatchedException
     187: dup
     188: invokespecial #238                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     191: athrow
     192: areturn

  public static final <K, V> kotlin.sequences.Sequence<kotlin.Pair<com.gitlab.lae.intellij.jump.TreePath<K>, V>> asSequence(com.gitlab.lae.intellij.jump.Tree<? extends K, ? extends V>, com.gitlab.lae.intellij.jump.TreePath<? extends K>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #246                // String path
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: astore_2
      14: aload_2
      15: instanceof    #80                 // class com/gitlab/lae/intellij/jump/TreeLeaf
      18: ifeq          47
      21: iconst_1
      22: anewarray     #226                // class kotlin/Pair
      25: astore_3
      26: aload_3
      27: iconst_0
      28: aload_1
      29: aload_0
      30: checkcast     #80                 // class com/gitlab/lae/intellij/jump/TreeLeaf
      33: invokevirtual #249                // Method com/gitlab/lae/intellij/jump/TreeLeaf.getValue:()Ljava/lang/Object;
      36: invokestatic  #166                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      39: aastore
      40: aload_3
      41: invokestatic  #253                // Method kotlin/sequences/SequencesKt.sequenceOf:([Ljava/lang/Object;)Lkotlin/sequences/Sequence;
      44: goto          87
      47: aload_2
      48: instanceof    #168                // class com/gitlab/lae/intellij/jump/TreeNode
      51: ifeq          79
      54: aload_0
      55: checkcast     #168                // class com/gitlab/lae/intellij/jump/TreeNode
      58: invokevirtual #224                // Method com/gitlab/lae/intellij/jump/TreeNode.getNodes:()Ljava/util/List;
      61: checkcast     #55                 // class java/lang/Iterable
      64: invokestatic  #173                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      67: aload_1
      68: invokedynamic #263,  0            // InvokeDynamic #1:invoke:(Lcom/gitlab/lae/intellij/jump/TreePath;)Lkotlin/jvm/functions/Function1;
      73: invokestatic  #266                // Method kotlin/sequences/SequencesKt.flatMap:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      76: goto          87
      79: new           #237                // class kotlin/NoWhenBranchMatchedException
      82: dup
      83: invokespecial #238                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
      86: athrow
      87: areturn

  public static kotlin.sequences.Sequence asSequence$default(com.gitlab.lae.intellij.jump.Tree, com.gitlab.lae.intellij.jump.TreePath, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          10
       6: getstatic     #42                 // Field emptyPath:Lcom/gitlab/lae/intellij/jump/TreePath;
       9: astore_1
      10: aload_0
      11: aload_1
      12: invokestatic  #273                // Method asSequence:(Lcom/gitlab/lae/intellij/jump/Tree;Lcom/gitlab/lae/intellij/jump/TreePath;)Lkotlin/sequences/Sequence;
      15: areturn

  public static final <K, V> com.gitlab.lae.intellij.jump.Tree<K, V> get(com.gitlab.lae.intellij.jump.Tree<? extends K, ? extends V>, K);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: instanceof    #168                // class com/gitlab/lae/intellij/jump/TreeNode
      10: ifeq          106
      13: aload_0
      14: checkcast     #168                // class com/gitlab/lae/intellij/jump/TreeNode
      17: invokevirtual #224                // Method com/gitlab/lae/intellij/jump/TreeNode.getNodes:()Ljava/util/List;
      20: checkcast     #55                 // class java/lang/Iterable
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_2
      27: invokeinterface #68,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        4
      34: aload         4
      36: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          84
      44: aload         4
      46: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: astore        5
      53: aload         5
      55: checkcast     #226                // class kotlin/Pair
      58: astore        6
      60: iconst_0
      61: istore        7
      63: aload         6
      65: invokevirtual #228                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      68: astore        8
      70: aload         8
      72: aload_1
      73: invokestatic  #281                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      76: ifeq          34
      79: aload         5
      81: goto          85
      84: aconst_null
      85: checkcast     #226                // class kotlin/Pair
      88: dup
      89: ifnull        101
      92: invokevirtual #284                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      95: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
      98: goto          107
     101: pop
     102: aconst_null
     103: goto          107
     106: aconst_null
     107: areturn

  private static final com.gitlab.lae.intellij.jump.Tree join$lambda$2(int, java.util.List);
    Code:
       0: aload_1
       1: ldc_w         #291                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: checkcast     #24                 // class java/util/Collection
      11: iload_0
      12: invokestatic  #96                 // Method join:(Ljava/util/Collection;I)Lcom/gitlab/lae/intellij/jump/Tree;
      15: areturn

  private static final kotlin.sequences.Sequence asSequence$lambda$6(com.gitlab.lae.intellij.jump.TreePath, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #294                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #228                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: astore_2
      12: aload_1
      13: invokevirtual #229                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      16: checkcast     #142                // class com/gitlab/lae/intellij/jump/Tree
      19: astore_3
      20: aload_3
      21: aload_0
      22: aload_2
      23: invokestatic  #296                // Method plus:(Lcom/gitlab/lae/intellij/jump/TreePath;Ljava/lang/Object;)Lcom/gitlab/lae/intellij/jump/TreePath;
      26: invokestatic  #273                // Method asSequence:(Lcom/gitlab/lae/intellij/jump/Tree;Lcom/gitlab/lae/intellij/jump/TreePath;)Lkotlin/sequences/Sequence;
      29: areturn

  static {};
    Code:
       0: new           #18                 // class com/gitlab/lae/intellij/jump/TreePath
       3: dup
       4: invokestatic  #301                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
       7: invokespecial #33                 // Method com/gitlab/lae/intellij/jump/TreePath."<init>":(Ljava/util/List;)V
      10: putstatic     #42                 // Field emptyPath:Lcom/gitlab/lae/intellij/jump/TreePath;
      13: new           #168                // class com/gitlab/lae/intellij/jump/TreeNode
      16: dup
      17: invokestatic  #301                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      20: invokespecial #169                // Method com/gitlab/lae/intellij/jump/TreeNode."<init>":(Ljava/util/List;)V
      23: putstatic     #48                 // Field emptyTree:Lcom/gitlab/lae/intellij/jump/TreeNode;
      26: return
}

Compiled from "Tree.kt"
public abstract class com.gitlab.lae.intellij.jump.Tree<K, V> {
  private com.gitlab.lae.intellij.jump.Tree();
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: return

  public com.gitlab.lae.intellij.jump.Tree(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #13                 // Method "<init>":()V
       4: return
}


package net.codetreats.aoc.common

class Dijkstra {
    /**
     * Calculate the minimum distance between startNode and endNode.
     * The algorithm expects, that there are exactly [nodeCount] nodes with names from 0 to [nodeCount - 1]
     * @param: nodeCount the total number of nodes
     * @param: startNOde the name of the start node
     * @param: endNode the name of the end node
     * @param: edges defines all edges. An edge starts at the key of the map and ends in 0 .. n other nodes.
     *         A target node is of type [EdgeDistance],
     *         which contains the name of the target node and the distance between the key and the target
     */
    fun shortestPath(nodeCount: Int, startNode: Int, endNode: Int, edges: Map<Int, Set<EdgeDistance>>) : DijkstraResult {
        val distances  = IntArray(nodeCount) { Integer.MAX_VALUE}
        val preds = IntArray(nodeCount) { -1 }
        distances[startNode] = 0
        val queue : MutableList<Int> = mutableListOf(0)
        val added = mutableSetOf<Int>(0)
        while(queue.isNotEmpty()) {
            val u : Int = queue.minBy { distances[it] }!!
            queue.remove(u)
            if (u == endNode) {
                return DijkstraResult(preds, distances[u])
            }
            edges[u]!!.forEach { v ->
                if (v.node !in queue && v.node !in added) {
                    queue.add(v.node)
                    added.add(v.node)
                }
                if (v.node in queue) {
                    val newDistance = distances[u] + v.weight
                    if (newDistance < distances[v.node]) {
                        distances[v.node] = newDistance
                        preds[v.node] = u
                    }
                }
            }
        }
        throw IllegalStateException("Algorithm finished without result")
    }
}

data class EdgeDistance(val node: Int, val weight: Int)

data class DijkstraResult(val preds: IntArray, val length: Int) {
    fun shortestPath(from: Int, to: Int) : List<Int> {
        val path = mutableListOf(to)
        while (path.last() != from) {
            path.add(preds[path.last()])
        }
        return path.reversed()
    }
}

Compiled from "Dijkstra.kt"
public final class net.codetreats.aoc.common.Dijkstra {
  public net.codetreats.aoc.common.Dijkstra();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final net.codetreats.aoc.common.DijkstraResult shortestPath(int, int, int, java.util.Map<java.lang.Integer, ? extends java.util.Set<net.codetreats.aoc.common.EdgeDistance>>);
    Code:
       0: aload         4
       2: ldc           #16                 // String edges
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: iconst_0
       8: istore        6
      10: iload_1
      11: newarray       int
      13: astore        7
      15: iload         6
      17: iload_1
      18: if_icmpge     38
      21: iload         6
      23: istore        8
      25: aload         7
      27: iload         8
      29: ldc           #23                 // int 2147483647
      31: iastore
      32: iinc          6, 1
      35: goto          15
      38: aload         7
      40: astore        5
      42: iconst_0
      43: istore        7
      45: iload_1
      46: newarray       int
      48: astore        8
      50: iload         7
      52: iload_1
      53: if_icmpge     72
      56: iload         7
      58: istore        9
      60: aload         8
      62: iload         9
      64: iconst_m1
      65: iastore
      66: iinc          7, 1
      69: goto          50
      72: aload         8
      74: astore        6
      76: aload         5
      78: iload_2
      79: iconst_0
      80: iastore
      81: iconst_1
      82: anewarray     #25                 // class java/lang/Integer
      85: astore        8
      87: aload         8
      89: iconst_0
      90: iconst_0
      91: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: aastore
      95: aload         8
      97: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     100: astore        7
     102: iconst_1
     103: anewarray     #25                 // class java/lang/Integer
     106: astore        9
     108: aload         9
     110: iconst_0
     111: iconst_0
     112: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     115: aastore
     116: aload         9
     118: invokestatic  #41                 // Method kotlin/collections/SetsKt.mutableSetOf:([Ljava/lang/Object;)Ljava/util/Set;
     121: astore        8
     123: aload         7
     125: checkcast     #43                 // class java/util/Collection
     128: invokeinterface #47,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     133: ifne          140
     136: iconst_1
     137: goto          141
     140: iconst_0
     141: ifeq          530
     144: aload         7
     146: checkcast     #49                 // class java/lang/Iterable
     149: astore        10
     151: iconst_0
     152: istore        11
     154: aload         10
     156: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     161: astore        12
     163: aload         12
     165: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     170: ifne          181
     173: new           #60                 // class java/util/NoSuchElementException
     176: dup
     177: invokespecial #61                 // Method java/util/NoSuchElementException."<init>":()V
     180: athrow
     181: aload         12
     183: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     188: astore        13
     190: aload         12
     192: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     197: ifne          205
     200: aload         13
     202: goto          281
     205: aload         13
     207: checkcast     #67                 // class java/lang/Number
     210: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     213: istore        14
     215: iconst_0
     216: istore        15
     218: aload         5
     220: iload         14
     222: iaload
     223: istore        14
     225: aload         12
     227: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     232: astore        15
     234: aload         15
     236: checkcast     #67                 // class java/lang/Number
     239: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     242: istore        16
     244: iconst_0
     245: istore        17
     247: aload         5
     249: iload         16
     251: iaload
     252: istore        16
     254: iload         14
     256: iload         16
     258: if_icmple     269
     261: aload         15
     263: astore        13
     265: iload         16
     267: istore        14
     269: aload         12
     271: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     276: ifne          225
     279: aload         13
     281: dup
     282: invokestatic  #75                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     285: checkcast     #67                 // class java/lang/Number
     288: invokevirtual #71                 // Method java/lang/Number.intValue:()I
     291: istore        9
     293: aload         7
     295: iload         9
     297: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     300: invokeinterface #81,  2           // InterfaceMethod java/util/List.remove:(Ljava/lang/Object;)Z
     305: pop
     306: iload         9
     308: iload_3
     309: if_icmpne     327
     312: new           #83                 // class net/codetreats/aoc/common/DijkstraResult
     315: dup
     316: aload         6
     318: aload         5
     320: iload         9
     322: iaload
     323: invokespecial #86                 // Method net/codetreats/aoc/common/DijkstraResult."<init>":([II)V
     326: areturn
     327: aload         4
     329: iload         9
     331: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     334: invokeinterface #92,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     339: dup
     340: invokestatic  #75                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     343: checkcast     #49                 // class java/lang/Iterable
     346: astore        10
     348: iconst_0
     349: istore        11
     351: aload         10
     353: invokeinterface #53,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     358: astore        12
     360: aload         12
     362: invokeinterface #58,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     367: ifeq          526
     370: aload         12
     372: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     377: astore        13
     379: aload         13
     381: checkcast     #94                 // class net/codetreats/aoc/common/EdgeDistance
     384: astore        14
     386: iconst_0
     387: istore        15
     389: aload         7
     391: aload         14
     393: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     396: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     399: invokeinterface #100,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     404: ifne          457
     407: aload         8
     409: aload         14
     411: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     414: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     417: invokeinterface #103,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     422: ifne          457
     425: aload         7
     427: aload         14
     429: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     432: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     435: invokeinterface #106,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     440: pop
     441: aload         8
     443: aload         14
     445: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     448: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     451: invokeinterface #107,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     456: pop
     457: aload         7
     459: aload         14
     461: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     464: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     467: invokeinterface #100,  2          // InterfaceMethod java/util/List.contains:(Ljava/lang/Object;)Z
     472: ifeq          521
     475: aload         5
     477: iload         9
     479: iaload
     480: aload         14
     482: invokevirtual #110                // Method net/codetreats/aoc/common/EdgeDistance.getWeight:()I
     485: iadd
     486: istore        16
     488: iload         16
     490: aload         5
     492: aload         14
     494: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     497: iaload
     498: if_icmpge     521
     501: aload         5
     503: aload         14
     505: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     508: iload         16
     510: iastore
     511: aload         6
     513: aload         14
     515: invokevirtual #97                 // Method net/codetreats/aoc/common/EdgeDistance.getNode:()I
     518: iload         9
     520: iastore
     521: nop
     522: nop
     523: goto          360
     526: nop
     527: goto          123
     530: new           #112                // class java/lang/IllegalStateException
     533: dup
     534: ldc           #114                // String Algorithm finished without result
     536: invokespecial #117                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     539: athrow
}


package net.codetreats.aoc.day02

import kotlin.math.max

data class Game(val id: Int, val extractions: List<Extraction>) {
    fun isPossible(input: Map<String, Int>) =
        extractions.map { it.dices }.flatten().none { input[it.color]!! < it.amount }

    fun power(): Int {
        val min = mutableMapOf("green" to 0, "red" to 0, "blue" to 0)
        extractions.map { it.dices }.flatten().forEach { dices ->
            min[dices.color] = max(dices.amount, min[dices.color]!!)
        }
        return min.map { it.value }.reduce { min1, min2 -> min1 * min2 }
    }

    companion object {
        fun from(line: String): Game {
            val id = line.split(":")[0].split(" ")[1].toInt()
            val extractions: List<Extraction> = line.split(":")[1].trim().split(";").map { Extraction.from(it.trim()) }
            return Game(id, extractions)
        }
    }

}

data class Extraction(val dices: List<ColorDices>) {
    companion object {
        fun from(part: String): Extraction =
            Extraction(part.trim().split(",").map { ColorDices.from(it.trim()) })
    }
}

data class ColorDices(val color: String, val amount: Int) {
    companion object {
        fun from(part: String): ColorDices {
            val amount = part.split(" ")[0].trim().toInt()
            val color = part.split(" ")[1].trim()
            return ColorDices(color, amount)
        }
    }
}

Compiled from "Game.kt"
public final class net.codetreats.aoc.day02.Game {
  public static final net.codetreats.aoc.day02.Game$Companion Companion;

  private final int id;

  private final java.util.List<net.codetreats.aoc.day02.Extraction> extractions;

  public net.codetreats.aoc.day02.Game(int, java.util.List<net.codetreats.aoc.day02.Extraction>);
    Code:
       0: aload_2
       1: ldc           #10                 // String extractions
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: iload_1
      12: putfield      #23                 // Field id:I
      15: aload_0
      16: aload_2
      17: putfield      #26                 // Field extractions:Ljava/util/List;
      20: return

  public final int getId();
    Code:
       0: aload_0
       1: getfield      #23                 // Field id:I
       4: ireturn

  public final java.util.List<net.codetreats.aoc.day02.Extraction> getExtractions();
    Code:
       0: aload_0
       1: getfield      #26                 // Field extractions:Ljava/util/List;
       4: areturn

  public final boolean isPossible(java.util.Map<java.lang.String, java.lang.Integer>);
    Code:
       0: aload_1
       1: ldc           #38                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #26                 // Field extractions:Ljava/util/List;
      10: checkcast     #40                 // class java/lang/Iterable
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_2
      17: astore        4
      19: new           #42                 // class java/util/ArrayList
      22: dup
      23: aload_2
      24: bipush        10
      26: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      29: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
      32: checkcast     #53                 // class java/util/Collection
      35: astore        5
      37: iconst_0
      38: istore        6
      40: aload         4
      42: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      47: astore        7
      49: aload         7
      51: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifeq          99
      59: aload         7
      61: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: astore        8
      68: aload         5
      70: aload         8
      72: checkcast     #69                 // class net/codetreats/aoc/day02/Extraction
      75: astore        9
      77: astore        11
      79: iconst_0
      80: istore        10
      82: aload         9
      84: invokevirtual #72                 // Method net/codetreats/aoc/day02/Extraction.getDices:()Ljava/util/List;
      87: aload         11
      89: swap
      90: invokeinterface #76,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: goto          49
      99: aload         5
     101: checkcast     #78                 // class java/util/List
     104: nop
     105: checkcast     #40                 // class java/lang/Iterable
     108: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     111: checkcast     #40                 // class java/lang/Iterable
     114: astore_2
     115: iconst_0
     116: istore_3
     117: aload_2
     118: instanceof    #53                 // class java/util/Collection
     121: ifeq          140
     124: aload_2
     125: checkcast     #53                 // class java/util/Collection
     128: invokeinterface #85,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     133: ifeq          140
     136: iconst_1
     137: goto          219
     140: aload_2
     141: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     146: astore        4
     148: aload         4
     150: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifeq          218
     158: aload         4
     160: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     165: astore        5
     167: aload         5
     169: checkcast     #87                 // class net/codetreats/aoc/day02/ColorDices
     172: astore        6
     174: iconst_0
     175: istore        7
     177: aload_1
     178: aload         6
     180: invokevirtual #91                 // Method net/codetreats/aoc/day02/ColorDices.getColor:()Ljava/lang/String;
     183: invokeinterface #97,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     188: dup
     189: invokestatic  #101                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     192: checkcast     #103                // class java/lang/Number
     195: invokevirtual #106                // Method java/lang/Number.intValue:()I
     198: aload         6
     200: invokevirtual #109                // Method net/codetreats/aoc/day02/ColorDices.getAmount:()I
     203: if_icmpge     210
     206: iconst_1
     207: goto          211
     210: iconst_0
     211: ifeq          148
     214: iconst_0
     215: goto          219
     218: iconst_1
     219: ireturn

  public final int power();
    Code:
       0: iconst_3
       1: anewarray     #130                // class kotlin/Pair
       4: astore_2
       5: aload_2
       6: iconst_0
       7: ldc           #132                // String green
       9: iconst_0
      10: invokestatic  #138                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: invokestatic  #144                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      16: aastore
      17: aload_2
      18: iconst_1
      19: ldc           #146                // String red
      21: iconst_0
      22: invokestatic  #138                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: invokestatic  #144                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      28: aastore
      29: aload_2
      30: iconst_2
      31: ldc           #148                // String blue
      33: iconst_0
      34: invokestatic  #138                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: invokestatic  #144                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      40: aastore
      41: aload_2
      42: invokestatic  #154                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
      45: astore_1
      46: aload_0
      47: getfield      #26                 // Field extractions:Ljava/util/List;
      50: checkcast     #40                 // class java/lang/Iterable
      53: astore_2
      54: iconst_0
      55: istore_3
      56: aload_2
      57: astore        4
      59: new           #42                 // class java/util/ArrayList
      62: dup
      63: aload_2
      64: bipush        10
      66: invokestatic  #48                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      69: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
      72: checkcast     #53                 // class java/util/Collection
      75: astore        5
      77: iconst_0
      78: istore        6
      80: aload         4
      82: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        7
      89: aload         7
      91: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          139
      99: aload         7
     101: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: astore        8
     108: aload         5
     110: aload         8
     112: checkcast     #69                 // class net/codetreats/aoc/day02/Extraction
     115: astore        9
     117: astore        11
     119: iconst_0
     120: istore        10
     122: aload         9
     124: invokevirtual #72                 // Method net/codetreats/aoc/day02/Extraction.getDices:()Ljava/util/List;
     127: aload         11
     129: swap
     130: invokeinterface #76,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          89
     139: aload         5
     141: checkcast     #78                 // class java/util/List
     144: nop
     145: checkcast     #40                 // class java/lang/Iterable
     148: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     151: checkcast     #40                 // class java/lang/Iterable
     154: astore_2
     155: iconst_0
     156: istore_3
     157: aload_2
     158: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     163: astore        4
     165: aload         4
     167: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     172: ifeq          244
     175: aload         4
     177: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     182: astore        5
     184: aload         5
     186: checkcast     #87                 // class net/codetreats/aoc/day02/ColorDices
     189: astore        6
     191: iconst_0
     192: istore        7
     194: nop
     195: aload_1
     196: aload         6
     198: invokevirtual #91                 // Method net/codetreats/aoc/day02/ColorDices.getColor:()Ljava/lang/String;
     201: aload         6
     203: invokevirtual #109                // Method net/codetreats/aoc/day02/ColorDices.getAmount:()I
     206: aload_1
     207: aload         6
     209: invokevirtual #91                 // Method net/codetreats/aoc/day02/ColorDices.getColor:()Ljava/lang/String;
     212: invokeinterface #97,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     217: dup
     218: invokestatic  #101                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     221: checkcast     #103                // class java/lang/Number
     224: invokevirtual #106                // Method java/lang/Number.intValue:()I
     227: invokestatic  #160                // Method java/lang/Math.max:(II)I
     230: invokestatic  #138                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     233: invokeinterface #164,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     238: pop
     239: nop
     240: nop
     241: goto          165
     244: nop
     245: aload_1
     246: astore_2
     247: iconst_0
     248: istore_3
     249: aload_2
     250: astore        4
     252: new           #42                 // class java/util/ArrayList
     255: dup
     256: aload_2
     257: invokeinterface #167,  1          // InterfaceMethod java/util/Map.size:()I
     262: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     265: checkcast     #53                 // class java/util/Collection
     268: astore        5
     270: iconst_0
     271: istore        6
     273: aload         4
     275: invokeinterface #171,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     280: invokeinterface #174,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     285: astore        7
     287: aload         7
     289: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     294: ifeq          348
     297: aload         7
     299: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     304: checkcast     #176                // class java/util/Map$Entry
     307: astore        8
     309: aload         5
     311: aload         8
     313: astore        9
     315: astore        11
     317: iconst_0
     318: istore        10
     320: aload         9
     322: invokeinterface #179,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     327: checkcast     #103                // class java/lang/Number
     330: invokevirtual #106                // Method java/lang/Number.intValue:()I
     333: invokestatic  #138                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     336: aload         11
     338: swap
     339: invokeinterface #76,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     344: pop
     345: goto          287
     348: aload         5
     350: checkcast     #78                 // class java/util/List
     353: nop
     354: checkcast     #40                 // class java/lang/Iterable
     357: astore_2
     358: nop
     359: iconst_0
     360: istore_3
     361: aload_2
     362: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     367: astore        4
     369: aload         4
     371: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     376: ifne          389
     379: new           #181                // class java/lang/UnsupportedOperationException
     382: dup
     383: ldc           #183                // String Empty collection can\'t be reduced.
     385: invokespecial #186                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     388: athrow
     389: aload         4
     391: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     396: astore        5
     398: aload         4
     400: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     405: ifeq          449
     408: aload         5
     410: aload         4
     412: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     417: checkcast     #103                // class java/lang/Number
     420: invokevirtual #106                // Method java/lang/Number.intValue:()I
     423: istore        6
     425: checkcast     #103                // class java/lang/Number
     428: invokevirtual #106                // Method java/lang/Number.intValue:()I
     431: istore        7
     433: iconst_0
     434: istore        8
     436: iload         7
     438: iload         6
     440: imul
     441: invokestatic  #138                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     444: astore        5
     446: goto          398
     449: aload         5
     451: checkcast     #103                // class java/lang/Number
     454: invokevirtual #106                // Method java/lang/Number.intValue:()I
     457: ireturn

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

  public final java.util.List<net.codetreats.aoc.day02.Extraction> component2();
    Code:
       0: aload_0
       1: getfield      #26                 // Field extractions:Ljava/util/List;
       4: areturn

  public final net.codetreats.aoc.day02.Game copy(int, java.util.List<net.codetreats.aoc.day02.Extraction>);
    Code:
       0: aload_2
       1: ldc           #10                 // String extractions
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class net/codetreats/aoc/day02/Game
       9: dup
      10: iload_1
      11: aload_2
      12: invokespecial #209                // Method "<init>":(ILjava/util/List;)V
      15: areturn

  public static net.codetreats.aoc.day02.Game copy$default(net.codetreats.aoc.day02.Game, int, java.util.List, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #23                 // Field id:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #26                 // Field extractions:Ljava/util/List;
      21: astore_2
      22: aload_0
      23: iload_1
      24: aload_2
      25: invokevirtual #213                // Method copy:(ILjava/util/List;)Lnet/codetreats/aoc/day02/Game;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #216                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #217                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #219                // String Game(id=
       9: invokevirtual #223                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #23                 // Field id:I
      16: invokevirtual #226                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #228                // String , extractions=
      21: invokevirtual #223                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #26                 // Field extractions:Ljava/util/List;
      28: invokevirtual #231                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #234                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #236                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #23                 // Field id:I
       4: invokestatic  #240                // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #26                 // Field extractions:Ljava/util/List;
      16: invokevirtual #242                // Method java/lang/Object.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class net/codetreats/aoc/day02/Game
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class net/codetreats/aoc/day02/Game
      20: astore_2
      21: aload_0
      22: getfield      #23                 // Field id:I
      25: aload_2
      26: getfield      #23                 // Field id:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #26                 // Field extractions:Ljava/util/List;
      38: aload_2
      39: getfield      #26                 // Field extractions:Ljava/util/List;
      42: invokestatic  #249                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      45: ifne          50
      48: iconst_0
      49: ireturn
      50: iconst_1
      51: ireturn

  static {};
    Code:
       0: new           #253                // class net/codetreats/aoc/day02/Game$Companion
       3: dup
       4: aconst_null
       5: invokespecial #256                // Method net/codetreats/aoc/day02/Game$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #260                // Field Companion:Lnet/codetreats/aoc/day02/Game$Companion;
      11: return
}

Compiled from "Game.kt"
public final class net.codetreats.aoc.day02.Game$Companion {
  private net.codetreats.aoc.day02.Game$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final net.codetreats.aoc.day02.Game from(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String line
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #23                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #25                 // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #27                 // String :
      19: aastore
      20: aload_3
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: iconst_0
      30: invokeinterface #39,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #23                 // class java/lang/CharSequence
      38: iconst_1
      39: anewarray     #25                 // class java/lang/String
      42: astore_3
      43: aload_3
      44: iconst_0
      45: ldc           #41                 // String
      47: aastore
      48: aload_3
      49: iconst_0
      50: iconst_0
      51: bipush        6
      53: aconst_null
      54: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      57: iconst_1
      58: invokeinterface #39,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      63: checkcast     #25                 // class java/lang/String
      66: invokestatic  #47                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      69: istore_2
      70: aload_1
      71: checkcast     #23                 // class java/lang/CharSequence
      74: iconst_1
      75: anewarray     #25                 // class java/lang/String
      78: astore        4
      80: aload         4
      82: iconst_0
      83: ldc           #27                 // String :
      85: aastore
      86: aload         4
      88: iconst_0
      89: iconst_0
      90: bipush        6
      92: aconst_null
      93: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      96: iconst_1
      97: invokeinterface #39,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     102: checkcast     #25                 // class java/lang/String
     105: checkcast     #23                 // class java/lang/CharSequence
     108: invokestatic  #51                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     111: invokevirtual #55                 // Method java/lang/Object.toString:()Ljava/lang/String;
     114: checkcast     #23                 // class java/lang/CharSequence
     117: iconst_1
     118: anewarray     #25                 // class java/lang/String
     121: astore        4
     123: aload         4
     125: iconst_0
     126: ldc           #57                 // String ;
     128: aastore
     129: aload         4
     131: iconst_0
     132: iconst_0
     133: bipush        6
     135: aconst_null
     136: invokestatic  #33                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     139: checkcast     #59                 // class java/lang/Iterable
     142: astore        4
     144: iconst_0
     145: istore        5
     147: aload         4
     149: astore        6
     151: new           #61                 // class java/util/ArrayList
     154: dup
     155: aload         4
     157: bipush        10
     159: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     162: invokespecial #70                 // Method java/util/ArrayList."<init>":(I)V
     165: checkcast     #72                 // class java/util/Collection
     168: astore        7
     170: iconst_0
     171: istore        8
     173: aload         6
     175: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        9
     182: aload         9
     184: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          244
     192: aload         9
     194: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        10
     201: aload         7
     203: aload         10
     205: checkcast     #25                 // class java/lang/String
     208: astore        11
     210: astore        13
     212: iconst_0
     213: istore        12
     215: getstatic     #92                 // Field net/codetreats/aoc/day02/Extraction.Companion:Lnet/codetreats/aoc/day02/Extraction$Companion;
     218: aload         11
     220: checkcast     #23                 // class java/lang/CharSequence
     223: invokestatic  #51                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     226: invokevirtual #55                 // Method java/lang/Object.toString:()Ljava/lang/String;
     229: invokevirtual #97                 // Method net/codetreats/aoc/day02/Extraction$Companion.from:(Ljava/lang/String;)Lnet/codetreats/aoc/day02/Extraction;
     232: aload         13
     234: swap
     235: invokeinterface #101,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     240: pop
     241: goto          182
     244: aload         7
     246: checkcast     #35                 // class java/util/List
     249: nop
     250: astore_3
     251: new           #103                // class net/codetreats/aoc/day02/Game
     254: dup
     255: iload_2
     256: aload_3
     257: invokespecial #106                // Method net/codetreats/aoc/day02/Game."<init>":(ILjava/util/List;)V
     260: areturn

  public net.codetreats.aoc.day02.Game$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #126                // Method "<init>":()V
       4: return
}


package com.ssynhtn.medium

import java.util.*

class UniquePermutations {
    fun permuteUnique(nums: IntArray): List<List<Int>> {
        nums.sort()
        val collection = mutableListOf<List<Int>>()
        permute(nums, 0, collection)
        return collection

    }

    private fun permute(nums: IntArray, fixCount: Int, collection: MutableList<List<Int>>) {
        if (!checkIncreasing(nums, fixCount)) {
            return
        }

        if (fixCount == nums.size) {
            collection.add(nums.toList())
            return
        }

        permute(nums, fixCount + 1, collection)
        val index = fixCount
        for (i in index + 1 until nums.size) {
            if (nums[i] == nums[i - 1]) continue

            shiftRight(nums, index, i)
            permute(nums, fixCount + 1, collection)
            shiftLeft(nums, index, i)
        }
    }

    private fun shiftLeft(nums: IntArray, index: Int, i: Int) {
        val temp = nums[index]
        System.arraycopy(nums, index + 1, nums, index, i - index)
        nums[i] = temp
    }

    private fun shiftRight(nums: IntArray, index: Int, i: Int) {
        val temp = nums[i]
        System.arraycopy(nums, index, nums, index + 1, i - index)
        nums[index] = temp
    }

    private fun checkIncreasing(nums: IntArray, fixCount: Int): Boolean {
        for (i in fixCount until nums.size - 1) {
            if (nums[i] > nums[i + 1]) {
//                println("bad " + nums.toList() + ", fixCount " + fixCount)
                return false;
            }
        }

//        println("good " + nums.toList() + ", fixCount " + fixCount)
        return true;
    }

    fun swap(nums: IntArray, i: Int, j: Int) {
        val temp = nums[i]
        nums[i] = nums[j]
        nums[j] = temp
    }
}

fun main(args: Array<String>) {
    val nums = intArrayOf(0, 0, 1, 2)
    val res = UniquePermutations().permuteUnique(nums)
    println(res)
}

Compiled from "UniquePermutations.kt"
public final class com.ssynhtn.medium.UniquePermutationsKt {
  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: iconst_4
       7: newarray       int
       9: astore_2
      10: aload_2
      11: iconst_0
      12: iconst_0
      13: iastore
      14: aload_2
      15: iconst_1
      16: iconst_0
      17: iastore
      18: aload_2
      19: iconst_2
      20: iconst_1
      21: iastore
      22: aload_2
      23: iconst_3
      24: iconst_2
      25: iastore
      26: aload_2
      27: astore_1
      28: new           #17                 // class com/ssynhtn/medium/UniquePermutations
      31: dup
      32: invokespecial #21                 // Method com/ssynhtn/medium/UniquePermutations."<init>":()V
      35: aload_1
      36: invokevirtual #25                 // Method com/ssynhtn/medium/UniquePermutations.permuteUnique:([I)Ljava/util/List;
      39: astore_2
      40: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
      43: aload_2
      44: invokevirtual #37                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      47: return
}

Compiled from "UniquePermutations.kt"
public final class com.ssynhtn.medium.UniquePermutations {
  public com.ssynhtn.medium.UniquePermutations();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

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

  private final void permute(int[], int, java.util.List<java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #45                 // Method checkIncreasing:([II)Z
       6: ifne          10
       9: return
      10: iload_2
      11: aload_1
      12: arraylength
      13: if_icmpne     28
      16: aload_3
      17: aload_1
      18: invokestatic  #48                 // Method kotlin/collections/ArraysKt.toList:([I)Ljava/util/List;
      21: invokeinterface #52,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      26: pop
      27: return
      28: aload_0
      29: aload_1
      30: iload_2
      31: iconst_1
      32: iadd
      33: aload_3
      34: invokespecial #37                 // Method permute:([IILjava/util/List;)V
      37: iload_2
      38: istore        4
      40: iload         4
      42: iconst_1
      43: iadd
      44: istore        5
      46: aload_1
      47: arraylength
      48: istore        6
      50: iload         5
      52: iload         6
      54: if_icmpge     103
      57: aload_1
      58: iload         5
      60: iaload
      61: aload_1
      62: iload         5
      64: iconst_1
      65: isub
      66: iaload
      67: if_icmpeq     97
      70: aload_0
      71: aload_1
      72: iload         4
      74: iload         5
      76: invokespecial #56                 // Method shiftRight:([III)V
      79: aload_0
      80: aload_1
      81: iload_2
      82: iconst_1
      83: iadd
      84: aload_3
      85: invokespecial #37                 // Method permute:([IILjava/util/List;)V
      88: aload_0
      89: aload_1
      90: iload         4
      92: iload         5
      94: invokespecial #59                 // Method shiftLeft:([III)V
      97: iinc          5, 1
     100: goto          50
     103: return

  private final void shiftLeft(int[], int, int);
    Code:
       0: aload_1
       1: iload_2
       2: iaload
       3: istore        4
       5: aload_1
       6: iload_2
       7: iconst_1
       8: iadd
       9: aload_1
      10: iload_2
      11: iload_3
      12: iload_2
      13: isub
      14: invokestatic  #69                 // Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V
      17: aload_1
      18: iload_3
      19: iload         4
      21: iastore
      22: return

  private final void shiftRight(int[], int, int);
    Code:
       0: aload_1
       1: iload_3
       2: iaload
       3: istore        4
       5: aload_1
       6: iload_2
       7: aload_1
       8: iload_2
       9: iconst_1
      10: iadd
      11: iload_3
      12: iload_2
      13: isub
      14: invokestatic  #69                 // Method java/lang/System.arraycopy:(Ljava/lang/Object;ILjava/lang/Object;II)V
      17: aload_1
      18: iload_2
      19: iload         4
      21: iastore
      22: return

  private final boolean checkIncreasing(int[], int);
    Code:
       0: iload_2
       1: istore_3
       2: aload_1
       3: arraylength
       4: iconst_1
       5: isub
       6: istore        4
       8: iload_3
       9: iload         4
      11: if_icmpge     33
      14: aload_1
      15: iload_3
      16: iaload
      17: aload_1
      18: iload_3
      19: iconst_1
      20: iadd
      21: iaload
      22: if_icmple     27
      25: iconst_0
      26: ireturn
      27: iinc          3, 1
      30: goto          8
      33: iconst_1
      34: ireturn

  public final void swap(int[], int, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String nums
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: iload_2
       8: iaload
       9: istore        4
      11: aload_1
      12: iload_2
      13: aload_1
      14: iload_3
      15: iaload
      16: iastore
      17: aload_1
      18: iload_3
      19: iload         4
      21: iastore
      22: return
}


package com.ssynhtn.medium

class NQueens {
    fun solveNQueens2(n: Int): Int {
        val table = Array<CharArray>(n, {i -> CharArray(n)})
        for (i in 0 until n) {
            for (j in 0 until n) {
                table[i][j] = '.'
            }
        }

        return putQueens(table, 0)

    }

    private fun putQueens(table: Array<CharArray>, fixedRows: Int): Int {
        if (fixedRows == table.size) {
            return 1
        }

        var count = 0
        for (col in 0 until table.size) {
            if (checkHasConflictWithPrev(table, fixedRows, col)) continue
            table[fixedRows][col] = 'Q'
            count += putQueens(table, fixedRows + 1)
            table[fixedRows][col] = '.'

        }

        return count
    }

    fun solveNQueens(n: Int): List<List<String>> {
        val table = Array<CharArray>(n, {i -> CharArray(n)})
        for (i in 0 until n) {
            for (j in 0 until n) {
                table[i][j] = '.'
            }
        }

        val collection = mutableListOf<List<String>>()

        putQueens(table, 0, collection)

        return collection

    }

    private fun putQueens(table: Array<CharArray>, fixedRows: Int, collection: MutableList<List<String>>) {
        if (fixedRows == table.size) {
            collection.add(table.map { chs -> String(chs) })
            return
        }

        for (col in 0 until table.size) {
            if (checkHasConflictWithPrev(table, fixedRows, col)) continue
            table[fixedRows][col] = 'Q'
            putQueens(table, fixedRows + 1, collection)
            table[fixedRows][col] = '.'

        }
    }

    private fun checkHasConflictWithPrev(table: Array<CharArray>, row: Int, col: Int): Boolean {
        for (i in 0 until row) {
            var j = col - row + i
            if (j >= 0 && j < table.size) {
                if (table[i][j] == 'Q') {
                    return true
                }
            }
            j = row + col - i
            if (j >= 0 && j < table.size) {
                if (table[i][j] == 'Q') {
                    return true
                }
            }
            j = col
            if (j >= 0 && j < table.size) {
                if (table[i][j] == 'Q') {
                    return true
                }
            }
        }
        return false
    }
}

fun main(args: Array<String>) {
    println(NQueens().solveNQueens2(4))
//    var queenPlacements = NQueens().solveNQueens(4)
//    for (table in queenPlacements) {
//        println(table.joinToString("\n"))
//        println()
//    }
}

Compiled from "NQueens.kt"
public final class com.ssynhtn.medium.NQueensKt {
  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: new           #17                 // class com/ssynhtn/medium/NQueens
       9: dup
      10: invokespecial #21                 // Method com/ssynhtn/medium/NQueens."<init>":()V
      13: iconst_4
      14: invokevirtual #25                 // Method com/ssynhtn/medium/NQueens.solveNQueens2:(I)I
      17: istore_1
      18: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: iload_1
      22: invokevirtual #37                 // Method java/io/PrintStream.println:(I)V
      25: return
}

Compiled from "NQueens.kt"
public final class com.ssynhtn.medium.NQueens {
  public com.ssynhtn.medium.NQueens();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int solveNQueens2(int);
    Code:
       0: iconst_0
       1: istore_3
       2: iload_1
       3: anewarray     #14                 // class "[C"
       6: astore        4
       8: iload_3
       9: iload_1
      10: if_icmpge     30
      13: iload_3
      14: istore        5
      16: aload         4
      18: iload         5
      20: iload_1
      21: newarray       char
      23: aastore
      24: iinc          3, 1
      27: goto          8
      30: aload         4
      32: astore_2
      33: iconst_0
      34: istore_3
      35: iload_3
      36: iload_1
      37: if_icmpge     69
      40: iconst_0
      41: istore        4
      43: iload         4
      45: iload_1
      46: if_icmpge     63
      49: aload_2
      50: iload_3
      51: aaload
      52: iload         4
      54: bipush        46
      56: castore
      57: iinc          4, 1
      60: goto          43
      63: iinc          3, 1
      66: goto          35
      69: aload_0
      70: aload_2
      71: iconst_0
      72: invokespecial #18                 // Method putQueens:([[CI)I
      75: ireturn

  private final int putQueens(char[][], int);
    Code:
       0: iload_2
       1: aload_1
       2: checkcast     #27                 // class "[Ljava/lang/Object;"
       5: arraylength
       6: if_icmpne     11
       9: iconst_1
      10: ireturn
      11: iconst_0
      12: istore_3
      13: iconst_0
      14: istore        4
      16: aload_1
      17: checkcast     #27                 // class "[Ljava/lang/Object;"
      20: arraylength
      21: istore        5
      23: iload         4
      25: iload         5
      27: if_icmpge     74
      30: aload_0
      31: aload_1
      32: iload_2
      33: iload         4
      35: invokespecial #31                 // Method checkHasConflictWithPrev:([[CII)Z
      38: ifne          68
      41: aload_1
      42: iload_2
      43: aaload
      44: iload         4
      46: bipush        81
      48: castore
      49: iload_3
      50: aload_0
      51: aload_1
      52: iload_2
      53: iconst_1
      54: iadd
      55: invokespecial #18                 // Method putQueens:([[CI)I
      58: iadd
      59: istore_3
      60: aload_1
      61: iload_2
      62: aaload
      63: iload         4
      65: bipush        46
      67: castore
      68: iinc          4, 1
      71: goto          23
      74: iload_3
      75: ireturn

  public final java.util.List<java.util.List<java.lang.String>> solveNQueens(int);
    Code:
       0: iconst_0
       1: istore_3
       2: iload_1
       3: anewarray     #14                 // class "[C"
       6: astore        4
       8: iload_3
       9: iload_1
      10: if_icmpge     30
      13: iload_3
      14: istore        5
      16: aload         4
      18: iload         5
      20: iload_1
      21: newarray       char
      23: aastore
      24: iinc          3, 1
      27: goto          8
      30: aload         4
      32: astore_2
      33: iconst_0
      34: istore_3
      35: iload_3
      36: iload_1
      37: if_icmpge     69
      40: iconst_0
      41: istore        4
      43: iload         4
      45: iload_1
      46: if_icmpge     63
      49: aload_2
      50: iload_3
      51: aaload
      52: iload         4
      54: bipush        46
      56: castore
      57: iinc          4, 1
      60: goto          43
      63: iinc          3, 1
      66: goto          35
      69: new           #40                 // class java/util/ArrayList
      72: dup
      73: invokespecial #41                 // Method java/util/ArrayList."<init>":()V
      76: checkcast     #43                 // class java/util/List
      79: astore_3
      80: aload_0
      81: aload_2
      82: iconst_0
      83: aload_3
      84: invokespecial #46                 // Method putQueens:([[CILjava/util/List;)V
      87: aload_3
      88: areturn

  private final void putQueens(char[][], int, java.util.List<java.util.List<java.lang.String>>);
    Code:
       0: iload_2
       1: aload_1
       2: checkcast     #27                 // class "[Ljava/lang/Object;"
       5: arraylength
       6: if_icmpne     120
       9: aload_3
      10: aload_1
      11: checkcast     #27                 // class "[Ljava/lang/Object;"
      14: astore        4
      16: astore        14
      18: iconst_0
      19: istore        5
      21: aload         4
      23: astore        6
      25: new           #40                 // class java/util/ArrayList
      28: dup
      29: aload         4
      31: arraylength
      32: invokespecial #52                 // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #54                 // class java/util/Collection
      38: astore        7
      40: iconst_0
      41: istore        8
      43: iconst_0
      44: istore        9
      46: aload         6
      48: arraylength
      49: istore        10
      51: iload         9
      53: iload         10
      55: if_icmpge     104
      58: aload         6
      60: iload         9
      62: aaload
      63: astore        11
      65: aload         7
      67: aload         11
      69: checkcast     #14                 // class "[C"
      72: astore        12
      74: astore        15
      76: iconst_0
      77: istore        13
      79: new           #56                 // class java/lang/String
      82: dup
      83: aload         12
      85: invokespecial #59                 // Method java/lang/String."<init>":([C)V
      88: nop
      89: aload         15
      91: swap
      92: invokeinterface #63,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: iinc          9, 1
     101: goto          51
     104: aload         7
     106: checkcast     #43                 // class java/util/List
     109: nop
     110: aload         14
     112: swap
     113: invokeinterface #64,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     118: pop
     119: return
     120: iconst_0
     121: istore        4
     123: aload_1
     124: checkcast     #27                 // class "[Ljava/lang/Object;"
     127: arraylength
     128: istore        5
     130: iload         4
     132: iload         5
     134: if_icmpge     179
     137: aload_0
     138: aload_1
     139: iload_2
     140: iload         4
     142: invokespecial #31                 // Method checkHasConflictWithPrev:([[CII)Z
     145: ifne          173
     148: aload_1
     149: iload_2
     150: aaload
     151: iload         4
     153: bipush        81
     155: castore
     156: aload_0
     157: aload_1
     158: iload_2
     159: iconst_1
     160: iadd
     161: aload_3
     162: invokespecial #46                 // Method putQueens:([[CILjava/util/List;)V
     165: aload_1
     166: iload_2
     167: aaload
     168: iload         4
     170: bipush        46
     172: castore
     173: iinc          4, 1
     176: goto          130
     179: return

  private final boolean checkHasConflictWithPrev(char[][], int, int);
    Code:
       0: iconst_0
       1: istore        4
       3: iload         4
       5: iload_2
       6: if_icmpge     121
       9: iload_3
      10: iload_2
      11: isub
      12: iload         4
      14: iadd
      15: istore        5
      17: iload         5
      19: iflt          46
      22: iload         5
      24: aload_1
      25: checkcast     #27                 // class "[Ljava/lang/Object;"
      28: arraylength
      29: if_icmpge     46
      32: aload_1
      33: iload         4
      35: aaload
      36: iload         5
      38: caload
      39: bipush        81
      41: if_icmpne     46
      44: iconst_1
      45: ireturn
      46: iload_2
      47: iload_3
      48: iadd
      49: iload         4
      51: isub
      52: istore        5
      54: iload         5
      56: iflt          83
      59: iload         5
      61: aload_1
      62: checkcast     #27                 // class "[Ljava/lang/Object;"
      65: arraylength
      66: if_icmpge     83
      69: aload_1
      70: iload         4
      72: aaload
      73: iload         5
      75: caload
      76: bipush        81
      78: if_icmpne     83
      81: iconst_1
      82: ireturn
      83: iload_3
      84: istore        5
      86: iload         5
      88: iflt          115
      91: iload         5
      93: aload_1
      94: checkcast     #27                 // class "[Ljava/lang/Object;"
      97: arraylength
      98: if_icmpge     115
     101: aload_1
     102: iload         4
     104: aaload
     105: iload         5
     107: caload
     108: bipush        81
     110: if_icmpne     115
     113: iconst_1
     114: ireturn
     115: iinc          4, 1
     118: goto          3
     121: iconst_0
     122: ireturn
}


package com.ssynhtn.medium

class MaximumSubarray {
    fun maxSubArrayDivConquer(nums: IntArray): Int {
        return maxSubArrayDivConquer(nums, 0, nums.size)[0] // max, left max, right max, total, each requiring at least length one
    }

    // end > start
    fun maxSubArrayDivConquer(nums: IntArray, start: Int, end: Int): IntArray {
        if (end - start == 1) {
            val ans = nums[start]
            return intArrayOf(ans, ans, ans, ans)
        }

        val mid = (start + end) / 2
        val max1 = maxSubArrayDivConquer(nums, start, mid)
        val max2 = maxSubArrayDivConquer(nums, mid, end)

//        val total = max1[3] + max2[3]
//        val leftMax = Math.max(max1[1], max1[3] + max2[1])
//        val rightMax = Math.max(max2[2], max2[3] + max1[2])
//        val max = Math.max(max1[0], Math.max(max2[0], max1[2] + max2[1]))

        max1[0] = Math.max(max1[0], Math.max(max2[0], max1[2] + max2[1]))
        max1[1] = Math.max(max1[1], max1[3] + max2[1])
        max1[2] = Math.max(max2[2], max2[3] + max1[2])
        max1[3] = max1[3] + max2[3]

        return max1

    }

    fun maxSubArray(nums: IntArray): Int {
        var max = Int.MIN_VALUE

        var sum = 0
        for (num in nums) {
            if (num > max) {
                max = num
            }

            sum += num
            if (sum > max) {
                max = sum
            }

            if (sum < 0) {
                sum = 0
            }
        }

        return max
    }
}

fun main(args: Array<String>) {
    println(MaximumSubarray().maxSubArrayDivConquer(intArrayOf(-2,1,-3,4,-1,2,1,-5,4)))
    println(MaximumSubarray().maxSubArrayDivConquer(intArrayOf(1)))
    println(MaximumSubarray().maxSubArrayDivConquer(intArrayOf(0)))
    println(MaximumSubarray().maxSubArrayDivConquer(intArrayOf(-1)))
    println(MaximumSubarray().maxSubArrayDivConquer(intArrayOf(-2147483647)))
}

Compiled from "MaximumSubarray.kt"
public final class com.ssynhtn.medium.MaximumSubarray {
  public com.ssynhtn.medium.MaximumSubarray();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int maxSubArrayDivConquer(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: aload_1
      10: arraylength
      11: invokevirtual #24                 // Method maxSubArrayDivConquer:([III)[I
      14: iconst_0
      15: iaload
      16: ireturn

  public final int[] maxSubArrayDivConquer(int[], int, int);
    Code:
       0: aload_1
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_3
       7: iload_2
       8: isub
       9: iconst_1
      10: if_icmpne     50
      13: aload_1
      14: iload_2
      15: iaload
      16: istore        4
      18: iconst_4
      19: newarray       int
      21: astore        5
      23: aload         5
      25: iconst_0
      26: iload         4
      28: iastore
      29: aload         5
      31: iconst_1
      32: iload         4
      34: iastore
      35: aload         5
      37: iconst_2
      38: iload         4
      40: iastore
      41: aload         5
      43: iconst_3
      44: iload         4
      46: iastore
      47: aload         5
      49: areturn
      50: iload_2
      51: iload_3
      52: iadd
      53: iconst_2
      54: idiv
      55: istore        4
      57: aload_0
      58: aload_1
      59: iload_2
      60: iload         4
      62: invokevirtual #24                 // Method maxSubArrayDivConquer:([III)[I
      65: astore        5
      67: aload_0
      68: aload_1
      69: iload         4
      71: iload_3
      72: invokevirtual #24                 // Method maxSubArrayDivConquer:([III)[I
      75: astore        6
      77: aload         5
      79: iconst_0
      80: aload         5
      82: iconst_0
      83: iaload
      84: aload         6
      86: iconst_0
      87: iaload
      88: aload         5
      90: iconst_2
      91: iaload
      92: aload         6
      94: iconst_1
      95: iaload
      96: iadd
      97: invokestatic  #31                 // Method java/lang/Math.max:(II)I
     100: invokestatic  #31                 // Method java/lang/Math.max:(II)I
     103: iastore
     104: aload         5
     106: iconst_1
     107: aload         5
     109: iconst_1
     110: iaload
     111: aload         5
     113: iconst_3
     114: iaload
     115: aload         6
     117: iconst_1
     118: iaload
     119: iadd
     120: invokestatic  #31                 // Method java/lang/Math.max:(II)I
     123: iastore
     124: aload         5
     126: iconst_2
     127: aload         6
     129: iconst_2
     130: iaload
     131: aload         6
     133: iconst_3
     134: iaload
     135: aload         5
     137: iconst_2
     138: iaload
     139: iadd
     140: invokestatic  #31                 // Method java/lang/Math.max:(II)I
     143: iastore
     144: aload         5
     146: iconst_3
     147: aload         5
     149: iconst_3
     150: iaload
     151: aload         6
     153: iconst_3
     154: iaload
     155: iadd
     156: iastore
     157: aload         5
     159: areturn

  public final int maxSubArray(int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String nums
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: ldc           #40                 // int -2147483648
       8: istore_2
       9: iconst_0
      10: istore_3
      11: iconst_0
      12: istore        4
      14: aload_1
      15: arraylength
      16: istore        5
      18: iload         4
      20: iload         5
      22: if_icmpge     64
      25: aload_1
      26: iload         4
      28: iaload
      29: istore        6
      31: iload         6
      33: iload_2
      34: if_icmple     40
      37: iload         6
      39: istore_2
      40: iload_3
      41: iload         6
      43: iadd
      44: istore_3
      45: iload_3
      46: iload_2
      47: if_icmple     52
      50: iload_3
      51: istore_2
      52: iload_3
      53: ifge          58
      56: iconst_0
      57: istore_3
      58: iinc          4, 1
      61: goto          18
      64: iload_2
      65: ireturn
}

Compiled from "MaximumSubarray.kt"
public final class com.ssynhtn.medium.MaximumSubarrayKt {
  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: new           #17                 // class com/ssynhtn/medium/MaximumSubarray
       9: dup
      10: invokespecial #21                 // Method com/ssynhtn/medium/MaximumSubarray."<init>":()V
      13: bipush        9
      15: newarray       int
      17: astore_1
      18: aload_1
      19: iconst_0
      20: bipush        -2
      22: iastore
      23: aload_1
      24: iconst_1
      25: iconst_1
      26: iastore
      27: aload_1
      28: iconst_2
      29: bipush        -3
      31: iastore
      32: aload_1
      33: iconst_3
      34: iconst_4
      35: iastore
      36: aload_1
      37: iconst_4
      38: iconst_m1
      39: iastore
      40: aload_1
      41: iconst_5
      42: iconst_2
      43: iastore
      44: aload_1
      45: bipush        6
      47: iconst_1
      48: iastore
      49: aload_1
      50: bipush        7
      52: bipush        -5
      54: iastore
      55: aload_1
      56: bipush        8
      58: iconst_4
      59: iastore
      60: aload_1
      61: invokevirtual #25                 // Method com/ssynhtn/medium/MaximumSubarray.maxSubArrayDivConquer:([I)I
      64: istore_1
      65: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
      68: iload_1
      69: invokevirtual #37                 // Method java/io/PrintStream.println:(I)V
      72: new           #17                 // class com/ssynhtn/medium/MaximumSubarray
      75: dup
      76: invokespecial #21                 // Method com/ssynhtn/medium/MaximumSubarray."<init>":()V
      79: iconst_1
      80: newarray       int
      82: astore_1
      83: aload_1
      84: iconst_0
      85: iconst_1
      86: iastore
      87: aload_1
      88: invokevirtual #25                 // Method com/ssynhtn/medium/MaximumSubarray.maxSubArrayDivConquer:([I)I
      91: istore_1
      92: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
      95: iload_1
      96: invokevirtual #37                 // Method java/io/PrintStream.println:(I)V
      99: new           #17                 // class com/ssynhtn/medium/MaximumSubarray
     102: dup
     103: invokespecial #21                 // Method com/ssynhtn/medium/MaximumSubarray."<init>":()V
     106: iconst_1
     107: newarray       int
     109: astore_1
     110: aload_1
     111: iconst_0
     112: iconst_0
     113: iastore
     114: aload_1
     115: invokevirtual #25                 // Method com/ssynhtn/medium/MaximumSubarray.maxSubArrayDivConquer:([I)I
     118: istore_1
     119: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
     122: iload_1
     123: invokevirtual #37                 // Method java/io/PrintStream.println:(I)V
     126: new           #17                 // class com/ssynhtn/medium/MaximumSubarray
     129: dup
     130: invokespecial #21                 // Method com/ssynhtn/medium/MaximumSubarray."<init>":()V
     133: iconst_1
     134: newarray       int
     136: astore_1
     137: aload_1
     138: iconst_0
     139: iconst_m1
     140: iastore
     141: aload_1
     142: invokevirtual #25                 // Method com/ssynhtn/medium/MaximumSubarray.maxSubArrayDivConquer:([I)I
     145: istore_1
     146: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
     149: iload_1
     150: invokevirtual #37                 // Method java/io/PrintStream.println:(I)V
     153: new           #17                 // class com/ssynhtn/medium/MaximumSubarray
     156: dup
     157: invokespecial #21                 // Method com/ssynhtn/medium/MaximumSubarray."<init>":()V
     160: iconst_1
     161: newarray       int
     163: astore_1
     164: aload_1
     165: iconst_0
     166: ldc           #38                 // int -2147483647
     168: iastore
     169: aload_1
     170: invokevirtual #25                 // Method com/ssynhtn/medium/MaximumSubarray.maxSubArrayDivConquer:([I)I
     173: istore_1
     174: getstatic     #31                 // Field java/lang/System.out:Ljava/io/PrintStream;
     177: iload_1
     178: invokevirtual #37                 // Method java/io/PrintStream.println:(I)V
     181: return
}