package day24

import java.nio.file.Files
import java.nio.file.Paths
import java.util.TreeMap
import kotlin.system.measureTimeMillis

fun main() {
  fun Char.registerId() = code - 'w'.code

  val alu = longArrayOf(0, 0, 0, 0)
  var nextInput = -1

  fun String.parseCommand(): Command {
    return if (startsWith("inp ")) {
      Command { alu[this[4].registerId()] = nextInput.toLong().also { check(it in 1..9) } }
    } else {
      val (cmd, a, b) = split(" ")
      check(a.length == 1)
      val register = a.first().registerId()
      val value = { if (b.first() in "wxyz") alu[b.first().registerId()] else b.toLong() }
      when (cmd) {
        "add" -> Command { alu[register] += value() }
        "mul" -> Command { alu[register] *= value() }
        "div" -> Command { alu[register] /= value() }
        "mod" -> Command { alu[register] %= value() }
        "eql" -> Command { alu[register] = if (alu[register] == value()) 1 else 0 }
        else -> error("Unknown command $cmd")
      }
    }
  }

  fun solve(input: Input, comparator: Comparator<Int>): Long {
    check(input.size % 14 == 0)
    val commands = input.map(String::parseCommand).chunked(input.size / 14)

    data class State(val digit: Int, val prevZ: Long) : Comparable<State> {
      override fun compareTo(other: State) = comparator.compare(this.digit, other.digit)
    }

    val mem = Array(15) { TreeMap<Long, State>() }
    mem[0][0] = State(0, Long.MIN_VALUE)
    val pow26 = generateSequence(1L) { it * 26 }.takeWhile { it < Int.MAX_VALUE }.toList()
    for (len in 1..14) {
      val threshold = pow26.getOrElse(15 - len) { Long.MAX_VALUE }
      for (digit in 1..9) {
        nextInput = digit
        for (z in mem[len - 1].keys) {
          if (z > threshold) break // We won't get Z=0 in the end if current Z is too big.
          alu.fill(0); alu['z'.registerId()] = z
          commands[len - 1].forEach { it.execute() }
          mem[len].merge(alu['z'.registerId()], State(digit, z), ::maxOf)
        }
      }
    }

    val (answer, _, _) = mem.foldRight(Triple(0L, 1L, 0L)) { map, (acc, pow10, z) ->
      val (digit, prevZ) = map[z]!!
      Triple(acc + digit * pow10, pow10 * 10, prevZ)
    }
    return answer
  }

  fun part1(input: Input): Long {
    return solve(input, Comparator.naturalOrder())
  }

  fun part2(input: Input): Long {
    return solve(input, Comparator.reverseOrder())
  }

  val millis = measureTimeMillis {
    println(part1(readInput("input.txt")))
    println(part2(readInput("input.txt")))
  }
  System.err.println("Done in $millis ms")
}

private fun interface Command {
  fun execute()
}

private fun readInput(s: String): Input {
  return Files.newBufferedReader(Paths.get("src/day24/$s")).readLines()
}

private typealias Input = List<String>

Compiled from "Solution.kt"
final class day24.SolutionKt$main$solve$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<day24.SolutionKt$main$solve$State, day24.SolutionKt$main$solve$State, day24.SolutionKt$main$solve$State> {
  public static final day24.SolutionKt$main$solve$2 INSTANCE;

  day24.SolutionKt$main$solve$2();
    Code:
       0: aload_0
       1: iconst_2
       2: ldc           #11                 // class kotlin/comparisons/ComparisonsKt
       4: ldc           #13                 // String maxOf
       6: ldc           #15                 // String maxOf(Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final day24.SolutionKt$main$solve$State invoke(day24.SolutionKt$main$solve$State, day24.SolutionKt$main$solve$State);
    Code:
       0: aload_1
       1: ldc           #24                 // String p0
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #32                 // String p1
       9: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: checkcast     #34                 // class java/lang/Comparable
      16: aload_2
      17: checkcast     #34                 // class java/lang/Comparable
      20: invokestatic  #37                 // Method kotlin/comparisons/ComparisonsKt.maxOf:(Ljava/lang/Comparable;Ljava/lang/Comparable;)Ljava/lang/Comparable;
      23: checkcast     #39                 // class day24/SolutionKt$main$solve$State
      26: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #39                 // class day24/SolutionKt$main$solve$State
       5: aload_2
       6: checkcast     #39                 // class day24/SolutionKt$main$solve$State
       9: invokevirtual #43                 // Method invoke:(Lday24/SolutionKt$main$solve$State;Lday24/SolutionKt$main$solve$State;)Lday24/SolutionKt$main$solve$State;
      12: areturn

  static {};
    Code:
       0: new           #2                  // class day24/SolutionKt$main$solve$2
       3: dup
       4: invokespecial #48                 // Method "<init>":()V
       7: putstatic     #51                 // Field INSTANCE:Lday24/SolutionKt$main$solve$2;
      10: return
}

Compiled from "Solution.kt"
public final class day24.SolutionKt$main$solve$State implements java.lang.Comparable<day24.SolutionKt$main$solve$State> {
  private final int digit;

  private final long prevZ;

  final java.util.Comparator<java.lang.Integer> $comparator;

  public day24.SolutionKt$main$solve$State(java.util.Comparator<java.lang.Integer>, int, long);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #14                 // Field $comparator:Ljava/util/Comparator;
       5: aload_0
       6: invokespecial #17                 // Method java/lang/Object."<init>":()V
       9: aload_0
      10: iload_2
      11: putfield      #21                 // Field digit:I
      14: aload_0
      15: lload_3
      16: putfield      #25                 // Field prevZ:J
      19: return

  public final int getDigit();
    Code:
       0: aload_0
       1: getfield      #21                 // Field digit:I
       4: ireturn

  public final long getPrevZ();
    Code:
       0: aload_0
       1: getfield      #25                 // Field prevZ:J
       4: lreturn

  public int compareTo(day24.SolutionKt$main$solve$State);
    Code:
       0: aload_1
       1: ldc           #35                 // String other
       3: invokestatic  #41                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #14                 // Field $comparator:Ljava/util/Comparator;
      10: aload_0
      11: getfield      #21                 // Field digit:I
      14: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: aload_1
      18: getfield      #21                 // Field digit:I
      21: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: invokeinterface #53,  3           // InterfaceMethod java/util/Comparator.compare:(Ljava/lang/Object;Ljava/lang/Object;)I
      29: ireturn

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

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

  public final day24.SolutionKt$main$solve$State copy(int, long);
    Code:
       0: new           #2                  // class day24/SolutionKt$main$solve$State
       3: dup
       4: aload_0
       5: getfield      #14                 // Field $comparator:Ljava/util/Comparator;
       8: iload_1
       9: lload_2
      10: invokespecial #59                 // Method "<init>":(Ljava/util/Comparator;IJ)V
      13: areturn

  public static day24.SolutionKt$main$solve$State copy$default(day24.SolutionKt$main$solve$State, int, long, int, java.lang.Object);
    Code:
       0: iload         4
       2: iconst_1
       3: iand
       4: ifeq          12
       7: aload_0
       8: getfield      #21                 // Field digit:I
      11: istore_1
      12: iload         4
      14: iconst_2
      15: iand
      16: ifeq          24
      19: aload_0
      20: getfield      #25                 // Field prevZ:J
      23: lstore_2
      24: aload_0
      25: iload_1
      26: lload_2
      27: invokevirtual #63                 // Method copy:(IJ)Lday24/SolutionKt$main$solve$State;
      30: areturn

