import Day16.Type.EQUAL_TO
import Day16.Type.G_THAN
import Day16.Type.LITERAL
import Day16.Type.L_THAN
import Day16.Type.MAX
import Day16.Type.MIN
import Day16.Type.PRODUCT
import Day16.Type.SUM
import java.io.File
import java.math.BigInteger
import java.nio.charset.Charset.defaultCharset

object Day16 {

    enum class Type(val code: Int) {
        SUM(0),
        PRODUCT(1),
        MIN(2),
        MAX(3),
        LITERAL(4),
        G_THAN(5),
        L_THAN(6),
        EQUAL_TO(7);

        companion object {
            fun fromCode(code: Int) = values().first { it.code == code }
        }
    }

    private fun String.toBinary() = BigInteger(this, 16).toString(2).let {
        String.format("%4s", it).replace(" ", "0").toCharArray().toList()
    }

    sealed class Packet(
        open val version: Int,
        open val type: Type,
    ) {
        abstract fun getTotalVersion(): Int
        abstract fun evaluate(): Long
    }

    data class Literal(
        override val version: Int,
        val literal: Long
    ) : Packet(version, LITERAL) {
        override fun getTotalVersion() = version
        override fun evaluate(): Long = literal
    }

    data class Operator(
        override val version: Int,
        override val type: Type,
        val payload: List<Packet>
    ) : Packet(version, type) {
        override fun getTotalVersion() = version + (payload.sumOf { it.getTotalVersion() })
        override fun evaluate() = when (type) {
            SUM -> payload.sumOf { it.evaluate() }
            PRODUCT -> payload.fold(1L) { acc, i -> acc * i.evaluate() }
            MIN -> payload.minOf { it.evaluate() }
            MAX -> payload.maxOf { it.evaluate() }
            G_THAN -> if (payload[0].evaluate() > payload[1].evaluate()) 1 else 0
            L_THAN -> if (payload[0].evaluate() < payload[1].evaluate()) 1 else 0
            EQUAL_TO -> if (payload[0].evaluate() == payload[1].evaluate()) 1 else 0
            else -> throw RuntimeException("unexpected type")
        }
    }

    data class BinaryString(var input: List<Char>) {

        fun isNotEmpty() = input.isNotEmpty() && input.size > 3

        fun readString(length: Int): String {
            val chars = mutableListOf<Char>()
            var index = 0
            var realCount = 0

            do {
                when (val c = input[index]) {
                    '%' -> {}
                    else -> {
                        chars.add(c)
                        realCount++
                    }
                }
                index++
            } while (realCount != length)
            input = input.subList(index, input.size)
            return chars.joinToString("")
        }

        fun readSection(length: Int): BinaryString {
            val chars = mutableListOf<Char>()
            var index = 0
            var realCount = 0

            do {
                val c = input[index]
                when (c) {
                    '%' -> {}
                    else -> {
                        realCount++
                    }
                }
                chars.add(c)
                index++
            } while (realCount != length)
            input = input.subList(index, input.size)
            return BinaryString(chars)
        }

        fun readInt(length: Int): Int {
            val string = readString(length)
            return Integer.parseInt(string, 2)
        }
    }

    private fun readPackets(input: BinaryString): MutableList<Packet> {
        val packets = mutableListOf<Packet>()
        while (input.isNotEmpty()) {
            packets.add(input.readPacket())
        }
        return packets
    }

    private fun BinaryString.readPacket(): Packet {
        val version = this.readInt(3)
        return when (val type = Type.fromCode(this.readInt(3))) {
            LITERAL -> readLiteral(version, this)
            else -> readOperator(version, type, this)
        }
    }

    private fun readOperator(version: Int, type: Type, input: BinaryString): Packet {
        val packets = when (input.readString(1)) {
            "0" -> {
                val size = input.readInt(15)
                readPackets(input.readSection(size))
            }
            "1" -> {
                val numberOfPackets = input.readInt(11)
                (0 until numberOfPackets).map { input.readPacket() }
            }
            else -> throw RuntimeException("unexpected val")
        }
        return Operator(version, type, packets)
    }

    private fun readLiteral(version: Int, input: BinaryString): Packet {
        val parts = mutableListOf<Char>()
        var finish: Boolean
        do {
            val (a, b, c, d, e) = input.readString(5).toList()
            parts.addAll(listOf(b, c, d, e))
            finish = a == '0'
        } while (!finish)
        val value = BigInteger(parts.joinToString(""), 2).longValueExact()
        return Literal(version, value)
    }

    val input = {
        File("day16/input-real.txt")
            .readText(defaultCharset())
            .map { it.toString().toBinary() }
            .flatMap { it + '%' }
            .let { BinaryString(it) }
    }

    object Part1 {
        fun run() = println(input().readPacket().getTotalVersion())
    }

    object Part2 {
        fun run() = println(input().readPacket().evaluate())
    }
}

fun main() {
    Day16.Part1.run()
    Day16.Part2.run()
}

Compiled from "Day16.kt"
public abstract class Day16$Packet {
  private final int version;

  private final Day16$Type type;

  private Day16$Packet(int, Day16$Type);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field version:I
       9: aload_0
      10: aload_2
      11: putfield      #17                 // Field type:LDay16$Type;
      14: return

  public int getVersion();
    Code:
       0: aload_0
       1: getfield      #13                 // Field version:I
       4: ireturn

  public Day16$Type getType();
    Code:
       0: aload_0
       1: getfield      #17                 // Field type:LDay16$Type;
       4: areturn

  public abstract int getTotalVersion();

  public abstract long evaluate();

  public Day16$Packet(int, Day16$Type, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: iload_1
       2: aload_2
       3: invokespecial #30                 // Method "<init>":(ILDay16$Type;)V
       6: return
}

Compiled from "Day16.kt"
public final class Day16$Operator extends Day16$Packet {
  private final int version;

  private final Day16$Type type;

  private final java.util.List<Day16$Packet> payload;

  public Day16$Operator(int, Day16$Type, java.util.List<? extends Day16$Packet>);
    Code:
       0: aload_2
       1: ldc           #10                 // String type
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #18                 // String payload
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iload_1
      14: aload_2
      15: aconst_null
      16: invokespecial #21                 // Method Day16$Packet."<init>":(ILDay16$Type;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
      19: aload_0
      20: iload_1
      21: putfield      #25                 // Field version:I
      24: aload_0
      25: aload_2
      26: putfield      #28                 // Field type:LDay16$Type;
      29: aload_0
      30: aload_3
      31: putfield      #31                 // Field payload:Ljava/util/List;
      34: return

