import java.util.*

private class Block(val l: Int, val r: Int) : Comparable<Block> {
    fun cover(c: Block) = l <= c.l && r >= c.r
    override fun compareTo(other: Block): Int = l.compareTo(other.l)
}

fun main() {
    val (n, d) = readLine()!!.split(" ").map { it.toInt() }
    val bh = arrayOfNulls<TreeSet<Block>>(n + 1) // blocks by height
    // Segment tree
    val tt = BooleanArray(4 * d) // terminal(leaf) node in segment tree
    val th = IntArray(4 * d) // max height in this segment
    tt[0] = true
    // Segment tree functions
    fun findMax(b: Block, i: Int, tl: Int, tr: Int): Int {
        if (tt[i] || b.l <= tl && b.r >= tr) return th[i]
        val tm = (tl + tr) / 2
        return maxOf(
            if (b.l <= tm) findMax(b, 2 * i + 1, tl, tm) else 0,
            if (b.r > tm) findMax(b, 2 * i + 2, tm + 1, tr) else 0
        )
    }
    fun setLeaf(i: Int, h: Int) {
        tt[i] = true
        th[i] = h
    }
    fun place(b: Block, h: Int, i: Int, tl: Int, tr: Int) {
        if (b.l <= tl && b.r >= tr) return setLeaf(i, h)
        val tm = (tl + tr) / 2
        val j1 = 2 * i + 1
        val j2 = 2 * i + 2
        if (tt[i]) { // split node
            tt[i] = false
            setLeaf(j1, th[i])
            setLeaf(j2, th[i])
        }
        if (b.l <= tm) place(b, h, j1, tl, tm)
        if (b.r > tm) place(b, h, j2, tm + 1, tr)
        th[i] = maxOf(th[j1], th[j2])
    }
    // Simulate each incoming block & print answer
    var bc = 0
    repeat(n) {
        val b = readLine()!!.split(" ").map { it.toInt() }.let{ (l, r) -> Block(l, r) }
        var maxH = findMax(b, 0, 1, d)
        while (true) {
            val bs = bh[maxH] ?: break
            var floor = bs.floor(b)
            if (floor != null && floor.r < b.l) floor = bs.higher(floor)
            if (floor == null) floor = bs.first()
            check(floor.l <= b.r)
            val list = bs.tailSet(floor).takeWhile { it.l <= b.r }
            if (!b.cover(list.first()) || !b.cover(list.last())) break
            for (c in list) bs -= c // don't use bs.removeAll(list)
            bc -= list.size
            maxH--
        }
        val h = maxH + 1
        place(b, h, 0, 1, d)
        val bs = bh[h] ?: run { TreeSet<Block>().also { bh[h] = it } }
        bs += b
        println(++bc)
    }
}

Compiled from "FallingBlocks.kt"
public final class FallingBlocksKt {
  public static final void main();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #20                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #22                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #24                 // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #32                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #34                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #46                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #22                 // class java/lang/String
      92: astore        8
      94: astore        23
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #66                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         23
     110: swap
     111: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #76                 // class java/util/List
     125: nop
     126: astore_0
     127: aload_0
     128: iconst_0
     129: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #82                 // class java/lang/Number
     137: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     140: istore_1
     141: aload_0
     142: iconst_1
     143: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     148: checkcast     #82                 // class java/lang/Number
     151: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     154: istore_2
     155: iload_1
     156: iconst_1
     157: iadd
     158: anewarray     #88                 // class java/util/TreeSet
     161: astore_3
     162: iconst_4
     163: iload_2
     164: imul
     165: newarray       boolean
     167: astore        4
     169: iconst_4
     170: iload_2
     171: imul
     172: newarray       int
     174: astore        5
     176: aload         4
     178: iconst_0
     179: iconst_1
     180: bastore
     181: iconst_0
     182: istore        6
     184: iconst_0
     185: istore        7
     187: iload         7
     189: iload_1
     190: if_icmpge     823
     193: iload         7
     195: istore        8
     197: iconst_0
     198: istore        9
     200: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     203: dup
     204: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     207: checkcast     #20                 // class java/lang/CharSequence
     210: iconst_1
     211: anewarray     #22                 // class java/lang/String
     214: astore        10
     216: aload         10
     218: iconst_0
     219: ldc           #24                 // String
     221: aastore
     222: aload         10
     224: iconst_0
     225: iconst_0
     226: bipush        6
     228: aconst_null
     229: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     232: checkcast     #32                 // class java/lang/Iterable
     235: astore        10
     237: iconst_0
     238: istore        11
     240: aload         10
     242: astore        12
     244: new           #34                 // class java/util/ArrayList
     247: dup
     248: aload         10
     250: bipush        10
     252: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     255: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
     258: checkcast     #46                 // class java/util/Collection
     261: astore        13
     263: iconst_0
     264: istore        14
     266: aload         12
     268: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     273: astore        15
     275: aload         15
     277: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          329
     285: aload         15
     287: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     292: astore        16
     294: aload         13
     296: aload         16
     298: checkcast     #22                 // class java/lang/String
     301: astore        17
     303: astore        18
     305: iconst_0
     306: istore        19
     308: aload         17
     310: invokestatic  #66                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     313: nop
     314: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     317: aload         18
     319: swap
     320: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     325: pop
     326: goto          275
     329: aload         13
     331: checkcast     #76                 // class java/util/List
     334: nop
     335: astore        11
     337: iconst_0
     338: istore        12
     340: aload         11
     342: iconst_0
     343: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     348: checkcast     #82                 // class java/lang/Number
     351: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     354: istore        13
     356: aload         11
     358: iconst_1
     359: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     364: checkcast     #82                 // class java/lang/Number
     367: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     370: istore        14
     372: new           #90                 // class Block
     375: dup
     376: iload         13
     378: iload         14
     380: invokespecial #93                 // Method Block."<init>":(II)V
     383: nop
     384: astore        20
     386: aload         4
     388: aload         5
     390: aload         20
     392: iconst_0
     393: iconst_1
     394: iload_2
     395: invokestatic  #97                 // Method main$findMax:([Z[ILBlock;III)I
     398: istore        10
     400: nop
     401: aload_3
     402: iload         10
     404: aaload
     405: dup
     406: ifnonnull     413
     409: pop
     410: goto          725
     413: astore        11
     415: aload         11
     417: aload         20
     419: invokevirtual #101                // Method java/util/TreeSet.floor:(Ljava/lang/Object;)Ljava/lang/Object;
     422: checkcast     #90                 // class Block
     425: astore        12
     427: aload         12
     429: ifnull        457
     432: aload         12
     434: invokevirtual #104                // Method Block.getR:()I
     437: aload         20
     439: invokevirtual #107                // Method Block.getL:()I
     442: if_icmpge     457
     445: aload         11
     447: aload         12
     449: invokevirtual #110                // Method java/util/TreeSet.higher:(Ljava/lang/Object;)Ljava/lang/Object;
     452: checkcast     #90                 // class Block
     455: astore        12
     457: aload         12
     459: ifnonnull     472
     462: aload         11
     464: invokevirtual #113                // Method java/util/TreeSet.first:()Ljava/lang/Object;
     467: checkcast     #90                 // class Block
     470: astore        12
     472: aload         12
     474: invokevirtual #107                // Method Block.getL:()I
     477: aload         20
     479: invokevirtual #104                // Method Block.getR:()I
     482: if_icmpgt     489
     485: iconst_1
     486: goto          490
     489: iconst_0
     490: ifne          503
     493: new           #115                // class java/lang/IllegalStateException
     496: dup
     497: ldc           #117                // String Check failed.
     499: invokespecial #120                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     502: athrow
     503: aload         11
     505: aload         12
     507: invokevirtual #124                // Method java/util/TreeSet.tailSet:(Ljava/lang/Object;)Ljava/util/SortedSet;
     510: dup
     511: ldc           #126                // String tailSet(...)
     513: invokestatic  #130                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     516: checkcast     #32                 // class java/lang/Iterable
     519: astore        14
     521: iconst_0
     522: istore        15
     524: new           #34                 // class java/util/ArrayList
     527: dup
     528: invokespecial #132                // Method java/util/ArrayList."<init>":()V
     531: astore        16
     533: aload         14
     535: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     540: astore        17
     542: aload         17
     544: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     549: ifeq          606
     552: aload         17
     554: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     559: astore        19
     561: aload         19
     563: checkcast     #90                 // class Block
     566: astore        21
     568: iconst_0
     569: istore        22
     571: aload         21
     573: invokevirtual #107                // Method Block.getL:()I
     576: aload         20
     578: invokevirtual #104                // Method Block.getR:()I
     581: if_icmpgt     588
     584: iconst_1
     585: goto          589
     588: iconst_0
     589: ifne          595
     592: goto          606
     595: aload         16
     597: aload         19
     599: invokevirtual #133                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     602: pop
     603: goto          542
     606: aload         16
     608: checkcast     #76                 // class java/util/List
     611: astore        13
     613: aload         20
     615: aload         13
     617: invokestatic  #136                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     620: dup
     621: ldc           #138                // String first(...)
     623: invokestatic  #130                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     626: checkcast     #90                 // class Block
     629: invokevirtual #142                // Method Block.cover:(LBlock;)Z
     632: ifeq          725
     635: aload         20
     637: aload         13
     639: invokestatic  #145                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     642: dup
     643: ldc           #147                // String last(...)
     645: invokestatic  #130                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     648: checkcast     #90                 // class Block
     651: invokevirtual #142                // Method Block.cover:(LBlock;)Z
     654: ifne          660
     657: goto          725
     660: aload         13
     662: invokeinterface #148,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     667: astore        14
     669: aload         14
     671: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     676: ifeq          707
     679: aload         14
     681: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     686: checkcast     #90                 // class Block
     689: astore        15
     691: aload         11
     693: checkcast     #46                 // class java/util/Collection
     696: aload         15
     698: invokeinterface #151,  2          // InterfaceMethod java/util/Collection.remove:(Ljava/lang/Object;)Z
     703: pop
     704: goto          669
     707: iload         6
     709: aload         13
     711: invokeinterface #154,  1          // InterfaceMethod java/util/List.size:()I
     716: isub
     717: istore        6
     719: iinc          10, -1
     722: goto          400
     725: iload         10
     727: iconst_1
     728: iadd
     729: istore        11
     731: aload         4
     733: aload         5
     735: aload         20
     737: iload         11
     739: iconst_0
     740: iconst_1
     741: iload_2
     742: invokestatic  #158                // Method main$place:([Z[ILBlock;IIII)V
     745: aload_3
     746: iload         11
     748: aaload
     749: dup
     750: ifnonnull     783
     753: pop
     754: iconst_0
     755: istore        14
     757: new           #88                 // class java/util/TreeSet
     760: dup
     761: invokespecial #159                // Method java/util/TreeSet."<init>":()V
     764: astore        15
     766: aload         15
     768: astore        16
     770: iconst_0
     771: istore        17
     773: aload_3
     774: iload         11
     776: aload         16
     778: aastore
     779: aload         15
     781: nop
     782: nop
     783: astore        12
     785: aload         12
     787: checkcast     #46                 // class java/util/Collection
     790: aload         20
     792: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     797: pop
     798: iload         6
     800: iconst_1
     801: iadd
     802: istore        6
     804: iload         6
     806: istore        13
     808: getstatic     #165                // Field java/lang/System.out:Ljava/io/PrintStream;
     811: iload         13
     813: invokevirtual #170                // Method java/io/PrintStream.println:(I)V
     816: nop
     817: iinc          7, 1
     820: goto          187
     823: return

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

