package day17

import java.io.File
import kotlin.math.max

fun main() {
    val data = parse("src/main/kotlin/day17/Day17.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 17 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

@Suppress("SameParameterValue")
private fun parse(path: String): List<Int> =
    File(path).readText().trim()
        .map { if (it == '>') +1 else -1  }

private val shapes = listOf(
    setOf(0 to 0, 1 to 0, 2 to 0, 3 to 0),
    setOf(1 to 0, 0 to 1, 1 to 1, 2 to 1, 1 to 2),
    setOf(0 to 0, 1 to 0, 2 to 0, 2 to 1, 2 to 2),
    setOf(0 to 0, 0 to 1, 0 to 2, 0 to 3),
    setOf(0 to 0, 1 to 0, 0 to 1, 1 to 1),
)

private data class State(
    val shifts: List<Int>,
    val obstacles: MutableSet<Pair<Int, Int>> = mutableSetOf(),
    var shapeIndex: Int = 0,
    var shiftIndex: Int = 0,
    var height: Int = 0,
)

private data class Step(
    val ceiling: List<Int>,
    val shapeIndex: Int,
    val shiftIndex: Int,
)

private fun State.step() {
    var shape = shapes[shapeIndex++ % shapes.size]
        .map { (x, y) -> (2 + x) to (height + 3 + y) }
        .toSet()

    while (true) {
        val shift = shifts[shiftIndex++ % shifts.size]
        val shiftedShapeX = shape
            .map { (x, y) -> (x + shift) to y }
            .toSet()

        if (shiftedShapeX.all { (x, _) -> x in 0..6 }) {
            if ((shiftedShapeX intersect obstacles).isEmpty()) {
                shape = shiftedShapeX
            }
        }

        val shiftedShapeY = shape
            .map { (x, y) -> x to (y - 1) }
            .toSet()

        if (shiftedShapeY.all { (_, y) -> y >= 0 }) {
            if ((shiftedShapeY intersect obstacles).isEmpty()) {
                shape = shiftedShapeY
                continue
            }
        }

        break
    }

    obstacles += shape
    height = max(height, shape.maxOf { (_, y) -> y } + 1)
}

private fun solve(shifts: List<Int>, count: Long): Long {
    val state = State(shifts)
    val history = mutableMapOf<Step, Pair<Int, Int>>()
    while (true) {
        state.step()

        val highest = state.obstacles.maxOf { (_, y) -> y }
        val ceiling = state.obstacles
            .groupBy { (x, _) -> x }.entries
            .sortedBy { (x, _) -> x }
            .map { (_, points) -> points.maxOf { (_, y) -> y } }
            .let { ys -> ys.map { y -> highest - y } }

        val step = Step(
            ceiling = ceiling,
            shapeIndex = state.shapeIndex % shapes.size,
            shiftIndex = state.shiftIndex % shifts.size,
        )

        if (step !in history) {
            history[step] = state.shapeIndex to state.height
            continue
        }

        val (shapeCount, height) = history.getValue(step)
        val shapesPerCycle = state.shapeIndex - shapeCount
        val cycleCount = (count - shapeCount) / shapesPerCycle
        val cycleHeight = state.height - height
        val shapesRemain = (count - shapeCount) - (shapesPerCycle * cycleCount)

        repeat(shapesRemain.toInt()) {
            state.step()
        }

        return state.height + (cycleHeight * (cycleCount - 1))
    }
}

private fun part1(shifts: List<Int>): Long =
    solve(shifts, count = 2022L)

private fun part2(shifts: List<Int>): Long =
    solve(shifts, count = 1_000_000_000_000L)

Compiled from "Day17.kt"
public final class day17.Day17Kt {
  private static final java.util.List<java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>> shapes;

  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day17/Day17.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Ljava/util/List;)J
      10: lstore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/List;)J
      15: lstore_3
      16: ldc           #21                 // String 🎄 Day 17 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: lload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: lload_3
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final java.util.List<java.lang.Integer> parse(java.lang.String);
    Code:
       0: new           #65                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #68                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #74                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      14: checkcast     #76                 // class java/lang/CharSequence
      17: invokestatic  #82                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      20: invokevirtual #83                 // Method java/lang/Object.toString:()Ljava/lang/String;
      23: checkcast     #76                 // class java/lang/CharSequence
      26: astore_1
      27: nop
      28: iconst_0
      29: istore_2
      30: aload_1
      31: astore_3
      32: new           #85                 // class java/util/ArrayList
      35: dup
      36: aload_1
      37: invokeinterface #89,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      42: invokespecial #92                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #94                 // class java/util/Collection
      48: astore        4
      50: iconst_0
      51: istore        5
      53: iconst_0
      54: istore        6
      56: iload         6
      58: aload_3
      59: invokeinterface #89,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      64: if_icmpge     118
      67: aload_3
      68: iload         6
      70: invokeinterface #98,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      75: istore        7
      77: aload         4
      79: iload         7
      81: istore        8
      83: astore        10
      85: iconst_0
      86: istore        9
      88: iload         8
      90: bipush        62
      92: if_icmpne     99
      95: iconst_1
      96: goto          100
      99: iconst_m1
     100: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     103: aload         10
     105: swap
     106: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     111: pop
     112: iinc          6, 1
     115: goto          56
     118: aload         4
     120: checkcast     #110                // class java/util/List
     123: nop
     124: areturn

  private static final void step(day17.State);
    Code:
       0: getstatic     #131                // Field shapes:Ljava/util/List;
       3: aload_0
       4: invokevirtual #136                // Method day17/State.getShapeIndex:()I
       7: istore_2
       8: aload_0
       9: iload_2
      10: iconst_1
      11: iadd
      12: invokevirtual #139                // Method day17/State.setShapeIndex:(I)V
      15: iload_2
      16: getstatic     #131                // Field shapes:Ljava/util/List;
      19: invokeinterface #142,  1          // InterfaceMethod java/util/List.size:()I
      24: irem
      25: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      30: checkcast     #148                // class java/lang/Iterable
      33: astore_2
      34: nop
      35: iconst_0
      36: istore_3
      37: aload_2
      38: astore        4
      40: new           #85                 // class java/util/ArrayList
      43: dup
      44: aload_2
      45: bipush        10
      47: invokestatic  #154                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      50: invokespecial #92                 // Method java/util/ArrayList."<init>":(I)V
      53: checkcast     #94                 // class java/util/Collection
      56: astore        5
      58: iconst_0
      59: istore        6
      61: aload         4
      63: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      68: astore        7
      70: aload         7
      72: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          163
      80: aload         7
      82: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      87: astore        8
      89: aload         5
      91: aload         8
      93: checkcast     #170                // class kotlin/Pair
      96: astore        9
      98: astore        16
     100: iconst_0
     101: istore        10
     103: aload         9
     105: invokevirtual #173                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     108: checkcast     #175                // class java/lang/Number
     111: invokevirtual #178                // Method java/lang/Number.intValue:()I
     114: istore        11
     116: aload         9
     118: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     121: checkcast     #175                // class java/lang/Number
     124: invokevirtual #178                // Method java/lang/Number.intValue:()I
     127: istore        12
     129: iconst_2
     130: iload         11
     132: iadd
     133: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     136: aload_0
     137: invokevirtual #184                // Method day17/State.getHeight:()I
     140: iconst_3
     141: iadd
     142: iload         12
     144: iadd
     145: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     148: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     151: aload         16
     153: swap
     154: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     159: pop
     160: goto          70
     163: aload         5
     165: checkcast     #110                // class java/util/List
     168: nop
     169: checkcast     #148                // class java/lang/Iterable
     172: invokestatic  #194                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     175: astore_1
     176: nop
     177: aload_0
     178: invokevirtual #198                // Method day17/State.getShifts:()Ljava/util/List;
     181: aload_0
     182: invokevirtual #201                // Method day17/State.getShiftIndex:()I
     185: istore_3
     186: aload_0
     187: iload_3
     188: iconst_1
     189: iadd
     190: invokevirtual #204                // Method day17/State.setShiftIndex:(I)V
     193: iload_3
     194: aload_0
     195: invokevirtual #198                // Method day17/State.getShifts:()Ljava/util/List;
     198: invokeinterface #142,  1          // InterfaceMethod java/util/List.size:()I
     203: irem
     204: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     209: checkcast     #175                // class java/lang/Number
     212: invokevirtual #178                // Method java/lang/Number.intValue:()I
     215: istore_2
     216: aload_1
     217: checkcast     #148                // class java/lang/Iterable
     220: astore        4
     222: nop
     223: iconst_0
     224: istore        5
     226: aload         4
     228: astore        6
     230: new           #85                 // class java/util/ArrayList
     233: dup
     234: aload         4
     236: bipush        10
     238: invokestatic  #154                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     241: invokespecial #92                 // Method java/util/ArrayList."<init>":(I)V
     244: checkcast     #94                 // class java/util/Collection
     247: astore        7
     249: iconst_0
     250: istore        8
     252: aload         6
     254: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     259: astore        9
     261: aload         9
     263: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     268: ifeq          347
     271: aload         9
     273: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     278: astore        10
     280: aload         7
     282: aload         10
     284: checkcast     #170                // class kotlin/Pair
     287: astore        11
     289: astore        16
     291: iconst_0
     292: istore        12
     294: aload         11
     296: invokevirtual #173                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     299: checkcast     #175                // class java/lang/Number
     302: invokevirtual #178                // Method java/lang/Number.intValue:()I
     305: istore        13
     307: aload         11
     309: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     312: checkcast     #175                // class java/lang/Number
     315: invokevirtual #178                // Method java/lang/Number.intValue:()I
     318: istore        14
     320: iload         13
     322: iload_2
     323: iadd
     324: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     327: iload         14
     329: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     332: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     335: aload         16
     337: swap
     338: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     343: pop
     344: goto          261
     347: aload         7
     349: checkcast     #110                // class java/util/List
     352: nop
     353: checkcast     #148                // class java/lang/Iterable
     356: invokestatic  #194                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     359: astore_3
     360: aload_3
     361: checkcast     #148                // class java/lang/Iterable
     364: astore        4
     366: iconst_0
     367: istore        5
     369: aload         4
     371: instanceof    #94                 // class java/util/Collection
     374: ifeq          394
     377: aload         4
     379: checkcast     #94                 // class java/util/Collection
     382: invokeinterface #207,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     387: ifeq          394
     390: iconst_1
     391: goto          475
     394: aload         4
     396: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     401: astore        6
     403: aload         6
     405: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     410: ifeq          474
     413: aload         6
     415: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     420: astore        7
     422: aload         7
     424: checkcast     #170                // class kotlin/Pair
     427: astore        8
     429: iconst_0
     430: istore        9
     432: aload         8
     434: invokevirtual #173                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     437: checkcast     #175                // class java/lang/Number
     440: invokevirtual #178                // Method java/lang/Number.intValue:()I
     443: istore        10
     445: iconst_0
     446: iload         10
     448: if_icmpgt     466
     451: iload         10
     453: bipush        7
     455: if_icmpge     462
     458: iconst_1
     459: goto          467
     462: iconst_0
     463: goto          467
     466: iconst_0
     467: ifne          403
     470: iconst_0
     471: goto          475
     474: iconst_1
     475: ifeq          502
     478: aload_3
     479: checkcast     #148                // class java/lang/Iterable
     482: aload_0
     483: invokevirtual #211                // Method day17/State.getObstacles:()Ljava/util/Set;
     486: checkcast     #148                // class java/lang/Iterable
     489: invokestatic  #215                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     492: invokeinterface #218,  1          // InterfaceMethod java/util/Set.isEmpty:()Z
     497: ifeq          502
     500: aload_3
     501: astore_1
     502: aload_1
     503: checkcast     #148                // class java/lang/Iterable
     506: astore        5
     508: nop
     509: iconst_0
     510: istore        6
     512: aload         5
     514: astore        7
     516: new           #85                 // class java/util/ArrayList
     519: dup
     520: aload         5
     522: bipush        10
     524: invokestatic  #154                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     527: invokespecial #92                 // Method java/util/ArrayList."<init>":(I)V
     530: checkcast     #94                 // class java/util/Collection
     533: astore        8
     535: iconst_0
     536: istore        9
     538: aload         7
     540: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     545: astore        10
     547: aload         10
     549: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     554: ifeq          633
     557: aload         10
     559: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     564: astore        11
     566: aload         8
     568: aload         11
     570: checkcast     #170                // class kotlin/Pair
     573: astore        12
     575: astore        16
     577: iconst_0
     578: istore        13
     580: aload         12
     582: invokevirtual #173                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     585: checkcast     #175                // class java/lang/Number
     588: invokevirtual #178                // Method java/lang/Number.intValue:()I
     591: istore        14
     593: aload         12
     595: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     598: checkcast     #175                // class java/lang/Number
     601: invokevirtual #178                // Method java/lang/Number.intValue:()I
     604: istore        15
     606: iload         14
     608: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     611: iload         15
     613: iconst_1
     614: isub
     615: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     618: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     621: aload         16
     623: swap
     624: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     629: pop
     630: goto          547
     633: aload         8
     635: checkcast     #110                // class java/util/List
     638: nop
     639: checkcast     #148                // class java/lang/Iterable
     642: invokestatic  #194                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     645: astore        4
     647: aload         4
     649: checkcast     #148                // class java/lang/Iterable
     652: astore        5
     654: iconst_0
     655: istore        6
     657: aload         5
     659: instanceof    #94                 // class java/util/Collection
     662: ifeq          682
     665: aload         5
     667: checkcast     #94                 // class java/util/Collection
     670: invokeinterface #207,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     675: ifeq          682
     678: iconst_1
     679: goto          751
     682: aload         5
     684: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     689: astore        7
     691: aload         7
     693: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     698: ifeq          750
     701: aload         7
     703: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     708: astore        8
     710: aload         8
     712: checkcast     #170                // class kotlin/Pair
     715: astore        9
     717: iconst_0
     718: istore        10
     720: aload         9
     722: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     725: checkcast     #175                // class java/lang/Number
     728: invokevirtual #178                // Method java/lang/Number.intValue:()I
     731: istore        11
     733: iload         11
     735: iflt          742
     738: iconst_1
     739: goto          743
     742: iconst_0
     743: ifne          691
     746: iconst_0
     747: goto          751
     750: iconst_1
     751: ifeq          783
     754: aload         4
     756: checkcast     #148                // class java/lang/Iterable
     759: aload_0
     760: invokevirtual #211                // Method day17/State.getObstacles:()Ljava/util/Set;
     763: checkcast     #148                // class java/lang/Iterable
     766: invokestatic  #215                // Method kotlin/collections/CollectionsKt.intersect:(Ljava/lang/Iterable;Ljava/lang/Iterable;)Ljava/util/Set;
     769: invokeinterface #218,  1          // InterfaceMethod java/util/Set.isEmpty:()Z
     774: ifeq          783
     777: aload         4
     779: astore_1
     780: goto          176
     783: nop
     784: aload_0
     785: invokevirtual #211                // Method day17/State.getObstacles:()Ljava/util/Set;
     788: checkcast     #94                 // class java/util/Collection
     791: aload_1
     792: checkcast     #148                // class java/lang/Iterable
     795: invokestatic  #222                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     798: pop
     799: aload_0
     800: aload_0
     801: invokevirtual #184                // Method day17/State.getHeight:()I
     804: istore_2
     805: aload_1
     806: checkcast     #148                // class java/lang/Iterable
     809: astore_3
     810: astore        16
     812: aload_3
     813: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     818: astore        4
     820: aload         4
     822: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     827: ifne          838
     830: new           #224                // class java/util/NoSuchElementException
     833: dup
     834: invokespecial #225                // Method java/util/NoSuchElementException."<init>":()V
     837: athrow
     838: aload         4
     840: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     845: checkcast     #170                // class kotlin/Pair
     848: astore        5
     850: iconst_0
     851: istore        6
     853: aload         5
     855: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     858: checkcast     #175                // class java/lang/Number
     861: invokevirtual #178                // Method java/lang/Number.intValue:()I
     864: istore        7
     866: iload         7
     868: istore        5
     870: aload         4
     872: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     877: ifeq          926
     880: aload         4
     882: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     887: checkcast     #170                // class kotlin/Pair
     890: astore        6
     892: iconst_0
     893: istore        7
     895: aload         6
     897: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     900: checkcast     #175                // class java/lang/Number
     903: invokevirtual #178                // Method java/lang/Number.intValue:()I
     906: istore        8
     908: iload         8
     910: istore        6
     912: iload         5
     914: iload         6
     916: if_icmpge     870
     919: iload         6
     921: istore        5
     923: goto          870
     926: iload         5
     928: istore        17
     930: aload         16
     932: iload         17
     934: iconst_1
     935: iadd
     936: istore_3
     937: iload_2
     938: iload_3
     939: invokestatic  #231                // Method java/lang/Math.max:(II)I
     942: invokevirtual #234                // Method day17/State.setHeight:(I)V
     945: return

  private static final long solve(java.util.List<java.lang.Integer>, long);
    Code:
       0: new           #133                // class day17/State
       3: dup
       4: aload_0
       5: aconst_null
       6: iconst_0
       7: iconst_0
       8: iconst_0
       9: bipush        30
      11: aconst_null
      12: invokespecial #260                // Method day17/State."<init>":(Ljava/util/List;Ljava/util/Set;IIIILkotlin/jvm/internal/DefaultConstructorMarker;)V
      15: astore_3
      16: new           #262                // class java/util/LinkedHashMap
      19: dup
      20: invokespecial #263                // Method java/util/LinkedHashMap."<init>":()V
      23: checkcast     #265                // class java/util/Map
      26: astore        4
      28: nop
      29: aload_3
      30: invokestatic  #267                // Method step:(Lday17/State;)V
      33: aload_3
      34: invokevirtual #211                // Method day17/State.getObstacles:()Ljava/util/Set;
      37: checkcast     #148                // class java/lang/Iterable
      40: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        7
      47: aload         7
      49: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifne          65
      57: new           #224                // class java/util/NoSuchElementException
      60: dup
      61: invokespecial #225                // Method java/util/NoSuchElementException."<init>":()V
      64: athrow
      65: aload         7
      67: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: checkcast     #170                // class kotlin/Pair
      75: astore        8
      77: iconst_0
      78: istore        9
      80: aload         8
      82: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      85: checkcast     #175                // class java/lang/Number
      88: invokevirtual #178                // Method java/lang/Number.intValue:()I
      91: istore        10
      93: iload         10
      95: istore        8
      97: aload         7
      99: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     104: ifeq          153
     107: aload         7
     109: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     114: checkcast     #170                // class kotlin/Pair
     117: astore        9
     119: iconst_0
     120: istore        10
     122: aload         9
     124: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     127: checkcast     #175                // class java/lang/Number
     130: invokevirtual #178                // Method java/lang/Number.intValue:()I
     133: istore        11
     135: iload         11
     137: istore        9
     139: iload         8
     141: iload         9
     143: if_icmpge     97
     146: iload         9
     148: istore        8
     150: goto          97
     153: iload         8
     155: istore        5
     157: aload_3
     158: invokevirtual #211                // Method day17/State.getObstacles:()Ljava/util/Set;
     161: checkcast     #148                // class java/lang/Iterable
     164: astore        7
     166: nop
     167: iconst_0
     168: istore        8
     170: aload         7
     172: astore        9
     174: new           #262                // class java/util/LinkedHashMap
     177: dup
     178: invokespecial #263                // Method java/util/LinkedHashMap."<init>":()V
     181: checkcast     #265                // class java/util/Map
     184: astore        10
     186: iconst_0
     187: istore        11
     189: aload         9
     191: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     196: astore        12
     198: aload         12
     200: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     205: ifeq          323
     208: aload         12
     210: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     215: astore        13
     217: aload         13
     219: checkcast     #170                // class kotlin/Pair
     222: astore        14
     224: iconst_0
     225: istore        15
     227: aload         14
     229: invokevirtual #173                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     232: checkcast     #175                // class java/lang/Number
     235: invokevirtual #178                // Method java/lang/Number.intValue:()I
     238: istore        16
     240: iload         16
     242: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: astore        17
     247: aload         10
     249: astore        18
     251: iconst_0
     252: istore        19
     254: aload         18
     256: aload         17
     258: invokeinterface #270,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     263: astore        20
     265: aload         20
     267: ifnonnull     302
     270: iconst_0
     271: istore        21
     273: new           #85                 // class java/util/ArrayList
     276: dup
     277: invokespecial #271                // Method java/util/ArrayList."<init>":()V
     280: checkcast     #110                // class java/util/List
     283: astore        21
     285: aload         18
     287: aload         17
     289: aload         21
     291: invokeinterface #275,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     296: pop
     297: aload         21
     299: goto          304
     302: aload         20
     304: nop
     305: checkcast     #110                // class java/util/List
     308: astore        14
     310: aload         14
     312: aload         13
     314: invokeinterface #276,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     319: pop
     320: goto          198
     323: aload         10
     325: nop
     326: invokeinterface #279,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     331: checkcast     #148                // class java/lang/Iterable
     334: astore        7
     336: nop
     337: iconst_0
     338: istore        8
     340: aload         7
     342: new           #281                // class day17/Day17Kt$solve$$inlined$sortedBy$1
     345: dup
     346: invokespecial #282                // Method day17/Day17Kt$solve$$inlined$sortedBy$1."<init>":()V
     349: checkcast     #284                // class java/util/Comparator
     352: invokestatic  #288                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     355: checkcast     #148                // class java/lang/Iterable
     358: astore        7
     360: nop
     361: iconst_0
     362: istore        8
     364: aload         7
     366: astore        9
     368: new           #85                 // class java/util/ArrayList
     371: dup
     372: aload         7
     374: bipush        10
     376: invokestatic  #154                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     379: invokespecial #92                 // Method java/util/ArrayList."<init>":(I)V
     382: checkcast     #94                 // class java/util/Collection
     385: astore        10
     387: iconst_0
     388: istore        11
     390: aload         9
     392: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     397: astore        12
     399: aload         12
     401: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     406: ifeq          580
     409: aload         12
     411: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     416: astore        13
     418: aload         10
     420: aload         13
     422: checkcast     #290                // class java/util/Map$Entry
     425: astore        14
     427: astore        22
     429: iconst_0
     430: istore        15
     432: aload         14
     434: invokeinterface #293,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     439: checkcast     #110                // class java/util/List
     442: astore        16
     444: aload         16
     446: checkcast     #148                // class java/lang/Iterable
     449: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     454: astore        17
     456: aload         17
     458: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     463: ifne          474
     466: new           #224                // class java/util/NoSuchElementException
     469: dup
     470: invokespecial #225                // Method java/util/NoSuchElementException."<init>":()V
     473: athrow
     474: aload         17
     476: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     481: checkcast     #170                // class kotlin/Pair
     484: astore        18
     486: iconst_0
     487: istore        19
     489: aload         18
     491: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     494: checkcast     #175                // class java/lang/Number
     497: invokevirtual #178                // Method java/lang/Number.intValue:()I
     500: istore        20
     502: iload         20
     504: istore        18
     506: aload         17
     508: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     513: ifeq          562
     516: aload         17
     518: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     523: checkcast     #170                // class kotlin/Pair
     526: astore        19
     528: iconst_0
     529: istore        20
     531: aload         19
     533: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     536: checkcast     #175                // class java/lang/Number
     539: invokevirtual #178                // Method java/lang/Number.intValue:()I
     542: istore        21
     544: iload         21
     546: istore        19
     548: iload         18
     550: iload         19
     552: if_icmpge     506
     555: iload         19
     557: istore        18
     559: goto          506
     562: iload         18
     564: nop
     565: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     568: aload         22
     570: swap
     571: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     576: pop
     577: goto          399
     580: aload         10
     582: checkcast     #110                // class java/util/List
     585: nop
     586: astore        8
     588: iconst_0
     589: istore        9
     591: aload         8
     593: checkcast     #148                // class java/lang/Iterable
     596: astore        10
     598: iconst_0
     599: istore        11
     601: aload         10
     603: astore        12
     605: new           #85                 // class java/util/ArrayList
     608: dup
     609: aload         10
     611: bipush        10
     613: invokestatic  #154                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     616: invokespecial #92                 // Method java/util/ArrayList."<init>":(I)V
     619: checkcast     #94                 // class java/util/Collection
     622: astore        13
     624: iconst_0
     625: istore        14
     627: aload         12
     629: invokeinterface #158,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     634: astore        15
     636: aload         15
     638: invokeinterface #164,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     643: ifeq          692
     646: aload         15
     648: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     653: astore        16
     655: aload         13
     657: aload         16
     659: checkcast     #175                // class java/lang/Number
     662: invokevirtual #178                // Method java/lang/Number.intValue:()I
     665: istore        17
     667: astore        18
     669: iconst_0
     670: istore        19
     672: iload         5
     674: iload         17
     676: isub
     677: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     680: aload         18
     682: swap
     683: invokeinterface #108,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     688: pop
     689: goto          636
     692: aload         13
     694: checkcast     #110                // class java/util/List
     697: nop
     698: nop
     699: nop
     700: astore        6
     702: new           #295                // class day17/Step
     705: dup
     706: aload         6
     708: aload_3
     709: invokevirtual #136                // Method day17/State.getShapeIndex:()I
     712: getstatic     #131                // Field shapes:Ljava/util/List;
     715: invokeinterface #142,  1          // InterfaceMethod java/util/List.size:()I
     720: irem
     721: aload_3
     722: invokevirtual #201                // Method day17/State.getShiftIndex:()I
     725: aload_0
     726: invokeinterface #142,  1          // InterfaceMethod java/util/List.size:()I
     731: irem
     732: invokespecial #298                // Method day17/Step."<init>":(Ljava/util/List;II)V
     735: astore        7
     737: aload         4
     739: aload         7
     741: invokeinterface #301,  2          // InterfaceMethod java/util/Map.containsKey:(Ljava/lang/Object;)Z
     746: ifne          779
     749: aload         4
     751: aload         7
     753: aload_3
     754: invokevirtual #136                // Method day17/State.getShapeIndex:()I
     757: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     760: aload_3
     761: invokevirtual #184                // Method day17/State.getHeight:()I
     764: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     767: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     770: invokeinterface #275,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     775: pop
     776: goto          28
     779: aload         4
     781: aload         7
     783: invokestatic  #306                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     786: checkcast     #170                // class kotlin/Pair
     789: astore        8
     791: aload         8
     793: invokevirtual #173                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     796: checkcast     #175                // class java/lang/Number
     799: invokevirtual #178                // Method java/lang/Number.intValue:()I
     802: istore        9
     804: aload         8
     806: invokevirtual #181                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     809: checkcast     #175                // class java/lang/Number
     812: invokevirtual #178                // Method java/lang/Number.intValue:()I
     815: istore        10
     817: aload_3
     818: invokevirtual #136                // Method day17/State.getShapeIndex:()I
     821: iload         9
     823: isub
     824: istore        11
     826: lload_1
     827: iload         9
     829: i2l
     830: lsub
     831: iload         11
     833: i2l
     834: ldiv
     835: lstore        12
     837: aload_3
     838: invokevirtual #184                // Method day17/State.getHeight:()I
     841: iload         10
     843: isub
     844: istore        14
     846: lload_1
     847: iload         9
     849: i2l
     850: lsub
     851: iload         11
     853: i2l
     854: lload         12
     856: lmul
     857: lsub
     858: lstore        15
     860: lload         15
     862: l2i
     863: istore        17
     865: iconst_0
     866: istore        18
     868: iload         18
     870: iload         17
     872: if_icmpge     893
     875: iload         18
     877: istore        19
     879: iconst_0
     880: istore        20
     882: aload_3
     883: invokestatic  #267                // Method step:(Lday17/State;)V
     886: nop
     887: iinc          18, 1
     890: goto          868
     893: aload_3
     894: invokevirtual #184                // Method day17/State.getHeight:()I
     897: i2l
     898: iload         14
     900: i2l
     901: lload         12
     903: lconst_1
     904: lsub
     905: lmul
     906: ladd
     907: lreturn

  private static final long part1(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc2_w        #345                // long 2022l
       4: invokestatic  #348                // Method solve:(Ljava/util/List;J)J
       7: lreturn

  private static final long part2(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc2_w        #349                // long 1000000000000l
       4: invokestatic  #348                // Method solve:(Ljava/util/List;J)J
       7: lreturn

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

  static {};
    Code:
       0: iconst_5
       1: anewarray     #217                // class java/util/Set
       4: astore_0
       5: aload_0
       6: iconst_0
       7: iconst_4
       8: anewarray     #170                // class kotlin/Pair
      11: astore_1
      12: aload_1
      13: iconst_0
      14: iconst_0
      15: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: iconst_0
      19: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      22: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      25: aastore
      26: aload_1
      27: iconst_1
      28: iconst_1
      29: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: iconst_0
      33: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      39: aastore
      40: aload_1
      41: iconst_2
      42: iconst_2
      43: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: iconst_0
      47: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      53: aastore
      54: aload_1
      55: iconst_3
      56: iconst_3
      57: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      60: iconst_0
      61: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      64: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      67: aastore
      68: aload_1
      69: invokestatic  #362                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
      72: aastore
      73: aload_0
      74: iconst_1
      75: iconst_5
      76: anewarray     #170                // class kotlin/Pair
      79: astore_1
      80: aload_1
      81: iconst_0
      82: iconst_1
      83: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: iconst_0
      87: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      90: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      93: aastore
      94: aload_1
      95: iconst_1
      96: iconst_0
      97: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     100: iconst_1
     101: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     107: aastore
     108: aload_1
     109: iconst_2
     110: iconst_1
     111: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: iconst_1
     115: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     118: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     121: aastore
     122: aload_1
     123: iconst_3
     124: iconst_2
     125: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     128: iconst_1
     129: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     132: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     135: aastore
     136: aload_1
     137: iconst_4
     138: iconst_1
     139: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     142: iconst_2
     143: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     146: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     149: aastore
     150: aload_1
     151: invokestatic  #362                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     154: aastore
     155: aload_0
     156: iconst_2
     157: iconst_5
     158: anewarray     #170                // class kotlin/Pair
     161: astore_1
     162: aload_1
     163: iconst_0
     164: iconst_0
     165: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     168: iconst_0
     169: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     172: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     175: aastore
     176: aload_1
     177: iconst_1
     178: iconst_1
     179: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     182: iconst_0
     183: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     186: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     189: aastore
     190: aload_1
     191: iconst_2
     192: iconst_2
     193: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     196: iconst_0
     197: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     200: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     203: aastore
     204: aload_1
     205: iconst_3
     206: iconst_2
     207: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: iconst_1
     211: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     214: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     217: aastore
     218: aload_1
     219: iconst_4
     220: iconst_2
     221: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     224: iconst_2
     225: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     228: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     231: aastore
     232: aload_1
     233: invokestatic  #362                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     236: aastore
     237: aload_0
     238: iconst_3
     239: iconst_4
     240: anewarray     #170                // class kotlin/Pair
     243: astore_1
     244: aload_1
     245: iconst_0
     246: iconst_0
     247: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     250: iconst_0
     251: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     254: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     257: aastore
     258: aload_1
     259: iconst_1
     260: iconst_0
     261: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     264: iconst_1
     265: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     268: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     271: aastore
     272: aload_1
     273: iconst_2
     274: iconst_0
     275: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     278: iconst_2
     279: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     282: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     285: aastore
     286: aload_1
     287: iconst_3
     288: iconst_0
     289: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     292: iconst_3
     293: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     296: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     299: aastore
     300: aload_1
     301: invokestatic  #362                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     304: aastore
     305: aload_0
     306: iconst_4
     307: iconst_4
     308: anewarray     #170                // class kotlin/Pair
     311: astore_1
     312: aload_1
     313: iconst_0
     314: iconst_0
     315: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     318: iconst_0
     319: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     322: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     325: aastore
     326: aload_1
     327: iconst_1
     328: iconst_1
     329: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     332: iconst_0
     333: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     336: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     339: aastore
     340: aload_1
     341: iconst_2
     342: iconst_0
     343: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     346: iconst_1
     347: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     350: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     353: aastore
     354: aload_1
     355: iconst_3
     356: iconst_1
     357: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     360: iconst_1
     361: invokestatic  #104                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     364: invokestatic  #190                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     367: aastore
     368: aload_1
     369: invokestatic  #362                // Method kotlin/collections/SetsKt.setOf:([Ljava/lang/Object;)Ljava/util/Set;
     372: aastore
     373: aload_0
     374: invokestatic  #366                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     377: putstatic     #131                // Field shapes:Ljava/util/List;
     380: return
}

Compiled from "Comparisons.kt"
public final class day17.Day17Kt$solve$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public day17.Day17Kt$solve$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class java/util/Map$Entry
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokeinterface #27,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      14: checkcast     #29                 // class java/lang/Number
      17: invokevirtual #33                 // Method java/lang/Number.intValue:()I
      20: istore        5
      22: iload         5
      24: invokestatic  #39                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      27: checkcast     #41                 // class java/lang/Comparable
      30: aload_2
      31: checkcast     #23                 // class java/util/Map$Entry
      34: astore_3
      35: astore        6
      37: iconst_0
      38: istore        4
      40: aload_3
      41: invokeinterface #27,  1           // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      46: checkcast     #29                 // class java/lang/Number
      49: invokevirtual #33                 // Method java/lang/Number.intValue:()I
      52: istore        5
      54: iload         5
      56: invokestatic  #39                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: aload         6
      61: swap
      62: checkcast     #41                 // class java/lang/Comparable
      65: invokestatic  #47                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      68: ireturn
}


package day21

import java.io.File

fun main() {
    val data = parse("src/main/kotlin/day21/Day21.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 21 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private sealed interface Monkey {
    data class Yelling(
        val number: Long,
    ) : Monkey

    data class Operation(
        val lhs: String,
        val rhs: String,
        val op: String,
    ) : Monkey
}

@Suppress("SameParameterValue")
private fun parse(path: String): Map<String, Monkey> {
    val data = mutableMapOf<String, Monkey>()
    File(path).forEachLine { line ->
        val (name, job) = line.split(": ")
        val monkey = job.toLongOrNull()?.let { Monkey.Yelling(it) } ?: run {
            val (lhs, op, rhs) = job.split(" ")
            Monkey.Operation(lhs, rhs, op)
        }
        data[name] = monkey
    }
    return data
}

private fun Monkey.evaluate(ctx: Map<String, Monkey>): Long =
    when (this) {
        is Monkey.Yelling -> number
        is Monkey.Operation -> {
            val lhsNumber = ctx.getValue(lhs).evaluate(ctx)
            val rhsNumber = ctx.getValue(rhs).evaluate(ctx)
            when (op) {
                "+" -> lhsNumber + rhsNumber
                "-" -> lhsNumber - rhsNumber
                "*" -> lhsNumber * rhsNumber
                "/" -> lhsNumber / rhsNumber
                else -> error("Unknown operation: $op")
            }
        }
    }

private fun Monkey.evaluateOrNull(ctx: Map<String, Monkey>): Long? {
    return when (this) {
        is Monkey.Yelling -> number
        is Monkey.Operation -> {
            if (lhs == "humn" || rhs == "humn") {
                return null
            }

            val lhsNumber = ctx.getValue(lhs).evaluateOrNull(ctx) ?: return null
            val rhsNumber = ctx.getValue(rhs).evaluateOrNull(ctx) ?: return null
            when (op) {
                "+" -> lhsNumber + rhsNumber
                "-" -> lhsNumber - rhsNumber
                "*" -> lhsNumber * rhsNumber
                "/" -> lhsNumber / rhsNumber
                else -> error("Unknown operation: $op")
            }
        }
    }
}

private fun Monkey.coerce(ctx: Map<String, Monkey>, expected: Long): Long {
    return when (this) {
        is Monkey.Yelling -> expected
        is Monkey.Operation -> {
            ctx.getValue(rhs).evaluateOrNull(ctx)?.let { value ->
                val next = ctx.getValue(lhs)
                return when (op) {
                    "+" -> next.coerce(ctx, expected - value)
                    "-" -> next.coerce(ctx, expected + value)
                    "*" -> next.coerce(ctx, expected / value)
                    "/" -> next.coerce(ctx, expected * value)
                    else -> error("Unknown operation: $op")
                }
            }
            ctx.getValue(lhs).evaluateOrNull(ctx)?.let { value ->
                val next = ctx.getValue(rhs)
                return when (op) {
                    "+" -> next.coerce(ctx, expected - value)
                    "-" -> next.coerce(ctx, value - expected)
                    "*" -> next.coerce(ctx, expected / value)
                    "/" -> next.coerce(ctx, value / expected)
                    else -> error("Unknown operation: $op")
                }
            }
            error("Cannot evaluate either branch.")
        }
    }
}

private fun part1(data: Map<String, Monkey>): Long =
    data.getValue("root").evaluate(data)

private fun part2(data: Map<String, Monkey>): Long {
    val (lhs, rhs, _) = data["root"] as Monkey.Operation
    data.getValue(lhs).evaluateOrNull(data)?.let { expected ->
        return data.getValue(rhs).coerce(data, expected)
    }
    data.getValue(rhs).evaluateOrNull(data)?.let { expected ->
        return data.getValue(lhs).coerce(data, expected)
    }
    error("Cannot evaluate either branch.")
}

Compiled from "Day21.kt"
public final class day21.Day21Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day21/Day21.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/Map;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Ljava/util/Map;)J
      10: lstore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/Map;)J
      15: lstore_3
      16: ldc           #21                 // String 🎄 Day 21 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: lload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: lload_3
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final java.util.Map<java.lang.String, day21.Monkey> parse(java.lang.String);
    Code:
       0: new           #65                 // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #66                 // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #68                 // class java/util/Map
      10: astore_1
      11: new           #70                 // class java/io/File
      14: dup
      15: aload_0
      16: invokespecial #73                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      19: aconst_null
      20: aload_1
      21: invokedynamic #93,  0             // InvokeDynamic #0:invoke:(Ljava/util/Map;)Lkotlin/jvm/functions/Function1;
      26: iconst_1
      27: aconst_null
      28: invokestatic  #99                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      31: aload_1
      32: areturn

  private static final long evaluate(day21.Monkey, java.util.Map<java.lang.String, ? extends day21.Monkey>);
    Code:
       0: aload_0
       1: astore_2
       2: aload_2
       3: instanceof    #106                // class day21/Monkey$Yelling
       6: ifeq          19
       9: aload_0
      10: checkcast     #106                // class day21/Monkey$Yelling
      13: invokevirtual #110                // Method day21/Monkey$Yelling.getNumber:()J
      16: goto          240
      19: aload_2
      20: instanceof    #112                // class day21/Monkey$Operation
      23: ifeq          232
      26: aload_1
      27: aload_0
      28: checkcast     #112                // class day21/Monkey$Operation
      31: invokevirtual #115                // Method day21/Monkey$Operation.getLhs:()Ljava/lang/String;
      34: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      37: checkcast     #123                // class day21/Monkey
      40: aload_1
      41: invokestatic  #125                // Method evaluate:(Lday21/Monkey;Ljava/util/Map;)J
      44: lstore_3
      45: aload_1
      46: aload_0
      47: checkcast     #112                // class day21/Monkey$Operation
      50: invokevirtual #128                // Method day21/Monkey$Operation.getRhs:()Ljava/lang/String;
      53: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      56: checkcast     #123                // class day21/Monkey
      59: aload_1
      60: invokestatic  #125                // Method evaluate:(Lday21/Monkey;Ljava/util/Map;)J
      63: lstore        5
      65: aload_0
      66: checkcast     #112                // class day21/Monkey$Operation
      69: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
      72: astore        7
      74: aload         7
      76: invokevirtual #137                // Method java/lang/String.hashCode:()I
      79: tableswitch   { // 42 to 47
                    42: 116
                    43: 129
                    44: 196
                    45: 142
                    46: 196
                    47: 155
               default: 196
          }
     116: aload         7
     118: ldc           #139                // String *
     120: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     123: ifne          182
     126: goto          196
     129: aload         7
     131: ldc           #145                // String +
     133: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     136: ifne          168
     139: goto          196
     142: aload         7
     144: ldc           #147                // String -
     146: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     149: ifne          175
     152: goto          196
     155: aload         7
     157: ldc           #149                // String /
     159: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     162: ifne          189
     165: goto          196
     168: lload_3
     169: lload         5
     171: ladd
     172: goto          240
     175: lload_3
     176: lload         5
     178: lsub
     179: goto          240
     182: lload_3
     183: lload         5
     185: lmul
     186: goto          240
     189: lload_3
     190: lload         5
     192: ldiv
     193: goto          240
     196: new           #151                // class java/lang/IllegalStateException
     199: dup
     200: new           #39                 // class java/lang/StringBuilder
     203: dup
     204: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
     207: ldc           #153                // String Unknown operation:
     209: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     212: aload_0
     213: checkcast     #112                // class day21/Monkey$Operation
     216: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
     219: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     222: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     225: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     228: invokespecial #155                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     231: athrow
     232: new           #157                // class kotlin/NoWhenBranchMatchedException
     235: dup
     236: invokespecial #158                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     239: athrow
     240: lreturn

  private static final java.lang.Long evaluateOrNull(day21.Monkey, java.util.Map<java.lang.String, ? extends day21.Monkey>);
    Code:
       0: aload_0
       1: astore_2
       2: aload_2
       3: instanceof    #106                // class day21/Monkey$Yelling
       6: ifeq          22
       9: aload_0
      10: checkcast     #106                // class day21/Monkey$Yelling
      13: invokevirtual #110                // Method day21/Monkey$Yelling.getNumber:()J
      16: invokestatic  #172                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      19: goto          310
      22: aload_2
      23: instanceof    #112                // class day21/Monkey$Operation
      26: ifeq          302
      29: aload_0
      30: checkcast     #112                // class day21/Monkey$Operation
      33: invokevirtual #115                // Method day21/Monkey$Operation.getLhs:()Ljava/lang/String;
      36: ldc           #174                // String humn
      38: invokestatic  #180                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      41: ifne          59
      44: aload_0
      45: checkcast     #112                // class day21/Monkey$Operation
      48: invokevirtual #128                // Method day21/Monkey$Operation.getRhs:()Ljava/lang/String;
      51: ldc           #174                // String humn
      53: invokestatic  #180                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      56: ifeq          61
      59: aconst_null
      60: areturn
      61: aload_1
      62: aload_0
      63: checkcast     #112                // class day21/Monkey$Operation
      66: invokevirtual #115                // Method day21/Monkey$Operation.getLhs:()Ljava/lang/String;
      69: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      72: checkcast     #123                // class day21/Monkey
      75: aload_1
      76: invokestatic  #182                // Method evaluateOrNull:(Lday21/Monkey;Ljava/util/Map;)Ljava/lang/Long;
      79: dup
      80: ifnull        89
      83: invokevirtual #185                // Method java/lang/Long.longValue:()J
      86: goto          92
      89: pop
      90: aconst_null
      91: areturn
      92: lstore_3
      93: aload_1
      94: aload_0
      95: checkcast     #112                // class day21/Monkey$Operation
      98: invokevirtual #128                // Method day21/Monkey$Operation.getRhs:()Ljava/lang/String;
     101: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     104: checkcast     #123                // class day21/Monkey
     107: aload_1
     108: invokestatic  #182                // Method evaluateOrNull:(Lday21/Monkey;Ljava/util/Map;)Ljava/lang/Long;
     111: dup
     112: ifnull        121
     115: invokevirtual #185                // Method java/lang/Long.longValue:()J
     118: goto          124
     121: pop
     122: aconst_null
     123: areturn
     124: lstore        5
     126: aload_0
     127: checkcast     #112                // class day21/Monkey$Operation
     130: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
     133: astore        7
     135: aload         7
     137: invokevirtual #137                // Method java/lang/String.hashCode:()I
     140: tableswitch   { // 42 to 47
                    42: 180
                    43: 193
                    44: 260
                    45: 206
                    46: 260
                    47: 219
               default: 260
          }
     180: aload         7
     182: ldc           #139                // String *
     184: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     187: ifne          246
     190: goto          260
     193: aload         7
     195: ldc           #145                // String +
     197: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     200: ifne          232
     203: goto          260
     206: aload         7
     208: ldc           #147                // String -
     210: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     213: ifne          239
     216: goto          260
     219: aload         7
     221: ldc           #149                // String /
     223: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     226: ifne          253
     229: goto          260
     232: lload_3
     233: lload         5
     235: ladd
     236: goto          296
     239: lload_3
     240: lload         5
     242: lsub
     243: goto          296
     246: lload_3
     247: lload         5
     249: lmul
     250: goto          296
     253: lload_3
     254: lload         5
     256: ldiv
     257: goto          296
     260: new           #151                // class java/lang/IllegalStateException
     263: dup
     264: new           #39                 // class java/lang/StringBuilder
     267: dup
     268: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
     271: ldc           #153                // String Unknown operation:
     273: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     276: aload_0
     277: checkcast     #112                // class day21/Monkey$Operation
     280: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
     283: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     286: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     289: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     292: invokespecial #155                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     295: athrow
     296: invokestatic  #172                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     299: goto          310
     302: new           #157                // class kotlin/NoWhenBranchMatchedException
     305: dup
     306: invokespecial #158                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     309: athrow
     310: areturn

  private static final long coerce(day21.Monkey, java.util.Map<java.lang.String, ? extends day21.Monkey>, long);
    Code:
       0: aload_0
       1: astore        4
       3: aload         4
       5: instanceof    #106                // class day21/Monkey$Yelling
       8: ifeq          15
      11: lload_2
      12: goto          538
      15: aload         4
      17: instanceof    #112                // class day21/Monkey$Operation
      20: ifeq          530
      23: aload_1
      24: aload_0
      25: checkcast     #112                // class day21/Monkey$Operation
      28: invokevirtual #128                // Method day21/Monkey$Operation.getRhs:()Ljava/lang/String;
      31: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      34: checkcast     #123                // class day21/Monkey
      37: aload_1
      38: invokestatic  #182                // Method evaluateOrNull:(Lday21/Monkey;Ljava/util/Map;)Ljava/lang/Long;
      41: astore        5
      43: aload         5
      45: ifnull        269
      48: aload         5
      50: checkcast     #191                // class java/lang/Number
      53: invokevirtual #192                // Method java/lang/Number.longValue:()J
      56: lstore        6
      58: iconst_0
      59: istore        8
      61: aload_1
      62: aload_0
      63: checkcast     #112                // class day21/Monkey$Operation
      66: invokevirtual #115                // Method day21/Monkey$Operation.getLhs:()Ljava/lang/String;
      69: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      72: checkcast     #123                // class day21/Monkey
      75: astore        9
      77: aload_0
      78: checkcast     #112                // class day21/Monkey$Operation
      81: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
      84: astore        10
      86: aload         10
      88: invokevirtual #137                // Method java/lang/String.hashCode:()I
      91: tableswitch   { // 42 to 47
                    42: 128
                    43: 141
                    44: 232
                    45: 154
                    46: 232
                    47: 167
               default: 232
          }
     128: aload         10
     130: ldc           #139                // String *
     132: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     135: ifne          206
     138: goto          232
     141: aload         10
     143: ldc           #145                // String +
     145: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     148: ifne          180
     151: goto          232
     154: aload         10
     156: ldc           #147                // String -
     158: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     161: ifne          193
     164: goto          232
     167: aload         10
     169: ldc           #149                // String /
     171: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     174: ifne          219
     177: goto          232
     180: aload         9
     182: aload_1
     183: lload_2
     184: lload         6
     186: lsub
     187: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     190: goto          268
     193: aload         9
     195: aload_1
     196: lload_2
     197: lload         6
     199: ladd
     200: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     203: goto          268
     206: aload         9
     208: aload_1
     209: lload_2
     210: lload         6
     212: ldiv
     213: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     216: goto          268
     219: aload         9
     221: aload_1
     222: lload_2
     223: lload         6
     225: lmul
     226: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     229: goto          268
     232: new           #151                // class java/lang/IllegalStateException
     235: dup
     236: new           #39                 // class java/lang/StringBuilder
     239: dup
     240: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
     243: ldc           #153                // String Unknown operation:
     245: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     248: aload_0
     249: checkcast     #112                // class day21/Monkey$Operation
     252: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
     255: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     258: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     261: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     264: invokespecial #155                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     267: athrow
     268: lreturn
     269: aload_1
     270: aload_0
     271: checkcast     #112                // class day21/Monkey$Operation
     274: invokevirtual #115                // Method day21/Monkey$Operation.getLhs:()Ljava/lang/String;
     277: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     280: checkcast     #123                // class day21/Monkey
     283: aload_1
     284: invokestatic  #182                // Method evaluateOrNull:(Lday21/Monkey;Ljava/util/Map;)Ljava/lang/Long;
     287: astore        5
     289: aload         5
     291: ifnull        517
     294: aload         5
     296: checkcast     #191                // class java/lang/Number
     299: invokevirtual #192                // Method java/lang/Number.longValue:()J
     302: lstore        6
     304: iconst_0
     305: istore        8
     307: aload_1
     308: aload_0
     309: checkcast     #112                // class day21/Monkey$Operation
     312: invokevirtual #128                // Method day21/Monkey$Operation.getRhs:()Ljava/lang/String;
     315: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     318: checkcast     #123                // class day21/Monkey
     321: astore        9
     323: aload_0
     324: checkcast     #112                // class day21/Monkey$Operation
     327: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
     330: astore        10
     332: aload         10
     334: invokevirtual #137                // Method java/lang/String.hashCode:()I
     337: tableswitch   { // 42 to 47
                    42: 376
                    43: 389
                    44: 480
                    45: 402
                    46: 480
                    47: 415
               default: 480
          }
     376: aload         10
     378: ldc           #139                // String *
     380: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     383: ifne          454
     386: goto          480
     389: aload         10
     391: ldc           #145                // String +
     393: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     396: ifne          428
     399: goto          480
     402: aload         10
     404: ldc           #147                // String -
     406: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     409: ifne          441
     412: goto          480
     415: aload         10
     417: ldc           #149                // String /
     419: invokevirtual #143                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     422: ifne          467
     425: goto          480
     428: aload         9
     430: aload_1
     431: lload_2
     432: lload         6
     434: lsub
     435: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     438: goto          516
     441: aload         9
     443: aload_1
     444: lload         6
     446: lload_2
     447: lsub
     448: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     451: goto          516
     454: aload         9
     456: aload_1
     457: lload_2
     458: lload         6
     460: ldiv
     461: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     464: goto          516
     467: aload         9
     469: aload_1
     470: lload         6
     472: lload_2
     473: ldiv
     474: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     477: goto          516
     480: new           #151                // class java/lang/IllegalStateException
     483: dup
     484: new           #39                 // class java/lang/StringBuilder
     487: dup
     488: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
     491: ldc           #153                // String Unknown operation:
     493: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     496: aload_0
     497: checkcast     #112                // class day21/Monkey$Operation
     500: invokevirtual #131                // Method day21/Monkey$Operation.getOp:()Ljava/lang/String;
     503: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     506: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     509: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     512: invokespecial #155                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     515: athrow
     516: lreturn
     517: new           #151                // class java/lang/IllegalStateException
     520: dup
     521: ldc           #196                // String Cannot evaluate either branch.
     523: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     526: invokespecial #155                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     529: athrow
     530: new           #157                // class kotlin/NoWhenBranchMatchedException
     533: dup
     534: invokespecial #158                // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     537: athrow
     538: lreturn

  private static final long part1(java.util.Map<java.lang.String, ? extends day21.Monkey>);
    Code:
       0: aload_0
       1: ldc           #206                // String root
       3: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
       6: checkcast     #123                // class day21/Monkey
       9: aload_0
      10: invokestatic  #125                // Method evaluate:(Lday21/Monkey;Ljava/util/Map;)J
      13: lreturn

  private static final long part2(java.util.Map<java.lang.String, ? extends day21.Monkey>);
    Code:
       0: aload_0
       1: ldc           #206                // String root
       3: invokeinterface #209,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
       8: dup
       9: ldc           #211                // String null cannot be cast to non-null type day21.Monkey.Operation
      11: invokestatic  #215                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;Ljava/lang/String;)V
      14: checkcast     #112                // class day21/Monkey$Operation
      17: astore_1
      18: aload_1
      19: invokevirtual #218                // Method day21/Monkey$Operation.component1:()Ljava/lang/String;
      22: astore_2
      23: aload_1
      24: invokevirtual #221                // Method day21/Monkey$Operation.component2:()Ljava/lang/String;
      27: astore_3
      28: aload_0
      29: aload_2
      30: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      33: checkcast     #123                // class day21/Monkey
      36: aload_0
      37: invokestatic  #182                // Method evaluateOrNull:(Lday21/Monkey;Ljava/util/Map;)Ljava/lang/Long;
      40: dup
      41: ifnull        70
      44: checkcast     #191                // class java/lang/Number
      47: invokevirtual #192                // Method java/lang/Number.longValue:()J
      50: lstore        4
      52: iconst_0
      53: istore        6
      55: aload_0
      56: aload_3
      57: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      60: checkcast     #123                // class day21/Monkey
      63: aload_0
      64: lload         4
      66: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
      69: lreturn
      70: pop
      71: aload_0
      72: aload_3
      73: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
      76: checkcast     #123                // class day21/Monkey
      79: aload_0
      80: invokestatic  #182                // Method evaluateOrNull:(Lday21/Monkey;Ljava/util/Map;)Ljava/lang/Long;
      83: dup
      84: ifnull        113
      87: checkcast     #191                // class java/lang/Number
      90: invokevirtual #192                // Method java/lang/Number.longValue:()J
      93: lstore        4
      95: iconst_0
      96: istore        6
      98: aload_0
      99: aload_2
     100: invokestatic  #121                // Method kotlin/collections/MapsKt.getValue:(Ljava/util/Map;Ljava/lang/Object;)Ljava/lang/Object;
     103: checkcast     #123                // class day21/Monkey
     106: aload_0
     107: lload         4
     109: invokestatic  #194                // Method coerce:(Lday21/Monkey;Ljava/util/Map;J)J
     112: lreturn
     113: pop
     114: new           #151                // class java/lang/IllegalStateException
     117: dup
     118: ldc           #196                // String Cannot evaluate either branch.
     120: invokevirtual #154                // Method java/lang/Object.toString:()Ljava/lang/String;
     123: invokespecial #155                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     126: athrow

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

  private static final kotlin.Unit parse$lambda$2(java.util.Map, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #232                // String line
       3: invokestatic  #235                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #237                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #133                // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #239                // String :
      19: aastore
      20: aload_3
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #245                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: astore_2
      30: aload_2
      31: iconst_0
      32: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #133                // class java/lang/String
      40: astore_3
      41: aload_2
      42: iconst_1
      43: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      48: checkcast     #133                // class java/lang/String
      51: astore        4
      53: aload         4
      55: invokestatic  #254                // Method kotlin/text/StringsKt.toLongOrNull:(Ljava/lang/String;)Ljava/lang/Long;
      58: dup
      59: ifnull        89
      62: checkcast     #191                // class java/lang/Number
      65: invokevirtual #192                // Method java/lang/Number.longValue:()J
      68: lstore        7
      70: iconst_0
      71: istore        9
      73: new           #106                // class day21/Monkey$Yelling
      76: dup
      77: lload         7
      79: invokespecial #257                // Method day21/Monkey$Yelling."<init>":(J)V
      82: nop
      83: checkcast     #123                // class day21/Monkey
      86: goto          178
      89: pop
      90: iconst_0
      91: istore        6
      93: aload         4
      95: checkcast     #237                // class java/lang/CharSequence
      98: iconst_1
      99: anewarray     #133                // class java/lang/String
     102: astore        7
     104: aload         7
     106: iconst_0
     107: ldc_w         #259                // String
     110: aastore
     111: aload         7
     113: iconst_0
     114: iconst_0
     115: bipush        6
     117: aconst_null
     118: invokestatic  #245                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     121: astore        8
     123: aload         8
     125: iconst_0
     126: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     131: checkcast     #133                // class java/lang/String
     134: astore        7
     136: aload         8
     138: iconst_1
     139: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     144: checkcast     #133                // class java/lang/String
     147: astore        9
     149: aload         8
     151: iconst_2
     152: invokeinterface #250,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     157: checkcast     #133                // class java/lang/String
     160: astore        10
     162: new           #112                // class day21/Monkey$Operation
     165: dup
     166: aload         7
     168: aload         10
     170: aload         9
     172: invokespecial #262                // Method day21/Monkey$Operation."<init>":(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     175: checkcast     #123                // class day21/Monkey
     178: astore        5
     180: aload_0
     181: aload_3
     182: aload         5
     184: invokeinterface #266,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     189: pop
     190: getstatic     #272                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     193: areturn
}