  public int getVersion();
    Code:
       0: aload_0
       1: getfield      #25                 // Field version:I
       4: ireturn

  public Day16$Type getType();
    Code:
       0: aload_0
       1: getfield      #28                 // Field type:LDay16$Type;
       4: areturn

  public final java.util.List<Day16$Packet> getPayload();
    Code:
       0: aload_0
       1: getfield      #31                 // Field payload:Ljava/util/List;
       4: areturn

  public int getTotalVersion();
    Code:
       0: aload_0
       1: invokevirtual #43                 // Method getVersion:()I
       4: aload_0
       5: getfield      #31                 // Field payload:Ljava/util/List;
       8: checkcast     #45                 // class java/lang/Iterable
      11: astore_1
      12: istore        7
      14: iconst_0
      15: istore_2
      16: aload_1
      17: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore_3
      23: aload_3
      24: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          69
      32: aload_3
      33: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: astore        4
      40: iload_2
      41: aload         4
      43: checkcast     #4                  // class Day16$Packet
      46: astore        5
      48: istore        8
      50: iconst_0
      51: istore        6
      53: aload         5
      55: invokevirtual #61                 // Method Day16$Packet.getTotalVersion:()I
      58: istore        9
      60: iload         8
      62: iload         9
      64: iadd
      65: istore_2
      66: goto          23
      69: iload_2
      70: istore        8
      72: iload         7
      74: iload         8
      76: iadd
      77: ireturn

  public long evaluate();
    Code:
       0: aload_0
       1: invokevirtual #68                 // Method getType:()LDay16$Type;
       4: getstatic     #74                 // Field Day16$Operator$WhenMappings.$EnumSwitchMapping$0:[I
       7: swap
       8: invokevirtual #79                 // Method Day16$Type.ordinal:()I
      11: iaload
      12: tableswitch   { // 1 to 7
                     1: 56
                     2: 126
                     3: 201
                     4: 302
                     5: 403
                     6: 447
                     7: 491
               default: 535
          }
      56: aload_0
      57: getfield      #31                 // Field payload:Ljava/util/List;
      60: checkcast     #45                 // class java/lang/Iterable
      63: astore_1
      64: lconst_0
      65: lstore_2
      66: aload_1
      67: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        6
      74: aload         6
      76: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          122
      84: aload         6
      86: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      91: astore        8
      93: lload_2
      94: aload         8
      96: checkcast     #4                  // class Day16$Packet
      99: astore        9
     101: lstore        14
     103: iconst_0
     104: istore        10
     106: aload         9
     108: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     111: lstore        16
     113: lload         14
     115: lload         16
     117: ladd
     118: lstore_2
     119: goto          74
     122: lload_2
     123: goto          545
     126: aload_0
     127: getfield      #31                 // Field payload:Ljava/util/List;
     130: checkcast     #45                 // class java/lang/Iterable
     133: astore_1
     134: lconst_1
     135: lstore_2
     136: iconst_0
     137: istore        4
     139: lload_2
     140: lstore        6
     142: aload_1
     143: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     148: astore        8
     150: aload         8
     152: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     157: ifeq          196
     160: aload         8
     162: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     167: astore        9
     169: lload         6
     171: aload         9
     173: checkcast     #4                  // class Day16$Packet
     176: astore        10
     178: lstore        11
     180: iconst_0
     181: istore        13
     183: lload         11
     185: aload         10
     187: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     190: lmul
     191: lstore        6
     193: goto          150
     196: lload         6
     198: goto          545
     201: aload_0
     202: getfield      #31                 // Field payload:Ljava/util/List;
     205: checkcast     #45                 // class java/lang/Iterable
     208: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     213: astore_2
     214: aload_2
     215: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     220: ifne          231
     223: new           #83                 // class java/util/NoSuchElementException
     226: dup
     227: invokespecial #86                 // Method java/util/NoSuchElementException."<init>":()V
     230: athrow
     231: aload_2
     232: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     237: checkcast     #4                  // class Day16$Packet
     240: astore        4
     242: iconst_0
     243: istore        6
     245: aload         4
     247: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     250: lstore        4
     252: aload_2
     253: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     258: ifeq          297
     261: aload_2
     262: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     267: checkcast     #4                  // class Day16$Packet
     270: astore        6
     272: iconst_0
     273: istore        8
     275: aload         6
     277: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     280: lstore        6
     282: lload         4
     284: lload         6
     286: lcmp
     287: ifle          252
     290: lload         6
     292: lstore        4
     294: goto          252
     297: lload         4
     299: goto          545
     302: aload_0
     303: getfield      #31                 // Field payload:Ljava/util/List;
     306: checkcast     #45                 // class java/lang/Iterable
     309: invokeinterface #49,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     314: astore_2
     315: aload_2
     316: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     321: ifne          332
     324: new           #83                 // class java/util/NoSuchElementException
     327: dup
     328: invokespecial #86                 // Method java/util/NoSuchElementException."<init>":()V
     331: athrow
     332: aload_2
     333: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     338: checkcast     #4                  // class Day16$Packet
     341: astore        4
     343: iconst_0
     344: istore        6
     346: aload         4
     348: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     351: lstore        4
     353: aload_2
     354: invokeinterface #55,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     359: ifeq          398
     362: aload_2
     363: invokeinterface #59,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     368: checkcast     #4                  // class Day16$Packet
     371: astore        6
     373: iconst_0
     374: istore        8
     376: aload         6
     378: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     381: lstore        6
     383: lload         4
     385: lload         6
     387: lcmp
     388: ifge          353
     391: lload         6
     393: lstore        4
     395: goto          353
     398: lload         4
     400: goto          545
     403: aload_0
     404: getfield      #31                 // Field payload:Ljava/util/List;
     407: iconst_0
     408: invokeinterface #92,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     413: checkcast     #4                  // class Day16$Packet
     416: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     419: aload_0
     420: getfield      #31                 // Field payload:Ljava/util/List;
     423: iconst_1
     424: invokeinterface #92,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     429: checkcast     #4                  // class Day16$Packet
     432: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     435: lcmp
     436: ifle          443
     439: lconst_1
     440: goto          545
     443: lconst_0
     444: goto          545
     447: aload_0
     448: getfield      #31                 // Field payload:Ljava/util/List;
     451: iconst_0
     452: invokeinterface #92,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     457: checkcast     #4                  // class Day16$Packet
     460: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     463: aload_0
     464: getfield      #31                 // Field payload:Ljava/util/List;
     467: iconst_1
     468: invokeinterface #92,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     473: checkcast     #4                  // class Day16$Packet
     476: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     479: lcmp
     480: ifge          487
     483: lconst_1
     484: goto          545
     487: lconst_0
     488: goto          545
     491: aload_0
     492: getfield      #31                 // Field payload:Ljava/util/List;
     495: iconst_0
     496: invokeinterface #92,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     501: checkcast     #4                  // class Day16$Packet
     504: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     507: aload_0
     508: getfield      #31                 // Field payload:Ljava/util/List;
     511: iconst_1
     512: invokeinterface #92,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     517: checkcast     #4                  // class Day16$Packet
     520: invokevirtual #81                 // Method Day16$Packet.evaluate:()J
     523: lcmp
     524: ifne          531
     527: lconst_1
     528: goto          545
     531: lconst_0
     532: goto          545
     535: new           #94                 // class java/lang/RuntimeException
     538: dup
     539: ldc           #96                 // String unexpected type
     541: invokespecial #99                 // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
     544: athrow
     545: lreturn

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

