package com.oocode

fun almanacFrom(input: String): Almanac {
    val lines = input.split("\n")
    val seedNumbers = lines[0].split(" ").drop(1).map { it.toLong() }
    val seeds = seedNumbers.chunked(2).map {
        val startNumber = it[0]
        val rangeSize = it[1]
        InputRange(startNumber, (startNumber + rangeSize) - 1)
    }

    val converters = mutableListOf<Converter>()
    var currentMappings = mutableListOf<Mapping>()
    lines.drop(1).forEach { line ->
        if (line.isEmpty()) {
            if (currentMappings.isNotEmpty()) converters.add(Converter(currentMappings))
            currentMappings = mutableListOf()
        } else {
            val numbers = numbersFrom(line)
            if (numbers.isNotEmpty()) {
                currentMappings.add(Mapping(numbers[0], numbers[1], numbers[2]))
            }
        }
    }
    if (currentMappings.isNotEmpty()) converters.add(Converter(currentMappings))

    return Almanac(seeds, ConverterChain(converters))
}

data class InputRange(val startNumber: Long, val endNumber: Long)

private fun numbersFrom(line: String) =
    Regex("(\\d+)")
        .findAll(line)
        .map { it.value.toLong() }
        .toList()

class Almanac(private val seeds: List<InputRange>, private val converterChain: ConverterChain) {
    fun lowestLocationNumber() = seeds.flatMap { converterChain.convert(it) }.map { it.startNumber }.min()
}

data class Mapping(
    private val destinationRangeStart: Long,
    private val sourceRangeStart: Long,
    private val rangeLength: Long,
) {
    val sourceRange = LongRange(sourceRangeStart, sourceRangeStart + rangeLength - 1)

    fun find(sourceNumber: Long) =
        if (sourceRange.contains(sourceNumber))
            destinationRangeStart + (sourceNumber - sourceRangeStart)
        else
            null
}

class Converter(private val mappings: List<Mapping>) {
    fun convert(sourceNumber: Long) = mappings.firstNotNullOfOrNull { it.find(sourceNumber) } ?: sourceNumber

    fun convert(inputRanges: Set<InputRange>): Set<InputRange> = inputRanges.flatMap { convert(it) }.toSet()

    fun convert(inputRange: InputRange): Set<InputRange> {
        val mappingsInOrder = overlappingMappings(inputRange)
        if (mappingsInOrder.isEmpty()) {
            return setOf(inputRange)
        }
        val firstMappingSourceRange = mappingsInOrder[0].sourceRange
        val firstMappingStart = firstMappingSourceRange.start
        if (inputRange.startNumber < firstMappingStart) {
            return setOf(inputRange.copy(endNumber = firstMappingStart - 1)) +
                    convert(inputRange.copy(startNumber = firstMappingStart))
        }
        if (inputRange.endNumber <= firstMappingSourceRange.endInclusive) {
            return mapped(inputRange)
        }
        return mapped(inputRange.copy(endNumber = firstMappingSourceRange.endInclusive)) +
                convert(inputRange.copy(startNumber = firstMappingSourceRange.endInclusive + 1))
    }

    private fun mapped(inputRange: InputRange): Set<InputRange> =
        setOf(InputRange(convert(inputRange.startNumber), convert(inputRange.endNumber)))

    private fun overlappingMappings(inputRange: InputRange) = mappings
        .sortedBy { it.sourceRange.first }
        .filter { it.sourceRange.overlapsWith(inputRange) }
}

private fun LongRange.overlapsWith(inputRange: InputRange) =
    !(inputRange.endNumber < start || inputRange.startNumber > endInclusive)

class ConverterChain(private val converters: List<Converter>) {
    fun convert(sourceNumber: InputRange) =
        converters.fold(setOf(sourceNumber), { accumulator, converter -> converter.convert(accumulator) })
}

