package other

import java.math.BigInteger

/**
 *
 * This algorithm is taken from Google Guava library
 *
 */

class FactorialAdvanced {

    // precomputed factorials
    private val factorials = longArrayOf(
        1L,
        1L,
        1L * 2,
        1L * 2 * 3,
        1L * 2 * 3 * 4,
        1L * 2 * 3 * 4 * 5,
        1L * 2 * 3 * 4 * 5 * 6,
        1L * 2 * 3 * 4 * 5 * 6 * 7,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19,
        1L * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * 10 * 11 * 12 * 13 * 14 * 15 * 16 * 17 * 18 * 19 * 20
    )

    fun compute(n: Int): BigInteger {
        if (n <= 0) {
            return BigInteger.ZERO
        }

        if (n < factorials.size) {
            return BigInteger.valueOf(factorials[n])
        }

        // pre-allocate space for our list of intermediate BigIntegers.
        val approxSize = divide(n * log2Celling(n), Long.SIZE_BITS)
        val bigNumbers = ArrayList<BigInteger>(approxSize)

        // start from the pre-computed maximum long factorial.
        val startingNumber = factorials.size
        var number = factorials[startingNumber - 1]
        // strip off 2s from this value.
        var shift = number.countTrailingZeroBits()
        number = number shr shift

        // use floor(log2(num)) + 1 to prevent overflow of multiplication.
        var numberBits = log2Floor(number) + 1
        var bits = log2Floor(startingNumber.toLong()) + 1
        // check for the next power of two boundary, to save us a CLZ operation.
        var nextPowerOfTwo = 1 shl bits - 1

        // iteratively multiply the longs as big as they can go.
        for (num in startingNumber..n) {
            // check to see if the floor(log2(num)) + 1 has changed.
            if ((num and nextPowerOfTwo) != 0) {
                nextPowerOfTwo = nextPowerOfTwo shl 1
                bits++
            }
            // get rid of the 2s in num.
            val tz = num.toLong().countTrailingZeroBits()
            val normalizedNum = (num shr tz).toLong()
            shift += tz
            // adjust floor(log2(num)) + 1.
            val normalizedBits = bits - tz
            // if it won't fit in a long, then we store off the intermediate product.
            if (normalizedBits + numberBits >= Long.SIZE_BITS) {
                bigNumbers.add(BigInteger.valueOf(number))
                number = 1
                numberBits = 0
            }
            number *= normalizedNum
            numberBits = log2Floor(number) + 1
        }
        // check for leftovers.
        if (number > 1) {
            bigNumbers.add(BigInteger.valueOf(number))
        }
        // efficiently multiply all the intermediate products together.
        return listNumbers(bigNumbers).shiftLeft(shift)
    }

    /**
     * Returns the result of dividing p by q, rounding using the celling
     *
     * @throws ArithmeticException if q == 0
     */
    private fun divide(number: Int, divider: Int): Int {
        if (divider == 0) {
            throw ArithmeticException("/ by zero") // for GWT
        }
        val div = number / divider
        val rem = number - divider * div // equal to number % divider
        if (rem == 0) {
            return div
        }
        val signedNumber = 1 or (number xor divider shr Int.SIZE_BITS - 1)
        val increment = signedNumber > 0
        return if (increment) div + signedNumber else div
    }

    private fun listNumbers(numbers: List<BigInteger>, start: Int = 0, end: Int = numbers.size): BigInteger {
        return when (end - start) {
            0 -> BigInteger.ONE
            1 -> numbers[start]
            2 -> numbers[start].multiply(numbers[start + 1])
            3 -> numbers[start].multiply(numbers[start + 1]).multiply(numbers[start + 2])
            else -> {
                // otherwise, split the list in half and recursively do this.
                val m = end + start ushr 1
                listNumbers(numbers, start, m).multiply(listNumbers(numbers, m, end))
            }
        }
    }

    // returns the base-2 logarithm of number, rounded according to the celling.
    private fun log2Celling(number: Int): Int {
        return Int.SIZE_BITS - (number - 1).countLeadingZeroBits()
    }

    // returns the base-2 logarithm of number rounded according to the floor.
    private fun log2Floor(number: Long): Int {
        return Long.SIZE_BITS - 1 - number.countLeadingZeroBits()
    }

}

Compiled from "FactorialAdvanced.kt"
public final class other.FactorialAdvanced {
  private final long[] factorials;

  public other.FactorialAdvanced();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: bipush        21
       7: newarray       long
       9: astore_1
      10: aload_1
      11: iconst_0
      12: lconst_1
      13: lastore
      14: aload_1
      15: iconst_1
      16: lconst_1
      17: lastore
      18: aload_1
      19: iconst_2
      20: ldc2_w        #9                  // long 2l
      23: lastore
      24: aload_1
      25: iconst_3
      26: ldc2_w        #11                 // long 6l
      29: lastore
      30: aload_1
      31: iconst_4
      32: ldc2_w        #13                 // long 24l
      35: lastore
      36: aload_1
      37: iconst_5
      38: ldc2_w        #15                 // long 120l
      41: lastore
      42: aload_1
      43: bipush        6
      45: ldc2_w        #17                 // long 720l
      48: lastore
      49: aload_1
      50: bipush        7
      52: ldc2_w        #19                 // long 5040l
      55: lastore
      56: aload_1
      57: bipush        8
      59: ldc2_w        #21                 // long 40320l
      62: lastore
      63: aload_1
      64: bipush        9
      66: ldc2_w        #23                 // long 362880l
      69: lastore
      70: aload_1
      71: bipush        10
      73: ldc2_w        #25                 // long 3628800l
      76: lastore
      77: aload_1
      78: bipush        11
      80: ldc2_w        #27                 // long 39916800l
      83: lastore
      84: aload_1
      85: bipush        12
      87: ldc2_w        #29                 // long 479001600l
      90: lastore
      91: aload_1
      92: bipush        13
      94: ldc2_w        #31                 // long 6227020800l
      97: lastore
      98: aload_1
      99: bipush        14
     101: ldc2_w        #33                 // long 87178291200l
     104: lastore
     105: aload_1
     106: bipush        15
     108: ldc2_w        #35                 // long 1307674368000l
     111: lastore
     112: aload_1
     113: bipush        16
     115: ldc2_w        #37                 // long 20922789888000l
     118: lastore
     119: aload_1
     120: bipush        17
     122: ldc2_w        #39                 // long 355687428096000l
     125: lastore
     126: aload_1
     127: bipush        18
     129: ldc2_w        #41                 // long 6402373705728000l
     132: lastore
     133: aload_1
     134: bipush        19
     136: ldc2_w        #43                 // long 121645100408832000l
     139: lastore
     140: aload_1
     141: bipush        20
     143: ldc2_w        #45                 // long 2432902008176640000l
     146: lastore
     147: aload_1
     148: putfield      #50                 // Field factorials:[J
     151: return