  public java.lang.String toString();
    Code:
       0: new           #67                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #68                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #70                 // String State(digit=
       9: invokevirtual #74                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #21                 // Field digit:I
      16: invokevirtual #77                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #79                 // String , prevZ=
      21: invokevirtual #74                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #25                 // Field prevZ:J
      28: invokevirtual #82                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #85                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #87                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #21                 // Field digit:I
       4: invokestatic  #91                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #25                 // Field prevZ:J
      16: invokestatic  #96                 // 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 day24/SolutionKt$main$solve$State
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class day24/SolutionKt$main$solve$State
      20: astore_2
      21: aload_0
      22: getfield      #21                 // Field digit:I
      25: aload_2
      26: getfield      #21                 // Field digit:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #25                 // Field prevZ:J
      38: aload_2
      39: getfield      #25                 // Field prevZ:J
      42: lcmp
      43: ifeq          48
      46: iconst_0
      47: ireturn
      48: iconst_1
      49: ireturn

  public int compareTo(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #2                  // class day24/SolutionKt$main$solve$State
       5: invokevirtual #103                // Method compareTo:(Lday24/SolutionKt$main$solve$State;)I
       8: ireturn
}

Compiled from "Solution.kt"
public final class day24.SolutionKt {
  public static final void main();
    Code:
       0: iconst_4
       1: newarray       long
       3: astore_1
       4: aload_1
       5: iconst_0
       6: lconst_0
       7: lastore
       8: aload_1
       9: iconst_1
      10: lconst_0
      11: lastore
      12: aload_1
      13: iconst_2
      14: lconst_0
      15: lastore
      16: aload_1
      17: iconst_3
      18: lconst_0
      19: lastore
      20: aload_1
      21: astore_0
      22: new           #8                  // class kotlin/jvm/internal/Ref$IntRef
      25: dup
      26: invokespecial #11                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      29: astore_1
      30: aload_1
      31: iconst_m1
      32: putfield      #15                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      35: iconst_0
      36: istore        4
      38: invokestatic  #21                 // Method java/lang/System.currentTimeMillis:()J
      41: lstore        5
      43: iconst_0
      44: istore        7
      46: aload_1
      47: aload_0
      48: ldc           #23                 // String input.txt
      50: invokestatic  #27                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      53: invokestatic  #31                 // Method main$part1:(Lkotlin/jvm/internal/Ref$IntRef;[JLjava/util/List;)J
      56: lstore        8
      58: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      61: lload         8
      63: invokevirtual #41                 // Method java/io/PrintStream.println:(J)V
      66: aload_1
      67: aload_0
      68: ldc           #23                 // String input.txt
      70: invokestatic  #27                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      73: invokestatic  #44                 // Method main$part2:(Lkotlin/jvm/internal/Ref$IntRef;[JLjava/util/List;)J
      76: lstore        8
      78: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      81: lload         8
      83: invokevirtual #41                 // Method java/io/PrintStream.println:(J)V
      86: nop
      87: nop
      88: invokestatic  #21                 // Method java/lang/System.currentTimeMillis:()J
      91: lload         5
      93: lsub
      94: lstore_2
      95: getstatic     #47                 // Field java/lang/System.err:Ljava/io/PrintStream;
      98: new           #49                 // class java/lang/StringBuilder
     101: dup
     102: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
     105: ldc           #52                 // String Done in
     107: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     110: lload_2
     111: invokevirtual #59                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     114: ldc           #61                 // String  ms
     116: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     119: invokevirtual #65                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     122: invokevirtual #68                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
     125: return

  private static final java.util.List<java.lang.String> readInput(java.lang.String);
    Code:
       0: new           #49                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #80                 // String src/day24/
       9: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      16: invokevirtual #65                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      19: iconst_0
      20: anewarray     #82                 // class java/lang/String
      23: invokestatic  #88                 // Method java/nio/file/Paths.get:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      26: invokestatic  #94                 // Method java/nio/file/Files.newBufferedReader:(Ljava/nio/file/Path;)Ljava/io/BufferedReader;
      29: dup
      30: ldc           #96                 // String newBufferedReader(...)
      32: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      35: checkcast     #104                // class java/io/Reader
      38: invokestatic  #110                // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      41: areturn

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

  private static final int main$registerId(char);
    Code:
       0: iload_0
       1: bipush        119
       3: isub
       4: ireturn

  private static final void main$parseCommand$lambda$1(long[], java.lang.String, kotlin.jvm.internal.Ref$IntRef);
    Code:
       0: aload_0
       1: aload_1
       2: iconst_4
       3: invokevirtual #127                // Method java/lang/String.charAt:(I)C
       6: invokestatic  #129                // Method main$registerId:(C)I
       9: aload_2
      10: getfield      #15                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
      13: i2l
      14: lstore_3
      15: lload_3
      16: lstore        5
      18: istore        9
      20: astore        8
      22: iconst_0
      23: istore        7
      25: lconst_1
      26: lload         5
      28: lcmp
      29: ifgt          49
      32: lload         5
      34: ldc2_w        #130                // long 10l
      37: lcmp
      38: ifge          45
      41: iconst_1
      42: goto          50
      45: iconst_0
      46: goto          50
      49: iconst_0
      50: ifne          63
      53: new           #133                // class java/lang/IllegalStateException
      56: dup
      57: ldc           #135                // String Check failed.
      59: invokespecial #137                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      62: athrow
      63: nop
      64: getstatic     #143                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      67: astore        10
      69: aload         8
      71: iload         9
      73: lload_3
      74: lastore
      75: return

  private static final long main$parseCommand$lambda$2(java.lang.String, long[]);
    Code:
       0: ldc           #153                // String wxyz
       2: checkcast     #155                // class java/lang/CharSequence
       5: aload_0
       6: checkcast     #155                // class java/lang/CharSequence
       9: invokestatic  #161                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
      12: iconst_0
      13: iconst_2
      14: aconst_null
      15: invokestatic  #165                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;CZILjava/lang/Object;)Z
      18: ifeq          36
      21: aload_1
      22: aload_0
      23: checkcast     #155                // class java/lang/CharSequence
      26: invokestatic  #161                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
      29: invokestatic  #129                // Method main$registerId:(C)I
      32: laload
      33: goto          40
      36: aload_0
      37: invokestatic  #171                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      40: lreturn

  private static final void main$parseCommand$lambda$3(long[], int, kotlin.jvm.functions.Function0);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: iload_1
       4: laload
       5: aload_2
       6: invokeinterface #180,  1          // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #182                // class java/lang/Number
      14: invokevirtual #185                // Method java/lang/Number.longValue:()J
      17: ladd
      18: lastore
      19: return

  private static final void main$parseCommand$lambda$4(long[], int, kotlin.jvm.functions.Function0);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: iload_1
       4: laload
       5: aload_2
       6: invokeinterface #180,  1          // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #182                // class java/lang/Number
      14: invokevirtual #185                // Method java/lang/Number.longValue:()J
      17: lmul
      18: lastore
      19: return

  private static final void main$parseCommand$lambda$5(long[], int, kotlin.jvm.functions.Function0);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: iload_1
       4: laload
       5: aload_2
       6: invokeinterface #180,  1          // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #182                // class java/lang/Number
      14: invokevirtual #185                // Method java/lang/Number.longValue:()J
      17: ldiv
      18: lastore
      19: return

  private static final void main$parseCommand$lambda$6(long[], int, kotlin.jvm.functions.Function0);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: iload_1
       4: laload
       5: aload_2
       6: invokeinterface #180,  1          // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #182                // class java/lang/Number
      14: invokevirtual #185                // Method java/lang/Number.longValue:()J
      17: lrem
      18: lastore
      19: return

  private static final void main$parseCommand$lambda$7(long[], int, kotlin.jvm.functions.Function0);
    Code:
       0: aload_0
       1: iload_1
       2: aload_0
       3: iload_1
       4: laload
       5: aload_2
       6: invokeinterface #180,  1          // InterfaceMethod kotlin/jvm/functions/Function0.invoke:()Ljava/lang/Object;
      11: checkcast     #182                // class java/lang/Number
      14: invokevirtual #185                // Method java/lang/Number.longValue:()J
      17: lcmp
      18: ifne          25
      21: lconst_1
      22: goto          26
      25: lconst_0
      26: lastore
      27: return

