package day14

import java.io.File

fun readFile(fileName: String): Pair<String, Map<String, String>> {
    return readFromString(File(fileName)
        .readText()
        .trim())
}

fun Map<String, String>.toCharacterMap(): Map<String, Char> {
    return mapValues { (_, character) -> character[0] }
}

fun performInsertion(template: String, map: Map<String, String>): String {
    val insertions = mutableListOf<String>()

    val groups = template.windowed(size = 2, step = 1, partialWindows = false)
    groups.forEach { group ->
        val insertion = map[group] ?: throw IllegalStateException("No mapping for $group")
        insertions.add(insertion)
    }

    return buildString {
        insertions.forEachIndexed { index, insertion ->
            append(template[index])
            append(insertion)
        }
        append(template.last())
    }
}

fun createGroupCount(template: String): Map<String, Long> {
    val map = mutableMapOf<String, Long>()
    template.windowed(size = 2, step = 1, partialWindows = false).forEach { group ->
        map.count(group, 1)
    }
    return map
}

fun MutableMap<Char, Long>.count(character: Char, count: Long) {
    val value = getOrDefault(character, 0L)
    val updated = value + count
    if (updated < value) {
        throw IllegalStateException("Oops, we failed")
    }
    put(character, updated)
}

fun MutableMap<String, Long>.count(group: String, count: Long = 1L) {
    val value = getOrDefault(group, 0L)
    val updated = value + count
    if (updated < value) {
        throw IllegalStateException("Oops, we failed")
    }
    put(group, updated)
}

fun Map<String, Char>.toInsertionMap(): Map<String, Pair<String, String>> {
    return mapValues { (group, character) ->
        Pair(
            "${group[0]}$character",
            "$character${group[1]}"
        )
    }
}

fun countAllTheThings(
    template: String,
    times: Int,
    characterMap: Map<String, Char>,
    insertionMap: Map<String, Pair<String, String>>
): Map<Char, Long> {
    val countCharacters = mutableMapOf<Char, Long>() // B -> 0
    var groupCount = createGroupCount(template)      // AB -> 0

    repeat(times) {
        val updatedGroupCount = mutableMapOf<String, Long>()

        groupCount.forEach { (group, count) ->
            val insertion = characterMap[group]
                ?: throw IllegalStateException("No character mapping for group: $group")
            countCharacters.count(insertion, count)

            val (first, second) = insertionMap[group]
                ?: throw IllegalStateException("No group mapping for group: $group")

            updatedGroupCount.count(first, count)
            updatedGroupCount.count(second, count)
        }

        groupCount = updatedGroupCount
    }

    template.toCharArray().forEach { character ->
        countCharacters.count(character, 1)
    }

    return countCharacters
}

fun countQuantities(input: String): Map<Char, Int> {
    return input.toCharArray().groupBy { it }
        .mapValues { (_, list) -> list.size }
}

fun Map<Char, Int>.max(): Pair<Char, Int> {
    return maxByOrNull { (_, count) -> count}!!.toPair()
}

fun Map<Char, Int>.min(): Pair<Char, Int> {
    return minByOrNull { (_, count) -> count}!!.toPair()
}

fun Map<Char, Long>.maxLong(): Pair<Char, Long> {
    return maxByOrNull { (_, count) -> count}!!.toPair()
}

fun Map<Char, Long>.minLong(): Pair<Char, Long> {
    return minByOrNull { (_, count) -> count}!!.toPair()
}

fun readFromString(input: String): Pair<String, Map<String, String>> {
    val lines = input.lines()
    val template = lines[0]
    val map = mutableMapOf<String, String>()

    for (line in lines.drop(2)) {
        val (from, to) = line.split(" -> ")
        map[from] = to
    }

    return Pair(template, map)
}

fun part1() {
    var (template, map) = readFile("day14.txt")

    repeat(10) {
       template = performInsertion(template, map)
    }

    val quantities = countQuantities(template)

    val (minCharacter, minValue) = quantities.min()
    val (maxCharacter, maxValue) = quantities.max()

    println("Min: $minCharacter => $minValue")
    println("Max: $maxCharacter => $maxValue")

    val result = maxValue - minValue

    println("Result: $result")
}

fun part2() {
    val (template, map) = readFile("day14.txt")

    val characterMap = map.toCharacterMap()
    val insertionMap = characterMap.toInsertionMap()

    val countMap = countAllTheThings(
        template,
        40,
        characterMap,
        insertionMap
    )

    val (maxChar, maxCount) = countMap.maxLong()
    val (minChar, minCount) = countMap.minLong()

    println("Max $maxChar = $maxCount")
    println("Min $minChar = $minCount")
    println("Result = ${maxCount - minCount}")
}

fun main() {
    println(">> PART 1")
    part1()
    println(">> PART 2")
    part2()
}

Compiled from "Day14.kt"
public final class day14.Day14Kt {
  public static final kotlin.Pair<java.lang.String, java.util.Map<java.lang.String, java.lang.String>> readFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String fileName
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: nop
       7: new           #18                 // class java/io/File
      10: dup
      11: aload_0
      12: invokespecial #22                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: aconst_null
      16: iconst_1
      17: aconst_null
      18: invokestatic  #28                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      21: checkcast     #30                 // class java/lang/CharSequence
      24: invokestatic  #36                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      27: invokevirtual #40                 // Method java/lang/Object.toString:()Ljava/lang/String;
      30: invokestatic  #43                 // Method readFromString:(Ljava/lang/String;)Lkotlin/Pair;
      33: areturn