  private static final int main$findMax(boolean[], int[], Block, int, int, int);
    Code:
       0: aload_0
       1: iload_3
       2: baload
       3: ifne          24
       6: aload_2
       7: invokevirtual #107                // Method Block.getL:()I
      10: iload         4
      12: if_icmpgt     28
      15: aload_2
      16: invokevirtual #104                // Method Block.getR:()I
      19: iload         5
      21: if_icmplt     28
      24: aload_1
      25: iload_3
      26: iaload
      27: ireturn
      28: iload         4
      30: iload         5
      32: iadd
      33: iconst_2
      34: idiv
      35: istore        6
      37: nop
      38: aload_2
      39: invokevirtual #107                // Method Block.getL:()I
      42: iload         6
      44: if_icmpgt     65
      47: aload_0
      48: aload_1
      49: aload_2
      50: iconst_2
      51: iload_3
      52: imul
      53: iconst_1
      54: iadd
      55: iload         4
      57: iload         6
      59: invokestatic  #97                 // Method main$findMax:([Z[ILBlock;III)I
      62: goto          66
      65: iconst_0
      66: aload_2
      67: invokevirtual #104                // Method Block.getR:()I
      70: iload         6
      72: if_icmple     95
      75: aload_0
      76: aload_1
      77: aload_2
      78: iconst_2
      79: iload_3
      80: imul
      81: iconst_2
      82: iadd
      83: iload         6
      85: iconst_1
      86: iadd
      87: iload         5
      89: invokestatic  #97                 // Method main$findMax:([Z[ILBlock;III)I
      92: goto          96
      95: iconst_0
      96: invokestatic  #228                // Method java/lang/Math.max:(II)I
      99: ireturn

  private static final void main$setLeaf(boolean[], int[], int, int);
    Code:
       0: aload_0
       1: iload_2
       2: iconst_1
       3: bastore
       4: aload_1
       5: iload_2
       6: iload_3
       7: iastore
       8: return

  private static final void main$place(boolean[], int[], Block, int, int, int, int);
    Code:
       0: aload_2
       1: invokevirtual #107                // Method Block.getL:()I
       4: iload         5
       6: if_icmpgt     27
       9: aload_2
      10: invokevirtual #104                // Method Block.getR:()I
      13: iload         6
      15: if_icmplt     27
      18: aload_0
      19: aload_1
      20: iload         4
      22: iload_3
      23: invokestatic  #236                // Method main$setLeaf:([Z[III)V
      26: return
      27: iload         5
      29: iload         6
      31: iadd
      32: iconst_2
      33: idiv
      34: istore        7
      36: iconst_2
      37: iload         4
      39: imul
      40: iconst_1
      41: iadd
      42: istore        8
      44: iconst_2
      45: iload         4
      47: imul
      48: iconst_2
      49: iadd
      50: istore        9
      52: aload_0
      53: iload         4
      55: baload
      56: ifeq          86
      59: aload_0
      60: iload         4
      62: iconst_0
      63: bastore
      64: aload_0
      65: aload_1
      66: iload         8
      68: aload_1
      69: iload         4
      71: iaload
      72: invokestatic  #236                // Method main$setLeaf:([Z[III)V
      75: aload_0
      76: aload_1
      77: iload         9
      79: aload_1
      80: iload         4
      82: iaload
      83: invokestatic  #236                // Method main$setLeaf:([Z[III)V
      86: aload_2
      87: invokevirtual #107                // Method Block.getL:()I
      90: iload         7
      92: if_icmpgt     108
      95: aload_0
      96: aload_1
      97: aload_2
      98: iload_3
      99: iload         8
     101: iload         5
     103: iload         7
     105: invokestatic  #158                // Method main$place:([Z[ILBlock;IIII)V
     108: aload_2
     109: invokevirtual #104                // Method Block.getR:()I
     112: iload         7
     114: if_icmple     132
     117: aload_0
     118: aload_1
     119: aload_2
     120: iload_3
     121: iload         9
     123: iload         7
     125: iconst_1
     126: iadd
     127: iload         6
     129: invokestatic  #158                // Method main$place:([Z[ILBlock;IIII)V
     132: aload_1
     133: iload         4
     135: aload_1
     136: iload         8
     138: iaload
     139: aload_1
     140: iload         9
     142: iaload
     143: invokestatic  #228                // Method java/lang/Math.max:(II)I
     146: iastore
     147: return
}