  public final Day16$Type component2();
    Code:
       0: aload_0
       1: getfield      #28                 // Field type:LDay16$Type;
       4: areturn

  public final java.util.List<Day16$Packet> component3();
    Code:
       0: aload_0
       1: getfield      #31                 // Field payload:Ljava/util/List;
       4: areturn

  public final Day16$Operator copy(int, Day16$Type, java.util.List<? extends Day16$Packet>);
    Code:
       0: aload_2
       1: ldc           #10                 // String type
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #18                 // String payload
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class Day16$Operator
      15: dup
      16: iload_1
      17: aload_2
      18: aload_3
      19: invokespecial #121                // Method "<init>":(ILDay16$Type;Ljava/util/List;)V
      22: areturn

  public static Day16$Operator copy$default(Day16$Operator, int, Day16$Type, java.util.List, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #25                 // Field version:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #28                 // Field type:LDay16$Type;
      23: astore_2
      24: iload         4
      26: iconst_4
      27: iand
      28: ifeq          36
      31: aload_0
      32: getfield      #31                 // Field payload:Ljava/util/List;
      35: astore_3
      36: aload_0
      37: iload_1
      38: aload_2
      39: aload_3
      40: invokevirtual #125                // Method copy:(ILDay16$Type;Ljava/util/List;)LDay16$Operator;
      43: areturn

  public java.lang.String toString();
    Code:
       0: new           #129                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #130                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #132                // String Operator(version=
       9: invokevirtual #136                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #25                 // Field version:I
      16: invokevirtual #139                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #141                // String , type=
      21: invokevirtual #136                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #28                 // Field type:LDay16$Type;
      28: invokevirtual #144                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: ldc           #146                // String , payload=
      33: invokevirtual #136                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      36: aload_0
      37: getfield      #31                 // Field payload:Ljava/util/List;
      40: invokevirtual #144                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      43: bipush        41
      45: invokevirtual #149                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      48: invokevirtual #151                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      51: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #25                 // Field version:I
       4: invokestatic  #157                // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #28                 // Field type:LDay16$Type;
      16: invokevirtual #159                // Method Day16$Type.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: bipush        31
      24: imul
      25: aload_0
      26: getfield      #31                 // Field payload:Ljava/util/List;
      29: invokevirtual #162                // Method java/lang/Object.hashCode:()I
      32: iadd
      33: istore_1
      34: iload_1
      35: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Day16$Operator
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day16$Operator
      20: astore_2
      21: aload_0
      22: getfield      #25                 // Field version:I
      25: aload_2
      26: getfield      #25                 // Field version:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #28                 // Field type:LDay16$Type;
      38: aload_2
      39: getfield      #28                 // Field type:LDay16$Type;
      42: if_acmpeq     47
      45: iconst_0
      46: ireturn
      47: aload_0
      48: getfield      #31                 // Field payload:Ljava/util/List;
      51: aload_2
      52: getfield      #31                 // Field payload:Ljava/util/List;
      55: invokestatic  #170                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      58: ifne          63
      61: iconst_0
      62: ireturn
      63: iconst_1
      64: ireturn
}

Compiled from "Day16.kt"
public final class Day16$Type$Companion {
  private Day16$Type$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final Day16$Type fromCode(int);
    Code:
       0: invokestatic  #19                 // Method Day16$Type.values:()[LDay16$Type;
       3: astore_2
       4: iconst_0
       5: istore_3
       6: iconst_0
       7: istore        4
       9: aload_2
      10: arraylength
      11: istore        5
      13: iload         4
      15: iload         5
      17: if_icmpge     61
      20: aload_2
      21: iload         4
      23: aaload
      24: astore        6
      26: aload         6
      28: astore        7
      30: iconst_0
      31: istore        8
      33: aload         7
      35: invokevirtual #23                 // Method Day16$Type.getCode:()I
      38: iload_1
      39: if_icmpne     46
      42: iconst_1
      43: goto          47
      46: iconst_0
      47: ifeq          55
      50: aload         6
      52: goto          71
      55: iinc          4, 1
      58: goto          13
      61: new           #25                 // class java/util/NoSuchElementException
      64: dup
      65: ldc           #27                 // String Array contains no element matching the predicate.
      67: invokespecial #30                 // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      70: athrow
      71: areturn

  public Day16$Type$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #44                 // Method "<init>":()V
       4: return
}

Compiled from "Day16.kt"
public final class Day16 {
  public static final Day16 INSTANCE;

  private static final kotlin.jvm.functions.Function0<Day16$BinaryString> input;

