package kr.co.programmers

import java.util.*

// https://github.com/antop-dev/algorithm/issues/497
class P159993 {
    fun solution(maps: Array<String>): Int {
        // 시작 지점, 레버, 출구 위치를 찾는다
        val pos = IntArray(6)
        for (i in maps.indices) {
            for (j in maps[i].indices) {
                when (maps[i][j]) {
                    'S' -> {
                        pos[0] = i
                        pos[1] = j
                    }

                    'L' -> {
                        pos[2] = i
                        pos[3] = j
                    }

                    'E' -> {
                        pos[4] = i
                        pos[5] = j
                    }
                }
            }
        }

        // 시작지점 -> 레버
        val move1 = move(maps, intArrayOf(pos[0], pos[1]), intArrayOf(pos[2], pos[3]))
        if (move1 == -1) return -1
        // 레버 -> 출구
        val move2 = move(maps, intArrayOf(pos[2], pos[3]), intArrayOf(pos[4], pos[5]))
        if (move2 == -1) return -1

        return move1 + move2
    }

    private val dy = intArrayOf(-1, 0, 1, 0)
    private val dx = intArrayOf(0, 1, 0, -1)

    private fun move(maps: Array<String>, start: IntArray, end: IntArray): Int {
        println()
        val n = maps.size
        val m = maps[0].length
        val visited = Array(n) { IntArray(m) }

        val queue = LinkedList<IntArray>()
        queue.add(start)

        var move = 0
        while (queue.isNotEmpty()) {
            // 큐 안에 들어있는 모든 위치를 다 이동해야 한번 움직인 것이다
            val size = queue.size
            repeat(size) {
                val (y, x) = queue.poll()
                // 목적지에 도착
                if (y == end[0] && x == end[1]) return move
                // 4방향으로 이동 예약
                dy.zip(dx) { a, b ->
                    val nextY = y + a
                    val nextX = x + b
                    // 북,동,남,서 방향으로 이동할 수 있는지 체크
                    if (nextY in 0 until n
                        && nextX in 0 until m
                        && visited[nextY][nextX] == 0
                        && maps[nextY][nextX] != 'X'
                    ) { // 이동할 수 있다
                        // 방문 체크를 미리 한다.
                        // 이래야 시간초과가 안난다.
                        visited[nextY][nextX] = 1
                        queue += intArrayOf(nextY, nextX)
                    }
                }
            }

            move++
        }
        return -1
    }
}

Compiled from "P159993.kt"
public final class kr.co.programmers.P159993 {
  private final int[] dy;

  private final int[] dx;

  public kr.co.programmers.P159993();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iconst_4
       6: newarray       int
       8: astore_1
       9: aload_1
      10: iconst_0
      11: iconst_m1
      12: iastore
      13: aload_1
      14: iconst_1
      15: iconst_0
      16: iastore
      17: aload_1
      18: iconst_2
      19: iconst_1
      20: iastore
      21: aload_1
      22: iconst_3
      23: iconst_0
      24: iastore
      25: aload_1
      26: putfield      #12                 // Field dy:[I
      29: aload_0
      30: iconst_4
      31: newarray       int
      33: astore_1
      34: aload_1
      35: iconst_0
      36: iconst_0
      37: iastore
      38: aload_1
      39: iconst_1
      40: iconst_1
      41: iastore
      42: aload_1
      43: iconst_2
      44: iconst_0
      45: iastore
      46: aload_1
      47: iconst_3
      48: iconst_m1
      49: iastore
      50: aload_1
      51: putfield      #15                 // Field dx:[I
      54: return