  private static final day24.Command main$parseCommand(java.lang.String, long[], kotlin.jvm.internal.Ref$IntRef);
    Code:
       0: aload_0
       1: ldc           #196                // String inp
       3: iconst_0
       4: iconst_2
       5: aconst_null
       6: invokestatic  #200                // Method kotlin/text/StringsKt.startsWith$default:(Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Z
       9: ifeq          23
      12: aload_1
      13: aload_0
      14: aload_2
      15: invokedynamic #215,  0            // InvokeDynamic #0:execute:([JLjava/lang/String;Lkotlin/jvm/internal/Ref$IntRef;)Lday24/Command;
      20: goto          359
      23: aload_0
      24: checkcast     #155                // class java/lang/CharSequence
      27: iconst_1
      28: anewarray     #82                 // class java/lang/String
      31: astore        4
      33: aload         4
      35: iconst_0
      36: ldc           #217                // String
      38: aastore
      39: aload         4
      41: iconst_0
      42: iconst_0
      43: bipush        6
      45: aconst_null
      46: invokestatic  #221                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      49: astore_3
      50: aload_3
      51: iconst_0
      52: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      57: checkcast     #82                 // class java/lang/String
      60: astore        4
      62: aload_3
      63: iconst_1
      64: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      69: checkcast     #82                 // class java/lang/String
      72: astore        5
      74: aload_3
      75: iconst_2
      76: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      81: checkcast     #82                 // class java/lang/String
      84: astore        6
      86: aload         5
      88: invokevirtual #230                // Method java/lang/String.length:()I
      91: iconst_1
      92: if_icmpne     99
      95: iconst_1
      96: goto          100
      99: iconst_0
     100: ifne          113
     103: new           #133                // class java/lang/IllegalStateException
     106: dup
     107: ldc           #135                // String Check failed.
     109: invokespecial #137                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     112: athrow
     113: aload         5
     115: checkcast     #155                // class java/lang/CharSequence
     118: invokestatic  #161                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
     121: invokestatic  #129                // Method main$registerId:(C)I
     124: istore        7
     126: aload         6
     128: aload_1
     129: invokedynamic #239,  0            // InvokeDynamic #1:invoke:(Ljava/lang/String;[J)Lkotlin/jvm/functions/Function0;
     134: astore        8
     136: aload         4
     138: astore        9
     140: aload         9
     142: invokevirtual #242                // Method java/lang/String.hashCode:()I
     145: lookupswitch  { // 5
                 96417: 196
                 99473: 209
                100672: 222
                108290: 235
                108484: 248
               default: 327
          }
     196: aload         9
     198: ldc           #244                // String add
     200: invokevirtual #248                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     203: ifne          262
     206: goto          327
     209: aload         9
     211: ldc           #250                // String div
     213: invokevirtual #248                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     216: ifne          288
     219: goto          327
     222: aload         9
     224: ldc           #252                // String eql
     226: invokevirtual #248                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     229: ifne          314
     232: goto          327
     235: aload         9
     237: ldc           #254                // String mod
     239: invokevirtual #248                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     242: ifne          301
     245: goto          327
     248: aload         9
     250: ldc_w         #256                // String mul
     253: invokevirtual #248                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     256: ifne          275
     259: goto          327
     262: aload_1
     263: iload         7
     265: aload         8
     267: invokedynamic #262,  0            // InvokeDynamic #2:execute:([JILkotlin/jvm/functions/Function0;)Lday24/Command;
     272: goto          359
     275: aload_1
     276: iload         7
     278: aload         8
     280: invokedynamic #266,  0            // InvokeDynamic #3:execute:([JILkotlin/jvm/functions/Function0;)Lday24/Command;
     285: goto          359
     288: aload_1
     289: iload         7
     291: aload         8
     293: invokedynamic #270,  0            // InvokeDynamic #4:execute:([JILkotlin/jvm/functions/Function0;)Lday24/Command;
     298: goto          359
     301: aload_1
     302: iload         7
     304: aload         8
     306: invokedynamic #274,  0            // InvokeDynamic #5:execute:([JILkotlin/jvm/functions/Function0;)Lday24/Command;
     311: goto          359
     314: aload_1
     315: iload         7
     317: aload         8
     319: invokedynamic #278,  0            // InvokeDynamic #6:execute:([JILkotlin/jvm/functions/Function0;)Lday24/Command;
     324: goto          359
     327: new           #133                // class java/lang/IllegalStateException
     330: dup
     331: new           #49                 // class java/lang/StringBuilder
     334: dup
     335: invokespecial #50                 // Method java/lang/StringBuilder."<init>":()V
     338: ldc_w         #280                // String Unknown command
     341: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     344: aload         4
     346: invokevirtual #56                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     349: invokevirtual #65                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     352: invokevirtual #281                // Method java/lang/Object.toString:()Ljava/lang/String;
     355: invokespecial #137                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     358: athrow
     359: areturn

  private static final java.lang.Long main$solve$lambda$8(long);
    Code:
       0: lload_0
       1: bipush        26
       3: i2l
       4: lmul
       5: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       8: areturn

  private static final boolean main$solve$lambda$9(long);
    Code:
       0: lload_0
       1: ldc2_w        #297                // long 2147483647l
       4: lcmp
       5: ifge          12
       8: iconst_1
       9: goto          13
      12: iconst_0
      13: ireturn