  private Day16();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  private final java.util.List<java.lang.Character> toBinary(java.lang.String);
    Code:
       0: new           #15                 // class java/math/BigInteger
       3: dup
       4: aload_1
       5: bipush        16
       7: invokespecial #18                 // Method java/math/BigInteger."<init>":(Ljava/lang/String;I)V
      10: iconst_2
      11: invokevirtual #22                 // Method java/math/BigInteger.toString:(I)Ljava/lang/String;
      14: astore_2
      15: iconst_0
      16: istore_3
      17: getstatic     #28                 // Field kotlin/jvm/internal/StringCompanionObject.INSTANCE:Lkotlin/jvm/internal/StringCompanionObject;
      20: pop
      21: ldc           #30                 // String %4s
      23: astore        4
      25: iconst_1
      26: anewarray     #4                  // class java/lang/Object
      29: astore        5
      31: aload         5
      33: iconst_0
      34: aload_2
      35: aastore
      36: aload         5
      38: astore        5
      40: aload         4
      42: aload         5
      44: aload         5
      46: arraylength
      47: invokestatic  #36                 // Method java/util/Arrays.copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;
      50: invokestatic  #42                 // Method java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
      53: dup
      54: ldc           #44                 // String format(...)
      56: invokestatic  #50                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      59: ldc           #52                 // String
      61: ldc           #54                 // String 0
      63: iconst_0
      64: iconst_4
      65: aconst_null
      66: invokestatic  #60                 // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      69: invokevirtual #64                 // Method java/lang/String.toCharArray:()[C
      72: dup
      73: ldc           #66                 // String toCharArray(...)
      75: invokestatic  #50                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      78: invokestatic  #72                 // Method kotlin/collections/ArraysKt.toList:([C)Ljava/util/List;
      81: nop
      82: areturn

  private final java.util.List<Day16$Packet> readPackets(Day16$BinaryString);
    Code:
       0: new           #82                 // class java/util/ArrayList
       3: dup
       4: invokespecial #83                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #85                 // class java/util/List
      10: astore_2
      11: aload_1
      12: invokevirtual #91                 // Method Day16$BinaryString.isNotEmpty:()Z
      15: ifeq          33
      18: aload_2
      19: aload_0
      20: aload_1
      21: invokespecial #95                 // Method readPacket:(LDay16$BinaryString;)LDay16$Packet;
      24: invokeinterface #99,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      29: pop
      30: goto          11
      33: aload_2
      34: areturn

  private final Day16$Packet readPacket(Day16$BinaryString);
    Code:
       0: aload_1
       1: iconst_3
       2: invokevirtual #107                // Method Day16$BinaryString.readInt:(I)I
       5: istore_2
       6: getstatic     #113                // Field Day16$Type.Companion:LDay16$Type$Companion;
       9: aload_1
      10: iconst_3
      11: invokevirtual #107                // Method Day16$BinaryString.readInt:(I)I
      14: invokevirtual #119                // Method Day16$Type$Companion.fromCode:(I)LDay16$Type;
      17: astore_3
      18: getstatic     #125                // Field Day16$WhenMappings.$EnumSwitchMapping$0:[I
      21: aload_3
      22: invokevirtual #129                // Method Day16$Type.ordinal:()I
      25: iaload
      26: iconst_1
      27: if_icmpne     39
      30: aload_0
      31: iload_2
      32: aload_1
      33: invokespecial #133                // Method readLiteral:(ILDay16$BinaryString;)LDay16$Packet;
      36: goto          46
      39: aload_0
      40: iload_2
      41: aload_3
      42: aload_1
      43: invokespecial #137                // Method readOperator:(ILDay16$Type;LDay16$BinaryString;)LDay16$Packet;
      46: areturn

  private final Day16$Packet readOperator(int, Day16$Type, Day16$BinaryString);
    Code:
       0: aload_3
       1: iconst_1
       2: invokevirtual #146                // Method Day16$BinaryString.readString:(I)Ljava/lang/String;
       5: astore        5
       7: aload         5
       9: ldc           #54                 // String 0
      11: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      14: ifeq          38
      17: aload_3
      18: bipush        15
      20: invokevirtual #107                // Method Day16$BinaryString.readInt:(I)I
      23: istore        6
      25: aload_0
      26: aload_3
      27: iload         6
      29: invokevirtual #154                // Method Day16$BinaryString.readSection:(I)LDay16$BinaryString;
      32: invokespecial #156                // Method readPackets:(LDay16$BinaryString;)Ljava/util/List;
      35: goto          174
      38: aload         5
      40: ldc           #158                // String 1
      42: invokestatic  #150                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      45: ifeq          164
      48: aload_3
      49: bipush        11
      51: invokevirtual #107                // Method Day16$BinaryString.readInt:(I)I
      54: istore        6
      56: iconst_0
      57: iload         6
      59: invokestatic  #164                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      62: checkcast     #166                // class java/lang/Iterable
      65: astore        7
      67: iconst_0
      68: istore        8
      70: aload         7
      72: astore        9
      74: new           #82                 // class java/util/ArrayList
      77: dup
      78: aload         7
      80: bipush        10
      82: invokestatic  #172                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      85: invokespecial #175                // Method java/util/ArrayList."<init>":(I)V
      88: checkcast     #177                // class java/util/Collection
      91: astore        10
      93: iconst_0
      94: istore        11
      96: aload         9
      98: invokeinterface #181,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     103: astore        12
     105: aload         12
     107: invokeinterface #186,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     112: ifeq          155
     115: aload         12
     117: checkcast     #188                // class kotlin/collections/IntIterator
     120: invokevirtual #191                // Method kotlin/collections/IntIterator.nextInt:()I
     123: istore        13
     125: aload         10
     127: iload         13
     129: istore        14
     131: astore        16
     133: iconst_0
     134: istore        15
     136: getstatic     #193                // Field INSTANCE:LDay16;
     139: aload_3
     140: invokespecial #95                 // Method readPacket:(LDay16$BinaryString;)LDay16$Packet;
     143: aload         16
     145: swap
     146: invokeinterface #194,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     151: pop
     152: goto          105
     155: aload         10
     157: checkcast     #85                 // class java/util/List
     160: nop
     161: goto          174
     164: new           #196                // class java/lang/RuntimeException
     167: dup
     168: ldc           #198                // String unexpected val
     170: invokespecial #201                // Method java/lang/RuntimeException."<init>":(Ljava/lang/String;)V
     173: athrow
     174: astore        4
     176: new           #203                // class Day16$Operator
     179: dup
     180: iload_1
     181: aload_2
     182: aload         4
     184: invokespecial #206                // Method Day16$Operator."<init>":(ILDay16$Type;Ljava/util/List;)V
     187: checkcast     #143                // class Day16$Packet
     190: areturn