  public static final java.util.Map<java.lang.String, java.lang.Character> toCharacterMap(java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #51                 // class java/util/LinkedHashMap
      15: dup
      16: aload_1
      17: invokeinterface #57,  1           // InterfaceMethod java/util/Map.size:()I
      22: invokestatic  #63                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      25: invokespecial #66                 // Method java/util/LinkedHashMap."<init>":(I)V
      28: checkcast     #53                 // class java/util/Map
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      42: checkcast     #72                 // class java/lang/Iterable
      45: astore        6
      47: iconst_0
      48: istore        7
      50: aload         6
      52: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        8
      59: aload         8
      61: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          154
      69: aload         8
      71: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      76: astore        9
      78: aload         4
      80: aload         9
      82: checkcast     #88                 // class java/util/Map$Entry
      85: astore        10
      87: astore        11
      89: iconst_0
      90: istore        12
      92: aload         10
      94: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      99: aload         11
     101: swap
     102: aload         9
     104: checkcast     #88                 // class java/util/Map$Entry
     107: astore        13
     109: astore        17
     111: astore        16
     113: iconst_0
     114: istore        14
     116: aload         13
     118: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     123: checkcast     #96                 // class java/lang/String
     126: astore        15
     128: aload         15
     130: iconst_0
     131: invokevirtual #100                // Method java/lang/String.charAt:(I)C
     134: invokestatic  #106                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     137: astore        18
     139: aload         16
     141: aload         17
     143: aload         18
     145: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     150: pop
     151: goto          59
     154: aload         4
     156: nop
     157: nop
     158: areturn

  public static final java.lang.String performInsertion(java.lang.String, java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #133                // String template
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #135                // String map
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #137                // class java/util/ArrayList
      15: dup
      16: invokespecial #140                // Method java/util/ArrayList."<init>":()V
      19: checkcast     #142                // class java/util/List
      22: astore_2
      23: aload_0
      24: checkcast     #30                 // class java/lang/CharSequence
      27: iconst_2
      28: iconst_1
      29: iconst_0
      30: invokestatic  #146                // Method kotlin/text/StringsKt.windowed:(Ljava/lang/CharSequence;IIZ)Ljava/util/List;
      33: astore_3
      34: aload_3
      35: checkcast     #72                 // class java/lang/Iterable
      38: astore        4
      40: iconst_0
      41: istore        5
      43: aload         4
      45: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          141
      62: aload         6
      64: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         7
      73: checkcast     #96                 // class java/lang/String
      76: astore        8
      78: iconst_0
      79: istore        9
      81: aload_1
      82: aload         8
      84: invokeinterface #150,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      89: checkcast     #96                 // class java/lang/String
      92: dup
      93: ifnonnull     125
      96: pop
      97: new           #152                // class java/lang/IllegalStateException
     100: dup
     101: new           #154                // class java/lang/StringBuilder
     104: dup
     105: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     108: ldc           #157                // String No mapping for
     110: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     113: aload         8
     115: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     118: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     121: invokespecial #163                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     124: athrow
     125: astore        10
     127: aload_2
     128: aload         10
     130: invokeinterface #167,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     135: pop
     136: nop
     137: nop
     138: goto          52
     141: nop
     142: new           #154                // class java/lang/StringBuilder
     145: dup
     146: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     149: astore        4
     151: aload         4
     153: astore        5
     155: iconst_0
     156: istore        6
     158: aload_2
     159: checkcast     #72                 // class java/lang/Iterable
     162: astore        7
     164: iconst_0
     165: istore        8
     167: iconst_0
     168: istore        9
     170: aload         7
     172: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     177: astore        10
     179: aload         10
     181: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     186: ifeq          252
     189: aload         10
     191: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     196: astore        11
     198: iload         9
     200: iinc          9, 1
     203: istore        12
     205: iload         12
     207: ifge          213
     210: invokestatic  #172                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     213: iload         12
     215: aload         11
     217: checkcast     #96                 // class java/lang/String
     220: astore        13
     222: istore        14
     224: iconst_0
     225: istore        15
     227: aload         5
     229: aload_0
     230: iload         14
     232: invokevirtual #100                // Method java/lang/String.charAt:(I)C
     235: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     238: pop
     239: aload         5
     241: aload         13
     243: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     246: pop
     247: nop
     248: nop
     249: goto          179
     252: nop
     253: aload         5
     255: aload_0
     256: checkcast     #30                 // class java/lang/CharSequence
     259: invokestatic  #179                // Method kotlin/text/StringsKt.last:(Ljava/lang/CharSequence;)C
     262: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     265: pop
     266: nop
     267: aload         4
     269: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     272: areturn

  public static final java.util.Map<java.lang.String, java.lang.Long> createGroupCount(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #133                // String template
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #51                 // class java/util/LinkedHashMap
       9: dup
      10: invokespecial #201                // Method java/util/LinkedHashMap."<init>":()V
      13: checkcast     #53                 // class java/util/Map
      16: astore_1
      17: aload_0
      18: checkcast     #30                 // class java/lang/CharSequence
      21: iconst_2
      22: iconst_1
      23: iconst_0
      24: invokestatic  #146                // Method kotlin/text/StringsKt.windowed:(Ljava/lang/CharSequence;IIZ)Ljava/util/List;
      27: checkcast     #72                 // class java/lang/Iterable
      30: astore_2
      31: iconst_0
      32: istore_3
      33: aload_2
      34: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      39: astore        4
      41: aload         4
      43: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      48: ifeq          82
      51: aload         4
      53: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      58: astore        5
      60: aload         5
      62: checkcast     #96                 // class java/lang/String
      65: astore        6
      67: iconst_0
      68: istore        7
      70: aload_1
      71: aload         6
      73: lconst_1
      74: invokestatic  #205                // Method count:(Ljava/util/Map;Ljava/lang/String;J)V
      77: nop
      78: nop
      79: goto          41
      82: nop
      83: aload_1
      84: areturn

  public static final void count(java.util.Map<java.lang.Character, java.lang.Long>, char, long);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_1
       8: invokestatic  #106                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      11: lconst_0
      12: invokestatic  #213                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      15: invokeinterface #216,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      20: checkcast     #218                // class java/lang/Number
      23: invokevirtual #222                // Method java/lang/Number.longValue:()J
      26: lstore        4
      28: lload         4
      30: lload_2
      31: ladd
      32: lstore        6
      34: lload         6
      36: lload         4
      38: lcmp
      39: ifge          52
      42: new           #152                // class java/lang/IllegalStateException
      45: dup
      46: ldc           #224                // String Oops, we failed
      48: invokespecial #163                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      51: athrow
      52: aload_0
      53: iload_1
      54: invokestatic  #106                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      57: lload         6
      59: invokestatic  #213                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      62: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      67: pop
      68: return

  public static final void count(java.util.Map<java.lang.String, java.lang.Long>, java.lang.String, long);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #231                // String group
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: lconst_0
      15: invokestatic  #213                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      18: invokeinterface #216,  3          // InterfaceMethod java/util/Map.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      23: checkcast     #218                // class java/lang/Number
      26: invokevirtual #222                // Method java/lang/Number.longValue:()J
      29: lstore        4
      31: lload         4
      33: lload_2
      34: ladd
      35: lstore        6
      37: lload         6
      39: lload         4
      41: lcmp
      42: ifge          55
      45: new           #152                // class java/lang/IllegalStateException
      48: dup
      49: ldc           #224                // String Oops, we failed
      51: invokespecial #163                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      54: athrow
      55: aload_0
      56: aload_1
      57: lload         6
      59: invokestatic  #213                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      62: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      67: pop
      68: return

  public static void count$default(java.util.Map, java.lang.String, long, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_2
       3: iand
       4: ifeq          9
       7: lconst_1
       8: lstore_2
       9: aload_0
      10: aload_1
      11: lload_2
      12: invokestatic  #205                // Method count:(Ljava/util/Map;Ljava/lang/String;J)V
      15: return

  public static final java.util.Map<java.lang.String, kotlin.Pair<java.lang.String, java.lang.String>> toInsertionMap(java.util.Map<java.lang.String, java.lang.Character>);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_1
      11: astore_3
      12: new           #51                 // class java/util/LinkedHashMap
      15: dup
      16: aload_1
      17: invokeinterface #57,  1           // InterfaceMethod java/util/Map.size:()I
      22: invokestatic  #63                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      25: invokespecial #66                 // Method java/util/LinkedHashMap."<init>":(I)V
      28: checkcast     #53                 // class java/util/Map
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      42: checkcast     #72                 // class java/lang/Iterable
      45: astore        6
      47: iconst_0
      48: istore        7
      50: aload         6
      52: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      57: astore        8
      59: aload         8
      61: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          216
      69: aload         8
      71: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      76: astore        9
      78: aload         4
      80: aload         9
      82: checkcast     #88                 // class java/util/Map$Entry
      85: astore        10
      87: astore        11
      89: iconst_0
      90: istore        12
      92: aload         10
      94: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      99: aload         11
     101: swap
     102: aload         9
     104: checkcast     #88                 // class java/util/Map$Entry
     107: astore        13
     109: astore        18
     111: astore        17
     113: iconst_0
     114: istore        14
     116: aload         13
     118: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     123: checkcast     #96                 // class java/lang/String
     126: astore        15
     128: aload         13
     130: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     135: checkcast     #102                // class java/lang/Character
     138: invokevirtual #239                // Method java/lang/Character.charValue:()C
     141: istore        16
     143: new           #241                // class kotlin/Pair
     146: dup
     147: new           #154                // class java/lang/StringBuilder
     150: dup
     151: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     154: aload         15
     156: iconst_0
     157: invokevirtual #100                // Method java/lang/String.charAt:(I)C
     160: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     163: iload         16
     165: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     168: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     171: new           #154                // class java/lang/StringBuilder
     174: dup
     175: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     178: iload         16
     180: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     183: aload         15
     185: iconst_1
     186: invokevirtual #100                // Method java/lang/String.charAt:(I)C
     189: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     192: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     195: invokespecial #244                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     198: nop
     199: astore        19
     201: aload         17
     203: aload         18
     205: aload         19
     207: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     212: pop
     213: goto          59
     216: aload         4
     218: nop
     219: nop
     220: areturn

  public static final java.util.Map<java.lang.Character, java.lang.Long> countAllTheThings(java.lang.String, int, java.util.Map<java.lang.String, java.lang.Character>, java.util.Map<java.lang.String, kotlin.Pair<java.lang.String, java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #133                // String template
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #251                // String characterMap
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_3
      13: ldc           #253                // String insertionMap
      15: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: new           #51                 // class java/util/LinkedHashMap
      21: dup
      22: invokespecial #201                // Method java/util/LinkedHashMap."<init>":()V
      25: checkcast     #53                 // class java/util/Map
      28: astore        4
      30: aconst_null
      31: astore        5
      33: aload_0
      34: invokestatic  #255                // Method createGroupCount:(Ljava/lang/String;)Ljava/util/Map;
      37: astore        5
      39: iconst_0
      40: istore        6
      42: iload         6
      44: iload_1
      45: if_icmpge     308
      48: iload         6
      50: istore        7
      52: iconst_0
      53: istore        8
      55: new           #51                 // class java/util/LinkedHashMap
      58: dup
      59: invokespecial #201                // Method java/util/LinkedHashMap."<init>":()V
      62: checkcast     #53                 // class java/util/Map
      65: astore        9
      67: aload         5
      69: astore        10
      71: iconst_0
      72: istore        11
      74: aload         10
      76: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      81: invokeinterface #258,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      86: astore        12
      88: aload         12
      90: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      95: ifeq          296
      98: aload         12
     100: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     105: checkcast     #88                 // class java/util/Map$Entry
     108: astore        13
     110: aload         13
     112: astore        14
     114: iconst_0
     115: istore        15
     117: aload         14
     119: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     124: checkcast     #96                 // class java/lang/String
     127: astore        16
     129: aload         14
     131: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     136: checkcast     #218                // class java/lang/Number
     139: invokevirtual #222                // Method java/lang/Number.longValue:()J
     142: lstore        17
     144: aload_2
     145: aload         16
     147: invokeinterface #150,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     152: checkcast     #102                // class java/lang/Character
     155: dup
     156: ifnull        165
     159: invokevirtual #239                // Method java/lang/Character.charValue:()C
     162: goto          195
     165: pop
     166: new           #152                // class java/lang/IllegalStateException
     169: dup
     170: new           #154                // class java/lang/StringBuilder
     173: dup
     174: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     177: ldc_w         #260                // String No character mapping for group:
     180: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     183: aload         16
     185: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     188: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     191: invokespecial #163                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     194: athrow
     195: istore        19
     197: aload         4
     199: iload         19
     201: lload         17
     203: invokestatic  #262                // Method count:(Ljava/util/Map;CJ)V
     206: aload_3
     207: aload         16
     209: invokeinterface #150,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     214: checkcast     #241                // class kotlin/Pair
     217: dup
     218: ifnonnull     251
     221: pop
     222: new           #152                // class java/lang/IllegalStateException
     225: dup
     226: new           #154                // class java/lang/StringBuilder
     229: dup
     230: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     233: ldc_w         #264                // String No group mapping for group:
     236: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     239: aload         16
     241: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     244: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     247: invokespecial #163                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     250: athrow
     251: astore        20
     253: aload         20
     255: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     258: checkcast     #96                 // class java/lang/String
     261: astore        21
     263: aload         20
     265: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     268: checkcast     #96                 // class java/lang/String
     271: astore        22
     273: aload         9
     275: aload         21
     277: lload         17
     279: invokestatic  #205                // Method count:(Ljava/util/Map;Ljava/lang/String;J)V
     282: aload         9
     284: aload         22
     286: lload         17
     288: invokestatic  #205                // Method count:(Ljava/util/Map;Ljava/lang/String;J)V
     291: nop
     292: nop
     293: goto          88
     296: nop
     297: aload         9
     299: astore        5
     301: nop
     302: iinc          6, 1
     305: goto          42
     308: aload_0
     309: invokevirtual #274                // Method java/lang/String.toCharArray:()[C
     312: dup
     313: ldc_w         #276                // String toCharArray(...)
     316: invokestatic  #279                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     319: astore        6
     321: nop
     322: iconst_0
     323: istore        7
     325: iconst_0
     326: istore        8
     328: aload         6
     330: arraylength
     331: istore        9
     333: iload         8
     335: iload         9
     337: if_icmpge     370
     340: aload         6
     342: iload         8
     344: caload
     345: istore        10
     347: iload         10
     349: istore        11
     351: iconst_0
     352: istore        12
     354: aload         4
     356: iload         11
     358: lconst_1
     359: invokestatic  #262                // Method count:(Ljava/util/Map;CJ)V
     362: nop
     363: nop
     364: iinc          8, 1
     367: goto          333
     370: nop
     371: aload         4
     373: areturn

  public static final java.util.Map<java.lang.Character, java.lang.Integer> countQuantities(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #295                // String input
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #274                // Method java/lang/String.toCharArray:()[C
      11: dup
      12: ldc_w         #276                // String toCharArray(...)
      15: invokestatic  #279                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: astore_1
      19: nop
      20: iconst_0
      21: istore_2
      22: aload_1
      23: astore_3
      24: new           #51                 // class java/util/LinkedHashMap
      27: dup
      28: invokespecial #201                // Method java/util/LinkedHashMap."<init>":()V
      31: checkcast     #53                 // class java/util/Map
      34: astore        4
      36: iconst_0
      37: istore        5
      39: iconst_0
      40: istore        6
      42: aload_3
      43: arraylength
      44: istore        7
      46: iload         6
      48: iload         7
      50: if_icmpge     155
      53: aload_3
      54: iload         6
      56: caload
      57: istore        8
      59: iload         8
      61: istore        9
      63: iconst_0
      64: istore        10
      66: iload         9
      68: invokestatic  #106                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      71: astore        11
      73: aload         4
      75: astore        12
      77: iconst_0
      78: istore        13
      80: aload         12
      82: aload         11
      84: invokeinterface #150,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      89: astore        14
      91: aload         14
      93: ifnonnull     128
      96: iconst_0
      97: istore        15
      99: new           #137                // class java/util/ArrayList
     102: dup
     103: invokespecial #140                // Method java/util/ArrayList."<init>":()V
     106: checkcast     #142                // class java/util/List
     109: astore        15
     111: aload         12
     113: aload         11
     115: aload         15
     117: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     122: pop
     123: aload         15
     125: goto          130
     128: aload         14
     130: nop
     131: checkcast     #142                // class java/util/List
     134: astore        9
     136: aload         9
     138: iload         8
     140: invokestatic  #106                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     143: invokeinterface #167,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     148: pop
     149: iinc          6, 1
     152: goto          46
     155: aload         4
     157: nop
     158: astore_1
     159: nop
     160: iconst_0
     161: istore_2
     162: aload_1
     163: astore_3
     164: new           #51                 // class java/util/LinkedHashMap
     167: dup
     168: aload_1
     169: invokeinterface #57,  1           // InterfaceMethod java/util/Map.size:()I
     174: invokestatic  #63                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     177: invokespecial #66                 // Method java/util/LinkedHashMap."<init>":(I)V
     180: checkcast     #53                 // class java/util/Map
     183: astore        4
     185: iconst_0
     186: istore        5
     188: aload_3
     189: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     194: checkcast     #72                 // class java/lang/Iterable
     197: astore        6
     199: iconst_0
     200: istore        7
     202: aload         6
     204: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     209: astore        8
     211: aload         8
     213: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     218: ifeq          307
     221: aload         8
     223: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     228: astore        9
     230: aload         4
     232: aload         9
     234: checkcast     #88                 // class java/util/Map$Entry
     237: astore        10
     239: astore        11
     241: iconst_0
     242: istore        12
     244: aload         10
     246: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     251: aload         11
     253: swap
     254: aload         9
     256: checkcast     #88                 // class java/util/Map$Entry
     259: astore        13
     261: astore        17
     263: astore        16
     265: iconst_0
     266: istore        14
     268: aload         13
     270: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     275: checkcast     #142                // class java/util/List
     278: astore        15
     280: aload         15
     282: invokeinterface #296,  1          // InterfaceMethod java/util/List.size:()I
     287: invokestatic  #301                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     290: astore        18
     292: aload         16
     294: aload         17
     296: aload         18
     298: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     303: pop
     304: goto          211
     307: aload         4
     309: nop
     310: nop
     311: areturn

  public static final kotlin.Pair<java.lang.Character, java.lang.Integer> max(java.util.Map<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      12: checkcast     #72                 // class java/lang/Iterable
      15: astore_2
      16: aload_2
      17: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifne          36
      32: aconst_null
      33: goto          150
      36: aload_3
      37: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        4
      44: aload_3
      45: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifne          58
      53: aload         4
      55: goto          150
      58: aload         4
      60: checkcast     #88                 // class java/util/Map$Entry
      63: astore        5
      65: iconst_0
      66: istore        6
      68: aload         5
      70: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      75: checkcast     #218                // class java/lang/Number
      78: invokevirtual #322                // Method java/lang/Number.intValue:()I
      81: istore        7
      83: iload         7
      85: istore        5
      87: aload_3
      88: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        6
      95: aload         6
      97: checkcast     #88                 // class java/util/Map$Entry
     100: astore        7
     102: iconst_0
     103: istore        8
     105: aload         7
     107: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     112: checkcast     #218                // class java/lang/Number
     115: invokevirtual #322                // Method java/lang/Number.intValue:()I
     118: istore        9
     120: iload         9
     122: istore        7
     124: iload         5
     126: iload         7
     128: if_icmpge     139
     131: aload         6
     133: astore        4
     135: iload         7
     137: istore        5
     139: aload_3
     140: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     145: ifne          87
     148: aload         4
     150: checkcast     #88                 // class java/util/Map$Entry
     153: dup
     154: invokestatic  #326                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     157: astore_1
     158: new           #241                // class kotlin/Pair
     161: dup
     162: aload_1
     163: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     168: aload_1
     169: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     174: invokespecial #244                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     177: areturn

  public static final kotlin.Pair<java.lang.Character, java.lang.Integer> min(java.util.Map<java.lang.Character, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      12: checkcast     #72                 // class java/lang/Iterable
      15: astore_2
      16: aload_2
      17: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifne          36
      32: aconst_null
      33: goto          150
      36: aload_3
      37: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        4
      44: aload_3
      45: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifne          58
      53: aload         4
      55: goto          150
      58: aload         4
      60: checkcast     #88                 // class java/util/Map$Entry
      63: astore        5
      65: iconst_0
      66: istore        6
      68: aload         5
      70: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      75: checkcast     #218                // class java/lang/Number
      78: invokevirtual #322                // Method java/lang/Number.intValue:()I
      81: istore        7
      83: iload         7
      85: istore        5
      87: aload_3
      88: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        6
      95: aload         6
      97: checkcast     #88                 // class java/util/Map$Entry
     100: astore        7
     102: iconst_0
     103: istore        8
     105: aload         7
     107: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     112: checkcast     #218                // class java/lang/Number
     115: invokevirtual #322                // Method java/lang/Number.intValue:()I
     118: istore        9
     120: iload         9
     122: istore        7
     124: iload         5
     126: iload         7
     128: if_icmple     139
     131: aload         6
     133: astore        4
     135: iload         7
     137: istore        5
     139: aload_3
     140: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     145: ifne          87
     148: aload         4
     150: checkcast     #88                 // class java/util/Map$Entry
     153: dup
     154: invokestatic  #326                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     157: astore_1
     158: new           #241                // class kotlin/Pair
     161: dup
     162: aload_1
     163: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     168: aload_1
     169: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     174: invokespecial #244                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     177: areturn

  public static final kotlin.Pair<java.lang.Character, java.lang.Long> maxLong(java.util.Map<java.lang.Character, java.lang.Long>);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      12: checkcast     #72                 // class java/lang/Iterable
      15: astore_2
      16: aload_2
      17: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifne          36
      32: aconst_null
      33: goto          151
      36: aload_3
      37: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        4
      44: aload_3
      45: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifne          58
      53: aload         4
      55: goto          151
      58: aload         4
      60: checkcast     #88                 // class java/util/Map$Entry
      63: astore        5
      65: iconst_0
      66: istore        7
      68: aload         5
      70: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      75: checkcast     #218                // class java/lang/Number
      78: invokevirtual #222                // Method java/lang/Number.longValue:()J
      81: lstore        8
      83: lload         8
      85: lstore        5
      87: aload_3
      88: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        7
      95: aload         7
      97: checkcast     #88                 // class java/util/Map$Entry
     100: astore        10
     102: iconst_0
     103: istore        12
     105: aload         10
     107: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     112: checkcast     #218                // class java/lang/Number
     115: invokevirtual #222                // Method java/lang/Number.longValue:()J
     118: lstore        13
     120: lload         13
     122: lstore        10
     124: lload         5
     126: lload         10
     128: lcmp
     129: ifge          140
     132: aload         7
     134: astore        4
     136: lload         10
     138: lstore        5
     140: aload_3
     141: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     146: ifne          87
     149: aload         4
     151: checkcast     #88                 // class java/util/Map$Entry
     154: dup
     155: invokestatic  #326                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     158: astore_1
     159: new           #241                // class kotlin/Pair
     162: dup
     163: aload_1
     164: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     169: aload_1
     170: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     175: invokespecial #244                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     178: areturn

  public static final kotlin.Pair<java.lang.Character, java.lang.Long> minLong(java.util.Map<java.lang.Character, java.lang.Long>);
    Code:
       0: aload_0
       1: ldc           #49                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #70,  1           // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      12: checkcast     #72                 // class java/lang/Iterable
      15: astore_2
      16: aload_2
      17: invokeinterface #76,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifne          36
      32: aconst_null
      33: goto          151
      36: aload_3
      37: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: astore        4
      44: aload_3
      45: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifne          58
      53: aload         4
      55: goto          151
      58: aload         4
      60: checkcast     #88                 // class java/util/Map$Entry
      63: astore        5
      65: iconst_0
      66: istore        7
      68: aload         5
      70: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      75: checkcast     #218                // class java/lang/Number
      78: invokevirtual #222                // Method java/lang/Number.longValue:()J
      81: lstore        8
      83: lload         8
      85: lstore        5
      87: aload_3
      88: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      93: astore        7
      95: aload         7
      97: checkcast     #88                 // class java/util/Map$Entry
     100: astore        10
     102: iconst_0
     103: istore        12
     105: aload         10
     107: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     112: checkcast     #218                // class java/lang/Number
     115: invokevirtual #222                // Method java/lang/Number.longValue:()J
     118: lstore        13
     120: lload         13
     122: lstore        10
     124: lload         5
     126: lload         10
     128: lcmp
     129: ifle          140
     132: aload         7
     134: astore        4
     136: lload         10
     138: lstore        5
     140: aload_3
     141: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     146: ifne          87
     149: aload         4
     151: checkcast     #88                 // class java/util/Map$Entry
     154: dup
     155: invokestatic  #326                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     158: astore_1
     159: new           #241                // class kotlin/Pair
     162: dup
     163: aload_1
     164: invokeinterface #91,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     169: aload_1
     170: invokeinterface #94,  1           // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     175: invokespecial #244                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     178: areturn

  public static final kotlin.Pair<java.lang.String, java.util.Map<java.lang.String, java.lang.String>> readFromString(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #295                // String input
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #30                 // class java/lang/CharSequence
      11: invokestatic  #342                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      14: astore_1
      15: aload_1
      16: iconst_0
      17: invokeinterface #345,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: checkcast     #96                 // class java/lang/String
      25: astore_2
      26: new           #51                 // class java/util/LinkedHashMap
      29: dup
      30: invokespecial #201                // Method java/util/LinkedHashMap."<init>":()V
      33: checkcast     #53                 // class java/util/Map
      36: astore_3
      37: aload_1
      38: checkcast     #72                 // class java/lang/Iterable
      41: iconst_2
      42: invokestatic  #349                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      45: invokeinterface #350,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      50: astore        4
      52: aload         4
      54: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          144
      62: aload         4
      64: invokeinterface #86,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: checkcast     #96                 // class java/lang/String
      72: astore        5
      74: aload         5
      76: checkcast     #30                 // class java/lang/CharSequence
      79: iconst_1
      80: anewarray     #96                 // class java/lang/String
      83: astore        7
      85: aload         7
      87: iconst_0
      88: ldc_w         #352                // String  ->
      91: aastore
      92: aload         7
      94: iconst_0
      95: iconst_0
      96: bipush        6
      98: aconst_null
      99: invokestatic  #356                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     102: astore        6
     104: aload         6
     106: iconst_0
     107: invokeinterface #345,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #96                 // class java/lang/String
     115: astore        7
     117: aload         6
     119: iconst_1
     120: invokeinterface #345,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     125: checkcast     #96                 // class java/lang/String
     128: astore        8
     130: aload_3
     131: aload         7
     133: aload         8
     135: invokeinterface #110,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     140: pop
     141: goto          52
     144: new           #241                // class kotlin/Pair
     147: dup
     148: aload_2
     149: aload_3
     150: invokespecial #244                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     153: areturn

  public static final void part1();
    Code:
       0: ldc_w         #362                // String day14.txt
       3: invokestatic  #364                // Method readFile:(Ljava/lang/String;)Lkotlin/Pair;
       6: astore_0
       7: aconst_null
       8: astore_1
       9: aload_0
      10: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      13: astore_1
      14: aconst_null
      15: astore_2
      16: aload_0
      17: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      20: astore_2
      21: bipush        10
      23: istore_3
      24: iconst_0
      25: istore        4
      27: iload         4
      29: iload_3
      30: if_icmpge     59
      33: iload         4
      35: istore        5
      37: iconst_0
      38: istore        6
      40: aload_1
      41: checkcast     #96                 // class java/lang/String
      44: aload_2
      45: checkcast     #53                 // class java/util/Map
      48: invokestatic  #366                // Method performInsertion:(Ljava/lang/String;Ljava/util/Map;)Ljava/lang/String;
      51: astore_1
      52: nop
      53: iinc          4, 1
      56: goto          27
      59: aload_1
      60: checkcast     #96                 // class java/lang/String
      63: invokestatic  #368                // Method countQuantities:(Ljava/lang/String;)Ljava/util/Map;
      66: astore_3
      67: aload_3
      68: invokestatic  #370                // Method min:(Ljava/util/Map;)Lkotlin/Pair;
      71: astore        4
      73: aload         4
      75: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      78: checkcast     #102                // class java/lang/Character
      81: invokevirtual #239                // Method java/lang/Character.charValue:()C
      84: istore        5
      86: aload         4
      88: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      91: checkcast     #218                // class java/lang/Number
      94: invokevirtual #322                // Method java/lang/Number.intValue:()I
      97: istore        6
      99: aload_3
     100: invokestatic  #372                // Method max:(Ljava/util/Map;)Lkotlin/Pair;
     103: astore        7
     105: aload         7
     107: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     110: checkcast     #102                // class java/lang/Character
     113: invokevirtual #239                // Method java/lang/Character.charValue:()C
     116: istore        8
     118: aload         7
     120: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     123: checkcast     #218                // class java/lang/Number
     126: invokevirtual #322                // Method java/lang/Number.intValue:()I
     129: istore        9
     131: new           #154                // class java/lang/StringBuilder
     134: dup
     135: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     138: ldc_w         #374                // String Min:
     141: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     144: iload         5
     146: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     149: ldc_w         #376                // String  =>
     152: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     155: iload         6
     157: invokevirtual #379                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     160: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     163: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
     166: swap
     167: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     170: new           #154                // class java/lang/StringBuilder
     173: dup
     174: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     177: ldc_w         #392                // String Max:
     180: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     183: iload         8
     185: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     188: ldc_w         #376                // String  =>
     191: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     194: iload         9
     196: invokevirtual #379                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     199: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     202: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
     205: swap
     206: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     209: iload         9
     211: iload         6
     213: isub
     214: istore        10
     216: new           #154                // class java/lang/StringBuilder
     219: dup
     220: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     223: ldc_w         #394                // String Result:
     226: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     229: iload         10
     231: invokevirtual #379                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     234: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     237: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
     240: swap
     241: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     244: return

  public static final void part2();
    Code:
       0: ldc_w         #362                // String day14.txt
       3: invokestatic  #364                // Method readFile:(Ljava/lang/String;)Lkotlin/Pair;
       6: astore_0
       7: aload_0
       8: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #96                 // class java/lang/String
      14: astore_1
      15: aload_0
      16: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      19: checkcast     #53                 // class java/util/Map
      22: astore_2
      23: aload_2
      24: invokestatic  #404                // Method toCharacterMap:(Ljava/util/Map;)Ljava/util/Map;
      27: astore_3
      28: aload_3
      29: invokestatic  #406                // Method toInsertionMap:(Ljava/util/Map;)Ljava/util/Map;
      32: astore        4
      34: aload_1
      35: bipush        40
      37: aload_3
      38: aload         4
      40: invokestatic  #408                // Method countAllTheThings:(Ljava/lang/String;ILjava/util/Map;Ljava/util/Map;)Ljava/util/Map;
      43: astore        5
      45: aload         5
      47: invokestatic  #410                // Method maxLong:(Ljava/util/Map;)Lkotlin/Pair;
      50: astore        6
      52: aload         6
      54: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      57: checkcast     #102                // class java/lang/Character
      60: invokevirtual #239                // Method java/lang/Character.charValue:()C
      63: istore        7
      65: aload         6
      67: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      70: checkcast     #218                // class java/lang/Number
      73: invokevirtual #222                // Method java/lang/Number.longValue:()J
      76: lstore        8
      78: aload         5
      80: invokestatic  #412                // Method minLong:(Ljava/util/Map;)Lkotlin/Pair;
      83: astore        10
      85: aload         10
      87: invokevirtual #267                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      90: checkcast     #102                // class java/lang/Character
      93: invokevirtual #239                // Method java/lang/Character.charValue:()C
      96: istore        11
      98: aload         10
     100: invokevirtual #270                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     103: checkcast     #218                // class java/lang/Number
     106: invokevirtual #222                // Method java/lang/Number.longValue:()J
     109: lstore        12
     111: new           #154                // class java/lang/StringBuilder
     114: dup
     115: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     118: ldc_w         #414                // String Max
     121: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     124: iload         7
     126: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     129: ldc_w         #416                // String  =
     132: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     135: lload         8
     137: invokevirtual #419                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     140: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     143: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
     146: swap
     147: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     150: new           #154                // class java/lang/StringBuilder
     153: dup
     154: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     157: ldc_w         #421                // String Min
     160: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     163: iload         11
     165: invokevirtual #175                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     168: ldc_w         #416                // String  =
     171: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     174: lload         12
     176: invokevirtual #419                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     179: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     182: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
     185: swap
     186: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     189: new           #154                // class java/lang/StringBuilder
     192: dup
     193: invokespecial #155                // Method java/lang/StringBuilder."<init>":()V
     196: ldc_w         #423                // String Result =
     199: invokevirtual #161                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     202: lload         8
     204: lload         12
     206: lsub
     207: invokevirtual #419                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     210: invokevirtual #162                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     213: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
     216: swap
     217: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     220: return

  public static final void main();
    Code:
       0: ldc_w         #431                // String >> PART 1
       3: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
       6: swap
       7: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      10: invokestatic  #433                // Method part1:()V
      13: ldc_w         #435                // String >> PART 2
      16: getstatic     #385                // Field java/lang/System.out:Ljava/io/PrintStream;
      19: swap
      20: invokevirtual #390                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      23: invokestatic  #437                // Method part2:()V
      26: return

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


package day13

import java.io.File

data class Point(
    val x: Int,
    val y: Int
)

data class Paper(
    val points: Map<Point, Boolean>
) {
    fun fold(instruction: Instruction): Paper {
        return when (instruction) {
            is Instruction.FoldUp -> foldUp(instruction.y)
            is Instruction.FoldLeft -> foldLeft(instruction.x)
        }
    }

    fun fold(instructions: List<Instruction>): Paper {
        var paper = this

        for (instruction in instructions) {
            paper = paper.fold(instruction)
        }

        return paper
    }

    fun foldLeft(x: Int): Paper {
        val newPoints = mutableMapOf<Point, Boolean>()

        points.keys.forEach { point ->
            if (point.x < x) {
                newPoints[point] = true
            } else if (point.x > x) {
                val steps = point.x - x
                val mirroredPoint = Point(
                    x - steps,
                    point.y
                )
                newPoints[mirroredPoint] = true
            } else {
                throw IllegalStateException("Point on fold line")
            }
        }

        return Paper(newPoints)
    }

    fun foldUp(y: Int): Paper {
        val newPoints = mutableMapOf<Point, Boolean>()

        points.keys.forEach { point ->
            if (point.y < y) {
                newPoints[point] = true
            } else if (point.y > y) {
                val steps = point.y - y
                val mirroredPoint = Point(
                    point.x,
                    y - steps
                )
                newPoints[mirroredPoint] = true
            } else {
                throw IllegalStateException("Point on fold line")
            }
        }

        return Paper(newPoints)
    }

    fun countPoints(): Int {
        return points.size
    }

    fun isMarked(x: Int, y: Int): Boolean {
        return isMarked(Point(x, y))
    }

    fun isMarked(point: Point): Boolean {
        return points[point] == true
    }

    fun dump(): String {
        val size = size()

        return buildString {
            for (y in 0..size.y) {
                for (x in 0..size.x) {
                    if (isMarked(x, y)) {
                        append('#')
                    } else {
                        append('.')
                    }
                }
                appendLine()
            }
        }.trim()
    }

    fun size(): Point {
        var x = 0
        var y = 0

        points.keys.forEach { point ->
            x = if (point.x > x) point.x else x
            y = if (point.y > y) point.y else y
        }

        return Point(x, y)
    }
}

sealed interface Instruction {
    data class FoldUp(
        val y: Int
    ) : Instruction

    data class FoldLeft(
        val x: Int
    ) : Instruction
}

fun readFromFile(fileName: String): Pair<Paper, List<Instruction>> {
    return readFromString(File(fileName)
        .readText())
}

fun parsePoint(line: String): Point {
    val (x, y) = line.split(",")
    return Point(x.toInt(), y.toInt())
}

fun parseInstruction(line: String): Instruction {
    return when {
        line.startsWith("fold along x=") -> Instruction.FoldLeft(line.split("=")[1].toInt())
        line.startsWith("fold along y=") -> Instruction.FoldUp(line.split("=")[1].toInt())
        else -> throw IllegalStateException("Unknown instruction: $line")
    }
}

fun readFromString(input: String): Pair<Paper, List<Instruction>> {
    var parsingPoints = true
    val points = mutableMapOf<Point, Boolean>()
    val instructions = mutableListOf<Instruction>()

    input.lines().forEach { line ->
        when {
            line.isEmpty() -> parsingPoints = false
            parsingPoints -> points[parsePoint(line)] = true
            else -> instructions.add(parseInstruction(line))
        }
    }

    return Pair(Paper(points), instructions)
}

fun part1() {
    val (paper, instructions) = readFromFile("day13.txt")
    val instruction = instructions[0]

    val foldedPaper = paper.fold(instruction)
    val points = foldedPaper.countPoints()

    println("Points before fold: ${paper.countPoints()}")
    println("Points after fold: $points")
}

fun part2() {
    val (paper, instructions) = readFromFile("day13.txt")

    val foldedPaper = paper.fold(instructions)

    println(foldedPaper.dump())
}

fun main() {
    part2()
}

Compiled from "Day13.kt"
public final class day13.Day13Kt {
  public static final kotlin.Pair<day13.Paper, java.util.List<day13.Instruction>> readFromFile(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String fileName
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/io/File
       9: dup
      10: aload_0
      11: invokespecial #22                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      14: aconst_null
      15: iconst_1
      16: aconst_null
      17: invokestatic  #28                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      20: invokestatic  #31                 // Method readFromString:(Ljava/lang/String;)Lkotlin/Pair;
      23: areturn

  public static final day13.Point parsePoint(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #36                 // String line
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       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 ,
      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: astore_1
      30: aload_1
      31: iconst_0
      32: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #40                 // class java/lang/String
      40: astore_2
      41: aload_1
      42: iconst_1
      43: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      48: checkcast     #40                 // class java/lang/String
      51: astore_3
      52: new           #56                 // class day13/Point
      55: dup
      56: aload_2
      57: invokestatic  #62                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      60: aload_3
      61: invokestatic  #62                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      64: invokespecial #65                 // Method day13/Point."<init>":(II)V
      67: areturn

  public static final day13.Instruction parseInstruction(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #36                 // String line
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: nop
       7: aload_0
       8: ldc           #71                 // String fold along x=
      10: iconst_0
      11: iconst_2
      12: aconst_null
      13: invokestatic  #75                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      16: ifeq          67
      19: new           #77                 // class day13/Instruction$FoldLeft
      22: dup
      23: aload_0
      24: checkcast     #38                 // class java/lang/CharSequence
      27: iconst_1
      28: anewarray     #40                 // class java/lang/String
      31: astore_1
      32: aload_1
      33: iconst_0
      34: ldc           #79                 // String =
      36: aastore
      37: aload_1
      38: iconst_0
      39: iconst_0
      40: bipush        6
      42: aconst_null
      43: invokestatic  #48                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      46: iconst_1
      47: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      52: checkcast     #40                 // class java/lang/String
      55: invokestatic  #62                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      58: invokespecial #82                 // Method day13/Instruction$FoldLeft."<init>":(I)V
      61: checkcast     #84                 // class day13/Instruction
      64: goto          154
      67: aload_0
      68: ldc           #86                 // String fold along y=
      70: iconst_0
      71: iconst_2
      72: aconst_null
      73: invokestatic  #75                 // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      76: ifeq          127
      79: new           #88                 // class day13/Instruction$FoldUp
      82: dup
      83: aload_0
      84: checkcast     #38                 // class java/lang/CharSequence
      87: iconst_1
      88: anewarray     #40                 // class java/lang/String
      91: astore_1
      92: aload_1
      93: iconst_0
      94: ldc           #79                 // String =
      96: aastore
      97: aload_1
      98: iconst_0
      99: iconst_0
     100: bipush        6
     102: aconst_null
     103: invokestatic  #48                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     106: iconst_1
     107: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     112: checkcast     #40                 // class java/lang/String
     115: invokestatic  #62                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     118: invokespecial #89                 // Method day13/Instruction$FoldUp."<init>":(I)V
     121: checkcast     #84                 // class day13/Instruction
     124: goto          154
     127: new           #91                 // class java/lang/IllegalStateException
     130: dup
     131: new           #93                 // class java/lang/StringBuilder
     134: dup
     135: invokespecial #96                 // Method java/lang/StringBuilder."<init>":()V
     138: ldc           #98                 // String Unknown instruction:
     140: invokevirtual #102                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     143: aload_0
     144: invokevirtual #102                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     147: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     150: invokespecial #107                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     153: athrow
     154: areturn

  public static final kotlin.Pair<day13.Paper, java.util.List<day13.Instruction>> readFromString(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #111                // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_1
       8: iconst_1
       9: istore_1
      10: new           #113                // class java/util/LinkedHashMap
      13: dup
      14: invokespecial #114                // Method java/util/LinkedHashMap."<init>":()V
      17: checkcast     #116                // class java/util/Map
      20: astore_2
      21: new           #118                // class java/util/ArrayList
      24: dup
      25: invokespecial #119                // Method java/util/ArrayList."<init>":()V
      28: checkcast     #50                 // class java/util/List
      31: astore_3
      32: aload_0
      33: checkcast     #38                 // class java/lang/CharSequence
      36: invokestatic  #123                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      39: checkcast     #125                // class java/lang/Iterable
      42: astore        4
      44: iconst_0
      45: istore        5
      47: aload         4
      49: invokeinterface #129,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      54: astore        6
      56: aload         6
      58: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      63: ifeq          152
      66: aload         6
      68: invokeinterface #139,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      73: astore        7
      75: aload         7
      77: checkcast     #40                 // class java/lang/String
      80: astore        8
      82: iconst_0
      83: istore        9
      85: nop
      86: aload         8
      88: checkcast     #38                 // class java/lang/CharSequence
      91: invokeinterface #143,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      96: ifne          103
      99: iconst_1
     100: goto          104
     103: iconst_0
     104: ifeq          112
     107: iconst_0
     108: istore_1
     109: goto          147
     112: iload_1
     113: ifeq          135
     116: aload_2
     117: aload         8
     119: invokestatic  #145                // Method parsePoint:(Ljava/lang/String;)Lday13/Point;
     122: iconst_1
     123: invokestatic  #151                // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     126: invokeinterface #155,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     131: pop
     132: goto          147
     135: aload_3
     136: aload         8
     138: invokestatic  #157                // Method parseInstruction:(Ljava/lang/String;)Lday13/Instruction;
     141: invokeinterface #161,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     146: pop
     147: nop
     148: nop
     149: goto          56
     152: nop
     153: new           #163                // class kotlin/Pair
     156: dup
     157: new           #165                // class day13/Paper
     160: dup
     161: aload_2
     162: invokespecial #168                // Method day13/Paper."<init>":(Ljava/util/Map;)V
     165: aload_3
     166: invokespecial #171                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     169: areturn

  public static final void part1();
    Code:
       0: ldc           #187                // String day13.txt
       2: invokestatic  #189                // Method readFromFile:(Ljava/lang/String;)Lkotlin/Pair;
       5: astore_0
       6: aload_0
       7: invokevirtual #192                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      10: checkcast     #165                // class day13/Paper
      13: astore_1
      14: aload_0
      15: invokevirtual #195                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      18: checkcast     #50                 // class java/util/List
      21: astore_2
      22: aload_2
      23: iconst_0
      24: invokeinterface #54,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      29: checkcast     #84                 // class day13/Instruction
      32: astore_3
      33: aload_1
      34: aload_3
      35: invokevirtual #199                // Method day13/Paper.fold:(Lday13/Instruction;)Lday13/Paper;
      38: astore        4
      40: aload         4
      42: invokevirtual #202                // Method day13/Paper.countPoints:()I
      45: istore        5
      47: new           #93                 // class java/lang/StringBuilder
      50: dup
      51: invokespecial #96                 // Method java/lang/StringBuilder."<init>":()V
      54: ldc           #204                // String Points before fold:
      56: invokevirtual #102                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      59: aload_1
      60: invokevirtual #202                // Method day13/Paper.countPoints:()I
      63: invokevirtual #207                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      66: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      69: getstatic     #213                // Field java/lang/System.out:Ljava/io/PrintStream;
      72: swap
      73: invokevirtual #219                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      76: new           #93                 // class java/lang/StringBuilder
      79: dup
      80: invokespecial #96                 // Method java/lang/StringBuilder."<init>":()V
      83: ldc           #221                // String Points after fold:
      85: invokevirtual #102                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      88: iload         5
      90: invokevirtual #207                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      93: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: getstatic     #213                // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #219                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  public static final void part2();
    Code:
       0: ldc           #187                // String day13.txt
       2: invokestatic  #189                // Method readFromFile:(Ljava/lang/String;)Lkotlin/Pair;
       5: astore_0
       6: aload_0
       7: invokevirtual #192                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      10: checkcast     #165                // class day13/Paper
      13: astore_1
      14: aload_0
      15: invokevirtual #195                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      18: checkcast     #50                 // class java/util/List
      21: astore_2
      22: aload_1
      23: aload_2
      24: invokevirtual #230                // Method day13/Paper.fold:(Ljava/util/List;)Lday13/Paper;
      27: astore_3
      28: aload_3
      29: invokevirtual #233                // Method day13/Paper.dump:()Ljava/lang/String;
      32: getstatic     #213                // Field java/lang/System.out:Ljava/io/PrintStream;
      35: swap
      36: invokevirtual #219                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      39: return

  public static final void main();
    Code:
       0: invokestatic  #236                // Method part2:()V
       3: return

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