  private static final day24.SolutionKt$main$solve$State main$solve$lambda$12(kotlin.jvm.functions.Function2, java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokeinterface #305,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
       8: checkcast     #307                // class day24/SolutionKt$main$solve$State
      11: areturn

  private static final long main$solve(kotlin.jvm.internal.Ref$IntRef, long[], java.util.List<java.lang.String>, java.util.Comparator<java.lang.Integer>);
    Code:
       0: aload_2
       1: invokeinterface #318,  1          // InterfaceMethod java/util/List.size:()I
       6: bipush        14
       8: irem
       9: ifne          16
      12: iconst_1
      13: goto          17
      16: iconst_0
      17: ifne          30
      20: new           #133                // class java/lang/IllegalStateException
      23: dup
      24: ldc           #135                // String Check failed.
      26: invokespecial #137                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      29: athrow
      30: aload_2
      31: checkcast     #320                // class java/lang/Iterable
      34: astore        5
      36: iconst_0
      37: istore        6
      39: aload         5
      41: astore        7
      43: new           #322                // class java/util/ArrayList
      46: dup
      47: aload         5
      49: bipush        10
      51: invokestatic  #328                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      54: invokespecial #331                // Method java/util/ArrayList."<init>":(I)V
      57: checkcast     #333                // class java/util/Collection
      60: astore        8
      62: iconst_0
      63: istore        9
      65: aload         7
      67: invokeinterface #337,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        10
      74: aload         10
      76: invokeinterface #343,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          126
      84: aload         10
      86: invokeinterface #346,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      91: astore        11
      93: aload         8
      95: aload         11
      97: checkcast     #82                 // class java/lang/String
     100: astore        12
     102: astore        26
     104: iconst_0
     105: istore        13
     107: aload         12
     109: aload_1
     110: aload_0
     111: invokestatic  #348                // Method main$parseCommand:(Ljava/lang/String;[JLkotlin/jvm/internal/Ref$IntRef;)Lday24/Command;
     114: aload         26
     116: swap
     117: invokeinterface #350,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: goto          74
     126: aload         8
     128: checkcast     #223                // class java/util/List
     131: nop
     132: checkcast     #320                // class java/lang/Iterable
     135: aload_2
     136: invokeinterface #318,  1          // InterfaceMethod java/util/List.size:()I
     141: bipush        14
     143: idiv
     144: invokestatic  #354                // Method kotlin/collections/CollectionsKt.chunked:(Ljava/lang/Iterable;I)Ljava/util/List;
     147: astore        4
     149: iconst_0
     150: istore        6
     152: bipush        15
     154: anewarray     #356                // class java/util/TreeMap
     157: astore        7
     159: iload         6
     161: bipush        15
     163: if_icmpge     188
     166: iload         6
     168: istore        8
     170: aload         7
     172: iload         8
     174: new           #356                // class java/util/TreeMap
     177: dup
     178: invokespecial #357                // Method java/util/TreeMap."<init>":()V
     181: aastore
     182: iinc          6, 1
     185: goto          159
     188: aload         7
     190: astore        5
     192: aload         5
     194: iconst_0
     195: aaload
     196: checkcast     #359                // class java/util/Map
     199: lconst_0
     200: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     203: new           #307                // class day24/SolutionKt$main$solve$State
     206: dup
     207: aload_3
     208: iconst_0
     209: ldc2_w        #360                // long -9223372036854775808l
     212: invokespecial #364                // Method day24/SolutionKt$main$solve$State."<init>":(Ljava/util/Comparator;IJ)V
     215: invokeinterface #367,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     220: pop
     221: lconst_1
     222: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     225: invokedynamic #377,  0            // InvokeDynamic #7:invoke:()Lkotlin/jvm/functions/Function1;
     230: invokestatic  #383                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     233: invokedynamic #389,  0            // InvokeDynamic #8:invoke:()Lkotlin/jvm/functions/Function1;
     238: invokestatic  #393                // Method kotlin/sequences/SequencesKt.takeWhile:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     241: invokestatic  #397                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     244: astore        6
     246: iconst_1
     247: istore        7
     249: iload         7
     251: bipush        15
     253: if_icmpge     549
     256: aload         6
     258: astore        10
     260: bipush        15
     262: iload         7
     264: isub
     265: istore        11
     267: iconst_0
     268: iload         11
     270: if_icmpgt     293
     273: iload         11
     275: aload         10
     277: invokeinterface #318,  1          // InterfaceMethod java/util/List.size:()I
     282: if_icmpge     289
     285: iconst_1
     286: goto          294
     289: iconst_0
     290: goto          294
     293: iconst_0
     294: ifeq          309
     297: aload         10
     299: iload         11
     301: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     306: goto          323
     309: iload         11
     311: istore        12
     313: iconst_0
     314: istore        13
     316: ldc2_w        #398                // long 9223372036854775807l
     319: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     322: nop
     323: checkcast     #182                // class java/lang/Number
     326: invokevirtual #185                // Method java/lang/Number.longValue:()J
     329: lstore        8
     331: iconst_1
     332: istore        10
     334: iload         10
     336: bipush        10
     338: if_icmpge     543
     341: aload_0
     342: iload         10
     344: putfield      #15                 // Field kotlin/jvm/internal/Ref$IntRef.element:I
     347: aload         5
     349: iload         7
     351: iconst_1
     352: isub
     353: aaload
     354: invokevirtual #403                // Method java/util/TreeMap.keySet:()Ljava/util/Set;
     357: invokeinterface #406,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     362: astore        11
     364: aload         11
     366: invokeinterface #343,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     371: ifeq          537
     374: aload         11
     376: invokeinterface #346,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     381: dup
     382: ldc_w         #408                // String next(...)
     385: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     388: checkcast     #182                // class java/lang/Number
     391: invokevirtual #185                // Method java/lang/Number.longValue:()J
     394: lstore        12
     396: lload         12
     398: lload         8
     400: lcmp
     401: ifgt          537
     404: aload_1
     405: lconst_0
     406: iconst_0
     407: iconst_0
     408: bipush        6
     410: aconst_null
     411: invokestatic  #414                // Method kotlin/collections/ArraysKt.fill$default:([JJIIILjava/lang/Object;)V
     414: aload_1
     415: bipush        122
     417: invokestatic  #129                // Method main$registerId:(C)I
     420: lload         12
     422: lastore
     423: aload         4
     425: iload         7
     427: iconst_1
     428: isub
     429: invokeinterface #226,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     434: checkcast     #320                // class java/lang/Iterable
     437: astore        14
     439: iconst_0
     440: istore        15
     442: aload         14
     444: invokeinterface #337,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     449: astore        16
     451: aload         16
     453: invokeinterface #343,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     458: ifeq          491
     461: aload         16
     463: invokeinterface #346,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     468: astore        17
     470: aload         17
     472: checkcast     #289                // class day24/Command
     475: astore        18
     477: iconst_0
     478: istore        19
     480: aload         18
     482: invokeinterface #416,  1          // InterfaceMethod day24/Command.execute:()V
     487: nop
     488: goto          451
     491: nop
     492: aload         5
     494: iload         7
     496: aaload
     497: aload_1
     498: bipush        122
     500: invokestatic  #129                // Method main$registerId:(C)I
     503: laload
     504: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     507: new           #307                // class day24/SolutionKt$main$solve$State
     510: dup
     511: aload_3
     512: iload         10
     514: lload         12
     516: invokespecial #364                // Method day24/SolutionKt$main$solve$State."<init>":(Ljava/util/Comparator;IJ)V
     519: getstatic     #421                // Field day24/SolutionKt$main$solve$2.INSTANCE:Lday24/SolutionKt$main$solve$2;
     522: checkcast     #302                // class kotlin/jvm/functions/Function2
     525: invokedynamic #431,  0            // InvokeDynamic #9:apply:(Lkotlin/jvm/functions/Function2;)Ljava/util/function/BiFunction;
     530: invokevirtual #435                // Method java/util/TreeMap.merge:(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;
     533: pop
     534: goto          364
     537: iinc          10, 1
     540: goto          334
     543: iinc          7, 1
     546: goto          249
     549: aload         5
     551: astore        8
     553: new           #437                // class kotlin/Triple
     556: dup
     557: lconst_0
     558: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     561: lconst_1
     562: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     565: lconst_0
     566: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     569: invokespecial #440                // Method kotlin/Triple."<init>":(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
     572: astore        9
     574: iconst_0
     575: istore        10
     577: aload         8
     579: invokestatic  #444                // Method kotlin/collections/ArraysKt.getLastIndex:([Ljava/lang/Object;)I
     582: istore        11
     584: aload         9
     586: astore        12
     588: iload         11
     590: iflt          720
     593: aload         8
     595: iload         11
     597: iinc          11, -1
     600: aaload
     601: aload         12
     603: astore        13
     605: astore        14
     607: iconst_0
     608: istore        15
     610: aload         13
     612: invokevirtual #447                // Method kotlin/Triple.component1:()Ljava/lang/Object;
     615: checkcast     #182                // class java/lang/Number
     618: invokevirtual #185                // Method java/lang/Number.longValue:()J
     621: lstore        16
     623: aload         13
     625: invokevirtual #450                // Method kotlin/Triple.component2:()Ljava/lang/Object;
     628: checkcast     #182                // class java/lang/Number
     631: invokevirtual #185                // Method java/lang/Number.longValue:()J
     634: lstore        18
     636: aload         13
     638: invokevirtual #453                // Method kotlin/Triple.component3:()Ljava/lang/Object;
     641: checkcast     #182                // class java/lang/Number
     644: invokevirtual #185                // Method java/lang/Number.longValue:()J
     647: lstore        20
     649: aload         14
     651: lload         20
     653: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     656: invokevirtual #455                // Method java/util/TreeMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
     659: dup
     660: invokestatic  #459                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     663: checkcast     #307                // class day24/SolutionKt$main$solve$State
     666: astore        22
     668: aload         22
     670: invokevirtual #461                // Method day24/SolutionKt$main$solve$State.component1:()I
     673: istore        23
     675: aload         22
     677: invokevirtual #463                // Method day24/SolutionKt$main$solve$State.component2:()J
     680: lstore        24
     682: new           #437                // class kotlin/Triple
     685: dup
     686: lload         16
     688: iload         23
     690: i2l
     691: lload         18
     693: lmul
     694: ladd
     695: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     698: lload         18
     700: bipush        10
     702: i2l
     703: lmul
     704: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     707: lload         24
     709: invokestatic  #294                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     712: invokespecial #440                // Method kotlin/Triple."<init>":(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
     715: astore        12
     717: goto          588
     720: aload         12
     722: invokevirtual #447                // Method kotlin/Triple.component1:()Ljava/lang/Object;
     725: checkcast     #182                // class java/lang/Number
     728: invokevirtual #185                // Method java/lang/Number.longValue:()J
     731: lstore        8
     733: lload         8
     735: lreturn

  private static final long main$part1(kotlin.jvm.internal.Ref$IntRef, long[], java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokestatic  #511                // InterfaceMethod java/util/Comparator.naturalOrder:()Ljava/util/Comparator;
       6: dup
       7: ldc_w         #513                // String naturalOrder(...)
      10: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      13: invokestatic  #515                // Method main$solve:(Lkotlin/jvm/internal/Ref$IntRef;[JLjava/util/List;Ljava/util/Comparator;)J
      16: lreturn

  private static final long main$part2(kotlin.jvm.internal.Ref$IntRef, long[], java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokestatic  #518                // InterfaceMethod java/util/Comparator.reverseOrder:()Ljava/util/Comparator;
       6: dup
       7: ldc_w         #520                // String reverseOrder(...)
      10: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      13: invokestatic  #515                // Method main$solve:(Lkotlin/jvm/internal/Ref$IntRef;[JLjava/util/List;Ljava/util/Comparator;)J
      16: lreturn
}


package day12

import java.nio.file.Files
import java.nio.file.Paths

fun main() {
  fun buildGraph(lines: Input): Map<String, List<String>> = buildMap<String, MutableList<String>> {
    for (line in lines) {
      val (v, w) = line.split("-")
      val vList = getOrPut(v) { mutableListOf() }
      val wList = getOrPut(w) { mutableListOf() }
      vList.add(w)
      wList.add(v)
    }
  }

  fun dfs(vertex: String, graph: Map<String, List<String>>, visited: Set<String>, visitedTwice: Boolean): Int {
    if (vertex == "end") return 1
    var sum = 0
    for (next in graph[vertex]!!) {
      if (next !in visited) {
        val nextVisited = if (next.first().isLowerCase()) visited + next else visited
        sum += dfs(next, graph, nextVisited, visitedTwice)
      } else if (next != "start" && !visitedTwice) {
        sum += dfs(next, graph, visited, true)
      }
    }
    return sum
  }

  fun part1(lines: Input): Int {
    val graph = buildGraph(lines)
    return dfs("start", graph, setOf("start"), true)
  }

  fun part2(lines: Input): Int {
    val graph = buildGraph(lines)
    return dfs("start", graph, setOf("start"), false)
  }

  check(part1(readInput("test-input.txt")) == 226)
  check(part2(readInput("test-input.txt")) == 3509)

  println(part1(readInput("input.txt")))
  println(part2(readInput("input.txt")))
}

private fun readInput(s: String): Input {
  return Files.newBufferedReader(Paths.get("src/day12/$s")).readLines()
}

private typealias Input = List<String>

Compiled from "Solution.kt"
public final class day12.SolutionKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String test-input.txt
       2: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
       5: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
       8: sipush        226
      11: if_icmpne     18
      14: iconst_1
      15: goto          19
      18: iconst_0
      19: ifne          32
      22: new           #18                 // class java/lang/IllegalStateException
      25: dup
      26: ldc           #20                 // String Check failed.
      28: invokespecial #24                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      31: athrow
      32: ldc           #8                  // String test-input.txt
      34: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      37: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)I
      40: sipush        3509
      43: if_icmpne     50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: ifne          64
      54: new           #18                 // class java/lang/IllegalStateException
      57: dup
      58: ldc           #20                 // String Check failed.
      60: invokespecial #24                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      63: athrow
      64: ldc           #29                 // String input.txt
      66: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      69: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
      72: istore_0
      73: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      76: iload_0
      77: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
      80: ldc           #29                 // String input.txt
      82: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      85: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)I
      88: istore_0
      89: getstatic     #35                 // Field java/lang/System.out:Ljava/io/PrintStream;
      92: iload_0
      93: invokevirtual #41                 // Method java/io/PrintStream.println:(I)V
      96: return