fun main() {
    class Ans(val a: String, val m: String)
    repeat(readLine()!!.toInt()) {
        val s = readLine()!!
        val n = s.length
        val dp = Array(n) { i -> arrayOfNulls<Ans>(i + 1) }
        dp[0][0] = Ans(s.substring(0, 1), "R")
        var best = Ans(s, "")
        fun updateBest(p: Ans) {
            if (p.a <= best.a) best = p
        }
        fun updateDP(i: Int, j: Int, p: Ans) {
            val cur = dp[i][j]
            if (cur == null || p.a < cur.a) dp[i][j] = p
        }
        for (i in 1 until n) {
            for (j in 0 until i) {
                val p = dp[i - 1][j] ?: continue
                updateDP(i, j, Ans(p.a + s[i], p.m + "R"))
                if (j >= i - j) continue
                if (s[i] == p.a[j]) updateDP(i, j + 1, Ans(p.a, p.m + "B"))
                if (s[i] < p.a[j]) updateBest(Ans(p.a, p.m + "B".repeat(n - i)))
            }
        }
        for (p in dp[n - 1]) if (p != null) updateBest(p)
        println(best.m)
    }
}

Compiled from "PaintString.kt"
public final class PaintStringKt$main$Ans {
  private final java.lang.String a;

  private final java.lang.String m;

  public PaintStringKt$main$Ans(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #8                  // String a
       3: invokestatic  #14                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #16                 // String m
       9: invokestatic  #14                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #19                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #22                 // Field a:Ljava/lang/String;
      21: aload_0
      22: aload_2
      23: putfield      #24                 // Field m:Ljava/lang/String;
      26: return

  public final java.lang.String getA();
    Code:
       0: aload_0
       1: getfield      #22                 // Field a:Ljava/lang/String;
       4: areturn

  public final java.lang.String getM();
    Code:
       0: aload_0
       1: getfield      #24                 // Field m:Ljava/lang/String;
       4: areturn
}

Compiled from "PaintString.kt"
public final class PaintStringKt {
  public static final void main();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: invokestatic  #24                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      10: istore_0
      11: iconst_0
      12: istore_1
      13: iload_1
      14: iload_0
      15: if_icmpge     477
      18: iload_1
      19: istore_2
      20: iconst_0
      21: istore_3
      22: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      25: dup
      26: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      29: astore        4
      31: aload         4
      33: invokevirtual #30                 // Method java/lang/String.length:()I
      36: istore        5
      38: iconst_0
      39: istore        6
      41: iload         5
      43: anewarray     #32                 // class "[LPaintStringKt$main$Ans;"
      46: astore        7
      48: iload         6
      50: iload         5
      52: if_icmpge     77
      55: iload         6
      57: istore        8
      59: aload         7
      61: iload         8
      63: iload         8
      65: iconst_1
      66: iadd
      67: anewarray     #34                 // class PaintStringKt$main$Ans
      70: aastore
      71: iinc          6, 1
      74: goto          48
      77: aload         7
      79: astore        9
      81: aload         9
      83: iconst_0
      84: aaload
      85: iconst_0
      86: new           #34                 // class PaintStringKt$main$Ans
      89: dup
      90: aload         4
      92: iconst_0
      93: iconst_1
      94: invokevirtual #38                 // Method java/lang/String.substring:(II)Ljava/lang/String;
      97: dup
      98: ldc           #40                 // String substring(...)
     100: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     103: ldc           #46                 // String R
     105: invokespecial #50                 // Method PaintStringKt$main$Ans."<init>":(Ljava/lang/String;Ljava/lang/String;)V
     108: aastore
     109: new           #52                 // class kotlin/jvm/internal/Ref$ObjectRef
     112: dup
     113: invokespecial #54                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     116: astore        6
     118: aload         6
     120: new           #34                 // class PaintStringKt$main$Ans
     123: dup
     124: aload         4
     126: ldc           #56                 // String
     128: invokespecial #50                 // Method PaintStringKt$main$Ans."<init>":(Ljava/lang/String;Ljava/lang/String;)V
     131: putfield      #60                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     134: iconst_1
     135: istore        7
     137: iload         7
     139: iload         5
     141: if_icmpge     403
     144: iconst_0
     145: istore        8
     147: iload         8
     149: iload         7
     151: if_icmpge     397
     154: aload         9
     156: iload         7
     158: iconst_1
     159: isub
     160: aaload
     161: iload         8
     163: aaload
     164: dup
     165: ifnonnull     172
     168: pop
     169: goto          391
     172: astore        10
     174: aload         9
     176: iload         7
     178: iload         8
     180: new           #34                 // class PaintStringKt$main$Ans
     183: dup
     184: new           #62                 // class java/lang/StringBuilder
     187: dup
     188: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
     191: aload         10
     193: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
     196: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     199: aload         4
     201: iload         7
     203: invokevirtual #74                 // Method java/lang/String.charAt:(I)C
     206: invokevirtual #77                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     209: invokevirtual #80                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     212: new           #62                 // class java/lang/StringBuilder
     215: dup
     216: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
     219: aload         10
     221: invokevirtual #83                 // Method PaintStringKt$main$Ans.getM:()Ljava/lang/String;
     224: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     227: bipush        82
     229: invokevirtual #77                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     232: invokevirtual #80                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     235: invokespecial #50                 // Method PaintStringKt$main$Ans."<init>":(Ljava/lang/String;Ljava/lang/String;)V
     238: invokestatic  #87                 // Method main$lambda$0$updateDP:([[LPaintStringKt$main$Ans;IILPaintStringKt$main$Ans;)V
     241: iload         8
     243: iload         7
     245: iload         8
     247: isub
     248: if_icmpge     391
     251: aload         4
     253: iload         7
     255: invokevirtual #74                 // Method java/lang/String.charAt:(I)C
     258: aload         10
     260: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
     263: iload         8
     265: invokevirtual #74                 // Method java/lang/String.charAt:(I)C
     268: if_icmpne     317
     271: aload         9
     273: iload         7
     275: iload         8
     277: iconst_1
     278: iadd
     279: new           #34                 // class PaintStringKt$main$Ans
     282: dup
     283: aload         10
     285: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
     288: new           #62                 // class java/lang/StringBuilder
     291: dup
     292: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
     295: aload         10
     297: invokevirtual #83                 // Method PaintStringKt$main$Ans.getM:()Ljava/lang/String;
     300: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     303: bipush        66
     305: invokevirtual #77                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     308: invokevirtual #80                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     311: invokespecial #50                 // Method PaintStringKt$main$Ans."<init>":(Ljava/lang/String;Ljava/lang/String;)V
     314: invokestatic  #87                 // Method main$lambda$0$updateDP:([[LPaintStringKt$main$Ans;IILPaintStringKt$main$Ans;)V
     317: aload         4
     319: iload         7
     321: invokevirtual #74                 // Method java/lang/String.charAt:(I)C
     324: aload         10
     326: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
     329: iload         8
     331: invokevirtual #74                 // Method java/lang/String.charAt:(I)C
     334: invokestatic  #91                 // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     337: ifge          391
     340: aload         6
     342: new           #34                 // class PaintStringKt$main$Ans
     345: dup
     346: aload         10
     348: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
     351: new           #62                 // class java/lang/StringBuilder
     354: dup
     355: invokespecial #63                 // Method java/lang/StringBuilder."<init>":()V
     358: aload         10
     360: invokevirtual #83                 // Method PaintStringKt$main$Ans.getM:()Ljava/lang/String;
     363: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     366: ldc           #93                 // String B
     368: checkcast     #95                 // class java/lang/CharSequence
     371: iload         5
     373: iload         7
     375: isub
     376: invokestatic  #101                // Method kotlin/text/StringsKt.repeat:(Ljava/lang/CharSequence;I)Ljava/lang/String;
     379: invokevirtual #70                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     382: invokevirtual #80                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     385: invokespecial #50                 // Method PaintStringKt$main$Ans."<init>":(Ljava/lang/String;Ljava/lang/String;)V
     388: invokestatic  #105                // Method main$lambda$0$updateBest:(Lkotlin/jvm/internal/Ref$ObjectRef;LPaintStringKt$main$Ans;)V
     391: iinc          8, 1
     394: goto          147
     397: iinc          7, 1
     400: goto          137
     403: aload         9
     405: iload         5
     407: iconst_1
     408: isub
     409: aaload
     410: astore        7
     412: iconst_0
     413: istore        8
     415: aload         7
     417: arraylength
     418: istore        10
     420: iload         8
     422: iload         10
     424: if_icmpge     452
     427: aload         7
     429: iload         8
     431: aaload
     432: astore        11
     434: aload         11
     436: ifnull        446
     439: aload         6
     441: aload         11
     443: invokestatic  #105                // Method main$lambda$0$updateBest:(Lkotlin/jvm/internal/Ref$ObjectRef;LPaintStringKt$main$Ans;)V
     446: iinc          8, 1
     449: goto          420
     452: aload         6
     454: getfield      #60                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     457: checkcast     #34                 // class PaintStringKt$main$Ans
     460: invokevirtual #83                 // Method PaintStringKt$main$Ans.getM:()Ljava/lang/String;
     463: getstatic     #111                // Field java/lang/System.out:Ljava/io/PrintStream;
     466: swap
     467: invokevirtual #116                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     470: nop
     471: iinc          1, 1
     474: goto          13
     477: return

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

