package ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck

import java.lang.IllegalArgumentException
import java.util.*

fun luckBalance(k: Int, contests: List<Contest>): Int {
    val (importantContests, unimportanceContests) =
        contests.partition { it.importance == Importance.IMPORTANT }

    val sortedImportantContests =
        importantContests.sortedBy { it.luck }

    val lostContestLuck =
        (unimportanceContests + sortedImportantContests.takeLast(k)).totalLuck

    val importantContestsCnt = importantContests.size

    return if (importantContestsCnt > k) {
        val winContestsLuck =
            sortedImportantContests.take(importantContestsCnt - k).totalLuck

        lostContestLuck - winContestsLuck
    } else lostContestLuck
}

private val List<Contest>.totalLuck: Int
        get() = sumBy { it.luck }

data class Contest(val luck: Int, val importance: Importance)

enum class Importance {
    IMPORTANT,
    UNIMPORTANT
}

private fun from(importanceValue: Int): Importance = when (importanceValue) {
    0 -> Importance.UNIMPORTANT
    1 -> Importance.IMPORTANT
    else -> throw IllegalArgumentException(
        "got illegal importanceValue = $importanceValue; 0 or 1 expected"
    )
}

fun main() {
    val scan = Scanner(System.`in`)

    val (n, k) = scan.nextLine().split(" ").map { it.toInt() }

    val contests = (1..n).map {
        val (luck, importanceValue) = scan.nextLine().split(" ").map { it.trim().toInt() }
        Contest(luck, from(importanceValue))
    }

    val result = luckBalance(k, contests)
    println(result)
}

Compiled from "Comparisons.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck.LuckBalanceKt$luckBalance$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck.LuckBalanceKt$luckBalance$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest.getLuck:()I
      12: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest.getLuck:()I
      32: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "LuckBalance.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck.LuckBalanceKt {
  public static final int luckBalance(int, java.util.List<ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck.Contest>);
    Code:
       0: aload_1
       1: ldc           #10                 // String contests
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_3
      11: iconst_0
      12: istore        4
      14: new           #20                 // class java/util/ArrayList
      17: dup
      18: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      21: astore        5
      23: new           #20                 // class java/util/ArrayList
      26: dup
      27: invokespecial #24                 // Method java/util/ArrayList."<init>":()V
      30: astore        6
      32: aload_3
      33: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          109
      50: aload         7
      52: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         8
      61: checkcast     #40                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest
      64: astore        9
      66: iconst_0
      67: istore        10
      69: aload         9
      71: invokevirtual #44                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest.getImportance:()Lru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance;
      74: getstatic     #50                 // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance.IMPORTANT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance;
      77: if_acmpne     84
      80: iconst_1
      81: goto          85
      84: iconst_0
      85: ifeq          98
      88: aload         5
      90: aload         8
      92: invokevirtual #54                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      95: goto          105
      98: aload         6
     100: aload         8
     102: invokevirtual #54                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     105: pop
     106: goto          40
     109: new           #56                 // class kotlin/Pair
     112: dup
     113: aload         5
     115: aload         6
     117: invokespecial #59                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     120: astore_2
     121: aload_2
     122: invokevirtual #62                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     125: checkcast     #64                 // class java/util/List
     128: astore_3
     129: aload_2
     130: invokevirtual #67                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     133: checkcast     #64                 // class java/util/List
     136: astore        4
     138: aload_3
     139: checkcast     #18                 // class java/lang/Iterable
     142: astore        6
     144: iconst_0
     145: istore        7
     147: aload         6
     149: new           #69                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/LuckBalanceKt$luckBalance$$inlined$sortedBy$1
     152: dup
     153: invokespecial #70                 // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/LuckBalanceKt$luckBalance$$inlined$sortedBy$1."<init>":()V
     156: checkcast     #72                 // class java/util/Comparator
     159: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     162: astore        5
     164: aload         4
     166: checkcast     #80                 // class java/util/Collection
     169: aload         5
     171: iload_0
     172: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.takeLast:(Ljava/util/List;I)Ljava/util/List;
     175: checkcast     #18                 // class java/lang/Iterable
     178: invokestatic  #88                 // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
     181: invokestatic  #92                 // Method getTotalLuck:(Ljava/util/List;)I
     184: istore        6
     186: aload_3
     187: invokeinterface #96,  1           // InterfaceMethod java/util/List.size:()I
     192: istore        7
     194: iload         7
     196: iload_0
     197: if_icmple     225
     200: aload         5
     202: checkcast     #18                 // class java/lang/Iterable
     205: iload         7
     207: iload_0
     208: isub
     209: invokestatic  #100                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     212: invokestatic  #92                 // Method getTotalLuck:(Ljava/util/List;)I
     215: istore        8
     217: iload         6
     219: iload         8
     221: isub
     222: goto          227
     225: iload         6
     227: ireturn

  private static final int getTotalLuck(java.util.List<ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck.Contest>);
    Code:
       0: aload_0
       1: checkcast     #18                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: aload_1
      10: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore        4
      17: aload         4
      19: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          65
      27: aload         4
      29: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        5
      36: iload_3
      37: aload         5
      39: checkcast     #40                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest
      42: astore        6
      44: istore        8
      46: iconst_0
      47: istore        7
      49: aload         6
      51: invokevirtual #126                // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest.getLuck:()I
      54: istore        9
      56: iload         8
      58: iload         9
      60: iadd
      61: istore_3
      62: goto          17
      65: iload_3
      66: ireturn

  private static final ru.amai.study.hackerrank.practice.interviewPreparationKit.greedy.luck.Importance from(int);
    Code:
       0: iload_0
       1: tableswitch   { // 0 to 1
                     0: 24
                     1: 30
               default: 36
          }
      24: getstatic     #136                // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance.UNIMPORTANT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance;
      27: goto          68
      30: getstatic     #50                 // Field ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance.IMPORTANT:Lru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance;
      33: goto          68
      36: new           #138                // class java/lang/IllegalArgumentException
      39: dup
      40: new           #140                // class java/lang/StringBuilder
      43: dup
      44: invokespecial #141                // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #143                // String got illegal importanceValue =
      49: invokevirtual #147                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_0
      53: invokevirtual #150                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: ldc           #152                // String ; 0 or 1 expected
      58: invokevirtual #147                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      61: invokevirtual #156                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      64: invokespecial #159                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      67: athrow
      68: areturn

  public static final void main();
    Code:
       0: new           #163                // class java/util/Scanner
       3: dup
       4: getstatic     #169                // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #172                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #175                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      15: dup
      16: ldc           #177                // String nextLine(...)
      18: invokestatic  #180                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: checkcast     #182                // class java/lang/CharSequence
      24: iconst_1
      25: anewarray     #184                // class java/lang/String
      28: astore_2
      29: aload_2
      30: iconst_0
      31: ldc           #186                // String
      33: aastore
      34: aload_2
      35: iconst_0
      36: iconst_0
      37: bipush        6
      39: aconst_null
      40: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      43: checkcast     #18                 // class java/lang/Iterable
      46: astore_2
      47: iconst_0
      48: istore_3
      49: aload_2
      50: astore        4
      52: new           #20                 // class java/util/ArrayList
      55: dup
      56: aload_2
      57: bipush        10
      59: invokestatic  #196                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      62: invokespecial #199                // Method java/util/ArrayList."<init>":(I)V
      65: checkcast     #80                 // class java/util/Collection
      68: astore        5
      70: iconst_0
      71: istore        6
      73: aload         4
      75: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      80: astore        7
      82: aload         7
      84: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      89: ifeq          136
      92: aload         7
      94: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      99: astore        8
     101: aload         5
     103: aload         8
     105: checkcast     #184                // class java/lang/String
     108: astore        9
     110: astore        25
     112: iconst_0
     113: istore        10
     115: aload         9
     117: invokestatic  #205                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     120: nop
     121: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     124: aload         25
     126: swap
     127: invokeinterface #210,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     132: pop
     133: goto          82
     136: aload         5
     138: checkcast     #64                 // class java/util/List
     141: nop
     142: astore_1
     143: aload_1
     144: iconst_0
     145: invokeinterface #214,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     150: checkcast     #216                // class java/lang/Number
     153: invokevirtual #219                // Method java/lang/Number.intValue:()I
     156: istore_2
     157: aload_1
     158: iconst_1
     159: invokeinterface #214,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     164: checkcast     #216                // class java/lang/Number
     167: invokevirtual #219                // Method java/lang/Number.intValue:()I
     170: istore_3
     171: new           #221                // class kotlin/ranges/IntRange
     174: dup
     175: iconst_1
     176: iload_2
     177: invokespecial #224                // Method kotlin/ranges/IntRange."<init>":(II)V
     180: checkcast     #18                 // class java/lang/Iterable
     183: astore        5
     185: iconst_0
     186: istore        6
     188: aload         5
     190: astore        7
     192: new           #20                 // class java/util/ArrayList
     195: dup
     196: aload         5
     198: bipush        10
     200: invokestatic  #196                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     203: invokespecial #199                // Method java/util/ArrayList."<init>":(I)V
     206: checkcast     #80                 // class java/util/Collection
     209: astore        8
     211: iconst_0
     212: istore        9
     214: aload         7
     216: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     221: astore        10
     223: aload         10
     225: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     230: ifeq          462
     233: aload         10
     235: checkcast     #226                // class kotlin/collections/IntIterator
     238: invokevirtual #229                // Method kotlin/collections/IntIterator.nextInt:()I
     241: istore        11
     243: aload         8
     245: iload         11
     247: istore        12
     249: astore        25
     251: iconst_0
     252: istore        13
     254: aload_0
     255: invokevirtual #175                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
     258: dup
     259: ldc           #177                // String nextLine(...)
     261: invokestatic  #180                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     264: checkcast     #182                // class java/lang/CharSequence
     267: iconst_1
     268: anewarray     #184                // class java/lang/String
     271: astore        14
     273: aload         14
     275: iconst_0
     276: ldc           #186                // String
     278: aastore
     279: aload         14
     281: iconst_0
     282: iconst_0
     283: bipush        6
     285: aconst_null
     286: invokestatic  #192                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     289: checkcast     #18                 // class java/lang/Iterable
     292: astore        14
     294: iconst_0
     295: istore        15
     297: aload         14
     299: astore        16
     301: new           #20                 // class java/util/ArrayList
     304: dup
     305: aload         14
     307: bipush        10
     309: invokestatic  #196                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     312: invokespecial #199                // Method java/util/ArrayList."<init>":(I)V
     315: checkcast     #80                 // class java/util/Collection
     318: astore        17
     320: iconst_0
     321: istore        18
     323: aload         16
     325: invokeinterface #28,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     330: astore        19
     332: aload         19
     334: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     339: ifeq          396
     342: aload         19
     344: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     349: astore        20
     351: aload         17
     353: aload         20
     355: checkcast     #184                // class java/lang/String
     358: astore        21
     360: astore        22
     362: iconst_0
     363: istore        23
     365: nop
     366: aload         21
     368: checkcast     #182                // class java/lang/CharSequence
     371: invokestatic  #233                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     374: invokevirtual #234                // Method java/lang/Object.toString:()Ljava/lang/String;
     377: invokestatic  #205                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     380: nop
     381: invokestatic  #209                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     384: aload         22
     386: swap
     387: invokeinterface #210,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     392: pop
     393: goto          332
     396: aload         17
     398: checkcast     #64                 // class java/util/List
     401: nop
     402: astore        24
     404: aload         24
     406: iconst_0
     407: invokeinterface #214,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     412: checkcast     #216                // class java/lang/Number
     415: invokevirtual #219                // Method java/lang/Number.intValue:()I
     418: istore        14
     420: aload         24
     422: iconst_1
     423: invokeinterface #214,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     428: checkcast     #216                // class java/lang/Number
     431: invokevirtual #219                // Method java/lang/Number.intValue:()I
     434: istore        15
     436: new           #40                 // class ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest
     439: dup
     440: iload         14
     442: iload         15
     444: invokestatic  #236                // Method from:(I)Lru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance;
     447: invokespecial #239                // Method ru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Contest."<init>":(ILru/amai/study/hackerrank/practice/interviewPreparationKit/greedy/luck/Importance;)V
     450: aload         25
     452: swap
     453: invokeinterface #210,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     458: pop
     459: goto          223
     462: aload         8
     464: checkcast     #64                 // class java/util/List
     467: nop
     468: astore        4
     470: iload_3
     471: aload         4
     473: invokestatic  #241                // Method luckBalance:(ILjava/util/List;)I
     476: istore        5
     478: getstatic     #245                // Field java/lang/System.out:Ljava/io/PrintStream;
     481: iload         5
     483: invokevirtual #250                // Method java/io/PrintStream.println:(I)V
     486: return

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