Compiled from "Almanac.kt"
public final class com.oocode.AlmanacKt {
  public static final com.oocode.Almanac almanacFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #21                 // String \n
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_1
      30: aload_1
      31: iconst_0
      32: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #17                 // class java/lang/CharSequence
      40: iconst_1
      41: anewarray     #19                 // class java/lang/String
      44: astore_3
      45: aload_3
      46: iconst_0
      47: ldc           #35                 // String
      49: aastore
      50: aload_3
      51: iconst_0
      52: iconst_0
      53: bipush        6
      55: aconst_null
      56: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      59: checkcast     #37                 // class java/lang/Iterable
      62: iconst_1
      63: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      66: checkcast     #37                 // class java/lang/Iterable
      69: astore_3
      70: iconst_0
      71: istore        4
      73: aload_3
      74: astore        5
      76: new           #45                 // class java/util/ArrayList
      79: dup
      80: aload_3
      81: bipush        10
      83: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      86: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
      89: checkcast     #55                 // class java/util/Collection
      92: astore        6
      94: iconst_0
      95: istore        7
      97: aload         5
      99: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     104: astore        8
     106: aload         8
     108: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     113: ifeq          160
     116: aload         8
     118: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     123: astore        9
     125: aload         6
     127: aload         9
     129: checkcast     #19                 // class java/lang/String
     132: astore        10
     134: astore        17
     136: iconst_0
     137: istore        11
     139: aload         10
     141: invokestatic  #75                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     144: nop
     145: invokestatic  #79                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     148: aload         17
     150: swap
     151: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     156: pop
     157: goto          106
     160: aload         6
     162: checkcast     #29                 // class java/util/List
     165: nop
     166: astore_2
     167: aload_2
     168: checkcast     #37                 // class java/lang/Iterable
     171: iconst_2
     172: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
     175: checkcast     #37                 // class java/lang/Iterable
     178: astore        4
     180: iconst_0
     181: istore        5
     183: aload         4
     185: astore        6
     187: new           #45                 // class java/util/ArrayList
     190: dup
     191: aload         4
     193: bipush        10
     195: invokestatic  #49                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     198: invokespecial #53                 // Method java/util/ArrayList."<init>":(I)V
     201: checkcast     #55                 // class java/util/Collection
     204: astore        7
     206: iconst_0
     207: istore        8
     209: aload         6
     211: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     216: astore        9
     218: aload         9
     220: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     225: ifeq          311
     228: aload         9
     230: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     235: astore        10
     237: aload         7
     239: aload         10
     241: checkcast     #29                 // class java/util/List
     244: astore        11
     246: astore        17
     248: iconst_0
     249: istore        12
     251: aload         11
     253: iconst_0
     254: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     259: checkcast     #88                 // class java/lang/Number
     262: invokevirtual #92                 // Method java/lang/Number.longValue:()J
     265: lstore        13
     267: aload         11
     269: iconst_1
     270: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     275: checkcast     #88                 // class java/lang/Number
     278: invokevirtual #92                 // Method java/lang/Number.longValue:()J
     281: lstore        15
     283: new           #94                 // class com/oocode/InputRange
     286: dup
     287: lload         13
     289: lload         13
     291: lload         15
     293: ladd
     294: lconst_1
     295: lsub
     296: invokespecial #97                 // Method com/oocode/InputRange."<init>":(JJ)V
     299: aload         17
     301: swap
     302: invokeinterface #83,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     307: pop
     308: goto          218
     311: aload         7
     313: checkcast     #29                 // class java/util/List
     316: nop
     317: astore_3
     318: new           #45                 // class java/util/ArrayList
     321: dup
     322: invokespecial #100                // Method java/util/ArrayList."<init>":()V
     325: checkcast     #29                 // class java/util/List
     328: astore        4
     330: aconst_null
     331: astore        5
     333: new           #45                 // class java/util/ArrayList
     336: dup
     337: invokespecial #100                // Method java/util/ArrayList."<init>":()V
     340: checkcast     #29                 // class java/util/List
     343: astore        5
     345: aload_1
     346: checkcast     #37                 // class java/lang/Iterable
     349: iconst_1
     350: invokestatic  #43                 // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     353: checkcast     #37                 // class java/lang/Iterable
     356: astore        6
     358: iconst_0
     359: istore        7
     361: aload         6
     363: invokeinterface #59,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     368: astore        8
     370: aload         8
     372: invokeinterface #65,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     377: ifeq          563
     380: aload         8
     382: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     387: astore        9
     389: aload         9
     391: checkcast     #19                 // class java/lang/String
     394: astore        10
     396: iconst_0
     397: istore        11
     399: aload         10
     401: checkcast     #17                 // class java/lang/CharSequence
     404: invokeinterface #104,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     409: ifne          416
     412: iconst_1
     413: goto          417
     416: iconst_0
     417: ifeq          473
     420: aload         5
     422: checkcast     #55                 // class java/util/Collection
     425: invokeinterface #107,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     430: ifne          437
     433: iconst_1
     434: goto          438
     437: iconst_0
     438: ifeq          458
     441: aload         4
     443: new           #109                // class com/oocode/Converter
     446: dup
     447: aload         5
     449: invokespecial #112                // Method com/oocode/Converter."<init>":(Ljava/util/List;)V
     452: invokeinterface #113,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     457: pop
     458: new           #45                 // class java/util/ArrayList
     461: dup
     462: invokespecial #100                // Method java/util/ArrayList."<init>":()V
     465: checkcast     #29                 // class java/util/List
     468: astore        5
     470: goto          558
     473: aload         10
     475: invokestatic  #117                // Method numbersFrom:(Ljava/lang/String;)Ljava/util/List;
     478: astore        12
     480: aload         12
     482: checkcast     #55                 // class java/util/Collection
     485: invokeinterface #107,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     490: ifne          497
     493: iconst_1
     494: goto          498
     497: iconst_0
     498: ifeq          558
     501: aload         5
     503: new           #119                // class com/oocode/Mapping
     506: dup
     507: aload         12
     509: iconst_0
     510: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     515: checkcast     #88                 // class java/lang/Number
     518: invokevirtual #92                 // Method java/lang/Number.longValue:()J
     521: aload         12
     523: iconst_1
     524: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     529: checkcast     #88                 // class java/lang/Number
     532: invokevirtual #92                 // Method java/lang/Number.longValue:()J
     535: aload         12
     537: iconst_2
     538: invokeinterface #33,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     543: checkcast     #88                 // class java/lang/Number
     546: invokevirtual #92                 // Method java/lang/Number.longValue:()J
     549: invokespecial #122                // Method com/oocode/Mapping."<init>":(JJJ)V
     552: invokeinterface #113,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     557: pop
     558: nop
     559: nop
     560: goto          370
     563: nop
     564: aload         5
     566: checkcast     #55                 // class java/util/Collection
     569: invokeinterface #107,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     574: ifne          581
     577: iconst_1
     578: goto          582
     581: iconst_0
     582: ifeq          602
     585: aload         4
     587: new           #109                // class com/oocode/Converter
     590: dup
     591: aload         5
     593: invokespecial #112                // Method com/oocode/Converter."<init>":(Ljava/util/List;)V
     596: invokeinterface #113,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     601: pop
     602: new           #124                // class com/oocode/Almanac
     605: dup
     606: aload_3
     607: new           #126                // class com/oocode/ConverterChain
     610: dup
     611: aload         4
     613: invokespecial #127                // Method com/oocode/ConverterChain."<init>":(Ljava/util/List;)V
     616: invokespecial #130                // Method com/oocode/Almanac."<init>":(Ljava/util/List;Lcom/oocode/ConverterChain;)V
     619: areturn