  private static final void main$lambda$0$updateBest(kotlin.jvm.internal.Ref$ObjectRef<PaintStringKt$main$Ans>, PaintStringKt$main$Ans);
    Code:
       0: aload_1
       1: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
       4: aload_0
       5: getfield      #60                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
       8: checkcast     #34                 // class PaintStringKt$main$Ans
      11: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
      14: invokevirtual #140                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
      17: ifgt          25
      20: aload_0
      21: aload_1
      22: putfield      #60                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      25: return

  private static final void main$lambda$0$updateDP(PaintStringKt$main$Ans[][], int, int, PaintStringKt$main$Ans);
    Code:
       0: aload_0
       1: iload_1
       2: aaload
       3: iload_2
       4: aaload
       5: astore        4
       7: aload         4
       9: ifnull        27
      12: aload_3
      13: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
      16: aload         4
      18: invokevirtual #66                 // Method PaintStringKt$main$Ans.getA:()Ljava/lang/String;
      21: invokevirtual #140                // Method java/lang/String.compareTo:(Ljava/lang/String;)I
      24: ifge          33
      27: aload_0
      28: iload_1
      29: aaload
      30: iload_2
      31: aload_3
      32: aastore
      33: return
}


import java.util.*

fun main() {
    repeat(readLine()!!.toInt()) {
//        readLine() // skip empty line
        solveCase()
    }
}

private data class Mv(val i: Int, val a: Int, val b: Int, var t: Int = 0) : Comparable<Mv> {
    override fun compareTo(other: Mv): Int = if (b != other.b) b.compareTo(other.b) else i.compareTo(other.i)
}

private fun solveCase() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val d = Array(n) { i ->
        readLine()!!.split(" ").map { it.toInt() }.let { (a, b) -> Mv(i, a, b) }
    }
    d.sortBy { it.a }
    var t = 0
    val w = TreeSet<Mv>()
    fun advance(to: Int) {
        while (t < to && !w.isEmpty()) {
            repeat(minOf(w.size, m)) {
                val v = w.first()
                v.t = t
                w -= v
            }
            t++
        }
        t = to
    }
    for (v in d) {
        advance(v.a)
        w += v
    }
    advance(Int.MAX_VALUE)
    d.sortBy { it.i }
    println(maxOf(0, d.map { it.t - it.b }.max()!!))
    println(d.joinToString(" ") { it.t.toString() })
}

Compiled from "Comparisons.kt"
public final class MovieFanKt$solveCase$$inlined$sortBy$1<T> implements java.util.Comparator {
  public MovieFanKt$solveCase$$inlined$sortBy$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 Mv
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method Mv.getA:()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 Mv
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method Mv.getA:()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 "MovieFan.kt"
public final class MovieFanKt {
  public static final void main();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: invokestatic  #24                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      10: istore_0
      11: iconst_0
      12: istore_1
      13: iload_1
      14: iload_0
      15: if_icmpge     32
      18: iload_1
      19: istore_2
      20: iconst_0
      21: istore_3
      22: invokestatic  #27                 // Method solveCase:()V
      25: nop
      26: iinc          1, 1
      29: goto          13
      32: return

