package day20

import readInput

const val encryptionKey = 811589153L

fun main() {
    val input = readInput("main/day20/Day20_test")
    println(part1(input))
    println(part2(input))
}

fun part1(input: List<String>): Long {
    val original = input.mapIndexed { index, s -> Num(originalPosition = index, number = s.toLong()) }.toMutableList()
    val mixed = mix(original)

    return summedCoordinates(mixed)
}

fun part2(input: List<String>): Long {
    val original = input.mapIndexed { index, s ->
        Num(originalPosition = index, number = s.toLong() * encryptionKey)
    }.toMutableList()

    val mixed = generateSequence(original) { mix(original, it).toMutableList() }.drop(10).first()
    return summedCoordinates(mixed)
}

private fun mix(list: MutableList<Num>, original: MutableList<Num> = list, position: Int = 0): List<Num> {
    if (position == list.size) return list

    val index = list.indexOfFirst {
        it == original.firstOrNull { o ->
            o.originalPosition == position
        }
    }
    val current = list[index]
    var newIndex = (index + current.number) % (list.size - 1)
    if (newIndex <= 0) newIndex += list.size - 1
    list.removeAt(index)
    list.add(newIndex.toInt(), current.move())

    return mix(list = list, original = list, position = position + 1)
}

private fun summedCoordinates(mixed: List<Num>): Long {
    val zero = mixed.indexOfFirst { it.number == 0L }
    val a = mixed[(zero + 1000) % mixed.size].number
    val b = mixed[(zero + 2000) % mixed.size].number
    val c = mixed[(zero + 3000) % mixed.size].number
    return a + b + c
}

data class Num(val originalPosition: Int, val currentPosition: Int = originalPosition, val number: Long, val moved: Int = 0) {
    fun move() = copy(moved = moved + 1)
}

Compiled from "day20.kt"
public final class day20.Day20Kt {
  public static final long encryptionKey;

  public static final void main();
    Code:
       0: ldc           #8                  // String main/day20/Day20_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method part1:(Ljava/util/List;)J
      10: lstore_1
      11: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: lload_1
      15: invokevirtual #30                 // Method java/io/PrintStream.println:(J)V
      18: aload_0
      19: invokestatic  #33                 // Method part2:(Ljava/util/List;)J
      22: lstore_1
      23: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: lload_1
      27: invokevirtual #30                 // Method java/io/PrintStream.println:(J)V
      30: return

  public static final long part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String input
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #46                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #48                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #60                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: iconst_0
      38: istore        7
      40: aload         4
      42: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      47: astore        8
      49: aload         8
      51: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifeq          132
      59: aload         8
      61: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: astore        9
      68: aload         5
      70: iload         7
      72: iinc          7, 1
      75: istore        10
      77: iload         10
      79: ifge          85
      82: invokestatic  #77                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      85: iload         10
      87: aload         9
      89: checkcast     #79                 // class java/lang/String
      92: astore        11
      94: istore        12
      96: astore        14
      98: iconst_0
      99: istore        13
     101: new           #81                 // class day20/Num
     104: dup
     105: iload         12
     107: iconst_0
     108: aload         11
     110: invokestatic  #87                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     113: iconst_0
     114: bipush        10
     116: aconst_null
     117: invokespecial #90                 // Method day20/Num."<init>":(IIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     120: aload         14
     122: swap
     123: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     128: pop
     129: goto          49
     132: aload         5
     134: checkcast     #96                 // class java/util/List
     137: nop
     138: checkcast     #60                 // class java/util/Collection
     141: invokestatic  #100                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     144: astore_1
     145: aload_1
     146: aconst_null
     147: iconst_0
     148: bipush        6
     150: aconst_null
     151: invokestatic  #104                // Method mix$default:(Ljava/util/List;Ljava/util/List;IILjava/lang/Object;)Ljava/util/List;
     154: astore_2
     155: aload_2
     156: invokestatic  #107                // Method summedCoordinates:(Ljava/util/List;)J
     159: lreturn

  public static final long part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #38                 // String input
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #46                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #48                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #54                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #58                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #60                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: iconst_0
      38: istore        7
      40: aload         4
      42: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      47: astore        8
      49: aload         8
      51: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifeq          136
      59: aload         8
      61: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: astore        9
      68: aload         5
      70: iload         7
      72: iinc          7, 1
      75: istore        10
      77: iload         10
      79: ifge          85
      82: invokestatic  #77                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      85: iload         10
      87: aload         9
      89: checkcast     #79                 // class java/lang/String
      92: astore        11
      94: istore        12
      96: astore        14
      98: iconst_0
      99: istore        13
     101: new           #81                 // class day20/Num
     104: dup
     105: iload         12
     107: iconst_0
     108: aload         11
     110: invokestatic  #87                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     113: ldc2_w        #125                // long 811589153l
     116: lmul
     117: iconst_0
     118: bipush        10
     120: aconst_null
     121: invokespecial #90                 // Method day20/Num."<init>":(IIJIILkotlin/jvm/internal/DefaultConstructorMarker;)V
     124: aload         14
     126: swap
     127: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     132: pop
     133: goto          49
     136: aload         5
     138: checkcast     #96                 // class java/util/List
     141: nop
     142: checkcast     #60                 // class java/util/Collection
     145: invokestatic  #100                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     148: astore_1
     149: aload_1
     150: aload_1
     151: invokedynamic #146,  0            // InvokeDynamic #0:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     156: invokestatic  #152                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     159: bipush        10
     161: invokestatic  #156                // Method kotlin/sequences/SequencesKt.drop:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     164: invokestatic  #160                // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
     167: checkcast     #96                 // class java/util/List
     170: astore_2
     171: aload_2
     172: invokestatic  #107                // Method summedCoordinates:(Ljava/util/List;)J
     175: lreturn