  private static final java.util.List<java.lang.Long> numbersFrom(java.lang.String);
    Code:
       0: new           #164                // class kotlin/text/Regex
       3: dup
       4: ldc           #166                // String (\\d+)
       6: invokespecial #169                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: aload_0
      10: checkcast     #17                 // class java/lang/CharSequence
      13: iconst_0
      14: iconst_2
      15: aconst_null
      16: invokestatic  #173                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      19: invokedynamic #193,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      24: invokestatic  #199                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      27: invokestatic  #203                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      30: areturn

  private static final boolean overlapsWith(kotlin.ranges.LongRange, com.oocode.InputRange);
    Code:
       0: aload_1
       1: invokevirtual #208                // Method com/oocode/InputRange.getEndNumber:()J
       4: aload_0
       5: invokevirtual #214                // Method kotlin/ranges/LongRange.getStart:()Ljava/lang/Long;
       8: invokevirtual #215                // Method java/lang/Long.longValue:()J
      11: lcmp
      12: iflt          34
      15: aload_1
      16: invokevirtual #218                // Method com/oocode/InputRange.getStartNumber:()J
      19: aload_0
      20: invokevirtual #221                // Method kotlin/ranges/LongRange.getEndInclusive:()Ljava/lang/Long;
      23: invokevirtual #215                // Method java/lang/Long.longValue:()J
      26: lcmp
      27: ifgt          34
      30: iconst_1
      31: goto          35
      34: iconst_0
      35: ireturn

  private static final long numbersFrom$lambda$3(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc           #226                // String it
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #232,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      12: invokestatic  #75                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      15: lreturn

  public static final boolean access$overlapsWith(kotlin.ranges.LongRange, com.oocode.InputRange);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #236                // Method overlapsWith:(Lkotlin/ranges/LongRange;Lcom/oocode/InputRange;)Z
       5: ireturn
}

Compiled from "Almanac.kt"
public final class com.oocode.Almanac {
  private final java.util.List<com.oocode.InputRange> seeds;

  private final com.oocode.ConverterChain converterChain;

  public com.oocode.Almanac(java.util.List<com.oocode.InputRange>, com.oocode.ConverterChain);
    Code:
       0: aload_1
       1: ldc           #10                 // String seeds
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #18                 // String converterChain
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #21                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #24                 // Field seeds:Ljava/util/List;
      21: aload_0
      22: aload_2
      23: putfield      #27                 // Field converterChain:Lcom/oocode/ConverterChain;
      26: return