package ru.amai.study.hackerrank.practice.interviewPreparationKit.sorting.merge

import java.util.*

fun countInversions(arr: IntArray): Long =
    mergeSortSupport(arr, IntArray(arr.size), 0, arr.size)

fun mergeSortSupport(arr: IntArray, temp: IntArray, left: Int, right: Int): Long =
    if (right - left > 1) {
        var inversionCnt: Long
        val mid = (right + left) / 2

        inversionCnt = mergeSortSupport(arr, temp, left, mid)
        inversionCnt += mergeSortSupport(arr, temp, mid, right)

        inversionCnt += merge(arr, temp, left, mid, right)

        inversionCnt
    } else 0L

fun merge(arr: IntArray, temp: IntArray, left: Int, mid: Int, right: Int): Long {
    var inversionCnt = 0L

    var i: Int = left
    var j: Int = mid
    var k: Int = left
    while (i < mid && j < right) {
        if (arr[i] <= arr[j]) {
            temp[k++] = arr[i++]
        } else {
            temp[k++] = arr[j++]
            inversionCnt += (mid - i)
        }
    }

    (i until mid).forEach { temp[k++] = arr[it] }
    (j until right).forEach { temp[k++] = arr[it] }

    (left until right).forEach { arr[it] = temp[it] }

    return inversionCnt
}

fun main() {
    val scan = Scanner(System.`in`)

    val t = scan.nextLine().trim().toInt()
    for (tItr in 1..t) {
        scan.nextLine().trim().toInt()
        val arr = scan.nextLine().split(" ").map { it.trim().toInt() }.toIntArray()

        val result = countInversions(arr)
        println(result)
    }
}