  private static final java.util.List<day20.Num> mix(java.util.List<day20.Num>, java.util.List<day20.Num>, int);
    Code:
       0: iload_2
       1: aload_0
       2: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
       7: if_icmpne     12
      10: aload_0
      11: areturn
      12: aload_0
      13: astore        4
      15: iconst_0
      16: istore        5
      18: iconst_0
      19: istore        6
      21: aload         4
      23: invokeinterface #169,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      28: astore        7
      30: aload         7
      32: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          154
      40: aload         7
      42: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: astore        8
      49: aload         8
      51: checkcast     #81                 // class day20/Num
      54: astore        9
      56: iconst_0
      57: istore        10
      59: aload         9
      61: aload_1
      62: checkcast     #46                 // class java/lang/Iterable
      65: astore        11
      67: astore        12
      69: iconst_0
      70: istore        13
      72: aload         11
      74: invokeinterface #64,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      79: astore        14
      81: aload         14
      83: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      88: ifeq          132
      91: aload         14
      93: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      98: astore        15
     100: aload         15
     102: checkcast     #81                 // class day20/Num
     105: astore        16
     107: iconst_0
     108: istore        17
     110: aload         16
     112: invokevirtual #172                // Method day20/Num.getOriginalPosition:()I
     115: iload_2
     116: if_icmpne     123
     119: iconst_1
     120: goto          124
     123: iconst_0
     124: ifeq          81
     127: aload         15
     129: goto          133
     132: aconst_null
     133: aload         12
     135: swap
     136: invokestatic  #176                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     139: nop
     140: ifeq          148
     143: iload         6
     145: goto          155
     148: iinc          6, 1
     151: goto          30
     154: iconst_m1
     155: istore_3
     156: aload_0
     157: iload_3
     158: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     163: checkcast     #81                 // class day20/Num
     166: astore        4
     168: iload_3
     169: i2l
     170: aload         4
     172: invokevirtual #184                // Method day20/Num.getNumber:()J
     175: ladd
     176: aload_0
     177: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
     182: iconst_1
     183: isub
     184: i2l
     185: lrem
     186: lstore        5
     188: lload         5
     190: lconst_0
     191: lcmp
     192: ifgt          209
     195: lload         5
     197: aload_0
     198: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
     203: iconst_1
     204: isub
     205: i2l
     206: ladd
     207: lstore        5
     209: aload_0
     210: iload_3
     211: invokeinterface #187,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     216: pop
     217: aload_0
     218: lload         5
     220: l2i
     221: aload         4
     223: invokevirtual #191                // Method day20/Num.move:()Lday20/Num;
     226: invokeinterface #194,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     231: aload_0
     232: aload_0
     233: iload_2
     234: iconst_1
     235: iadd
     236: invokestatic  #196                // Method mix:(Ljava/util/List;Ljava/util/List;I)Ljava/util/List;
     239: areturn