  public final long lowestLocationNumber();
    Code:
       0: aload_0
       1: getfield      #24                 // Field seeds:Ljava/util/List;
       4: checkcast     #33                 // class java/lang/Iterable
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #35                 // class java/util/ArrayList
      15: dup
      16: invokespecial #36                 // Method java/util/ArrayList."<init>":()V
      19: checkcast     #38                 // class java/util/Collection
      22: astore        4
      24: iconst_0
      25: istore        5
      27: aload_3
      28: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        6
      35: aload         6
      37: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          89
      45: aload         6
      47: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        7
      54: aload         7
      56: checkcast     #54                 // class com/oocode/InputRange
      59: astore        8
      61: iconst_0
      62: istore        9
      64: aload_0
      65: getfield      #27                 // Field converterChain:Lcom/oocode/ConverterChain;
      68: aload         8
      70: invokevirtual #60                 // Method com/oocode/ConverterChain.convert:(Lcom/oocode/InputRange;)Ljava/util/Set;
      73: checkcast     #33                 // class java/lang/Iterable
      76: astore        8
      78: aload         4
      80: aload         8
      82: invokestatic  #66                 // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
      85: pop
      86: goto          35
      89: aload         4
      91: checkcast     #68                 // class java/util/List
      94: nop
      95: checkcast     #33                 // class java/lang/Iterable
      98: astore_1
      99: nop
     100: iconst_0
     101: istore_2
     102: aload_1
     103: astore_3
     104: new           #35                 // class java/util/ArrayList
     107: dup
     108: aload_1
     109: bipush        10
     111: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     114: invokespecial #75                 // Method java/util/ArrayList."<init>":(I)V
     117: checkcast     #38                 // class java/util/Collection
     120: astore        4
     122: iconst_0
     123: istore        5
     125: aload_3
     126: invokeinterface #42,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     131: astore        6
     133: aload         6
     135: invokeinterface #48,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          186
     143: aload         6
     145: invokeinterface #52,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: astore        7
     152: aload         4
     154: aload         7
     156: checkcast     #54                 // class com/oocode/InputRange
     159: astore        8
     161: astore        10
     163: iconst_0
     164: istore        9
     166: aload         8
     168: invokevirtual #78                 // Method com/oocode/InputRange.getStartNumber:()J
     171: invokestatic  #84                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     174: aload         10
     176: swap
     177: invokeinterface #88,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     182: pop
     183: goto          133
     186: aload         4
     188: checkcast     #68                 // class java/util/List
     191: nop
     192: checkcast     #33                 // class java/lang/Iterable
     195: invokestatic  #92                 // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     198: checkcast     #94                 // class java/lang/Number
     201: invokevirtual #97                 // Method java/lang/Number.longValue:()J
     204: lreturn
}


package com.oocode

fun camelCardHandsFrom(input: String): CamelCardHands =
    CamelCardHands(input.split("\n")
        .map { line -> line.split(" ").let { CamelCardHand(it[0]) to it[1].toInt() } })

class CamelCardHands(private val handsWithBids: List<Pair<CamelCardHand, Int>>) {
    fun totalWinnings(): Int {
        val sortedBy = handsWithBids.sortedBy { it.first }
        return sortedBy.foldIndexed(0, { index, accumulator, cardWithBid ->
            accumulator + (cardWithBid.second * (index + 1))
        })
    }
}

data class CamelCardHand(val cards: String) : Comparable<CamelCardHand> {
    enum class Type {
        HIGH_CARD, ONE_PAIR, TWO_PAIR, THREE_OF_A_KIND, FULL_HOUSE, FOUR_OF_A_KIND, FIVE_OF_A_KIND
    }

    private val labels = "AKQT98765432J".reversed()

    override operator fun compareTo(other: CamelCardHand): Int {
        if (this.type() == other.type()) {
            fun makeEasilyComparable(cards: String) =
                cards.map { labels.indexOf(it) }.map { 'a'.plus(it) }.toString()
            return makeEasilyComparable(this.cards).compareTo(makeEasilyComparable(other.cards))
        }
        return this.type().compareTo(other.type())
    }

    private fun type(): Type {
        val cardsWithJSubstituted = cards.replace('J', mostCommonNonJCard())
        val groupsOfSameCards = cardsWithJSubstituted.groupBy { it }
        if (groupsOfSameCards.size == 1)
            return Type.FIVE_OF_A_KIND
        if (groupsOfSameCards.size == 2)
            if (groupsOfSameCards.map { it.value.size }.max() == 4)
                return Type.FOUR_OF_A_KIND
            else
                return Type.FULL_HOUSE
        if (groupsOfSameCards.size == 3)
            if (groupsOfSameCards.map { it.value.size }.max() == 3)
                return Type.THREE_OF_A_KIND
            else
                return Type.TWO_PAIR
        if (groupsOfSameCards.size == 4)
            return Type.ONE_PAIR
        else
            return Type.HIGH_CARD
    }