  public final java.math.BigInteger compute(int);
    Code:
       0: iload_1
       1: ifgt          14
       4: getstatic     #61                 // Field java/math/BigInteger.ZERO:Ljava/math/BigInteger;
       7: dup
       8: ldc           #62                 // String ZERO
      10: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      13: areturn
      14: iload_1
      15: aload_0
      16: getfield      #50                 // Field factorials:[J
      19: arraylength
      20: if_icmpge     39
      23: aload_0
      24: getfield      #50                 // Field factorials:[J
      27: iload_1
      28: laload
      29: invokestatic  #72                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      32: dup
      33: ldc           #74                 // String valueOf(...)
      35: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      38: areturn
      39: aload_0
      40: iload_1
      41: aload_0
      42: iload_1
      43: invokespecial #78                 // Method log2Celling:(I)I
      46: imul
      47: bipush        64
      49: invokespecial #82                 // Method divide:(II)I
      52: istore_2
      53: new           #84                 // class java/util/ArrayList
      56: dup
      57: iload_2
      58: invokespecial #87                 // Method java/util/ArrayList."<init>":(I)V
      61: astore_3
      62: aload_0
      63: getfield      #50                 // Field factorials:[J
      66: arraylength
      67: istore        4
      69: aload_0
      70: getfield      #50                 // Field factorials:[J
      73: iload         4
      75: iconst_1
      76: isub
      77: laload
      78: lstore        5
      80: lload         5
      82: invokestatic  #93                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
      85: istore        7
      87: lload         5
      89: iload         7
      91: lshr
      92: lstore        5
      94: aload_0
      95: lload         5
      97: invokespecial #96                 // Method log2Floor:(J)I
     100: iconst_1
     101: iadd
     102: istore        8
     104: aload_0
     105: iload         4
     107: i2l
     108: invokespecial #96                 // Method log2Floor:(J)I
     111: iconst_1
     112: iadd
     113: istore        9
     115: iconst_1
     116: iload         9
     118: iconst_1
     119: isub
     120: ishl
     121: istore        10
     123: iload         4
     125: istore        11
     127: iload         11
     129: iload_1
     130: if_icmpgt     235
     133: iload         11
     135: iload         10
     137: iand
     138: ifeq          150
     141: iload         10
     143: iconst_1
     144: ishl
     145: istore        10
     147: iinc          9, 1
     150: iload         11
     152: i2l
     153: invokestatic  #93                 // Method java/lang/Long.numberOfTrailingZeros:(J)I
     156: istore        12
     158: iload         11
     160: iload         12
     162: ishr
     163: i2l
     164: lstore        13
     166: iload         7
     168: iload         12
     170: iadd
     171: istore        7
     173: iload         9
     175: iload         12
     177: isub
     178: istore        15
     180: iload         15
     182: iload         8
     184: iadd
     185: bipush        64
     187: if_icmplt     206
     190: aload_3
     191: lload         5
     193: invokestatic  #72                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     196: invokevirtual #100                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     199: pop
     200: lconst_1
     201: lstore        5
     203: iconst_0
     204: istore        8
     206: lload         5
     208: lload         13
     210: lmul
     211: lstore        5
     213: aload_0
     214: lload         5
     216: invokespecial #96                 // Method log2Floor:(J)I
     219: iconst_1
     220: iadd
     221: istore        8
     223: iload         11
     225: iload_1
     226: if_icmpeq     235
     229: iinc          11, 1
     232: goto          133
     235: lload         5
     237: lconst_1
     238: lcmp
     239: ifle          252
     242: aload_3
     243: lload         5
     245: invokestatic  #72                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     248: invokevirtual #100                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     251: pop
     252: aload_0
     253: aload_3
     254: checkcast     #102                // class java/util/List
     257: iconst_0
     258: iconst_0
     259: bipush        6
     261: aconst_null
     262: invokestatic  #106                // Method listNumbers$default:(Lother/FactorialAdvanced;Ljava/util/List;IIILjava/lang/Object;)Ljava/math/BigInteger;
     265: iload         7
     267: invokevirtual #109                // Method java/math/BigInteger.shiftLeft:(I)Ljava/math/BigInteger;
     270: dup
     271: ldc           #111                // String shiftLeft(...)
     273: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     276: areturn

  private final int divide(int, int);
    Code:
       0: iload_2
       1: ifne          14
       4: new           #129                // class java/lang/ArithmeticException
       7: dup
       8: ldc           #131                // String / by zero
      10: invokespecial #134                // Method java/lang/ArithmeticException."<init>":(Ljava/lang/String;)V
      13: athrow
      14: iload_1
      15: iload_2
      16: idiv
      17: istore_3
      18: iload_1
      19: iload_2
      20: iload_3
      21: imul
      22: isub
      23: istore        4
      25: iload         4
      27: ifne          32
      30: iload_3
      31: ireturn
      32: iconst_1
      33: iload_1
      34: iload_2
      35: ixor
      36: bipush        31
      38: ishr
      39: ior
      40: istore        5
      42: iload         5
      44: ifle          51
      47: iconst_1
      48: goto          52
      51: iconst_0
      52: istore        6
      54: iload         6
      56: ifeq          66
      59: iload_3
      60: iload         5
      62: iadd
      63: goto          67
      66: iload_3
      67: ireturn

  private final java.math.BigInteger listNumbers(java.util.List<? extends java.math.BigInteger>, int, int);
    Code:
       0: iload_3
       1: iload_2
       2: isub
       3: tableswitch   { // 0 to 3
                     0: 32
                     1: 44
                     2: 57
                     3: 91
               default: 140
          }
      32: getstatic     #146                // Field java/math/BigInteger.ONE:Ljava/math/BigInteger;
      35: dup
      36: ldc           #147                // String ONE
      38: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      41: goto          175
      44: aload_1
      45: iload_2
      46: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      51: checkcast     #57                 // class java/math/BigInteger
      54: goto          175
      57: aload_1
      58: iload_2
      59: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      64: checkcast     #57                 // class java/math/BigInteger
      67: aload_1
      68: iload_2
      69: iconst_1
      70: iadd
      71: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      76: checkcast     #57                 // class java/math/BigInteger
      79: invokevirtual #155                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      82: dup
      83: ldc           #157                // String multiply(...)
      85: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      88: goto          175
      91: aload_1
      92: iload_2
      93: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      98: checkcast     #57                 // class java/math/BigInteger
     101: aload_1
     102: iload_2
     103: iconst_1
     104: iadd
     105: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: checkcast     #57                 // class java/math/BigInteger
     113: invokevirtual #155                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     116: aload_1
     117: iload_2
     118: iconst_2
     119: iadd
     120: invokeinterface #151,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #57                 // class java/math/BigInteger
     128: invokevirtual #155                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     131: dup
     132: ldc           #157                // String multiply(...)
     134: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     137: goto          175
     140: iload_3
     141: iload_2
     142: iadd
     143: iconst_1
     144: iushr
     145: istore        5
     147: aload_0
     148: aload_1
     149: iload_2
     150: iload         5
     152: invokespecial #159                // Method listNumbers:(Ljava/util/List;II)Ljava/math/BigInteger;
     155: aload_0
     156: aload_1
     157: iload         5
     159: iload_3
     160: invokespecial #159                // Method listNumbers:(Ljava/util/List;II)Ljava/math/BigInteger;
     163: invokevirtual #155                // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     166: astore        4
     168: aload         4
     170: invokestatic  #163                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     173: aload         4
     175: areturn

  static java.math.BigInteger listNumbers$default(other.FactorialAdvanced, java.util.List, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_2
       3: iand
       4: ifeq          9
       7: iconst_0
       8: istore_2
       9: iload         4
      11: iconst_4
      12: iand
      13: ifeq          23
      16: aload_1
      17: invokeinterface #172,  1          // InterfaceMethod java/util/List.size:()I
      22: istore_3
      23: aload_0
      24: aload_1
      25: iload_2
      26: iload_3
      27: invokespecial #159                // Method listNumbers:(Ljava/util/List;II)Ljava/math/BigInteger;
      30: areturn

  private final int log2Celling(int);
    Code:
       0: bipush        32
       2: iload_1
       3: iconst_1
       4: isub
       5: invokestatic  #177                // Method java/lang/Integer.numberOfLeadingZeros:(I)I
       8: isub
       9: ireturn

  private final int log2Floor(long);
    Code:
       0: bipush        63
       2: lload_1
       3: invokestatic  #179                // Method java/lang/Long.numberOfLeadingZeros:(J)I
       6: isub
       7: ireturn
}


package dev.akkinoc.atcoder.workspace.kotlin.algo

/**
 * The algorithms for [List].
 */
object ListAlgo {