  static java.util.List mix$default(java.util.List, java.util.List, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: aload_0
       7: astore_1
       8: iload_3
       9: iconst_4
      10: iand
      11: ifeq          16
      14: iconst_0
      15: istore_2
      16: aload_0
      17: aload_1
      18: iload_2
      19: invokestatic  #196                // Method mix:(Ljava/util/List;Ljava/util/List;I)Ljava/util/List;
      22: areturn

  private static final long summedCoordinates(java.util.List<day20.Num>);
    Code:
       0: aload_0
       1: astore_2
       2: iconst_0
       3: istore_3
       4: iconst_0
       5: istore        4
       7: aload_2
       8: invokeinterface #169,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      13: astore        5
      15: aload         5
      17: invokeinterface #70,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifeq          73
      25: aload         5
      27: invokeinterface #74,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      32: astore        6
      34: aload         6
      36: checkcast     #81                 // class day20/Num
      39: astore        7
      41: iconst_0
      42: istore        8
      44: aload         7
      46: invokevirtual #184                // Method day20/Num.getNumber:()J
      49: lconst_0
      50: lcmp
      51: ifne          58
      54: iconst_1
      55: goto          59
      58: iconst_0
      59: ifeq          67
      62: iload         4
      64: goto          74
      67: iinc          4, 1
      70: goto          15
      73: iconst_m1
      74: istore_1
      75: aload_0
      76: iload_1
      77: sipush        1000
      80: iadd
      81: aload_0
      82: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
      87: irem
      88: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      93: checkcast     #81                 // class day20/Num
      96: invokevirtual #184                // Method day20/Num.getNumber:()J
      99: lstore_2
     100: aload_0
     101: iload_1
     102: sipush        2000
     105: iadd
     106: aload_0
     107: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
     112: irem
     113: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #81                 // class day20/Num
     121: invokevirtual #184                // Method day20/Num.getNumber:()J
     124: lstore        4
     126: aload_0
     127: iload_1
     128: sipush        3000
     131: iadd
     132: aload_0
     133: invokeinterface #168,  1          // InterfaceMethod java/util/List.size:()I
     138: irem
     139: invokeinterface #180,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     144: checkcast     #81                 // class day20/Num
     147: invokevirtual #184                // Method day20/Num.getNumber:()J
     150: lstore        6
     152: lload_2
     153: lload         4
     155: ladd
     156: lload         6
     158: ladd
     159: lreturn

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

  private static final java.util.List part2$lambda$2(java.util.List, java.util.List);
    Code:
       0: aload_1
       1: ldc           #225                // String it
       3: invokestatic  #44                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: iconst_0
       9: iconst_4
      10: aconst_null
      11: invokestatic  #104                // Method mix$default:(Ljava/util/List;Ljava/util/List;IILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #60                 // class java/util/Collection
      17: invokestatic  #100                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
      20: areturn
}


package day16

import kotlin.math.max
import readInput

const val START = "AA"

val flowRegex = """(\d+)""".toRegex()
val valveRegex = """[A-Z]{2}""".toRegex()

var totalTime = 30
var maxPressureRelease = 0
var allValves: Map<String, Valve> = mapOf()
var shortestPaths: MutableMap<String, MutableMap<String, Int>> = mutableMapOf()

fun main() {
    val input = readInput("main/day16/Day16_test")
    println(part1(input))
    println(part2(input))
}

fun part1(input: List<String>): Int {
    prepareSearch(input)

    checkAllPaths(0, START, emptySet(), 0)
    return maxPressureRelease
}

fun part2(input: List<String>): Int {
    totalTime = 26
    prepareSearch(input)

    checkAllPaths(0, START, emptySet(), 0, true)
    return maxPressureRelease
}

private fun prepareSearch(input: List<String>) {
    maxPressureRelease = 0
    val valves = input.map { it.parse() }

    allValves = valves.associateBy { it.id }
    shortestPaths =
        shortestPathsFromEachTunnelToAllOtherTunnels(
            valves.associate {
                it.id to it.neighbouringValves.associateWith { 1 }
                    .toMutableMap()
            }.toMutableMap()
        )
}

private fun checkAllPaths(currentPressureRelease: Int, currentValveId: String, visited: Set<String>, time: Int, withElefant: Boolean = false) {
    maxPressureRelease = max(maxPressureRelease, currentPressureRelease)
    shortestPaths[currentValveId]!!.forEach { (valveId, distance) ->
        if (!visited.contains(valveId) && time + distance + 1 < totalTime) {
            checkAllPaths(
                currentPressureRelease = currentPressureRelease + (totalTime - time - distance - 1) * allValves[valveId]?.flow!!,
                currentValveId = valveId,
                visited = visited + valveId,
                time = time + distance + 1,
                withElefant = withElefant
            )
        }
    }
    if (withElefant) {
        checkAllPaths(currentPressureRelease, START, visited, 0, false)
    }
}

private fun shortestPathsFromEachTunnelToAllOtherTunnels(shortestPaths: MutableMap<String, MutableMap<String, Int>>): MutableMap<String, MutableMap<String, Int>> {
    shortestPaths.keys.forEach { a ->
        shortestPaths.keys.forEach { b ->
            shortestPaths.keys.forEach { c ->
                val ab = shortestPaths[b]?.get(a) ?: 100
                val ac = shortestPaths[a]?.get(c) ?: 100
                val bc = shortestPaths[b]?.get(c) ?: 100
                if (ab + ac < bc)
                    shortestPaths[b]?.set(c, ab + ac)
            }
        }
    }
    shortestPaths.values.forEach {
        it.keys.mapNotNull { key -> if (allValves[key]?.flow == 0) key else null }
            .forEach { uselessValve ->
                it.remove(uselessValve)
            }
    }
    return shortestPaths
}

fun String.parse(): Valve {
    val valves = valveRegex.findAll(this).map { it.groupValues.first() }.toList()
    val flow = flowRegex.findAll(this).first().groupValues.first().toInt()
    val tunnels = valves.drop(1)
    return Valve(id = valves.first(), flow = flow, neighbouringValves = tunnels)
}

data class Valve(val id: String, val flow: Int, val neighbouringValves: List<String>)

Compiled from "day16.kt"
public final class day16.Day16Kt {
  public static final java.lang.String START;

  private static final kotlin.text.Regex flowRegex;

  private static final kotlin.text.Regex valveRegex;

  private static int totalTime;

  private static int maxPressureRelease;

  private static java.util.Map<java.lang.String, day16.Valve> allValves;

  private static java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Integer>> shortestPaths;

  public static final kotlin.text.Regex getFlowRegex();
    Code:
       0: getstatic     #11                 // Field flowRegex:Lkotlin/text/Regex;
       3: areturn

  public static final kotlin.text.Regex getValveRegex();
    Code:
       0: getstatic     #15                 // Field valveRegex:Lkotlin/text/Regex;
       3: areturn

  public static final int getTotalTime();
    Code:
       0: getstatic     #21                 // Field totalTime:I
       3: ireturn

  public static final void setTotalTime(int);
    Code:
       0: iload_0
       1: putstatic     #21                 // Field totalTime:I
       4: return

  public static final int getMaxPressureRelease();
    Code:
       0: getstatic     #28                 // Field maxPressureRelease:I
       3: ireturn

  public static final void setMaxPressureRelease(int);
    Code:
       0: iload_0
       1: putstatic     #28                 // Field maxPressureRelease:I
       4: return

  public static final java.util.Map<java.lang.String, day16.Valve> getAllValves();
    Code:
       0: getstatic     #36                 // Field allValves:Ljava/util/Map;
       3: areturn

  public static final void setAllValves(java.util.Map<java.lang.String, day16.Valve>);
    Code:
       0: aload_0
       1: ldc           #40                 // String <set-?>
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #36                 // Field allValves:Ljava/util/Map;
      10: return

  public static final java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Integer>> getShortestPaths();
    Code:
       0: getstatic     #51                 // Field shortestPaths:Ljava/util/Map;
       3: areturn

