fun main() {
    print("Enter the two matrices line separated: \n")
    val size = 3

    val a = readMatrix(size)
    readln()
    val b = readMatrix(size)

    val c = addMatrices(a, b)
    println("Result of adding the matrices: \n")
    printMatrix(c)
}

// Takes number of rows and columns and reads the matrix from input
fun readMatrix(rows : Int): ArrayList<ArrayList<Int>>{
    val matrix = arrayListOf<ArrayList<Int>>()
    for(row in 0 until rows){
        val line = readln().trim().split(' ')
        matrix.add(ArrayList())
        for(number in line){
            matrix[row].add(Integer.valueOf(number))
        }
    }
    return matrix
}

// prints a matrix
fun printMatrix(matrix : ArrayList<ArrayList<Int>>){
    for (row in matrix){
        for (cell in row){
            print("$cell ")
        }
        println()
    }
}

// adds two matrices and return the result in a new matrix
fun addMatrices(a : ArrayList<ArrayList<Int>>, b : ArrayList<ArrayList<Int>>) : ArrayList<ArrayList<Int>>{
    val c = a.clone() as ArrayList<ArrayList<Int>>
    for(i in 0 until b.size){
        for(j in 0 until b.size){
            c[i][j] += b[i][j]
        }
    }
    return c
}

