package day16

import java.io.File

fun main() {
    val data = parse("src/day16/Day16.txt")

    println("🎄 Day 16 🎄")

    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 data class Vec2(
    val x: Int,
    val y: Int,
)

private data class Beam(
    val position: Vec2,
    val direction: Vec2,
)

private fun Beam.advance(): Beam =
    copy(position = Vec2(position.x + direction.x, position.y + direction.y))

private val List<List<Char>>.w get() = this[0].size
private val List<List<Char>>.h get() = this.size

private fun List<List<Char>>.contains(beam: Beam): Boolean =
    beam.position.let { (x, y) -> x >= 0 && y >= 0 && x < w && y < h }

private fun List<List<Char>>.at(beam: Beam): Char =
    beam.position.let { (x, y) -> this[y][x] }

private fun solve(grid: List<List<Char>>, initialBeam: Beam): Int {
    val pool = ArrayDeque<Beam>().apply { add(initialBeam) }

    val cache = mutableSetOf<Beam>()
    val trace = mutableSetOf<Vec2>()

    while (pool.isNotEmpty()) {
        var beam = pool.removeFirst()
        while (grid.contains(beam) && beam !in cache) {
            cache += beam
            trace += beam.position

            when (grid.at(beam)) {
                '-' -> if (beam.direction.y != 0) {
                    pool += beam.copy(direction = Vec2(+1, 0))
                    pool += beam.copy(direction = Vec2(-1, 0))
                    break
                }
                '|' -> if (beam.direction.x != 0) {
                    pool += beam.copy(direction = Vec2(0, +1))
                    pool += beam.copy(direction = Vec2(0, -1))
                    break
                }
                '/' -> {
                    val (dx, dy) = beam.direction
                    beam = if (dx == 0) {
                        beam.copy(direction = Vec2(-dy, 0))
                    } else {
                        beam.copy(direction = Vec2(0, -dx))
                    }
                }
                '\\' -> {
                    val (dx, dy) = beam.direction
                    beam = if (dx == 0) {
                        beam.copy(direction = Vec2(dy, 0))
                    } else {
                        beam.copy(direction = Vec2(0, dx))
                    }
                }
            }

            beam = beam.advance()
        }
    }

    return trace.size
}

private fun part1(data: List<List<Char>>): Int {
    return solve(data, initialBeam = Beam(Vec2(0, 0), Vec2(1, 0)))
}

private fun part2(data: List<List<Char>>): Int {
    val (x0, x1) = (0 to data.w - 1)
    val (y0, y1) = (0 to data.h - 1)
    return maxOf(
        (x0..x1).maxOf { x -> solve(data, initialBeam = Beam(Vec2(x, y0), Vec2(0, +1))) },
        (x0..x1).maxOf { x -> solve(data, initialBeam = Beam(Vec2(x, y1), Vec2(0, -1))) },
        (y0..y1).maxOf { y -> solve(data, initialBeam = Beam(Vec2(x0, y), Vec2(+1, 0))) },
        (y0..y1).maxOf { y -> solve(data, initialBeam = Beam(Vec2(x1, y), Vec2(-1, 0))) },
    )
}

Compiled from "Day16.kt"
public final class day16.Day16Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day16/Day16.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 16 🎄
       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.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 day16.Beam advance(day16.Beam);
    Code:
       0: aload_0
       1: new           #134                // class day16/Vec2
       4: dup
       5: aload_0
       6: invokevirtual #140                // Method day16/Beam.getPosition:()Lday16/Vec2;
       9: invokevirtual #144                // Method day16/Vec2.getX:()I
      12: aload_0
      13: invokevirtual #147                // Method day16/Beam.getDirection:()Lday16/Vec2;
      16: invokevirtual #144                // Method day16/Vec2.getX:()I
      19: iadd
      20: aload_0
      21: invokevirtual #140                // Method day16/Beam.getPosition:()Lday16/Vec2;
      24: invokevirtual #150                // Method day16/Vec2.getY:()I
      27: aload_0
      28: invokevirtual #147                // Method day16/Beam.getDirection:()Lday16/Vec2;
      31: invokevirtual #150                // Method day16/Vec2.getY:()I
      34: iadd
      35: invokespecial #153                // Method day16/Vec2."<init>":(II)V
      38: aconst_null
      39: iconst_2
      40: aconst_null
      41: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
      44: areturn

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

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

  private static final boolean contains(java.util.List<? extends java.util.List<java.lang.Character>>, day16.Beam);
    Code:
       0: aload_1
       1: invokevirtual #140                // Method day16/Beam.getPosition:()Lday16/Vec2;
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: invokevirtual #177                // Method day16/Vec2.component1:()I
      11: istore        4
      13: aload_2
      14: invokevirtual #180                // Method day16/Vec2.component2:()I
      17: istore        5
      19: iload         4
      21: iflt          51
      24: iload         5
      26: iflt          51
      29: iload         4
      31: aload_0
      32: invokestatic  #182                // Method getW:(Ljava/util/List;)I
      35: if_icmpge     51
      38: iload         5
      40: aload_0
      41: invokestatic  #184                // Method getH:(Ljava/util/List;)I
      44: if_icmpge     51
      47: iconst_1
      48: goto          52
      51: iconst_0
      52: nop
      53: ireturn

  private static final char at(java.util.List<? extends java.util.List<java.lang.Character>>, day16.Beam);
    Code:
       0: aload_1
       1: invokevirtual #140                // Method day16/Beam.getPosition:()Lday16/Vec2;
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: invokevirtual #177                // Method day16/Vec2.component1:()I
      11: istore        4
      13: aload_2
      14: invokevirtual #180                // Method day16/Vec2.component2:()I
      17: istore        5
      19: aload_0
      20: iload         5
      22: invokeinterface #165,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: checkcast     #116                // class java/util/List
      30: iload         4
      32: invokeinterface #165,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #194                // class java/lang/Character
      40: invokevirtual #198                // Method java/lang/Character.charValue:()C
      43: nop
      44: ireturn

  private static final int solve(java.util.List<? extends java.util.List<java.lang.Character>>, day16.Beam);
    Code:
       0: new           #205                // class kotlin/collections/ArrayDeque
       3: dup
       4: invokespecial #206                // Method kotlin/collections/ArrayDeque."<init>":()V
       7: astore_3
       8: aload_3
       9: astore        4
      11: iconst_0
      12: istore        5
      14: aload         4
      16: aload_1
      17: invokevirtual #207                // Method kotlin/collections/ArrayDeque.add:(Ljava/lang/Object;)Z
      20: pop
      21: aload_3
      22: astore_2
      23: new           #209                // class java/util/LinkedHashSet
      26: dup
      27: invokespecial #210                // Method java/util/LinkedHashSet."<init>":()V
      30: checkcast     #212                // class java/util/Set
      33: astore_3
      34: new           #209                // class java/util/LinkedHashSet
      37: dup
      38: invokespecial #210                // Method java/util/LinkedHashSet."<init>":()V
      41: checkcast     #212                // class java/util/Set
      44: astore        4
      46: aload_2
      47: checkcast     #86                 // class java/util/Collection
      50: invokeinterface #215,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      55: ifne          62
      58: iconst_1
      59: goto          63
      62: iconst_0
      63: ifeq          457
      66: aload_2
      67: invokevirtual #218                // Method kotlin/collections/ArrayDeque.removeFirst:()Ljava/lang/Object;
      70: checkcast     #136                // class day16/Beam
      73: astore        5
      75: aload_0
      76: aload         5
      78: invokestatic  #220                // Method contains:(Ljava/util/List;Lday16/Beam;)Z
      81: ifeq          46
      84: aload_3
      85: aload         5
      87: invokeinterface #222,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      92: ifne          46
      95: aload_3
      96: checkcast     #86                 // class java/util/Collection
      99: aload         5
     101: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     106: pop
     107: aload         4
     109: checkcast     #86                 // class java/util/Collection
     112: aload         5
     114: invokevirtual #140                // Method day16/Beam.getPosition:()Lday16/Vec2;
     117: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: aload_0
     124: aload         5
     126: invokestatic  #224                // Method at:(Ljava/util/List;Lday16/Beam;)C
     129: lookupswitch  { // 4
                    45: 172
                    47: 308
                    92: 380
                   124: 240
               default: 447
          }
     172: aload         5
     174: invokevirtual #147                // Method day16/Beam.getDirection:()Lday16/Vec2;
     177: invokevirtual #150                // Method day16/Vec2.getY:()I
     180: ifeq          447
     183: aload_2
     184: checkcast     #86                 // class java/util/Collection
     187: aload         5
     189: aconst_null
     190: new           #134                // class day16/Vec2
     193: dup
     194: iconst_1
     195: iconst_0
     196: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     199: iconst_1
     200: aconst_null
     201: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     204: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     209: pop
     210: aload_2
     211: checkcast     #86                 // class java/util/Collection
     214: aload         5
     216: aconst_null
     217: new           #134                // class day16/Vec2
     220: dup
     221: iconst_m1
     222: iconst_0
     223: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     226: iconst_1
     227: aconst_null
     228: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     231: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     236: pop
     237: goto          46
     240: aload         5
     242: invokevirtual #147                // Method day16/Beam.getDirection:()Lday16/Vec2;
     245: invokevirtual #144                // Method day16/Vec2.getX:()I
     248: ifeq          447
     251: aload_2
     252: checkcast     #86                 // class java/util/Collection
     255: aload         5
     257: aconst_null
     258: new           #134                // class day16/Vec2
     261: dup
     262: iconst_0
     263: iconst_1
     264: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     267: iconst_1
     268: aconst_null
     269: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     272: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     277: pop
     278: aload_2
     279: checkcast     #86                 // class java/util/Collection
     282: aload         5
     284: aconst_null
     285: new           #134                // class day16/Vec2
     288: dup
     289: iconst_0
     290: iconst_m1
     291: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     294: iconst_1
     295: aconst_null
     296: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     299: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     304: pop
     305: goto          46
     308: aload         5
     310: invokevirtual #147                // Method day16/Beam.getDirection:()Lday16/Vec2;
     313: astore        6
     315: aload         6
     317: invokevirtual #177                // Method day16/Vec2.component1:()I
     320: istore        7
     322: aload         6
     324: invokevirtual #180                // Method day16/Vec2.component2:()I
     327: istore        8
     329: iload         7
     331: ifne          356
     334: aload         5
     336: aconst_null
     337: new           #134                // class day16/Vec2
     340: dup
     341: iload         8
     343: ineg
     344: iconst_0
     345: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     348: iconst_1
     349: aconst_null
     350: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     353: goto          375
     356: aload         5
     358: aconst_null
     359: new           #134                // class day16/Vec2
     362: dup
     363: iconst_0
     364: iload         7
     366: ineg
     367: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     370: iconst_1
     371: aconst_null
     372: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     375: astore        5
     377: goto          447
     380: aload         5
     382: invokevirtual #147                // Method day16/Beam.getDirection:()Lday16/Vec2;
     385: astore        6
     387: aload         6
     389: invokevirtual #177                // Method day16/Vec2.component1:()I
     392: istore        7
     394: aload         6
     396: invokevirtual #180                // Method day16/Vec2.component2:()I
     399: istore        8
     401: iload         7
     403: ifne          427
     406: aload         5
     408: aconst_null
     409: new           #134                // class day16/Vec2
     412: dup
     413: iload         8
     415: iconst_0
     416: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     419: iconst_1
     420: aconst_null
     421: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     424: goto          445
     427: aload         5
     429: aconst_null
     430: new           #134                // class day16/Vec2
     433: dup
     434: iconst_0
     435: iload         7
     437: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     440: iconst_1
     441: aconst_null
     442: invokestatic  #157                // Method day16/Beam.copy$default:(Lday16/Beam;Lday16/Vec2;Lday16/Vec2;ILjava/lang/Object;)Lday16/Beam;
     445: astore        5
     447: aload         5
     449: invokestatic  #226                // Method advance:(Lday16/Beam;)Lday16/Beam;
     452: astore        5
     454: goto          75
     457: aload         4
     459: invokeinterface #227,  1          // InterfaceMethod java/util/Set.size:()I
     464: ireturn

  private static final int part1(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: new           #136                // class day16/Beam
       4: dup
       5: new           #134                // class day16/Vec2
       8: dup
       9: iconst_0
      10: iconst_0
      11: invokespecial #153                // Method day16/Vec2."<init>":(II)V
      14: new           #134                // class day16/Vec2
      17: dup
      18: iconst_1
      19: iconst_0
      20: invokespecial #153                // Method day16/Vec2."<init>":(II)V
      23: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
      26: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
      29: ireturn

  private static final int part2(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: iconst_0
       1: invokestatic  #249                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       4: aload_0
       5: invokestatic  #182                // Method getW:(Ljava/util/List;)I
       8: iconst_1
       9: isub
      10: invokestatic  #249                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      13: invokestatic  #255                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      16: astore_1
      17: aload_1
      18: invokevirtual #259                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      21: checkcast     #261                // class java/lang/Number
      24: invokevirtual #264                // Method java/lang/Number.intValue:()I
      27: istore_2
      28: aload_1
      29: invokevirtual #266                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      32: checkcast     #261                // class java/lang/Number
      35: invokevirtual #264                // Method java/lang/Number.intValue:()I
      38: istore_3
      39: iconst_0
      40: invokestatic  #249                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      43: aload_0
      44: invokestatic  #184                // Method getH:(Ljava/util/List;)I
      47: iconst_1
      48: isub
      49: invokestatic  #249                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: invokestatic  #255                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      55: astore        4
      57: aload         4
      59: invokevirtual #259                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      62: checkcast     #261                // class java/lang/Number
      65: invokevirtual #264                // Method java/lang/Number.intValue:()I
      68: istore        5
      70: aload         4
      72: invokevirtual #266                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      75: checkcast     #261                // class java/lang/Number
      78: invokevirtual #264                // Method java/lang/Number.intValue:()I
      81: istore        6
      83: new           #268                // class kotlin/ranges/IntRange
      86: dup
      87: iload_2
      88: iload_3
      89: invokespecial #269                // Method kotlin/ranges/IntRange."<init>":(II)V
      92: checkcast     #73                 // class java/lang/Iterable
      95: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     100: astore        8
     102: aload         8
     104: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     109: ifne          120
     112: new           #271                // class java/util/NoSuchElementException
     115: dup
     116: invokespecial #272                // Method java/util/NoSuchElementException."<init>":()V
     119: athrow
     120: aload         8
     122: checkcast     #274                // class kotlin/collections/IntIterator
     125: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     128: istore        9
     130: iconst_0
     131: istore        10
     133: aload_0
     134: new           #136                // class day16/Beam
     137: dup
     138: new           #134                // class day16/Vec2
     141: dup
     142: iload         9
     144: iload         5
     146: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     149: new           #134                // class day16/Vec2
     152: dup
     153: iconst_0
     154: iconst_1
     155: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     158: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     161: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     164: istore        9
     166: aload         8
     168: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     173: ifeq          236
     176: aload         8
     178: checkcast     #274                // class kotlin/collections/IntIterator
     181: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     184: istore        10
     186: iconst_0
     187: istore        11
     189: aload_0
     190: new           #136                // class day16/Beam
     193: dup
     194: new           #134                // class day16/Vec2
     197: dup
     198: iload         10
     200: iload         5
     202: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     205: new           #134                // class day16/Vec2
     208: dup
     209: iconst_0
     210: iconst_1
     211: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     214: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     217: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     220: istore        10
     222: iload         9
     224: iload         10
     226: if_icmpge     166
     229: iload         10
     231: istore        9
     233: goto          166
     236: iload         9
     238: iconst_3
     239: newarray       int
     241: astore        7
     243: aload         7
     245: iconst_0
     246: new           #268                // class kotlin/ranges/IntRange
     249: dup
     250: iload_2
     251: iload_3
     252: invokespecial #269                // Method kotlin/ranges/IntRange."<init>":(II)V
     255: checkcast     #73                 // class java/lang/Iterable
     258: astore        8
     260: istore        15
     262: astore        14
     264: istore        13
     266: aload         8
     268: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     273: astore        9
     275: aload         9
     277: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifne          293
     285: new           #271                // class java/util/NoSuchElementException
     288: dup
     289: invokespecial #272                // Method java/util/NoSuchElementException."<init>":()V
     292: athrow
     293: aload         9
     295: checkcast     #274                // class kotlin/collections/IntIterator
     298: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     301: istore        10
     303: iconst_0
     304: istore        11
     306: aload_0
     307: new           #136                // class day16/Beam
     310: dup
     311: new           #134                // class day16/Vec2
     314: dup
     315: iload         10
     317: iload         6
     319: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     322: new           #134                // class day16/Vec2
     325: dup
     326: iconst_0
     327: iconst_m1
     328: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     331: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     334: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     337: istore        10
     339: aload         9
     341: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     346: ifeq          409
     349: aload         9
     351: checkcast     #274                // class kotlin/collections/IntIterator
     354: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     357: istore        11
     359: iconst_0
     360: istore        12
     362: aload_0
     363: new           #136                // class day16/Beam
     366: dup
     367: new           #134                // class day16/Vec2
     370: dup
     371: iload         11
     373: iload         6
     375: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     378: new           #134                // class day16/Vec2
     381: dup
     382: iconst_0
     383: iconst_m1
     384: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     387: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     390: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     393: istore        11
     395: iload         10
     397: iload         11
     399: if_icmpge     339
     402: iload         11
     404: istore        10
     406: goto          339
     409: iload         10
     411: istore        16
     413: iload         13
     415: aload         14
     417: iload         15
     419: iload         16
     421: iastore
     422: aload         7
     424: iconst_1
     425: new           #268                // class kotlin/ranges/IntRange
     428: dup
     429: iload         5
     431: iload         6
     433: invokespecial #269                // Method kotlin/ranges/IntRange."<init>":(II)V
     436: checkcast     #73                 // class java/lang/Iterable
     439: astore        8
     441: istore        15
     443: astore        14
     445: istore        13
     447: aload         8
     449: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     454: astore        9
     456: aload         9
     458: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     463: ifne          474
     466: new           #271                // class java/util/NoSuchElementException
     469: dup
     470: invokespecial #272                // Method java/util/NoSuchElementException."<init>":()V
     473: athrow
     474: aload         9
     476: checkcast     #274                // class kotlin/collections/IntIterator
     479: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     482: istore        10
     484: iconst_0
     485: istore        11
     487: aload_0
     488: new           #136                // class day16/Beam
     491: dup
     492: new           #134                // class day16/Vec2
     495: dup
     496: iload_2
     497: iload         10
     499: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     502: new           #134                // class day16/Vec2
     505: dup
     506: iconst_1
     507: iconst_0
     508: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     511: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     514: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     517: istore        10
     519: aload         9
     521: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     526: ifeq          588
     529: aload         9
     531: checkcast     #274                // class kotlin/collections/IntIterator
     534: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     537: istore        11
     539: iconst_0
     540: istore        12
     542: aload_0
     543: new           #136                // class day16/Beam
     546: dup
     547: new           #134                // class day16/Vec2
     550: dup
     551: iload_2
     552: iload         11
     554: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     557: new           #134                // class day16/Vec2
     560: dup
     561: iconst_1
     562: iconst_0
     563: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     566: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     569: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     572: istore        11
     574: iload         10
     576: iload         11
     578: if_icmpge     519
     581: iload         11
     583: istore        10
     585: goto          519
     588: iload         10
     590: istore        16
     592: iload         13
     594: aload         14
     596: iload         15
     598: iload         16
     600: iastore
     601: aload         7
     603: iconst_2
     604: new           #268                // class kotlin/ranges/IntRange
     607: dup
     608: iload         5
     610: iload         6
     612: invokespecial #269                // Method kotlin/ranges/IntRange."<init>":(II)V
     615: checkcast     #73                 // class java/lang/Iterable
     618: astore        8
     620: istore        15
     622: astore        14
     624: istore        13
     626: aload         8
     628: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     633: astore        9
     635: aload         9
     637: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     642: ifne          653
     645: new           #271                // class java/util/NoSuchElementException
     648: dup
     649: invokespecial #272                // Method java/util/NoSuchElementException."<init>":()V
     652: athrow
     653: aload         9
     655: checkcast     #274                // class kotlin/collections/IntIterator
     658: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     661: istore        10
     663: iconst_0
     664: istore        11
     666: aload_0
     667: new           #136                // class day16/Beam
     670: dup
     671: new           #134                // class day16/Vec2
     674: dup
     675: iload_3
     676: iload         10
     678: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     681: new           #134                // class day16/Vec2
     684: dup
     685: iconst_m1
     686: iconst_0
     687: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     690: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     693: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     696: istore        10
     698: aload         9
     700: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     705: ifeq          767
     708: aload         9
     710: checkcast     #274                // class kotlin/collections/IntIterator
     713: invokevirtual #277                // Method kotlin/collections/IntIterator.nextInt:()I
     716: istore        11
     718: iconst_0
     719: istore        12
     721: aload_0
     722: new           #136                // class day16/Beam
     725: dup
     726: new           #134                // class day16/Vec2
     729: dup
     730: iload_3
     731: iload         11
     733: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     736: new           #134                // class day16/Vec2
     739: dup
     740: iconst_m1
     741: iconst_0
     742: invokespecial #153                // Method day16/Vec2."<init>":(II)V
     745: invokespecial #241                // Method day16/Beam."<init>":(Lday16/Vec2;Lday16/Vec2;)V
     748: invokestatic  #243                // Method solve:(Ljava/util/List;Lday16/Beam;)I
     751: istore        11
     753: iload         10
     755: iload         11
     757: if_icmpge     698
     760: iload         11
     762: istore        10
     764: goto          698
     767: iload         10
     769: istore        16
     771: iload         13
     773: aload         14
     775: iload         15
     777: iload         16
     779: iastore
     780: aload         7
     782: invokestatic  #283                // Method kotlin/comparisons/ComparisonsKt.maxOf:(I[I)I
     785: ireturn

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


package day11

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

fun main() {
    val data = parse("src/day11/Day11.txt")

    println("🎄 Day 11 🎄")

    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>>, scale: Long): Long {
    val emptyRows = data.indices
        .filter { row -> data[row].all { it == '.' } }

    val emptyCols = data[0].indices
        .filter { col -> data.all { it[col] == '.' } }

    val galaxies = mutableListOf<Pair<Int, Int>>()
    for ((y, row) in data.withIndex()) {
        for ((x, col) in row.withIndex()) {
            if (col == '#') {
                galaxies.add(x to y)
            }
        }
    }

    var accumulator = 0L
    for (a in 0..galaxies.lastIndex) {
        for (b in (a + 1)..galaxies.lastIndex) {
            val (ax, ay) = galaxies[a]
            val (bx, by) = galaxies[b]

            val x0 = min(ax, bx)
            val x1 = max(ax, bx)

            val y0 = min(ay, by)
            val y1 = max(ay, by)

            val nx = emptyCols.count { it in x0..x1 }
            val ny = emptyRows.count { it in y0..y1 }

            accumulator += (x1 - x0) + nx * (scale - 1)
            accumulator += (y1 - y0) + ny * (scale - 1)
        }
    }

    return accumulator
}

private fun part1(data: List<List<Char>>): Long =
    solve(data, scale = 2L)

private fun part2(data: List<List<Char>>): Long =
    solve(data, scale = 1_000_000L)

Compiled from "Day11.kt"
public final class day11.Day11Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/day11/Day11.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: ldc           #14                 // String 🎄 Day 11 🎄
       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>>, long);
    Code:
       0: aload_0
       1: checkcast     #86                 // class java/util/Collection
       4: invokestatic  #137                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore        4
      12: nop
      13: iconst_0
      14: istore        5
      16: aload         4
      18: astore        6
      20: new           #75                 // class java/util/ArrayList
      23: dup
      24: invokespecial #138                // Method java/util/ArrayList."<init>":()V
      27: checkcast     #86                 // class java/util/Collection
      30: astore        7
      32: iconst_0
      33: istore        8
      35: aload         6
      37: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        9
      44: aload         9
      46: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          195
      54: aload         9
      56: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        10
      63: aload         10
      65: checkcast     #140                // class java/lang/Number
      68: invokevirtual #144                // Method java/lang/Number.intValue:()I
      71: istore        11
      73: iconst_0
      74: istore        12
      76: aload_0
      77: iload         11
      79: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      84: checkcast     #73                 // class java/lang/Iterable
      87: astore        13
      89: iconst_0
      90: istore        14
      92: aload         13
      94: instanceof    #86                 // class java/util/Collection
      97: ifeq          117
     100: aload         13
     102: checkcast     #86                 // class java/util/Collection
     105: invokeinterface #151,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     110: ifeq          117
     113: iconst_1
     114: goto          178
     117: aload         13
     119: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     124: astore        15
     126: aload         15
     128: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     133: ifeq          177
     136: aload         15
     138: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     143: astore        16
     145: aload         16
     147: checkcast     #153                // class java/lang/Character
     150: invokevirtual #157                // Method java/lang/Character.charValue:()C
     153: istore        17
     155: iconst_0
     156: istore        18
     158: iload         17
     160: bipush        46
     162: if_icmpne     169
     165: iconst_1
     166: goto          170
     169: iconst_0
     170: ifne          126
     173: iconst_0
     174: goto          178
     177: iconst_1
     178: nop
     179: ifeq          44
     182: aload         7
     184: aload         10
     186: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     191: pop
     192: goto          44
     195: aload         7
     197: checkcast     #116                // class java/util/List
     200: nop
     201: astore_3
     202: aload_0
     203: iconst_0
     204: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     209: checkcast     #86                 // class java/util/Collection
     212: invokestatic  #137                // Method kotlin/collections/CollectionsKt.getIndices:(Ljava/util/Collection;)Lkotlin/ranges/IntRange;
     215: checkcast     #73                 // class java/lang/Iterable
     218: astore        5
     220: nop
     221: iconst_0
     222: istore        6
     224: aload         5
     226: astore        7
     228: new           #75                 // class java/util/ArrayList
     231: dup
     232: invokespecial #138                // Method java/util/ArrayList."<init>":()V
     235: checkcast     #86                 // class java/util/Collection
     238: astore        8
     240: iconst_0
     241: istore        9
     243: aload         7
     245: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     250: astore        10
     252: aload         10
     254: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     259: ifeq          406
     262: aload         10
     264: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     269: astore        11
     271: aload         11
     273: checkcast     #140                // class java/lang/Number
     276: invokevirtual #144                // Method java/lang/Number.intValue:()I
     279: istore        12
     281: iconst_0
     282: istore        13
     284: aload_0
     285: checkcast     #73                 // class java/lang/Iterable
     288: astore        14
     290: iconst_0
     291: istore        15
     293: aload         14
     295: instanceof    #86                 // class java/util/Collection
     298: ifeq          318
     301: aload         14
     303: checkcast     #86                 // class java/util/Collection
     306: invokeinterface #151,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     311: ifeq          318
     314: iconst_1
     315: goto          389
     318: aload         14
     320: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     325: astore        16
     327: aload         16
     329: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     334: ifeq          388
     337: aload         16
     339: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     344: astore        17
     346: aload         17
     348: checkcast     #116                // class java/util/List
     351: astore        18
     353: iconst_0
     354: istore        19
     356: aload         18
     358: iload         12
     360: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     365: checkcast     #153                // class java/lang/Character
     368: invokevirtual #157                // Method java/lang/Character.charValue:()C
     371: bipush        46
     373: if_icmpne     380
     376: iconst_1
     377: goto          381
     380: iconst_0
     381: ifne          327
     384: iconst_0
     385: goto          389
     388: iconst_1
     389: nop
     390: ifeq          252
     393: aload         8
     395: aload         11
     397: invokeinterface #114,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     402: pop
     403: goto          252
     406: aload         8
     408: checkcast     #116                // class java/util/List
     411: nop
     412: astore        4
     414: new           #75                 // class java/util/ArrayList
     417: dup
     418: invokespecial #138                // Method java/util/ArrayList."<init>":()V
     421: checkcast     #116                // class java/util/List
     424: astore        5
     426: aload_0
     427: checkcast     #73                 // class java/lang/Iterable
     430: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     435: astore        6
     437: iconst_0
     438: istore        7
     440: aload         6
     442: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     447: ifeq          553
     450: iload         7
     452: istore        8
     454: iload         7
     456: iconst_1
     457: iadd
     458: istore        7
     460: aload         6
     462: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     467: checkcast     #116                // class java/util/List
     470: astore        9
     472: aload         9
     474: checkcast     #73                 // class java/lang/Iterable
     477: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     482: astore        10
     484: iconst_0
     485: istore        11
     487: aload         10
     489: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     494: ifeq          440
     497: iload         11
     499: istore        12
     501: iload         11
     503: iconst_1
     504: iadd
     505: istore        11
     507: aload         10
     509: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     514: checkcast     #153                // class java/lang/Character
     517: invokevirtual #157                // Method java/lang/Character.charValue:()C
     520: istore        13
     522: iload         13
     524: bipush        35
     526: if_icmpne     487
     529: aload         5
     531: iload         12
     533: invokestatic  #163                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     536: iload         8
     538: invokestatic  #163                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     541: invokestatic  #169                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     544: invokeinterface #170,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     549: pop
     550: goto          487
     553: lconst_0
     554: lstore        6
     556: iconst_0
     557: istore        8
     559: aload         5
     561: invokestatic  #174                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     564: istore        9
     566: iload         8
     568: iload         9
     570: if_icmpgt     1018
     573: iload         8
     575: iconst_1
     576: iadd
     577: istore        10
     579: aload         5
     581: invokestatic  #174                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     584: istore        11
     586: iload         10
     588: iload         11
     590: if_icmpgt     1005
     593: aload         5
     595: iload         8
     597: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     602: checkcast     #176                // class kotlin/Pair
     605: astore        12
     607: aload         12
     609: invokevirtual #179                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     612: checkcast     #140                // class java/lang/Number
     615: invokevirtual #144                // Method java/lang/Number.intValue:()I
     618: istore        13
     620: aload         12
     622: invokevirtual #182                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     625: checkcast     #140                // class java/lang/Number
     628: invokevirtual #144                // Method java/lang/Number.intValue:()I
     631: istore        14
     633: aload         5
     635: iload         10
     637: invokeinterface #148,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     642: checkcast     #176                // class kotlin/Pair
     645: astore        15
     647: aload         15
     649: invokevirtual #179                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     652: checkcast     #140                // class java/lang/Number
     655: invokevirtual #144                // Method java/lang/Number.intValue:()I
     658: istore        16
     660: aload         15
     662: invokevirtual #182                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     665: checkcast     #140                // class java/lang/Number
     668: invokevirtual #144                // Method java/lang/Number.intValue:()I
     671: istore        17
     673: iload         13
     675: iload         16
     677: invokestatic  #188                // Method java/lang/Math.min:(II)I
     680: istore        18
     682: iload         13
     684: iload         16
     686: invokestatic  #191                // Method java/lang/Math.max:(II)I
     689: istore        19
     691: iload         14
     693: iload         17
     695: invokestatic  #188                // Method java/lang/Math.min:(II)I
     698: istore        20
     700: iload         14
     702: iload         17
     704: invokestatic  #191                // Method java/lang/Math.max:(II)I
     707: istore        21
     709: aload         4
     711: checkcast     #73                 // class java/lang/Iterable
     714: astore        23
     716: iconst_0
     717: istore        24
     719: aload         23
     721: instanceof    #86                 // class java/util/Collection
     724: ifeq          744
     727: aload         23
     729: checkcast     #86                 // class java/util/Collection
     732: invokeinterface #151,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     737: ifeq          744
     740: iconst_0
     741: goto          830
     744: iconst_0
     745: istore        25
     747: aload         23
     749: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     754: astore        26
     756: aload         26
     758: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     763: ifeq          828
     766: aload         26
     768: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     773: astore        27
     775: aload         27
     777: checkcast     #140                // class java/lang/Number
     780: invokevirtual #144                // Method java/lang/Number.intValue:()I
     783: istore        28
     785: iconst_0
     786: istore        29
     788: iload         18
     790: iload         28
     792: if_icmpgt     810
     795: iload         28
     797: iload         19
     799: if_icmpgt     806
     802: iconst_1
     803: goto          811
     806: iconst_0
     807: goto          811
     810: iconst_0
     811: ifeq          756
     814: iinc          25, 1
     817: iload         25
     819: ifge          756
     822: invokestatic  #194                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     825: goto          756
     828: iload         25
     830: istore        22
     832: aload_3
     833: checkcast     #73                 // class java/lang/Iterable
     836: astore        24
     838: iconst_0
     839: istore        25
     841: aload         24
     843: instanceof    #86                 // class java/util/Collection
     846: ifeq          866
     849: aload         24
     851: checkcast     #86                 // class java/util/Collection
     854: invokeinterface #151,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     859: ifeq          866
     862: iconst_0
     863: goto          952
     866: iconst_0
     867: istore        26
     869: aload         24
     871: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     876: astore        27
     878: aload         27
     880: invokeinterface #96,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     885: ifeq          950
     888: aload         27
     890: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     895: astore        28
     897: aload         28
     899: checkcast     #140                // class java/lang/Number
     902: invokevirtual #144                // Method java/lang/Number.intValue:()I
     905: istore        29
     907: iconst_0
     908: istore        30
     910: iload         20
     912: iload         29
     914: if_icmpgt     932
     917: iload         29
     919: iload         21
     921: if_icmpgt     928
     924: iconst_1
     925: goto          933
     928: iconst_0
     929: goto          933
     932: iconst_0
     933: ifeq          878
     936: iinc          26, 1
     939: iload         26
     941: ifge          878
     944: invokestatic  #194                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     947: goto          878
     950: iload         26
     952: istore        23
     954: lload         6
     956: iload         19
     958: iload         18
     960: isub
     961: i2l
     962: iload         22
     964: i2l
     965: lload_1
     966: lconst_1
     967: lsub
     968: lmul
     969: ladd
     970: ladd
     971: lstore        6
     973: lload         6
     975: iload         21
     977: iload         20
     979: isub
     980: i2l
     981: iload         23
     983: i2l
     984: lload_1
     985: lconst_1
     986: lsub
     987: lmul
     988: ladd
     989: ladd
     990: lstore        6
     992: iload         10
     994: iload         11
     996: if_icmpeq     1005
     999: iinc          10, 1
    1002: goto          593
    1005: iload         8
    1007: iload         9
    1009: if_icmpeq     1018
    1012: iinc          8, 1
    1015: goto          573
    1018: lload         6
    1020: lreturn

  private static final long part1(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: ldc2_w        #237                // long 2l
       4: invokestatic  #240                // Method solve:(Ljava/util/List;J)J
       7: lreturn

  private static final long part2(java.util.List<? extends java.util.List<java.lang.Character>>);
    Code:
       0: aload_0
       1: ldc2_w        #241                // long 1000000l
       4: invokestatic  #240                // Method solve:(Ljava/util/List;J)J
       7: lreturn

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