  private static final void solveCase();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #32                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #34                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #36                 // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #42                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #44                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #46                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #58                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #34                 // class java/lang/String
      92: astore        8
      94: astore        17
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #24                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         17
     110: swap
     111: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #82                 // class java/util/List
     125: nop
     126: astore_0
     127: aload_0
     128: iconst_0
     129: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #88                 // class java/lang/Number
     137: invokevirtual #92                 // Method java/lang/Number.intValue:()I
     140: istore_1
     141: aload_0
     142: iconst_1
     143: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     148: checkcast     #88                 // class java/lang/Number
     151: invokevirtual #92                 // Method java/lang/Number.intValue:()I
     154: istore_2
     155: iconst_0
     156: istore        4
     158: iload_1
     159: anewarray     #94                 // class Mv
     162: astore        5
     164: iload         4
     166: iload_1
     167: if_icmpge     398
     170: iload         4
     172: istore        6
     174: aload         5
     176: iload         6
     178: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     181: dup
     182: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     185: checkcast     #32                 // class java/lang/CharSequence
     188: iconst_1
     189: anewarray     #34                 // class java/lang/String
     192: astore        7
     194: aload         7
     196: iconst_0
     197: ldc           #36                 // String
     199: aastore
     200: aload         7
     202: iconst_0
     203: iconst_0
     204: bipush        6
     206: aconst_null
     207: invokestatic  #42                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     210: checkcast     #44                 // class java/lang/Iterable
     213: astore        7
     215: istore        18
     217: astore        17
     219: iconst_0
     220: istore        8
     222: aload         7
     224: astore        9
     226: new           #46                 // class java/util/ArrayList
     229: dup
     230: aload         7
     232: bipush        10
     234: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     237: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
     240: checkcast     #58                 // class java/util/Collection
     243: astore        10
     245: iconst_0
     246: istore        11
     248: aload         9
     250: invokeinterface #62,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     255: astore        12
     257: aload         12
     259: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     264: ifeq          311
     267: aload         12
     269: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     274: astore        13
     276: aload         10
     278: aload         13
     280: checkcast     #34                 // class java/lang/String
     283: astore        14
     285: astore        19
     287: iconst_0
     288: istore        15
     290: aload         14
     292: invokestatic  #24                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     295: nop
     296: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     299: aload         19
     301: swap
     302: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     307: pop
     308: goto          257
     311: aload         10
     313: checkcast     #82                 // class java/util/List
     316: nop
     317: astore        19
     319: aload         17
     321: iload         18
     323: aload         19
     325: astore        8
     327: istore        18
     329: astore        17
     331: iconst_0
     332: istore        9
     334: aload         8
     336: iconst_0
     337: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     342: checkcast     #88                 // class java/lang/Number
     345: invokevirtual #92                 // Method java/lang/Number.intValue:()I
     348: istore        10
     350: aload         8
     352: iconst_1
     353: invokeinterface #86,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     358: checkcast     #88                 // class java/lang/Number
     361: invokevirtual #92                 // Method java/lang/Number.intValue:()I
     364: istore        11
     366: new           #94                 // class Mv
     369: dup
     370: iload         6
     372: iload         10
     374: iload         11
     376: iconst_0
     377: bipush        8
     379: aconst_null
     380: invokespecial #97                 // Method Mv."<init>":(IIIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     383: astore        19
     385: aload         17
     387: iload         18
     389: aload         19
     391: aastore
     392: iinc          4, 1
     395: goto          164
     398: aload         5
     400: astore_3
     401: aload_3
     402: astore        4
     404: iconst_0
     405: istore        5
     407: aload         4
     409: arraylength
     410: iconst_1
     411: if_icmple     429
     414: aload         4
     416: new           #99                 // class MovieFanKt$solveCase$$inlined$sortBy$1
     419: dup
     420: invokespecial #101                // Method MovieFanKt$solveCase$$inlined$sortBy$1."<init>":()V
     423: checkcast     #103                // class java/util/Comparator
     426: invokestatic  #109                // Method kotlin/collections/ArraysKt.sortWith:([Ljava/lang/Object;Ljava/util/Comparator;)V
     429: nop
     430: new           #111                // class kotlin/jvm/internal/Ref$IntRef
     433: dup
     434: invokespecial #112                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     437: astore        4
     439: new           #114                // class java/util/TreeSet
     442: dup
     443: invokespecial #115                // Method java/util/TreeSet."<init>":()V
     446: astore        5
     448: iconst_0
     449: istore        6
     451: aload_3
     452: arraylength
     453: istore        7
     455: iload         6
     457: iload         7
     459: if_icmpge     500
     462: aload_3
     463: iload         6
     465: aaload
     466: astore        8
     468: aload         4
     470: aload         5
     472: iload_2
     473: aload         8
     475: invokevirtual #118                // Method Mv.getA:()I
     478: invokestatic  #122                // Method solveCase$advance:(Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/TreeSet;II)V
     481: aload         5
     483: checkcast     #58                 // class java/util/Collection
     486: aload         8
     488: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     493: pop
     494: iinc          6, 1
     497: goto          455
     500: aload         4
     502: aload         5
     504: iload_2
     505: ldc           #123                // int 2147483647
     507: invokestatic  #122                // Method solveCase$advance:(Lkotlin/jvm/internal/Ref$IntRef;Ljava/util/TreeSet;II)V
     510: aload_3
     511: astore        6
     513: iconst_0
     514: istore        7
     516: aload         6
     518: arraylength
     519: iconst_1
     520: if_icmple     538
     523: aload         6
     525: new           #125                // class MovieFanKt$solveCase$$inlined$sortBy$2
     528: dup
     529: invokespecial #126                // Method MovieFanKt$solveCase$$inlined$sortBy$2."<init>":()V
     532: checkcast     #103                // class java/util/Comparator
     535: invokestatic  #109                // Method kotlin/collections/ArraysKt.sortWith:([Ljava/lang/Object;Ljava/util/Comparator;)V
     538: nop
     539: iconst_0
     540: istore        6
     542: aload_3
     543: astore        7
     545: iconst_0
     546: istore        8
     548: aload         7
     550: astore        9
     552: new           #46                 // class java/util/ArrayList
     555: dup
     556: aload         7
     558: arraylength
     559: invokespecial #56                 // Method java/util/ArrayList."<init>":(I)V
     562: checkcast     #58                 // class java/util/Collection
     565: astore        10
     567: iconst_0
     568: istore        11
     570: iconst_0
     571: istore        12
     573: aload         9
     575: arraylength
     576: istore        13
     578: iload         12
     580: iload         13
     582: if_icmpge     632
     585: aload         9
     587: iload         12
     589: aaload
     590: astore        14
     592: aload         10
     594: aload         14
     596: astore        15
     598: astore        17
     600: iconst_0
     601: istore        16
     603: aload         15
     605: invokevirtual #129                // Method Mv.getT:()I
     608: aload         15
     610: invokevirtual #132                // Method Mv.getB:()I
     613: isub
     614: invokestatic  #76                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     617: aload         17
     619: swap
     620: invokeinterface #80,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     625: pop
     626: iinc          12, 1
     629: goto          578
     632: aload         10
     634: checkcast     #82                 // class java/util/List
     637: nop
     638: checkcast     #44                 // class java/lang/Iterable
     641: invokestatic  #136                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     644: dup
     645: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     648: checkcast     #88                 // class java/lang/Number
     651: invokevirtual #92                 // Method java/lang/Number.intValue:()I
     654: istore        7
     656: iload         6
     658: iload         7
     660: invokestatic  #142                // Method java/lang/Math.max:(II)I
     663: istore        6
     665: getstatic     #148                // Field java/lang/System.out:Ljava/io/PrintStream;
     668: iload         6
     670: invokevirtual #153                // Method java/io/PrintStream.println:(I)V
     673: aload_3
     674: ldc           #36                 // String
     676: checkcast     #32                 // class java/lang/CharSequence
     679: aconst_null
     680: aconst_null
     681: iconst_0
     682: aconst_null
     683: invokedynamic #172,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     688: bipush        30
     690: aconst_null
     691: invokestatic  #176                // Method kotlin/collections/ArraysKt.joinToString$default:([Ljava/lang/Object;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     694: getstatic     #148                // Field java/lang/System.out:Ljava/io/PrintStream;
     697: swap
     698: invokevirtual #178                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     701: return

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

  private static final void solveCase$advance(kotlin.jvm.internal.Ref$IntRef, java.util.TreeSet<Mv>, int, int);
    Code:
       0: aload_0
       1: getfield      #217                // Field kotlin/jvm/internal/Ref$IntRef.element:I
       4: iload_3
       5: if_icmpge     96
       8: aload_1
       9: invokevirtual #220                // Method java/util/TreeSet.isEmpty:()Z
      12: ifne          96
      15: aload_1
      16: invokevirtual #223                // Method java/util/TreeSet.size:()I
      19: iload_2
      20: invokestatic  #226                // Method java/lang/Math.min:(II)I
      23: istore        4
      25: iconst_0
      26: istore        5
      28: iload         5
      30: iload         4
      32: if_icmpge     79
      35: iload         5
      37: istore        6
      39: iconst_0
      40: istore        7
      42: aload_1
      43: invokevirtual #229                // Method java/util/TreeSet.first:()Ljava/lang/Object;
      46: checkcast     #94                 // class Mv
      49: astore        8
      51: aload         8
      53: aload_0
      54: getfield      #217                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      57: invokevirtual #232                // Method Mv.setT:(I)V
      60: aload_1
      61: checkcast     #58                 // class java/util/Collection
      64: aload         8
      66: invokeinterface #235,  2          // InterfaceMethod java/util/Collection.remove:(Ljava/lang/Object;)Z
      71: pop
      72: nop
      73: iinc          5, 1
      76: goto          28
      79: aload_0
      80: getfield      #217                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      83: istore        4
      85: aload_0
      86: iload         4
      88: iconst_1
      89: iadd
      90: putfield      #217                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      93: goto          0
      96: aload_0
      97: iload_3
      98: putfield      #217                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     101: return

  private static final java.lang.CharSequence solveCase$lambda$8(Mv);
    Code:
       0: aload_0
       1: ldc           #238                // String it
       3: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #129                // Method Mv.getT:()I
      10: invokestatic  #245                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      13: checkcast     #32                 // class java/lang/CharSequence
      16: areturn
}

Compiled from "Comparisons.kt"
public final class MovieFanKt$solveCase$$inlined$sortBy$2<T> implements java.util.Comparator {
  public MovieFanKt$solveCase$$inlined$sortBy$2();
    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 Mv
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method Mv.getI:()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 Mv
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method Mv.getI:()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
}


fun main() {
    val (m, k) = readLine()!!.split(" ").map { it.toInt() }
    val f = factor(m) ?: run {
        println(-1)
        return
    }
    val dp = HashMap<Long,Long>()
    val dig = IntArray(100_000)
    fun count(nd: Int, p: Long = -1): Long {
        val e = f[0] + (f[1] shl 5) + (f[2] shl 10) + (f[3] shl 15) + (nd.toLong() shl 20)
        if (nd == 0) return if (e == 0L) 1 else 0
        if (p == -1L) dp[e]?.let { return it }
        var cnt = 0L
        for (d in 1..9) {
            dig[nd - 1] = d
            val df = factors[d]
            for (i in 0..3) f[i] -= df[i]
            if (f.all { it >= 0 }) {
                val nc = count(nd - 1)
                if (p >= 0 && cnt + nc > p) return count(nd - 1, p - cnt)
                cnt += nc
            }
            for (i in 0..3) f[i] += df[i]
        }
        dp[e] = cnt
        return cnt
    }
    var num = 1L
    var nd = 1
    while (count(nd) <= k - num) num += count(nd++)
    check(count(nd, k - num) == 1L)
    println(dig.take(nd).reversed().joinToString(""))
}

private val pr = listOf(2, 3, 5, 7)
private val factors = Array(10) { factor(it)!! }

private fun factor(m: Int): IntArray? {
    val f = IntArray(4)
    if (m <= 1) return f
    var rem = m
    for ((i, p) in pr.withIndex()) {
        while (rem % p == 0) {
            rem /= p
            f[i]++
        }
    }
    return f.takeIf { rem == 1 }
}

Compiled from "MNumbers.kt"
public final class MNumbersKt {
  private static final java.util.List<java.lang.Integer> pr;