Compiled from "CountInversions.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.sorting.merge.CountInversionsKt {
  public static final long countInversions(int[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_0
       8: arraylength
       9: newarray       int
      11: iconst_0
      12: aload_0
      13: arraylength
      14: invokestatic  #19                 // Method mergeSortSupport:([I[III)J
      17: lreturn

  public static final long mergeSortSupport(int[], int[], int, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #22                 // String temp
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_3
      13: iload_2
      14: isub
      15: iconst_1
      16: if_icmple     71
      19: lconst_0
      20: lstore        4
      22: iload_3
      23: iload_2
      24: iadd
      25: iconst_2
      26: idiv
      27: istore        6
      29: aload_0
      30: aload_1
      31: iload_2
      32: iload         6
      34: invokestatic  #19                 // Method mergeSortSupport:([I[III)J
      37: lstore        4
      39: lload         4
      41: aload_0
      42: aload_1
      43: iload         6
      45: iload_3
      46: invokestatic  #19                 // Method mergeSortSupport:([I[III)J
      49: ladd
      50: lstore        4
      52: lload         4
      54: aload_0
      55: aload_1
      56: iload_2
      57: iload         6
      59: iload_3
      60: invokestatic  #26                 // Method merge:([I[IIII)J
      63: ladd
      64: lstore        4
      66: lload         4
      68: goto          72
      71: lconst_0
      72: lreturn

  public static final long merge(int[], int[], int, int, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String arr
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #22                 // String temp
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: lconst_0
      13: lstore        5
      15: iload_2
      16: istore        7
      18: iload_3
      19: istore        8
      21: iconst_0
      22: istore        9
      24: iload_2
      25: istore        9
      27: iload         7
      29: iload_3
      30: if_icmpge     109
      33: iload         8
      35: iload         4
      37: if_icmpge     109
      40: aload_0
      41: iload         7
      43: iaload
      44: aload_0
      45: iload         8
      47: iaload
      48: if_icmpgt     75
      51: aload_1
      52: iload         9
      54: istore        10
      56: iload         10
      58: iconst_1
      59: iadd
      60: istore        9
      62: iload         10
      64: aload_0
      65: iload         7
      67: iinc          7, 1
      70: iaload
      71: iastore
      72: goto          27
      75: aload_1
      76: iload         9
      78: istore        10
      80: iload         10
      82: iconst_1
      83: iadd
      84: istore        9
      86: iload         10
      88: aload_0
      89: iload         8
      91: iinc          8, 1
      94: iaload
      95: iastore
      96: lload         5
      98: iload_3
      99: iload         7
     101: isub
     102: i2l
     103: ladd
     104: lstore        5
     106: goto          27
     109: iload         7
     111: iload_3
     112: invokestatic  #38                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     115: checkcast     #40                 // class java/lang/Iterable
     118: astore        10
     120: iconst_0
     121: istore        11
     123: aload         10
     125: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     130: astore        12
     132: aload         12
     134: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     139: ifeq          181
     142: aload         12
     144: checkcast     #52                 // class kotlin/collections/IntIterator
     147: invokevirtual #56                 // Method kotlin/collections/IntIterator.nextInt:()I
     150: istore        13
     152: iload         13
     154: istore        14
     156: iconst_0
     157: istore        15
     159: aload_1
     160: iload         9
     162: istore        16
     164: iload         16
     166: iconst_1
     167: iadd
     168: istore        9
     170: iload         16
     172: aload_0
     173: iload         14
     175: iaload
     176: iastore
     177: nop
     178: goto          132
     181: nop
     182: iload         8
     184: iload         4
     186: invokestatic  #38                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     189: checkcast     #40                 // class java/lang/Iterable
     192: astore        10
     194: iconst_0
     195: istore        11
     197: aload         10
     199: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     204: astore        12
     206: aload         12
     208: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     213: ifeq          255
     216: aload         12
     218: checkcast     #52                 // class kotlin/collections/IntIterator
     221: invokevirtual #56                 // Method kotlin/collections/IntIterator.nextInt:()I
     224: istore        13
     226: iload         13
     228: istore        14
     230: iconst_0
     231: istore        15
     233: aload_1
     234: iload         9
     236: istore        16
     238: iload         16
     240: iconst_1
     241: iadd
     242: istore        9
     244: iload         16
     246: aload_0
     247: iload         14
     249: iaload
     250: iastore
     251: nop
     252: goto          206
     255: nop
     256: iload_2
     257: iload         4
     259: invokestatic  #38                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     262: checkcast     #40                 // class java/lang/Iterable
     265: astore        10
     267: iconst_0
     268: istore        11
     270: aload         10
     272: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     277: astore        12
     279: aload         12
     281: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     286: ifeq          318
     289: aload         12
     291: checkcast     #52                 // class kotlin/collections/IntIterator
     294: invokevirtual #56                 // Method kotlin/collections/IntIterator.nextInt:()I
     297: istore        13
     299: iload         13
     301: istore        14
     303: iconst_0
     304: istore        15
     306: aload_0
     307: iload         14
     309: aload_1
     310: iload         14
     312: iaload
     313: iastore
     314: nop
     315: goto          279
     318: nop
     319: lload         5
     321: lreturn

  public static final void main();
    Code:
       0: new           #72                 // class java/util/Scanner
       3: dup
       4: getstatic     #78                 // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #82                 // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #86                 // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      15: dup
      16: ldc           #88                 // String nextLine(...)
      18: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: checkcast     #93                 // class java/lang/CharSequence
      24: invokestatic  #99                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      27: invokevirtual #102                // Method java/lang/Object.toString:()Ljava/lang/String;
      30: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      33: istore_1
      34: iconst_1
      35: istore_2
      36: iload_2
      37: iload_1
      38: if_icmpgt     244
      41: aload_0
      42: invokevirtual #86                 // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      45: dup
      46: ldc           #88                 // String nextLine(...)
      48: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      51: checkcast     #93                 // class java/lang/CharSequence
      54: invokestatic  #99                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      57: invokevirtual #102                // Method java/lang/Object.toString:()Ljava/lang/String;
      60: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      63: pop
      64: aload_0
      65: invokevirtual #86                 // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      68: dup
      69: ldc           #88                 // String nextLine(...)
      71: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      74: checkcast     #93                 // class java/lang/CharSequence
      77: iconst_1
      78: anewarray     #110                // class java/lang/String
      81: astore        4
      83: aload         4
      85: iconst_0
      86: ldc           #112                // String
      88: aastore
      89: aload         4
      91: iconst_0
      92: iconst_0
      93: bipush        6
      95: aconst_null
      96: invokestatic  #116                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      99: checkcast     #40                 // class java/lang/Iterable
     102: astore        4
     104: iconst_0
     105: istore        5
     107: aload         4
     109: astore        6
     111: new           #118                // class java/util/ArrayList
     114: dup
     115: aload         4
     117: bipush        10
     119: invokestatic  #124                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     122: invokespecial #127                // Method java/util/ArrayList."<init>":(I)V
     125: checkcast     #129                // class java/util/Collection
     128: astore        7
     130: iconst_0
     131: istore        8
     133: aload         6
     135: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     140: astore        9
     142: aload         9
     144: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     149: ifeq          206
     152: aload         9
     154: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     159: astore        10
     161: aload         7
     163: aload         10
     165: checkcast     #110                // class java/lang/String
     168: astore        11
     170: astore        13
     172: iconst_0
     173: istore        12
     175: nop
     176: aload         11
     178: checkcast     #93                 // class java/lang/CharSequence
     181: invokestatic  #99                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     184: invokevirtual #102                // Method java/lang/Object.toString:()Ljava/lang/String;
     187: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     190: nop
     191: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     194: aload         13
     196: swap
     197: invokeinterface #141,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     202: pop
     203: goto          142
     206: aload         7
     208: checkcast     #143                // class java/util/List
     211: nop
     212: checkcast     #129                // class java/util/Collection
     215: invokestatic  #147                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     218: astore_3
     219: aload_3
     220: invokestatic  #149                // Method countInversions:([I)J
     223: lstore        4
     225: getstatic     #153                // Field java/lang/System.out:Ljava/io/PrintStream;
     228: lload         4
     230: invokevirtual #159                // Method java/io/PrintStream.println:(J)V
     233: iload_2
     234: iload_1
     235: if_icmpeq     244
     238: iinc          2, 1
     241: goto          41
     244: return

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


package ru.amai.study.hackerrank.practice.interviewPreparationKit.sorting.fraud

import java.util.*

private const val MAX_EXPENDITURE = 201

fun activityNotifications(expenditure: IntArray, d: Int): Int {
    val counts = buildCounts(expenditure, d)

    return (d until expenditure.size).count { i ->
        val median = median(counts, d)

        counts[expenditure[i]] += 1
        counts[expenditure[i - d]] -= 1

        (expenditure[i] >= 2 * median)
    }
}

private fun buildCounts(array: IntArray, size: Int): IntArray {
    val counts = IntArray(MAX_EXPENDITURE)
    array.take(size).forEach {
        counts[it] += 1
    }
    return counts
}

private fun median(counts: IntArray, size: Int): Double {
    fun medianSupport(index: Int): Double {
        var currIndex = 0
        var value = 0.0
        for ((i, count) in counts.withIndex()) {
            if (index in (currIndex until (currIndex + count))) {
                value = i.toDouble()
                break
            }
            currIndex += count
        }
        return value
    }

    return when (size % 2) {
        1 -> medianSupport(size / 2)
        else -> (medianSupport(size / 2 - 1) + medianSupport(size / 2)) / 2
    }
}

fun main() {
    val scan = Scanner(System.`in`)

    val nd = scan.nextLine().split(" ")
    val d = nd[1].trim().toInt()
    val expenditure = scan.nextLine().split(" ").map { it.trim().toInt() }.toIntArray()

    val result = activityNotifications(expenditure, d)
    println(result)
}

Compiled from "ActivityNotifications.kt"
public final class ru.amai.study.hackerrank.practice.interviewPreparationKit.sorting.fraud.ActivityNotificationsKt {
  private static final int MAX_EXPENDITURE;

  public static final int activityNotifications(int[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String expenditure
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: invokestatic  #19                 // Method buildCounts:([II)[I
      11: astore_2
      12: iload_1
      13: aload_0
      14: arraylength
      15: invokestatic  #25                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      18: checkcast     #27                 // class java/lang/Iterable
      21: astore_3
      22: iconst_0
      23: istore        4
      25: aload_3
      26: instanceof    #29                 // class java/util/Collection
      29: ifeq          48
      32: aload_3
      33: checkcast     #29                 // class java/util/Collection
      36: invokeinterface #33,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      41: ifeq          48
      44: iconst_0
      45: goto          165
      48: iconst_0
      49: istore        5
      51: aload_3
      52: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        6
      59: aload         6
      61: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          163
      69: aload         6
      71: checkcast     #44                 // class kotlin/collections/IntIterator
      74: invokevirtual #48                 // Method kotlin/collections/IntIterator.nextInt:()I
      77: istore        7
      79: iload         7
      81: istore        8
      83: iconst_0
      84: istore        9
      86: aload_2
      87: iload_1
      88: invokestatic  #52                 // Method median:([II)D
      91: dstore        10
      93: aload_0
      94: iload         8
      96: iaload
      97: istore        12
      99: aload_2
     100: iload         12
     102: aload_2
     103: iload         12
     105: iaload
     106: iconst_1
     107: iadd
     108: iastore
     109: aload_0
     110: iload         8
     112: iload_1
     113: isub
     114: iaload
     115: istore        12
     117: aload_2
     118: iload         12
     120: aload_2
     121: iload         12
     123: iaload
     124: iconst_1
     125: isub
     126: iastore
     127: aload_0
     128: iload         8
     130: iaload
     131: i2d
     132: iconst_2
     133: i2d
     134: dload         10
     136: dmul
     137: dcmpl
     138: iflt          145
     141: iconst_1
     142: goto          146
     145: iconst_0
     146: ifeq          59
     149: iinc          5, 1
     152: iload         5
     154: ifge          59
     157: invokestatic  #58                 // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     160: goto          59
     163: iload         5
     165: ireturn

  private static final int[] buildCounts(int[], int);
    Code:
       0: sipush        201
       3: newarray       int
       5: astore_2
       6: aload_0
       7: iload_1
       8: invokestatic  #77                 // Method kotlin/collections/ArraysKt.take:([II)Ljava/util/List;
      11: checkcast     #27                 // class java/lang/Iterable
      14: astore_3
      15: iconst_0
      16: istore        4
      18: aload_3
      19: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      24: astore        5
      26: aload         5
      28: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          73
      36: aload         5
      38: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: astore        6
      45: aload         6
      47: checkcast     #83                 // class java/lang/Number
      50: invokevirtual #86                 // Method java/lang/Number.intValue:()I
      53: istore        7
      55: iconst_0
      56: istore        8
      58: aload_2
      59: iload         7
      61: aload_2
      62: iload         7
      64: iaload
      65: iconst_1
      66: iadd
      67: iastore
      68: nop
      69: nop
      70: goto          26
      73: nop
      74: aload_2
      75: areturn

  private static final double median(int[], int);
    Code:
       0: iload_1
       1: iconst_2
       2: irem
       3: iconst_1
       4: if_icmpne     17
       7: aload_0
       8: iload_1
       9: iconst_2
      10: idiv
      11: invokestatic  #96                 // Method median$medianSupport:([II)D
      14: goto          37
      17: aload_0
      18: iload_1
      19: iconst_2
      20: idiv
      21: iconst_1
      22: isub
      23: invokestatic  #96                 // Method median$medianSupport:([II)D
      26: aload_0
      27: iload_1
      28: iconst_2
      29: idiv
      30: invokestatic  #96                 // Method median$medianSupport:([II)D
      33: dadd
      34: iconst_2
      35: i2d
      36: ddiv
      37: dreturn

  public static final void main();
    Code:
       0: new           #99                 // class java/util/Scanner
       3: dup
       4: getstatic     #105                // Field java/lang/System.in:Ljava/io/InputStream;
       7: invokespecial #109                // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      10: astore_0
      11: aload_0
      12: invokevirtual #113                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      15: dup
      16: ldc           #115                // String nextLine(...)
      18: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      21: checkcast     #120                // class java/lang/CharSequence
      24: iconst_1
      25: anewarray     #122                // class java/lang/String
      28: astore_2
      29: aload_2
      30: iconst_0
      31: ldc           #124                // String
      33: aastore
      34: aload_2
      35: iconst_0
      36: iconst_0
      37: bipush        6
      39: aconst_null
      40: invokestatic  #130                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      43: astore_1
      44: nop
      45: aload_1
      46: iconst_1
      47: invokeinterface #136,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      52: checkcast     #122                // class java/lang/String
      55: checkcast     #120                // class java/lang/CharSequence
      58: invokestatic  #140                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      61: invokevirtual #143                // Method java/lang/Object.toString:()Ljava/lang/String;
      64: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      67: istore_2
      68: aload_0
      69: invokevirtual #113                // Method java/util/Scanner.nextLine:()Ljava/lang/String;
      72: dup
      73: ldc           #115                // String nextLine(...)
      75: invokestatic  #118                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      78: checkcast     #120                // class java/lang/CharSequence
      81: iconst_1
      82: anewarray     #122                // class java/lang/String
      85: astore        4
      87: aload         4
      89: iconst_0
      90: ldc           #124                // String
      92: aastore
      93: aload         4
      95: iconst_0
      96: iconst_0
      97: bipush        6
      99: aconst_null
     100: invokestatic  #130                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     103: checkcast     #27                 // class java/lang/Iterable
     106: astore        4
     108: iconst_0
     109: istore        5
     111: aload         4
     113: astore        6
     115: new           #151                // class java/util/ArrayList
     118: dup
     119: aload         4
     121: bipush        10
     123: invokestatic  #155                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     126: invokespecial #158                // Method java/util/ArrayList."<init>":(I)V
     129: checkcast     #29                 // class java/util/Collection
     132: astore        7
     134: iconst_0
     135: istore        8
     137: aload         6
     139: invokeinterface #37,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     144: astore        9
     146: aload         9
     148: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     153: ifeq          210
     156: aload         9
     158: invokeinterface #81,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     163: astore        10
     165: aload         7
     167: aload         10
     169: checkcast     #122                // class java/lang/String
     172: astore        11
     174: astore        13
     176: iconst_0
     177: istore        12
     179: nop
     180: aload         11
     182: checkcast     #120                // class java/lang/CharSequence
     185: invokestatic  #140                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     188: invokevirtual #143                // Method java/lang/Object.toString:()Ljava/lang/String;
     191: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     194: nop
     195: invokestatic  #162                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: aload         13
     200: swap
     201: invokeinterface #166,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     206: pop
     207: goto          146
     210: aload         7
     212: checkcast     #132                // class java/util/List
     215: nop
     216: checkcast     #29                 // class java/util/Collection
     219: invokestatic  #170                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     222: astore_3
     223: aload_3
     224: iload_2
     225: invokestatic  #172                // Method activityNotifications:([II)I
     228: istore        4
     230: getstatic     #176                // Field java/lang/System.out:Ljava/io/PrintStream;
     233: iload         4
     235: invokevirtual #181                // Method java/io/PrintStream.println:(I)V
     238: return

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

  private static final double median$medianSupport(int[], int);
    Code:
       0: iconst_0
       1: istore_2
       2: dconst_0
       3: dstore_3
       4: iconst_0
       5: istore        5
       7: aload_0
       8: arraylength
       9: istore        6
      11: iload         5
      13: iload         6
      15: if_icmpge     71
      18: iload         5
      20: istore        7
      22: aload_0
      23: iload         5
      25: iaload
      26: istore        8
      28: iload_2
      29: iload_1
      30: if_icmpgt     49
      33: iload_1
      34: iload_2
      35: iload         8
      37: iadd
      38: if_icmpge     45
      41: iconst_1
      42: goto          50
      45: iconst_0
      46: goto          50
      49: iconst_0
      50: ifeq          60
      53: iload         7
      55: i2d
      56: dstore_3
      57: goto          71
      60: iload_2
      61: iload         8
      63: iadd
      64: istore_2
      65: iinc          5, 1
      68: goto          11
      71: dload_3
      72: dreturn
}


package kr.co.programmers

// https://github.com/antop-dev/algorithm/issues/409
class P86052 {

    companion object {
        const val UP = 0
        const val RIGHT = 1
        const val DOWN = 2
        const val LEFT = 3
    }

    fun solution(grid: Array<String>): IntArray {
        // 각 격자에서 네방향으로 이동한 기록
        val memo = Array(grid.size) {
            Array(grid[0].length) {
                intArrayOf(0, 0, 0, 0)
            }
        }

        val steps = mutableListOf<Int>()

        for (i in memo.indices) {
            for (j in memo[i].indices) {
                for (k in 0 until 4) { // 4방향으로 빛을 쏜다.
                    var y = i
                    var x = j
                    var d = k
                    var step = 0

                    while (memo[y][x][d] == 0) {
                        memo[y][x][d] = 1
                        step++
                        // 다음 격자로 이동 했다.
                        y += when (d) {
                            UP -> -1
                            DOWN -> 1
                            else -> 0
                        }
                        if (y < 0) y = memo.lastIndex
                        if (y > memo.lastIndex) y = 0

                        x += when (d) {
                            RIGHT -> 1
                            LEFT -> -1
                            else -> 0
                        }
                        if (x < 0) x = memo[0].lastIndex
                        if (x > memo[0].lastIndex) x = 0
                        // 이동한 격자에서 이동할 방향을 구한다.
                        when (grid[y][x]) {
                            'L' -> {
                                d--
                                if (d < 0) d = LEFT
                            }
                            'R' -> {
                                d++
                                if (d > 3) d = UP
                            }
                        }
                    }

                    if (step > 0) steps += step
                }
            }
        }

        return steps.sorted().toIntArray()
    }

}

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

  public kr.co.programmers.P86052$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #12                 // Method "<init>":()V
       4: return
}

Compiled from "P86052.kt"
public final class kr.co.programmers.P86052 {
  public static final kr.co.programmers.P86052$Companion Companion;

  public static final int UP;

  public static final int RIGHT;

  public static final int DOWN;

  public static final int LEFT;

  public kr.co.programmers.P86052();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int[] solution(java.lang.String[]);
    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: iconst_0
       7: istore_3
       8: aload_1
       9: arraylength
      10: istore        4
      12: iload         4
      14: anewarray     #23                 // class "[[I"
      17: astore        5
      19: iload_3
      20: iload         4
      22: if_icmpge     116
      25: iload_3
      26: istore        6
      28: aload         5
      30: iload         6
      32: iconst_0
      33: istore        7
      35: aload_1
      36: iconst_0
      37: aaload
      38: invokevirtual #29                 // Method java/lang/String.length:()I
      41: istore        8
      43: iload         8
      45: anewarray     #31                 // class "[I"
      48: astore        9
      50: istore        15
      52: astore        14
      54: iload         7
      56: iload         8
      58: if_icmpge     103
      61: iload         7
      63: istore        10
      65: aload         9
      67: iload         10
      69: iconst_4
      70: newarray       int
      72: astore        11
      74: aload         11
      76: iconst_0
      77: iconst_0
      78: iastore
      79: aload         11
      81: iconst_1
      82: iconst_0
      83: iastore
      84: aload         11
      86: iconst_2
      87: iconst_0
      88: iastore
      89: aload         11
      91: iconst_3
      92: iconst_0
      93: iastore
      94: aload         11
      96: aastore
      97: iinc          7, 1
     100: goto          54
     103: aload         14
     105: iload         15
     107: aload         9
     109: aastore
     110: iinc          3, 1
     113: goto          19
     116: aload         5
     118: astore_2
     119: new           #33                 // class java/util/ArrayList
     122: dup
     123: invokespecial #34                 // Method java/util/ArrayList."<init>":()V
     126: checkcast     #36                 // class java/util/List
     129: astore_3
     130: iconst_0
     131: istore        4
     133: aload_2
     134: checkcast     #38                 // class "[Ljava/lang/Object;"
     137: arraylength
     138: istore        5
     140: iload         4
     142: iload         5
     144: if_icmpge     471
     147: iconst_0
     148: istore        6
     150: aload_2
     151: iload         4
     153: aaload
     154: checkcast     #38                 // class "[Ljava/lang/Object;"
     157: arraylength
     158: istore        7
     160: iload         6
     162: iload         7
     164: if_icmpge     465
     167: iconst_0
     168: istore        8
     170: iload         8
     172: iconst_4
     173: if_icmpge     459
     176: iload         4
     178: istore        9
     180: iload         6
     182: istore        10
     184: iload         8
     186: istore        11
     188: iconst_0
     189: istore        12
     191: aload_2
     192: iload         9
     194: aaload
     195: iload         10
     197: aaload
     198: iload         11
     200: iaload
     201: ifne          429
     204: aload_2
     205: iload         9
     207: aaload
     208: iload         10
     210: aaload
     211: iload         11
     213: iconst_1
     214: iastore
     215: iinc          12, 1
     218: iload         9
     220: iload         11
     222: tableswitch   { // 0 to 2
                     0: 248
                     1: 256
                     2: 252
               default: 256
          }
     248: iconst_m1
     249: goto          257
     252: iconst_1
     253: goto          257
     256: iconst_0
     257: iadd
     258: istore        9
     260: iload         9
     262: ifge          274
     265: aload_2
     266: checkcast     #38                 // class "[Ljava/lang/Object;"
     269: invokestatic  #44                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     272: istore        9
     274: iload         9
     276: aload_2
     277: checkcast     #38                 // class "[Ljava/lang/Object;"
     280: invokestatic  #44                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     283: if_icmple     289
     286: iconst_0
     287: istore        9
     289: iload         10
     291: iload         11
     293: tableswitch   { // 1 to 3
                     1: 320
                     2: 328
                     3: 324
               default: 328
          }
     320: iconst_1
     321: goto          329
     324: iconst_m1
     325: goto          329
     328: iconst_0
     329: iadd
     330: istore        10
     332: iload         10
     334: ifge          348
     337: aload_2
     338: iconst_0
     339: aaload
     340: checkcast     #38                 // class "[Ljava/lang/Object;"
     343: invokestatic  #44                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     346: istore        10
     348: iload         10
     350: aload_2
     351: iconst_0
     352: aaload
     353: checkcast     #38                 // class "[Ljava/lang/Object;"
     356: invokestatic  #44                 // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     359: if_icmple     365
     362: iconst_0
     363: istore        10
     365: aload_1
     366: iload         9
     368: aaload
     369: iload         10
     371: invokevirtual #48                 // Method java/lang/String.charAt:(I)C
     374: lookupswitch  { // 2
                    76: 400
                    82: 414
               default: 426
          }
     400: iinc          11, -1
     403: iload         11
     405: ifge          191
     408: iconst_3
     409: istore        11
     411: goto          191
     414: iinc          11, 1
     417: iload         11
     419: iconst_3
     420: if_icmple     191
     423: iconst_0
     424: istore        11
     426: goto          191
     429: iload         12
     431: ifle          453
     434: iload         12
     436: invokestatic  #54                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     439: astore        13
     441: aload_3
     442: checkcast     #56                 // class java/util/Collection
     445: aload         13
     447: invokeinterface #60,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     452: pop
     453: iinc          8, 1
     456: goto          170
     459: iinc          6, 1
     462: goto          160
     465: iinc          4, 1
     468: goto          140
     471: aload_3
     472: checkcast     #62                 // class java/lang/Iterable
     475: invokestatic  #68                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     478: checkcast     #56                 // class java/util/Collection
     481: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     484: areturn

  static {};
    Code:
       0: new           #90                 // class kr/co/programmers/P86052$Companion
       3: dup
       4: aconst_null
       5: invokespecial #93                 // Method kr/co/programmers/P86052$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #97                 // Field Companion:Lkr/co/programmers/P86052$Companion;
      11: return
}


package kr.co.programmers

import kotlin.math.abs

// https://github.com/antop-dev/algorithm/issues/535
class P12952 {
    fun solution(n: Int): Int {
        return dfs(IntArray(n), 0)
    }

    private fun dfs(arr: IntArray, row: Int): Int {
        if (row == arr.size) { // n번째 행까지 퀸을 다 놓았다.
            return 1
        }
        var count = 0
        for (col in arr.indices) {
            // row 행, col 열에 퀸을 배치 시켜놓고 검사한다.
            arr[row] = col
            if (valid(arr, row)) {
                count += dfs(arr, row + 1)
            }
        }
        return count
    }

    // 현재 행의 퀸 위치와 이전 행들의 퀸 위치를 비교한다.
    private fun valid(arr: IntArray, currRow: Int): Boolean {
        for (prevRow in 0 until currRow) {
            if (arr[currRow] == arr[prevRow]) { // 같은 열이면 안됨
                return false
            }
            // 대각선 위치면 안됨 (기울기로 계산)
            if (abs(currRow - prevRow) == abs(arr[currRow] - arr[prevRow])) {
                return false
            }
        }
        return true
    }

}

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

  public final int solution(int);
    Code:
       0: aload_0
       1: iload_1
       2: newarray       int
       4: iconst_0
       5: invokespecial #16                 // Method dfs:([II)I
       8: ireturn

  private final int dfs(int[], int);
    Code:
       0: iload_2
       1: aload_1
       2: arraylength
       3: if_icmpne     8
       6: iconst_1
       7: ireturn
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: aload_1
      14: arraylength
      15: istore        5
      17: iload         4
      19: iload         5
      21: if_icmpge     55
      24: aload_1
      25: iload_2
      26: iload         4
      28: iastore
      29: aload_0
      30: aload_1
      31: iload_2
      32: invokespecial #22                 // Method valid:([II)Z
      35: ifeq          49
      38: iload_3
      39: aload_0
      40: aload_1
      41: iload_2
      42: iconst_1
      43: iadd
      44: invokespecial #16                 // Method dfs:([II)I
      47: iadd
      48: istore_3
      49: iinc          4, 1
      52: goto          17
      55: iload_3
      56: ireturn

  private final boolean valid(int[], int);
    Code:
       0: iconst_0
       1: istore_3
       2: iload_3
       3: iload_2
       4: if_icmpge     45
       7: aload_1
       8: iload_2
       9: iaload
      10: aload_1
      11: iload_3
      12: iaload
      13: if_icmpne     18
      16: iconst_0
      17: ireturn
      18: iload_2
      19: iload_3
      20: isub
      21: invokestatic  #32                 // Method java/lang/Math.abs:(I)I
      24: aload_1
      25: iload_2
      26: iaload
      27: aload_1
      28: iload_3
      29: iaload
      30: isub
      31: invokestatic  #32                 // Method java/lang/Math.abs:(I)I
      34: if_icmpne     39
      37: iconst_0
      38: ireturn
      39: iinc          3, 1
      42: goto          2
      45: iconst_1
      46: ireturn
}


package kr.co.programmers

// https://github.com/antop-dev/algorithm/issues/455
class P67258 {
    fun solution(gems: Array<String>): IntArray {
        // ["AA", "AB", "AC", "AA", "AC"]
        // [  0,    1,    2,    0,    2 ]
        val map = mutableMapOf<String, Int>()
        val list = mutableListOf<Int>()
        var i = 0
        for (gem in gems) {
            val idx = map[gem] ?: i++
            map[gem] = idx
            list += idx
        }
        val counter = IntArray(i)
        counter[list[0]]++

        // 계산하기
        var count = 1
        var from = 0
        var to = 0
        // [가장 짧은 구간 길이, 시작 진열대 번호, 끝 진열대 번호]
        val min = intArrayOf(gems.size, 1, gems.size)

        while (from < gems.size) {
            if (count < counter.size) { // 모든 물건을 사지 않았다
                if (to < list.lastIndex) { // to + 1
                    to++
                    counter[list[to]]++
                    if (counter[list[to]] == 1) {
                        count++
                    }
                } else { // from + 1
                    counter[list[from]]--
                    if (counter[list[from]] == 0) {
                        count--
                    }
                    from++
                }
            } else { // 모든 물건을 샀다
                if (to - from + 1 < min[0]) {
                    min[0] = to - from + 1
                    min[1] = from + 1
                    min[2] = to + 1
                }
                // 완성된 크기가 고유한 물건의 크기와 일치하면 바로 종료
                if (min[0] == counter.size) break

                counter[list[from]]--
                if (counter[list[from]] == 0) {
                    count--
                }
                from++
            }
        }

        return intArrayOf(min[1], min[2])
    }
}

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

  public final int[] solution(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String gems
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #24                 // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #26                 // class java/util/Map
      16: astore_2
      17: new           #28                 // class java/util/ArrayList
      20: dup
      21: invokespecial #29                 // Method java/util/ArrayList."<init>":()V
      24: checkcast     #31                 // class java/util/List
      27: astore_3
      28: iconst_0
      29: istore        4
      31: iconst_0
      32: istore        5
      34: aload_1
      35: arraylength
      36: istore        6
      38: iload         5
      40: iload         6
      42: if_icmpge     123
      45: aload_1
      46: iload         5
      48: aaload
      49: astore        7
      51: aload_2
      52: aload         7
      54: invokeinterface #35,  2           // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      59: checkcast     #37                 // class java/lang/Integer
      62: dup
      63: ifnull        72
      66: invokevirtual #41                 // Method java/lang/Integer.intValue:()I
      69: goto          78
      72: pop
      73: iload         4
      75: iinc          4, 1
      78: istore        8
      80: iload         8
      82: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      85: astore        10
      87: aload_2
      88: aload         7
      90: aload         10
      92: invokeinterface #49,  3           // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      97: pop
      98: iload         8
     100: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     103: astore        10
     105: aload_3
     106: checkcast     #51                 // class java/util/Collection
     109: aload         10
     111: invokeinterface #55,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: iinc          5, 1
     120: goto          38
     123: iload         4
     125: newarray       int
     127: astore        5
     129: aload_3
     130: iconst_0
     131: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     136: checkcast     #60                 // class java/lang/Number
     139: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     142: istore        6
     144: aload         5
     146: iload         6
     148: iaload
     149: istore        7
     151: aload         5
     153: iload         6
     155: iload         7
     157: iconst_1
     158: iadd
     159: iastore
     160: iconst_1
     161: istore        8
     163: iconst_0
     164: istore        9
     166: iconst_0
     167: istore        10
     169: iconst_3
     170: newarray       int
     172: astore        12
     174: aload         12
     176: iconst_0
     177: aload_1
     178: arraylength
     179: iastore
     180: aload         12
     182: iconst_1
     183: iconst_1
     184: iastore
     185: aload         12
     187: iconst_2
     188: aload_1
     189: arraylength
     190: iastore
     191: aload         12
     193: astore        11
     195: iload         9
     197: aload_1
     198: arraylength
     199: if_icmpge     460
     202: iload         8
     204: aload         5
     206: arraylength
     207: if_icmpge     345
     210: iload         10
     212: aload_3
     213: invokestatic  #67                 // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     216: if_icmpge     281
     219: iinc          10, 1
     222: aload_3
     223: iload         10
     225: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     230: checkcast     #60                 // class java/lang/Number
     233: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     236: istore        12
     238: aload         5
     240: iload         12
     242: iaload
     243: istore        13
     245: aload         5
     247: iload         12
     249: iload         13
     251: iconst_1
     252: iadd
     253: iastore
     254: aload         5
     256: aload_3
     257: iload         10
     259: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     264: checkcast     #60                 // class java/lang/Number
     267: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     270: iaload
     271: iconst_1
     272: if_icmpne     195
     275: iinc          8, 1
     278: goto          195
     281: aload_3
     282: iload         9
     284: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     289: checkcast     #60                 // class java/lang/Number
     292: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     295: istore        12
     297: aload         5
     299: iload         12
     301: iaload
     302: istore        13
     304: aload         5
     306: iload         12
     308: iload         13
     310: iconst_m1
     311: iadd
     312: iastore
     313: aload         5
     315: aload_3
     316: iload         9
     318: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     323: checkcast     #60                 // class java/lang/Number
     326: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     329: iaload
     330: ifne          336
     333: iinc          8, -1
     336: iload         9
     338: iinc          9, 1
     341: pop
     342: goto          195
     345: iload         10
     347: iload         9
     349: isub
     350: iconst_1
     351: iadd
     352: aload         11
     354: iconst_0
     355: iaload
     356: if_icmpge     386
     359: aload         11
     361: iconst_0
     362: iload         10
     364: iload         9
     366: isub
     367: iconst_1
     368: iadd
     369: iastore
     370: aload         11
     372: iconst_1
     373: iload         9
     375: iconst_1
     376: iadd
     377: iastore
     378: aload         11
     380: iconst_2
     381: iload         10
     383: iconst_1
     384: iadd
     385: iastore
     386: aload         11
     388: iconst_0
     389: iaload
     390: aload         5
     392: arraylength
     393: if_icmpeq     460
     396: aload_3
     397: iload         9
     399: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     404: checkcast     #60                 // class java/lang/Number
     407: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     410: istore        12
     412: aload         5
     414: iload         12
     416: iaload
     417: istore        13
     419: aload         5
     421: iload         12
     423: iload         13
     425: iconst_m1
     426: iadd
     427: iastore
     428: aload         5
     430: aload_3
     431: iload         9
     433: invokeinterface #58,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     438: checkcast     #60                 // class java/lang/Number
     441: invokevirtual #61                 // Method java/lang/Number.intValue:()I
     444: iaload
     445: ifne          451
     448: iinc          8, -1
     451: iload         9
     453: iinc          9, 1
     456: pop
     457: goto          195
     460: iconst_2
     461: newarray       int
     463: astore        12
     465: aload         12
     467: iconst_0
     468: aload         11
     470: iconst_1
     471: iaload
     472: iastore
     473: aload         12
     475: iconst_1
     476: aload         11
     478: iconst_2
     479: iaload
     480: iastore
     481: aload         12
     483: areturn
}


package kr.co.programmers

// https://github.com/antop-dev/algorithm/issues/240
class P68936 {

    fun solution(arr: Array<IntArray>): IntArray {
        return recursive(arr, 0, 0, arr.size)
    }

    private fun recursive(arr: Array<IntArray>, y: Int, x: Int, size: Int): IntArray {
        val count = intArrayOf(0, 0);
        val n = y + size
        val m = x + size
        // 시작위치 ~ 크기만큼 0과 1의 개수를 카운트
        var zero = 0
        var one = 0
        for (i in y until n) {
            for (j in x until m) {
                if (arr[i][j] == 0) zero++ else one++
            }
        }
        when {
            // 모두 0인 경우
            zero == size * size -> count[0]++
            // 모두 1인 경우
            one == size * size -> count[1]++
            // 최소 크기인 경우
            size == 2 -> {
                count[0] += zero
                count[1] += one
            }
            // 범위를 반으로 줄여서 다시 카운팅
            else -> {
                val half = size / 2
                for (i in y until n step half) {
                    for (j in x until m step half) {
                        val (z, o) = recursive(arr, i, j, half)
                        count[0] += z
                        count[1] += o
                    }
                }
            }
        }
        // 카운팅을 위로 올린다.
        return count
    }

}

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

  public final int[] solution(int[][]);
    Code:
       0: aload_1
       1: ldc           #15                 // String arr
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: iconst_0
      10: aload_1
      11: checkcast     #23                 // class "[Ljava/lang/Object;"
      14: arraylength
      15: invokespecial #27                 // Method recursive:([[IIII)[I
      18: areturn

  private final int[] recursive(int[][], int, int, int);
    Code:
       0: iconst_2
       1: newarray       int
       3: astore        6
       5: aload         6
       7: iconst_0
       8: iconst_0
       9: iastore
      10: aload         6
      12: iconst_1
      13: iconst_0
      14: iastore
      15: aload         6
      17: astore        5
      19: iload_2
      20: iload         4
      22: iadd
      23: istore        6
      25: iload_3
      26: iload         4
      28: iadd
      29: istore        7
      31: iconst_0
      32: istore        8
      34: iconst_0
      35: istore        9
      37: iload_2
      38: istore        10
      40: iload         10
      42: iload         6
      44: if_icmpge     88
      47: iload_3
      48: istore        11
      50: iload         11
      52: iload         7
      54: if_icmpge     82
      57: aload_1
      58: iload         10
      60: aaload
      61: iload         11
      63: iaload
      64: ifne          73
      67: iinc          8, 1
      70: goto          76
      73: iinc          9, 1
      76: iinc          11, 1
      79: goto          50
      82: iinc          10, 1
      85: goto          40
      88: nop
      89: iload         8
      91: iload         4
      93: iload         4
      95: imul
      96: if_icmpne     119
      99: aload         5
     101: iconst_0
     102: iaload
     103: istore        10
     105: aload         5
     107: iconst_0
     108: iload         10
     110: iconst_1
     111: iadd
     112: iastore
     113: iload         10
     115: pop
     116: goto          389
     119: iload         9
     121: iload         4
     123: iload         4
     125: imul
     126: if_icmpne     149
     129: aload         5
     131: iconst_1
     132: iaload
     133: istore        10
     135: aload         5
     137: iconst_1
     138: iload         10
     140: iconst_1
     141: iadd
     142: iastore
     143: iload         10
     145: pop
     146: goto          389
     149: iload         4
     151: iconst_2
     152: if_icmpne     180
     155: aload         5
     157: iconst_0
     158: aload         5
     160: iconst_0
     161: iaload
     162: iload         8
     164: iadd
     165: iastore
     166: aload         5
     168: iconst_1
     169: aload         5
     171: iconst_1
     172: iaload
     173: iload         9
     175: iadd
     176: iastore
     177: goto          389
     180: iload         4
     182: iconst_2
     183: idiv
     184: istore        10
     186: iload_2
     187: iload         6
     189: invokestatic  #34                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     192: checkcast     #36                 // class kotlin/ranges/IntProgression
     195: iload         10
     197: invokestatic  #40                 // Method kotlin/ranges/RangesKt.step:(Lkotlin/ranges/IntProgression;I)Lkotlin/ranges/IntProgression;
     200: astore        11
     202: aload         11
     204: invokevirtual #44                 // Method kotlin/ranges/IntProgression.getFirst:()I
     207: istore        12
     209: aload         11
     211: invokevirtual #47                 // Method kotlin/ranges/IntProgression.getLast:()I
     214: istore        13
     216: aload         11
     218: invokevirtual #50                 // Method kotlin/ranges/IntProgression.getStep:()I
     221: istore        14
     223: iload         14
     225: ifle          235
     228: iload         12
     230: iload         13
     232: if_icmple     247
     235: iload         14
     237: ifge          389
     240: iload         13
     242: iload         12
     244: if_icmpgt     389
     247: iload_3
     248: iload         7
     250: invokestatic  #34                 // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     253: checkcast     #36                 // class kotlin/ranges/IntProgression
     256: iload         10
     258: invokestatic  #40                 // Method kotlin/ranges/RangesKt.step:(Lkotlin/ranges/IntProgression;I)Lkotlin/ranges/IntProgression;
     261: astore        15
     263: aload         15
     265: invokevirtual #44                 // Method kotlin/ranges/IntProgression.getFirst:()I
     268: istore        16
     270: aload         15
     272: invokevirtual #47                 // Method kotlin/ranges/IntProgression.getLast:()I
     275: istore        17
     277: aload         15
     279: invokevirtual #50                 // Method kotlin/ranges/IntProgression.getStep:()I
     282: istore        18
     284: iload         18
     286: ifle          296
     289: iload         16
     291: iload         17
     293: if_icmple     308
     296: iload         18
     298: ifge          372
     301: iload         17
     303: iload         16
     305: if_icmpgt     372
     308: aload_0
     309: aload_1
     310: iload         12
     312: iload         16
     314: iload         10
     316: invokespecial #27                 // Method recursive:([[IIII)[I
     319: astore        19
     321: aload         19
     323: iconst_0
     324: iaload
     325: istore        20
     327: aload         19
     329: iconst_1
     330: iaload
     331: istore        21
     333: aload         5
     335: iconst_0
     336: aload         5
     338: iconst_0
     339: iaload
     340: iload         20
     342: iadd
     343: iastore
     344: aload         5
     346: iconst_1
     347: aload         5
     349: iconst_1
     350: iaload
     351: iload         21
     353: iadd
     354: iastore
     355: iload         16
     357: iload         17
     359: if_icmpeq     372
     362: iload         16
     364: iload         18
     366: iadd
     367: istore        16
     369: goto          308
     372: iload         12
     374: iload         13
     376: if_icmpeq     389
     379: iload         12
     381: iload         14
     383: iadd
     384: istore        12
     386: goto          247
     389: aload         5
     391: areturn
}


package kr.co.programmers

// https://github.com/antop-dev/algorithm/issues/488
class P150368 {
    fun solution(users: Array<IntArray>, emoticons: IntArray): IntArray {
        val answer = intArrayOf(0, 0)
        // 모든 조합으로 구매를 계산한다.
        val combinations = combinations(emoticons.size)
        for (comb in combinations) {
            var subscribe = 0 // 총 이모티콘 플러스 서비스 가입자수
            var total = 0 // 총 판매 금액
            for (user in users) {
                var amount = 0 // 유저의 총 구매 금액
                for (i in emoticons.indices) {
                    // 할인율이 사용자의 기준 이상이면 구매
                    if (comb[i] >= user[0]) {
                        amount += emoticons[i] * (100 - comb[i]) / 100
                    }
                    // 사용자의 총 구매 금액이 기준 금액을 넘으면 서비스 가입으로 전환
                    if (amount >= user[1]) {
                        subscribe++
                        amount = 0
                        break
                    }
                }
                total += amount // 총 만패 금액에 합산
            }
            // 교체 기준
            if (subscribe > answer[0]) {
                answer[0] = subscribe
                answer[1] = total
            } else if (subscribe == answer[0] && total > answer[1]) {
                answer[1] = total
            }
        }

        return answer
    }

    private fun combinations(n: Int): List<List<Int>> {
        val combinations = mutableListOf<List<Int>>()
        backtrack(combinations, mutableListOf(), n)
        return combinations
    }

    private fun backtrack(combinations: MutableList<List<Int>>, current: MutableList<Int>, N: Int) {
        if (current.size == N) {
            combinations.add(current.toList())
            return
        }

        val numbers = listOf(10, 20, 30, 40)
        for (number in numbers) {
            current.add(number)
            backtrack(combinations, current, N)
            current.removeAt(current.size - 1)
        }
    }
}

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

  public final int[] solution(int[][], int[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String users
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String emoticons
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_2
      13: newarray       int
      15: astore        4
      17: aload         4
      19: iconst_0
      20: iconst_0
      21: iastore
      22: aload         4
      24: iconst_1
      25: iconst_0
      26: iastore
      27: aload         4
      29: astore_3
      30: aload_0
      31: aload_2
      32: arraylength
      33: invokespecial #27                 // Method combinations:(I)Ljava/util/List;
      36: astore        4
      38: aload         4
      40: invokeinterface #33,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      45: astore        5
      47: aload         5
      49: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          250
      57: aload         5
      59: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: checkcast     #29                 // class java/util/List
      67: astore        6
      69: iconst_0
      70: istore        7
      72: iconst_0
      73: istore        8
      75: iconst_0
      76: istore        9
      78: aload_1
      79: checkcast     #45                 // class "[Ljava/lang/Object;"
      82: arraylength
      83: istore        10
      85: iload         9
      87: iload         10
      89: if_icmpge     205
      92: aload_1
      93: iload         9
      95: aaload
      96: astore        11
      98: iconst_0
      99: istore        12
     101: iconst_0
     102: istore        13
     104: aload_2
     105: arraylength
     106: istore        14
     108: iload         13
     110: iload         14
     112: if_icmpge     192
     115: aload         6
     117: iload         13
     119: invokeinterface #49,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     124: checkcast     #51                 // class java/lang/Number
     127: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     130: aload         11
     132: iconst_0
     133: iaload
     134: if_icmplt     168
     137: iload         12
     139: aload_2
     140: iload         13
     142: iaload
     143: bipush        100
     145: aload         6
     147: iload         13
     149: invokeinterface #49,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     154: checkcast     #51                 // class java/lang/Number
     157: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     160: isub
     161: imul
     162: bipush        100
     164: idiv
     165: iadd
     166: istore        12
     168: iload         12
     170: aload         11
     172: iconst_1
     173: iaload
     174: if_icmplt     186
     177: iinc          7, 1
     180: iconst_0
     181: istore        12
     183: goto          192
     186: iinc          13, 1
     189: goto          108
     192: iload         8
     194: iload         12
     196: iadd
     197: istore        8
     199: iinc          9, 1
     202: goto          85
     205: iload         7
     207: aload_3
     208: iconst_0
     209: iaload
     210: if_icmple     226
     213: aload_3
     214: iconst_0
     215: iload         7
     217: iastore
     218: aload_3
     219: iconst_1
     220: iload         8
     222: iastore
     223: goto          47
     226: iload         7
     228: aload_3
     229: iconst_0
     230: iaload
     231: if_icmpne     47
     234: iload         8
     236: aload_3
     237: iconst_1
     238: iaload
     239: if_icmple     47
     242: aload_3
     243: iconst_1
     244: iload         8
     246: iastore
     247: goto          47
     250: aload_3
     251: areturn

  private final java.util.List<java.util.List<java.lang.Integer>> combinations(int);
    Code:
       0: new           #71                 // class java/util/ArrayList
       3: dup
       4: invokespecial #72                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #29                 // class java/util/List
      10: astore_2
      11: aload_0
      12: aload_2
      13: new           #71                 // class java/util/ArrayList
      16: dup
      17: invokespecial #72                 // Method java/util/ArrayList."<init>":()V
      20: checkcast     #29                 // class java/util/List
      23: iload_1
      24: invokespecial #76                 // Method backtrack:(Ljava/util/List;Ljava/util/List;I)V
      27: aload_2
      28: areturn

  private final void backtrack(java.util.List<java.util.List<java.lang.Integer>>, java.util.List<java.lang.Integer>, int);
    Code:
       0: aload_2
       1: invokeinterface #81,  1           // InterfaceMethod java/util/List.size:()I
       6: iload_3
       7: if_icmpne     25
      10: aload_1
      11: aload_2
      12: checkcast     #83                 // class java/lang/Iterable
      15: invokestatic  #89                 // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
      18: invokeinterface #93,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      23: pop
      24: return
      25: iconst_4
      26: anewarray     #95                 // class java/lang/Integer
      29: astore        5
      31: aload         5
      33: iconst_0
      34: bipush        10
      36: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: aastore
      40: aload         5
      42: iconst_1
      43: bipush        20
      45: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      48: aastore
      49: aload         5
      51: iconst_2
      52: bipush        30
      54: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      57: aastore
      58: aload         5
      60: iconst_3
      61: bipush        40
      63: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: aastore
      67: aload         5
      69: invokestatic  #103                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      72: astore        4
      74: aload         4
      76: invokeinterface #33,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      81: astore        5
      83: aload         5
      85: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      90: ifeq          145
      93: aload         5
      95: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: checkcast     #51                 // class java/lang/Number
     103: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     106: istore        6
     108: aload_2
     109: iload         6
     111: invokestatic  #99                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: invokeinterface #93,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     119: pop
     120: aload_0
     121: aload_1
     122: aload_2
     123: iload_3
     124: invokespecial #76                 // Method backtrack:(Ljava/util/List;Ljava/util/List;I)V
     127: aload_2
     128: aload_2
     129: invokeinterface #81,  1           // InterfaceMethod java/util/List.size:()I
     134: iconst_1
     135: isub
     136: invokeinterface #106,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     141: pop
     142: goto          83
     145: return
}