    /**
     * Generate a sequence of permutations.
     *
     * @receiver The source elements.
     * @param T The element type.
     * @param r The number of elements to select.
     * @return A sequence of permutations.
     */
    fun <T> List<T>.perm(r: Int): Sequence<List<T>> {
        val i = IntArray(size) { it }
        val c = IntArray(r) { size - it }
        return generateSequence(List(r) { get(i[it]) }) s@{ _ ->
            val p = (r - 1 downTo 0).find f@{ p ->
                if (--c[p] > 0) return@f true
                i[size - 1] = i[p].also { i.copyInto(i, p, p + 1) }
                c[p] = size - p
                false
            } ?: return@s null
            i[size - c[p]] = i[p].also { i[p] = i[size - c[p]] }
            List(r) { get(i[it]) }
        }
    }

    /**
     * Generate a sequence of repeated permutations.
     *
     * @receiver The source elements.
     * @param T The element type.
     * @param r The number of elements to select.
     * @return A sequence of repeated permutations.
     */
    fun <T> List<T>.rperm(r: Int): Sequence<List<T>> {
        val i = IntArray(r)
        return generateSequence(i.map(::get)) s@{ _ ->
            val p = (r - 1 downTo 0).find { i[it] < size - 1 } ?: return@s null
            ++i[p]
            i.fill(0, p + 1)
            i.map(::get)
        }
    }

    /**
     * Generate a sequence of combinations.
     *
     * @receiver The source elements.
     * @param T The element type.
     * @param r The number of elements to select.
     * @return A sequence of combinations.
     */
    fun <T> List<T>.comb(r: Int): Sequence<List<T>> {
        val i = IntArray(r) { it }
        return generateSequence(i.map(::get)) s@{ _ ->
            var p = (r - 1 downTo 0).find { i[it] < size - r + it } ?: return@s null
            var n = i[p]
            while (p < r) i[p++] = ++n
            i.map(::get)
        }
    }

    /**
     * Generate a sequence of repeated combinations.
     *
     * @receiver The source elements.
     * @param T The element type.
     * @param r The number of elements to select.
     * @return A sequence of repeated combinations.
     */
    fun <T> List<T>.rcomb(r: Int): Sequence<List<T>> {
        val i = IntArray(r)
        return generateSequence(i.map(::get)) s@{ _ ->
            val p = (r - 1 downTo 0).find { i[it] < size - 1 } ?: return@s null
            i.fill(i[p] + 1, p)
            i.map(::get)
        }
    }

}

Compiled from "ListAlgo.kt"
public final class dev.akkinoc.atcoder.workspace.kotlin.algo.ListAlgo {
  public static final dev.akkinoc.atcoder.workspace.kotlin.algo.ListAlgo INSTANCE;