  private final Day16$Packet readLiteral(int, Day16$BinaryString);
    Code:
       0: new           #82                 // class java/util/ArrayList
       3: dup
       4: invokespecial #83                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #85                 // class java/util/List
      10: astore_3
      11: iconst_0
      12: istore        4
      14: aload_2
      15: iconst_5
      16: invokevirtual #146                // Method Day16$BinaryString.readString:(I)Ljava/lang/String;
      19: checkcast     #219                // class java/lang/CharSequence
      22: invokestatic  #222                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      25: astore        5
      27: aload         5
      29: iconst_0
      30: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      35: checkcast     #228                // class java/lang/Character
      38: invokevirtual #232                // Method java/lang/Character.charValue:()C
      41: istore        6
      43: aload         5
      45: iconst_1
      46: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      51: checkcast     #228                // class java/lang/Character
      54: invokevirtual #232                // Method java/lang/Character.charValue:()C
      57: istore        7
      59: aload         5
      61: iconst_2
      62: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #228                // class java/lang/Character
      70: invokevirtual #232                // Method java/lang/Character.charValue:()C
      73: istore        8
      75: aload         5
      77: iconst_3
      78: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      83: checkcast     #228                // class java/lang/Character
      86: invokevirtual #232                // Method java/lang/Character.charValue:()C
      89: istore        9
      91: aload         5
      93: iconst_4
      94: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      99: checkcast     #228                // class java/lang/Character
     102: invokevirtual #232                // Method java/lang/Character.charValue:()C
     105: istore        10
     107: aload_3
     108: iconst_4
     109: anewarray     #228                // class java/lang/Character
     112: astore        11
     114: aload         11
     116: iconst_0
     117: iload         7
     119: invokestatic  #236                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     122: aastore
     123: aload         11
     125: iconst_1
     126: iload         8
     128: invokestatic  #236                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     131: aastore
     132: aload         11
     134: iconst_2
     135: iload         9
     137: invokestatic  #236                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     140: aastore
     141: aload         11
     143: iconst_3
     144: iload         10
     146: invokestatic  #236                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     149: aastore
     150: aload         11
     152: invokestatic  #240                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     155: checkcast     #177                // class java/util/Collection
     158: invokeinterface #244,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     163: pop
     164: iload         6
     166: bipush        48
     168: if_icmpne     175
     171: iconst_1
     172: goto          176
     175: iconst_0
     176: istore        4
     178: iload         4
     180: ifeq          14
     183: new           #15                 // class java/math/BigInteger
     186: dup
     187: aload_3
     188: checkcast     #166                // class java/lang/Iterable
     191: ldc           #246                // String
     193: checkcast     #219                // class java/lang/CharSequence
     196: aconst_null
     197: aconst_null
     198: iconst_0
     199: aconst_null
     200: aconst_null
     201: bipush        62
     203: aconst_null
     204: invokestatic  #250                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     207: iconst_2
     208: invokespecial #18                 // Method java/math/BigInteger."<init>":(Ljava/lang/String;I)V
     211: invokevirtual #254                // Method java/math/BigInteger.longValueExact:()J
     214: lstore        5
     216: new           #256                // class Day16$Literal
     219: dup
     220: iload_1
     221: lload         5
     223: invokespecial #259                // Method Day16$Literal."<init>":(IJ)V
     226: checkcast     #143                // class Day16$Packet
     229: areturn

  public final kotlin.jvm.functions.Function0<Day16$BinaryString> getInput();
    Code:
       0: getstatic     #279                // Field input:Lkotlin/jvm/functions/Function0;
       3: areturn

  private static final Day16$BinaryString input$lambda$5();
    Code:
       0: new           #283                // class java/io/File
       3: dup
       4: ldc_w         #285                // String day16/input-real.txt
       7: invokespecial #286                // Method java/io/File."<init>":(Ljava/lang/String;)V
      10: invokestatic  #292                // Method java/nio/charset/Charset.defaultCharset:()Ljava/nio/charset/Charset;
      13: dup
      14: ldc_w         #294                // String defaultCharset(...)
      17: invokestatic  #50                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      20: invokestatic  #300                // Method kotlin/io/FilesKt.readText:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/lang/String;
      23: checkcast     #219                // class java/lang/CharSequence
      26: astore_0
      27: nop
      28: iconst_0
      29: istore_1
      30: aload_0
      31: astore_2
      32: new           #82                 // class java/util/ArrayList
      35: dup
      36: aload_0
      37: invokeinterface #303,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      42: invokespecial #175                // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #177                // class java/util/Collection
      48: astore_3
      49: iconst_0
      50: istore        4
      52: iconst_0
      53: istore        5
      55: iload         5
      57: aload_2
      58: invokeinterface #303,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      63: if_icmpge     112
      66: aload_2
      67: iload         5
      69: invokeinterface #307,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      74: istore        6
      76: aload_3
      77: iload         6
      79: istore        7
      81: astore        9
      83: iconst_0
      84: istore        8
      86: getstatic     #193                // Field INSTANCE:LDay16;
      89: iload         7
      91: invokestatic  #310                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      94: invokespecial #312                // Method toBinary:(Ljava/lang/String;)Ljava/util/List;
      97: aload         9
      99: swap
     100: invokeinterface #194,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     105: pop
     106: iinc          5, 1
     109: goto          55
     112: aload_3
     113: checkcast     #85                 // class java/util/List
     116: nop
     117: checkcast     #166                // class java/lang/Iterable
     120: astore_0
     121: nop
     122: iconst_0
     123: istore_1
     124: aload_0
     125: astore_2
     126: new           #82                 // class java/util/ArrayList
     129: dup
     130: invokespecial #83                 // Method java/util/ArrayList."<init>":()V
     133: checkcast     #177                // class java/util/Collection
     136: astore_3
     137: iconst_0
     138: istore        4
     140: aload_2
     141: invokeinterface #181,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     146: astore        5
     148: aload         5
     150: invokeinterface #186,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     155: ifeq          205
     158: aload         5
     160: invokeinterface #316,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     165: astore        6
     167: aload         6
     169: checkcast     #85                 // class java/util/List
     172: astore        7
     174: iconst_0
     175: istore        8
     177: aload         7
     179: checkcast     #177                // class java/util/Collection
     182: bipush        37
     184: invokestatic  #236                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     187: invokestatic  #320                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
     190: checkcast     #166                // class java/lang/Iterable
     193: astore        7
     195: aload_3
     196: aload         7
     198: invokestatic  #323                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     201: pop
     202: goto          148
     205: aload_3
     206: checkcast     #85                 // class java/util/List
     209: nop
     210: astore_1
     211: iconst_0
     212: istore_2
     213: new           #87                 // class Day16$BinaryString
     216: dup
     217: aload_1
     218: invokespecial #326                // Method Day16$BinaryString."<init>":(Ljava/util/List;)V
     221: nop
     222: areturn

  public static final Day16$Packet access$readPacket(Day16, Day16$BinaryString);
    Code:
       0: aload_0
       1: aload_1
       2: invokespecial #95                 // Method readPacket:(LDay16$BinaryString;)LDay16$Packet;
       5: areturn