  private static final java.util.List<java.lang.String> readInput(java.lang.String);
    Code:
       0: new           #44                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #46                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #48                 // String src/day12/
       9: invokevirtual #52                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: invokevirtual #52                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      16: invokevirtual #56                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      19: iconst_0
      20: anewarray     #58                 // class java/lang/String
      23: invokestatic  #64                 // Method java/nio/file/Paths.get:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      26: invokestatic  #70                 // Method java/nio/file/Files.newBufferedReader:(Ljava/nio/file/Path;)Ljava/io/BufferedReader;
      29: dup
      30: ldc           #72                 // String newBufferedReader(...)
      32: invokestatic  #78                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      35: checkcast     #80                 // class java/io/Reader
      38: invokestatic  #86                 // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      41: areturn

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

  private static final java.util.Map<java.lang.String, java.util.List<java.lang.String>> main$buildGraph(java.util.List<java.lang.String>);
    Code:
       0: invokestatic  #102                // Method kotlin/collections/MapsKt.createMapBuilder:()Ljava/util/Map;
       3: astore_1
       4: aload_1
       5: astore_2
       6: iconst_0
       7: istore_3
       8: aload_0
       9: invokeinterface #108,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      14: astore        4
      16: aload         4
      18: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      23: ifeq          242
      26: aload         4
      28: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #58                 // class java/lang/String
      36: astore        5
      38: aload         5
      40: checkcast     #120                // class java/lang/CharSequence
      43: iconst_1
      44: anewarray     #58                 // class java/lang/String
      47: astore        6
      49: aload         6
      51: iconst_0
      52: ldc           #122                // String -
      54: aastore
      55: aload         6
      57: iconst_0
      58: iconst_0
      59: bipush        6
      61: aconst_null
      62: invokestatic  #128                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      65: astore        7
      67: aload         7
      69: iconst_0
      70: invokeinterface #131,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      75: checkcast     #58                 // class java/lang/String
      78: astore        6
      80: aload         7
      82: iconst_1
      83: invokeinterface #131,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #58                 // class java/lang/String
      91: astore        8
      93: aload_2
      94: astore        9
      96: iconst_0
      97: istore        10
      99: aload         9
     101: aload         6
     103: invokeinterface #136,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     108: astore        11
     110: aload         11
     112: ifnonnull     148
     115: iconst_0
     116: istore        12
     118: new           #138                // class java/util/ArrayList
     121: dup
     122: invokespecial #139                // Method java/util/ArrayList."<init>":()V
     125: checkcast     #104                // class java/util/List
     128: nop
     129: astore        12
     131: aload         9
     133: aload         6
     135: aload         12
     137: invokeinterface #143,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     142: pop
     143: aload         12
     145: goto          150
     148: aload         11
     150: nop
     151: checkcast     #104                // class java/util/List
     154: astore        13
     156: aload_2
     157: astore        10
     159: iconst_0
     160: istore        11
     162: aload         10
     164: aload         8
     166: invokeinterface #136,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     171: astore        12
     173: aload         12
     175: ifnonnull     211
     178: iconst_0
     179: istore        14
     181: new           #138                // class java/util/ArrayList
     184: dup
     185: invokespecial #139                // Method java/util/ArrayList."<init>":()V
     188: checkcast     #104                // class java/util/List
     191: nop
     192: astore        14
     194: aload         10
     196: aload         8
     198: aload         14
     200: invokeinterface #143,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     205: pop
     206: aload         14
     208: goto          213
     211: aload         12
     213: nop
     214: checkcast     #104                // class java/util/List
     217: astore        9
     219: aload         13
     221: aload         8
     223: invokeinterface #147,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     228: pop
     229: aload         9
     231: aload         6
     233: invokeinterface #147,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     238: pop
     239: goto          16
     242: nop
     243: aload_1
     244: invokestatic  #151                // Method kotlin/collections/MapsKt.build:(Ljava/util/Map;)Ljava/util/Map;
     247: areturn