  private dev.akkinoc.atcoder.workspace.kotlin.algo.ListAlgo();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final <T> kotlin.sequences.Sequence<java.util.List<T>> perm(java.util.List<? extends T>, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String <this>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: aload_1
      10: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      15: istore        5
      17: iload         5
      19: newarray       int
      21: astore        6
      23: iload         4
      25: iload         5
      27: if_icmpge     47
      30: iload         4
      32: istore        7
      34: aload         6
      36: iload         7
      38: iload         7
      40: iastore
      41: iinc          4, 1
      44: goto          23
      47: aload         6
      49: astore_3
      50: iconst_0
      51: istore        5
      53: iload_2
      54: newarray       int
      56: astore        6
      58: iload         5
      60: iload_2
      61: if_icmpge     88
      64: iload         5
      66: istore        7
      68: aload         6
      70: iload         7
      72: aload_1
      73: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      78: iload         7
      80: isub
      81: iastore
      82: iinc          5, 1
      85: goto          58
      88: aload         6
      90: astore        4
      92: new           #30                 // class java/util/ArrayList
      95: dup
      96: iload_2
      97: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     100: astore        5
     102: iconst_0
     103: istore        6
     105: iload         6
     107: iload_2
     108: if_icmpge     149
     111: iload         6
     113: istore        7
     115: aload         5
     117: iload         7
     119: istore        8
     121: astore        10
     123: iconst_0
     124: istore        9
     126: aload_1
     127: aload_3
     128: iload         8
     130: iaload
     131: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     136: aload         10
     138: swap
     139: invokevirtual #41                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     142: pop
     143: iinc          6, 1
     146: goto          105
     149: aload         5
     151: checkcast     #24                 // class java/util/List
     154: iload_2
     155: aload_3
     156: aload_1
     157: aload         4
     159: invokedynamic #61,  0             // InvokeDynamic #0:invoke:(I[ILjava/util/List;[I)Lkotlin/jvm/functions/Function1;
     164: invokestatic  #67                 // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     167: areturn

  public final <T> kotlin.sequences.Sequence<java.util.List<T>> rperm(java.util.List<? extends T>, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String <this>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_2
       7: newarray       int
       9: astore_3
      10: aload_3
      11: astore        4
      13: iconst_0
      14: istore        5
      16: aload         4
      18: astore        6
      20: new           #30                 // class java/util/ArrayList
      23: dup
      24: aload         4
      26: arraylength
      27: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #80                 // class java/util/Collection
      33: astore        7
      35: iconst_0
      36: istore        8
      38: iconst_0
      39: istore        9
      41: aload         6
      43: arraylength
      44: istore        10
      46: iload         9
      48: iload         10
      50: if_icmpge     94
      53: aload         6
      55: iload         9
      57: iaload
      58: istore        11
      60: aload         7
      62: iload         11
      64: istore        12
      66: astore        14
      68: iconst_0
      69: istore        13
      71: aload_1
      72: iload         12
      74: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      79: aload         14
      81: swap
      82: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: iinc          9, 1
      91: goto          46
      94: aload         7
      96: checkcast     #24                 // class java/util/List
      99: nop
     100: iload_2
     101: aload_3
     102: aload_1
     103: invokedynamic #89,  0             // InvokeDynamic #1:invoke:(I[ILjava/util/List;)Lkotlin/jvm/functions/Function1;
     108: invokestatic  #67                 // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     111: areturn

  public final <T> kotlin.sequences.Sequence<java.util.List<T>> comb(java.util.List<? extends T>, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String <this>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore        4
       9: iload_2
      10: newarray       int
      12: astore        5
      14: iload         4
      16: iload_2
      17: if_icmpge     37
      20: iload         4
      22: istore        6
      24: aload         5
      26: iload         6
      28: iload         6
      30: iastore
      31: iinc          4, 1
      34: goto          14
      37: aload         5
      39: astore_3
      40: aload_3
      41: astore        4
      43: iconst_0
      44: istore        5
      46: aload         4
      48: astore        6
      50: new           #30                 // class java/util/ArrayList
      53: dup
      54: aload         4
      56: arraylength
      57: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      60: checkcast     #80                 // class java/util/Collection
      63: astore        7
      65: iconst_0
      66: istore        8
      68: iconst_0
      69: istore        9
      71: aload         6
      73: arraylength
      74: istore        10
      76: iload         9
      78: iload         10
      80: if_icmpge     124
      83: aload         6
      85: iload         9
      87: iaload
      88: istore        11
      90: aload         7
      92: iload         11
      94: istore        12
      96: astore        14
      98: iconst_0
      99: istore        13
     101: aload_1
     102: iload         12
     104: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     109: aload         14
     111: swap
     112: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     117: pop
     118: iinc          9, 1
     121: goto          76
     124: aload         7
     126: checkcast     #24                 // class java/util/List
     129: nop
     130: iload_2
     131: aload_3
     132: aload_1
     133: invokedynamic #105,  0            // InvokeDynamic #2:invoke:(I[ILjava/util/List;)Lkotlin/jvm/functions/Function1;
     138: invokestatic  #67                 // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     141: areturn

  public final <T> kotlin.sequences.Sequence<java.util.List<T>> rcomb(java.util.List<? extends T>, int);
    Code:
       0: aload_1
       1: ldc           #16                 // String <this>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_2
       7: newarray       int
       9: astore_3
      10: aload_3
      11: astore        4
      13: iconst_0
      14: istore        5
      16: aload         4
      18: astore        6
      20: new           #30                 // class java/util/ArrayList
      23: dup
      24: aload         4
      26: arraylength
      27: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #80                 // class java/util/Collection
      33: astore        7
      35: iconst_0
      36: istore        8
      38: iconst_0
      39: istore        9
      41: aload         6
      43: arraylength
      44: istore        10
      46: iload         9
      48: iload         10
      50: if_icmpge     94
      53: aload         6
      55: iload         9
      57: iaload
      58: istore        11
      60: aload         7
      62: iload         11
      64: istore        12
      66: astore        14
      68: iconst_0
      69: istore        13
      71: aload_1
      72: iload         12
      74: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      79: aload         14
      81: swap
      82: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: iinc          9, 1
      91: goto          46
      94: aload         7
      96: checkcast     #24                 // class java/util/List
      99: nop
     100: iload_2
     101: aload_3
     102: aload_1
     103: invokedynamic #113,  0            // InvokeDynamic #3:invoke:(I[ILjava/util/List;)Lkotlin/jvm/functions/Function1;
     108: invokestatic  #67                 // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     111: areturn

  private static final java.util.List perm$lambda$5(int, int[], java.util.List, int[], java.util.List);
    Code:
       0: aload         4
       2: ldc           #117                // String <unused var>
       4: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: iload_0
       8: iconst_1
       9: isub
      10: iconst_0
      11: invokestatic  #123                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      14: checkcast     #125                // class java/lang/Iterable
      17: astore        8
      19: aload         8
      21: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore        9
      28: aload         9
      30: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          157
      38: aload         9
      40: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        10
      47: aload         10
      49: checkcast     #141                // class java/lang/Number
      52: invokevirtual #144                // Method java/lang/Number.intValue:()I
      55: istore        11
      57: iconst_0
      58: istore        12
      60: aload_3
      61: iload         11
      63: aload_3
      64: iload         11
      66: iaload
      67: iconst_m1
      68: iadd
      69: iastore
      70: aload_3
      71: iload         11
      73: iaload
      74: ifle          81
      77: iconst_1
      78: goto          149
      81: aload_1
      82: aload_2
      83: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      88: iconst_1
      89: isub
      90: aload_1
      91: iload         11
      93: iaload
      94: istore        13
      96: iload         13
      98: istore        14
     100: istore        15
     102: astore        16
     104: iconst_0
     105: istore        17
     107: aload_1
     108: aload_1
     109: iload         11
     111: iload         11
     113: iconst_1
     114: iadd
     115: iconst_0
     116: bipush        8
     118: aconst_null
     119: invokestatic  #150                // Method kotlin/collections/ArraysKt.copyInto$default:([I[IIIIILjava/lang/Object;)[I
     122: pop
     123: getstatic     #156                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     126: astore        18
     128: aload         16
     130: iload         15
     132: iload         13
     134: iastore
     135: aload_3
     136: iload         11
     138: aload_2
     139: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
     144: iload         11
     146: isub
     147: iastore
     148: iconst_0
     149: ifeq          28
     152: aload         10
     154: goto          158
     157: aconst_null
     158: checkcast     #158                // class java/lang/Integer
     161: dup
     162: ifnull        171
     165: invokevirtual #159                // Method java/lang/Integer.intValue:()I
     168: goto          174
     171: pop
     172: aconst_null
     173: areturn
     174: istore        5
     176: aload_1
     177: aload_2
     178: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
     183: aload_3
     184: iload         5
     186: iaload
     187: isub
     188: aload_1
     189: iload         5
     191: iaload
     192: istore        6
     194: iload         6
     196: istore        7
     198: istore        20
     200: astore        19
     202: iconst_0
     203: istore        8
     205: aload_1
     206: iload         5
     208: aload_1
     209: aload_2
     210: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
     215: aload_3
     216: iload         5
     218: iaload
     219: isub
     220: iaload
     221: iastore
     222: getstatic     #156                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     225: astore        21
     227: aload         19
     229: iload         20
     231: iload         6
     233: iastore
     234: new           #30                 // class java/util/ArrayList
     237: dup
     238: iload_0
     239: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     242: astore        6
     244: iconst_0
     245: istore        7
     247: iload         7
     249: iload_0
     250: if_icmpge     291
     253: iload         7
     255: istore        8
     257: aload         6
     259: iload         8
     261: istore        9
     263: astore        19
     265: iconst_0
     266: istore        10
     268: aload_2
     269: aload_1
     270: iload         9
     272: iaload
     273: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     278: aload         19
     280: swap
     281: invokevirtual #41                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     284: pop
     285: iinc          7, 1
     288: goto          247
     291: aload         6
     293: checkcast     #24                 // class java/util/List
     296: areturn

  private static final java.util.List rperm$lambda$8(int, int[], java.util.List, java.util.List);
    Code:
       0: aload_3
       1: ldc           #117                // String <unused var>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: iconst_1
       8: isub
       9: iconst_0
      10: invokestatic  #123                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      13: checkcast     #125                // class java/lang/Iterable
      16: astore        7
      18: aload         7
      20: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      25: astore        8
      27: aload         8
      29: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          87
      37: aload         8
      39: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: astore        9
      46: aload         9
      48: checkcast     #141                // class java/lang/Number
      51: invokevirtual #144                // Method java/lang/Number.intValue:()I
      54: istore        10
      56: iconst_0
      57: istore        11
      59: aload_1
      60: iload         10
      62: iaload
      63: aload_2
      64: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      69: iconst_1
      70: isub
      71: if_icmpge     78
      74: iconst_1
      75: goto          79
      78: iconst_0
      79: ifeq          27
      82: aload         9
      84: goto          88
      87: aconst_null
      88: checkcast     #158                // class java/lang/Integer
      91: dup
      92: ifnull        101
      95: invokevirtual #159                // Method java/lang/Integer.intValue:()I
      98: goto          104
     101: pop
     102: aconst_null
     103: areturn
     104: istore        4
     106: aload_1
     107: iload         4
     109: aload_1
     110: iload         4
     112: iaload
     113: iconst_1
     114: iadd
     115: iastore
     116: aload_1
     117: iload         4
     119: iaload
     120: pop
     121: aload_1
     122: iconst_0
     123: iload         4
     125: iconst_1
     126: iadd
     127: iconst_0
     128: iconst_4
     129: aconst_null
     130: invokestatic  #172                // Method kotlin/collections/ArraysKt.fill$default:([IIIIILjava/lang/Object;)V
     133: aload_1
     134: astore        5
     136: iconst_0
     137: istore        6
     139: aload         5
     141: astore        7
     143: new           #30                 // class java/util/ArrayList
     146: dup
     147: aload         5
     149: arraylength
     150: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #80                 // class java/util/Collection
     156: astore        8
     158: iconst_0
     159: istore        9
     161: iconst_0
     162: istore        10
     164: aload         7
     166: arraylength
     167: istore        11
     169: iload         10
     171: iload         11
     173: if_icmpge     217
     176: aload         7
     178: iload         10
     180: iaload
     181: istore        12
     183: aload         8
     185: iload         12
     187: istore        13
     189: astore        15
     191: iconst_0
     192: istore        14
     194: aload_2
     195: iload         13
     197: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     202: aload         15
     204: swap
     205: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     210: pop
     211: iinc          10, 1
     214: goto          169
     217: aload         8
     219: checkcast     #24                 // class java/util/List
     222: nop
     223: areturn

  private static final java.util.List comb$lambda$12(int, int[], java.util.List, java.util.List);
    Code:
       0: aload_3
       1: ldc           #117                // String <unused var>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: iconst_1
       8: isub
       9: iconst_0
      10: invokestatic  #123                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      13: checkcast     #125                // class java/lang/Iterable
      16: astore        7
      18: aload         7
      20: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      25: astore        8
      27: aload         8
      29: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          90
      37: aload         8
      39: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: astore        9
      46: aload         9
      48: checkcast     #141                // class java/lang/Number
      51: invokevirtual #144                // Method java/lang/Number.intValue:()I
      54: istore        10
      56: iconst_0
      57: istore        11
      59: aload_1
      60: iload         10
      62: iaload
      63: aload_2
      64: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      69: iload_0
      70: isub
      71: iload         10
      73: iadd
      74: if_icmpge     81
      77: iconst_1
      78: goto          82
      81: iconst_0
      82: ifeq          27
      85: aload         9
      87: goto          91
      90: aconst_null
      91: checkcast     #158                // class java/lang/Integer
      94: dup
      95: ifnull        104
      98: invokevirtual #159                // Method java/lang/Integer.intValue:()I
     101: goto          107
     104: pop
     105: aconst_null
     106: areturn
     107: istore        4
     109: aload_1
     110: iload         4
     112: iaload
     113: istore        5
     115: iload         4
     117: iload_0
     118: if_icmpge     136
     121: aload_1
     122: iload         4
     124: iinc          4, 1
     127: iinc          5, 1
     130: iload         5
     132: iastore
     133: goto          115
     136: aload_1
     137: astore        6
     139: iconst_0
     140: istore        7
     142: aload         6
     144: astore        8
     146: new           #30                 // class java/util/ArrayList
     149: dup
     150: aload         6
     152: arraylength
     153: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     156: checkcast     #80                 // class java/util/Collection
     159: astore        9
     161: iconst_0
     162: istore        10
     164: iconst_0
     165: istore        11
     167: aload         8
     169: arraylength
     170: istore        12
     172: iload         11
     174: iload         12
     176: if_icmpge     220
     179: aload         8
     181: iload         11
     183: iaload
     184: istore        13
     186: aload         9
     188: iload         13
     190: istore        14
     192: astore        16
     194: iconst_0
     195: istore        15
     197: aload_2
     198: iload         14
     200: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     205: aload         16
     207: swap
     208: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     213: pop
     214: iinc          11, 1
     217: goto          172
     220: aload         9
     222: checkcast     #24                 // class java/util/List
     225: nop
     226: areturn

  private static final java.util.List rcomb$lambda$16(int, int[], java.util.List, java.util.List);
    Code:
       0: aload_3
       1: ldc           #117                // String <unused var>
       3: invokestatic  #22                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: iconst_1
       8: isub
       9: iconst_0
      10: invokestatic  #123                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      13: checkcast     #125                // class java/lang/Iterable
      16: astore        7
      18: aload         7
      20: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      25: astore        8
      27: aload         8
      29: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          87
      37: aload         8
      39: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      44: astore        9
      46: aload         9
      48: checkcast     #141                // class java/lang/Number
      51: invokevirtual #144                // Method java/lang/Number.intValue:()I
      54: istore        10
      56: iconst_0
      57: istore        11
      59: aload_1
      60: iload         10
      62: iaload
      63: aload_2
      64: invokeinterface #28,  1           // InterfaceMethod java/util/List.size:()I
      69: iconst_1
      70: isub
      71: if_icmpge     78
      74: iconst_1
      75: goto          79
      78: iconst_0
      79: ifeq          27
      82: aload         9
      84: goto          88
      87: aconst_null
      88: checkcast     #158                // class java/lang/Integer
      91: dup
      92: ifnull        101
      95: invokevirtual #159                // Method java/lang/Integer.intValue:()I
      98: goto          104
     101: pop
     102: aconst_null
     103: areturn
     104: istore        4
     106: aload_1
     107: aload_1
     108: iload         4
     110: iaload
     111: iconst_1
     112: iadd
     113: iload         4
     115: iconst_0
     116: iconst_4
     117: aconst_null
     118: invokestatic  #172                // Method kotlin/collections/ArraysKt.fill$default:([IIIIILjava/lang/Object;)V
     121: aload_1
     122: astore        5
     124: iconst_0
     125: istore        6
     127: aload         5
     129: astore        7
     131: new           #30                 // class java/util/ArrayList
     134: dup
     135: aload         5
     137: arraylength
     138: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     141: checkcast     #80                 // class java/util/Collection
     144: astore        8
     146: iconst_0
     147: istore        9
     149: iconst_0
     150: istore        10
     152: aload         7
     154: arraylength
     155: istore        11
     157: iload         10
     159: iload         11
     161: if_icmpge     205
     164: aload         7
     166: iload         10
     168: iaload
     169: istore        12
     171: aload         8
     173: iload         12
     175: istore        13
     177: astore        15
     179: iconst_0
     180: istore        14
     182: aload_2
     183: iload         13
     185: invokeinterface #37,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     190: aload         15
     192: swap
     193: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     198: pop
     199: iinc          10, 1
     202: goto          157
     205: aload         8
     207: checkcast     #24                 // class java/util/List
     210: nop
     211: areturn

  static {};
    Code:
       0: new           #2                  // class dev/akkinoc/atcoder/workspace/kotlin/algo/ListAlgo
       3: dup
       4: invokespecial #184                // Method "<init>":()V
       7: putstatic     #186                // Field INSTANCE:Ldev/akkinoc/atcoder/workspace/kotlin/algo/ListAlgo;
      10: return
}


package day07

import java.io.File

fun main() {
    val file = File("src/main/resources/day07-cards").readLines()
    file
        .map { line ->
            val (cards, bid) = line.split(" ")
            Hand(cards.trim(), bid.trim().toInt())
        }
        .sorted()
        .mapIndexed { order, hand -> (order + 1) * hand.bid }
        .sum()
        .let { println("Total: $it") }

    file
        .map { line ->
            val (cards, bid) = line.split(" ")
            HandWithJokers(cards.trim(), bid.trim().toInt())
        }
        .sorted()
        .mapIndexed { order, hand -> (order + 1) * hand.bid }
        .sum()
        .let { println("Total with Js: $it") }
}

data class Hand(val cards: String, val bid: Int) : Comparable<Hand> {
    private val suits = mutableMapOf<Char, Int>()

    init {
        cards.forEach { suits[it] = suits.getOrDefault(it, 0) + 1 }
    }

    private fun handValue() = when {
        suits.values.contains(5) -> 10
        suits.values.contains(4) -> 9
        suits.values.contains(3) && suits.values.contains(2) -> 8
        suits.values.contains(3) -> 7
        suits.values.filter { it == 2 }.size == 2 -> 6
        suits.values.contains(2) -> 5
        else -> 0
    }

    private fun suitValue(suit: Char) = when (suit) {
        'A' -> 14
        'K' -> 13
        'Q' -> 12
        'J' -> 11
        'T' -> 10
        else -> suit.digitToInt()
    }

    override fun compareTo(other: Hand) = when {
        this.handValue() < other.handValue() -> -1
        this.handValue() > other.handValue() -> 1
        else -> {
            cards.indices.first { index -> cards[index] != other.cards[index] }.let {
                suitValue(cards[it]).compareTo(suitValue(other.cards[it]))
            }
        }
    }
}

data class HandWithJokers(val cards: String, val bid: Int) : Comparable<HandWithJokers> {
    val suits = mutableMapOf<Char, Int>()

    init {
        cards.forEach { suits[it] = suits.getOrDefault(it, 0) + 1 }
        if (suits.contains('J') && !suits.values.contains(5)) {
            val noJokes = suits.filterKeys { it != 'J' }
            val bestCard = noJokes
                .filter { it.value == noJokes.maxOf { it.value } }
                .maxBy { suitValue(it.key) }.key
            suits[bestCard] = suits[bestCard]!! + suits['J']!!
            suits.remove('J')
        }
    }

    private fun handValue() = when {
        suits.values.contains(5) -> 10
        suits.values.contains(4) -> 9
        suits.values.contains(3) && suits.values.contains(2) -> 8
        suits.values.contains(3) -> 7
        suits.values.filter { it == 2 }.size == 2 -> 6
        suits.values.contains(2) -> 5
        else -> 0
    }

    private fun suitValue(suit: Char) = when (suit) {
        'A' -> 14
        'K' -> 13
        'Q' -> 12
        'J' -> 1
        'T' -> 10
        else -> suit.digitToInt()
    }

    override fun compareTo(other: HandWithJokers) = when {
        this.handValue() < other.handValue() -> -1
        this.handValue() > other.handValue() -> 1
        else -> {
            cards.indices.first { index -> cards[index] != other.cards[index] }.let {
                suitValue(cards[it]).compareTo(suitValue(other.cards[it]))
            }
        }
    }
}

Compiled from "cards.kt"
public final class day07.CardsKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/resources/day07-cards
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: checkcast     #22                 // class java/lang/Iterable
      20: astore_1
      21: nop
      22: iconst_0
      23: istore_2
      24: aload_1
      25: astore_3
      26: new           #24                 // class java/util/ArrayList
      29: dup
      30: aload_1
      31: bipush        10
      33: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      36: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      39: checkcast     #35                 // class java/util/Collection
      42: astore        4
      44: iconst_0
      45: istore        5
      47: aload_3
      48: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        6
      55: aload         6
      57: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          188
      65: aload         6
      67: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        7
      74: aload         4
      76: aload         7
      78: checkcast     #51                 // class java/lang/String
      81: astore        8
      83: astore        13
      85: iconst_0
      86: istore        9
      88: aload         8
      90: checkcast     #53                 // class java/lang/CharSequence
      93: iconst_1
      94: anewarray     #51                 // class java/lang/String
      97: astore        10
      99: aload         10
     101: iconst_0
     102: ldc           #55                 // String
     104: aastore
     105: aload         10
     107: iconst_0
     108: iconst_0
     109: bipush        6
     111: aconst_null
     112: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     115: astore        11
     117: aload         11
     119: iconst_0
     120: invokeinterface #67,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #51                 // class java/lang/String
     128: astore        10
     130: aload         11
     132: iconst_1
     133: invokeinterface #67,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     138: checkcast     #51                 // class java/lang/String
     141: astore        12
     143: new           #69                 // class day07/Hand
     146: dup
     147: aload         10
     149: checkcast     #53                 // class java/lang/CharSequence
     152: invokestatic  #73                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     155: invokevirtual #77                 // Method java/lang/Object.toString:()Ljava/lang/String;
     158: nop
     159: aload         12
     161: checkcast     #53                 // class java/lang/CharSequence
     164: invokestatic  #73                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     167: invokevirtual #77                 // Method java/lang/Object.toString:()Ljava/lang/String;
     170: invokestatic  #83                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     173: invokespecial #86                 // Method day07/Hand."<init>":(Ljava/lang/String;I)V
     176: aload         13
     178: swap
     179: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          55
     188: aload         4
     190: checkcast     #63                 // class java/util/List
     193: nop
     194: checkcast     #22                 // class java/lang/Iterable
     197: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     200: checkcast     #22                 // class java/lang/Iterable
     203: astore_1
     204: nop
     205: iconst_0
     206: istore_2
     207: aload_1
     208: astore_3
     209: new           #24                 // class java/util/ArrayList
     212: dup
     213: aload_1
     214: bipush        10
     216: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     219: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     222: checkcast     #35                 // class java/util/Collection
     225: astore        4
     227: iconst_0
     228: istore        5
     230: iconst_0
     231: istore        6
     233: aload_3
     234: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     239: astore        7
     241: aload         7
     243: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     248: ifeq          318
     251: aload         7
     253: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     258: astore        8
     260: aload         4
     262: iload         6
     264: iinc          6, 1
     267: istore        9
     269: iload         9
     271: ifge          277
     274: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     277: iload         9
     279: aload         8
     281: checkcast     #69                 // class day07/Hand
     284: astore        10
     286: istore        11
     288: astore        13
     290: iconst_0
     291: istore        12
     293: iload         11
     295: iconst_1
     296: iadd
     297: aload         10
     299: invokevirtual #101                // Method day07/Hand.getBid:()I
     302: imul
     303: invokestatic  #105                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     306: aload         13
     308: swap
     309: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     314: pop
     315: goto          241
     318: aload         4
     320: checkcast     #63                 // class java/util/List
     323: nop
     324: checkcast     #22                 // class java/lang/Iterable
     327: invokestatic  #109                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     330: istore_2
     331: iconst_0
     332: istore_3
     333: new           #111                // class java/lang/StringBuilder
     336: dup
     337: invokespecial #113                // Method java/lang/StringBuilder."<init>":()V
     340: ldc           #115                // String Total:
     342: invokevirtual #119                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     345: iload_2
     346: invokevirtual #122                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     349: invokevirtual #123                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     352: getstatic     #129                // Field java/lang/System.out:Ljava/io/PrintStream;
     355: swap
     356: invokevirtual #135                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     359: nop
     360: nop
     361: aload_0
     362: checkcast     #22                 // class java/lang/Iterable
     365: astore_1
     366: nop
     367: iconst_0
     368: istore_2
     369: aload_1
     370: astore_3
     371: new           #24                 // class java/util/ArrayList
     374: dup
     375: aload_1
     376: bipush        10
     378: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     381: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     384: checkcast     #35                 // class java/util/Collection
     387: astore        4
     389: iconst_0
     390: istore        5
     392: aload_3
     393: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     398: astore        6
     400: aload         6
     402: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     407: ifeq          533
     410: aload         6
     412: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     417: astore        7
     419: aload         4
     421: aload         7
     423: checkcast     #51                 // class java/lang/String
     426: astore        8
     428: astore        13
     430: iconst_0
     431: istore        9
     433: aload         8
     435: checkcast     #53                 // class java/lang/CharSequence
     438: iconst_1
     439: anewarray     #51                 // class java/lang/String
     442: astore        10
     444: aload         10
     446: iconst_0
     447: ldc           #55                 // String
     449: aastore
     450: aload         10
     452: iconst_0
     453: iconst_0
     454: bipush        6
     456: aconst_null
     457: invokestatic  #61                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     460: astore        11
     462: aload         11
     464: iconst_0
     465: invokeinterface #67,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     470: checkcast     #51                 // class java/lang/String
     473: astore        10
     475: aload         11
     477: iconst_1
     478: invokeinterface #67,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     483: checkcast     #51                 // class java/lang/String
     486: astore        12
     488: new           #137                // class day07/HandWithJokers
     491: dup
     492: aload         10
     494: checkcast     #53                 // class java/lang/CharSequence
     497: invokestatic  #73                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     500: invokevirtual #77                 // Method java/lang/Object.toString:()Ljava/lang/String;
     503: nop
     504: aload         12
     506: checkcast     #53                 // class java/lang/CharSequence
     509: invokestatic  #73                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     512: invokevirtual #77                 // Method java/lang/Object.toString:()Ljava/lang/String;
     515: invokestatic  #83                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     518: invokespecial #138                // Method day07/HandWithJokers."<init>":(Ljava/lang/String;I)V
     521: aload         13
     523: swap
     524: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     529: pop
     530: goto          400
     533: aload         4
     535: checkcast     #63                 // class java/util/List
     538: nop
     539: checkcast     #22                 // class java/lang/Iterable
     542: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     545: checkcast     #22                 // class java/lang/Iterable
     548: astore_1
     549: nop
     550: iconst_0
     551: istore_2
     552: aload_1
     553: astore_3
     554: new           #24                 // class java/util/ArrayList
     557: dup
     558: aload_1
     559: bipush        10
     561: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     564: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     567: checkcast     #35                 // class java/util/Collection
     570: astore        4
     572: iconst_0
     573: istore        5
     575: iconst_0
     576: istore        6
     578: aload_3
     579: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     584: astore        7
     586: aload         7
     588: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     593: ifeq          663
     596: aload         7
     598: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     603: astore        8
     605: aload         4
     607: iload         6
     609: iinc          6, 1
     612: istore        9
     614: iload         9
     616: ifge          622
     619: invokestatic  #97                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     622: iload         9
     624: aload         8
     626: checkcast     #137                // class day07/HandWithJokers
     629: astore        10
     631: istore        11
     633: astore        13
     635: iconst_0
     636: istore        12
     638: iload         11
     640: iconst_1
     641: iadd
     642: aload         10
     644: invokevirtual #139                // Method day07/HandWithJokers.getBid:()I
     647: imul
     648: invokestatic  #105                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     651: aload         13
     653: swap
     654: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     659: pop
     660: goto          586
     663: aload         4
     665: checkcast     #63                 // class java/util/List
     668: nop
     669: checkcast     #22                 // class java/lang/Iterable
     672: invokestatic  #109                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     675: istore_2
     676: iconst_0
     677: istore_3
     678: new           #111                // class java/lang/StringBuilder
     681: dup
     682: invokespecial #113                // Method java/lang/StringBuilder."<init>":()V
     685: ldc           #141                // String Total with Js:
     687: invokevirtual #119                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     690: iload_2
     691: invokevirtual #122                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     694: invokevirtual #123                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     697: getstatic     #129                // Field java/lang/System.out:Ljava/io/PrintStream;
     700: swap
     701: invokevirtual #135                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     704: nop
     705: nop
     706: return

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


package day08

import java.io.File

fun main() {
    val file = File("src/main/resources/day08-map").readLines()
    val instructions = file[0]

    val map = file.stream().skip(2).map { line ->
        val (def, dirs) = line.split(" = ")
        val (l, r) = dirs.split(", ")
        def.trim() to Pair(l.removePrefix("("), r.removeSuffix(")"))
    }.toList().toMap()

    fun step(steps: Long, current: String): String {
        val direction = instructions[(steps % instructions.length).toInt()]
        return if (direction == 'L') map[current]!!.first else map[current]!!.second
    }

    var steps = 0L
    var current = "AAA"
    while (current != "ZZZ") {
        current = step(steps++, current)
    }
    println("Steps: $steps")

    val stepsList = map.keys
        .filter { it.endsWith("A") }
        .map {
            steps = 0
            current = it
            while (!current.endsWith("Z")) {
                current = step(steps++, current)
            }
            steps
        }

    val lcm = stepsList.reduce { acc, i -> lcm(acc, i) }
    println("Simultaneous Steps: $lcm")
}

fun lcm(a: Long, b: Long): Long = a * b / gcd(a, b)

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

Compiled from "map.kt"
public final class day08.MapKt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/main/resources/day08-map
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: astore_0
      16: aload_0
      17: iconst_0
      18: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      23: checkcast     #28                 // class java/lang/String
      26: astore_1
      27: aload_0
      28: invokeinterface #32,  1           // InterfaceMethod java/util/List.stream:()Ljava/util/stream/Stream;
      33: ldc2_w        #33                 // long 2l
      36: invokeinterface #40,  3           // InterfaceMethod java/util/stream/Stream.skip:(J)Ljava/util/stream/Stream;
      41: invokedynamic #59,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      46: invokedynamic #70,  0             // InvokeDynamic #1:apply:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/Function;
      51: invokeinterface #74,  2           // InterfaceMethod java/util/stream/Stream.map:(Ljava/util/function/Function;)Ljava/util/stream/Stream;
      56: invokeinterface #78,  1           // InterfaceMethod java/util/stream/Stream.toList:()Ljava/util/List;
      61: astore_3
      62: aload_3
      63: ldc           #80                 // String toList(...)
      65: invokestatic  #86                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      68: aload_3
      69: checkcast     #88                 // class java/lang/Iterable
      72: invokestatic  #94                 // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
      75: astore_2
      76: lconst_0
      77: lstore        18
      79: aconst_null
      80: astore        4
      82: ldc           #96                 // String AAA
      84: astore        4
      86: aload         4
      88: ldc           #98                 // String ZZZ
      90: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      93: ifne          120
      96: aload_1
      97: aload_2
      98: lload         18
     100: lstore        5
     102: lload         5
     104: lconst_1
     105: ladd
     106: lstore        18
     108: lload         5
     110: aload         4
     112: invokestatic  #106                // Method main$step:(Ljava/lang/String;Ljava/util/Map;JLjava/lang/String;)Ljava/lang/String;
     115: astore        4
     117: goto          86
     120: new           #108                // class java/lang/StringBuilder
     123: dup
     124: invokespecial #110                // Method java/lang/StringBuilder."<init>":()V
     127: ldc           #112                // String Steps:
     129: invokevirtual #116                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     132: lload         18
     134: invokevirtual #119                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     137: invokevirtual #123                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     140: getstatic     #129                // Field java/lang/System.out:Ljava/io/PrintStream;
     143: swap
     144: invokevirtual #135                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     147: aload_2
     148: invokeinterface #141,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     153: checkcast     #88                 // class java/lang/Iterable
     156: astore        6
     158: nop
     159: iconst_0
     160: istore        7
     162: aload         6
     164: astore        8
     166: new           #143                // class java/util/ArrayList
     169: dup
     170: invokespecial #144                // Method java/util/ArrayList."<init>":()V
     173: checkcast     #146                // class java/util/Collection
     176: astore        9
     178: iconst_0
     179: istore        10
     181: aload         8
     183: invokeinterface #150,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     188: astore        11
     190: aload         11
     192: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     197: ifeq          245
     200: aload         11
     202: invokeinterface #160,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     207: astore        12
     209: aload         12
     211: checkcast     #28                 // class java/lang/String
     214: astore        13
     216: iconst_0
     217: istore        14
     219: aload         13
     221: ldc           #162                // String A
     223: iconst_0
     224: iconst_2
     225: aconst_null
     226: invokestatic  #168                // Method kotlin/text/StringsKt.endsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     229: ifeq          190
     232: aload         9
     234: aload         12
     236: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     241: pop
     242: goto          190
     245: aload         9
     247: checkcast     #22                 // class java/util/List
     250: nop
     251: checkcast     #88                 // class java/lang/Iterable
     254: astore        6
     256: nop
     257: iconst_0
     258: istore        7
     260: aload         6
     262: astore        8
     264: new           #143                // class java/util/ArrayList
     267: dup
     268: aload         6
     270: bipush        10
     272: invokestatic  #178                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     275: invokespecial #181                // Method java/util/ArrayList."<init>":(I)V
     278: checkcast     #146                // class java/util/Collection
     281: astore        9
     283: iconst_0
     284: istore        10
     286: aload         8
     288: invokeinterface #150,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     293: astore        11
     295: aload         11
     297: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     302: ifeq          389
     305: aload         11
     307: invokeinterface #160,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     312: astore        12
     314: aload         9
     316: aload         12
     318: checkcast     #28                 // class java/lang/String
     321: astore        13
     323: astore        17
     325: iconst_0
     326: istore        14
     328: lconst_0
     329: lstore        18
     331: aload         13
     333: astore        4
     335: aload         4
     337: ldc           #183                // String Z
     339: iconst_0
     340: iconst_2
     341: aconst_null
     342: invokestatic  #168                // Method kotlin/text/StringsKt.endsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
     345: ifne          372
     348: aload_1
     349: aload_2
     350: lload         18
     352: lstore        15
     354: lload         15
     356: lconst_1
     357: ladd
     358: lstore        18
     360: lload         15
     362: aload         4
     364: invokestatic  #106                // Method main$step:(Ljava/lang/String;Ljava/util/Map;JLjava/lang/String;)Ljava/lang/String;
     367: astore        4
     369: goto          335
     372: lload         18
     374: invokestatic  #189                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     377: aload         17
     379: swap
     380: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     385: pop
     386: goto          295
     389: aload         9
     391: checkcast     #22                 // class java/util/List
     394: nop
     395: astore        5
     397: aload         5
     399: checkcast     #88                 // class java/lang/Iterable
     402: astore        8
     404: iconst_0
     405: istore        9
     407: aload         8
     409: invokeinterface #150,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     414: astore        10
     416: aload         10
     418: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     423: ifne          436
     426: new           #191                // class java/lang/UnsupportedOperationException
     429: dup
     430: ldc           #193                // String Empty collection can\'t be reduced.
     432: invokespecial #194                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     435: athrow
     436: aload         10
     438: invokeinterface #160,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     443: astore        11
     445: aload         10
     447: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     452: ifeq          498
     455: aload         11
     457: aload         10
     459: invokeinterface #160,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     464: checkcast     #196                // class java/lang/Number
     467: invokevirtual #200                // Method java/lang/Number.longValue:()J
     470: lstore        12
     472: checkcast     #196                // class java/lang/Number
     475: invokevirtual #200                // Method java/lang/Number.longValue:()J
     478: lstore        14
     480: iconst_0
     481: istore        16
     483: lload         14
     485: lload         12
     487: invokestatic  #204                // Method lcm:(JJ)J
     490: invokestatic  #189                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     493: astore        11
     495: goto          445
     498: aload         11
     500: checkcast     #196                // class java/lang/Number
     503: invokevirtual #200                // Method java/lang/Number.longValue:()J
     506: lstore        6
     508: new           #108                // class java/lang/StringBuilder
     511: dup
     512: invokespecial #110                // Method java/lang/StringBuilder."<init>":()V
     515: ldc           #206                // String Simultaneous Steps:
     517: invokevirtual #116                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     520: lload         6
     522: invokevirtual #119                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     525: invokevirtual #123                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     528: getstatic     #129                // Field java/lang/System.out:Ljava/io/PrintStream;
     531: swap
     532: invokevirtual #135                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     535: return

  public static final long lcm(long, long);
    Code:
       0: lload_0
       1: lload_2
       2: lmul
       3: lload_0
       4: lload_2
       5: invokestatic  #244                // Method gcd:(JJ)J
       8: ldiv
       9: lreturn

  public static final long gcd(long, long);
    Code:
       0: lload_2
       1: lconst_0
       2: lcmp
       3: ifne          10
       6: lload_0
       7: goto          17
      10: lload_2
      11: lload_0
      12: lload_2
      13: lrem
      14: invokestatic  #244                // Method gcd:(JJ)J
      17: lreturn

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

  private static final kotlin.Pair main$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       4: aload_0
       5: checkcast     #256                // class java/lang/CharSequence
       8: iconst_1
       9: anewarray     #28                 // class java/lang/String
      12: astore_2
      13: aload_2
      14: iconst_0
      15: ldc_w         #258                // String  =
      18: aastore
      19: aload_2
      20: iconst_0
      21: iconst_0
      22: bipush        6
      24: aconst_null
      25: invokestatic  #262                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      28: astore_1
      29: aload_1
      30: iconst_0
      31: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      36: checkcast     #28                 // class java/lang/String
      39: astore_2
      40: aload_1
      41: iconst_1
      42: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      47: checkcast     #28                 // class java/lang/String
      50: astore_3
      51: aload_3
      52: checkcast     #256                // class java/lang/CharSequence
      55: iconst_1
      56: anewarray     #28                 // class java/lang/String
      59: astore        5
      61: aload         5
      63: iconst_0
      64: ldc_w         #264                // String ,
      67: aastore
      68: aload         5
      70: iconst_0
      71: iconst_0
      72: bipush        6
      74: aconst_null
      75: invokestatic  #262                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      78: astore        4
      80: aload         4
      82: iconst_0
      83: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #28                 // class java/lang/String
      91: astore        5
      93: aload         4
      95: iconst_1
      96: invokeinterface #26,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     101: checkcast     #28                 // class java/lang/String
     104: astore        6
     106: aload_2
     107: checkcast     #256                // class java/lang/CharSequence
     110: invokestatic  #268                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     113: invokevirtual #269                // Method java/lang/Object.toString:()Ljava/lang/String;
     116: new           #271                // class kotlin/Pair
     119: dup
     120: aload         5
     122: ldc_w         #273                // String (
     125: checkcast     #256                // class java/lang/CharSequence
     128: invokestatic  #277                // Method kotlin/text/StringsKt.removePrefix:(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String;
     131: aload         6
     133: ldc_w         #279                // String )
     136: checkcast     #256                // class java/lang/CharSequence
     139: invokestatic  #282                // Method kotlin/text/StringsKt.removeSuffix:(Ljava/lang/String;Ljava/lang/CharSequence;)Ljava/lang/String;
     142: invokespecial #285                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     145: invokestatic  #291                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     148: areturn

  private static final kotlin.Pair main$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #300,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #271                // class kotlin/Pair
      10: areturn

  private static final java.lang.String main$step(java.lang.String, java.util.Map<java.lang.String, kotlin.Pair<java.lang.String, java.lang.String>>, long, java.lang.String);
    Code:
       0: aload_0
       1: lload_2
       2: aload_0
       3: invokevirtual #308                // Method java/lang/String.length:()I
       6: i2l
       7: lrem
       8: l2i
       9: invokevirtual #312                // Method java/lang/String.charAt:(I)C
      12: istore        5
      14: iload         5
      16: bipush        76
      18: if_icmpne     45
      21: aload_1
      22: aload         4
      24: invokeinterface #314,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      29: dup
      30: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      33: checkcast     #271                // class kotlin/Pair
      36: invokevirtual #317                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      39: checkcast     #28                 // class java/lang/String
      42: goto          66
      45: aload_1
      46: aload         4
      48: invokeinterface #314,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      53: dup
      54: invokestatic  #254                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      57: checkcast     #271                // class kotlin/Pair
      60: invokevirtual #320                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      63: checkcast     #28                 // class java/lang/String
      66: areturn
}