  static {};
    Code:
       0: new           #2                  // class Day16
       3: dup
       4: invokespecial #343                // Method "<init>":()V
       7: putstatic     #193                // Field INSTANCE:LDay16;
      10: invokedynamic #358,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function0;
      15: putstatic     #279                // Field input:Lkotlin/jvm/functions/Function0;
      18: return
}

Compiled from "Day16.kt"
public final class Day16Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Day16$Part1.INSTANCE:LDay16$Part1;
       3: invokevirtual #15                 // Method Day16$Part1.run:()V
       6: getstatic     #20                 // Field Day16$Part2.INSTANCE:LDay16$Part2;
       9: invokevirtual #21                 // Method Day16$Part2.run:()V
      12: return

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

Compiled from "Day16.kt"
public final class Day16$Type extends java.lang.Enum<Day16$Type> {
  public static final Day16$Type$Companion Companion;

  private final int code;

  public static final Day16$Type SUM;

  public static final Day16$Type PRODUCT;

  public static final Day16$Type MIN;

  public static final Day16$Type MAX;

  public static final Day16$Type LITERAL;

  public static final Day16$Type G_THAN;

  public static final Day16$Type L_THAN;

  public static final Day16$Type EQUAL_TO;

  private static final Day16$Type[] $VALUES;

  private static final kotlin.enums.EnumEntries $ENTRIES;

  private Day16$Type(int);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #11                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
       6: aload_0
       7: iload_3
       8: putfield      #15                 // Field code:I
      11: return

  public final int getCode();
    Code:
       0: aload_0
       1: getfield      #15                 // Field code:I
       4: ireturn

  public static Day16$Type[] values();
    Code:
       0: getstatic     #28                 // Field $VALUES:[LDay16$Type;
       3: invokevirtual #34                 // Method java/lang/Object.clone:()Ljava/lang/Object;
       6: checkcast     #35                 // class "[LDay16$Type;"
       9: areturn

  public static Day16$Type valueOf(java.lang.String);
    Code:
       0: ldc           #2                  // class Day16$Type
       2: aload_0
       3: invokestatic  #40                 // Method java/lang/Enum.valueOf:(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;
       6: checkcast     #2                  // class Day16$Type
       9: areturn

  public static kotlin.enums.EnumEntries<Day16$Type> getEntries();
    Code:
       0: getstatic     #49                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
       3: areturn

  private static final Day16$Type[] $values();
    Code:
       0: bipush        8
       2: anewarray     #2                  // class Day16$Type
       5: astore_0
       6: aload_0
       7: iconst_0
       8: getstatic     #53                 // Field SUM:LDay16$Type;
      11: aastore
      12: aload_0
      13: iconst_1
      14: getstatic     #56                 // Field PRODUCT:LDay16$Type;
      17: aastore
      18: aload_0
      19: iconst_2
      20: getstatic     #59                 // Field MIN:LDay16$Type;
      23: aastore
      24: aload_0
      25: iconst_3
      26: getstatic     #62                 // Field MAX:LDay16$Type;
      29: aastore
      30: aload_0
      31: iconst_4
      32: getstatic     #65                 // Field LITERAL:LDay16$Type;
      35: aastore
      36: aload_0
      37: iconst_5
      38: getstatic     #68                 // Field G_THAN:LDay16$Type;
      41: aastore
      42: aload_0
      43: bipush        6
      45: getstatic     #71                 // Field L_THAN:LDay16$Type;
      48: aastore
      49: aload_0
      50: bipush        7
      52: getstatic     #74                 // Field EQUAL_TO:LDay16$Type;
      55: aastore
      56: aload_0
      57: areturn

  static {};
    Code:
       0: new           #2                  // class Day16$Type
       3: dup
       4: ldc           #77                 // String SUM
       6: iconst_0
       7: iconst_0
       8: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      11: putstatic     #53                 // Field SUM:LDay16$Type;
      14: new           #2                  // class Day16$Type
      17: dup
      18: ldc           #80                 // String PRODUCT
      20: iconst_1
      21: iconst_1
      22: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      25: putstatic     #56                 // Field PRODUCT:LDay16$Type;
      28: new           #2                  // class Day16$Type
      31: dup
      32: ldc           #81                 // String MIN
      34: iconst_2
      35: iconst_2
      36: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      39: putstatic     #59                 // Field MIN:LDay16$Type;
      42: new           #2                  // class Day16$Type
      45: dup
      46: ldc           #82                 // String MAX
      48: iconst_3
      49: iconst_3
      50: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      53: putstatic     #62                 // Field MAX:LDay16$Type;
      56: new           #2                  // class Day16$Type
      59: dup
      60: ldc           #83                 // String LITERAL
      62: iconst_4
      63: iconst_4
      64: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      67: putstatic     #65                 // Field LITERAL:LDay16$Type;
      70: new           #2                  // class Day16$Type
      73: dup
      74: ldc           #84                 // String G_THAN
      76: iconst_5
      77: iconst_5
      78: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      81: putstatic     #68                 // Field G_THAN:LDay16$Type;
      84: new           #2                  // class Day16$Type
      87: dup
      88: ldc           #85                 // String L_THAN
      90: bipush        6
      92: bipush        6
      94: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
      97: putstatic     #71                 // Field L_THAN:LDay16$Type;
     100: new           #2                  // class Day16$Type
     103: dup
     104: ldc           #86                 // String EQUAL_TO
     106: bipush        7
     108: bipush        7
     110: invokespecial #79                 // Method "<init>":(Ljava/lang/String;II)V
     113: putstatic     #74                 // Field EQUAL_TO:LDay16$Type;
     116: invokestatic  #88                 // Method $values:()[LDay16$Type;
     119: putstatic     #28                 // Field $VALUES:[LDay16$Type;
     122: getstatic     #28                 // Field $VALUES:[LDay16$Type;
     125: checkcast     #90                 // class "[Ljava/lang/Enum;"
     128: invokestatic  #96                 // Method kotlin/enums/EnumEntriesKt.enumEntries:([Ljava/lang/Enum;)Lkotlin/enums/EnumEntries;
     131: putstatic     #49                 // Field $ENTRIES:Lkotlin/enums/EnumEntries;
     134: new           #98                 // class Day16$Type$Companion
     137: dup
     138: aconst_null
     139: invokespecial #101                // Method Day16$Type$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
     142: putstatic     #105                // Field Companion:LDay16$Type$Companion;
     145: return
}

Compiled from "Day16.kt"
public final class Day16$Part2 {
  public static final Day16$Part2 INSTANCE;