  private static final int[][] factors;

  public static final void main();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #20                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #22                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #24                 // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #32                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #34                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #46                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #22                 // class java/lang/String
      92: astore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #66                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         10
     110: swap
     111: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #76                 // class java/util/List
     125: nop
     126: astore_0
     127: aload_0
     128: iconst_0
     129: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #82                 // class java/lang/Number
     137: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     140: istore_1
     141: aload_0
     142: iconst_1
     143: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     148: checkcast     #82                 // class java/lang/Number
     151: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     154: istore_2
     155: iload_1
     156: invokestatic  #90                 // Method factor:(I)[I
     159: dup
     160: ifnonnull     179
     163: pop
     164: iconst_0
     165: istore        5
     167: iconst_m1
     168: istore        6
     170: getstatic     #96                 // Field java/lang/System.out:Ljava/io/PrintStream;
     173: iload         6
     175: invokevirtual #101                // Method java/io/PrintStream.println:(I)V
     178: return
     179: astore_3
     180: new           #103                // class java/util/HashMap
     183: dup
     184: invokespecial #105                // Method java/util/HashMap."<init>":()V
     187: astore        4
     189: ldc           #106                // int 100000
     191: newarray       int
     193: astore        5
     195: lconst_1
     196: lstore        6
     198: iconst_1
     199: istore        8
     201: aload_3
     202: aload         4
     204: aload         5
     206: iload         8
     208: lconst_0
     209: bipush        16
     211: aconst_null
     212: invokestatic  #110                // Method main$count$default:([ILjava/util/HashMap;[IIJILjava/lang/Object;)J
     215: iload_2
     216: i2l
     217: lload         6
     219: lsub
     220: lcmp
     221: ifgt          249
     224: lload         6
     226: aload_3
     227: aload         4
     229: aload         5
     231: iload         8
     233: iinc          8, 1
     236: lconst_0
     237: bipush        16
     239: aconst_null
     240: invokestatic  #110                // Method main$count$default:([ILjava/util/HashMap;[IIJILjava/lang/Object;)J
     243: ladd
     244: lstore        6
     246: goto          201
     249: aload_3
     250: aload         4
     252: aload         5
     254: iload         8
     256: iload_2
     257: i2l
     258: lload         6
     260: lsub
     261: invokestatic  #114                // Method main$count:([ILjava/util/HashMap;[IIJ)J
     264: lconst_1
     265: lcmp
     266: ifne          273
     269: iconst_1
     270: goto          274
     273: iconst_0
     274: ifne          287
     277: new           #116                // class java/lang/IllegalStateException
     280: dup
     281: ldc           #118                // String Check failed.
     283: invokespecial #121                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     286: athrow
     287: aload         5
     289: iload         8
     291: invokestatic  #127                // Method kotlin/collections/ArraysKt.take:([II)Ljava/util/List;
     294: checkcast     #32                 // class java/lang/Iterable
     297: invokestatic  #131                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     300: checkcast     #32                 // class java/lang/Iterable
     303: ldc           #133                // String
     305: checkcast     #20                 // class java/lang/CharSequence
     308: aconst_null
     309: aconst_null
     310: iconst_0
     311: aconst_null
     312: aconst_null
     313: bipush        62
     315: aconst_null
     316: invokestatic  #137                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     319: getstatic     #96                 // Field java/lang/System.out:Ljava/io/PrintStream;
     322: swap
     323: invokevirtual #139                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     326: return

  private static final int[] factor(int);
    Code:
       0: iconst_4
       1: newarray       int
       3: astore_1
       4: iload_0
       5: iconst_1
       6: if_icmpgt     11
       9: aload_1
      10: areturn
      11: iconst_0
      12: istore_2
      13: iload_0
      14: istore_2
      15: getstatic     #168                // Field pr:Ljava/util/List;
      18: checkcast     #32                 // class java/lang/Iterable
      21: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore_3
      27: iconst_0
      28: istore        4
      30: aload_3
      31: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          92
      39: iload         4
      41: istore        5
      43: iload         4
      45: iconst_1
      46: iadd
      47: istore        4
      49: aload_3
      50: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: checkcast     #82                 // class java/lang/Number
      58: invokevirtual #86                 // Method java/lang/Number.intValue:()I
      61: istore        6
      63: iload_2
      64: iload         6
      66: irem
      67: ifne          30
      70: iload_2
      71: iload         6
      73: idiv
      74: istore_2
      75: aload_1
      76: iload         5
      78: iaload
      79: istore        7
      81: aload_1
      82: iload         5
      84: iload         7
      86: iconst_1
      87: iadd
      88: iastore
      89: goto          63
      92: aload_1
      93: astore_3
      94: aload_3
      95: astore        4
      97: iconst_0
      98: istore        5
     100: iload_2
     101: iconst_1
     102: if_icmpne     109
     105: iconst_1
     106: goto          110
     109: iconst_0
     110: ifeq          117
     113: aload_3
     114: goto          118
     117: aconst_null
     118: areturn

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

  private static final long main$count(int[], java.util.HashMap<java.lang.Long, java.lang.Long>, int[], int, long);
    Code:
       0: aload_0
       1: iconst_0
       2: iaload
       3: aload_0
       4: iconst_1
       5: iaload
       6: iconst_5
       7: ishl
       8: iadd
       9: aload_0
      10: iconst_2
      11: iaload
      12: bipush        10
      14: ishl
      15: iadd
      16: aload_0
      17: iconst_3
      18: iaload
      19: bipush        15
      21: ishl
      22: iadd
      23: i2l
      24: iload_3
      25: i2l
      26: bipush        20
      28: lshl
      29: ladd
      30: lstore        6
      32: iload_3
      33: ifne          49
      36: lload         6
      38: lconst_0
      39: lcmp
      40: ifne          47
      43: lconst_1
      44: goto          48
      47: lconst_0
      48: lreturn
      49: lload         4
      51: ldc2_w        #179                // long -1l
      54: lcmp
      55: ifne          93
      58: aload_1
      59: lload         6
      61: invokestatic  #185                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      64: invokevirtual #188                // Method java/util/HashMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
      67: checkcast     #182                // class java/lang/Long
      70: astore        8
      72: aload         8
      74: ifnull        93
      77: aload         8
      79: checkcast     #82                 // class java/lang/Number
      82: invokevirtual #192                // Method java/lang/Number.longValue:()J
      85: lstore        10
      87: iconst_0
      88: istore        12
      90: lload         10
      92: lreturn
      93: lconst_0
      94: lstore        8
      96: iconst_1
      97: istore        10
      99: iload         10
     101: bipush        10
     103: if_icmpge     310
     106: aload_2
     107: iload_3
     108: iconst_1
     109: isub
     110: iload         10
     112: iastore
     113: getstatic     #196                // Field factors:[[I
     116: iload         10
     118: aaload
     119: astore        11
     121: iconst_0
     122: istore        12
     124: iload         12
     126: iconst_4
     127: if_icmpge     154
     130: iload         12
     132: istore        13
     134: aload_0
     135: iload         13
     137: aload_0
     138: iload         13
     140: iaload
     141: aload         11
     143: iload         12
     145: iaload
     146: isub
     147: iastore
     148: iinc          12, 1
     151: goto          124
     154: aload_0
     155: astore        12
     157: iconst_0
     158: istore        13
     160: iconst_0
     161: istore        14
     163: aload         12
     165: arraylength
     166: istore        15
     168: iload         14
     170: iload         15
     172: if_icmpge     212
     175: aload         12
     177: iload         14
     179: iaload
     180: istore        16
     182: iload         16
     184: istore        17
     186: iconst_0
     187: istore        18
     189: iload         17
     191: iflt          198
     194: iconst_1
     195: goto          199
     198: iconst_0
     199: ifne          206
     202: iconst_0
     203: goto          213
     206: iinc          14, 1
     209: goto          168
     212: iconst_1
     213: ifeq          271
     216: aload_0
     217: aload_1
     218: aload_2
     219: iload_3
     220: iconst_1
     221: isub
     222: lconst_0
     223: bipush        16
     225: aconst_null
     226: invokestatic  #110                // Method main$count$default:([ILjava/util/HashMap;[IIJILjava/lang/Object;)J
     229: lstore        12
     231: lload         4
     233: lconst_0
     234: lcmp
     235: iflt          264
     238: lload         8
     240: lload         12
     242: ladd
     243: lload         4
     245: lcmp
     246: ifle          264
     249: aload_0
     250: aload_1
     251: aload_2
     252: iload_3
     253: iconst_1
     254: isub
     255: lload         4
     257: lload         8
     259: lsub
     260: invokestatic  #114                // Method main$count:([ILjava/util/HashMap;[IIJ)J
     263: lreturn
     264: lload         8
     266: lload         12
     268: ladd
     269: lstore        8
     271: iconst_0
     272: istore        12
     274: iload         12
     276: iconst_4
     277: if_icmpge     304
     280: iload         12
     282: istore        13
     284: aload_0
     285: iload         13
     287: aload_0
     288: iload         13
     290: iaload
     291: aload         11
     293: iload         12
     295: iaload
     296: iadd
     297: iastore
     298: iinc          12, 1
     301: goto          274
     304: iinc          10, 1
     307: goto          99
     310: lload         6
     312: invokestatic  #185                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     315: astore        11
     317: lload         8
     319: invokestatic  #185                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     322: astore        12
     324: aload_1
     325: checkcast     #198                // class java/util/Map
     328: aload         11
     330: aload         12
     332: invokeinterface #202,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     337: pop
     338: lload         8
     340: lreturn