    private fun mostCommonNonJCard() =
        if(cards == "JJJJJ") // very special case
            'J'
        else
            cards.groupBy { it }
                .filter { it.key != 'J' }
                .map { it.value }
                .sortedBy { it.size }
                .reversed()[0][0] // doesn't matter which one of equal commonality
}

fun camelCardHandFrom(s: String) = CamelCardHand(s)

Compiled from "CamelCards.kt"
public final class com.oocode.CamelCardsKt {
  public static final com.oocode.CamelCardHands camelCardHandsFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #21                 // String \n
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #29                 // class java/lang/Iterable
      32: astore_1
      33: nop
      34: iconst_0
      35: istore_2
      36: aload_1
      37: astore_3
      38: new           #31                 // class java/util/ArrayList
      41: dup
      42: aload_1
      43: bipush        10
      45: invokestatic  #37                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #41                 // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #43                 // class java/util/Collection
      54: astore        4
      56: iconst_0
      57: istore        5
      59: aload_3
      60: invokeinterface #47,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      65: astore        6
      67: aload         6
      69: invokeinterface #53,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      74: ifeq          184
      77: aload         6
      79: invokeinterface #57,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: astore        7
      86: aload         4
      88: aload         7
      90: checkcast     #19                 // class java/lang/String
      93: astore        8
      95: astore        13
      97: iconst_0
      98: istore        9
     100: aload         8
     102: checkcast     #17                 // class java/lang/CharSequence
     105: iconst_1
     106: anewarray     #19                 // class java/lang/String
     109: astore        10
     111: aload         10
     113: iconst_0
     114: ldc           #59                 // String
     116: aastore
     117: aload         10
     119: iconst_0
     120: iconst_0
     121: bipush        6
     123: aconst_null
     124: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     127: astore        11
     129: iconst_0
     130: istore        12
     132: new           #61                 // class com/oocode/CamelCardHand
     135: dup
     136: aload         11
     138: iconst_0
     139: invokeinterface #67,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     144: checkcast     #19                 // class java/lang/String
     147: invokespecial #70                 // Method com/oocode/CamelCardHand."<init>":(Ljava/lang/String;)V
     150: aload         11
     152: iconst_1
     153: invokeinterface #67,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     158: checkcast     #19                 // class java/lang/String
     161: invokestatic  #76                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     164: invokestatic  #80                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     167: invokestatic  #86                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     170: nop
     171: nop
     172: aload         13
     174: swap
     175: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     180: pop
     181: goto          67
     184: aload         4
     186: checkcast     #63                 // class java/util/List
     189: nop
     190: astore        14
     192: new           #92                 // class com/oocode/CamelCardHands
     195: dup
     196: aload         14
     198: invokespecial #95                 // Method com/oocode/CamelCardHands."<init>":(Ljava/util/List;)V
     201: areturn

  public static final com.oocode.CamelCardHand camelCardHandFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #115                // String s
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #61                 // class com/oocode/CamelCardHand
       9: dup
      10: aload_0
      11: invokespecial #70                 // Method com/oocode/CamelCardHand."<init>":(Ljava/lang/String;)V
      14: areturn
}


package com.oocode

fun powerOf(input: String) =
    input.split("\n").sumOf { line -> gameFrom(line).power() }

data class Bag(val red: Int, val green: Int, val blue: Int) {
    fun possibilityTotal(input: String) =
        input.split("\n").sumOf { line -> line.possibilityValue(this) }

