package day17

import java.io.File
import java.util.PriorityQueue

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

    println("🎄 Day 17 🎄")

    println()

    println("[Part 1]")
    println("Answer: ${part1(data)}")

    println()

    println("[Part 2]")
    println("Answer: ${part2(data)}")
}

private typealias Graph = List<List<Int>>

private fun parse(path: String): Graph =
    File(path)
        .readLines()
        .map { it.map(Char::digitToInt) }

private data class Vec2(
    val x: Int,
    val y: Int,
)

private typealias Vertex = Vec2

private data class Endpoint(
    val vertex: Vertex,
    val streakDirection: Vec2,
    val streakLength: Int,
)

private data class Path(
    val endpoint: Endpoint,
    val distance: Int,
) : Comparable<Path> {

    override fun compareTo(other: Path): Int =
        distance.compareTo(other.distance)
}

private val Graph.h get() = this.size
private val Graph.w get() = this[0].size

private fun Graph.neighborsOf(vertex: Vertex): List<Vertex> =
    listOfNotNull(
        if (vertex.x - 1 >= 0) Vertex(vertex.x - 1, vertex.y) else null,
        if (vertex.x + 1 <  w) Vertex(vertex.x + 1, vertex.y) else null,
        if (vertex.y - 1 >= 0) Vertex(vertex.x, vertex.y - 1) else null,
        if (vertex.y + 1 <  h) Vertex(vertex.x, vertex.y + 1) else null,
    )

private fun part1(graph: Graph): Int {
    val visited = mutableSetOf<Endpoint>()

    val (xs, xt) = (0 to graph.w - 1)
    val (ys, yt) = (0 to graph.h - 1)

    val source = Vertex(xs, ys)
    val target = Vertex(xt, yt)

    val sourceEndpoint = Endpoint(source, Vec2(0, 0), streakLength = 0)
    val queue = PriorityQueue<Path>()
        .apply { add(Path(sourceEndpoint, distance = 0)) }

    while (queue.isNotEmpty()) {
        val (endpoint, distanceToVertex) = queue.poll()
        if (endpoint in visited) {
            continue
        } else {
            visited += endpoint
        }

        val (vertex, streakDirection, streakLength) = endpoint
        if (vertex == target) {
            return distanceToVertex
        }

        for (neighbor in graph.neighborsOf(vertex)) {
            val dx = neighbor.x - vertex.x
            val dy = neighbor.y - vertex.y

            val nextDirection = Vec2(dx, dy)
            if (nextDirection.x == -streakDirection.x && nextDirection.y == -streakDirection.y) {
                continue
            }

            val nextLength = if (nextDirection == streakDirection) streakLength + 1 else 1
            if (nextLength == 4) {
                continue
            }

            val endpointToNeighbor = Endpoint(neighbor, nextDirection, nextLength)
            val distanceToNeighbor = distanceToVertex + graph[neighbor.y][neighbor.x]
            queue += Path(endpointToNeighbor, distanceToNeighbor)
        }
    }

    error("Could not find any path from source to target.")
}

private fun part2(graph: Graph): Int {
    val visited = mutableSetOf<Endpoint>()

    val (xs, xt) = (0 to graph.w - 1)
    val (ys, yt) = (0 to graph.h - 1)

    val source = Vertex(xs, ys)
    val target = Vertex(xt, yt)

    val sourceEndpoint = Endpoint(source, Vec2(0, 0), streakLength = 0)
    val queue = PriorityQueue<Path>()
        .apply { add(Path(sourceEndpoint, distance = 0)) }

    while (queue.isNotEmpty()) {
        val (endpoint, distanceToVertex) = queue.poll()
        if (endpoint in visited) {
            continue
        } else {
            visited += endpoint
        }

        val (vertex, streakDirection, streakLength) = endpoint
        if (vertex == target && streakLength >= 4) {
            return distanceToVertex
        }

        for (neighbor in graph.neighborsOf(vertex)) {
            val dx = neighbor.x - vertex.x
            val dy = neighbor.y - vertex.y

            val nextDirection = Vec2(dx, dy)
            if (nextDirection.x == -streakDirection.x && nextDirection.y == -streakDirection.y) {
                continue
            }

            val nextLength = if (nextDirection == streakDirection) streakLength + 1 else 1
            if (nextLength > 10) {
                continue
            }
            if (streakDirection != Vec2(0, 0) && nextDirection != streakDirection && streakLength < 4) {
                continue
            }

            val endpointToNeighbor = Endpoint(neighbor, nextDirection, nextLength)
            val distanceToNeighbor = distanceToVertex + graph[neighbor.y][neighbor.x]
            queue += Path(endpointToNeighbor, distanceToNeighbor)
        }
    }

    error("Could not find any path from source to target.")
}