  static long main$count$default(int[], java.util.HashMap, int[], int, long, int, java.lang.Object);
    Code:
       0: iload         6
       2: bipush        16
       4: iand
       5: ifeq          13
       8: ldc2_w        #179                // long -1l
      11: lstore        4
      13: aload_0
      14: aload_1
      15: aload_2
      16: iload_3
      17: lload         4
      19: invokestatic  #114                // Method main$count:([ILjava/util/HashMap;[IIJ)J
      22: lreturn

  static {};
    Code:
       0: iconst_4
       1: anewarray     #62                 // class java/lang/Integer
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_2
       8: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      11: aastore
      12: aload_0
      13: iconst_1
      14: iconst_3
      15: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: aastore
      19: aload_0
      20: iconst_2
      21: iconst_5
      22: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: aastore
      26: aload_0
      27: iconst_3
      28: bipush        7
      30: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: aastore
      34: aload_0
      35: invokestatic  #217                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      38: putstatic     #168                // Field pr:Ljava/util/List;
      41: iconst_0
      42: istore_0
      43: bipush        10
      45: anewarray     #164                // class "[I"
      48: astore_1
      49: iload_0
      50: bipush        10
      52: if_icmpge     74
      55: iload_0
      56: istore_2
      57: aload_1
      58: iload_2
      59: iload_2
      60: invokestatic  #90                 // Method factor:(I)[I
      63: dup
      64: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      67: aastore
      68: iinc          0, 1
      71: goto          49
      74: aload_1
      75: putstatic     #196                // Field factors:[[I
      78: return
}


/**
 * Returns the longest subsequence with unique character.
 */
fun longestUniqueSubSequence(value: String): String {
    var longestUniqueSubSequence = ""
    value.forEachIndexed { index, _ ->
        val uniqueSubsequence = uniqueSubSequence(value.subSequence(index, value.length))
        if (longestUniqueSubSequence.length < uniqueSubsequence.length) {
            longestUniqueSubSequence = uniqueSubsequence
        }
    }

    return longestUniqueSubSequence
}

private fun uniqueSubSequence(sequence: CharSequence): String {
    var uniqueSubSequence = ""
    sequence.forEach { char ->
        if (!uniqueSubSequence.contains(char)) {
            uniqueSubSequence += char
        } else {
            return uniqueSubSequence
        }
    }

    return uniqueSubSequence
}

Compiled from "LongestUniqueSubSequence.kt"
public final class LongestUniqueSubSequenceKt {
  public static final java.lang.String longestUniqueSubSequence(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String value
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aconst_null
       7: astore_1
       8: ldc           #17                 // String
      10: astore_1
      11: aload_0
      12: checkcast     #19                 // class java/lang/CharSequence
      15: astore_2
      16: iconst_0
      17: istore_3
      18: iconst_0
      19: istore        4
      21: iconst_0
      22: istore        5
      24: iload         5
      26: aload_2
      27: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      32: if_icmpge     93
      35: aload_2
      36: iload         5
      38: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      43: istore        6
      45: iload         4
      47: iinc          4, 1
      50: istore        7
      52: iconst_0
      53: istore        8
      55: aload_0
      56: iload         7
      58: aload_0
      59: invokevirtual #30                 // Method java/lang/String.length:()I
      62: invokevirtual #34                 // Method java/lang/String.subSequence:(II)Ljava/lang/CharSequence;
      65: invokestatic  #38                 // Method uniqueSubSequence:(Ljava/lang/CharSequence;)Ljava/lang/String;
      68: astore        9
      70: aload_1
      71: invokevirtual #30                 // Method java/lang/String.length:()I
      74: aload         9
      76: invokevirtual #30                 // Method java/lang/String.length:()I
      79: if_icmpge     85
      82: aload         9
      84: astore_1
      85: nop
      86: nop
      87: iinc          5, 1
      90: goto          24
      93: nop
      94: aload_1
      95: areturn

  private static final java.lang.String uniqueSubSequence(java.lang.CharSequence);
    Code:
       0: aconst_null
       1: astore_1
       2: ldc           #17                 // String
       4: astore_1
       5: aload_0
       6: astore_2
       7: iconst_0
       8: istore_3
       9: iconst_0
      10: istore        4
      12: iload         4
      14: aload_2
      15: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      20: if_icmpge     88
      23: aload_2
      24: iload         4
      26: invokeinterface #27,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      31: istore        5
      33: iload         5
      35: istore        6
      37: iconst_0
      38: istore        7
      40: aload_1
      41: checkcast     #19                 // class java/lang/CharSequence
      44: iload         6
      46: iconst_0
      47: iconst_2
      48: aconst_null
      49: invokestatic  #56                 // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      52: ifne          78
      55: new           #58                 // class java/lang/StringBuilder
      58: dup
      59: invokespecial #62                 // Method java/lang/StringBuilder."<init>":()V
      62: aload_1
      63: invokevirtual #66                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      66: iload         6
      68: invokevirtual #69                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      71: invokevirtual #73                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      74: astore_1
      75: goto          80
      78: aload_1
      79: areturn
      80: nop
      81: nop
      82: iinc          4, 1
      85: goto          12
      88: nop
      89: aload_1
      90: areturn
}


/**
 * Parses the string as an [Int] number and returns the result.
 * See https://leetcode.com/problems/string-to-integer-atoi/
 *
 * @throws NumberFormatException if the string is not a valid representation of a number.
 */
fun atoi(string: String): Int {

    val noWhitespaces = string.trim { it.isWhitespace() }
    if (!isDigit(noWhitespaces[0])) {
        return 0
    }

    val digitsAndNegativeSign = noWhitespaces.trim { char -> !isDigit(char) || char == '+' }

    val isNegative = digitsAndNegativeSign[0] == '-'
    val digits = if (isNegative) {
        digitsAndNegativeSign.removeRange(0, 1)
    } else {
        digitsAndNegativeSign
    }

    var result = 0
    var exponent = 1.0
    var overflow = false

    for (i in digits.length - 1 downTo 0) {

        val digitValue = (charToInt(digits[i]) * exponent).toInt()

        val r = result + digitValue
        // HD 2-12 Overflow if both arguments have the opposite sign of r
        if (result xor r and (digitValue xor r) < 0) {
            overflow = true
            break
        }
        result = r

        exponent *= 10
    }

    result = if (isNegative) -result else result

    return if (overflow) {
        if (result < 0) {
            Int.MIN_VALUE
        } else {
            Int.MAX_VALUE
        }
    } else {
        result
    }
}

private fun isDigit(char: Char) = charToInt(char) >= 0 || char == '-' || char == '+'

private fun charToInt(char: Char): Int {
    return when (char) {
        '0' -> 0
        '1' -> 1
        '2' -> 2
        '3' -> 3
        '4' -> 4
        '5' -> 5
        '6' -> 6
        '7' -> 7
        '8' -> 8
        '9' -> 9
        else -> Int.MIN_VALUE
    }
}

Compiled from "Atoi.kt"
public final class AtoiKt {
  public static final int atoi(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String string
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_2
       8: iconst_0
       9: istore_3
      10: aload_2
      11: checkcast     #17                 // class java/lang/CharSequence
      14: astore        4
      16: iconst_0
      17: istore        5
      19: iconst_0
      20: istore        6
      22: aload         4
      24: invokeinterface #21,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      29: iconst_1
      30: isub
      31: istore        7
      33: iconst_0
      34: istore        8
      36: iload         6
      38: iload         7
      40: if_icmpgt     114
      43: iload         8
      45: ifne          53
      48: iload         6
      50: goto          55
      53: iload         7
      55: istore        9
      57: aload         4
      59: iload         9
      61: invokeinterface #25,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      66: istore        10
      68: iconst_0
      69: istore        11
      71: iload         10
      73: invokestatic  #31                 // Method kotlin/text/CharsKt.isWhitespace:(C)Z
      76: istore        10
      78: iload         8
      80: ifne          100
      83: iload         10
      85: ifne          94
      88: iconst_1
      89: istore        8
      91: goto          36
      94: iinc          6, 1
      97: goto          36
     100: iload         10
     102: ifne          108
     105: goto          114
     108: iinc          7, -1
     111: goto          36
     114: aload         4
     116: iload         6
     118: iload         7
     120: iconst_1
     121: iadd
     122: invokeinterface #35,  3           // InterfaceMethod java/lang/CharSequence.subSequence:(II)Ljava/lang/CharSequence;
     127: invokevirtual #39                 // Method java/lang/Object.toString:()Ljava/lang/String;
     130: astore_1
     131: aload_1
     132: iconst_0
     133: invokevirtual #42                 // Method java/lang/String.charAt:(I)C
     136: invokestatic  #45                 // Method isDigit:(C)Z
     139: ifne          144
     142: iconst_0
     143: ireturn
     144: aload_1
     145: astore_3
     146: iconst_0
     147: istore        4
     149: aload_3
     150: checkcast     #17                 // class java/lang/CharSequence
     153: astore        5
     155: iconst_0
     156: istore        6
     158: iconst_0
     159: istore        7
     161: aload         5
     163: invokeinterface #21,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     168: iconst_1
     169: isub
     170: istore        8
     172: iconst_0
     173: istore        9
     175: iload         7
     177: iload         8
     179: if_icmpgt     268
     182: iload         9
     184: ifne          192
     187: iload         7
     189: goto          194
     192: iload         8
     194: istore        10
     196: aload         5
     198: iload         10
     200: invokeinterface #25,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     205: istore        11
     207: iconst_0
     208: istore        12
     210: iload         11
     212: invokestatic  #45                 // Method isDigit:(C)Z
     215: ifeq          225
     218: iload         11
     220: bipush        43
     222: if_icmpne     229
     225: iconst_1
     226: goto          230
     229: iconst_0
     230: istore        11
     232: iload         9
     234: ifne          254
     237: iload         11
     239: ifne          248
     242: iconst_1
     243: istore        9
     245: goto          175
     248: iinc          7, 1
     251: goto          175
     254: iload         11
     256: ifne          262
     259: goto          268
     262: iinc          8, -1
     265: goto          175
     268: aload         5
     270: iload         7
     272: iload         8
     274: iconst_1
     275: iadd
     276: invokeinterface #35,  3           // InterfaceMethod java/lang/CharSequence.subSequence:(II)Ljava/lang/CharSequence;
     281: invokevirtual #39                 // Method java/lang/Object.toString:()Ljava/lang/String;
     284: astore_2
     285: aload_2
     286: iconst_0
     287: invokevirtual #42                 // Method java/lang/String.charAt:(I)C
     290: bipush        45
     292: if_icmpne     299
     295: iconst_1
     296: goto          300
     299: iconst_0
     300: istore_3
     301: iload_3
     302: ifeq          332
     305: aload_2
     306: astore        5
     308: iconst_0
     309: istore        6
     311: iconst_1
     312: istore        7
     314: aload         5
     316: checkcast     #17                 // class java/lang/CharSequence
     319: iload         6
     321: iload         7
     323: invokestatic  #51                 // Method kotlin/text/StringsKt.removeRange:(Ljava/lang/CharSequence;II)Ljava/lang/CharSequence;
     326: invokevirtual #39                 // Method java/lang/Object.toString:()Ljava/lang/String;
     329: goto          333
     332: aload_2
     333: astore        4
     335: iconst_0
     336: istore        5
     338: dconst_1
     339: dstore        6
     341: iconst_0
     342: istore        8
     344: aload         4
     346: invokevirtual #52                 // Method java/lang/String.length:()I
     349: iconst_1
     350: isub
     351: istore        9
     353: iconst_m1
     354: iload         9
     356: if_icmpge     421
     359: aload         4
     361: iload         9
     363: invokevirtual #42                 // Method java/lang/String.charAt:(I)C
     366: invokestatic  #56                 // Method charToInt:(C)I
     369: i2d
     370: dload         6
     372: dmul
     373: d2i
     374: istore        10
     376: iload         5
     378: iload         10
     380: iadd
     381: istore        11
     383: iload         5
     385: iload         11
     387: ixor
     388: iload         10
     390: iload         11
     392: ixor
     393: iand
     394: ifge          403
     397: iconst_1
     398: istore        8
     400: goto          421
     403: iload         11
     405: istore        5
     407: dload         6
     409: bipush        10
     411: i2d
     412: dmul
     413: dstore        6
     415: iinc          9, -1
     418: goto          353
     421: iload_3
     422: ifeq          431
     425: iload         5
     427: ineg
     428: goto          433
     431: iload         5
     433: istore        5
     435: iload         8
     437: ifeq          455
     440: iload         5
     442: ifge          450
     445: ldc           #57                 // int -2147483648
     447: goto          457
     450: ldc           #58                 // int 2147483647
     452: goto          457
     455: iload         5
     457: ireturn

  private static final boolean isDigit(char);
    Code:
       0: iload_0
       1: invokestatic  #56                 // Method charToInt:(C)I
       4: ifge          19
       7: iload_0
       8: bipush        45
      10: if_icmpeq     19
      13: iload_0
      14: bipush        43
      16: if_icmpne     23
      19: iconst_1
      20: goto          24
      23: iconst_0
      24: ireturn

  private static final int charToInt(char);
    Code:
       0: iload_0
       1: tableswitch   { // 48 to 57
                    48: 56
                    49: 60
                    50: 64
                    51: 68
                    52: 72
                    53: 76
                    54: 80
                    55: 85
                    56: 90
                    57: 95
               default: 100
          }
      56: iconst_0
      57: goto          102
      60: iconst_1
      61: goto          102
      64: iconst_2
      65: goto          102
      68: iconst_3
      69: goto          102
      72: iconst_4
      73: goto          102
      76: iconst_5
      77: goto          102
      80: bipush        6
      82: goto          102
      85: bipush        7
      87: goto          102
      90: bipush        8
      92: goto          102
      95: bipush        9
      97: goto          102
     100: ldc           #57                 // int -2147483648
     102: ireturn
}