  private static final int main$dfs(java.lang.String, java.util.Map<java.lang.String, ? extends java.util.List<java.lang.String>>, java.util.Set<java.lang.String>, boolean);
    Code:
       0: aload_0
       1: ldc           #174                // String end
       3: invokestatic  #178                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
       6: ifeq          11
       9: iconst_1
      10: ireturn
      11: iconst_0
      12: istore        4
      14: aload_1
      15: aload_0
      16: invokeinterface #136,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      21: dup
      22: invokestatic  #182                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      25: checkcast     #104                // class java/util/List
      28: invokeinterface #108,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      33: astore        5
      35: aload         5
      37: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          141
      45: aload         5
      47: invokeinterface #118,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: checkcast     #58                 // class java/lang/String
      55: astore        6
      57: aload_2
      58: aload         6
      60: invokeinterface #187,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      65: ifne          111
      68: aload         6
      70: checkcast     #120                // class java/lang/CharSequence
      73: invokestatic  #191                // Method kotlin/text/StringsKt.first:(Ljava/lang/CharSequence;)C
      76: invokestatic  #197                // Method java/lang/Character.isLowerCase:(C)Z
      79: ifeq          91
      82: aload_2
      83: aload         6
      85: invokestatic  #203                // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
      88: goto          92
      91: aload_2
      92: astore        7
      94: iload         4
      96: aload         6
      98: aload_1
      99: aload         7
     101: iload_3
     102: invokestatic  #205                // Method main$dfs:(Ljava/lang/String;Ljava/util/Map;Ljava/util/Set;Z)I
     105: iadd
     106: istore        4
     108: goto          35
     111: aload         6
     113: ldc           #207                // String start
     115: invokestatic  #178                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     118: ifne          35
     121: iload_3
     122: ifne          35
     125: iload         4
     127: aload         6
     129: aload_1
     130: aload_2
     131: iconst_1
     132: invokestatic  #205                // Method main$dfs:(Ljava/lang/String;Ljava/util/Map;Ljava/util/Set;Z)I
     135: iadd
     136: istore        4
     138: goto          35
     141: iload         4
     143: ireturn

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #218                // Method main$buildGraph:(Ljava/util/List;)Ljava/util/Map;
       4: astore_1
       5: ldc           #207                // String start
       7: aload_1
       8: ldc           #207                // String start
      10: invokestatic  #222                // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      13: iconst_1
      14: invokestatic  #205                // Method main$dfs:(Ljava/lang/String;Ljava/util/Map;Ljava/util/Set;Z)I
      17: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: invokestatic  #218                // Method main$buildGraph:(Ljava/util/List;)Ljava/util/Map;
       4: astore_1
       5: ldc           #207                // String start
       7: aload_1
       8: ldc           #207                // String start
      10: invokestatic  #222                // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      13: iconst_0
      14: invokestatic  #205                // Method main$dfs:(Ljava/lang/String;Ljava/util/Map;Ljava/util/Set;Z)I
      17: ireturn
}


package day15

import java.nio.file.Files
import java.nio.file.Paths
import java.util.TreeSet
import kotlin.system.measureTimeMillis

fun main() {
  fun part1(input: Input): Int {
    val costs = Array(input.size) {
      IntArray(input[it].size) { Int.MAX_VALUE }
    }
    val priorityQueue = TreeSet(
      Comparator
        .comparingInt<Pair<Int, Int>> { costs[it.first][it.second] }
        .thenComparingInt { it.first }
        .thenComparingInt { it.second }
    )
    costs[0][0] = 0
    priorityQueue.add(0 to 0)
    val dx = arrayOf(-1, 0, 1, 0)
    val dy = arrayOf(0, 1, 0, -1)
    while (priorityQueue.isNotEmpty()) {
      val (x, y) = priorityQueue.pollFirst()!!
      if (x == input.lastIndex && y == input[x].lastIndex) {
        return costs[x][y]
      }
      for (d in 0 until 4) {
        val xx = x + dx[d]
        val yy = y + dy[d]
        if (xx in input.indices && yy in input[xx].indices) {
          val newCost = costs[x][y] + input[xx][yy]
          if (newCost < costs[xx][yy]) {
            priorityQueue.remove(xx to yy)
            costs[xx][yy] = newCost
            priorityQueue.add(xx to yy)
          }
        }
      }
    }
    error("Polundra!")
  }

  fun part2(input: Input): Int {
    val newInput = List(input.size * 5) { xx ->
      val x = xx % input.size
      List(input[x].size * 5) { yy ->
        val y = yy % input[x].size
        val diagonal = xx / input.size + yy / input[x].size
        (input[x][y] - 1 + diagonal) % 9 + 1
      }
    }
    return part1(newInput)
  }

  check(part1(readInput("test-input.txt")) == 40)
  check(part2(readInput("test-input.txt")) == 315)

  val timeSpent = measureTimeMillis {
    println(part1(readInput("input.txt")))
    println(part2(readInput("input.txt")))
  }
  System.err.println("In ${timeSpent}ms")
}

private fun readInput(s: String): Input {
  return Files.newBufferedReader(Paths.get("src/day15/$s")).readLines().map { it.map { it.code - '0'.code } }
}

private typealias Input = List<List<Int>>

Compiled from "Solution.kt"
public final class day15.SolutionKt {
  public static final void main();
    Code:
       0: ldc           #8                  // String test-input.txt
       2: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
       5: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
       8: bipush        40
      10: if_icmpne     17
      13: iconst_1
      14: goto          18
      17: iconst_0
      18: ifne          31
      21: new           #18                 // class java/lang/IllegalStateException
      24: dup
      25: ldc           #20                 // String Check failed.
      27: invokespecial #24                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      30: athrow
      31: ldc           #8                  // String test-input.txt
      33: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      36: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)I
      39: sipush        315
      42: if_icmpne     49
      45: iconst_1
      46: goto          50
      49: iconst_0
      50: ifne          63
      53: new           #18                 // class java/lang/IllegalStateException
      56: dup
      57: ldc           #20                 // String Check failed.
      59: invokespecial #24                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      62: athrow
      63: iconst_0
      64: istore_2
      65: invokestatic  #33                 // Method java/lang/System.currentTimeMillis:()J
      68: lstore_3
      69: iconst_0
      70: istore        5
      72: ldc           #35                 // String input.txt
      74: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      77: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
      80: istore        6
      82: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
      85: iload         6
      87: invokevirtual #45                 // Method java/io/PrintStream.println:(I)V
      90: ldc           #35                 // String input.txt
      92: invokestatic  #12                 // Method readInput:(Ljava/lang/String;)Ljava/util/List;
      95: invokestatic  #27                 // Method main$part2:(Ljava/util/List;)I
      98: istore        6
     100: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: iload         6
     105: invokevirtual #45                 // Method java/io/PrintStream.println:(I)V
     108: nop
     109: nop
     110: invokestatic  #33                 // Method java/lang/System.currentTimeMillis:()J
     113: lload_3
     114: lsub
     115: lstore_0
     116: getstatic     #48                 // Field java/lang/System.err:Ljava/io/PrintStream;
     119: new           #50                 // class java/lang/StringBuilder
     122: dup
     123: invokespecial #52                 // Method java/lang/StringBuilder."<init>":()V
     126: ldc           #54                 // String In
     128: invokevirtual #58                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     131: lload_0
     132: invokevirtual #61                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     135: ldc           #63                 // String ms
     137: invokevirtual #58                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     140: invokevirtual #67                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     143: invokevirtual #69                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
     146: return