Compiled from "Day17.kt"
public final class day17.Day17Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day17/Day17.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 17 🎄
       8: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      21: ldc           #30                 // String [Part 1]
      23: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: new           #32                 // class java/lang/StringBuilder
      33: dup
      34: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      37: ldc           #37                 // String Answer:
      39: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: aload_0
      43: invokestatic  #45                 // Method part1:(Ljava/util/List;)I
      46: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      49: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      52: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      55: swap
      56: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      59: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      65: ldc           #54                 // String [Part 2]
      67: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: new           #32                 // class java/lang/StringBuilder
      77: dup
      78: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      81: ldc           #37                 // String Answer:
      83: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      86: aload_0
      87: invokestatic  #57                 // Method part2:(Ljava/util/List;)I
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      93: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  private static final java.util.List<java.util.List<java.lang.Integer>> parse(java.lang.String);
    Code:
       0: new           #62                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #65                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #71                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #73                 // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #75                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #84                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #86                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          200
      62: aload         6
      64: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #102                // class java/lang/String
      78: astore        8
      80: astore        20
      82: iconst_0
      83: istore        9
      85: aload         8
      87: checkcast     #104                // class java/lang/CharSequence
      90: astore        10
      92: iconst_0
      93: istore        11
      95: aload         10
      97: astore        12
      99: new           #75                 // class java/util/ArrayList
     102: dup
     103: aload         10
     105: invokeinterface #108,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     110: invokespecial #84                 // Method java/util/ArrayList."<init>":(I)V
     113: checkcast     #86                 // class java/util/Collection
     116: astore        13
     118: iconst_0
     119: istore        14
     121: iconst_0
     122: istore        15
     124: iload         15
     126: aload         12
     128: invokeinterface #108,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     133: if_icmpge     181
     136: aload         12
     138: iload         15
     140: invokeinterface #112,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     145: istore        16
     147: aload         13
     149: iload         16
     151: istore        17
     153: astore        18
     155: iconst_0
     156: istore        19
     158: iload         17
     160: invokestatic  #118                // Method kotlin/text/CharsKt.digitToInt:(C)I
     163: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     166: aload         18
     168: swap
     169: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     174: pop
     175: iinc          15, 1
     178: goto          124
     181: aload         13
     183: checkcast     #130                // class java/util/List
     186: nop
     187: nop
     188: aload         20
     190: swap
     191: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     196: pop
     197: goto          52
     200: aload         4
     202: checkcast     #130                // class java/util/List
     205: nop
     206: areturn

  private static final int getH(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: invokeinterface #153,  1          // InterfaceMethod java/util/List.size:()I
       6: ireturn

  private static final int getW(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: aload_0
       1: iconst_0
       2: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
       7: checkcast     #130                // class java/util/List
      10: invokeinterface #153,  1          // InterfaceMethod java/util/List.size:()I
      15: ireturn

  private static final java.util.List<day17.Vec2> neighborsOf(java.util.List<? extends java.util.List<java.lang.Integer>>, day17.Vec2);
    Code:
       0: iconst_4
       1: anewarray     #165                // class day17/Vec2
       4: astore_2
       5: aload_2
       6: iconst_0
       7: aload_1
       8: invokevirtual #168                // Method day17/Vec2.getX:()I
      11: iconst_1
      12: isub
      13: iflt          36
      16: new           #165                // class day17/Vec2
      19: dup
      20: aload_1
      21: invokevirtual #168                // Method day17/Vec2.getX:()I
      24: iconst_1
      25: isub
      26: aload_1
      27: invokevirtual #171                // Method day17/Vec2.getY:()I
      30: invokespecial #174                // Method day17/Vec2."<init>":(II)V
      33: goto          37
      36: aconst_null
      37: aastore
      38: aload_2
      39: iconst_1
      40: aload_1
      41: invokevirtual #168                // Method day17/Vec2.getX:()I
      44: iconst_1
      45: iadd
      46: aload_0
      47: invokestatic  #176                // Method getW:(Ljava/util/List;)I
      50: if_icmpge     73
      53: new           #165                // class day17/Vec2
      56: dup
      57: aload_1
      58: invokevirtual #168                // Method day17/Vec2.getX:()I
      61: iconst_1
      62: iadd
      63: aload_1
      64: invokevirtual #171                // Method day17/Vec2.getY:()I
      67: invokespecial #174                // Method day17/Vec2."<init>":(II)V
      70: goto          74
      73: aconst_null
      74: aastore
      75: aload_2
      76: iconst_2
      77: aload_1
      78: invokevirtual #171                // Method day17/Vec2.getY:()I
      81: iconst_1
      82: isub
      83: iflt          106
      86: new           #165                // class day17/Vec2
      89: dup
      90: aload_1
      91: invokevirtual #168                // Method day17/Vec2.getX:()I
      94: aload_1
      95: invokevirtual #171                // Method day17/Vec2.getY:()I
      98: iconst_1
      99: isub
     100: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     103: goto          107
     106: aconst_null
     107: aastore
     108: aload_2
     109: iconst_3
     110: aload_1
     111: invokevirtual #171                // Method day17/Vec2.getY:()I
     114: iconst_1
     115: iadd
     116: aload_0
     117: invokestatic  #178                // Method getH:(Ljava/util/List;)I
     120: if_icmpge     143
     123: new           #165                // class day17/Vec2
     126: dup
     127: aload_1
     128: invokevirtual #168                // Method day17/Vec2.getX:()I
     131: aload_1
     132: invokevirtual #171                // Method day17/Vec2.getY:()I
     135: iconst_1
     136: iadd
     137: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     140: goto          144
     143: aconst_null
     144: aastore
     145: aload_2
     146: invokestatic  #182                // Method kotlin/collections/CollectionsKt.listOfNotNull:([Ljava/lang/Object;)Ljava/util/List;
     149: areturn

  private static final int part1(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: new           #189                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #190                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #192                // class java/util/Set
      10: astore_1
      11: iconst_0
      12: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: aload_0
      16: invokestatic  #176                // Method getW:(Ljava/util/List;)I
      19: iconst_1
      20: isub
      21: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: invokestatic  #198                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      27: astore_2
      28: aload_2
      29: invokevirtual #203                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      32: checkcast     #205                // class java/lang/Number
      35: invokevirtual #208                // Method java/lang/Number.intValue:()I
      38: istore_3
      39: aload_2
      40: invokevirtual #211                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      43: checkcast     #205                // class java/lang/Number
      46: invokevirtual #208                // Method java/lang/Number.intValue:()I
      49: istore        4
      51: iconst_0
      52: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: aload_0
      56: invokestatic  #178                // Method getH:(Ljava/util/List;)I
      59: iconst_1
      60: isub
      61: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      64: invokestatic  #198                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      67: astore        5
      69: aload         5
      71: invokevirtual #203                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      74: checkcast     #205                // class java/lang/Number
      77: invokevirtual #208                // Method java/lang/Number.intValue:()I
      80: istore        6
      82: aload         5
      84: invokevirtual #211                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      87: checkcast     #205                // class java/lang/Number
      90: invokevirtual #208                // Method java/lang/Number.intValue:()I
      93: istore        7
      95: new           #165                // class day17/Vec2
      98: dup
      99: iload_3
     100: iload         6
     102: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     105: astore        8
     107: new           #165                // class day17/Vec2
     110: dup
     111: iload         4
     113: iload         7
     115: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     118: astore        9
     120: new           #213                // class day17/Endpoint
     123: dup
     124: aload         8
     126: new           #165                // class day17/Vec2
     129: dup
     130: iconst_0
     131: iconst_0
     132: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     135: iconst_0
     136: invokespecial #216                // Method day17/Endpoint."<init>":(Lday17/Vec2;Lday17/Vec2;I)V
     139: astore        10
     141: new           #218                // class java/util/PriorityQueue
     144: dup
     145: invokespecial #219                // Method java/util/PriorityQueue."<init>":()V
     148: astore        12
     150: aload         12
     152: astore        13
     154: iconst_0
     155: istore        14
     157: aload         13
     159: new           #221                // class day17/Path
     162: dup
     163: aload         10
     165: iconst_0
     166: invokespecial #224                // Method day17/Path."<init>":(Lday17/Endpoint;I)V
     169: invokevirtual #225                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     172: pop
     173: aload         12
     175: astore        11
     177: aload         11
     179: checkcast     #86                 // class java/util/Collection
     182: invokeinterface #228,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     187: ifne          194
     190: iconst_1
     191: goto          195
     194: iconst_0
     195: ifeq          491
     198: aload         11
     200: invokevirtual #231                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     203: checkcast     #221                // class day17/Path
     206: astore        12
     208: aload         12
     210: invokevirtual #234                // Method day17/Path.component1:()Lday17/Endpoint;
     213: astore        13
     215: aload         12
     217: invokevirtual #236                // Method day17/Path.component2:()I
     220: istore        14
     222: aload_1
     223: aload         13
     225: invokeinterface #239,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     230: ifeq          236
     233: goto          177
     236: aload_1
     237: checkcast     #86                 // class java/util/Collection
     240: aload         13
     242: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     247: pop
     248: aload         13
     250: invokevirtual #242                // Method day17/Endpoint.component1:()Lday17/Vec2;
     253: astore        15
     255: aload         13
     257: invokevirtual #244                // Method day17/Endpoint.component2:()Lday17/Vec2;
     260: astore        16
     262: aload         13
     264: invokevirtual #247                // Method day17/Endpoint.component3:()I
     267: istore        17
     269: aload         15
     271: aload         9
     273: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     276: ifeq          282
     279: iload         14
     281: ireturn
     282: aload_0
     283: aload         15
     285: invokestatic  #255                // Method neighborsOf:(Ljava/util/List;Lday17/Vec2;)Ljava/util/List;
     288: invokeinterface #256,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     293: astore        18
     295: aload         18
     297: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     302: ifeq          177
     305: aload         18
     307: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     312: checkcast     #165                // class day17/Vec2
     315: astore        19
     317: aload         19
     319: invokevirtual #168                // Method day17/Vec2.getX:()I
     322: aload         15
     324: invokevirtual #168                // Method day17/Vec2.getX:()I
     327: isub
     328: istore        20
     330: aload         19
     332: invokevirtual #171                // Method day17/Vec2.getY:()I
     335: aload         15
     337: invokevirtual #171                // Method day17/Vec2.getY:()I
     340: isub
     341: istore        21
     343: new           #165                // class day17/Vec2
     346: dup
     347: iload         20
     349: iload         21
     351: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     354: astore        22
     356: aload         22
     358: invokevirtual #168                // Method day17/Vec2.getX:()I
     361: aload         16
     363: invokevirtual #168                // Method day17/Vec2.getX:()I
     366: ineg
     367: if_icmpne     387
     370: aload         22
     372: invokevirtual #171                // Method day17/Vec2.getY:()I
     375: aload         16
     377: invokevirtual #171                // Method day17/Vec2.getY:()I
     380: ineg
     381: if_icmpne     387
     384: goto          295
     387: aload         22
     389: aload         16
     391: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     394: ifeq          404
     397: iload         17
     399: iconst_1
     400: iadd
     401: goto          405
     404: iconst_1
     405: istore        23
     407: iload         23
     409: iconst_4
     410: if_icmpne     416
     413: goto          295
     416: new           #213                // class day17/Endpoint
     419: dup
     420: aload         19
     422: aload         22
     424: iload         23
     426: invokespecial #216                // Method day17/Endpoint."<init>":(Lday17/Vec2;Lday17/Vec2;I)V
     429: astore        24
     431: iload         14
     433: aload_0
     434: aload         19
     436: invokevirtual #171                // Method day17/Vec2.getY:()I
     439: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     444: checkcast     #130                // class java/util/List
     447: aload         19
     449: invokevirtual #168                // Method day17/Vec2.getX:()I
     452: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     457: checkcast     #205                // class java/lang/Number
     460: invokevirtual #208                // Method java/lang/Number.intValue:()I
     463: iadd
     464: istore        25
     466: aload         11
     468: checkcast     #86                 // class java/util/Collection
     471: new           #221                // class day17/Path
     474: dup
     475: aload         24
     477: iload         25
     479: invokespecial #224                // Method day17/Path."<init>":(Lday17/Endpoint;I)V
     482: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     487: pop
     488: goto          295
     491: new           #258                // class java/lang/IllegalStateException
     494: dup
     495: ldc_w         #260                // String Could not find any path from source to target.
     498: invokevirtual #261                // Method java/lang/Object.toString:()Ljava/lang/String;
     501: invokespecial #262                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     504: athrow

  private static final int part2(java.util.List<? extends java.util.List<java.lang.Integer>>);
    Code:
       0: new           #189                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #190                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #192                // class java/util/Set
      10: astore_1
      11: iconst_0
      12: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: aload_0
      16: invokestatic  #176                // Method getW:(Ljava/util/List;)I
      19: iconst_1
      20: isub
      21: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      24: invokestatic  #198                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      27: astore_2
      28: aload_2
      29: invokevirtual #203                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      32: checkcast     #205                // class java/lang/Number
      35: invokevirtual #208                // Method java/lang/Number.intValue:()I
      38: istore_3
      39: aload_2
      40: invokevirtual #211                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      43: checkcast     #205                // class java/lang/Number
      46: invokevirtual #208                // Method java/lang/Number.intValue:()I
      49: istore        4
      51: iconst_0
      52: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: aload_0
      56: invokestatic  #178                // Method getH:(Ljava/util/List;)I
      59: iconst_1
      60: isub
      61: invokestatic  #124                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      64: invokestatic  #198                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      67: astore        5
      69: aload         5
      71: invokevirtual #203                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      74: checkcast     #205                // class java/lang/Number
      77: invokevirtual #208                // Method java/lang/Number.intValue:()I
      80: istore        6
      82: aload         5
      84: invokevirtual #211                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      87: checkcast     #205                // class java/lang/Number
      90: invokevirtual #208                // Method java/lang/Number.intValue:()I
      93: istore        7
      95: new           #165                // class day17/Vec2
      98: dup
      99: iload_3
     100: iload         6
     102: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     105: astore        8
     107: new           #165                // class day17/Vec2
     110: dup
     111: iload         4
     113: iload         7
     115: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     118: astore        9
     120: new           #213                // class day17/Endpoint
     123: dup
     124: aload         8
     126: new           #165                // class day17/Vec2
     129: dup
     130: iconst_0
     131: iconst_0
     132: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     135: iconst_0
     136: invokespecial #216                // Method day17/Endpoint."<init>":(Lday17/Vec2;Lday17/Vec2;I)V
     139: astore        10
     141: new           #218                // class java/util/PriorityQueue
     144: dup
     145: invokespecial #219                // Method java/util/PriorityQueue."<init>":()V
     148: astore        12
     150: aload         12
     152: astore        13
     154: iconst_0
     155: istore        14
     157: aload         13
     159: new           #221                // class day17/Path
     162: dup
     163: aload         10
     165: iconst_0
     166: invokespecial #224                // Method day17/Path."<init>":(Lday17/Endpoint;I)V
     169: invokevirtual #225                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
     172: pop
     173: aload         12
     175: astore        11
     177: aload         11
     179: checkcast     #86                 // class java/util/Collection
     182: invokeinterface #228,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     187: ifne          194
     190: iconst_1
     191: goto          195
     194: iconst_0
     195: ifeq          534
     198: aload         11
     200: invokevirtual #231                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     203: checkcast     #221                // class day17/Path
     206: astore        12
     208: aload         12
     210: invokevirtual #234                // Method day17/Path.component1:()Lday17/Endpoint;
     213: astore        13
     215: aload         12
     217: invokevirtual #236                // Method day17/Path.component2:()I
     220: istore        14
     222: aload_1
     223: aload         13
     225: invokeinterface #239,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     230: ifeq          236
     233: goto          177
     236: aload_1
     237: checkcast     #86                 // class java/util/Collection
     240: aload         13
     242: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     247: pop
     248: aload         13
     250: invokevirtual #242                // Method day17/Endpoint.component1:()Lday17/Vec2;
     253: astore        15
     255: aload         13
     257: invokevirtual #244                // Method day17/Endpoint.component2:()Lday17/Vec2;
     260: astore        16
     262: aload         13
     264: invokevirtual #247                // Method day17/Endpoint.component3:()I
     267: istore        17
     269: aload         15
     271: aload         9
     273: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     276: ifeq          288
     279: iload         17
     281: iconst_4
     282: if_icmplt     288
     285: iload         14
     287: ireturn
     288: aload_0
     289: aload         15
     291: invokestatic  #255                // Method neighborsOf:(Ljava/util/List;Lday17/Vec2;)Ljava/util/List;
     294: invokeinterface #256,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     299: astore        18
     301: aload         18
     303: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     308: ifeq          177
     311: aload         18
     313: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     318: checkcast     #165                // class day17/Vec2
     321: astore        19
     323: aload         19
     325: invokevirtual #168                // Method day17/Vec2.getX:()I
     328: aload         15
     330: invokevirtual #168                // Method day17/Vec2.getX:()I
     333: isub
     334: istore        20
     336: aload         19
     338: invokevirtual #171                // Method day17/Vec2.getY:()I
     341: aload         15
     343: invokevirtual #171                // Method day17/Vec2.getY:()I
     346: isub
     347: istore        21
     349: new           #165                // class day17/Vec2
     352: dup
     353: iload         20
     355: iload         21
     357: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     360: astore        22
     362: aload         22
     364: invokevirtual #168                // Method day17/Vec2.getX:()I
     367: aload         16
     369: invokevirtual #168                // Method day17/Vec2.getX:()I
     372: ineg
     373: if_icmpne     393
     376: aload         22
     378: invokevirtual #171                // Method day17/Vec2.getY:()I
     381: aload         16
     383: invokevirtual #171                // Method day17/Vec2.getY:()I
     386: ineg
     387: if_icmpne     393
     390: goto          301
     393: aload         22
     395: aload         16
     397: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     400: ifeq          410
     403: iload         17
     405: iconst_1
     406: iadd
     407: goto          411
     410: iconst_1
     411: istore        23
     413: iload         23
     415: bipush        10
     417: if_icmple     423
     420: goto          301
     423: aload         16
     425: new           #165                // class day17/Vec2
     428: dup
     429: iconst_0
     430: iconst_0
     431: invokespecial #174                // Method day17/Vec2."<init>":(II)V
     434: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     437: ifne          459
     440: aload         22
     442: aload         16
     444: invokestatic  #253                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     447: ifne          459
     450: iload         17
     452: iconst_4
     453: if_icmpge     459
     456: goto          301
     459: new           #213                // class day17/Endpoint
     462: dup
     463: aload         19
     465: aload         22
     467: iload         23
     469: invokespecial #216                // Method day17/Endpoint."<init>":(Lday17/Vec2;Lday17/Vec2;I)V
     472: astore        24
     474: iload         14
     476: aload_0
     477: aload         19
     479: invokevirtual #171                // Method day17/Vec2.getY:()I
     482: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     487: checkcast     #130                // class java/util/List
     490: aload         19
     492: invokevirtual #168                // Method day17/Vec2.getX:()I
     495: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     500: checkcast     #205                // class java/lang/Number
     503: invokevirtual #208                // Method java/lang/Number.intValue:()I
     506: iadd
     507: istore        25
     509: aload         11
     511: checkcast     #86                 // class java/util/Collection
     514: new           #221                // class day17/Path
     517: dup
     518: aload         24
     520: iload         25
     522: invokespecial #224                // Method day17/Path."<init>":(Lday17/Endpoint;I)V
     525: invokeinterface #128,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     530: pop
     531: goto          301
     534: new           #258                // class java/lang/IllegalStateException
     537: dup
     538: ldc_w         #260                // String Could not find any path from source to target.
     541: invokevirtual #261                // Method java/lang/Object.toString:()Ljava/lang/String;
     544: invokespecial #262                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     547: athrow

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


package day21

import java.io.File

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

    println("🎄 Day 21 🎄")

    println()

    println("[Part 1]")
    println("Answer: ${part1(data)}")

    println()

    println("[Part 2]")
    println("Answer: ${part2(data)}")
}

private fun parse(path: String): List<List<Char>> =
    File(path)
        .readLines()
        .map(String::toList)

private fun solve(data: List<List<Char>>, start: Pair<Int, Int>, n: Int): Long {
    var plots = setOf(start)
    repeat(n) {
        val next = mutableSetOf<Pair<Int, Int>>()
        for ((px, py) in plots) {
            for ((dx, dy) in listOf((-1 to 0), (1 to 0), (0 to -1), (0 to 1))) {
                val nx = px + dx
                val ny = py + dy
                if (nx in data.indices && ny in data.indices) {
                    if (data[ny][nx] != '#') {
                        next += nx to ny
                    }
                }
            }
        }
        plots = next
    }

    return plots.size.toLong()
}

private fun part1(data: List<List<Char>>): Long {
    for ((y, row) in data.withIndex()) {
        for ((x, col) in row.withIndex()) {
            if (col == 'S') {
                return solve(data, Pair(x, y), 64)
            }
        }
    }

    error("Starting point not found.")
}

private fun part2(data: List<List<Char>>): Long {
    val size = data.size
    val steps = 26_501_365

    val sx = size / 2
    val sy = size / 2

    val n = (steps / size - 1).toLong()

    val evenGrids = n * n
    val evenCount = evenGrids * solve(data, start = Pair(sx, sy), n = 2 * size + 1)

    val oddGrids = (n + 1) * (n + 1)
    val oddCount =  oddGrids * solve(data, start = Pair(sx, sy), n = 2 * size)

    val corners =
        solve(data, start = Pair(sx, size - 1), n = size - 1) +  // Top
        solve(data, start = Pair(size - 1, sy), n = size - 1) +  // Left
        solve(data, start = Pair(sx, 0), n = size - 1) +         // Bottom
        solve(data, start = Pair(0, sy), n = size - 1)           // Right

    val smallSections =
        solve(data, start = Pair(size - 1, size - 1), n = size / 2 - 1) + // Top-left
        solve(data, start = Pair(size - 1, 0), n = size / 2 - 1) +        // Bottom-left
        solve(data, start = Pair(0, 0), n = size / 2 - 1) +               // Bottom-right
        solve(data, start = Pair(0, size - 1), n = size / 2 - 1)          // Top-right

    val largeSections =
        solve(data, start = Pair(size - 1, size - 1), n = size * 3 / 2 - 1) + // Top-left
        solve(data, start = Pair(size - 1, 0), n = size * 3 / 2 - 1) +        // Bottom-left
        solve(data, start = Pair(0, 0), n = size * 3 / 2 - 1) +               // Bottom-right
        solve(data, start = Pair(0, size - 1), n = size * 3 / 2 - 1)          // Top-right

    return evenCount + oddCount + corners + (n + 1) * smallSections + n * largeSections
}

Compiled from "Day21.kt"
public final class day21.Day21Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day21/Day21.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 21 🎄
       8: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      18: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      21: ldc           #30                 // String [Part 1]
      23: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: swap
      27: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      30: new           #32                 // class java/lang/StringBuilder
      33: dup
      34: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      37: ldc           #37                 // String Answer:
      39: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      42: aload_0
      43: invokestatic  #45                 // Method part1:(Ljava/util/List;)J
      46: invokevirtual #48                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      49: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      52: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      55: swap
      56: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      59: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: invokevirtual #28                 // Method java/io/PrintStream.println:()V
      65: ldc           #54                 // String [Part 2]
      67: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      70: swap
      71: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      74: new           #32                 // class java/lang/StringBuilder
      77: dup
      78: invokespecial #35                 // Method java/lang/StringBuilder."<init>":()V
      81: ldc           #37                 // String Answer:
      83: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      86: aload_0
      87: invokestatic  #57                 // Method part2:(Ljava/util/List;)J
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      93: invokevirtual #52                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      96: getstatic     #20                 // Field java/lang/System.out:Ljava/io/PrintStream;
      99: swap
     100: invokevirtual #26                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     103: return

  private static final java.util.List<java.util.List<java.lang.Character>> parse(java.lang.String);
    Code:
       0: new           #62                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #65                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #71                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #73                 // class java/lang/Iterable
      17: astore_1
      18: nop
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #75                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #84                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #86                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: aload_3
      45: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      50: astore        6
      52: aload         6
      54: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifeq          105
      62: aload         6
      64: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      69: astore        7
      71: aload         4
      73: aload         7
      75: checkcast     #102                // class java/lang/String
      78: astore        8
      80: astore        10
      82: iconst_0
      83: istore        9
      85: aload         8
      87: checkcast     #104                // class java/lang/CharSequence
      90: invokestatic  #110                // Method kotlin/text/StringsKt.toList:(Ljava/lang/CharSequence;)Ljava/util/List;
      93: aload         10
      95: swap
      96: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     101: pop
     102: goto          52
     105: aload         4
     107: checkcast     #116                // class java/util/List
     110: nop
     111: areturn

  private static final long solve(java.util.List<? extends java.util.List<java.lang.Character>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>, int);
    Code:
       0: aconst_null
       1: astore_3
       2: aload_1
       3: invokestatic  #139                // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
       6: astore_3
       7: iconst_0
       8: istore        4
      10: iload         4
      12: iload_2
      13: if_icmpge     361
      16: iload         4
      18: istore        5
      20: iconst_0
      21: istore        6
      23: new           #141                // class java/util/LinkedHashSet
      26: dup
      27: invokespecial #142                // Method java/util/LinkedHashSet."<init>":()V
      30: checkcast     #144                // class java/util/Set
      33: astore        7
      35: aload_3
      36: invokeinterface #145,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      41: astore        8
      43: aload         8
      45: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          351
      53: aload         8
      55: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: checkcast     #147                // class kotlin/Pair
      63: astore        9
      65: aload         9
      67: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      70: checkcast     #152                // class java/lang/Number
      73: invokevirtual #156                // Method java/lang/Number.intValue:()I
      76: istore        10
      78: aload         9
      80: invokevirtual #159                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      83: checkcast     #152                // class java/lang/Number
      86: invokevirtual #156                // Method java/lang/Number.intValue:()I
      89: istore        11
      91: iconst_4
      92: anewarray     #147                // class kotlin/Pair
      95: astore        12
      97: aload         12
      99: iconst_0
     100: iconst_m1
     101: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: iconst_0
     105: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload         12
     114: iconst_1
     115: iconst_1
     116: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     119: iconst_0
     120: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     126: aastore
     127: aload         12
     129: iconst_2
     130: iconst_0
     131: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     134: iconst_m1
     135: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     141: aastore
     142: aload         12
     144: iconst_3
     145: iconst_0
     146: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     149: iconst_1
     150: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     153: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     156: aastore
     157: aload         12
     159: invokestatic  #175                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     162: invokeinterface #176,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     167: astore        13
     169: aload         13
     171: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     176: ifeq          43
     179: aload         13
     181: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     186: checkcast     #147                // class kotlin/Pair
     189: astore        12
     191: aload         12
     193: invokevirtual #150                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     196: checkcast     #152                // class java/lang/Number
     199: invokevirtual #156                // Method java/lang/Number.intValue:()I
     202: istore        14
     204: aload         12
     206: invokevirtual #159                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     209: checkcast     #152                // class java/lang/Number
     212: invokevirtual #156                // Method java/lang/Number.intValue:()I
     215: istore        15
     217: iload         10
     219: iload         14
     221: iadd
     222: istore        16
     224: iload         11
     226: iload         15
     228: iadd
     229: istore        17
     231: iconst_0
     232: iload         16
     234: if_icmpgt     259
     237: iload         16
     239: aload_0
     240: checkcast     #86                 // class java/util/Collection
     243: invokeinterface #179,  1          // InterfaceMethod java/util/Collection.size:()I
     248: if_icmpge     255
     251: iconst_1
     252: goto          260
     255: iconst_0
     256: goto          260
     259: iconst_0
     260: ifeq          169
     263: iconst_0
     264: iload         17
     266: if_icmpgt     291
     269: iload         17
     271: aload_0
     272: checkcast     #86                 // class java/util/Collection
     275: invokeinterface #179,  1          // InterfaceMethod java/util/Collection.size:()I
     280: if_icmpge     287
     283: iconst_1
     284: goto          292
     287: iconst_0
     288: goto          292
     291: iconst_0
     292: ifeq          169
     295: aload_0
     296: iload         17
     298: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     303: checkcast     #116                // class java/util/List
     306: iload         16
     308: invokeinterface #183,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     313: checkcast     #185                // class java/lang/Character
     316: invokevirtual #189                // Method java/lang/Character.charValue:()C
     319: bipush        35
     321: if_icmpeq     169
     324: aload         7
     326: checkcast     #86                 // class java/util/Collection
     329: iload         16
     331: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     334: iload         17
     336: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     339: invokestatic  #171                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     342: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     347: pop
     348: goto          169
     351: aload         7
     353: astore_3
     354: nop
     355: iinc          4, 1
     358: goto          10
     361: aload_3
     362: invokeinterface #190,  1          // InterfaceMethod java/util/Set.size:()I
     367: i2l
     368: lreturn

  private static final long part1(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: checkcast     #73                 // class java/lang/Iterable
       4: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
       9: astore_1
      10: iconst_0
      11: istore_2
      12: aload_1
      13: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      18: ifeq          118
      21: iload_2
      22: istore_3
      23: iload_2
      24: iconst_1
      25: iadd
      26: istore_2
      27: aload_1
      28: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #116                // class java/util/List
      36: astore        4
      38: aload         4
      40: checkcast     #73                 // class java/lang/Iterable
      43: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        5
      50: iconst_0
      51: istore        6
      53: aload         5
      55: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      60: ifeq          12
      63: iload         6
      65: istore        7
      67: iload         6
      69: iconst_1
      70: iadd
      71: istore        6
      73: aload         5
      75: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      80: checkcast     #185                // class java/lang/Character
      83: invokevirtual #189                // Method java/lang/Character.charValue:()C
      86: istore        8
      88: iload         8
      90: bipush        83
      92: if_icmpne     53
      95: aload_0
      96: new           #147                // class kotlin/Pair
      99: dup
     100: iload         7
     102: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: iload_3
     106: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     109: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     112: bipush        64
     114: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     117: lreturn
     118: new           #211                // class java/lang/IllegalStateException
     121: dup
     122: ldc           #213                // String Starting point not found.
     124: invokevirtual #214                // Method java/lang/Object.toString:()Ljava/lang/String;
     127: invokespecial #215                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     130: athrow

  private static final long part2(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: invokeinterface #221,  1          // InterfaceMethod java/util/List.size:()I
       6: istore_1
       7: ldc           #222                // int 26501365
       9: istore_2
      10: iload_1
      11: iconst_2
      12: idiv
      13: istore_3
      14: iload_1
      15: iconst_2
      16: idiv
      17: istore        4
      19: iload_2
      20: iload_1
      21: idiv
      22: iconst_1
      23: isub
      24: i2l
      25: lstore        5
      27: lload         5
      29: lload         5
      31: lmul
      32: lstore        7
      34: lload         7
      36: aload_0
      37: new           #147                // class kotlin/Pair
      40: dup
      41: iload_3
      42: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      45: iload         4
      47: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      50: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      53: iconst_2
      54: iload_1
      55: imul
      56: iconst_1
      57: iadd
      58: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
      61: lmul
      62: lstore        9
      64: lload         5
      66: lconst_1
      67: ladd
      68: lload         5
      70: lconst_1
      71: ladd
      72: lmul
      73: lstore        11
      75: lload         11
      77: aload_0
      78: new           #147                // class kotlin/Pair
      81: dup
      82: iload_3
      83: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: iload         4
      88: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      91: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      94: iconst_2
      95: iload_1
      96: imul
      97: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     100: lmul
     101: lstore        13
     103: aload_0
     104: new           #147                // class kotlin/Pair
     107: dup
     108: iload_3
     109: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     112: iload_1
     113: iconst_1
     114: isub
     115: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     118: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     121: iload_1
     122: iconst_1
     123: isub
     124: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     127: aload_0
     128: new           #147                // class kotlin/Pair
     131: dup
     132: iload_1
     133: iconst_1
     134: isub
     135: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: iload         4
     140: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     146: iload_1
     147: iconst_1
     148: isub
     149: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     152: ladd
     153: aload_0
     154: new           #147                // class kotlin/Pair
     157: dup
     158: iload_3
     159: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     162: iconst_0
     163: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     166: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     169: iload_1
     170: iconst_1
     171: isub
     172: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     175: ladd
     176: aload_0
     177: new           #147                // class kotlin/Pair
     180: dup
     181: iconst_0
     182: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     185: iload         4
     187: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     190: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     193: iload_1
     194: iconst_1
     195: isub
     196: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     199: ladd
     200: lstore        15
     202: aload_0
     203: new           #147                // class kotlin/Pair
     206: dup
     207: iload_1
     208: iconst_1
     209: isub
     210: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     213: iload_1
     214: iconst_1
     215: isub
     216: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     219: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     222: iload_1
     223: iconst_2
     224: idiv
     225: iconst_1
     226: isub
     227: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     230: aload_0
     231: new           #147                // class kotlin/Pair
     234: dup
     235: iload_1
     236: iconst_1
     237: isub
     238: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     241: iconst_0
     242: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     245: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     248: iload_1
     249: iconst_2
     250: idiv
     251: iconst_1
     252: isub
     253: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     256: ladd
     257: aload_0
     258: new           #147                // class kotlin/Pair
     261: dup
     262: iconst_0
     263: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     266: iconst_0
     267: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     270: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     273: iload_1
     274: iconst_2
     275: idiv
     276: iconst_1
     277: isub
     278: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     281: ladd
     282: aload_0
     283: new           #147                // class kotlin/Pair
     286: dup
     287: iconst_0
     288: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     291: iload_1
     292: iconst_1
     293: isub
     294: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     297: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     300: iload_1
     301: iconst_2
     302: idiv
     303: iconst_1
     304: isub
     305: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     308: ladd
     309: lstore        17
     311: aload_0
     312: new           #147                // class kotlin/Pair
     315: dup
     316: iload_1
     317: iconst_1
     318: isub
     319: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     322: iload_1
     323: iconst_1
     324: isub
     325: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     328: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     331: iload_1
     332: iconst_3
     333: imul
     334: iconst_2
     335: idiv
     336: iconst_1
     337: isub
     338: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     341: aload_0
     342: new           #147                // class kotlin/Pair
     345: dup
     346: iload_1
     347: iconst_1
     348: isub
     349: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     352: iconst_0
     353: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     356: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     359: iload_1
     360: iconst_3
     361: imul
     362: iconst_2
     363: idiv
     364: iconst_1
     365: isub
     366: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     369: ladd
     370: aload_0
     371: new           #147                // class kotlin/Pair
     374: dup
     375: iconst_0
     376: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     379: iconst_0
     380: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     383: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     386: iload_1
     387: iconst_3
     388: imul
     389: iconst_2
     390: idiv
     391: iconst_1
     392: isub
     393: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     396: ladd
     397: aload_0
     398: new           #147                // class kotlin/Pair
     401: dup
     402: iconst_0
     403: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     406: iload_1
     407: iconst_1
     408: isub
     409: invokestatic  #165                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     412: invokespecial #207                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     415: iload_1
     416: iconst_3
     417: imul
     418: iconst_2
     419: idiv
     420: iconst_1
     421: isub
     422: invokestatic  #209                // Method solve:(Ljava/util/List;Lkotlin/Pair;I)J
     425: ladd
     426: lstore        19
     428: lload         9
     430: lload         13
     432: ladd
     433: lload         15
     435: ladd
     436: lload         5
     438: lconst_1
     439: ladd
     440: lload         17
     442: lmul
     443: ladd
     444: lload         5
     446: lload         19
     448: lmul
     449: ladd
     450: lreturn

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