Compiled from "AddTwoMatrices.kt"
public final class AddTwoMatricesKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String Enter the two matrices line separated: \n
       2: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
       5: swap
       6: invokevirtual #20                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
       9: iconst_3
      10: istore_0
      11: iload_0
      12: invokestatic  #24                 // Method readMatrix:(I)Ljava/util/ArrayList;
      15: astore_1
      16: invokestatic  #30                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
      19: pop
      20: iload_0
      21: invokestatic  #24                 // Method readMatrix:(I)Ljava/util/ArrayList;
      24: astore_2
      25: aload_1
      26: aload_2
      27: invokestatic  #34                 // Method addMatrices:(Ljava/util/ArrayList;Ljava/util/ArrayList;)Ljava/util/ArrayList;
      30: astore_3
      31: ldc           #36                 // String Result of adding the matrices: \n
      33: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #39                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: aload_3
      41: invokestatic  #43                 // Method printMatrix:(Ljava/util/ArrayList;)V
      44: return

  public static final java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> readMatrix(int);
    Code:
       0: new           #53                 // class java/util/ArrayList
       3: dup
       4: invokespecial #56                 // Method java/util/ArrayList."<init>":()V
       7: astore_1
       8: iconst_0
       9: istore_2
      10: iload_2
      11: iload_0
      12: if_icmpge     120
      15: invokestatic  #30                 // Method kotlin/io/ConsoleKt.readln:()Ljava/lang/String;
      18: checkcast     #58                 // class java/lang/CharSequence
      21: invokestatic  #64                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      24: invokevirtual #67                 // Method java/lang/Object.toString:()Ljava/lang/String;
      27: checkcast     #58                 // class java/lang/CharSequence
      30: iconst_1
      31: newarray       char
      33: astore        4
      35: aload         4
      37: iconst_0
      38: bipush        32
      40: castore
      41: aload         4
      43: iconst_0
      44: iconst_0
      45: bipush        6
      47: aconst_null
      48: invokestatic  #71                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      51: astore_3
      52: aload_1
      53: new           #53                 // class java/util/ArrayList
      56: dup
      57: invokespecial #56                 // Method java/util/ArrayList."<init>":()V
      60: invokevirtual #75                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      63: pop
      64: aload_3
      65: invokeinterface #81,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      70: astore        4
      72: aload         4
      74: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      79: ifeq          114
      82: aload         4
      84: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      89: checkcast     #93                 // class java/lang/String
      92: astore        5
      94: aload_1
      95: iload_2
      96: invokevirtual #97                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      99: checkcast     #53                 // class java/util/ArrayList
     102: aload         5
     104: invokestatic  #103                // Method java/lang/Integer.valueOf:(Ljava/lang/String;)Ljava/lang/Integer;
     107: invokevirtual #75                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     110: pop
     111: goto          72
     114: iinc          2, 1
     117: goto          10
     120: aload_1
     121: areturn

  public static final void printMatrix(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #112                // String matrix
       3: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #119                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
      10: dup
      11: ldc           #121                // String iterator(...)
      13: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      16: astore_1
      17: aload_1
      18: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          121
      26: aload_1
      27: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: dup
      33: ldc           #126                // String next(...)
      35: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      38: checkcast     #53                 // class java/util/ArrayList
      41: astore_2
      42: aload_2
      43: invokevirtual #119                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
      46: dup
      47: ldc           #121                // String iterator(...)
      49: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      52: astore_3
      53: aload_3
      54: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          112
      62: aload_3
      63: invokeinterface #91,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: dup
      69: ldc           #126                // String next(...)
      71: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      74: checkcast     #128                // class java/lang/Number
      77: invokevirtual #132                // Method java/lang/Number.intValue:()I
      80: istore        4
      82: new           #134                // class java/lang/StringBuilder
      85: dup
      86: invokespecial #135                // Method java/lang/StringBuilder."<init>":()V
      89: iload         4
      91: invokevirtual #139                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      94: bipush        32
      96: invokevirtual #142                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      99: invokevirtual #143                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     102: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     105: swap
     106: invokevirtual #20                 // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     109: goto          53
     112: getstatic     #14                 // Field java/lang/System.out:Ljava/io/PrintStream;
     115: invokevirtual #145                // Method java/io/PrintStream.println:()V
     118: goto          17
     121: return

  public static final java.util.ArrayList<java.util.ArrayList<java.lang.Integer>> addMatrices(java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>, java.util.ArrayList<java.util.ArrayList<java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #148                // String a
       3: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #149                // String b
       9: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #152                // Method java/util/ArrayList.clone:()Ljava/lang/Object;
      16: dup
      17: ldc           #154                // String null cannot be cast to non-null type java.util.ArrayList<java.util.ArrayList<kotlin.Int>>
      19: invokestatic  #157                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      22: checkcast     #53                 // class java/util/ArrayList
      25: astore_2
      26: iconst_0
      27: istore_3
      28: aload_1
      29: invokevirtual #159                // Method java/util/ArrayList.size:()I
      32: istore        4
      34: iload_3
      35: iload         4
      37: if_icmpge     132
      40: iconst_0
      41: istore        5
      43: aload_1
      44: invokevirtual #159                // Method java/util/ArrayList.size:()I
      47: istore        6
      49: iload         5
      51: iload         6
      53: if_icmpge     126
      56: aload_2
      57: iload_3
      58: invokevirtual #97                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      61: checkcast     #53                 // class java/util/ArrayList
      64: astore        7
      66: iload         5
      68: istore        8
      70: aload         7
      72: iload         8
      74: aload         7
      76: iload         8
      78: invokevirtual #97                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      81: checkcast     #128                // class java/lang/Number
      84: invokevirtual #132                // Method java/lang/Number.intValue:()I
      87: aload_1
      88: iload_3
      89: invokevirtual #97                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
      92: checkcast     #53                 // class java/util/ArrayList
      95: iload         5
      97: invokevirtual #97                 // Method java/util/ArrayList.get:(I)Ljava/lang/Object;
     100: dup
     101: ldc           #161                // String get(...)
     103: invokestatic  #124                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     106: checkcast     #128                // class java/lang/Number
     109: invokevirtual #132                // Method java/lang/Number.intValue:()I
     112: iadd
     113: invokestatic  #164                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     116: invokevirtual #168                // Method java/util/ArrayList.set:(ILjava/lang/Object;)Ljava/lang/Object;
     119: pop
     120: iinc          5, 1
     123: goto          49
     126: iinc          3, 1
     129: goto          34
     132: aload_2
     133: areturn

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


import java.io.File
import java.lang.Integer.max
import kotlin.math.absoluteValue

fun main() {
    val seatLayout = File("src/main/kotlin/day11/day11-input.txt").readLines().map { it.toCharArray() }

    var current = seatLayout
    var currentHashCode = current.contentHashCode()
    val found = mutableSetOf<Int>()

    while (!found.contains(currentHashCode)) {
        found.add(currentHashCode)
        current = current.nextSeatLayout()
        currentHashCode = current.contentHashCode()
    }

    println("Answer 1: " + current.occupiedSeatCount())
}

private fun List<CharArray>.contentHashCode(): Int =
    fold(0) { result, line -> result + 31 * line.contentHashCode() }

private fun List<CharArray>.nextSeatLayout(): List<CharArray> {
    val next = toMutableList().map { it.clone() }
    for (row in 0 until size) {
        for (column in 0 until width()) {
            when (get(row)[column]) {
                'L' -> if (noSeatsAround(row, column)) {
                    next[row][column] = '#'
                }
                '#' -> if (atLeastFourSeatsAround(row, column)) {
                    next[row][column] = 'L'
                }
            }
        }
    }
    return next
}

private fun List<CharArray>.width() = first().size

private fun List<CharArray>.noSeatsAround(row: Int, column: Int) = forSeatsAround(row, column, true) { false }

private fun List<CharArray>.atLeastFourSeatsAround(row: Int, column: Int): Boolean {
    var count = 0
    return forSeatsAround(row, column, false) {
        count += 1
        if (count == 4) true else null
    }
}

private fun List<CharArray>.forSeatsAround(row: Int, column: Int, default: Boolean, block: List<CharArray>.() -> Boolean?): Boolean {
    for (dx in -1..1) {
        for (dy in -1..1) {
            val x = column + dy
            val y = row + dx
            if (!(x == column && y == row) && x >= 0 && x < width() && y >= 0 && y < size && get(y)[x] == '#') {
                val result = block()
                if (result != null) {
                    return result
                }
            }
        }
    }
    return default
}

private fun List<CharArray>.occupiedSeatCount() = map { row -> row.count { it == '#' } }.sum()

fun List<CharArray>.print() {
    forEach { println(it.joinToString("")) }
}

Compiled from "Day11.kt"
public final class Day11Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/kotlin/day11/day11-input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #22                 // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #24                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #35                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          109
      62: aload         6
      64: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #51                 // class java/lang/String
      78: astore        8
      80: astore        10
      82: iconst_0
      83: istore        9
      85: aload         8
      87: invokevirtual #55                 // Method java/lang/String.toCharArray:()[C
      90: dup
      91: ldc           #57                 // String toCharArray(...)
      93: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      96: nop
      97: aload         10
      99: swap
     100: invokeinterface #67,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     105: pop
     106: goto          52
     109: aload         4
     111: checkcast     #69                 // class java/util/List
     114: nop
     115: astore_0
     116: aload_0
     117: astore_1
     118: aload_1
     119: invokestatic  #73                 // Method contentHashCode:(Ljava/util/List;)I
     122: istore_2
     123: new           #75                 // class java/util/LinkedHashSet
     126: dup
     127: invokespecial #77                 // Method java/util/LinkedHashSet."<init>":()V
     130: checkcast     #79                 // class java/util/Set
     133: astore_3
     134: aload_3
     135: iload_2
     136: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     139: invokeinterface #88,  2           // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     144: ifne          171
     147: aload_3
     148: iload_2
     149: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: invokeinterface #89,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     157: pop
     158: aload_1
     159: invokestatic  #93                 // Method nextSeatLayout:(Ljava/util/List;)Ljava/util/List;
     162: astore_1
     163: aload_1
     164: invokestatic  #73                 // Method contentHashCode:(Ljava/util/List;)I
     167: istore_2
     168: goto          134
     171: new           #95                 // class java/lang/StringBuilder
     174: dup
     175: invokespecial #96                 // Method java/lang/StringBuilder."<init>":()V
     178: ldc           #98                 // String Answer 1:
     180: invokevirtual #102                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     183: aload_1
     184: invokestatic  #105                // Method occupiedSeatCount:(Ljava/util/List;)I
     187: invokevirtual #108                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     190: invokevirtual #112                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     193: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
     196: swap
     197: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     200: return

  private static final int contentHashCode(java.util.List<char[]>);
    Code:
       0: aload_0
       1: checkcast     #22                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: iload_2
      10: istore        4
      12: aload_1
      13: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore        5
      20: aload         5
      22: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          69
      30: aload         5
      32: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: astore        6
      39: iload         4
      41: aload         6
      43: checkcast     #146                // class "[C"
      46: astore        7
      48: istore        8
      50: iconst_0
      51: istore        9
      53: iload         8
      55: bipush        31
      57: aload         7
      59: invokestatic  #152                // Method java/util/Arrays.hashCode:([C)I
      62: imul
      63: iadd
      64: istore        4
      66: goto          20
      69: iload         4
      71: ireturn

  private static final java.util.List<char[]> nextSeatLayout(java.util.List<char[]>);
    Code:
       0: aload_0
       1: checkcast     #35                 // class java/util/Collection
       4: invokestatic  #166                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
       7: checkcast     #22                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #24                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #35                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          99
      56: aload         7
      58: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #146                // class "[C"
      72: astore        9
      74: astore        11
      76: iconst_0
      77: istore        10
      79: aload         9
      81: invokevirtual #169                // Method java/lang/Object.clone:()Ljava/lang/Object;
      84: checkcast     #146                // class "[C"
      87: aload         11
      89: swap
      90: invokeinterface #67,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: goto          46
      99: aload         5
     101: checkcast     #69                 // class java/util/List
     104: nop
     105: astore_1
     106: iconst_0
     107: istore_2
     108: aload_0
     109: invokeinterface #173,  1          // InterfaceMethod java/util/List.size:()I
     114: istore_3
     115: iload_2
     116: iload_3
     117: if_icmpge     241
     120: iconst_0
     121: istore        4
     123: aload_0
     124: invokestatic  #176                // Method width:(Ljava/util/List;)I
     127: istore        5
     129: iload         4
     131: iload         5
     133: if_icmpge     235
     136: aload_0
     137: iload_2
     138: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     143: checkcast     #146                // class "[C"
     146: iload         4
     148: caload
     149: lookupswitch  { // 2
                    35: 204
                    76: 176
               default: 229
          }
     176: aload_0
     177: iload_2
     178: iload         4
     180: invokestatic  #184                // Method noSeatsAround:(Ljava/util/List;II)Z
     183: ifeq          229
     186: aload_1
     187: iload_2
     188: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     193: checkcast     #146                // class "[C"
     196: iload         4
     198: bipush        35
     200: castore
     201: goto          229
     204: aload_0
     205: iload_2
     206: iload         4
     208: invokestatic  #187                // Method atLeastFourSeatsAround:(Ljava/util/List;II)Z
     211: ifeq          229
     214: aload_1
     215: iload_2
     216: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     221: checkcast     #146                // class "[C"
     224: iload         4
     226: bipush        76
     228: castore
     229: iinc          4, 1
     232: goto          129
     235: iinc          2, 1
     238: goto          115
     241: aload_1
     242: areturn

  private static final int width(java.util.List<char[]>);
    Code:
       0: aload_0
       1: invokestatic  #195                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
       4: checkcast     #146                // class "[C"
       7: arraylength
       8: ireturn

  private static final boolean noSeatsAround(java.util.List<char[]>, int, int);
    Code:
       0: aload_0
       1: iload_1
       2: iload_2
       3: iconst_1
       4: invokedynamic #216,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       9: invokestatic  #220                // Method forSeatsAround:(Ljava/util/List;IIZLkotlin/jvm/functions/Function1;)Z
      12: ireturn

  private static final boolean atLeastFourSeatsAround(java.util.List<char[]>, int, int);
    Code:
       0: new           #223                // class kotlin/jvm/internal/Ref$IntRef
       3: dup
       4: invokespecial #224                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
       7: astore_3
       8: aload_0
       9: iload_1
      10: iload_2
      11: iconst_0
      12: aload_3
      13: invokedynamic #232,  0            // InvokeDynamic #1:invoke:(Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function1;
      18: invokestatic  #220                // Method forSeatsAround:(Ljava/util/List;IIZLkotlin/jvm/functions/Function1;)Z
      21: ireturn

  private static final boolean forSeatsAround(java.util.List<char[]>, int, int, boolean, kotlin.jvm.functions.Function1<? super java.util.List<char[]>, java.lang.Boolean>);
    Code:
       0: iconst_m1
       1: istore        5
       3: iload         5
       5: iconst_2
       6: if_icmpge     127
       9: iconst_m1
      10: istore        6
      12: iload         6
      14: iconst_2
      15: if_icmpge     121
      18: iload_2
      19: iload         6
      21: iadd
      22: istore        7
      24: iload_1
      25: iload         5
      27: iadd
      28: istore        8
      30: iload         7
      32: iload_2
      33: if_icmpne     42
      36: iload         8
      38: iload_1
      39: if_icmpeq     115
      42: iload         7
      44: iflt          115
      47: iload         7
      49: aload_0
      50: invokestatic  #176                // Method width:(Ljava/util/List;)I
      53: if_icmpge     115
      56: iload         8
      58: iflt          115
      61: iload         8
      63: aload_0
      64: invokeinterface #173,  1          // InterfaceMethod java/util/List.size:()I
      69: if_icmpge     115
      72: aload_0
      73: iload         8
      75: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      80: checkcast     #146                // class "[C"
      83: iload         7
      85: caload
      86: bipush        35
      88: if_icmpne     115
      91: aload         4
      93: aload_0
      94: invokeinterface #240,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      99: checkcast     #242                // class java/lang/Boolean
     102: astore        9
     104: aload         9
     106: ifnull        115
     109: aload         9
     111: invokevirtual #245                // Method java/lang/Boolean.booleanValue:()Z
     114: ireturn
     115: iinc          6, 1
     118: goto          12
     121: iinc          5, 1
     124: goto          3
     127: iload_3
     128: ireturn

  private static final int occupiedSeatCount(java.util.List<char[]>);
    Code:
       0: aload_0
       1: checkcast     #22                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #24                 // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #35                 // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          152
      48: aload         6
      50: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #146                // class "[C"
      64: astore        8
      66: astore        18
      68: iconst_0
      69: istore        9
      71: aload         8
      73: astore        10
      75: iconst_0
      76: istore        11
      78: iconst_0
      79: istore        12
      81: iconst_0
      82: istore        13
      84: aload         10
      86: arraylength
      87: istore        14
      89: iload         13
      91: iload         14
      93: if_icmpge     134
      96: aload         10
      98: iload         13
     100: caload
     101: istore        15
     103: iload         15
     105: istore        16
     107: iconst_0
     108: istore        17
     110: iload         16
     112: bipush        35
     114: if_icmpne     121
     117: iconst_1
     118: goto          122
     121: iconst_0
     122: ifeq          128
     125: iinc          12, 1
     128: iinc          13, 1
     131: goto          89
     134: iload         12
     136: nop
     137: invokestatic  #85                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     140: aload         18
     142: swap
     143: invokeinterface #67,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: goto          38
     152: aload         4
     154: checkcast     #69                 // class java/util/List
     157: nop
     158: checkcast     #22                 // class java/lang/Iterable
     161: invokestatic  #259                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     164: ireturn

  public static final void print(java.util.List<char[]>);
    Code:
       0: aload_0
       1: ldc_w         #272                // String <this>
       4: invokestatic  #275                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #22                 // class java/lang/Iterable
      11: astore_1
      12: iconst_0
      13: istore_2
      14: aload_1
      15: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      20: astore_3
      21: aload_3
      22: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          79
      30: aload_3
      31: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      36: astore        4
      38: aload         4
      40: checkcast     #146                // class "[C"
      43: astore        5
      45: iconst_0
      46: istore        6
      48: aload         5
      50: ldc_w         #277                // String
      53: checkcast     #279                // class java/lang/CharSequence
      56: aconst_null
      57: aconst_null
      58: iconst_0
      59: aconst_null
      60: aconst_null
      61: bipush        62
      63: aconst_null
      64: invokestatic  #285                // Method kotlin/collections/ArraysKt.joinToString$default:([CLjava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      67: getstatic     #118                // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #124                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: nop
      75: nop
      76: goto          21
      79: nop
      80: return

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

  private static final java.lang.Boolean noSeatsAround$lambda$3(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #295                // String $this$forSeatsAround
       4: invokestatic  #275                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: iconst_0
       8: invokestatic  #298                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      11: areturn

  private static final java.lang.Boolean atLeastFourSeatsAround$lambda$4(kotlin.jvm.internal.Ref$IntRef, java.util.List);
    Code:
       0: aload_1
       1: ldc_w         #295                // String $this$forSeatsAround
       4: invokestatic  #275                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_0
       9: getfield      #301                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      12: iconst_1
      13: iadd
      14: putfield      #301                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      17: aload_0
      18: getfield      #301                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      21: iconst_4
      22: if_icmpne     32
      25: iconst_1
      26: invokestatic  #298                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
      29: goto          33
      32: aconst_null
      33: areturn
}


// https://leetcode.com/problems/unique-paths-ii
fun uniquePathsWithObstacles(obstacleGrid: Array<IntArray>): Int {
    val lastRowIndex = obstacleGrid.lastIndex
    val lastColIndex = obstacleGrid.first().lastIndex
    val hasObstacle = obstacleGrid[lastRowIndex][lastColIndex] == 1
    obstacleGrid[lastRowIndex][lastColIndex] = if (hasObstacle) 0 else 1
    for (rowIndex in lastRowIndex - 1 downTo 0) {
        val row = obstacleGrid[rowIndex]
        if (row[lastColIndex] == 1 || obstacleGrid[rowIndex + 1][lastColIndex] == 0) {
            row[lastColIndex] = 0
        } else {
            row[lastColIndex] = 1
        }
    }
    for (colIndex in lastColIndex - 1 downTo 0) {
        val row = obstacleGrid.last()
        if (row[colIndex] == 1 || row[colIndex + 1] == 0) {
            row[colIndex] = 0
        } else {
            row[colIndex] = 1
        }
    }
    for (rowIndex in lastRowIndex - 1 downTo 0) {
        for (colIndex in lastColIndex - 1 downTo 0) {
            if (obstacleGrid[rowIndex][colIndex] == 1) {
                obstacleGrid[rowIndex][colIndex] = 0
            } else {
                obstacleGrid[rowIndex][colIndex] = obstacleGrid[rowIndex + 1][colIndex] + obstacleGrid[rowIndex][colIndex + 1]
            }
        }
    }
    return obstacleGrid[0][0]
}

Compiled from "_0063_UniquePathsII.kt"
public final class _0063_UniquePathsIIKt {
  public static final int uniquePathsWithObstacles(int[][]);
    Code:
       0: aload_0
       1: ldc           #9                  // String obstacleGrid
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class "[Ljava/lang/Object;"
      10: invokestatic  #23                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      13: istore_1
      14: aload_0
      15: checkcast     #17                 // class "[Ljava/lang/Object;"
      18: invokestatic  #27                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      21: checkcast     #29                 // class "[I"
      24: invokestatic  #32                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      27: istore_2
      28: aload_0
      29: iload_1
      30: aaload
      31: iload_2
      32: iaload
      33: iconst_1
      34: if_icmpne     41
      37: iconst_1
      38: goto          42
      41: iconst_0
      42: istore_3
      43: aload_0
      44: iload_1
      45: aaload
      46: iload_2
      47: iload_3
      48: ifeq          55
      51: iconst_0
      52: goto          56
      55: iconst_1
      56: iastore
      57: iload_1
      58: iconst_1
      59: isub
      60: istore        4
      62: iconst_m1
      63: iload         4
      65: if_icmpge     112
      68: aload_0
      69: iload         4
      71: aaload
      72: astore        5
      74: aload         5
      76: iload_2
      77: iaload
      78: iconst_1
      79: if_icmpeq     93
      82: aload_0
      83: iload         4
      85: iconst_1
      86: iadd
      87: aaload
      88: iload_2
      89: iaload
      90: ifne          101
      93: aload         5
      95: iload_2
      96: iconst_0
      97: iastore
      98: goto          106
     101: aload         5
     103: iload_2
     104: iconst_1
     105: iastore
     106: iinc          4, -1
     109: goto          62
     112: iload_2
     113: iconst_1
     114: isub
     115: istore        4
     117: iconst_m1
     118: iload         4
     120: if_icmpge     175
     123: aload_0
     124: checkcast     #17                 // class "[Ljava/lang/Object;"
     127: invokestatic  #35                 // Method kotlin/collections/ArraysKt.last:([Ljava/lang/Object;)Ljava/lang/Object;
     130: checkcast     #29                 // class "[I"
     133: astore        5
     135: aload         5
     137: iload         4
     139: iaload
     140: iconst_1
     141: if_icmpeq     154
     144: aload         5
     146: iload         4
     148: iconst_1
     149: iadd
     150: iaload
     151: ifne          163
     154: aload         5
     156: iload         4
     158: iconst_0
     159: iastore
     160: goto          169
     163: aload         5
     165: iload         4
     167: iconst_1
     168: iastore
     169: iinc          4, -1
     172: goto          117
     175: iload_1
     176: iconst_1
     177: isub
     178: istore        4
     180: iconst_m1
     181: iload         4
     183: if_icmpge     257
     186: iload_2
     187: iconst_1
     188: isub
     189: istore        5
     191: iconst_m1
     192: iload         5
     194: if_icmpge     251
     197: aload_0
     198: iload         4
     200: aaload
     201: iload         5
     203: iaload
     204: iconst_1
     205: if_icmpne     219
     208: aload_0
     209: iload         4
     211: aaload
     212: iload         5
     214: iconst_0
     215: iastore
     216: goto          245
     219: aload_0
     220: iload         4
     222: aaload
     223: iload         5
     225: aload_0
     226: iload         4
     228: iconst_1
     229: iadd
     230: aaload
     231: iload         5
     233: iaload
     234: aload_0
     235: iload         4
     237: aaload
     238: iload         5
     240: iconst_1
     241: iadd
     242: iaload
     243: iadd
     244: iastore
     245: iinc          5, -1
     248: goto          191
     251: iinc          4, -1
     254: goto          180
     257: aload_0
     258: iconst_0
     259: aaload
     260: iconst_0
     261: iaload
     262: ireturn
}


// https://leetcode.com/problems/combination-sum
fun combinationSum(candidates: IntArray, target: Int): List<List<Int>> {
    return mutableListOf<List<Int>>().also {
        buildCombinations(candidates, startIndex = 0, target = target, combination = mutableListOf(), combinations = it)
    }
}

private fun buildCombinations(
    candidates: IntArray,
    startIndex: Int,
    target: Int,
    combination: MutableList<Int>,
    combinations: MutableList<List<Int>>
) {
    if (target == 0) {
        combinations.add(combination.toList())
        return
    }
    for (index in startIndex..candidates.lastIndex) {
        val candidate = candidates[index]
        if (candidate <= target) {
            combination.add(candidate)
            buildCombinations(
                candidates = candidates,
                startIndex = index,
                target = target - candidate,
                combination = combination,
                combinations = combinations
            )
            combination.removeLast()
        }
    }
}

Compiled from "_0039_CombinationSum.kt"
public final class _0039_CombinationSumKt {
  public static final java.util.List<java.util.List<java.lang.Integer>> combinationSum(int[], int);
    Code:
       0: aload_0
       1: ldc           #10                 // String candidates
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/ArrayList
       9: dup
      10: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #24                 // class java/util/List
      16: astore_2
      17: aload_2
      18: astore_3
      19: iconst_0
      20: istore        4
      22: aload_0
      23: iconst_0
      24: iload_1
      25: new           #18                 // class java/util/ArrayList
      28: dup
      29: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      32: checkcast     #24                 // class java/util/List
      35: aload_3
      36: invokestatic  #28                 // Method buildCombinations:([IIILjava/util/List;Ljava/util/List;)V
      39: nop
      40: aload_2
      41: areturn

  private static final void buildCombinations(int[], int, int, java.util.List<java.lang.Integer>, java.util.List<java.util.List<java.lang.Integer>>);
    Code:
       0: iload_2
       1: ifne          20
       4: aload         4
       6: aload_3
       7: checkcast     #37                 // class java/lang/Iterable
      10: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      13: invokeinterface #47,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      18: pop
      19: return
      20: iload_1
      21: istore        5
      23: aload_0
      24: invokestatic  #53                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      27: istore        6
      29: iload         5
      31: iload         6
      33: if_icmpgt     93
      36: aload_0
      37: iload         5
      39: iaload
      40: istore        7
      42: iload         7
      44: iload_2
      45: if_icmpgt     80
      48: aload_3
      49: iload         7
      51: invokestatic  #59                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      54: invokeinterface #47,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      59: pop
      60: aload_0
      61: iload         5
      63: iload_2
      64: iload         7
      66: isub
      67: aload_3
      68: aload         4
      70: invokestatic  #28                 // Method buildCombinations:([IIILjava/util/List;Ljava/util/List;)V
      73: aload_3
      74: invokeinterface #63,  1           // InterfaceMethod java/util/List.removeLast:()Ljava/lang/Object;
      79: pop
      80: iload         5
      82: iload         6
      84: if_icmpeq     93
      87: iinc          5, 1
      90: goto          36
      93: return
}


// https://leetcode.com/problems/spiral-matrix
fun spiralOrder(matrix: Array<IntArray>): List<Int> {
    val numIndices = matrix.size * matrix.first().size
    val spiral = mutableListOf<Int>()
    val viewed = Array(matrix.size) { BooleanArray(matrix.first().size) }
    var row = 0
    var col = 0
    var rowOffset = 0
    var colOffset = 1
    while (spiral.size < numIndices) {
        spiral.add(matrix[row][col])
        viewed[row][col] = true
        val isNextIndexValid = validIndex(
            row = row + rowOffset,
            col = col + colOffset,
            lastRow = matrix.lastIndex,
            lastCol = matrix.first().lastIndex
        )
        if (!isNextIndexValid || viewed[row + rowOffset][col + colOffset]) {
            when {
                colOffset == 1 -> {
                    rowOffset = 1
                    colOffset = 0
                }
                rowOffset == 1 -> {
                    rowOffset = 0
                    colOffset = -1
                }
                colOffset == -1 -> {
                    rowOffset = -1
                    colOffset = 0
                }
                else -> {
                    rowOffset = 0
                    colOffset = 1
                }
            }
        }
        row += rowOffset
        col += colOffset
    }
    return spiral
}

private fun validIndex(row: Int, col: Int, lastRow: Int, lastCol: Int): Boolean {
    return row in 0..lastRow && col in 0..lastCol
}

Compiled from "_0054_SpiralMatrix.kt"
public final class _0054_SpiralMatrixKt {
  public static final java.util.List<java.lang.Integer> spiralOrder(int[][]);
    Code:
       0: aload_0
       1: ldc           #10                 // String matrix
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: aload_0
      12: checkcast     #18                 // class "[Ljava/lang/Object;"
      15: invokestatic  #24                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      18: checkcast     #26                 // class "[I"
      21: arraylength
      22: imul
      23: istore_1
      24: new           #28                 // class java/util/ArrayList
      27: dup
      28: invokespecial #32                 // Method java/util/ArrayList."<init>":()V
      31: checkcast     #34                 // class java/util/List
      34: astore_2
      35: iconst_0
      36: istore        4
      38: aload_0
      39: checkcast     #18                 // class "[Ljava/lang/Object;"
      42: arraylength
      43: istore        5
      45: iload         5
      47: anewarray     #36                 // class "[Z"
      50: astore        6
      52: iload         4
      54: iload         5
      56: if_icmpge     87
      59: iload         4
      61: istore        7
      63: aload         6
      65: iload         7
      67: aload_0
      68: checkcast     #18                 // class "[Ljava/lang/Object;"
      71: invokestatic  #24                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      74: checkcast     #26                 // class "[I"
      77: arraylength
      78: newarray       boolean
      80: aastore
      81: iinc          4, 1
      84: goto          52
      87: aload         6
      89: astore_3
      90: iconst_0
      91: istore        4
      93: iconst_0
      94: istore        5
      96: iconst_0
      97: istore        6
      99: iconst_1
     100: istore        7
     102: aload_2
     103: invokeinterface #40,  1           // InterfaceMethod java/util/List.size:()I
     108: iload_1
     109: if_icmpge     262
     112: aload_2
     113: aload_0
     114: iload         4
     116: aaload
     117: iload         5
     119: iaload
     120: invokestatic  #46                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokeinterface #50,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     128: pop
     129: aload_3
     130: iload         4
     132: aaload
     133: iload         5
     135: iconst_1
     136: bastore
     137: iload         4
     139: iload         6
     141: iadd
     142: iload         5
     144: iload         7
     146: iadd
     147: aload_0
     148: checkcast     #18                 // class "[Ljava/lang/Object;"
     151: invokestatic  #54                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     154: aload_0
     155: checkcast     #18                 // class "[Ljava/lang/Object;"
     158: invokestatic  #24                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
     161: checkcast     #26                 // class "[I"
     164: invokestatic  #57                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
     167: invokestatic  #61                 // Method validIndex:(IIII)Z
     170: istore        8
     172: iload         8
     174: ifeq          193
     177: aload_3
     178: iload         4
     180: iload         6
     182: iadd
     183: aaload
     184: iload         5
     186: iload         7
     188: iadd
     189: baload
     190: ifeq          245
     193: nop
     194: iload         7
     196: iconst_1
     197: if_icmpne     209
     200: iconst_1
     201: istore        6
     203: iconst_0
     204: istore        7
     206: goto          245
     209: iload         6
     211: iconst_1
     212: if_icmpne     224
     215: iconst_0
     216: istore        6
     218: iconst_m1
     219: istore        7
     221: goto          245
     224: iload         7
     226: iconst_m1
     227: if_icmpne     239
     230: iconst_m1
     231: istore        6
     233: iconst_0
     234: istore        7
     236: goto          245
     239: iconst_0
     240: istore        6
     242: iconst_1
     243: istore        7
     245: iload         4
     247: iload         6
     249: iadd
     250: istore        4
     252: iload         5
     254: iload         7
     256: iadd
     257: istore        5
     259: goto          102
     262: aload_2
     263: areturn

  private static final boolean validIndex(int, int, int, int);
    Code:
       0: iconst_0
       1: iload_0
       2: if_icmpgt     18
       5: iload_0
       6: iload_2
       7: if_icmpgt     14
      10: iconst_1
      11: goto          19
      14: iconst_0
      15: goto          19
      18: iconst_0
      19: ifeq          48
      22: iconst_0
      23: iload_1
      24: if_icmpgt     40
      27: iload_1
      28: iload_3
      29: if_icmpgt     36
      32: iconst_1
      33: goto          41
      36: iconst_0
      37: goto          41
      40: iconst_0
      41: ifeq          48
      44: iconst_1
      45: goto          49
      48: iconst_0
      49: ireturn
}


import java.lang.StringBuilder

// https://leetcode.com/problems/letter-combinations-of-a-phone-number
fun letterCombinations(digits: String): List<String> {
    val combinations = mutableListOf<String>()
    val digitToChars = mapOf(
        '2' to charArrayOf('a', 'b', 'c'),
        '3' to charArrayOf('d', 'e', 'f'),
        '4' to charArrayOf('g', 'h', 'i'),
        '5' to charArrayOf('j', 'k', 'l'),
        '6' to charArrayOf('m', 'n', 'o'),
        '7' to charArrayOf('p', 'q', 'r', 's'),
        '8' to charArrayOf('t', 'u', 'v'),
        '9' to charArrayOf('w', 'x', 'y', 'z')
    )
    if (digits.isNotEmpty()) {
        buildCombinations(digits, 0, StringBuilder(), combinations, digitToChars)
    }
    return combinations
}

private fun buildCombinations(
    digits: String,
    index: Int,
    combination: StringBuilder,
    combinations: MutableList<String>,
    digitToChars: Map<Char, CharArray>
) {
    if (index == digits.length) {
        combinations.add(combination.toString())
        return
    }
    for (char in digitToChars.getValue(digits[index])) {
        combination.append(char)
        buildCombinations(digits, index + 1, combination, combinations, digitToChars)
        combination.setLength(combination.length - 1)
    }
}

Compiled from "_0017_LetterCombinationsOfAPhoneNumber.kt"
public final class _0017_LetterCombinationsOfAPhoneNumberKt {
  public static final java.util.List<java.lang.String> letterCombinations(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String digits
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/ArrayList
       9: dup
      10: invokespecial #22                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #24                 // class java/util/List
      16: astore_1
      17: bipush        8
      19: anewarray     #26                 // class kotlin/Pair
      22: astore_3
      23: aload_3
      24: iconst_0
      25: bipush        50
      27: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      30: iconst_3
      31: newarray       char
      33: astore        4
      35: aload         4
      37: iconst_0
      38: bipush        97
      40: castore
      41: aload         4
      43: iconst_1
      44: bipush        98
      46: castore
      47: aload         4
      49: iconst_2
      50: bipush        99
      52: castore
      53: aload         4
      55: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      58: aastore
      59: aload_3
      60: iconst_1
      61: bipush        51
      63: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      66: iconst_3
      67: newarray       char
      69: astore        4
      71: aload         4
      73: iconst_0
      74: bipush        100
      76: castore
      77: aload         4
      79: iconst_1
      80: bipush        101
      82: castore
      83: aload         4
      85: iconst_2
      86: bipush        102
      88: castore
      89: aload         4
      91: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      94: aastore
      95: aload_3
      96: iconst_2
      97: bipush        52
      99: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     102: iconst_3
     103: newarray       char
     105: astore        4
     107: aload         4
     109: iconst_0
     110: bipush        103
     112: castore
     113: aload         4
     115: iconst_1
     116: bipush        104
     118: castore
     119: aload         4
     121: iconst_2
     122: bipush        105
     124: castore
     125: aload         4
     127: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     130: aastore
     131: aload_3
     132: iconst_3
     133: bipush        53
     135: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     138: iconst_3
     139: newarray       char
     141: astore        4
     143: aload         4
     145: iconst_0
     146: bipush        106
     148: castore
     149: aload         4
     151: iconst_1
     152: bipush        107
     154: castore
     155: aload         4
     157: iconst_2
     158: bipush        108
     160: castore
     161: aload         4
     163: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     166: aastore
     167: aload_3
     168: iconst_4
     169: bipush        54
     171: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     174: iconst_3
     175: newarray       char
     177: astore        4
     179: aload         4
     181: iconst_0
     182: bipush        109
     184: castore
     185: aload         4
     187: iconst_1
     188: bipush        110
     190: castore
     191: aload         4
     193: iconst_2
     194: bipush        111
     196: castore
     197: aload         4
     199: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     202: aastore
     203: aload_3
     204: iconst_5
     205: bipush        55
     207: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     210: iconst_4
     211: newarray       char
     213: astore        4
     215: aload         4
     217: iconst_0
     218: bipush        112
     220: castore
     221: aload         4
     223: iconst_1
     224: bipush        113
     226: castore
     227: aload         4
     229: iconst_2
     230: bipush        114
     232: castore
     233: aload         4
     235: iconst_3
     236: bipush        115
     238: castore
     239: aload         4
     241: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     244: aastore
     245: aload_3
     246: bipush        6
     248: bipush        56
     250: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     253: iconst_3
     254: newarray       char
     256: astore        4
     258: aload         4
     260: iconst_0
     261: bipush        116
     263: castore
     264: aload         4
     266: iconst_1
     267: bipush        117
     269: castore
     270: aload         4
     272: iconst_2
     273: bipush        118
     275: castore
     276: aload         4
     278: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     281: aastore
     282: aload_3
     283: bipush        7
     285: bipush        57
     287: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     290: iconst_4
     291: newarray       char
     293: astore        4
     295: aload         4
     297: iconst_0
     298: bipush        119
     300: castore
     301: aload         4
     303: iconst_1
     304: bipush        120
     306: castore
     307: aload         4
     309: iconst_2
     310: bipush        121
     312: castore
     313: aload         4
     315: iconst_3
     316: bipush        122
     318: castore
     319: aload         4
     321: invokestatic  #38                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     324: aastore
     325: aload_3
     326: invokestatic  #44                 // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     329: astore_2
     330: aload_0
     331: checkcast     #46                 // class java/lang/CharSequence
     334: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     339: ifle          346
     342: iconst_1
     343: goto          347
     346: iconst_0
     347: ifeq          364
     350: aload_0
     351: iconst_0
     352: new           #52                 // class java/lang/StringBuilder
     355: dup
     356: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
     359: aload_1
     360: aload_2
     361: invokestatic  #57                 // Method buildCombinations:(Ljava/lang/String;ILjava/lang/StringBuilder;Ljava/util/List;Ljava/util/Map;)V
     364: aload_1
     365: areturn

  private static final void buildCombinations(java.lang.String, int, java.lang.StringBuilder, java.util.List<java.lang.String>, java.util.Map<java.lang.Character, char[]>);
    Code:
       0: iload_1
       1: aload_0
       2: invokevirtual #72                 // Method java/lang/String.length:()I
       5: if_icmpne     26
       8: aload_3
       9: aload_2
      10: invokevirtual #76                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      13: dup
      14: ldc           #78                 // String toString(...)
      16: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      19: invokeinterface #85,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      24: pop
      25: return
      26: aload         4
      28: aload_0
      29: iload_1
      30: invokevirtual #89                 // Method java/lang/String.charAt:(I)C
      33: invokestatic  #32                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      36: invokestatic  #93                 // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      39: checkcast     #70                 // class "[C"
      42: astore        5
      44: iconst_0
      45: istore        6
      47: aload         5
      49: arraylength
      50: istore        7
      52: iload         6
      54: iload         7
      56: if_icmpge     100
      59: aload         5
      61: iload         6
      63: caload
      64: istore        8
      66: aload_2
      67: iload         8
      69: invokevirtual #97                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      72: pop
      73: aload_0
      74: iload_1
      75: iconst_1
      76: iadd
      77: aload_2
      78: aload_3
      79: aload         4
      81: invokestatic  #57                 // Method buildCombinations:(Ljava/lang/String;ILjava/lang/StringBuilder;Ljava/util/List;Ljava/util/Map;)V
      84: aload_2
      85: aload_2
      86: invokevirtual #98                 // Method java/lang/StringBuilder.length:()I
      89: iconst_1
      90: isub
      91: invokevirtual #102                // Method java/lang/StringBuilder.setLength:(I)V
      94: iinc          6, 1
      97: goto          52
     100: return
}


// https://leetcode.com/problems/edit-distance
fun minDistance(word1: String, word2: String): Int {
    return minDistance(word1, word2, 0, 0, Array(word1.length) { IntArray(word2.length) { -1 } })
}

private fun minDistance(word1: String, word2: String, index1: Int, index2: Int, memo: Array<IntArray>): Int {
    if (word1.length == index1) {
        return word2.length - index2
    }
    if (word2.length == index2) {
        return word1.length - index1
    }

    if (memo[index1][index2] != -1) {
        return memo[index1][index2]
    }

    memo[index1][index2] = if (word1[index1] == word2[index2]) {
        minDistance(word1, word2, index1 + 1, index2 + 1, memo)
    } else {
        val insert = minDistance(word1, word2, index1, index2 + 1, memo)
        val remove = minDistance(word1, word2, index1 + 1, index2, memo)
        val replace = minDistance(word1, word2, index1 + 1, index2 + 1, memo)
        1 + minOf(insert, remove, replace)
    }
    return memo[index1][index2]
}

Compiled from "_0072_EditDistance.kt"
public final class _0072_EditDistanceKt {
  public static final int minDistance(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String word1
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String word2
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: iconst_0
      15: iconst_0
      16: iconst_0
      17: istore_2
      18: aload_0
      19: invokevirtual #23                 // Method java/lang/String.length:()I
      22: istore_3
      23: iload_3
      24: anewarray     #25                 // class "[I"
      27: astore        4
      29: istore        13
      31: istore        12
      33: astore        11
      35: astore        10
      37: iload_2
      38: iload_3
      39: if_icmpge     104
      42: iload_2
      43: istore        5
      45: aload         4
      47: iload         5
      49: iconst_0
      50: istore        6
      52: aload_1
      53: invokevirtual #23                 // Method java/lang/String.length:()I
      56: istore        7
      58: iload         7
      60: newarray       int
      62: astore        8
      64: istore        15
      66: astore        14
      68: iload         6
      70: iload         7
      72: if_icmpge     91
      75: iload         6
      77: istore        9
      79: aload         8
      81: iload         9
      83: iconst_m1
      84: iastore
      85: iinc          6, 1
      88: goto          68
      91: aload         14
      93: iload         15
      95: aload         8
      97: aastore
      98: iinc          2, 1
     101: goto          37
     104: aload         10
     106: aload         11
     108: iload         12
     110: iload         13
     112: aload         4
     114: invokestatic  #28                 // Method minDistance:(Ljava/lang/String;Ljava/lang/String;II[[I)I
     117: ireturn

  private static final int minDistance(java.lang.String, java.lang.String, int, int, int[][]);
    Code:
       0: aload_0
       1: invokevirtual #23                 // Method java/lang/String.length:()I
       4: iload_2
       5: if_icmpne     15
       8: aload_1
       9: invokevirtual #23                 // Method java/lang/String.length:()I
      12: iload_3
      13: isub
      14: ireturn
      15: aload_1
      16: invokevirtual #23                 // Method java/lang/String.length:()I
      19: iload_3
      20: if_icmpne     30
      23: aload_0
      24: invokevirtual #23                 // Method java/lang/String.length:()I
      27: iload_2
      28: isub
      29: ireturn
      30: aload         4
      32: iload_2
      33: aaload
      34: iload_3
      35: iaload
      36: iconst_m1
      37: if_icmpeq     47
      40: aload         4
      42: iload_2
      43: aaload
      44: iload_3
      45: iaload
      46: ireturn
      47: aload         4
      49: iload_2
      50: aaload
      51: iload_3
      52: aload_0
      53: iload_2
      54: invokevirtual #35                 // Method java/lang/String.charAt:(I)C
      57: aload_1
      58: iload_3
      59: invokevirtual #35                 // Method java/lang/String.charAt:(I)C
      62: if_icmpne     81
      65: aload_0
      66: aload_1
      67: iload_2
      68: iconst_1
      69: iadd
      70: iload_3
      71: iconst_1
      72: iadd
      73: aload         4
      75: invokestatic  #28                 // Method minDistance:(Ljava/lang/String;Ljava/lang/String;II[[I)I
      78: goto          136
      81: aload_0
      82: aload_1
      83: iload_2
      84: iload_3
      85: iconst_1
      86: iadd
      87: aload         4
      89: invokestatic  #28                 // Method minDistance:(Ljava/lang/String;Ljava/lang/String;II[[I)I
      92: istore        5
      94: aload_0
      95: aload_1
      96: iload_2
      97: iconst_1
      98: iadd
      99: iload_3
     100: aload         4
     102: invokestatic  #28                 // Method minDistance:(Ljava/lang/String;Ljava/lang/String;II[[I)I
     105: istore        6
     107: aload_0
     108: aload_1
     109: iload_2
     110: iconst_1
     111: iadd
     112: iload_3
     113: iconst_1
     114: iadd
     115: aload         4
     117: invokestatic  #28                 // Method minDistance:(Ljava/lang/String;Ljava/lang/String;II[[I)I
     120: istore        7
     122: iconst_1
     123: iload         5
     125: iload         6
     127: iload         7
     129: invokestatic  #41                 // Method java/lang/Math.min:(II)I
     132: invokestatic  #41                 // Method java/lang/Math.min:(II)I
     135: iadd
     136: iastore
     137: aload         4
     139: iload_2
     140: aaload
     141: iload_3
     142: iaload
     143: ireturn
}


// https://leetcode.com/problems/combination-sum-ii
fun combinationSum2(candidates: IntArray, target: Int): List<List<Int>> {
    candidates.sort()
    return mutableSetOf<List<Int>>().also {
        buildCombinations(candidates, startIndex = 0, target = target, combination = mutableListOf(), combinations = it)
    }.toList()
}

private fun buildCombinations(
    candidates: IntArray,
    startIndex: Int,
    target: Int,
    combination: MutableList<Int>,
    combinations: MutableSet<List<Int>>
) {
    if (target == 0) {
        combinations.add(combination.toList())
        return
    }
    var index = startIndex
    while (index <= candidates.lastIndex) {
        val candidate = candidates[index]
        if (candidate <= target) {
            combination.add(candidate)
            buildCombinations(
                candidates = candidates,
                startIndex = index + 1,
                target = target - candidate,
                combination = combination,
                combinations = combinations
            )
            combination.removeLast()
        }
        while (index <= candidates.lastIndex && candidates[index] == candidate) {
            index++
        }
    }
}

Compiled from "_0040_CombinationSumII.kt"
public final class _0040_CombinationSumIIKt {
  public static final java.util.List<java.util.List<java.lang.Integer>> combinationSum2(int[], int);
    Code:
       0: aload_0
       1: ldc           #10                 // String candidates
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #22                 // Method kotlin/collections/ArraysKt.sort:([I)V
      10: new           #24                 // class java/util/LinkedHashSet
      13: dup
      14: invokespecial #28                 // Method java/util/LinkedHashSet."<init>":()V
      17: checkcast     #30                 // class java/util/Set
      20: astore_2
      21: aload_2
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_0
      27: iconst_0
      28: iload_1
      29: new           #32                 // class java/util/ArrayList
      32: dup
      33: invokespecial #33                 // Method java/util/ArrayList."<init>":()V
      36: checkcast     #35                 // class java/util/List
      39: aload_3
      40: invokestatic  #39                 // Method buildCombinations:([IIILjava/util/List;Ljava/util/Set;)V
      43: nop
      44: aload_2
      45: checkcast     #41                 // class java/lang/Iterable
      48: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      51: areturn

  private static final void buildCombinations(int[], int, int, java.util.List<java.lang.Integer>, java.util.Set<java.util.List<java.lang.Integer>>);
    Code:
       0: iload_2
       1: ifne          20
       4: aload         4
       6: aload_3
       7: checkcast     #41                 // class java/lang/Iterable
      10: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      13: invokeinterface #58,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      18: pop
      19: return
      20: iload_1
      21: istore        5
      23: iload         5
      25: aload_0
      26: invokestatic  #62                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      29: if_icmpgt     102
      32: aload_0
      33: iload         5
      35: iaload
      36: istore        6
      38: iload         6
      40: iload_2
      41: if_icmpgt     78
      44: aload_3
      45: iload         6
      47: invokestatic  #68                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: invokeinterface #69,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      55: pop
      56: aload_0
      57: iload         5
      59: iconst_1
      60: iadd
      61: iload_2
      62: iload         6
      64: isub
      65: aload_3
      66: aload         4
      68: invokestatic  #39                 // Method buildCombinations:([IIILjava/util/List;Ljava/util/Set;)V
      71: aload_3
      72: invokeinterface #73,  1           // InterfaceMethod java/util/List.removeLast:()Ljava/lang/Object;
      77: pop
      78: iload         5
      80: aload_0
      81: invokestatic  #62                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      84: if_icmpgt     23
      87: aload_0
      88: iload         5
      90: iaload
      91: iload         6
      93: if_icmpne     23
      96: iinc          5, 1
      99: goto          78
     102: return
}


import kotlin.math.min

// https://leetcode.com/problems/minimum-path-sum
fun minPathSum(grid: Array<IntArray>): Int {
    val lastRow = grid.lastIndex
    val lastCol = grid.first().lastIndex
    val memo = Array(lastRow + 1) { IntArray(lastCol + 1) }
    memo[lastRow][lastCol] = grid[lastRow][lastCol]
    for (row in lastRow - 1 downTo 0) {
        memo[row][lastCol] = grid[row][lastCol] + memo[row + 1][lastCol]
    }
    for (col in lastCol - 1 downTo 0) {
        memo[lastRow][col] = grid[lastRow][col] + memo[lastRow][col + 1]
    }
    for (row in lastRow - 1 downTo 0) {
        for (col in lastCol - 1 downTo 0) {
            memo[row][col] = grid[row][col] + min(memo[row + 1][col], memo[row][col + 1])
        }
    }
    return memo[0][0]
}

Compiled from "_0064_MinimumPathSum.kt"
public final class _0064_MinimumPathSumKt {
  public static final int minPathSum(int[][]);
    Code:
       0: aload_0
       1: ldc           #9                  // String grid
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class "[Ljava/lang/Object;"
      10: invokestatic  #23                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      13: istore_1
      14: aload_0
      15: checkcast     #17                 // class "[Ljava/lang/Object;"
      18: invokestatic  #27                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      21: checkcast     #29                 // class "[I"
      24: invokestatic  #32                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      27: istore_2
      28: iconst_0
      29: istore        4
      31: iload_1
      32: iconst_1
      33: iadd
      34: istore        5
      36: iload         5
      38: anewarray     #29                 // class "[I"
      41: astore        6
      43: iload         4
      45: iload         5
      47: if_icmpge     70
      50: iload         4
      52: istore        7
      54: aload         6
      56: iload         7
      58: iload_2
      59: iconst_1
      60: iadd
      61: newarray       int
      63: aastore
      64: iinc          4, 1
      67: goto          43
      70: aload         6
      72: astore_3
      73: aload_3
      74: iload_1
      75: aaload
      76: iload_2
      77: aload_0
      78: iload_1
      79: aaload
      80: iload_2
      81: iaload
      82: iastore
      83: iload_1
      84: iconst_1
      85: isub
      86: istore        4
      88: iconst_m1
      89: iload         4
      91: if_icmpge     121
      94: aload_3
      95: iload         4
      97: aaload
      98: iload_2
      99: aload_0
     100: iload         4
     102: aaload
     103: iload_2
     104: iaload
     105: aload_3
     106: iload         4
     108: iconst_1
     109: iadd
     110: aaload
     111: iload_2
     112: iaload
     113: iadd
     114: iastore
     115: iinc          4, -1
     118: goto          88
     121: iload_2
     122: iconst_1
     123: isub
     124: istore        4
     126: iconst_m1
     127: iload         4
     129: if_icmpge     159
     132: aload_3
     133: iload_1
     134: aaload
     135: iload         4
     137: aload_0
     138: iload_1
     139: aaload
     140: iload         4
     142: iaload
     143: aload_3
     144: iload_1
     145: aaload
     146: iload         4
     148: iconst_1
     149: iadd
     150: iaload
     151: iadd
     152: iastore
     153: iinc          4, -1
     156: goto          126
     159: iload_1
     160: iconst_1
     161: isub
     162: istore        4
     164: iconst_m1
     165: iload         4
     167: if_icmpge     229
     170: iload_2
     171: iconst_1
     172: isub
     173: istore        5
     175: iconst_m1
     176: iload         5
     178: if_icmpge     223
     181: aload_3
     182: iload         4
     184: aaload
     185: iload         5
     187: aload_0
     188: iload         4
     190: aaload
     191: iload         5
     193: iaload
     194: aload_3
     195: iload         4
     197: iconst_1
     198: iadd
     199: aaload
     200: iload         5
     202: iaload
     203: aload_3
     204: iload         4
     206: aaload
     207: iload         5
     209: iconst_1
     210: iadd
     211: iaload
     212: invokestatic  #38                 // Method java/lang/Math.min:(II)I
     215: iadd
     216: iastore
     217: iinc          5, -1
     220: goto          175
     223: iinc          4, -1
     226: goto          164
     229: aload_3
     230: iconst_0
     231: aaload
     232: iconst_0
     233: iaload
     234: ireturn
}


// https://leetcode.com/problems/word-search
fun exist(board: Array<CharArray>, word: String): Boolean {
    val visited = Array(board.size) { BooleanArray(board.first().size) }
    for (row in board.indices) {
        for (col in board.first().indices) {
            if (dfs(row = row, col = col, index = 0, word = word, board = board, visited = visited)) {
                return true
            }
        }
    }
    return false
}

fun dfs(
    row: Int,
    col: Int,
    index: Int,
    word: String,
    board: Array<CharArray>,
    visited: Array<BooleanArray>
): Boolean {
    if (visited[row][col] || board[row][col] != word[index]) return false
    if (index == word.lastIndex) return true
    visited[row][col] = true
    if (board.valid(row - 1, col) && dfs(row - 1, col, index + 1, word, board, visited)) return true
    if (board.valid(row + 1, col) && dfs(row + 1, col, index + 1, word, board, visited)) return true
    if (board.valid(row, col - 1) && dfs(row, col - 1, index + 1, word, board, visited)) return true
    if (board.valid(row, col + 1) && dfs(row, col + 1, index + 1, word, board, visited)) return true
    visited[row][col] = false
    return false
}

private fun Array<CharArray>.valid(row: Int, col: Int): Boolean {
    return row >= 0 && row <= this.lastIndex && col >= 0 && col <= this.first().lastIndex
}

Compiled from "_0079_WordSearch.kt"
public final class _0079_WordSearchKt {
  public static final boolean exist(char[][], java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String board
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String word
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_3
      14: aload_0
      15: checkcast     #19                 // class "[Ljava/lang/Object;"
      18: arraylength
      19: istore        4
      21: iload         4
      23: anewarray     #21                 // class "[Z"
      26: astore        5
      28: iload_3
      29: iload         4
      31: if_icmpge     61
      34: iload_3
      35: istore        6
      37: aload         5
      39: iload         6
      41: aload_0
      42: checkcast     #19                 // class "[Ljava/lang/Object;"
      45: invokestatic  #27                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      48: checkcast     #29                 // class "[C"
      51: arraylength
      52: newarray       boolean
      54: aastore
      55: iinc          3, 1
      58: goto          28
      61: aload         5
      63: astore_2
      64: iconst_0
      65: istore_3
      66: aload_0
      67: checkcast     #19                 // class "[Ljava/lang/Object;"
      70: arraylength
      71: istore        4
      73: iload_3
      74: iload         4
      76: if_icmpge     129
      79: iconst_0
      80: istore        5
      82: aload_0
      83: checkcast     #19                 // class "[Ljava/lang/Object;"
      86: invokestatic  #27                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      89: checkcast     #29                 // class "[C"
      92: arraylength
      93: istore        6
      95: iload         5
      97: iload         6
      99: if_icmpge     123
     102: iload_3
     103: iload         5
     105: iconst_0
     106: aload_1
     107: aload_0
     108: aload_2
     109: invokestatic  #33                 // Method dfs:(IIILjava/lang/String;[[C[[Z)Z
     112: ifeq          117
     115: iconst_1
     116: ireturn
     117: iinc          5, 1
     120: goto          95
     123: iinc          3, 1
     126: goto          73
     129: iconst_0
     130: ireturn

  public static final boolean dfs(int, int, int, java.lang.String, char[][], boolean[][]);
    Code:
       0: aload_3
       1: ldc           #17                 // String word
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload         4
       8: ldc           #9                  // String board
      10: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: aload         5
      15: ldc           #45                 // String visited
      17: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      20: aload         5
      22: iload_0
      23: aaload
      24: iload_1
      25: baload
      26: ifne          43
      29: aload         4
      31: iload_0
      32: aaload
      33: iload_1
      34: caload
      35: aload_3
      36: iload_2
      37: invokevirtual #49                 // Method java/lang/String.charAt:(I)C
      40: if_icmpeq     45
      43: iconst_0
      44: ireturn
      45: iload_2
      46: aload_3
      47: checkcast     #51                 // class java/lang/CharSequence
      50: invokestatic  #57                 // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
      53: if_icmpne     58
      56: iconst_1
      57: ireturn
      58: aload         5
      60: iload_0
      61: aaload
      62: iload_1
      63: iconst_1
      64: bastore
      65: aload         4
      67: iload_0
      68: iconst_1
      69: isub
      70: iload_1
      71: invokestatic  #61                 // Method valid:([[CII)Z
      74: ifeq          97
      77: iload_0
      78: iconst_1
      79: isub
      80: iload_1
      81: iload_2
      82: iconst_1
      83: iadd
      84: aload_3
      85: aload         4
      87: aload         5
      89: invokestatic  #33                 // Method dfs:(IIILjava/lang/String;[[C[[Z)Z
      92: ifeq          97
      95: iconst_1
      96: ireturn
      97: aload         4
      99: iload_0
     100: iconst_1
     101: iadd
     102: iload_1
     103: invokestatic  #61                 // Method valid:([[CII)Z
     106: ifeq          129
     109: iload_0
     110: iconst_1
     111: iadd
     112: iload_1
     113: iload_2
     114: iconst_1
     115: iadd
     116: aload_3
     117: aload         4
     119: aload         5
     121: invokestatic  #33                 // Method dfs:(IIILjava/lang/String;[[C[[Z)Z
     124: ifeq          129
     127: iconst_1
     128: ireturn
     129: aload         4
     131: iload_0
     132: iload_1
     133: iconst_1
     134: isub
     135: invokestatic  #61                 // Method valid:([[CII)Z
     138: ifeq          161
     141: iload_0
     142: iload_1
     143: iconst_1
     144: isub
     145: iload_2
     146: iconst_1
     147: iadd
     148: aload_3
     149: aload         4
     151: aload         5
     153: invokestatic  #33                 // Method dfs:(IIILjava/lang/String;[[C[[Z)Z
     156: ifeq          161
     159: iconst_1
     160: ireturn
     161: aload         4
     163: iload_0
     164: iload_1
     165: iconst_1
     166: iadd
     167: invokestatic  #61                 // Method valid:([[CII)Z
     170: ifeq          193
     173: iload_0
     174: iload_1
     175: iconst_1
     176: iadd
     177: iload_2
     178: iconst_1
     179: iadd
     180: aload_3
     181: aload         4
     183: aload         5
     185: invokestatic  #33                 // Method dfs:(IIILjava/lang/String;[[C[[Z)Z
     188: ifeq          193
     191: iconst_1
     192: ireturn
     193: aload         5
     195: iload_0
     196: aaload
     197: iload_1
     198: iconst_0
     199: bastore
     200: iconst_0
     201: ireturn

  private static final boolean valid(char[][], int, int);
    Code:
       0: iload_1
       1: iflt          40
       4: iload_1
       5: aload_0
       6: checkcast     #19                 // class "[Ljava/lang/Object;"
       9: invokestatic  #65                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      12: if_icmpgt     40
      15: iload_2
      16: iflt          40
      19: iload_2
      20: aload_0
      21: checkcast     #19                 // class "[Ljava/lang/Object;"
      24: invokestatic  #27                 // Method kotlin/collections/ArraysKt.first:([Ljava/lang/Object;)Ljava/lang/Object;
      27: checkcast     #29                 // class "[C"
      30: invokestatic  #68                 // Method kotlin/collections/ArraysKt.getLastIndex:([C)I
      33: if_icmpgt     40
      36: iconst_1
      37: goto          41
      40: iconst_0
      41: ireturn
}


// https://leetcode.com/problems/4sum
fun fourSum(nums: IntArray, target: Int): List<List<Int>> {
    val targetLong = target.toLong()
    val quardruplets = mutableSetOf<Quardruplet>()
    nums.sort()
    for (first in 0..nums.lastIndex - 3) {
        for (second in first + 1..nums.lastIndex - 2) {
            var third = second + 1
            var fourth = nums.lastIndex
            while (third < fourth) {
                val sum = nums[first].toLong() + nums[second] + nums[third] + nums[fourth]
                if (sum == targetLong) {
                    quardruplets.add(Quardruplet(nums[first], nums[second], nums[third], nums[fourth]))
                    third++
                    fourth--
                } else if (sum > target) {
                    fourth--
                } else {
                    third++
                }
            }
        }
    }
    return quardruplets.toList().map { listOf(it.first, it.second, it.third, it.fourth) }
}

data class Quardruplet(val first: Int, val second: Int, val third: Int, val fourth: Int)

Compiled from "_0018_4Sum.kt"
public final class _0018_4SumKt {
  public static final java.util.List<java.util.List<java.lang.Integer>> fourSum(int[], int);
    Code:
       0: aload_0
       1: ldc           #10                 // String nums
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_1
       7: i2l
       8: lstore_2
       9: new           #18                 // class java/util/LinkedHashSet
      12: dup
      13: invokespecial #22                 // Method java/util/LinkedHashSet."<init>":()V
      16: checkcast     #24                 // class java/util/Set
      19: astore        4
      21: aload_0
      22: invokestatic  #30                 // Method kotlin/collections/ArraysKt.sort:([I)V
      25: iconst_0
      26: istore        5
      28: aload_0
      29: invokestatic  #34                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      32: iconst_3
      33: isub
      34: istore        6
      36: iload         5
      38: iload         6
      40: if_icmpgt     201
      43: iload         5
      45: iconst_1
      46: iadd
      47: istore        7
      49: aload_0
      50: invokestatic  #34                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      53: iconst_2
      54: isub
      55: istore        8
      57: iload         7
      59: iload         8
      61: if_icmpgt     188
      64: iload         7
      66: iconst_1
      67: iadd
      68: istore        9
      70: aload_0
      71: invokestatic  #34                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      74: istore        10
      76: iload         9
      78: iload         10
      80: if_icmpge     175
      83: aload_0
      84: iload         5
      86: iaload
      87: i2l
      88: aload_0
      89: iload         7
      91: iaload
      92: i2l
      93: ladd
      94: aload_0
      95: iload         9
      97: iaload
      98: i2l
      99: ladd
     100: aload_0
     101: iload         10
     103: iaload
     104: i2l
     105: ladd
     106: lstore        11
     108: lload         11
     110: lload_2
     111: lcmp
     112: ifne          155
     115: aload         4
     117: new           #36                 // class Quardruplet
     120: dup
     121: aload_0
     122: iload         5
     124: iaload
     125: aload_0
     126: iload         7
     128: iaload
     129: aload_0
     130: iload         9
     132: iaload
     133: aload_0
     134: iload         10
     136: iaload
     137: invokespecial #39                 // Method Quardruplet."<init>":(IIII)V
     140: invokeinterface #43,  2           // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     145: pop
     146: iinc          9, 1
     149: iinc          10, -1
     152: goto          76
     155: lload         11
     157: iload_1
     158: i2l
     159: lcmp
     160: ifle          169
     163: iinc          10, -1
     166: goto          76
     169: iinc          9, 1
     172: goto          76
     175: iload         7
     177: iload         8
     179: if_icmpeq     188
     182: iinc          7, 1
     185: goto          64
     188: iload         5
     190: iload         6
     192: if_icmpeq     201
     195: iinc          5, 1
     198: goto          43
     201: aload         4
     203: checkcast     #45                 // class java/lang/Iterable
     206: invokestatic  #51                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     209: checkcast     #45                 // class java/lang/Iterable
     212: astore        5
     214: iconst_0
     215: istore        6
     217: aload         5
     219: astore        7
     221: new           #53                 // class java/util/ArrayList
     224: dup
     225: aload         5
     227: bipush        10
     229: invokestatic  #57                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     232: invokespecial #60                 // Method java/util/ArrayList."<init>":(I)V
     235: checkcast     #62                 // class java/util/Collection
     238: astore        8
     240: iconst_0
     241: istore        9
     243: aload         7
     245: invokeinterface #66,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     250: astore        10
     252: aload         10
     254: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     259: ifeq          356
     262: aload         10
     264: invokeinterface #76,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     269: astore        11
     271: aload         8
     273: aload         11
     275: checkcast     #36                 // class Quardruplet
     278: astore        12
     280: astore        15
     282: iconst_0
     283: istore        13
     285: iconst_4
     286: anewarray     #78                 // class java/lang/Integer
     289: astore        14
     291: aload         14
     293: iconst_0
     294: aload         12
     296: invokevirtual #82                 // Method Quardruplet.getFirst:()I
     299: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     302: aastore
     303: aload         14
     305: iconst_1
     306: aload         12
     308: invokevirtual #89                 // Method Quardruplet.getSecond:()I
     311: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     314: aastore
     315: aload         14
     317: iconst_2
     318: aload         12
     320: invokevirtual #92                 // Method Quardruplet.getThird:()I
     323: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     326: aastore
     327: aload         14
     329: iconst_3
     330: aload         12
     332: invokevirtual #95                 // Method Quardruplet.getFourth:()I
     335: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     338: aastore
     339: aload         14
     341: invokestatic  #99                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     344: aload         15
     346: swap
     347: invokeinterface #100,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     352: pop
     353: goto          252
     356: aload         8
     358: checkcast     #102                // class java/util/List
     361: nop
     362: areturn
}