  private static final java.util.List<java.util.List<java.lang.Integer>> readInput(java.lang.String);
    Code:
       0: new           #50                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #52                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #78                 // String src/day15/
       9: invokevirtual #58                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: invokevirtual #58                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      16: invokevirtual #67                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      19: iconst_0
      20: anewarray     #80                 // class java/lang/String
      23: invokestatic  #86                 // Method java/nio/file/Paths.get:(Ljava/lang/String;[Ljava/lang/String;)Ljava/nio/file/Path;
      26: invokestatic  #92                 // Method java/nio/file/Files.newBufferedReader:(Ljava/nio/file/Path;)Ljava/io/BufferedReader;
      29: dup
      30: ldc           #94                 // String newBufferedReader(...)
      32: invokestatic  #100                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      35: checkcast     #102                // class java/io/Reader
      38: invokestatic  #108                // Method kotlin/io/TextStreamsKt.readLines:(Ljava/io/Reader;)Ljava/util/List;
      41: checkcast     #110                // class java/lang/Iterable
      44: astore_1
      45: iconst_0
      46: istore_2
      47: aload_1
      48: astore_3
      49: new           #112                // class java/util/ArrayList
      52: dup
      53: aload_1
      54: bipush        10
      56: invokestatic  #118                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      59: invokespecial #120                // Method java/util/ArrayList."<init>":(I)V
      62: checkcast     #122                // class java/util/Collection
      65: astore        4
      67: iconst_0
      68: istore        5
      70: aload_3
      71: invokeinterface #126,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      76: astore        6
      78: aload         6
      80: invokeinterface #132,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      85: ifeq          226
      88: aload         6
      90: invokeinterface #136,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      95: astore        7
      97: aload         4
      99: aload         7
     101: checkcast     #80                 // class java/lang/String
     104: astore        8
     106: astore        20
     108: iconst_0
     109: istore        9
     111: aload         8
     113: checkcast     #138                // class java/lang/CharSequence
     116: astore        10
     118: iconst_0
     119: istore        11
     121: aload         10
     123: astore        12
     125: new           #112                // class java/util/ArrayList
     128: dup
     129: aload         10
     131: invokeinterface #142,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     136: invokespecial #120                // Method java/util/ArrayList."<init>":(I)V
     139: checkcast     #122                // class java/util/Collection
     142: astore        13
     144: iconst_0
     145: istore        14
     147: iconst_0
     148: istore        15
     150: iload         15
     152: aload         12
     154: invokeinterface #142,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     159: if_icmpge     207
     162: aload         12
     164: iload         15
     166: invokeinterface #146,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     171: istore        16
     173: aload         13
     175: iload         16
     177: istore        17
     179: astore        18
     181: iconst_0
     182: istore        19
     184: iload         17
     186: bipush        48
     188: isub
     189: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     192: aload         18
     194: swap
     195: invokeinterface #156,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     200: pop
     201: iinc          15, 1
     204: goto          150
     207: aload         13
     209: checkcast     #158                // class java/util/List
     212: nop
     213: nop
     214: aload         20
     216: swap
     217: invokeinterface #156,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     222: pop
     223: goto          78
     226: aload         4
     228: checkcast     #158                // class java/util/List
     231: nop
     232: areturn

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

  private static final int main$part1$lambda$0(int[][], kotlin.Pair);
    Code:
       0: aload_0
       1: aload_1
       2: invokevirtual #186                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #188                // class java/lang/Number
       8: invokevirtual #191                // Method java/lang/Number.intValue:()I
      11: aaload
      12: aload_1
      13: invokevirtual #194                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      16: checkcast     #188                // class java/lang/Number
      19: invokevirtual #191                // Method java/lang/Number.intValue:()I
      22: iaload
      23: ireturn