    fun power() = red * green * blue
}

private fun String.possibilityValue(bag: Bag) = gameFrom(this).possibilityValue(bag)

data class Game(val number: Int, val reveals: Set<Reveal>) {
    fun possibilityValue(bag: Bag) = if (reveals.all { it.isPossibleGiven(bag) }) number else 0
    fun minimumBag() = reveals.maxBag()
    fun power() = minimumBag().power()
}

private fun Set<Reveal>.maxBag() = Bag(red = maxRed(), green = maxGreen(), blue = maxBlue())
private fun Set<Reveal>.maxRed() = maxOf { it.red }
private fun Set<Reveal>.maxGreen() = maxOf { it.green }
private fun Set<Reveal>.maxBlue() = maxOf { it.blue }

data class Reveal(val red: Int = 0, val green: Int = 0, val blue: Int = 0) {
    fun isPossibleGiven(bag: Bag) = red <= bag.red && green <= bag.green && blue <= bag.blue
}

// "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green"
fun gameFrom(line: String): Game {
    val number = line.split(":")[0].split(" ")[1].toInt()
    val revealStrings = line.split(":")[1].split(";")
    return Game(number, revealStrings.map { revealFrom(it) }.toSet())
}

fun revealFrom(revealString: String): Reveal {
    val colorNumberPairs = revealString.split(",").associate { asColorNumberPair(it.trim()) }
    return Reveal(
        red = colorNumberPairs["red"] ?: 0,
        green = colorNumberPairs["green"] ?: 0,
        blue = colorNumberPairs["blue"] ?: 0,
    )
}

fun asColorNumberPair(colorNumberPairString: String): Pair<String, Int> =
    colorNumberPairString.split(" ")[1] to colorNumberPairString.split(" ")[0].toInt()

Compiled from "Bag.kt"
public final class com.oocode.BagKt {
  public static final int powerOf(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String input
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #21                 // String \n
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #29                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: invokeinterface #33,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore_3
      42: aload_3
      43: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          91
      51: aload_3
      52: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        4
      59: iload_2
      60: aload         4
      62: checkcast     #19                 // class java/lang/String
      65: astore        5
      67: istore        7
      69: iconst_0
      70: istore        6
      72: aload         5
      74: invokestatic  #47                 // Method gameFrom:(Ljava/lang/String;)Lcom/oocode/Game;
      77: invokevirtual #53                 // Method com/oocode/Game.power:()I
      80: istore        8
      82: iload         7
      84: iload         8
      86: iadd
      87: istore_2
      88: goto          42
      91: iload_2
      92: ireturn

  private static final int possibilityValue(java.lang.String, com.oocode.Bag);
    Code:
       0: aload_0
       1: invokestatic  #47                 // Method gameFrom:(Ljava/lang/String;)Lcom/oocode/Game;
       4: aload_1
       5: invokevirtual #62                 // Method com/oocode/Game.possibilityValue:(Lcom/oocode/Bag;)I
       8: ireturn

  private static final com.oocode.Bag maxBag(java.util.Set<com.oocode.Reveal>);
    Code:
       0: new           #70                 // class com/oocode/Bag
       3: dup
       4: aload_0
       5: invokestatic  #74                 // Method maxRed:(Ljava/util/Set;)I
       8: aload_0
       9: invokestatic  #77                 // Method maxGreen:(Ljava/util/Set;)I
      12: aload_0
      13: invokestatic  #80                 // Method maxBlue:(Ljava/util/Set;)I
      16: invokespecial #84                 // Method com/oocode/Bag."<init>":(III)V
      19: areturn

  private static final int maxRed(java.util.Set<com.oocode.Reveal>);
    Code:
       0: aload_0
       1: checkcast     #29                 // class java/lang/Iterable
       4: invokeinterface #33,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: astore_1
      10: aload_1
      11: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      16: ifne          27
      19: new           #89                 // class java/util/NoSuchElementException
      22: dup
      23: invokespecial #92                 // Method java/util/NoSuchElementException."<init>":()V
      26: athrow
      27: aload_1
      28: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #94                 // class com/oocode/Reveal
      36: astore_2
      37: iconst_0
      38: istore_3
      39: aload_2
      40: invokevirtual #97                 // Method com/oocode/Reveal.getRed:()I
      43: istore_2
      44: aload_1
      45: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          81
      53: aload_1
      54: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: checkcast     #94                 // class com/oocode/Reveal
      62: astore_3
      63: iconst_0
      64: istore        4
      66: aload_3
      67: invokevirtual #97                 // Method com/oocode/Reveal.getRed:()I
      70: istore_3
      71: iload_2
      72: iload_3
      73: if_icmpge     44
      76: iload_3
      77: istore_2
      78: goto          44
      81: iload_2
      82: ireturn

  private static final int maxGreen(java.util.Set<com.oocode.Reveal>);
    Code:
       0: aload_0
       1: checkcast     #29                 // class java/lang/Iterable
       4: invokeinterface #33,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: astore_1
      10: aload_1
      11: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      16: ifne          27
      19: new           #89                 // class java/util/NoSuchElementException
      22: dup
      23: invokespecial #92                 // Method java/util/NoSuchElementException."<init>":()V
      26: athrow
      27: aload_1
      28: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #94                 // class com/oocode/Reveal
      36: astore_2
      37: iconst_0
      38: istore_3
      39: aload_2
      40: invokevirtual #104                // Method com/oocode/Reveal.getGreen:()I
      43: istore_2
      44: aload_1
      45: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          81
      53: aload_1
      54: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: checkcast     #94                 // class com/oocode/Reveal
      62: astore_3
      63: iconst_0
      64: istore        4
      66: aload_3
      67: invokevirtual #104                // Method com/oocode/Reveal.getGreen:()I
      70: istore_3
      71: iload_2
      72: iload_3
      73: if_icmpge     44
      76: iload_3
      77: istore_2
      78: goto          44
      81: iload_2
      82: ireturn

  private static final int maxBlue(java.util.Set<com.oocode.Reveal>);
    Code:
       0: aload_0
       1: checkcast     #29                 // class java/lang/Iterable
       4: invokeinterface #33,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: astore_1
      10: aload_1
      11: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      16: ifne          27
      19: new           #89                 // class java/util/NoSuchElementException
      22: dup
      23: invokespecial #92                 // Method java/util/NoSuchElementException."<init>":()V
      26: athrow
      27: aload_1
      28: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #94                 // class com/oocode/Reveal
      36: astore_2
      37: iconst_0
      38: istore_3
      39: aload_2
      40: invokevirtual #109                // Method com/oocode/Reveal.getBlue:()I
      43: istore_2
      44: aload_1
      45: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          81
      53: aload_1
      54: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: checkcast     #94                 // class com/oocode/Reveal
      62: astore_3
      63: iconst_0
      64: istore        4
      66: aload_3
      67: invokevirtual #109                // Method com/oocode/Reveal.getBlue:()I
      70: istore_3
      71: iload_2
      72: iload_3
      73: if_icmpge     44
      76: iload_3
      77: istore_2
      78: goto          44
      81: iload_2
      82: ireturn

  public static final com.oocode.Game gameFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #112                // String line
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #114                // String :
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: iconst_0
      30: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #17                 // class java/lang/CharSequence
      38: iconst_1
      39: anewarray     #19                 // class java/lang/String
      42: astore_2
      43: aload_2
      44: iconst_0
      45: ldc           #122                // String
      47: aastore
      48: aload_2
      49: iconst_0
      50: iconst_0
      51: bipush        6
      53: aconst_null
      54: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      57: iconst_1
      58: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      63: checkcast     #19                 // class java/lang/String
      66: invokestatic  #127                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      69: istore_1
      70: aload_0
      71: checkcast     #17                 // class java/lang/CharSequence
      74: iconst_1
      75: anewarray     #19                 // class java/lang/String
      78: astore_3
      79: aload_3
      80: iconst_0
      81: ldc           #114                // String :
      83: aastore
      84: aload_3
      85: iconst_0
      86: iconst_0
      87: bipush        6
      89: aconst_null
      90: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      93: iconst_1
      94: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      99: checkcast     #17                 // class java/lang/CharSequence
     102: iconst_1
     103: anewarray     #19                 // class java/lang/String
     106: astore_3
     107: aload_3
     108: iconst_0
     109: ldc           #129                // String ;
     111: aastore
     112: aload_3
     113: iconst_0
     114: iconst_0
     115: bipush        6
     117: aconst_null
     118: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     121: astore_2
     122: iload_1
     123: aload_2
     124: checkcast     #29                 // class java/lang/Iterable
     127: astore_3
     128: istore        12
     130: iconst_0
     131: istore        4
     133: aload_3
     134: astore        5
     136: new           #131                // class java/util/ArrayList
     139: dup
     140: aload_3
     141: bipush        10
     143: invokestatic  #137                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     146: invokespecial #140                // Method java/util/ArrayList."<init>":(I)V
     149: checkcast     #142                // class java/util/Collection
     152: astore        6
     154: iconst_0
     155: istore        7
     157: aload         5
     159: invokeinterface #33,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     164: astore        8
     166: aload         8
     168: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     173: ifeq          216
     176: aload         8
     178: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     183: astore        9
     185: aload         6
     187: aload         9
     189: checkcast     #19                 // class java/lang/String
     192: astore        10
     194: astore        13
     196: iconst_0
     197: istore        11
     199: aload         10
     201: invokestatic  #146                // Method revealFrom:(Ljava/lang/String;)Lcom/oocode/Reveal;
     204: aload         13
     206: swap
     207: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     212: pop
     213: goto          166
     216: aload         6
     218: checkcast     #116                // class java/util/List
     221: nop
     222: astore        13
     224: iload         12
     226: aload         13
     228: checkcast     #29                 // class java/lang/Iterable
     231: invokestatic  #154                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     234: astore        14
     236: istore        15
     238: new           #49                 // class com/oocode/Game
     241: dup
     242: iload         15
     244: aload         14
     246: invokespecial #157                // Method com/oocode/Game."<init>":(ILjava/util/Set;)V
     249: areturn

  public static final com.oocode.Reveal revealFrom(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #172                // String revealString
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #174                // String ,
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #29                 // class java/lang/Iterable
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: bipush        10
      38: invokestatic  #137                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokestatic  #180                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      44: bipush        16
      46: invokestatic  #186                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      49: istore        4
      51: aload_2
      52: astore        5
      54: new           #188                // class java/util/LinkedHashMap
      57: dup
      58: iload         4
      60: invokespecial #189                // Method java/util/LinkedHashMap."<init>":(I)V
      63: checkcast     #191                // class java/util/Map
      66: astore        6
      68: iconst_0
      69: istore        7
      71: aload         5
      73: invokeinterface #33,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      78: astore        8
      80: aload         8
      82: invokeinterface #39,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      87: ifeq          150
      90: aload         8
      92: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      97: astore        9
      99: aload         6
     101: astore        10
     103: aload         9
     105: checkcast     #19                 // class java/lang/String
     108: astore        11
     110: iconst_0
     111: istore        12
     113: aload         11
     115: checkcast     #17                 // class java/lang/CharSequence
     118: invokestatic  #195                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     121: invokevirtual #199                // Method java/lang/Object.toString:()Ljava/lang/String;
     124: invokestatic  #203                // Method asColorNumberPair:(Ljava/lang/String;)Lkotlin/Pair;
     127: astore        11
     129: aload         10
     131: aload         11
     133: invokevirtual #208                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     136: aload         11
     138: invokevirtual #211                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     141: invokeinterface #215,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     146: pop
     147: goto          80
     150: aload         6
     152: nop
     153: astore_1
     154: new           #94                 // class com/oocode/Reveal
     157: dup
     158: aload_1
     159: ldc           #217                // String red
     161: invokeinterface #220,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     166: checkcast     #124                // class java/lang/Integer
     169: dup
     170: ifnull        179
     173: invokevirtual #223                // Method java/lang/Integer.intValue:()I
     176: goto          181
     179: pop
     180: iconst_0
     181: aload_1
     182: ldc           #225                // String green
     184: invokeinterface #220,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     189: checkcast     #124                // class java/lang/Integer
     192: dup
     193: ifnull        202
     196: invokevirtual #223                // Method java/lang/Integer.intValue:()I
     199: goto          204
     202: pop
     203: iconst_0
     204: aload_1
     205: ldc           #227                // String blue
     207: invokeinterface #220,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     212: checkcast     #124                // class java/lang/Integer
     215: dup
     216: ifnull        225
     219: invokevirtual #223                // Method java/lang/Integer.intValue:()I
     222: goto          227
     225: pop
     226: iconst_0
     227: invokespecial #228                // Method com/oocode/Reveal."<init>":(III)V
     230: areturn

  public static final kotlin.Pair<java.lang.String, java.lang.Integer> asColorNumberPair(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #240                // String colorNumberPairString
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #19                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #122                // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: iconst_1
      30: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: aload_0
      36: checkcast     #17                 // class java/lang/CharSequence
      39: iconst_1
      40: anewarray     #19                 // class java/lang/String
      43: astore_1
      44: aload_1
      45: iconst_0
      46: ldc           #122                // String
      48: aastore
      49: aload_1
      50: iconst_0
      51: iconst_0
      52: bipush        6
      54: aconst_null
      55: invokestatic  #27                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      58: iconst_0
      59: invokeinterface #120,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      64: checkcast     #19                 // class java/lang/String
      67: invokestatic  #127                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      70: invokestatic  #244                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: invokestatic  #250                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      76: areturn

  public static final int access$possibilityValue(java.lang.String, com.oocode.Bag);
    Code:
       0: aload_0
       1: aload_1
       2: invokestatic  #253                // Method possibilityValue:(Ljava/lang/String;Lcom/oocode/Bag;)I
       5: ireturn

  public static final com.oocode.Bag access$maxBag(java.util.Set);
    Code:
       0: aload_0
       1: invokestatic  #257                // Method maxBag:(Ljava/util/Set;)Lcom/oocode/Bag;
       4: areturn
}

Compiled from "Bag.kt"
public final class com.oocode.Bag {
  private final int red;

  private final int green;

  private final int blue;

  public com.oocode.Bag(int, int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field red:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field green:I
      14: aload_0
      15: iload_3
      16: putfield      #19                 // Field blue:I
      19: return

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

  public final int getGreen();
    Code:
       0: aload_0
       1: getfield      #16                 // Field green:I
       4: ireturn

  public final int getBlue();
    Code:
       0: aload_0
       1: getfield      #19                 // Field blue:I
       4: ireturn

  public final int possibilityTotal(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #30                 // String input
       3: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #38                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #40                 // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc           #42                 // String \n
      19: aastore
      20: aload_2
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #48                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #50                 // class java/lang/Iterable
      32: astore_2
      33: iconst_0
      34: istore_3
      35: aload_2
      36: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        4
      43: aload         4
      45: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          92
      53: aload         4
      55: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        5
      62: iload_3
      63: aload         5
      65: checkcast     #40                 // class java/lang/String
      68: astore        6
      70: istore        8
      72: iconst_0
      73: istore        7
      75: aload         6
      77: aload_0
      78: invokestatic  #70                 // Method com/oocode/BagKt.access$possibilityValue:(Ljava/lang/String;Lcom/oocode/Bag;)I
      81: istore        9
      83: iload         8
      85: iload         9
      87: iadd
      88: istore_3
      89: goto          43
      92: iload_3
      93: ireturn

  public final int power();
    Code:
       0: aload_0
       1: getfield      #13                 // Field red:I
       4: aload_0
       5: getfield      #16                 // Field green:I
       8: imul
       9: aload_0
      10: getfield      #19                 // Field blue:I
      13: imul
      14: ireturn

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

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field green:I
       4: ireturn

  public final int component3();
    Code:
       0: aload_0
       1: getfield      #19                 // Field blue:I
       4: ireturn

  public final com.oocode.Bag copy(int, int, int);
    Code:
       0: new           #2                  // class com/oocode/Bag
       3: dup
       4: iload_1
       5: iload_2
       6: iload_3
       7: invokespecial #81                 // Method "<init>":(III)V
      10: areturn

  public static com.oocode.Bag copy$default(com.oocode.Bag, int, int, int, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #13                 // Field red:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #16                 // Field green:I
      23: istore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #19                 // Field blue:I
      35: istore_3
      36: aload_0
      37: iload_1
      38: iload_2
      39: iload_3
      40: invokevirtual #85                 // Method copy:(III)Lcom/oocode/Bag;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #89                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #90                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #92                 // String Bag(red=
       9: invokevirtual #96                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field red:I
      16: invokevirtual #99                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #101                // String , green=
      21: invokevirtual #96                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field green:I
      28: invokevirtual #99                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: ldc           #103                // String , blue=
      33: invokevirtual #96                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #19                 // Field blue:I
      40: invokevirtual #99                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #106                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #108                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field red:I
       4: invokestatic  #114                // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field green:I
      16: invokestatic  #114                // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #19                 // Field blue:I
      29: invokestatic  #114                // Method java/lang/Integer.hashCode:(I)I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class com/oocode/Bag
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class com/oocode/Bag
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field red:I
      25: aload_2
      26: getfield      #13                 // Field red:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field green:I
      38: aload_2
      39: getfield      #16                 // Field green:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #19                 // Field blue:I
      51: aload_2
      52: getfield      #19                 // Field blue:I
      55: if_icmpeq     60
      58: iconst_0
      59: ireturn
      60: iconst_1
      61: ireturn
}