  public static final void setShortestPaths(java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_0
       1: ldc           #40                 // String <set-?>
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #51                 // Field shortestPaths:Ljava/util/Map;
      10: return

  public static final void main();
    Code:
       0: ldc           #57                 // String main/day16/Day16_test
       2: invokestatic  #63                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #67                 // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #78                 // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #81                 // Method part2:(Ljava/util/List;)I
      22: istore_1
      23: getstatic     #73                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: iload_1
      27: invokevirtual #78                 // Method java/io/PrintStream.println:(I)V
      30: return

  public static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #85                 // String input
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #89                 // Method prepareSearch:(Ljava/util/List;)V
      10: iconst_0
      11: ldc           #91                 // String AA
      13: invokestatic  #97                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      16: iconst_0
      17: iconst_0
      18: bipush        16
      20: aconst_null
      21: invokestatic  #101                // Method checkAllPaths$default:(ILjava/lang/String;Ljava/util/Set;IZILjava/lang/Object;)V
      24: getstatic     #28                 // Field maxPressureRelease:I
      27: ireturn

  public static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #85                 // String input
       3: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        26
       8: putstatic     #21                 // Field totalTime:I
      11: aload_0
      12: invokestatic  #89                 // Method prepareSearch:(Ljava/util/List;)V
      15: iconst_0
      16: ldc           #91                 // String AA
      18: invokestatic  #97                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
      21: iconst_0
      22: iconst_1
      23: invokestatic  #105                // Method checkAllPaths:(ILjava/lang/String;Ljava/util/Set;IZ)V
      26: getstatic     #28                 // Field maxPressureRelease:I
      29: ireturn

  private static final void prepareSearch(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: putstatic     #28                 // Field maxPressureRelease:I
       4: aload_0
       5: checkcast     #108                // class java/lang/Iterable
       8: astore_2
       9: iconst_0
      10: istore_3
      11: aload_2
      12: astore        4
      14: new           #110                // class java/util/ArrayList
      17: dup
      18: aload_2
      19: bipush        10
      21: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      24: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
      27: checkcast     #121                // class java/util/Collection
      30: astore        5
      32: iconst_0
      33: istore        6
      35: aload         4
      37: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        7
      44: aload         7
      46: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          94
      54: aload         7
      56: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        8
      63: aload         5
      65: aload         8
      67: checkcast     #137                // class java/lang/String
      70: astore        9
      72: astore        26
      74: iconst_0
      75: istore        10
      77: aload         9
      79: invokestatic  #141                // Method parse:(Ljava/lang/String;)Lday16/Valve;
      82: aload         26
      84: swap
      85: invokeinterface #145,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      90: pop
      91: goto          44
      94: aload         5
      96: checkcast     #147                // class java/util/List
      99: nop
     100: astore_1
     101: aload_1
     102: checkcast     #108                // class java/lang/Iterable
     105: astore_2
     106: iconst_0
     107: istore_3
     108: aload_2
     109: bipush        10
     111: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     114: invokestatic  #153                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     117: bipush        16
     119: invokestatic  #159                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     122: istore        4
     124: aload_2
     125: astore        5
     127: new           #161                // class java/util/LinkedHashMap
     130: dup
     131: iload         4
     133: invokespecial #162                // Method java/util/LinkedHashMap."<init>":(I)V
     136: checkcast     #164                // class java/util/Map
     139: astore        6
     141: iconst_0
     142: istore        7
     144: aload         5
     146: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     151: astore        8
     153: aload         8
     155: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     160: ifeq          205
     163: aload         8
     165: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: astore        9
     172: aload         6
     174: aload         9
     176: checkcast     #166                // class day16/Valve
     179: astore        10
     181: astore        26
     183: iconst_0
     184: istore        11
     186: aload         10
     188: invokevirtual #170                // Method day16/Valve.getId:()Ljava/lang/String;
     191: aload         26
     193: swap
     194: aload         9
     196: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     201: pop
     202: goto          153
     205: aload         6
     207: nop
     208: putstatic     #36                 // Field allValves:Ljava/util/Map;
     211: aload_1
     212: checkcast     #108                // class java/lang/Iterable
     215: astore_2
     216: iconst_0
     217: istore_3
     218: aload_2
     219: bipush        10
     221: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     224: invokestatic  #153                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     227: bipush        16
     229: invokestatic  #159                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     232: istore        4
     234: aload_2
     235: astore        5
     237: new           #161                // class java/util/LinkedHashMap
     240: dup
     241: iload         4
     243: invokespecial #162                // Method java/util/LinkedHashMap."<init>":(I)V
     246: checkcast     #164                // class java/util/Map
     249: astore        6
     251: iconst_0
     252: istore        7
     254: aload         5
     256: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     261: astore        8
     263: aload         8
     265: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     270: ifeq          456
     273: aload         8
     275: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     280: astore        9
     282: aload         6
     284: astore        10
     286: aload         9
     288: checkcast     #166                // class day16/Valve
     291: astore        11
     293: iconst_0
     294: istore        12
     296: aload         11
     298: invokevirtual #170                // Method day16/Valve.getId:()Ljava/lang/String;
     301: aload         11
     303: invokevirtual #178                // Method day16/Valve.getNeighbouringValves:()Ljava/util/List;
     306: checkcast     #108                // class java/lang/Iterable
     309: astore        13
     311: astore        14
     313: iconst_0
     314: istore        15
     316: new           #161                // class java/util/LinkedHashMap
     319: dup
     320: aload         13
     322: bipush        10
     324: invokestatic  #116                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     327: invokestatic  #153                // Method kotlin/collections/MapsKt.mapCapacity:(I)I
     330: bipush        16
     332: invokestatic  #159                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
     335: invokespecial #162                // Method java/util/LinkedHashMap."<init>":(I)V
     338: astore        16
     340: aload         13
     342: astore        17
     344: iconst_0
     345: istore        18
     347: aload         17
     349: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     354: astore        19
     356: aload         19
     358: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     363: ifeq          417
     366: aload         19
     368: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     373: astore        20
     375: aload         16
     377: checkcast     #164                // class java/util/Map
     380: aload         20
     382: aload         20
     384: checkcast     #137                // class java/lang/String
     387: astore        21
     389: astore        22
     391: astore        23
     393: iconst_0
     394: istore        24
     396: iconst_1
     397: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     400: astore        25
     402: aload         23
     404: aload         22
     406: aload         25
     408: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     413: pop
     414: goto          356
     417: aload         16
     419: checkcast     #164                // class java/util/Map
     422: nop
     423: aload         14
     425: swap
     426: invokestatic  #188                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     429: invokestatic  #194                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     432: nop
     433: astore        11
     435: aload         10
     437: aload         11
     439: invokevirtual #199                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     442: aload         11
     444: invokevirtual #202                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     447: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     452: pop
     453: goto          263
     456: aload         6
     458: nop
     459: invokestatic  #188                // Method kotlin/collections/MapsKt.toMutableMap:(Ljava/util/Map;)Ljava/util/Map;
     462: invokestatic  #205                // Method shortestPathsFromEachTunnelToAllOtherTunnels:(Ljava/util/Map;)Ljava/util/Map;
     465: putstatic     #51                 // Field shortestPaths:Ljava/util/Map;
     468: return

  private static final void checkAllPaths(int, java.lang.String, java.util.Set<java.lang.String>, int, boolean);
    Code:
       0: getstatic     #28                 // Field maxPressureRelease:I
       3: iload_0
       4: invokestatic  #244                // Method java/lang/Math.max:(II)I
       7: putstatic     #28                 // Field maxPressureRelease:I
      10: getstatic     #51                 // Field shortestPaths:Ljava/util/Map;
      13: aload_1
      14: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      19: dup
      20: invokestatic  #252                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      23: checkcast     #164                // class java/util/Map
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         5
      33: invokeinterface #255,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      38: invokeinterface #258,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      43: astore        7
      45: aload         7
      47: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          196
      55: aload         7
      57: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: checkcast     #260                // class java/util/Map$Entry
      65: astore        8
      67: aload         8
      69: astore        9
      71: iconst_0
      72: istore        10
      74: aload         9
      76: invokeinterface #263,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      81: checkcast     #137                // class java/lang/String
      84: astore        11
      86: aload         9
      88: invokeinterface #266,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      93: checkcast     #268                // class java/lang/Number
      96: invokevirtual #271                // Method java/lang/Number.intValue:()I
      99: istore        12
     101: aload_2
     102: aload         11
     104: invokeinterface #274,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     109: ifne          191
     112: iload_3
     113: iload         12
     115: iadd
     116: iconst_1
     117: iadd
     118: getstatic     #21                 // Field totalTime:I
     121: if_icmpge     191
     124: iload_0
     125: getstatic     #21                 // Field totalTime:I
     128: iload_3
     129: isub
     130: iload         12
     132: isub
     133: iconst_1
     134: isub
     135: getstatic     #36                 // Field allValves:Ljava/util/Map;
     138: aload         11
     140: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     145: checkcast     #166                // class day16/Valve
     148: dup
     149: ifnull        161
     152: invokevirtual #277                // Method day16/Valve.getFlow:()I
     155: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     158: goto          163
     161: pop
     162: aconst_null
     163: dup
     164: invokestatic  #252                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     167: invokevirtual #278                // Method java/lang/Integer.intValue:()I
     170: imul
     171: iadd
     172: aload         11
     174: aload_2
     175: aload         11
     177: invokestatic  #282                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     180: iload_3
     181: iload         12
     183: iadd
     184: iconst_1
     185: iadd
     186: iload         4
     188: invokestatic  #105                // Method checkAllPaths:(ILjava/lang/String;Ljava/util/Set;IZ)V
     191: nop
     192: nop
     193: goto          45
     196: nop
     197: iload         4
     199: ifeq          211
     202: iload_0
     203: ldc           #91                 // String AA
     205: aload_2
     206: iconst_0
     207: iconst_0
     208: invokestatic  #105                // Method checkAllPaths:(ILjava/lang/String;Ljava/util/Set;IZ)V
     211: return

  static void checkAllPaths$default(int, java.lang.String, java.util.Set, int, boolean, int, java.lang.Object);
    Code:
       0: iload         5
       2: bipush        16
       4: iand
       5: ifeq          11
       8: iconst_0
       9: istore        4
      11: iload_0
      12: aload_1
      13: aload_2
      14: iload_3
      15: iload         4
      17: invokestatic  #105                // Method checkAllPaths:(ILjava/lang/String;Ljava/util/Set;IZ)V
      20: return

  private static final java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Integer>> shortestPathsFromEachTunnelToAllOtherTunnels(java.util.Map<java.lang.String, java.util.Map<java.lang.String, java.lang.Integer>>);
    Code:
       0: aload_0
       1: invokeinterface #300,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
       6: checkcast     #108                // class java/lang/Iterable
       9: astore_1
      10: iconst_0
      11: istore_2
      12: aload_1
      13: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore_3
      19: aload_3
      20: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      25: ifeq          333
      28: aload_3
      29: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      34: astore        4
      36: aload         4
      38: checkcast     #137                // class java/lang/String
      41: astore        5
      43: iconst_0
      44: istore        6
      46: aload_0
      47: invokeinterface #300,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      52: checkcast     #108                // class java/lang/Iterable
      55: astore        7
      57: iconst_0
      58: istore        8
      60: aload         7
      62: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      67: astore        9
      69: aload         9
      71: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          327
      79: aload         9
      81: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: astore        10
      88: aload         10
      90: checkcast     #137                // class java/lang/String
      93: astore        11
      95: iconst_0
      96: istore        12
      98: aload_0
      99: invokeinterface #300,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     104: checkcast     #108                // class java/lang/Iterable
     107: astore        13
     109: iconst_0
     110: istore        14
     112: aload         13
     114: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     119: astore        15
     121: aload         15
     123: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     128: ifeq          321
     131: aload         15
     133: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     138: astore        16
     140: aload         16
     142: checkcast     #137                // class java/lang/String
     145: astore        17
     147: iconst_0
     148: istore        18
     150: aload_0
     151: aload         11
     153: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     158: checkcast     #164                // class java/util/Map
     161: dup
     162: ifnull        185
     165: aload         5
     167: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     172: checkcast     #180                // class java/lang/Integer
     175: dup
     176: ifnull        185
     179: invokevirtual #278                // Method java/lang/Integer.intValue:()I
     182: goto          188
     185: pop
     186: bipush        100
     188: istore        19
     190: aload_0
     191: aload         5
     193: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     198: checkcast     #164                // class java/util/Map
     201: dup
     202: ifnull        225
     205: aload         17
     207: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     212: checkcast     #180                // class java/lang/Integer
     215: dup
     216: ifnull        225
     219: invokevirtual #278                // Method java/lang/Integer.intValue:()I
     222: goto          228
     225: pop
     226: bipush        100
     228: istore        20
     230: aload_0
     231: aload         11
     233: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     238: checkcast     #164                // class java/util/Map
     241: dup
     242: ifnull        265
     245: aload         17
     247: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     252: checkcast     #180                // class java/lang/Integer
     255: dup
     256: ifnull        265
     259: invokevirtual #278                // Method java/lang/Integer.intValue:()I
     262: goto          268
     265: pop
     266: bipush        100
     268: istore        21
     270: iload         19
     272: iload         20
     274: iadd
     275: iload         21
     277: if_icmpge     316
     280: aload_0
     281: aload         11
     283: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     288: checkcast     #164                // class java/util/Map
     291: dup
     292: ifnull        314
     295: aload         17
     297: iload         19
     299: iload         20
     301: iadd
     302: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     305: invokeinterface #174,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     310: pop
     311: goto          316
     314: pop
     315: nop
     316: nop
     317: nop
     318: goto          121
     321: nop
     322: nop
     323: nop
     324: goto          69
     327: nop
     328: nop
     329: nop
     330: goto          19
     333: nop
     334: aload_0
     335: invokeinterface #304,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
     340: checkcast     #108                // class java/lang/Iterable
     343: astore_1
     344: iconst_0
     345: istore_2
     346: aload_1
     347: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     352: astore_3
     353: aload_3
     354: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     359: ifeq          610
     362: aload_3
     363: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     368: astore        4
     370: aload         4
     372: checkcast     #164                // class java/util/Map
     375: astore        5
     377: iconst_0
     378: istore        6
     380: aload         5
     382: invokeinterface #300,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
     387: checkcast     #108                // class java/lang/Iterable
     390: astore        7
     392: iconst_0
     393: istore        8
     395: aload         7
     397: astore        9
     399: new           #110                // class java/util/ArrayList
     402: dup
     403: invokespecial #306                // Method java/util/ArrayList."<init>":()V
     406: checkcast     #121                // class java/util/Collection
     409: astore        10
     411: iconst_0
     412: istore        11
     414: aload         9
     416: astore        12
     418: iconst_0
     419: istore        13
     421: aload         12
     423: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     428: astore        14
     430: aload         14
     432: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     437: ifeq          535
     440: aload         14
     442: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     447: astore        15
     449: aload         15
     451: astore        16
     453: iconst_0
     454: istore        17
     456: aload         16
     458: checkcast     #137                // class java/lang/String
     461: astore        18
     463: iconst_0
     464: istore        19
     466: getstatic     #36                 // Field allValves:Ljava/util/Map;
     469: aload         18
     471: invokeinterface #248,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     476: checkcast     #166                // class day16/Valve
     479: dup
     480: ifnull        497
     483: invokevirtual #277                // Method day16/Valve.getFlow:()I
     486: ifne          493
     489: iconst_1
     490: goto          499
     493: iconst_0
     494: goto          499
     497: pop
     498: iconst_0
     499: ifeq          507
     502: aload         18
     504: goto          508
     507: aconst_null
     508: dup
     509: ifnull        530
     512: astore        20
     514: iconst_0
     515: istore        21
     517: aload         10
     519: aload         20
     521: invokeinterface #145,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     526: pop
     527: goto          531
     530: pop
     531: nop
     532: goto          430
     535: nop
     536: aload         10
     538: checkcast     #147                // class java/util/List
     541: nop
     542: checkcast     #108                // class java/lang/Iterable
     545: astore        7
     547: nop
     548: iconst_0
     549: istore        8
     551: aload         7
     553: invokeinterface #125,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     558: astore        9
     560: aload         9
     562: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     567: ifeq          604
     570: aload         9
     572: invokeinterface #135,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     577: astore        10
     579: aload         10
     581: checkcast     #137                // class java/lang/String
     584: astore        11
     586: iconst_0
     587: istore        12
     589: aload         5
     591: aload         11
     593: invokeinterface #309,  2          // InterfaceMethod java/util/Map.remove:(Ljava/lang/Object;)Ljava/lang/Object;
     598: pop
     599: nop
     600: nop
     601: goto          560
     604: nop
     605: nop
     606: nop
     607: goto          353
     610: nop
     611: aload_0
     612: areturn

  public static final day16.Valve parse(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #334                // String <this>
       4: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: getstatic     #15                 // Field valveRegex:Lkotlin/text/Regex;
      10: aload_0
      11: checkcast     #336                // class java/lang/CharSequence
      14: iconst_0
      15: iconst_2
      16: aconst_null
      17: invokestatic  #342                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      20: invokedynamic #360,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      25: invokestatic  #366                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      28: invokestatic  #370                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      31: astore_1
      32: getstatic     #11                 // Field flowRegex:Lkotlin/text/Regex;
      35: aload_0
      36: checkcast     #336                // class java/lang/CharSequence
      39: iconst_0
      40: iconst_2
      41: aconst_null
      42: invokestatic  #342                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      45: invokestatic  #374                // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
      48: checkcast     #376                // class kotlin/text/MatchResult
      51: invokeinterface #379,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      56: invokestatic  #382                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      59: checkcast     #137                // class java/lang/String
      62: invokestatic  #386                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      65: istore_2
      66: aload_1
      67: checkcast     #108                // class java/lang/Iterable
      70: iconst_1
      71: invokestatic  #390                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      74: astore_3
      75: new           #166                // class day16/Valve
      78: dup
      79: aload_1
      80: invokestatic  #382                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      83: checkcast     #137                // class java/lang/String
      86: iload_2
      87: aload_3
      88: invokespecial #393                // Method day16/Valve."<init>":(Ljava/lang/String;ILjava/util/List;)V
      91: areturn

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

  private static final java.lang.String parse$lambda$11(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #402                // String it
       4: invokestatic  #46                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #379,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      13: invokestatic  #382                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      16: checkcast     #137                // class java/lang/String
      19: areturn

  static {};
    Code:
       0: new           #338                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #406                // String (\\d+)
       7: invokespecial #409                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: putstatic     #11                 // Field flowRegex:Lkotlin/text/Regex;
      13: new           #338                // class kotlin/text/Regex
      16: dup
      17: ldc_w         #411                // String [A-Z]{2}
      20: invokespecial #409                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      23: putstatic     #15                 // Field valveRegex:Lkotlin/text/Regex;
      26: bipush        30
      28: putstatic     #21                 // Field totalTime:I
      31: invokestatic  #414                // Method kotlin/collections/MapsKt.emptyMap:()Ljava/util/Map;
      34: putstatic     #36                 // Field allValves:Ljava/util/Map;
      37: new           #161                // class java/util/LinkedHashMap
      40: dup
      41: invokespecial #415                // Method java/util/LinkedHashMap."<init>":()V
      44: checkcast     #164                // class java/util/Map
      47: putstatic     #51                 // Field shortestPaths:Ljava/util/Map;
      50: return
}


package day10

import readInput

fun main() {
    val input = readInput("main/day10/Day10")

    println(part1(input))
    part2(input)
}

fun part1(input: List<String>): Int {
    val cycles = input.toCycles()
    val interestingCycles = listOf(20, 60, 100, 140, 180, 220)

    return interestingCycles.sumOf { cycles[it - 1] * it }
}

fun part2(input: List<String>) {
    val cycleMap = input.toCycles()

    val crt = cycleMap.mapIndexed { index, register ->
        val sprite = register - 1..register + 1
        if (index % 40 in sprite) "#" else " "
    }

    crt.forEachIndexed { index, s ->
        print(s)
        if (index % 40 == 39) println()
    }
}

private fun List<String>.toCycles(): List<Int> {
    var x = 1
    val cycles = mutableListOf<Int>()
    forEach {
        if (it.startsWith("noop")) {
            cycles.add(x)
        } else {
            repeat(2) { cycles.add(x) }
            x += it.split(" ").last().toInt()
        }
    }
    return cycles
}

Compiled from "day10.kt"
public final class day10.Day10Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String main/day10/Day10
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #30                 // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #34                 // Method part2:(Ljava/util/List;)V
      22: return

  public static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #39                 // String input
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #49                 // Method toCycles:(Ljava/util/List;)Ljava/util/List;
      10: astore_1
      11: bipush        6
      13: anewarray     #51                 // class java/lang/Integer
      16: astore_3
      17: aload_3
      18: iconst_0
      19: bipush        20
      21: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: aastore
      25: aload_3
      26: iconst_1
      27: bipush        60
      29: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: aastore
      33: aload_3
      34: iconst_2
      35: bipush        100
      37: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: aastore
      41: aload_3
      42: iconst_3
      43: sipush        140
      46: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: aastore
      50: aload_3
      51: iconst_4
      52: sipush        180
      55: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      58: aastore
      59: aload_3
      60: iconst_5
      61: sipush        220
      64: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      67: aastore
      68: aload_3
      69: invokestatic  #61                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      72: astore_2
      73: aload_2
      74: checkcast     #63                 // class java/lang/Iterable
      77: astore_3
      78: iconst_0
      79: istore        4
      81: aload_3
      82: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      87: astore        5
      89: aload         5
      91: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      96: ifeq          156
      99: aload         5
     101: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     106: astore        6
     108: iload         4
     110: aload         6
     112: checkcast     #79                 // class java/lang/Number
     115: invokevirtual #83                 // Method java/lang/Number.intValue:()I
     118: istore        7
     120: istore        9
     122: iconst_0
     123: istore        8
     125: aload_1
     126: iload         7
     128: iconst_1
     129: isub
     130: invokeinterface #89,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     135: checkcast     #79                 // class java/lang/Number
     138: invokevirtual #83                 // Method java/lang/Number.intValue:()I
     141: iload         7
     143: imul
     144: istore        10
     146: iload         9
     148: iload         10
     150: iadd
     151: istore        4
     153: goto          89
     156: iload         4
     158: ireturn

  public static final void part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #39                 // String input
       3: invokestatic  #45                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #49                 // Method toCycles:(Ljava/util/List;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: checkcast     #63                 // class java/lang/Iterable
      15: astore_3
      16: iconst_0
      17: istore        4
      19: aload_3
      20: astore        5
      22: new           #97                 // class java/util/ArrayList
      25: dup
      26: aload_3
      27: bipush        10
      29: invokestatic  #101                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #104                // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #106                // class java/util/Collection
      38: astore        6
      40: iconst_0
      41: istore        7
      43: iconst_0
      44: istore        8
      46: aload         5
      48: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        9
      55: aload         9
      57: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          193
      65: aload         9
      67: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        10
      74: aload         6
      76: iload         8
      78: iinc          8, 1
      81: istore        11
      83: iload         11
      85: ifge          91
      88: invokestatic  #109                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      91: iload         11
      93: aload         10
      95: checkcast     #79                 // class java/lang/Number
      98: invokevirtual #83                 // Method java/lang/Number.intValue:()I
     101: istore        12
     103: istore        13
     105: astore        19
     107: iconst_0
     108: istore        14
     110: new           #111                // class kotlin/ranges/IntRange
     113: dup
     114: iload         12
     116: iconst_1
     117: isub
     118: iload         12
     120: iconst_1
     121: iadd
     122: invokespecial #114                // Method kotlin/ranges/IntRange."<init>":(II)V
     125: astore        15
     127: aload         15
     129: invokevirtual #117                // Method kotlin/ranges/IntRange.getFirst:()I
     132: istore        16
     134: aload         15
     136: invokevirtual #120                // Method kotlin/ranges/IntRange.getLast:()I
     139: istore        17
     141: iload         13
     143: bipush        40
     145: irem
     146: istore        18
     148: iload         16
     150: iload         18
     152: if_icmpgt     170
     155: iload         18
     157: iload         17
     159: if_icmpgt     166
     162: iconst_1
     163: goto          171
     166: iconst_0
     167: goto          171
     170: iconst_0
     171: ifeq          179
     174: ldc           #122                // String #
     176: goto          181
     179: ldc           #124                // String
     181: aload         19
     183: swap
     184: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     189: pop
     190: goto          55
     193: aload         6
     195: checkcast     #85                 // class java/util/List
     198: nop
     199: astore_2
     200: aload_2
     201: checkcast     #63                 // class java/lang/Iterable
     204: astore_3
     205: iconst_0
     206: istore        4
     208: iconst_0
     209: istore        5
     211: aload_3
     212: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     217: astore        6
     219: aload         6
     221: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     226: ifeq          296
     229: aload         6
     231: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     236: astore        7
     238: iload         5
     240: iinc          5, 1
     243: istore        8
     245: iload         8
     247: ifge          253
     250: invokestatic  #109                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     253: iload         8
     255: aload         7
     257: checkcast     #130                // class java/lang/String
     260: astore        9
     262: istore        10
     264: iconst_0
     265: istore        11
     267: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
     270: aload         9
     272: invokevirtual #134                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     275: iload         10
     277: bipush        40
     279: irem
     280: bipush        39
     282: if_icmpne     291
     285: getstatic     #24                 // Field java/lang/System.out:Ljava/io/PrintStream;
     288: invokevirtual #136                // Method java/io/PrintStream.println:()V
     291: nop
     292: nop
     293: goto          219
     296: nop
     297: return

  private static final java.util.List<java.lang.Integer> toCycles(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_1
       3: istore_1
       4: new           #97                 // class java/util/ArrayList
       7: dup
       8: invokespecial #163                // Method java/util/ArrayList."<init>":()V
      11: checkcast     #85                 // class java/util/List
      14: astore_2
      15: aload_0
      16: checkcast     #63                 // class java/lang/Iterable
      19: astore_3
      20: iconst_0
      21: istore        4
      23: aload_3
      24: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      29: astore        5
      31: aload         5
      33: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      38: ifeq          168
      41: aload         5
      43: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: astore        6
      50: aload         6
      52: checkcast     #130                // class java/lang/String
      55: astore        7
      57: iconst_0
      58: istore        8
      60: aload         7
      62: ldc           #165                // String noop
      64: iconst_0
      65: iconst_2
      66: aconst_null
      67: invokestatic  #171                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
      70: ifeq          87
      73: aload_2
      74: iload_1
      75: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokeinterface #172,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      83: pop
      84: goto          163
      87: iconst_2
      88: istore        9
      90: iconst_0
      91: istore        10
      93: iload         10
      95: iload         9
      97: if_icmpge     124
     100: iload         10
     102: istore        11
     104: iconst_0
     105: istore        12
     107: aload_2
     108: iload_1
     109: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: invokeinterface #172,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     117: pop
     118: iinc          10, 1
     121: goto          93
     124: iload_1
     125: aload         7
     127: checkcast     #174                // class java/lang/CharSequence
     130: iconst_1
     131: anewarray     #130                // class java/lang/String
     134: astore        9
     136: aload         9
     138: iconst_0
     139: ldc           #124                // String
     141: aastore
     142: aload         9
     144: iconst_0
     145: iconst_0
     146: bipush        6
     148: aconst_null
     149: invokestatic  #178                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     152: invokestatic  #182                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     155: checkcast     #130                // class java/lang/String
     158: invokestatic  #186                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     161: iadd
     162: istore_1
     163: nop
     164: nop
     165: goto          31
     168: nop
     169: aload_2
     170: areturn

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