  public final int solution(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #22                 // String maps
       3: invokestatic  #28                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        6
       8: newarray       int
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_1
      14: arraylength
      15: istore        4
      17: iload_3
      18: iload         4
      20: if_icmpge     133
      23: iconst_0
      24: istore        5
      26: aload_1
      27: iload_3
      28: aaload
      29: checkcast     #30                 // class java/lang/CharSequence
      32: invokeinterface #34,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      37: istore        6
      39: iload         5
      41: iload         6
      43: if_icmpge     127
      46: aload_1
      47: iload_3
      48: aaload
      49: iload         5
      51: invokevirtual #40                 // Method java/lang/String.charAt:(I)C
      54: lookupswitch  { // 3
                    69: 112
                    76: 100
                    83: 88
               default: 121
          }
      88: aload_2
      89: iconst_0
      90: iload_3
      91: iastore
      92: aload_2
      93: iconst_1
      94: iload         5
      96: iastore
      97: goto          121
     100: aload_2
     101: iconst_2
     102: iload_3
     103: iastore
     104: aload_2
     105: iconst_3
     106: iload         5
     108: iastore
     109: goto          121
     112: aload_2
     113: iconst_4
     114: iload_3
     115: iastore
     116: aload_2
     117: iconst_5
     118: iload         5
     120: iastore
     121: iinc          5, 1
     124: goto          39
     127: iinc          3, 1
     130: goto          17
     133: aload_0
     134: aload_1
     135: iconst_2
     136: newarray       int
     138: astore        4
     140: aload         4
     142: iconst_0
     143: aload_2
     144: iconst_0
     145: iaload
     146: iastore
     147: aload         4
     149: iconst_1
     150: aload_2
     151: iconst_1
     152: iaload
     153: iastore
     154: aload         4
     156: iconst_2
     157: newarray       int
     159: astore        4
     161: aload         4
     163: iconst_0
     164: aload_2
     165: iconst_2
     166: iaload
     167: iastore
     168: aload         4
     170: iconst_1
     171: aload_2
     172: iconst_3
     173: iaload
     174: iastore
     175: aload         4
     177: invokespecial #44                 // Method move:([Ljava/lang/String;[I[I)I
     180: istore_3
     181: iload_3
     182: iconst_m1
     183: if_icmpne     188
     186: iconst_m1
     187: ireturn
     188: aload_0
     189: aload_1
     190: iconst_2
     191: newarray       int
     193: astore        5
     195: aload         5
     197: iconst_0
     198: aload_2
     199: iconst_2
     200: iaload
     201: iastore
     202: aload         5
     204: iconst_1
     205: aload_2
     206: iconst_3
     207: iaload
     208: iastore
     209: aload         5
     211: iconst_2
     212: newarray       int
     214: astore        5
     216: aload         5
     218: iconst_0
     219: aload_2
     220: iconst_4
     221: iaload
     222: iastore
     223: aload         5
     225: iconst_1
     226: aload_2
     227: iconst_5
     228: iaload
     229: iastore
     230: aload         5
     232: invokespecial #44                 // Method move:([Ljava/lang/String;[I[I)I
     235: istore        4
     237: iload         4
     239: iconst_m1
     240: if_icmpne     245
     243: iconst_m1
     244: ireturn
     245: iload_3
     246: iload         4
     248: iadd
     249: ireturn

  private final int move(java.lang.String[], int[], int[]);
    Code:
       0: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
       3: invokevirtual #64                 // Method java/io/PrintStream.println:()V
       6: aload_1
       7: arraylength
       8: istore        4
      10: aload_1
      11: iconst_0
      12: aaload
      13: invokevirtual #65                 // Method java/lang/String.length:()I
      16: istore        5
      18: iconst_0
      19: istore        7
      21: iload         4
      23: anewarray     #52                 // class "[I"
      26: astore        8
      28: iload         7
      30: iload         4
      32: if_icmpge     54
      35: iload         7
      37: istore        9
      39: aload         8
      41: iload         9
      43: iload         5
      45: newarray       int
      47: aastore
      48: iinc          7, 1
      51: goto          28
      54: aload         8
      56: astore        6
      58: new           #67                 // class java/util/LinkedList
      61: dup
      62: invokespecial #68                 // Method java/util/LinkedList."<init>":()V
      65: astore        7
      67: aload         7
      69: aload_2
      70: invokevirtual #72                 // Method java/util/LinkedList.add:(Ljava/lang/Object;)Z
      73: pop
      74: iconst_0
      75: istore        8
      77: aload         7
      79: checkcast     #74                 // class java/util/Collection
      82: invokeinterface #78,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      87: ifne          94
      90: iconst_1
      91: goto          95
      94: iconst_0
      95: ifeq          410
      98: aload         7
     100: invokevirtual #81                 // Method java/util/LinkedList.size:()I
     103: istore        9
     105: iconst_0
     106: istore        10
     108: iload         10
     110: iload         9
     112: if_icmpge     397
     115: iload         10
     117: istore        11
     119: iconst_0
     120: istore        12
     122: aload         7
     124: invokevirtual #85                 // Method java/util/LinkedList.poll:()Ljava/lang/Object;
     127: checkcast     #52                 // class "[I"
     130: astore        13
     132: aload         13
     134: invokestatic  #89                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     137: aload         13
     139: iconst_0
     140: iaload
     141: istore        14
     143: aload         13
     145: iconst_1
     146: iaload
     147: istore        15
     149: iload         14
     151: aload_3
     152: iconst_0
     153: iaload
     154: if_icmpne     168
     157: iload         15
     159: aload_3
     160: iconst_1
     161: iaload
     162: if_icmpne     168
     165: iload         8
     167: ireturn
     168: aload_0
     169: getfield      #12                 // Field dy:[I
     172: astore        16
     174: aload_0
     175: getfield      #15                 // Field dx:[I
     178: astore        17
     180: iconst_0
     181: istore        18
     183: aload         16
     185: arraylength
     186: aload         17
     188: arraylength
     189: invokestatic  #95                 // Method java/lang/Math.min:(II)I
     192: istore        19
     194: new           #97                 // class java/util/ArrayList
     197: dup
     198: iload         19
     200: invokespecial #100                // Method java/util/ArrayList."<init>":(I)V
     203: astore        20
     205: iconst_0
     206: istore        21
     208: iload         21
     210: iload         19
     212: if_icmpge     384
     215: aload         20
     217: aload         16
     219: iload         21
     221: iaload
     222: aload         17
     224: iload         21
     226: iaload
     227: istore        22
     229: istore        23
     231: astore        24
     233: iconst_0
     234: istore        25
     236: iload         14
     238: iload         23
     240: iadd
     241: istore        26
     243: iload         15
     245: iload         22
     247: iadd
     248: istore        27
     250: iconst_0
     251: iload         26
     253: if_icmpgt     271
     256: iload         26
     258: iload         4
     260: if_icmpge     267
     263: iconst_1
     264: goto          272
     267: iconst_0
     268: goto          272
     271: iconst_0
     272: ifeq          368
     275: iconst_0
     276: iload         27
     278: if_icmpgt     296
     281: iload         27
     283: iload         5
     285: if_icmpge     292
     288: iconst_1
     289: goto          297
     292: iconst_0
     293: goto          297
     296: iconst_0
     297: ifeq          368
     300: aload         6
     302: iload         26
     304: aaload
     305: iload         27
     307: iaload
     308: ifne          368
     311: aload_1
     312: iload         26
     314: aaload
     315: iload         27
     317: invokevirtual #40                 // Method java/lang/String.charAt:(I)C
     320: bipush        88
     322: if_icmpeq     368
     325: aload         6
     327: iload         26
     329: aaload
     330: iload         27
     332: iconst_1
     333: iastore
     334: aload         7
     336: checkcast     #74                 // class java/util/Collection
     339: astore        28
     341: iconst_2
     342: newarray       int
     344: astore        29
     346: aload         29
     348: iconst_0
     349: iload         26
     351: iastore
     352: aload         29
     354: iconst_1
     355: iload         27
     357: iastore
     358: aload         28
     360: aload         29
     362: invokeinterface #101,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     367: pop
     368: nop
     369: aload         24
     371: getstatic     #107                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     374: invokevirtual #108                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     377: pop
     378: iinc          21, 1
     381: goto          208
     384: aload         20
     386: checkcast     #110                // class java/util/List
     389: pop
     390: nop
     391: iinc          10, 1
     394: goto          108
     397: iload         8
     399: istore        10
     401: iload         10
     403: iconst_1
     404: iadd
     405: istore        8
     407: goto          77
     410: iconst_m1
     411: ireturn
}


package kr.co.programmers

import kotlin.math.abs

// https://programmers.co.kr/learn/courses/30/lessons/67256
class P67256 {
    fun solution(numbers: IntArray, hand: String): String {
        var answer = ""
        val prev = arrayOf(intArrayOf(3, 0), intArrayOf(3, 2)) // 초기 위치
        for (n in numbers) {
            // 키패드 -> 인덱스
            var idx = n - 1
            if (idx == -1) idx = 10
            // 인덱스 -> 2차원 배열
            val p = intArrayOf(idx / 3, idx % 3)
            if (p[1] == 0) { // 왼손
                answer += "L"
                prev[0] = p
            } else if (p[1] == 2) { // 오른손
                answer += "R"
                prev[1] = p
            } else {
                // 왼손으로부터의 거리
                val diffLeft = abs(prev[0][0] - p[0]) + abs(prev[0][1] - p[1])
                // 오른손으로부터의 거리
                val diffRight = abs(prev[1][0] - p[0]) + abs(prev[1][1] - p[1])
                if (diffLeft < diffRight) {
                    answer += "L"
                    prev[0] = p
                } else if (diffLeft > diffRight) {
                    answer += "R"
                    prev[1] = p
                } else {
                    if (hand == "left") {
                        answer += "L"
                        prev[0] = p
                    } else {
                        answer += "R"
                        prev[1] = p
                    }
                }
            }
        }
        return answer
    }
}

Compiled from "P67256.kt"
public final class kr.co.programmers.P67256 {
  public kr.co.programmers.P67256();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final java.lang.String solution(int[], java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String numbers
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String hand
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: ldc           #25                 // String
      14: astore_3
      15: iconst_2
      16: anewarray     #27                 // class "[I"
      19: astore        5
      21: aload         5
      23: iconst_0
      24: iconst_2
      25: newarray       int
      27: astore        6
      29: aload         6
      31: iconst_0
      32: iconst_3
      33: iastore
      34: aload         6
      36: iconst_1
      37: iconst_0
      38: iastore
      39: aload         6
      41: aastore
      42: aload         5
      44: iconst_1
      45: iconst_2
      46: newarray       int
      48: astore        6
      50: aload         6
      52: iconst_0
      53: iconst_3
      54: iastore
      55: aload         6
      57: iconst_1
      58: iconst_2
      59: iastore
      60: aload         6
      62: aastore
      63: aload         5
      65: astore        4
      67: iconst_0
      68: istore        5
      70: aload_1
      71: arraylength
      72: istore        6
      74: iload         5
      76: iload         6
      78: if_icmpge     405
      81: aload_1
      82: iload         5
      84: iaload
      85: istore        7
      87: iload         7
      89: iconst_1
      90: isub
      91: istore        8
      93: iload         8
      95: iconst_m1
      96: if_icmpne     103
      99: bipush        10
     101: istore        8
     103: iconst_2
     104: newarray       int
     106: astore        10
     108: aload         10
     110: iconst_0
     111: iload         8
     113: iconst_3
     114: idiv
     115: iastore
     116: aload         10
     118: iconst_1
     119: iload         8
     121: iconst_3
     122: irem
     123: iastore
     124: aload         10
     126: astore        9
     128: aload         9
     130: iconst_1
     131: iaload
     132: ifne          164
     135: new           #29                 // class java/lang/StringBuilder
     138: dup
     139: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
     142: aload_3
     143: invokevirtual #34                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     146: bipush        76
     148: invokevirtual #37                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     151: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     154: astore_3
     155: aload         4
     157: iconst_0
     158: aload         9
     160: aastore
     161: goto          399
     164: aload         9
     166: iconst_1
     167: iaload
     168: iconst_2
     169: if_icmpne     201
     172: new           #29                 // class java/lang/StringBuilder
     175: dup
     176: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
     179: aload_3
     180: invokevirtual #34                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     183: bipush        82
     185: invokevirtual #37                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     188: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     191: astore_3
     192: aload         4
     194: iconst_1
     195: aload         9
     197: aastore
     198: goto          399
     201: aload         4
     203: iconst_0
     204: aaload
     205: iconst_0
     206: iaload
     207: aload         9
     209: iconst_0
     210: iaload
     211: isub
     212: invokestatic  #47                 // Method java/lang/Math.abs:(I)I
     215: aload         4
     217: iconst_0
     218: aaload
     219: iconst_1
     220: iaload
     221: aload         9
     223: iconst_1
     224: iaload
     225: isub
     226: invokestatic  #47                 // Method java/lang/Math.abs:(I)I
     229: iadd
     230: istore        10
     232: aload         4
     234: iconst_1
     235: aaload
     236: iconst_0
     237: iaload
     238: aload         9
     240: iconst_0
     241: iaload
     242: isub
     243: invokestatic  #47                 // Method java/lang/Math.abs:(I)I
     246: aload         4
     248: iconst_1
     249: aaload
     250: iconst_1
     251: iaload
     252: aload         9
     254: iconst_1
     255: iaload
     256: isub
     257: invokestatic  #47                 // Method java/lang/Math.abs:(I)I
     260: iadd
     261: istore        11
     263: iload         10
     265: iload         11
     267: if_icmpge     299
     270: new           #29                 // class java/lang/StringBuilder
     273: dup
     274: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
     277: aload_3
     278: invokevirtual #34                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     281: bipush        76
     283: invokevirtual #37                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     286: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     289: astore_3
     290: aload         4
     292: iconst_0
     293: aload         9
     295: aastore
     296: goto          399
     299: iload         10
     301: iload         11
     303: if_icmple     335
     306: new           #29                 // class java/lang/StringBuilder
     309: dup
     310: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
     313: aload_3
     314: invokevirtual #34                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     317: bipush        82
     319: invokevirtual #37                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     322: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     325: astore_3
     326: aload         4
     328: iconst_1
     329: aload         9
     331: aastore
     332: goto          399
     335: aload_2
     336: ldc           #49                 // String left
     338: invokestatic  #53                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     341: ifeq          373
     344: new           #29                 // class java/lang/StringBuilder
     347: dup
     348: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
     351: aload_3
     352: invokevirtual #34                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     355: bipush        76
     357: invokevirtual #37                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     360: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     363: astore_3
     364: aload         4
     366: iconst_0
     367: aload         9
     369: aastore
     370: goto          399
     373: new           #29                 // class java/lang/StringBuilder
     376: dup
     377: invokespecial #30                 // Method java/lang/StringBuilder."<init>":()V
     380: aload_3
     381: invokevirtual #34                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     384: bipush        82
     386: invokevirtual #37                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     389: invokevirtual #41                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     392: astore_3
     393: aload         4
     395: iconst_1
     396: aload         9
     398: aastore
     399: iinc          5, 1
     402: goto          74
     405: aload_3
     406: areturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/316
class P79 {
    fun exist(board: Array<CharArray>, word: String): Boolean {
        for (i in board.indices) {
            for (j in board[i].indices) {
                if (dfs(board, i, j, word, 0)) {
                    return true
                }
            }
        }
        return false
    }

    private fun dfs(board: Array<CharArray>, i: Int, j: Int, word: String, k: Int): Boolean {
        if (k == word.length) return true
        // 행의 인덱스가 벗어난 경우
        if (i !in board.indices) return false
        // 열의 인덱스가 벗어난 경우
        if (j !in board[0].indices) return false
        // 단어가 틀린 경우
        if (board[i][j] != word[k]) return false
        // 방문 체크
        board[i][j] = ' '

        return if (dfs(board, i - 1, j, word, k + 1) // ↑
            || dfs(board, i + 1, j, word, k + 1) // ↓
            || dfs(board, i, j - 1, word, k + 1) // ←
            || dfs(board, i, j + 1, word, k + 1) // →
        ) {
            true
        } else {
            // 지나갔던 경로들이 답이 아니었다면 다시 복구한다.
            board[i][j] = word[k]
            false
        }
    }

}

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

  public final boolean exist(char[][], java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String board
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String word
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_3
      14: aload_1
      15: checkcast     #25                 // class "[Ljava/lang/Object;"
      18: arraylength
      19: istore        4
      21: iload_3
      22: iload         4
      24: if_icmpge     70
      27: iconst_0
      28: istore        5
      30: aload_1
      31: iload_3
      32: aaload
      33: arraylength
      34: istore        6
      36: iload         5
      38: iload         6
      40: if_icmpge     64
      43: aload_0
      44: aload_1
      45: iload_3
      46: iload         5
      48: aload_2
      49: iconst_0
      50: invokespecial #29                 // Method dfs:([[CIILjava/lang/String;I)Z
      53: ifeq          58
      56: iconst_1
      57: ireturn
      58: iinc          5, 1
      61: goto          36
      64: iinc          3, 1
      67: goto          21
      70: iconst_0
      71: ireturn

  private final boolean dfs(char[][], int, int, java.lang.String, int);
    Code:
       0: iload         5
       2: aload         4
       4: invokevirtual #40                 // Method java/lang/String.length:()I
       7: if_icmpne     12
      10: iconst_1
      11: ireturn
      12: iconst_0
      13: iload_2
      14: if_icmpgt     34
      17: iload_2
      18: aload_1
      19: checkcast     #25                 // class "[Ljava/lang/Object;"
      22: arraylength
      23: if_icmpge     30
      26: iconst_1
      27: goto          35
      30: iconst_0
      31: goto          35
      34: iconst_0
      35: ifne          40
      38: iconst_0
      39: ireturn
      40: iconst_0
      41: iload_3
      42: if_icmpgt     61
      45: iload_3
      46: aload_1
      47: iconst_0
      48: aaload
      49: arraylength
      50: if_icmpge     57
      53: iconst_1
      54: goto          62
      57: iconst_0
      58: goto          62
      61: iconst_0
      62: ifne          67
      65: iconst_0
      66: ireturn
      67: aload_1
      68: iload_2
      69: aaload
      70: iload_3
      71: caload
      72: aload         4
      74: iload         5
      76: invokevirtual #44                 // Method java/lang/String.charAt:(I)C
      79: if_icmpeq     84
      82: iconst_0
      83: ireturn
      84: aload_1
      85: iload_2
      86: aaload
      87: iload_3
      88: bipush        32
      90: castore
      91: aload_0
      92: aload_1
      93: iload_2
      94: iconst_1
      95: isub
      96: iload_3
      97: aload         4
      99: iload         5
     101: iconst_1
     102: iadd
     103: invokespecial #29                 // Method dfs:([[CIILjava/lang/String;I)Z
     106: ifne          163
     109: aload_0
     110: aload_1
     111: iload_2
     112: iconst_1
     113: iadd
     114: iload_3
     115: aload         4
     117: iload         5
     119: iconst_1
     120: iadd
     121: invokespecial #29                 // Method dfs:([[CIILjava/lang/String;I)Z
     124: ifne          163
     127: aload_0
     128: aload_1
     129: iload_2
     130: iload_3
     131: iconst_1
     132: isub
     133: aload         4
     135: iload         5
     137: iconst_1
     138: iadd
     139: invokespecial #29                 // Method dfs:([[CIILjava/lang/String;I)Z
     142: ifne          163
     145: aload_0
     146: aload_1
     147: iload_2
     148: iload_3
     149: iconst_1
     150: iadd
     151: aload         4
     153: iload         5
     155: iconst_1
     156: iadd
     157: invokespecial #29                 // Method dfs:([[CIILjava/lang/String;I)Z
     160: ifeq          167
     163: iconst_1
     164: goto          180
     167: aload_1
     168: iload_2
     169: aaload
     170: iload_3
     171: aload         4
     173: iload         5
     175: invokevirtual #44                 // Method java/lang/String.charAt:(I)C
     178: castore
     179: iconst_0
     180: ireturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/332
class P447 {
    fun numberOfBoomerangs(points: Array<IntArray>): Int {
        var answer = 0
        for (i in points.indices) {
            val map = mutableMapOf<Int, Int>()
            for (j in points.indices) {
                if (i == j) continue
                val distance = distance(points[i], points[j])
                map[distance] = (map[distance] ?: 0) + 1
            }
            // combinations of boomerang tuple
            for (count in map.values) {
                answer += count * (count - 1)
            }
        }
        return answer
    }

    private fun distance(p1: IntArray, p2: IntArray): Int {
        // 두 포인트간에 거리 구하기
        // 원래는 제곱과 루트(sqrt)를 계산해야 하지만
        // 모든 결과가 동일한 연산을 하므로 생략 가능하다
        val dx = p1[0] - p2[0]
        val dy = p1[1] - p2[1]
        return (dx * dx) + (dy * dy)
    }

}

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

  public final int numberOfBoomerangs(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String points
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iconst_0
       9: istore_3
      10: aload_1
      11: checkcast     #23                 // class "[Ljava/lang/Object;"
      14: arraylength
      15: istore        4
      17: iload_3
      18: iload         4
      20: if_icmpge     192
      23: new           #25                 // class java/util/LinkedHashMap
      26: dup
      27: invokespecial #26                 // Method java/util/LinkedHashMap."<init>":()V
      30: checkcast     #28                 // class java/util/Map
      33: astore        5
      35: iconst_0
      36: istore        6
      38: aload_1
      39: checkcast     #23                 // class "[Ljava/lang/Object;"
      42: arraylength
      43: istore        7
      45: iload         6
      47: iload         7
      49: if_icmpge     134
      52: iload_3
      53: iload         6
      55: if_icmpeq     128
      58: aload_0
      59: aload_1
      60: iload_3
      61: aaload
      62: aload_1
      63: iload         6
      65: aaload
      66: invokespecial #32                 // Method distance:([I[I)I
      69: istore        8
      71: aload         5
      73: astore        9
      75: iload         8
      77: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: astore        10
      82: aload         5
      84: iload         8
      86: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      89: invokeinterface #42,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      94: checkcast     #34                 // class java/lang/Integer
      97: dup
      98: ifnull        107
     101: invokevirtual #46                 // Method java/lang/Integer.intValue:()I
     104: goto          109
     107: pop
     108: iconst_0
     109: iconst_1
     110: iadd
     111: invokestatic  #38                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: astore        11
     116: aload         9
     118: aload         10
     120: aload         11
     122: invokeinterface #50,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     127: pop
     128: iinc          6, 1
     131: goto          45
     134: aload         5
     136: invokeinterface #54,  1           // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     141: invokeinterface #60,  1           // InterfaceMethod java/util/Collection.iterator:()Ljava/util/Iterator;
     146: astore        6
     148: aload         6
     150: invokeinterface #66,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifeq          186
     158: aload         6
     160: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     165: checkcast     #72                 // class java/lang/Number
     168: invokevirtual #73                 // Method java/lang/Number.intValue:()I
     171: istore        7
     173: iload_2
     174: iload         7
     176: iload         7
     178: iconst_1
     179: isub
     180: imul
     181: iadd
     182: istore_2
     183: goto          148
     186: iinc          3, 1
     189: goto          17
     192: iload_2
     193: ireturn

  private final int distance(int[], int[]);
    Code:
       0: aload_1
       1: iconst_0
       2: iaload
       3: aload_2
       4: iconst_0
       5: iaload
       6: isub
       7: istore_3
       8: aload_1
       9: iconst_1
      10: iaload
      11: aload_2
      12: iconst_1
      13: iaload
      14: isub
      15: istore        4
      17: iload_3
      18: iload_3
      19: imul
      20: iload         4
      22: iload         4
      24: imul
      25: iadd
      26: ireturn
}


package com.leetcode

import java.util.*

// https://github.com/antop-dev/algorithm/issues/487
class P994 {
    fun orangesRotting(grid: Array<IntArray>): Int {
        val queue = LinkedList<Pair<Int, Int>>()
        val fresh = intArrayOf(0) // 함수에 값을 넘기기위해 참조로 씀
        for (y in grid.indices) {
            for (x in grid[y].indices) {
                when (grid[y][x]) {
                    1 -> fresh[0]++ // fresh 카운팅
                    2 -> queue += y to x // rotten 위치 큐에 저장
                }
            }
        }

        if (fresh[0] == 0) return 0

        var minutes = -1
        while (queue.isNotEmpty()) {
            repeat(queue.size) {
                val (y, x) = queue.poll()
                go(queue, grid, fresh, y - 1, x) // 북
                go(queue, grid, fresh, y, x + 1) // 동
                go(queue, grid, fresh, y + 1, x) // 남
                go(queue, grid, fresh, y, x - 1) // 서
            }
            minutes++
        }

        return if (fresh[0] == 0) minutes else -1
    }

    private fun go(queue: LinkedList<Pair<Int, Int>>, grid: Array<IntArray>, fresh: IntArray, y: Int, x: Int) {
        if (y >= 0 && y < grid.size && x >= 0 && x < grid[y].size && grid[y][x] == 1) {
            queue += y to x
            grid[y][x] = 2
            fresh[0]--
        }
    }

}

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

  public final int orangesRotting(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String grid
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class java/util/LinkedList
       9: dup
      10: invokespecial #24                 // Method java/util/LinkedList."<init>":()V
      13: astore_2
      14: iconst_1
      15: newarray       int
      17: astore        4
      19: aload         4
      21: iconst_0
      22: iconst_0
      23: iastore
      24: aload         4
      26: astore_3
      27: iconst_0
      28: istore        4
      30: aload_1
      31: checkcast     #26                 // class "[Ljava/lang/Object;"
      34: arraylength
      35: istore        5
      37: iload         4
      39: iload         5
      41: if_icmpge     142
      44: iconst_0
      45: istore        6
      47: aload_1
      48: iload         4
      50: aaload
      51: arraylength
      52: istore        7
      54: iload         6
      56: iload         7
      58: if_icmpge     136
      61: aload_1
      62: iload         4
      64: aaload
      65: iload         6
      67: iaload
      68: tableswitch   { // 1 to 2
                     1: 92
                     2: 107
               default: 130
          }
      92: aload_3
      93: iconst_0
      94: iaload
      95: istore        9
      97: aload_3
      98: iconst_0
      99: iload         9
     101: iconst_1
     102: iadd
     103: iastore
     104: goto          130
     107: aload_2
     108: checkcast     #28                 // class java/util/Collection
     111: iload         4
     113: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     116: iload         6
     118: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     121: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     124: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     129: pop
     130: iinc          6, 1
     133: goto          54
     136: iinc          4, 1
     139: goto          37
     142: aload_3
     143: iconst_0
     144: iaload
     145: ifne          150
     148: iconst_0
     149: ireturn
     150: iconst_m1
     151: istore        4
     153: aload_2
     154: checkcast     #28                 // class java/util/Collection
     157: invokeinterface #48,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     162: ifne          169
     165: iconst_1
     166: goto          170
     169: iconst_0
     170: ifeq          296
     173: aload_2
     174: invokevirtual #52                 // Method java/util/LinkedList.size:()I
     177: istore        5
     179: iconst_0
     180: istore        6
     182: iload         6
     184: iload         5
     186: if_icmpge     290
     189: iload         6
     191: istore        7
     193: iconst_0
     194: istore        8
     196: aload_2
     197: invokevirtual #56                 // Method java/util/LinkedList.poll:()Ljava/lang/Object;
     200: checkcast     #58                 // class kotlin/Pair
     203: astore        9
     205: aload         9
     207: invokevirtual #61                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     210: checkcast     #63                 // class java/lang/Number
     213: invokevirtual #66                 // Method java/lang/Number.intValue:()I
     216: istore        10
     218: aload         9
     220: invokevirtual #69                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     223: checkcast     #63                 // class java/lang/Number
     226: invokevirtual #66                 // Method java/lang/Number.intValue:()I
     229: istore        11
     231: aload_0
     232: aload_2
     233: aload_1
     234: aload_3
     235: iload         10
     237: iconst_1
     238: isub
     239: iload         11
     241: invokespecial #73                 // Method go:(Ljava/util/LinkedList;[[I[III)V
     244: aload_0
     245: aload_2
     246: aload_1
     247: aload_3
     248: iload         10
     250: iload         11
     252: iconst_1
     253: iadd
     254: invokespecial #73                 // Method go:(Ljava/util/LinkedList;[[I[III)V
     257: aload_0
     258: aload_2
     259: aload_1
     260: aload_3
     261: iload         10
     263: iconst_1
     264: iadd
     265: iload         11
     267: invokespecial #73                 // Method go:(Ljava/util/LinkedList;[[I[III)V
     270: aload_0
     271: aload_2
     272: aload_1
     273: aload_3
     274: iload         10
     276: iload         11
     278: iconst_1
     279: isub
     280: invokespecial #73                 // Method go:(Ljava/util/LinkedList;[[I[III)V
     283: nop
     284: iinc          6, 1
     287: goto          182
     290: iinc          4, 1
     293: goto          153
     296: aload_3
     297: iconst_0
     298: iaload
     299: ifne          307
     302: iload         4
     304: goto          308
     307: iconst_m1
     308: ireturn

  private final void go(java.util.LinkedList<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, int[][], int[], int, int);
    Code:
       0: iload         4
       2: iflt          84
       5: iload         4
       7: aload_2
       8: checkcast     #26                 // class "[Ljava/lang/Object;"
      11: arraylength
      12: if_icmpge     84
      15: iload         5
      17: iflt          84
      20: iload         5
      22: aload_2
      23: iload         4
      25: aaload
      26: arraylength
      27: if_icmpge     84
      30: aload_2
      31: iload         4
      33: aaload
      34: iload         5
      36: iaload
      37: iconst_1
      38: if_icmpne     84
      41: aload_1
      42: checkcast     #28                 // class java/util/Collection
      45: iload         4
      47: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: iload         5
      52: invokestatic  #34                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: invokestatic  #40                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      58: invokeinterface #44,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      63: pop
      64: aload_2
      65: iload         4
      67: aaload
      68: iload         5
      70: iconst_2
      71: iastore
      72: aload_3
      73: iconst_0
      74: iaload
      75: istore        6
      77: aload_3
      78: iconst_0
      79: iload         6
      81: iconst_m1
      82: iadd
      83: iastore
      84: return
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/514
class P539 {
    fun findMinDifference(timePoints: List<String>): Int {
        // 문자열을 분으로 변경
        val times = mutableListOf<Int>()
        for (s in timePoints) {
            val time = time(s)
            times += time
            // 다음날 시간
            if (time < 13 * 60) times += (24 * 60) + time
        }
        // 오름차순 정렬
        times.sort()
        // 가장 작은 시간 차이 구하기
        var minDiff = 24 * 60
        for (i in 1 until times.size) {
            val diff = times[i] - times[i - 1]
            if (diff < minDiff) minDiff = diff
        }
        return minDiff
    }

    /**
     * time string to int
     */
    private fun time(s: String) =
        s.split(":")
            .map { it.toInt() }
            .let {
                val (hh, mm) = it
                (hh * 60) + mm
            }

}

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

  public final int findMinDifference(java.util.List<java.lang.String>);
    Code:
       0: aload_1
       1: ldc           #16                 // String timePoints
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #24                 // class java/util/ArrayList
       9: dup
      10: invokespecial #25                 // Method java/util/ArrayList."<init>":()V
      13: checkcast     #27                 // class java/util/List
      16: astore_2
      17: aload_1
      18: invokeinterface #31,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      23: astore_3
      24: aload_3
      25: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      30: ifeq          101
      33: aload_3
      34: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #43                 // class java/lang/String
      42: astore        4
      44: aload_0
      45: aload         4
      47: invokespecial #47                 // Method time:(Ljava/lang/String;)I
      50: istore        5
      52: iload         5
      54: invokestatic  #53                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      57: astore        7
      59: aload_2
      60: checkcast     #55                 // class java/util/Collection
      63: aload         7
      65: invokeinterface #59,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      70: pop
      71: iload         5
      73: sipush        780
      76: if_icmpge     24
      79: aload_2
      80: checkcast     #55                 // class java/util/Collection
      83: sipush        1440
      86: iload         5
      88: iadd
      89: invokestatic  #53                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: invokeinterface #59,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: goto          24
     101: aload_2
     102: invokestatic  #65                 // Method kotlin/collections/CollectionsKt.sort:(Ljava/util/List;)V
     105: sipush        1440
     108: istore_3
     109: iconst_1
     110: istore        4
     112: aload_2
     113: invokeinterface #69,  1           // InterfaceMethod java/util/List.size:()I
     118: istore        5
     120: iload         4
     122: iload         5
     124: if_icmpge     175
     127: aload_2
     128: iload         4
     130: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     135: checkcast     #75                 // class java/lang/Number
     138: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     141: aload_2
     142: iload         4
     144: iconst_1
     145: isub
     146: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #75                 // class java/lang/Number
     154: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     157: isub
     158: istore        6
     160: iload         6
     162: iload_3
     163: if_icmpge     169
     166: iload         6
     168: istore_3
     169: iinc          4, 1
     172: goto          120
     175: iload_3
     176: ireturn

  private final int time(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #88                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #43                 // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #90                 // String :
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #96                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #98                 // class java/lang/Iterable
      26: astore_2
      27: nop
      28: iconst_0
      29: istore_3
      30: aload_2
      31: astore        4
      33: new           #24                 // class java/util/ArrayList
      36: dup
      37: aload_2
      38: bipush        10
      40: invokestatic  #102                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      43: invokespecial #105                // Method java/util/ArrayList."<init>":(I)V
      46: checkcast     #55                 // class java/util/Collection
      49: astore        5
      51: iconst_0
      52: istore        6
      54: aload         4
      56: invokeinterface #106,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      61: astore        7
      63: aload         7
      65: invokeinterface #37,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      70: ifeq          117
      73: aload         7
      75: invokeinterface #41,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      80: astore        8
      82: aload         5
      84: aload         8
      86: checkcast     #43                 // class java/lang/String
      89: astore        9
      91: astore        11
      93: iconst_0
      94: istore        10
      96: aload         9
      98: invokestatic  #109                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     101: nop
     102: invokestatic  #53                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: aload         11
     107: swap
     108: invokeinterface #59,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     113: pop
     114: goto          63
     117: aload         5
     119: checkcast     #27                 // class java/util/List
     122: nop
     123: astore_3
     124: iconst_0
     125: istore        4
     127: aload_3
     128: iconst_0
     129: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #75                 // class java/lang/Number
     137: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     140: istore        5
     142: aload_3
     143: iconst_1
     144: invokeinterface #73,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     149: checkcast     #75                 // class java/lang/Number
     152: invokevirtual #78                 // Method java/lang/Number.intValue:()I
     155: istore        6
     157: iload         5
     159: bipush        60
     161: imul
     162: iload         6
     164: iadd
     165: nop
     166: ireturn
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/297
class P131 {
    fun partition(s: String): List<List<String>> {
        // dynamic programming
        val dp = Array(s.length) { IntArray(s.length) }.apply {
            for (i in s.indices) this[i][i] = 1
            for (i in 1 until s.length) {
                if (s[i - 1] == s[i]) {
                    this[i - 1][i] = 1
                }
            }

            for (start in 2 until s.length) {
                var i = 0
                var j = start
                while (j < s.length) {
                    if (s[i] == s[j] && this[i + 1][j - 1] == 1) {
                        this[i][j] = 1
                    }
                    i++
                    j++
                }
            }
        }

        // backtracking
        val answer = mutableListOf<List<String>>()
        val pool = mutableListOf<String>()
        dfs(dp, answer, pool, s, 0)
        return answer
    }

    private fun dfs(
        dp: Array<IntArray>,
        answer: MutableList<List<String>>,
        pool: MutableList<String>,
        s: String,
        p: Int
    ) {
        if (p == s.length) {
            answer += pool.toList()
            return
        }
        for (i in p until s.length) {
            if (dp[p][i] == 1) {
                pool.add(s.substring(p, i + 1))
                dfs(dp, answer, pool, s, i + 1)
                pool.removeAt(pool.lastIndex)
            }
        }
    }
}

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

  public final java.util.List<java.util.List<java.lang.String>> partition(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #16                 // String s
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_3
       8: aload_1
       9: invokevirtual #28                 // Method java/lang/String.length:()I
      12: istore        4
      14: iload         4
      16: anewarray     #30                 // class "[I"
      19: astore        5
      21: iload_3
      22: iload         4
      24: if_icmpge     47
      27: iload_3
      28: istore        6
      30: aload         5
      32: iload         6
      34: aload_1
      35: invokevirtual #28                 // Method java/lang/String.length:()I
      38: newarray       int
      40: aastore
      41: iinc          3, 1
      44: goto          21
      47: aload         5
      49: astore_3
      50: aload_3
      51: checkcast     #32                 // class "[[I"
      54: astore        4
      56: iconst_0
      57: istore        5
      59: iconst_0
      60: istore        6
      62: aload_1
      63: checkcast     #34                 // class java/lang/CharSequence
      66: invokeinterface #35,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      71: istore        7
      73: iload         6
      75: iload         7
      77: if_icmpge     95
      80: aload         4
      82: iload         6
      84: aaload
      85: iload         6
      87: iconst_1
      88: iastore
      89: iinc          6, 1
      92: goto          73
      95: iconst_1
      96: istore        6
      98: aload_1
      99: invokevirtual #28                 // Method java/lang/String.length:()I
     102: istore        7
     104: iload         6
     106: iload         7
     108: if_icmpge     145
     111: aload_1
     112: iload         6
     114: iconst_1
     115: isub
     116: invokevirtual #39                 // Method java/lang/String.charAt:(I)C
     119: aload_1
     120: iload         6
     122: invokevirtual #39                 // Method java/lang/String.charAt:(I)C
     125: if_icmpne     139
     128: aload         4
     130: iload         6
     132: iconst_1
     133: isub
     134: aaload
     135: iload         6
     137: iconst_1
     138: iastore
     139: iinc          6, 1
     142: goto          104
     145: iconst_2
     146: istore        6
     148: aload_1
     149: invokevirtual #28                 // Method java/lang/String.length:()I
     152: istore        7
     154: iload         6
     156: iload         7
     158: if_icmpge     232
     161: iconst_0
     162: istore        8
     164: iload         6
     166: istore        9
     168: iload         9
     170: aload_1
     171: invokevirtual #28                 // Method java/lang/String.length:()I
     174: if_icmpge     226
     177: aload_1
     178: iload         8
     180: invokevirtual #39                 // Method java/lang/String.charAt:(I)C
     183: aload_1
     184: iload         9
     186: invokevirtual #39                 // Method java/lang/String.charAt:(I)C
     189: if_icmpne     217
     192: aload         4
     194: iload         8
     196: iconst_1
     197: iadd
     198: aaload
     199: iload         9
     201: iconst_1
     202: isub
     203: iaload
     204: iconst_1
     205: if_icmpne     217
     208: aload         4
     210: iload         8
     212: aaload
     213: iload         9
     215: iconst_1
     216: iastore
     217: iinc          8, 1
     220: iinc          9, 1
     223: goto          168
     226: iinc          6, 1
     229: goto          154
     232: nop
     233: aload_3
     234: checkcast     #32                 // class "[[I"
     237: astore_2
     238: new           #41                 // class java/util/ArrayList
     241: dup
     242: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
     245: checkcast     #44                 // class java/util/List
     248: astore_3
     249: new           #41                 // class java/util/ArrayList
     252: dup
     253: invokespecial #42                 // Method java/util/ArrayList."<init>":()V
     256: checkcast     #44                 // class java/util/List
     259: astore        4
     261: aload_0
     262: aload_2
     263: aload_3
     264: aload         4
     266: aload_1
     267: iconst_0
     268: invokespecial #48                 // Method dfs:([[ILjava/util/List;Ljava/util/List;Ljava/lang/String;I)V
     271: aload_3
     272: areturn

  private final void dfs(int[][], java.util.List<java.util.List<java.lang.String>>, java.util.List<java.lang.String>, java.lang.String, int);
    Code:
       0: iload         5
       2: aload         4
       4: invokevirtual #28                 // Method java/lang/String.length:()I
       7: if_icmpne     28
      10: aload_2
      11: checkcast     #62                 // class java/util/Collection
      14: aload_3
      15: checkcast     #64                 // class java/lang/Iterable
      18: invokestatic  #70                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      21: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      26: pop
      27: return
      28: iload         5
      30: istore        6
      32: aload         4
      34: invokevirtual #28                 // Method java/lang/String.length:()I
      37: istore        7
      39: iload         6
      41: iload         7
      43: if_icmpge     111
      46: aload_1
      47: iload         5
      49: aaload
      50: iload         6
      52: iaload
      53: iconst_1
      54: if_icmpne     105
      57: aload_3
      58: aload         4
      60: iload         5
      62: iload         6
      64: iconst_1
      65: iadd
      66: invokevirtual #78                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      69: dup
      70: ldc           #80                 // String substring(...)
      72: invokestatic  #83                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      75: invokeinterface #84,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      80: pop
      81: aload_0
      82: aload_1
      83: aload_2
      84: aload_3
      85: aload         4
      87: iload         6
      89: iconst_1
      90: iadd
      91: invokespecial #48                 // Method dfs:([[ILjava/util/List;Ljava/util/List;Ljava/lang/String;I)V
      94: aload_3
      95: aload_3
      96: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      99: invokeinterface #92,  2           // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     104: pop
     105: iinc          6, 1
     108: goto          39
     111: return
}


package com.leetcode

// https://leetcode.com/problems/count-submatrices-with-all-ones/
class P1504 {
    fun numSubmat(mat: Array<IntArray>): Int {
        // For each row i, create an array nums where: if mat[i][j] == 0 then nums[j] = 0 else nums[j] = nums[j-1] +1.
        for (i in mat.indices) {
            for (j in 1 until mat[i].size) {
                mat[i][j] = if (mat[i][j] == 1) mat[i][j - 1] + 1 else 0
            }
        }

        var submatrices = 0;
        // In the row i, number of rectangles between column j and k(inclusive) and ends in row i, is equal to SUM(min(nums[j, .. idx])) where idx go from j to k.
        // Expected solution is O(n^3).
        for (i in mat.lastIndex downTo 0) {
            for (j in mat[i].indices) {
                submatrices += mat[i][j] + (0 until i).map { k ->
                    (k..i).map { idx -> mat[idx][j] }.min()!!
                }.sum()
            }
        }
        return submatrices
    }
}

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

  public final int numSubmat(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String mat
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: aload_1
       9: checkcast     #23                 // class "[Ljava/lang/Object;"
      12: arraylength
      13: istore_3
      14: iload_2
      15: iload_3
      16: if_icmpge     77
      19: iconst_1
      20: istore        4
      22: aload_1
      23: iload_2
      24: aaload
      25: arraylength
      26: istore        5
      28: iload         4
      30: iload         5
      32: if_icmpge     71
      35: aload_1
      36: iload_2
      37: aaload
      38: iload         4
      40: aload_1
      41: iload_2
      42: aaload
      43: iload         4
      45: iaload
      46: iconst_1
      47: if_icmpne     63
      50: aload_1
      51: iload_2
      52: aaload
      53: iload         4
      55: iconst_1
      56: isub
      57: iaload
      58: iconst_1
      59: iadd
      60: goto          64
      63: iconst_0
      64: iastore
      65: iinc          4, 1
      68: goto          28
      71: iinc          2, 1
      74: goto          14
      77: iconst_0
      78: istore_2
      79: aload_1
      80: checkcast     #23                 // class "[Ljava/lang/Object;"
      83: invokestatic  #29                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      86: istore_3
      87: iconst_m1
      88: iload_3
      89: if_icmpge     376
      92: iconst_0
      93: istore        4
      95: aload_1
      96: iload_3
      97: aaload
      98: arraylength
      99: istore        5
     101: iload         4
     103: iload         5
     105: if_icmpge     370
     108: iload_2
     109: aload_1
     110: iload_3
     111: aaload
     112: iload         4
     114: iaload
     115: iconst_0
     116: iload_3
     117: invokestatic  #35                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     120: checkcast     #37                 // class java/lang/Iterable
     123: astore        6
     125: istore        26
     127: istore        25
     129: iconst_0
     130: istore        7
     132: aload         6
     134: astore        8
     136: new           #39                 // class java/util/ArrayList
     139: dup
     140: aload         6
     142: bipush        10
     144: invokestatic  #45                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     147: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
     150: checkcast     #50                 // class java/util/Collection
     153: astore        9
     155: iconst_0
     156: istore        10
     158: aload         8
     160: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     165: astore        11
     167: aload         11
     169: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     174: ifeq          341
     177: aload         11
     179: checkcast     #62                 // class kotlin/collections/IntIterator
     182: invokevirtual #66                 // Method kotlin/collections/IntIterator.nextInt:()I
     185: istore        12
     187: aload         9
     189: iload         12
     191: istore        13
     193: astore        27
     195: iconst_0
     196: istore        14
     198: new           #68                 // class kotlin/ranges/IntRange
     201: dup
     202: iload         13
     204: iload_3
     205: invokespecial #71                 // Method kotlin/ranges/IntRange."<init>":(II)V
     208: checkcast     #37                 // class java/lang/Iterable
     211: astore        15
     213: iconst_0
     214: istore        16
     216: aload         15
     218: astore        17
     220: new           #39                 // class java/util/ArrayList
     223: dup
     224: aload         15
     226: bipush        10
     228: invokestatic  #45                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     231: invokespecial #48                 // Method java/util/ArrayList."<init>":(I)V
     234: checkcast     #50                 // class java/util/Collection
     237: astore        18
     239: iconst_0
     240: istore        19
     242: aload         17
     244: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     249: astore        20
     251: aload         20
     253: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     258: ifeq          304
     261: aload         20
     263: checkcast     #62                 // class kotlin/collections/IntIterator
     266: invokevirtual #66                 // Method kotlin/collections/IntIterator.nextInt:()I
     269: istore        21
     271: aload         18
     273: iload         21
     275: istore        22
     277: astore        23
     279: iconst_0
     280: istore        24
     282: aload_1
     283: iload         22
     285: aaload
     286: iload         4
     288: iaload
     289: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     292: aload         23
     294: swap
     295: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     300: pop
     301: goto          251
     304: aload         18
     306: checkcast     #83                 // class java/util/List
     309: nop
     310: checkcast     #37                 // class java/lang/Iterable
     313: invokestatic  #87                 // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     316: dup
     317: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     320: checkcast     #93                 // class java/lang/Number
     323: invokevirtual #96                 // Method java/lang/Number.intValue:()I
     326: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     329: aload         27
     331: swap
     332: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     337: pop
     338: goto          167
     341: aload         9
     343: checkcast     #83                 // class java/util/List
     346: nop
     347: astore        27
     349: iload         25
     351: iload         26
     353: aload         27
     355: checkcast     #37                 // class java/lang/Iterable
     358: invokestatic  #100                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     361: iadd
     362: iadd
     363: istore_2
     364: iinc          4, 1
     367: goto          101
     370: iinc          3, -1
     373: goto          87
     376: iload_2
     377: ireturn
}


package com.leetcode

// https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/
class P235 {
    fun lowestCommonAncestor(root: TreeNode?, p: TreeNode?, q: TreeNode?): TreeNode? {
        val path1 = path(root!!, p!!)
        val path2 = path(root, q!!)
        println()
        println("path1 = ${path1.contentToString()}, path2 = ${path2.contentToString()}")

        for (i in path1.lastIndex downTo 0) {
            for (j in path2.lastIndex downTo 0) {
                if (path1[i] == path2[j]) return TreeNode(path1[i])
            }
        }
        return null
    }

    // 재귀의 시작
    private fun path(root: TreeNode, target: TreeNode): IntArray {
        println()
        println("find path = ${target.`val`}")
        val list = mutableListOf<Int>()
        search(list, root, target.`val`);
        return list.toIntArray()
    }

    // 재귀 (꼬리)
    private fun search(list: MutableList<Int>, node: TreeNode?, target: Int): Boolean {
        if (node == null) return false
        println("  search node = ${node.`val`}")
        if (node.`val` == target // 현재 내 노드가 타겟과 같거나
                || search(list, node.left, target) // 내 왼쪽 노드를 탐색해서 참이 나오거나
                || search(list, node.right, target) // 내 오른쪽 노드를 탐색해서 참이 나오거나
        ) {
            list.add(0, node.`val`) // 리스트의 앞에 삽입
            return true
        }
        return false
    }

    class TreeNode(var `val`: Int = 0) {
        var left: TreeNode? = null
        var right: TreeNode? = null
    }
}

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

  public final com.leetcode.P235$TreeNode lowestCommonAncestor(com.leetcode.P235$TreeNode, com.leetcode.P235$TreeNode, com.leetcode.P235$TreeNode);
    Code:
       0: aload_0
       1: aload_1
       2: dup
       3: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       6: aload_2
       7: dup
       8: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      11: invokespecial #23                 // Method path:(Lcom/leetcode/P235$TreeNode;Lcom/leetcode/P235$TreeNode;)[I
      14: astore        4
      16: aload_0
      17: aload_1
      18: aload_3
      19: dup
      20: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      23: invokespecial #23                 // Method path:(Lcom/leetcode/P235$TreeNode;Lcom/leetcode/P235$TreeNode;)[I
      26: astore        5
      28: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: invokevirtual #34                 // Method java/io/PrintStream.println:()V
      34: new           #36                 // class java/lang/StringBuilder
      37: dup
      38: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
      41: ldc           #39                 // String path1 =
      43: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      46: aload         4
      48: invokestatic  #49                 // Method java/util/Arrays.toString:([I)Ljava/lang/String;
      51: dup
      52: ldc           #51                 // String toString(...)
      54: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      57: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      60: ldc           #57                 // String , path2 =
      62: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      65: aload         5
      67: invokestatic  #49                 // Method java/util/Arrays.toString:([I)Ljava/lang/String;
      70: dup
      71: ldc           #51                 // String toString(...)
      73: invokestatic  #55                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      76: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      79: invokevirtual #60                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      82: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      85: swap
      86: invokevirtual #62                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      89: aload         4
      91: invokestatic  #68                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
      94: istore        6
      96: iconst_m1
      97: iload         6
      99: if_icmpge     153
     102: aload         5
     104: invokestatic  #68                 // Method kotlin/collections/ArraysKt.getLastIndex:([I)I
     107: istore        7
     109: iconst_m1
     110: iload         7
     112: if_icmpge     147
     115: aload         4
     117: iload         6
     119: iaload
     120: aload         5
     122: iload         7
     124: iaload
     125: if_icmpne     141
     128: new           #70                 // class com/leetcode/P235$TreeNode
     131: dup
     132: aload         4
     134: iload         6
     136: iaload
     137: invokespecial #73                 // Method com/leetcode/P235$TreeNode."<init>":(I)V
     140: areturn
     141: iinc          7, -1
     144: goto          109
     147: iinc          6, -1
     150: goto          96
     153: aconst_null
     154: areturn

  private final int[] path(com.leetcode.P235$TreeNode, com.leetcode.P235$TreeNode);
    Code:
       0: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
       3: invokevirtual #34                 // Method java/io/PrintStream.println:()V
       6: new           #36                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #86                 // String find path =
      15: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_2
      19: invokevirtual #90                 // Method com/leetcode/P235$TreeNode.getVal:()I
      22: invokevirtual #93                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      25: invokevirtual #60                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #62                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: new           #95                 // class java/util/ArrayList
      38: dup
      39: invokespecial #96                 // Method java/util/ArrayList."<init>":()V
      42: checkcast     #98                 // class java/util/List
      45: astore_3
      46: aload_0
      47: aload_3
      48: aload_1
      49: aload_2
      50: invokevirtual #90                 // Method com/leetcode/P235$TreeNode.getVal:()I
      53: invokespecial #102                // Method search:(Ljava/util/List;Lcom/leetcode/P235$TreeNode;I)Z
      56: pop
      57: aload_3
      58: checkcast     #104                // class java/util/Collection
      61: invokestatic  #110                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
      64: areturn

  private final boolean search(java.util.List<java.lang.Integer>, com.leetcode.P235$TreeNode, int);
    Code:
       0: aload_2
       1: ifnonnull     6
       4: iconst_0
       5: ireturn
       6: new           #36                 // class java/lang/StringBuilder
       9: dup
      10: invokespecial #37                 // Method java/lang/StringBuilder."<init>":()V
      13: ldc           #116                // String   search node =
      15: invokevirtual #43                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      18: aload_2
      19: invokevirtual #90                 // Method com/leetcode/P235$TreeNode.getVal:()I
      22: invokevirtual #93                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      25: invokevirtual #60                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      28: getstatic     #29                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: swap
      32: invokevirtual #62                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      35: aload_2
      36: invokevirtual #90                 // Method com/leetcode/P235$TreeNode.getVal:()I
      39: iload_3
      40: if_icmpeq     69
      43: aload_0
      44: aload_1
      45: aload_2
      46: invokevirtual #120                // Method com/leetcode/P235$TreeNode.getLeft:()Lcom/leetcode/P235$TreeNode;
      49: iload_3
      50: invokespecial #102                // Method search:(Ljava/util/List;Lcom/leetcode/P235$TreeNode;I)Z
      53: ifne          69
      56: aload_0
      57: aload_1
      58: aload_2
      59: invokevirtual #123                // Method com/leetcode/P235$TreeNode.getRight:()Lcom/leetcode/P235$TreeNode;
      62: iload_3
      63: invokespecial #102                // Method search:(Ljava/util/List;Lcom/leetcode/P235$TreeNode;I)Z
      66: ifeq          85
      69: aload_1
      70: iconst_0
      71: aload_2
      72: invokevirtual #90                 // Method com/leetcode/P235$TreeNode.getVal:()I
      75: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokeinterface #133,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
      83: iconst_1
      84: ireturn
      85: iconst_0
      86: ireturn
}

Compiled from "P235.kt"
public final class com.leetcode.P235$TreeNode {
  private int val;

  private com.leetcode.P235$TreeNode left;

  private com.leetcode.P235$TreeNode right;

  public com.leetcode.P235$TreeNode(int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field val:I
       9: return

  public com.leetcode.P235$TreeNode(int, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_1
       8: aload_0
       9: iload_1
      10: invokespecial #18                 // Method "<init>":(I)V
      13: return

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

  public final void setVal(int);
    Code:
       0: aload_0
       1: iload_1
       2: putfield      #13                 // Field val:I
       5: return

  public final com.leetcode.P235$TreeNode getLeft();
    Code:
       0: aload_0
       1: getfield      #28                 // Field left:Lcom/leetcode/P235$TreeNode;
       4: areturn

  public final void setLeft(com.leetcode.P235$TreeNode);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #28                 // Field left:Lcom/leetcode/P235$TreeNode;
       5: return

  public final com.leetcode.P235$TreeNode getRight();
    Code:
       0: aload_0
       1: getfield      #34                 // Field right:Lcom/leetcode/P235$TreeNode;
       4: areturn

  public final void setRight(com.leetcode.P235$TreeNode);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #34                 // Field right:Lcom/leetcode/P235$TreeNode;
       5: return

  public com.leetcode.P235$TreeNode();
    Code:
       0: aload_0
       1: iconst_0
       2: iconst_1
       3: aconst_null
       4: invokespecial #37                 // Method "<init>":(IILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/267
class P720 {

    fun longestWord(words: Array<String>): String {
        val root = TrieNode()
        var answer = ""

        words.sortWith(
            Comparator<String> { o1, o2 -> o1.length - o2.length }
                .then(Comparator { o1, o2 -> if (o1 < o2) -1 else 1 })
        )

        word@ for (word in words) {
            var node = root
            for (i in word.indices) {
                val idx = word[i] - 'a'

                if (node.children[idx] != null) {
                    node = node.children[idx]!!
                    continue
                }

                if (i < word.lastIndex) continue@word
                if (i == word.lastIndex) {
                    if (word.length > answer.length) answer = word
                    val newNode = TrieNode(word[i])
                    node.children[idx] = newNode
                    node = newNode
                }
            }
        }
        return answer
    }

    class TrieNode(val char: Char? = null) {
        val children = Array<TrieNode?>(26) { null }
    }

}

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

  public final java.lang.String longestWord(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String words
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class com/leetcode/P720$TrieNode
       9: dup
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokespecial #26                 // Method com/leetcode/P720$TrieNode."<init>":(Ljava/lang/Character;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      16: astore_2
      17: ldc           #28                 // String
      19: astore_3
      20: aload_1
      21: invokedynamic #47,  0             // InvokeDynamic #0:compare:()Ljava/util/Comparator;
      26: invokedynamic #52,  0             // InvokeDynamic #1:compare:()Ljava/util/Comparator;
      31: invokestatic  #58                 // Method kotlin/comparisons/ComparisonsKt.then:(Ljava/util/Comparator;Ljava/util/Comparator;)Ljava/util/Comparator;
      34: invokestatic  #64                 // Method kotlin/collections/ArraysKt.sortWith:([Ljava/lang/Object;Ljava/util/Comparator;)V
      37: iconst_0
      38: istore        4
      40: aload_1
      41: arraylength
      42: istore        5
      44: iload         4
      46: iload         5
      48: if_icmpge     208
      51: aload_1
      52: iload         4
      54: aaload
      55: astore        6
      57: aload_2
      58: astore        7
      60: iconst_0
      61: istore        8
      63: aload         6
      65: checkcast     #66                 // class java/lang/CharSequence
      68: invokeinterface #70,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      73: istore        9
      75: iload         8
      77: iload         9
      79: if_icmpge     202
      82: aload         6
      84: iload         8
      86: invokevirtual #76                 // Method java/lang/String.charAt:(I)C
      89: bipush        97
      91: isub
      92: istore        10
      94: aload         7
      96: invokevirtual #80                 // Method com/leetcode/P720$TrieNode.getChildren:()[Lcom/leetcode/P720$TrieNode;
      99: iload         10
     101: aaload
     102: ifnull        122
     105: aload         7
     107: invokevirtual #80                 // Method com/leetcode/P720$TrieNode.getChildren:()[Lcom/leetcode/P720$TrieNode;
     110: iload         10
     112: aaload
     113: dup
     114: invokestatic  #84                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     117: astore        7
     119: goto          196
     122: iload         8
     124: aload         6
     126: checkcast     #66                 // class java/lang/CharSequence
     129: invokestatic  #90                 // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
     132: if_icmplt     202
     135: iload         8
     137: aload         6
     139: checkcast     #66                 // class java/lang/CharSequence
     142: invokestatic  #90                 // Method kotlin/text/StringsKt.getLastIndex:(Ljava/lang/CharSequence;)I
     145: if_icmpne     196
     148: aload         6
     150: invokevirtual #91                 // Method java/lang/String.length:()I
     153: aload_3
     154: invokevirtual #91                 // Method java/lang/String.length:()I
     157: if_icmple     163
     160: aload         6
     162: astore_3
     163: new           #23                 // class com/leetcode/P720$TrieNode
     166: dup
     167: aload         6
     169: iload         8
     171: invokevirtual #76                 // Method java/lang/String.charAt:(I)C
     174: invokestatic  #97                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     177: invokespecial #100                // Method com/leetcode/P720$TrieNode."<init>":(Ljava/lang/Character;)V
     180: astore        11
     182: aload         7
     184: invokevirtual #80                 // Method com/leetcode/P720$TrieNode.getChildren:()[Lcom/leetcode/P720$TrieNode;
     187: iload         10
     189: aload         11
     191: aastore
     192: aload         11
     194: astore        7
     196: iinc          8, 1
     199: goto          75
     202: iinc          4, 1
     205: goto          44
     208: aload_3
     209: areturn

  private static final int longestWord$lambda$0(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: invokevirtual #91                 // Method java/lang/String.length:()I
       4: aload_1
       5: invokevirtual #91                 // Method java/lang/String.length:()I
       8: isub
       9: ireturn

  private static final int longestWord$lambda$1(java.lang.String, java.lang.String);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #84                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       5: aload_1
       6: invokevirtual #118                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
       9: ifge          16
      12: iconst_m1
      13: goto          17
      16: iconst_1
      17: ireturn
}

Compiled from "P720.kt"
public final class com.leetcode.P720$TrieNode {
  private final java.lang.Character char;

  private final com.leetcode.P720$TrieNode[] children;

  public com.leetcode.P720$TrieNode(java.lang.Character);
    Code:
       0: aload_0
       1: invokespecial #10                 // Method java/lang/Object."<init>":()V
       4: aload_0
       5: aload_1
       6: putfield      #14                 // Field char:Ljava/lang/Character;
       9: aload_0
      10: iconst_0
      11: istore_2
      12: bipush        26
      14: anewarray     #2                  // class com/leetcode/P720$TrieNode
      17: astore_3
      18: astore        5
      20: iload_2
      21: bipush        26
      23: if_icmpge     40
      26: iload_2
      27: istore        4
      29: aload_3
      30: iload         4
      32: aconst_null
      33: aastore
      34: iinc          2, 1
      37: goto          20
      40: aload         5
      42: aload_3
      43: putfield      #18                 // Field children:[Lcom/leetcode/P720$TrieNode;
      46: return

  public com.leetcode.P720$TrieNode(java.lang.Character, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          8
       6: aconst_null
       7: astore_1
       8: aload_0
       9: aload_1
      10: invokespecial #26                 // Method "<init>":(Ljava/lang/Character;)V
      13: return

  public final java.lang.Character getChar();
    Code:
       0: aload_0
       1: getfield      #14                 // Field char:Ljava/lang/Character;
       4: areturn

  public final com.leetcode.P720$TrieNode[] getChildren();
    Code:
       0: aload_0
       1: getfield      #18                 // Field children:[Lcom/leetcode/P720$TrieNode;
       4: areturn

  public com.leetcode.P720$TrieNode();
    Code:
       0: aload_0
       1: aconst_null
       2: iconst_1
       3: aconst_null
       4: invokespecial #33                 // Method "<init>":(Ljava/lang/Character;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return
}


package com.leetcode

// https://github.com/antop-dev/algorithm/issues/313
class P130 {
    fun solve(board: Array<CharArray>) {
        val m = board.size
        val n = board[0].size
        // [0] : 방문 여부
        // [1] : 'O' 여부
        val visited = Array(m) { Array(n) { IntArray(2) } }

        for (j in 0 until n) {
            dfs(board, visited, 0, j)
            dfs(board, visited, m - 1, j)
        }

        for (i in 1 until m - 1) {
            dfs(board, visited, i, 0)
            dfs(board, visited, i, n - 1)
        }

        // 방문되지 않은 곳을 전부 'X'로 변경
        for (i in 0 until m) {
            for (j in 0 until n) {
                if (visited[i][j][0] == 0) {
                    board[i][j] = 'X'
                }
            }
        }
    }

    private fun dfs(board: Array<CharArray>, visited: Array<Array<IntArray>>, i: Int, j: Int) {
        if (i !in 0..board.lastIndex) return
        if (j !in 0..board[0].lastIndex) return

        val here = visited[i][j]
        if (here[0] == 1) return

        here[0] = 1 // visited
        if (board[i][j] == 'X') return

        here[1] = 1 // 'O'
        dfs(board, visited, i - 1, j) // ↑
        dfs(board, visited, i + 1, j) // ↓
        dfs(board, visited, i, j - 1) // ←
        dfs(board, visited, i, j + 1) // →
    }

}

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

  public final void solve(char[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String board
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #23                 // class "[Ljava/lang/Object;"
      10: arraylength
      11: istore_2
      12: aload_1
      13: iconst_0
      14: aaload
      15: arraylength
      16: istore_3
      17: iconst_0
      18: istore        5
      20: iload_2
      21: anewarray     #25                 // class "[[I"
      24: astore        6
      26: iload         5
      28: iload_2
      29: if_icmpge     90
      32: iload         5
      34: istore        7
      36: aload         6
      38: iload         7
      40: iconst_0
      41: istore        8
      43: iload_3
      44: anewarray     #27                 // class "[I"
      47: astore        9
      49: istore        12
      51: astore        11
      53: iload         8
      55: iload_3
      56: if_icmpge     77
      59: iload         8
      61: istore        10
      63: aload         9
      65: iload         10
      67: iconst_2
      68: newarray       int
      70: aastore
      71: iinc          8, 1
      74: goto          53
      77: aload         11
      79: iload         12
      81: aload         9
      83: aastore
      84: iinc          5, 1
      87: goto          26
      90: aload         6
      92: astore        4
      94: iconst_0
      95: istore        5
      97: iload         5
      99: iload_3
     100: if_icmpge     131
     103: aload_0
     104: aload_1
     105: aload         4
     107: iconst_0
     108: iload         5
     110: invokespecial #31                 // Method dfs:([[C[[[III)V
     113: aload_0
     114: aload_1
     115: aload         4
     117: iload_2
     118: iconst_1
     119: isub
     120: iload         5
     122: invokespecial #31                 // Method dfs:([[C[[[III)V
     125: iinc          5, 1
     128: goto          97
     131: iconst_1
     132: istore        5
     134: iload_2
     135: iconst_1
     136: isub
     137: istore        6
     139: iload         5
     141: iload         6
     143: if_icmpge     174
     146: aload_0
     147: aload_1
     148: aload         4
     150: iload         5
     152: iconst_0
     153: invokespecial #31                 // Method dfs:([[C[[[III)V
     156: aload_0
     157: aload_1
     158: aload         4
     160: iload         5
     162: iload_3
     163: iconst_1
     164: isub
     165: invokespecial #31                 // Method dfs:([[C[[[III)V
     168: iinc          5, 1
     171: goto          139
     174: iconst_0
     175: istore        5
     177: iload         5
     179: iload_2
     180: if_icmpge     226
     183: iconst_0
     184: istore        6
     186: iload         6
     188: iload_3
     189: if_icmpge     220
     192: aload         4
     194: iload         5
     196: aaload
     197: iload         6
     199: aaload
     200: iconst_0
     201: iaload
     202: ifne          214
     205: aload_1
     206: iload         5
     208: aaload
     209: iload         6
     211: bipush        88
     213: castore
     214: iinc          6, 1
     217: goto          186
     220: iinc          5, 1
     223: goto          177
     226: return

  private final void dfs(char[][], int[][][], int, int);
    Code:
       0: iconst_0
       1: iload_3
       2: if_icmpgt     24
       5: iload_3
       6: aload_1
       7: checkcast     #23                 // class "[Ljava/lang/Object;"
      10: invokestatic  #47                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
      13: if_icmpgt     20
      16: iconst_1
      17: goto          25
      20: iconst_0
      21: goto          25
      24: iconst_0
      25: ifne          29
      28: return
      29: iconst_0
      30: iload         4
      32: if_icmpgt     54
      35: iload         4
      37: aload_1
      38: iconst_0
      39: aaload
      40: invokestatic  #50                 // Method kotlin/collections/ArraysKt.getLastIndex:([C)I
      43: if_icmpgt     50
      46: iconst_1
      47: goto          55
      50: iconst_0
      51: goto          55
      54: iconst_0
      55: ifne          59
      58: return
      59: aload_2
      60: iload_3
      61: aaload
      62: iload         4
      64: aaload
      65: astore        5
      67: aload         5
      69: iconst_0
      70: iaload
      71: iconst_1
      72: if_icmpne     76
      75: return
      76: aload         5
      78: iconst_0
      79: iconst_1
      80: iastore
      81: aload_1
      82: iload_3
      83: aaload
      84: iload         4
      86: caload
      87: bipush        88
      89: if_icmpne     93
      92: return
      93: aload         5
      95: iconst_1
      96: iconst_1
      97: iastore
      98: aload_0
      99: aload_1
     100: aload_2
     101: iload_3
     102: iconst_1
     103: isub
     104: iload         4
     106: invokespecial #31                 // Method dfs:([[C[[[III)V
     109: aload_0
     110: aload_1
     111: aload_2
     112: iload_3
     113: iconst_1
     114: iadd
     115: iload         4
     117: invokespecial #31                 // Method dfs:([[C[[[III)V
     120: aload_0
     121: aload_1
     122: aload_2
     123: iload_3
     124: iload         4
     126: iconst_1
     127: isub
     128: invokespecial #31                 // Method dfs:([[C[[[III)V
     131: aload_0
     132: aload_1
     133: aload_2
     134: iload_3
     135: iload         4
     137: iconst_1
     138: iadd
     139: invokespecial #31                 // Method dfs:([[C[[[III)V
     142: return
}