  private Day16$Part2();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void run();
    Code:
       0: getstatic     #17                 // Field Day16.INSTANCE:LDay16;
       3: getstatic     #17                 // Field Day16.INSTANCE:LDay16;
       6: invokevirtual #21                 // Method Day16.getInput:()Lkotlin/jvm/functions/Function0;
       9: invokeinterface #27,  1           // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      14: checkcast     #29                 // class Day16$BinaryString
      17: invokestatic  #33                 // Method Day16.access$readPacket:(LDay16;LDay16$BinaryString;)LDay16$Packet;
      20: invokevirtual #39                 // Method Day16$Packet.evaluate:()J
      23: lstore_1
      24: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      27: lload_1
      28: invokevirtual #51                 // Method java/io/PrintStream.println:(J)V
      31: return

  static {};
    Code:
       0: new           #2                  // class Day16$Part2
       3: dup
       4: invokespecial #53                 // Method "<init>":()V
       7: putstatic     #55                 // Field INSTANCE:LDay16$Part2;
      10: return
}

Compiled from "Day16.kt"
public final class Day16$Literal extends Day16$Packet {
  private final int version;

  private final long literal;

  public Day16$Literal(int, long);
    Code:
       0: aload_0
       1: iload_1
       2: getstatic     #12                 // Field Day16$Type.LITERAL:LDay16$Type;
       5: aconst_null
       6: invokespecial #15                 // Method Day16$Packet."<init>":(ILDay16$Type;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       9: aload_0
      10: iload_1
      11: putfield      #19                 // Field version:I
      14: aload_0
      15: lload_2
      16: putfield      #23                 // Field literal:J
      19: return

  public int getVersion();
    Code:
       0: aload_0
       1: getfield      #19                 // Field version:I
       4: ireturn

  public final long getLiteral();
    Code:
       0: aload_0
       1: getfield      #23                 // Field literal:J
       4: lreturn

  public int getTotalVersion();
    Code:
       0: aload_0
       1: invokevirtual #32                 // Method getVersion:()I
       4: ireturn

  public long evaluate();
    Code:
       0: aload_0
       1: getfield      #23                 // Field literal:J
       4: lreturn

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

  public final long component2();
    Code:
       0: aload_0
       1: getfield      #23                 // Field literal:J
       4: lreturn

  public final Day16$Literal copy(int, long);
    Code:
       0: new           #2                  // class Day16$Literal
       3: dup
       4: iload_1
       5: lload_2
       6: invokespecial #40                 // Method "<init>":(IJ)V
       9: areturn

  public static Day16$Literal copy$default(Day16$Literal, int, long, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #19                 // Field version:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #23                 // Field literal:J
      23: lstore_2
      24: aload_0
      25: iload_1
      26: lload_2
      27: invokevirtual #44                 // Method copy:(IJ)LDay16$Literal;
      30: areturn

  public java.lang.String toString();
    Code:
       0: new           #48                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #51                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #53                 // String Literal(version=
       9: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #19                 // Field version:I
      16: invokevirtual #60                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #62                 // String , literal=
      21: invokevirtual #57                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #23                 // Field literal:J
      28: invokevirtual #65                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #68                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #70                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #19                 // Field version:I
       4: invokestatic  #76                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #23                 // Field literal:J
      16: invokestatic  #81                 // Method java/lang/Long.hashCode:(J)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Day16$Literal
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day16$Literal
      20: astore_2
      21: aload_0
      22: getfield      #19                 // Field version:I
      25: aload_2
      26: getfield      #19                 // Field version:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #23                 // Field literal:J
      38: aload_2
      39: getfield      #23                 // Field literal:J
      42: lcmp
      43: ifeq          48
      46: iconst_0
      47: ireturn
      48: iconst_1
      49: ireturn
}

Compiled from "Day16.kt"
public final class Day16$BinaryString {
  private java.util.List<java.lang.Character> input;

  public Day16$BinaryString(java.util.List<java.lang.Character>);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #19                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #22                 // Field input:Ljava/util/List;
      15: return

  public final java.util.List<java.lang.Character> getInput();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: areturn

  public final void setInput(java.util.List<java.lang.Character>);
    Code:
       0: aload_1
       1: ldc           #30                 // String <set-?>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: putfield      #22                 // Field input:Ljava/util/List;
      11: return

  public final boolean isNotEmpty();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: checkcast     #34                 // class java/util/Collection
       7: invokeinterface #37,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      12: ifne          19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ifeq          40
      23: aload_0
      24: getfield      #22                 // Field input:Ljava/util/List;
      27: invokeinterface #43,  1           // InterfaceMethod java/util/List.size:()I
      32: iconst_3
      33: if_icmple     40
      36: iconst_1
      37: goto          41
      40: iconst_0
      41: ireturn

  public final java.lang.String readString(int);
    Code:
       0: new           #47                 // class java/util/ArrayList
       3: dup
       4: invokespecial #48                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #39                 // class java/util/List
      10: astore_2
      11: iconst_0
      12: istore_3
      13: iconst_0
      14: istore        4
      16: aload_0
      17: getfield      #22                 // Field input:Ljava/util/List;
      20: iload_3
      21: invokeinterface #52,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      26: checkcast     #54                 // class java/lang/Character
      29: invokevirtual #58                 // Method java/lang/Character.charValue:()C
      32: istore        5
      34: iload         5
      36: bipush        37
      38: if_icmpeq     59
      41: aload_2
      42: iload         5
      44: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      47: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      52: pop
      53: iload         4
      55: iinc          4, 1
      58: pop
      59: iinc          3, 1
      62: iload         4
      64: iload_1
      65: if_icmpne     16
      68: aload_0
      69: aload_0
      70: getfield      #22                 // Field input:Ljava/util/List;
      73: iload_3
      74: aload_0
      75: getfield      #22                 // Field input:Ljava/util/List;
      78: invokeinterface #43,  1           // InterfaceMethod java/util/List.size:()I
      83: invokeinterface #70,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      88: putfield      #22                 // Field input:Ljava/util/List;
      91: aload_2
      92: checkcast     #72                 // class java/lang/Iterable
      95: ldc           #74                 // String
      97: checkcast     #76                 // class java/lang/CharSequence
     100: aconst_null
     101: aconst_null
     102: iconst_0
     103: aconst_null
     104: aconst_null
     105: bipush        62
     107: aconst_null
     108: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     111: areturn