  private static final int main$part1$lambda$1(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #205,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #188                // class java/lang/Number
      10: invokevirtual #191                // Method java/lang/Number.intValue:()I
      13: ireturn

  private static final int main$part1$lambda$2(kotlin.Pair);
    Code:
       0: aload_0
       1: invokevirtual #186                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #188                // class java/lang/Number
       7: invokevirtual #191                // Method java/lang/Number.intValue:()I
      10: ireturn

  private static final int main$part1$lambda$3(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #205,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #188                // class java/lang/Number
      10: invokevirtual #191                // Method java/lang/Number.intValue:()I
      13: ireturn

  private static final int main$part1$lambda$4(kotlin.Pair);
    Code:
       0: aload_0
       1: invokevirtual #194                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       4: checkcast     #188                // class java/lang/Number
       7: invokevirtual #191                // Method java/lang/Number.intValue:()I
      10: ireturn

  private static final int main$part1$lambda$5(kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: invokeinterface #205,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #188                // class java/lang/Number
      10: invokevirtual #191                // Method java/lang/Number.intValue:()I
      13: ireturn

  private static final int main$part1(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: iconst_0
       1: istore_2
       2: aload_0
       3: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
       8: istore_3
       9: iload_3
      10: anewarray     #219                // class "[I"
      13: astore        4
      15: iload_2
      16: iload_3
      17: if_icmpge     95
      20: iload_2
      21: istore        5
      23: aload         4
      25: iload         5
      27: iconst_0
      28: istore        6
      30: aload_0
      31: iload         5
      33: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      38: checkcast     #158                // class java/util/List
      41: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
      46: istore        7
      48: iload         7
      50: newarray       int
      52: astore        8
      54: istore        13
      56: astore        12
      58: iload         6
      60: iload         7
      62: if_icmpge     82
      65: iload         6
      67: istore        9
      69: aload         8
      71: iload         9
      73: ldc           #223                // int 2147483647
      75: iastore
      76: iinc          6, 1
      79: goto          58
      82: aload         12
      84: iload         13
      86: aload         8
      88: aastore
      89: iinc          2, 1
      92: goto          15
      95: aload         4
      97: astore_1
      98: new           #225                // class java/util/TreeSet
     101: dup
     102: aload_1
     103: invokedynamic #241,  0            // InvokeDynamic #0:invoke:([[I)Lkotlin/jvm/functions/Function1;
     108: invokedynamic #250,  0            // InvokeDynamic #1:applyAsInt:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/ToIntFunction;
     113: invokestatic  #256                // InterfaceMethod java/util/Comparator.comparingInt:(Ljava/util/function/ToIntFunction;)Ljava/util/Comparator;
     116: invokedynamic #262,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     121: invokedynamic #266,  0            // InvokeDynamic #3:applyAsInt:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/ToIntFunction;
     126: invokeinterface #269,  2          // InterfaceMethod java/util/Comparator.thenComparingInt:(Ljava/util/function/ToIntFunction;)Ljava/util/Comparator;
     131: invokedynamic #273,  0            // InvokeDynamic #4:invoke:()Lkotlin/jvm/functions/Function1;
     136: invokedynamic #277,  0            // InvokeDynamic #5:applyAsInt:(Lkotlin/jvm/functions/Function1;)Ljava/util/function/ToIntFunction;
     141: invokeinterface #269,  2          // InterfaceMethod java/util/Comparator.thenComparingInt:(Ljava/util/function/ToIntFunction;)Ljava/util/Comparator;
     146: invokespecial #280                // Method java/util/TreeSet."<init>":(Ljava/util/Comparator;)V
     149: astore_2
     150: aload_1
     151: iconst_0
     152: aaload
     153: iconst_0
     154: iconst_0
     155: iastore
     156: aload_2
     157: iconst_0
     158: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     161: iconst_0
     162: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     165: invokestatic  #286                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     168: invokevirtual #287                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     171: pop
     172: iconst_4
     173: anewarray     #148                // class java/lang/Integer
     176: astore        4
     178: aload         4
     180: iconst_0
     181: iconst_m1
     182: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     185: aastore
     186: aload         4
     188: iconst_1
     189: iconst_0
     190: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     193: aastore
     194: aload         4
     196: iconst_2
     197: iconst_1
     198: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     201: aastore
     202: aload         4
     204: iconst_3
     205: iconst_0
     206: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     209: aastore
     210: aload         4
     212: astore_3
     213: iconst_4
     214: anewarray     #148                // class java/lang/Integer
     217: astore        5
     219: aload         5
     221: iconst_0
     222: iconst_0
     223: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     226: aastore
     227: aload         5
     229: iconst_1
     230: iconst_1
     231: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     234: aastore
     235: aload         5
     237: iconst_2
     238: iconst_0
     239: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     242: aastore
     243: aload         5
     245: iconst_3
     246: iconst_m1
     247: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     250: aastore
     251: aload         5
     253: astore        4
     255: aload_2
     256: checkcast     #122                // class java/util/Collection
     259: invokeinterface #290,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     264: ifne          271
     267: iconst_1
     268: goto          272
     271: iconst_0
     272: ifeq          552
     275: aload_2
     276: invokevirtual #293                // Method java/util/TreeSet.pollFirst:()Ljava/lang/Object;
     279: dup
     280: invokestatic  #297                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     283: checkcast     #183                // class kotlin/Pair
     286: astore        5
     288: aload         5
     290: invokevirtual #300                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     293: checkcast     #188                // class java/lang/Number
     296: invokevirtual #191                // Method java/lang/Number.intValue:()I
     299: istore        6
     301: aload         5
     303: invokevirtual #303                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     306: checkcast     #188                // class java/lang/Number
     309: invokevirtual #191                // Method java/lang/Number.intValue:()I
     312: istore        7
     314: iload         6
     316: aload_0
     317: invokestatic  #306                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     320: if_icmpne     350
     323: iload         7
     325: aload_0
     326: iload         6
     328: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     333: checkcast     #158                // class java/util/List
     336: invokestatic  #306                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     339: if_icmpne     350
     342: aload_1
     343: iload         6
     345: aaload
     346: iload         7
     348: iaload
     349: ireturn
     350: iconst_0
     351: istore        8
     353: iload         8
     355: iconst_4
     356: if_icmpge     255
     359: iload         6
     361: aload_3
     362: iload         8
     364: aaload
     365: invokevirtual #307                // Method java/lang/Integer.intValue:()I
     368: iadd
     369: istore        9
     371: iload         7
     373: aload         4
     375: iload         8
     377: aaload
     378: invokevirtual #307                // Method java/lang/Integer.intValue:()I
     381: iadd
     382: istore        10
     384: iconst_0
     385: iload         9
     387: if_icmpgt     412
     390: iload         9
     392: aload_0
     393: checkcast     #122                // class java/util/Collection
     396: invokeinterface #308,  1          // InterfaceMethod java/util/Collection.size:()I
     401: if_icmpge     408
     404: iconst_1
     405: goto          413
     408: iconst_0
     409: goto          413
     412: iconst_0
     413: ifeq          546
     416: iconst_0
     417: iload         10
     419: if_icmpgt     451
     422: iload         10
     424: aload_0
     425: iload         9
     427: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     432: checkcast     #122                // class java/util/Collection
     435: invokeinterface #308,  1          // InterfaceMethod java/util/Collection.size:()I
     440: if_icmpge     447
     443: iconst_1
     444: goto          452
     447: iconst_0
     448: goto          452
     451: iconst_0
     452: ifeq          546
     455: aload_1
     456: iload         6
     458: aaload
     459: iload         7
     461: iaload
     462: aload_0
     463: iload         9
     465: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     470: checkcast     #158                // class java/util/List
     473: iload         10
     475: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     480: checkcast     #188                // class java/lang/Number
     483: invokevirtual #191                // Method java/lang/Number.intValue:()I
     486: iadd
     487: istore        11
     489: iload         11
     491: aload_1
     492: iload         9
     494: aaload
     495: iload         10
     497: iaload
     498: if_icmpge     546
     501: aload_2
     502: iload         9
     504: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     507: iload         10
     509: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     512: invokestatic  #286                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     515: invokevirtual #311                // Method java/util/TreeSet.remove:(Ljava/lang/Object;)Z
     518: pop
     519: aload_1
     520: iload         9
     522: aaload
     523: iload         10
     525: iload         11
     527: iastore
     528: aload_2
     529: iload         9
     531: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     534: iload         10
     536: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     539: invokestatic  #286                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     542: invokevirtual #287                // Method java/util/TreeSet.add:(Ljava/lang/Object;)Z
     545: pop
     546: iinc          8, 1
     549: goto          353
     552: new           #18                 // class java/lang/IllegalStateException
     555: dup
     556: ldc_w         #313                // String Polundra!
     559: invokevirtual #314                // Method java/lang/Object.toString:()Ljava/lang/String;
     562: invokespecial #24                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     565: athrow

  private static final int main$part2(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
       6: iconst_5
       7: imul
       8: istore_2
       9: new           #112                // class java/util/ArrayList
      12: dup
      13: iload_2
      14: invokespecial #120                // Method java/util/ArrayList."<init>":(I)V
      17: astore_3
      18: iconst_0
      19: istore        4
      21: iload         4
      23: iload_2
      24: if_icmpge     229
      27: iload         4
      29: istore        5
      31: aload_3
      32: iload         5
      34: istore        6
      36: astore        18
      38: iconst_0
      39: istore        7
      41: iload         6
      43: aload_0
      44: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
      49: irem
      50: istore        8
      52: aload_0
      53: iload         8
      55: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      60: checkcast     #158                // class java/util/List
      63: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
      68: iconst_5
      69: imul
      70: istore        9
      72: new           #112                // class java/util/ArrayList
      75: dup
      76: iload         9
      78: invokespecial #120                // Method java/util/ArrayList."<init>":(I)V
      81: astore        10
      83: iconst_0
      84: istore        11
      86: iload         11
      88: iload         9
      90: if_icmpge     210
      93: iload         11
      95: istore        12
      97: aload         10
      99: iload         12
     101: istore        13
     103: astore        14
     105: iconst_0
     106: istore        15
     108: iload         13
     110: aload_0
     111: iload         8
     113: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     118: checkcast     #158                // class java/util/List
     121: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
     126: irem
     127: istore        16
     129: iload         6
     131: aload_0
     132: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
     137: idiv
     138: iload         13
     140: aload_0
     141: iload         8
     143: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     148: checkcast     #158                // class java/util/List
     151: invokeinterface #217,  1          // InterfaceMethod java/util/List.size:()I
     156: idiv
     157: iadd
     158: istore        17
     160: aload_0
     161: iload         8
     163: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     168: checkcast     #158                // class java/util/List
     171: iload         16
     173: invokeinterface #222,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     178: checkcast     #188                // class java/lang/Number
     181: invokevirtual #191                // Method java/lang/Number.intValue:()I
     184: iconst_1
     185: isub
     186: iload         17
     188: iadd
     189: bipush        9
     191: irem
     192: iconst_1
     193: iadd
     194: invokestatic  #152                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     197: aload         14
     199: swap
     200: invokevirtual #331                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     203: pop
     204: iinc          11, 1
     207: goto          86
     210: aload         10
     212: checkcast     #158                // class java/util/List
     215: nop
     216: aload         18
     218: swap
     219: invokevirtual #331                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     222: pop
     223: iinc          4, 1
     226: goto          21
     229: aload_3
     230: checkcast     #158                // class java/util/List
     233: astore_1
     234: aload_1
     235: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
     238: ireturn
}