  public final Day16$BinaryString readSection(int);
    Code:
       0: new           #47                 // class java/util/ArrayList
       3: dup
       4: invokespecial #48                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #39                 // class java/util/List
      10: astore_2
      11: iconst_0
      12: istore_3
      13: iconst_0
      14: istore        4
      16: aload_0
      17: getfield      #22                 // Field input:Ljava/util/List;
      20: iload_3
      21: invokeinterface #52,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      26: checkcast     #54                 // class java/lang/Character
      29: invokevirtual #58                 // Method java/lang/Character.charValue:()C
      32: istore        5
      34: iload         5
      36: bipush        37
      38: if_icmpeq     47
      41: iload         4
      43: iinc          4, 1
      46: pop
      47: aload_2
      48: iload         5
      50: invokestatic  #62                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      53: invokeinterface #66,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      58: pop
      59: iinc          3, 1
      62: iload         4
      64: iload_1
      65: if_icmpne     16
      68: aload_0
      69: aload_0
      70: getfield      #22                 // Field input:Ljava/util/List;
      73: iload_3
      74: aload_0
      75: getfield      #22                 // Field input:Ljava/util/List;
      78: invokeinterface #43,  1           // InterfaceMethod java/util/List.size:()I
      83: invokeinterface #70,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      88: putfield      #22                 // Field input:Ljava/util/List;
      91: new           #2                  // class Day16$BinaryString
      94: dup
      95: aload_2
      96: invokespecial #93                 // Method "<init>":(Ljava/util/List;)V
      99: areturn

  public final int readInt(int);
    Code:
       0: aload_0
       1: iload_1
       2: invokevirtual #97                 // Method readString:(I)Ljava/lang/String;
       5: astore_2
       6: aload_2
       7: iconst_2
       8: invokestatic  #103                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      11: ireturn

  public final java.util.List<java.lang.Character> component1();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: areturn

  public final Day16$BinaryString copy(java.util.List<java.lang.Character>);
    Code:
       0: aload_1
       1: ldc           #10                 // String input
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #2                  // class Day16$BinaryString
       9: dup
      10: aload_1
      11: invokespecial #93                 // Method "<init>":(Ljava/util/List;)V
      14: areturn

  public static Day16$BinaryString copy$default(Day16$BinaryString, java.util.List, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #22                 // Field input:Ljava/util/List;
      10: astore_1
      11: aload_0
      12: aload_1
      13: invokevirtual #113                // Method copy:(Ljava/util/List;)LDay16$BinaryString;
      16: areturn

  public java.lang.String toString();
    Code:
       0: new           #117                // class java/lang/StringBuilder
       3: dup
       4: invokespecial #118                // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #120                // String BinaryString(input=
       9: invokevirtual #124                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #22                 // Field input:Ljava/util/List;
      16: invokevirtual #127                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: bipush        41
      21: invokevirtual #130                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      24: invokevirtual #132                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      27: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #22                 // Field input:Ljava/util/List;
       4: invokevirtual #135                // Method java/lang/Object.hashCode:()I
       7: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Day16$BinaryString
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Day16$BinaryString
      20: astore_2
      21: aload_0
      22: getfield      #22                 // Field input:Ljava/util/List;
      25: aload_2
      26: getfield      #22                 // Field input:Ljava/util/List;
      29: invokestatic  #141                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: iconst_1
      38: ireturn
}

Compiled from "Day16.kt"
public final class Day16$Part1 {
  public static final Day16$Part1 INSTANCE;

  private Day16$Part1();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void run();
    Code:
       0: getstatic     #17                 // Field Day16.INSTANCE:LDay16;
       3: getstatic     #17                 // Field Day16.INSTANCE:LDay16;
       6: invokevirtual #21                 // Method Day16.getInput:()Lkotlin/jvm/functions/Function0;
       9: invokeinterface #27,  1           // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      14: checkcast     #29                 // class Day16$BinaryString
      17: invokestatic  #33                 // Method Day16.access$readPacket:(LDay16;LDay16$BinaryString;)LDay16$Packet;
      20: invokevirtual #39                 // Method Day16$Packet.getTotalVersion:()I
      23: istore_1
      24: getstatic     #45                 // Field java/lang/System.out:Ljava/io/PrintStream;
      27: iload_1
      28: invokevirtual #51                 // Method java/io/PrintStream.println:(I)V
      31: return

  static {};
    Code:
       0: new           #2                  // class Day16$Part1
       3: dup
       4: invokespecial #53                 // Method "<init>":()V
       7: putstatic     #55                 // Field INSTANCE:LDay16$Part1;
      10: return
}

Compiled from "Day16.kt"
public final class Day16$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method Day16$Type.values:()[LDay16$Type;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field Day16$Type.LITERAL:LDay16$Type;
      12: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: aload_0
      22: putstatic     #26                 // Field $EnumSwitchMapping$0:[I
      25: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
}

Compiled from "Day16.kt"
public final class Day16$Operator$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method Day16$Type.values:()[LDay16$Type;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field Day16$Type.SUM:LDay16$Type;
      12: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field Day16$Type.PRODUCT:LDay16$Type;
      26: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field Day16$Type.MIN:LDay16$Type;
      40: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: nop
      50: aload_0
      51: getstatic     #31                 // Field Day16$Type.MAX:LDay16$Type;
      54: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      57: iconst_4
      58: iastore
      59: goto          63
      62: astore_1
      63: nop
      64: aload_0
      65: getstatic     #34                 // Field Day16$Type.G_THAN:LDay16$Type;
      68: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      71: iconst_5
      72: iastore
      73: goto          77
      76: astore_1
      77: nop
      78: aload_0
      79: getstatic     #37                 // Field Day16$Type.L_THAN:LDay16$Type;
      82: invokevirtual #22                 // Method Day16$Type.ordinal:()I
      85: bipush        6
      87: iastore
      88: goto          92
      91: astore_1
      92: nop
      93: aload_0
      94: getstatic     #40                 // Field Day16$Type.EQUAL_TO:LDay16$Type;
      97: invokevirtual #22                 // Method Day16$Type.ordinal:()I
     100: bipush        7
     102: iastore
     103: goto          107
     106: astore_1
     107: aload_0
     108: putstatic     #44                 // Field $EnumSwitchMapping$0:[I
     111: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
          49    59    62   Class java/lang/NoSuchFieldError
          63    73    76   Class java/lang/NoSuchFieldError
          77    88    91   Class java/lang/NoSuchFieldError
          92   103   106   Class java/lang/NoSuchFieldError
}