package day11

import java.io.File
import java.util.LinkedList

fun parseMap(rows: List<String>): Array<IntArray> =
  rows.map { row -> row.trim().map { it - '0' }.toIntArray() }.toTypedArray()

private fun expandAdjacentWithDiagonals(row: Int, column: Int, map: Array<IntArray>): List<Pair<Int, Int>> =
  (-1..1).flatMap { r -> (-1..1).map { c -> (r + row) to (c + column) } }
    .filterNot { (r, c) -> r < 0 || c < 0 || r >= map.size || c >= map[0].size || (r == row && c == column) }

fun simulateStep(octopusMap: Array<IntArray>): Int {
  val traverseIndices = octopusMap.flatMapIndexed { index, row -> row.indices.map { index to it } }
  val cellsToVisit = LinkedList(traverseIndices)
  val visited = mutableSetOf<Pair<Int, Int>>()
  var flashes = 0

  while (cellsToVisit.isNotEmpty()) {
    val current = cellsToVisit.removeFirst()
    val (x, y) = current
    when (octopusMap[x][y]) {
      9 -> {
        octopusMap[x][y] = 0
        visited.add(current)
        flashes += 1
        cellsToVisit.addAll(expandAdjacentWithDiagonals(x, y, octopusMap))
      }
      0 -> if (!visited.contains(current)) octopusMap[x][y] += 1 // Can only flash once
      in (1..8) -> octopusMap[x][y] += 1 // 0 is intentionally ignored
    }
  }
  return flashes
}

fun simulateSteps(steps: Int, octopusMap: Array<IntArray>): Int =
  (1..steps).fold(0) { acc, _ -> acc + simulateStep(octopusMap) }

fun countStepsUntilAllOctopusesSynchronize(octopusMap: Array<IntArray>): Int {
  fun allFlashed(map: Array<IntArray>): Boolean =
    map.all { energies -> energies.all { it == 0 } }

  return generateSequence(1) { it + 1 }.first {
    simulateStep(octopusMap)
    allFlashed(octopusMap)
  }.or(0)
}

fun main() {
  File("./input/day11.txt").useLines { lines ->
    val input = lines.toList()
    println(simulateSteps(100, parseMap(input)))
    println(countStepsUntilAllOctopusesSynchronize(parseMap(input)))
  }
}

Compiled from "Day11.kt"
public final class day11.Day11Kt {
  public static final int[][] parseMap(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #10                 // String rows
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #18                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #20                 // class java/util/ArrayList
      18: dup
      19: aload_1
      20: bipush        10
      22: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      25: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      28: checkcast     #32                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          207
      54: aload         6
      56: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         4
      65: aload         7
      67: checkcast     #48                 // class java/lang/String
      70: astore        8
      72: astore        20
      74: iconst_0
      75: istore        9
      77: aload         8
      79: checkcast     #50                 // class java/lang/CharSequence
      82: invokestatic  #56                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      85: invokevirtual #60                 // Method java/lang/Object.toString:()Ljava/lang/String;
      88: checkcast     #50                 // class java/lang/CharSequence
      91: astore        10
      93: nop
      94: iconst_0
      95: istore        11
      97: aload         10
      99: astore        12
     101: new           #20                 // class java/util/ArrayList
     104: dup
     105: aload         10
     107: invokeinterface #64,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     112: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     115: checkcast     #32                 // class java/util/Collection
     118: astore        13
     120: iconst_0
     121: istore        14
     123: iconst_0
     124: istore        15
     126: iload         15
     128: aload         12
     130: invokeinterface #64,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     135: if_icmpge     183
     138: aload         12
     140: iload         15
     142: invokeinterface #68,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     147: istore        16
     149: aload         13
     151: iload         16
     153: istore        17
     155: astore        18
     157: iconst_0
     158: istore        19
     160: iload         17
     162: bipush        48
     164: isub
     165: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     168: aload         18
     170: swap
     171: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     176: pop
     177: iinc          15, 1
     180: goto          126
     183: aload         13
     185: checkcast     #80                 // class java/util/List
     188: nop
     189: checkcast     #32                 // class java/util/Collection
     192: invokestatic  #84                 // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     195: aload         20
     197: swap
     198: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     203: pop
     204: goto          44
     207: aload         4
     209: checkcast     #80                 // class java/util/List
     212: nop
     213: checkcast     #32                 // class java/util/Collection
     216: astore_1
     217: nop
     218: iconst_0
     219: istore_2
     220: aload_1
     221: astore_3
     222: aload_3
     223: iconst_0
     224: anewarray     #86                 // class "[I"
     227: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.toArray:([Ljava/lang/Object;)[Ljava/lang/Object;
     232: checkcast     #92                 // class "[[I"
     235: areturn

  private static final java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>> expandAdjacentWithDiagonals(int, int, int[][]);
    Code:
       0: new           #118                // class kotlin/ranges/IntRange
       3: dup
       4: iconst_m1
       5: iconst_1
       6: invokespecial #121                // Method kotlin/ranges/IntRange."<init>":(II)V
       9: checkcast     #18                 // class java/lang/Iterable
      12: astore_3
      13: iconst_0
      14: istore        4
      16: aload_3
      17: astore        5
      19: new           #20                 // class java/util/ArrayList
      22: dup
      23: invokespecial #124                // Method java/util/ArrayList."<init>":()V
      26: checkcast     #32                 // class java/util/Collection
      29: astore        6
      31: iconst_0
      32: istore        7
      34: aload         5
      36: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        8
      43: aload         8
      45: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          205
      53: aload         8
      55: checkcast     #126                // class kotlin/collections/IntIterator
      58: invokevirtual #129                // Method kotlin/collections/IntIterator.nextInt:()I
      61: istore        9
      63: iload         9
      65: istore        10
      67: iconst_0
      68: istore        11
      70: new           #118                // class kotlin/ranges/IntRange
      73: dup
      74: iconst_m1
      75: iconst_1
      76: invokespecial #121                // Method kotlin/ranges/IntRange."<init>":(II)V
      79: checkcast     #18                 // class java/lang/Iterable
      82: astore        12
      84: iconst_0
      85: istore        13
      87: aload         12
      89: astore        14
      91: new           #20                 // class java/util/ArrayList
      94: dup
      95: aload         12
      97: bipush        10
      99: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     102: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
     105: checkcast     #32                 // class java/util/Collection
     108: astore        15
     110: iconst_0
     111: istore        16
     113: aload         14
     115: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     120: astore        17
     122: aload         17
     124: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     129: ifeq          182
     132: aload         17
     134: checkcast     #126                // class kotlin/collections/IntIterator
     137: invokevirtual #129                // Method kotlin/collections/IntIterator.nextInt:()I
     140: istore        18
     142: aload         15
     144: iload         18
     146: istore        19
     148: astore        20
     150: iconst_0
     151: istore        21
     153: iload         10
     155: iload_0
     156: iadd
     157: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     160: iload         19
     162: iload_1
     163: iadd
     164: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     167: invokestatic  #135                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     170: aload         20
     172: swap
     173: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     178: pop
     179: goto          122
     182: aload         15
     184: checkcast     #80                 // class java/util/List
     187: nop
     188: checkcast     #18                 // class java/lang/Iterable
     191: nop
     192: astore        10
     194: aload         6
     196: aload         10
     198: invokestatic  #139                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     201: pop
     202: goto          43
     205: aload         6
     207: checkcast     #80                 // class java/util/List
     210: nop
     211: checkcast     #18                 // class java/lang/Iterable
     214: astore_3
     215: nop
     216: iconst_0
     217: istore        4
     219: aload_3
     220: astore        5
     222: new           #20                 // class java/util/ArrayList
     225: dup
     226: invokespecial #124                // Method java/util/ArrayList."<init>":()V
     229: checkcast     #32                 // class java/util/Collection
     232: astore        6
     234: iconst_0
     235: istore        7
     237: aload         5
     239: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     244: astore        8
     246: aload         8
     248: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     253: ifeq          363
     256: aload         8
     258: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     263: astore        9
     265: aload         9
     267: checkcast     #141                // class kotlin/Pair
     270: astore        10
     272: iconst_0
     273: istore        11
     275: aload         10
     277: invokevirtual #144                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     280: checkcast     #146                // class java/lang/Number
     283: invokevirtual #149                // Method java/lang/Number.intValue:()I
     286: istore        12
     288: aload         10
     290: invokevirtual #152                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     293: checkcast     #146                // class java/lang/Number
     296: invokevirtual #149                // Method java/lang/Number.intValue:()I
     299: istore        13
     301: iload         12
     303: iflt          342
     306: iload         13
     308: iflt          342
     311: iload         12
     313: aload_2
     314: checkcast     #154                // class "[Ljava/lang/Object;"
     317: arraylength
     318: if_icmpge     342
     321: iload         13
     323: aload_2
     324: iconst_0
     325: aaload
     326: arraylength
     327: if_icmpge     342
     330: iload         12
     332: iload_0
     333: if_icmpne     346
     336: iload         13
     338: iload_1
     339: if_icmpne     346
     342: iconst_1
     343: goto          347
     346: iconst_0
     347: ifne          246
     350: aload         6
     352: aload         9
     354: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     359: pop
     360: goto          246
     363: aload         6
     365: checkcast     #80                 // class java/util/List
     368: nop
     369: areturn

  public static final int simulateStep(int[][]);
    Code:
       0: aload_0
       1: ldc           #175                // String octopusMap
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #154                // class "[Ljava/lang/Object;"
      10: astore_3
      11: new           #20                 // class java/util/ArrayList
      14: dup
      15: invokespecial #124                // Method java/util/ArrayList."<init>":()V
      18: checkcast     #32                 // class java/util/Collection
      21: astore        4
      23: iconst_0
      24: istore        5
      26: iconst_0
      27: istore        6
      29: aload_3
      30: arraylength
      31: istore        7
      33: iload         6
      35: iload         7
      37: if_icmpge     190
      40: aload_3
      41: iload         6
      43: aaload
      44: astore        8
      46: iload         5
      48: iinc          5, 1
      51: aload         8
      53: checkcast     #86                 // class "[I"
      56: astore        9
      58: istore        10
      60: iconst_0
      61: istore        11
      63: aload         9
      65: invokestatic  #181                // Method kotlin/collections/ArraysKt.getIndices:([I)Lkotlin/ranges/IntRange;
      68: checkcast     #18                 // class java/lang/Iterable
      71: astore        12
      73: iconst_0
      74: istore        13
      76: aload         12
      78: astore        14
      80: new           #20                 // class java/util/ArrayList
      83: dup
      84: aload         12
      86: bipush        10
      88: invokestatic  #26                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      91: invokespecial #30                 // Method java/util/ArrayList."<init>":(I)V
      94: checkcast     #32                 // class java/util/Collection
      97: astore        15
      99: iconst_0
     100: istore        16
     102: aload         14
     104: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     109: astore        17
     111: aload         17
     113: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     118: ifeq          167
     121: aload         17
     123: checkcast     #126                // class kotlin/collections/IntIterator
     126: invokevirtual #129                // Method kotlin/collections/IntIterator.nextInt:()I
     129: istore        18
     131: aload         15
     133: iload         18
     135: istore        19
     137: astore        20
     139: iconst_0
     140: istore        21
     142: iload         10
     144: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: iload         19
     149: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: invokestatic  #135                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     155: aload         20
     157: swap
     158: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     163: pop
     164: goto          111
     167: aload         15
     169: checkcast     #80                 // class java/util/List
     172: nop
     173: checkcast     #18                 // class java/lang/Iterable
     176: nop
     177: aload         4
     179: swap
     180: invokestatic  #139                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     183: pop
     184: iinc          6, 1
     187: goto          33
     190: aload         4
     192: checkcast     #80                 // class java/util/List
     195: astore_1
     196: new           #183                // class java/util/LinkedList
     199: dup
     200: aload_1
     201: checkcast     #32                 // class java/util/Collection
     204: invokespecial #186                // Method java/util/LinkedList."<init>":(Ljava/util/Collection;)V
     207: astore_2
     208: new           #188                // class java/util/LinkedHashSet
     211: dup
     212: invokespecial #189                // Method java/util/LinkedHashSet."<init>":()V
     215: checkcast     #191                // class java/util/Set
     218: astore_3
     219: iconst_0
     220: istore        4
     222: aload_2
     223: checkcast     #32                 // class java/util/Collection
     226: invokeinterface #194,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     231: ifne          238
     234: iconst_1
     235: goto          239
     238: iconst_0
     239: ifeq          420
     242: aload_2
     243: invokevirtual #197                // Method java/util/LinkedList.removeFirst:()Ljava/lang/Object;
     246: checkcast     #141                // class kotlin/Pair
     249: astore        5
     251: aload         5
     253: invokevirtual #144                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     256: checkcast     #146                // class java/lang/Number
     259: invokevirtual #149                // Method java/lang/Number.intValue:()I
     262: istore        6
     264: aload         5
     266: invokevirtual #152                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     269: checkcast     #146                // class java/lang/Number
     272: invokevirtual #149                // Method java/lang/Number.intValue:()I
     275: istore        7
     277: aload_0
     278: iload         6
     280: aaload
     281: iload         7
     283: iaload
     284: istore        8
     286: iload         8
     288: bipush        9
     290: if_icmpne     337
     293: aload_0
     294: iload         6
     296: aaload
     297: iload         7
     299: iconst_0
     300: iastore
     301: aload_3
     302: aload         5
     304: invokestatic  #201                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     307: aload         5
     309: invokeinterface #202,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     314: pop
     315: iinc          4, 1
     318: aload_2
     319: iload         6
     321: iload         7
     323: aload_0
     324: invokestatic  #204                // Method expandAdjacentWithDiagonals:(II[[I)Ljava/util/List;
     327: checkcast     #32                 // class java/util/Collection
     330: invokevirtual #207                // Method java/util/LinkedList.addAll:(Ljava/util/Collection;)Z
     333: pop
     334: goto          222
     337: iload         8
     339: ifne          374
     342: aload_3
     343: aload         5
     345: invokeinterface #210,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     350: ifne          222
     353: aload_0
     354: iload         6
     356: aaload
     357: astore        9
     359: aload         9
     361: iload         7
     363: aload         9
     365: iload         7
     367: iaload
     368: iconst_1
     369: iadd
     370: iastore
     371: goto          222
     374: iconst_1
     375: iload         8
     377: if_icmpgt     395
     380: iload         8
     382: bipush        9
     384: if_icmpge     391
     387: iconst_1
     388: goto          396
     391: iconst_0
     392: goto          396
     395: iconst_0
     396: ifeq          222
     399: aload_0
     400: iload         6
     402: aaload
     403: astore        9
     405: aload         9
     407: iload         7
     409: aload         9
     411: iload         7
     413: iaload
     414: iconst_1
     415: iadd
     416: iastore
     417: goto          222
     420: iload         4
     422: ireturn

  public static final int simulateSteps(int, int[][]);
    Code:
       0: aload_1
       1: ldc           #175                // String octopusMap
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #118                // class kotlin/ranges/IntRange
       9: dup
      10: iconst_1
      11: iload_0
      12: invokespecial #121                // Method kotlin/ranges/IntRange."<init>":(II)V
      15: checkcast     #18                 // class java/lang/Iterable
      18: astore_2
      19: iconst_0
      20: istore_3
      21: iconst_0
      22: istore        4
      24: iload_3
      25: istore        5
      27: aload_2
      28: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        6
      35: aload         6
      37: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          74
      45: aload         6
      47: checkcast     #126                // class kotlin/collections/IntIterator
      50: invokevirtual #129                // Method kotlin/collections/IntIterator.nextInt:()I
      53: istore        7
      55: iload         5
      57: istore        8
      59: iconst_0
      60: istore        9
      62: iload         8
      64: aload_1
      65: invokestatic  #227                // Method simulateStep:([[I)I
      68: iadd
      69: istore        5
      71: goto          35
      74: iload         5
      76: ireturn

  public static final int countStepsUntilAllOctopusesSynchronize(int[][]);
    Code:
       0: aload_0
       1: ldc           #175                // String octopusMap
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_1
       7: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      10: invokedynamic #255,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      15: invokestatic  #261                // Method kotlin/sequences/SequencesKt.generateSequence:(Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: invokeinterface #264,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      27: astore_3
      28: aload_3
      29: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      34: ifeq          75
      37: aload_3
      38: invokeinterface #46,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      43: astore        4
      45: aload         4
      47: checkcast     #146                // class java/lang/Number
      50: invokevirtual #149                // Method java/lang/Number.intValue:()I
      53: istore        5
      55: iconst_0
      56: istore        6
      58: aload_0
      59: invokestatic  #227                // Method simulateStep:([[I)I
      62: pop
      63: aload_0
      64: invokestatic  #268                // Method countStepsUntilAllOctopusesSynchronize$allFlashed:([[I)Z
      67: ifeq          28
      70: aload         4
      72: goto          86
      75: new           #270                // class java/util/NoSuchElementException
      78: dup
      79: ldc_w         #272                // String Sequence contains no element matching the predicate.
      82: invokespecial #275                // Method java/util/NoSuchElementException."<init>":(Ljava/lang/String;)V
      85: athrow
      86: checkcast     #146                // class java/lang/Number
      89: invokevirtual #149                // Method java/lang/Number.intValue:()I
      92: iconst_0
      93: ior
      94: ireturn

  public static final void main();
    Code:
       0: new           #284                // class java/io/File
       3: dup
       4: ldc_w         #286                // String ./input/day11.txt
       7: invokespecial #287                // Method java/io/File."<init>":(Ljava/lang/String;)V
      10: astore_0
      11: getstatic     #293                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      14: astore_1
      15: iconst_0
      16: istore_2
      17: aload_0
      18: astore_3
      19: sipush        8192
      22: istore        4
      24: aload_3
      25: astore        5
      27: new           #295                // class java/io/InputStreamReader
      30: dup
      31: new           #297                // class java/io/FileInputStream
      34: dup
      35: aload         5
      37: invokespecial #300                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      40: checkcast     #302                // class java/io/InputStream
      43: aload_1
      44: invokespecial #305                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      47: checkcast     #307                // class java/io/Reader
      50: astore        5
      52: aload         5
      54: instanceof    #309                // class java/io/BufferedReader
      57: ifeq          68
      60: aload         5
      62: checkcast     #309                // class java/io/BufferedReader
      65: goto          79
      68: new           #309                // class java/io/BufferedReader
      71: dup
      72: aload         5
      74: iload         4
      76: invokespecial #312                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      79: checkcast     #314                // class java/io/Closeable
      82: astore_3
      83: aconst_null
      84: astore        4
      86: nop
      87: aload_3
      88: checkcast     #309                // class java/io/BufferedReader
      91: astore        5
      93: iconst_0
      94: istore        6
      96: aload         5
      98: invokestatic  #320                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     101: astore        7
     103: iconst_0
     104: istore        8
     106: aload         7
     108: invokestatic  #324                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     111: astore        9
     113: bipush        100
     115: aload         9
     117: invokestatic  #326                // Method parseMap:(Ljava/util/List;)[[I
     120: invokestatic  #328                // Method simulateSteps:(I[[I)I
     123: istore        10
     125: getstatic     #334                // Field java/lang/System.out:Ljava/io/PrintStream;
     128: iload         10
     130: invokevirtual #339                // Method java/io/PrintStream.println:(I)V
     133: aload         9
     135: invokestatic  #326                // Method parseMap:(Ljava/util/List;)[[I
     138: invokestatic  #341                // Method countStepsUntilAllOctopusesSynchronize:([[I)I
     141: istore        10
     143: getstatic     #334                // Field java/lang/System.out:Ljava/io/PrintStream;
     146: iload         10
     148: invokevirtual #339                // Method java/io/PrintStream.println:(I)V
     151: nop
     152: getstatic     #347                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     155: astore        5
     157: aload_3
     158: aload         4
     160: invokestatic  #353                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     163: goto          186
     166: astore        6
     168: aload         6
     170: astore        4
     172: aload         6
     174: athrow
     175: astore        6
     177: aload_3
     178: aload         4
     180: invokestatic  #353                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     183: aload         6
     185: athrow
     186: nop
     187: return
    Exception table:
       from    to  target type
          86   157   166   Class java/lang/Throwable
          86   157   175   any
         166   175   175   any
         175   177   175   any

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

  private static final boolean countStepsUntilAllOctopusesSynchronize$allFlashed(int[][]);
    Code:
       0: aload_0
       1: checkcast     #154                // class "[Ljava/lang/Object;"
       4: astore_1
       5: iconst_0
       6: istore_2
       7: iconst_0
       8: istore_3
       9: aload_1
      10: arraylength
      11: istore        4
      13: iload_3
      14: iload         4
      16: if_icmpge     108
      19: aload_1
      20: iload_3
      21: aaload
      22: astore        5
      24: aload         5
      26: checkcast     #86                 // class "[I"
      29: astore        6
      31: iconst_0
      32: istore        7
      34: aload         6
      36: astore        8
      38: iconst_0
      39: istore        9
      41: iconst_0
      42: istore        10
      44: aload         8
      46: arraylength
      47: istore        11
      49: iload         10
      51: iload         11
      53: if_icmpge     93
      56: aload         8
      58: iload         10
      60: iaload
      61: istore        12
      63: iload         12
      65: istore        13
      67: iconst_0
      68: istore        14
      70: iload         13
      72: ifne          79
      75: iconst_1
      76: goto          80
      79: iconst_0
      80: ifne          87
      83: iconst_0
      84: goto          94
      87: iinc          10, 1
      90: goto          49
      93: iconst_1
      94: nop
      95: ifne          102
      98: iconst_0
      99: goto          109
     102: iinc          3, 1
     105: goto          13
     108: iconst_1
     109: ireturn

  private static final java.lang.Integer countStepsUntilAllOctopusesSynchronize$lambda$10(int);
    Code:
       0: iload_0
       1: iconst_1
       2: iadd
       3: invokestatic  #74                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       6: areturn
}


package day10

import java.io.File
import java.util.LinkedList

// Poor man's Either -> Pair<A?, B?>
fun findMissingSequenceOrOffendingChar(line: String): Pair<Char?, String?> {
  val missingSequence = LinkedList<Char>()
  line.forEach { c ->
    when (c) {
      '(' -> missingSequence.addFirst(')')
      '[' -> missingSequence.addFirst(']')
      '{' -> missingSequence.addFirst('}')
      '<' -> missingSequence.addFirst('>')
      ')', ']', '}', '>' -> if (missingSequence.firstOrNull() == c) missingSequence.removeFirst() else return (c to null)
    }
  }
  return null to missingSequence.joinToString("")
}

private val syntaxCheckerScoreMap = mutableMapOf(
  ')' to 3,
  ']' to 57,
  '}' to 1197,
  '>' to 25137,
)

fun sumScoreOfCorruptedLines(lines: List<String>): Int =
  lines
    .map { findMissingSequenceOrOffendingChar(it).first }
    .sumOf { maybeChar -> maybeChar?.let { c -> syntaxCheckerScoreMap[c] } ?: 0 }

private val autocompleteScoreMap = mapOf(
  ')' to 1,
  ']' to 2,
  '}' to 3,
  '>' to 4,
)

fun computeMiddleScoreOfIncompleteLinesMissingChars(lines: List<String>): Long {
  fun computeScoreOfAutocomplete(sequence: String): Long =
    sequence.map { autocompleteScoreMap[it]!! }.fold(0L) { acc, score -> (acc * 5L) + score }

  val scores =
    lines
      .map { findMissingSequenceOrOffendingChar(it).second }
      .filterNot { it.isNullOrBlank() }
      .map { computeScoreOfAutocomplete(it!!) }
      .sorted()

  return scores[scores.size / 2]
}

fun main() {
  File("./input/day10.txt").useLines { lines ->
    val input = lines.toList()
    println(sumScoreOfCorruptedLines(input))
    println(computeMiddleScoreOfIncompleteLinesMissingChars(input))
  }
}

Compiled from "Day10.kt"
public final class day10.Day10Kt {
  private static final java.util.Map<java.lang.Character, java.lang.Integer> syntaxCheckerScoreMap;

  private static final java.util.Map<java.lang.Character, java.lang.Integer> autocompleteScoreMap;

  public static final kotlin.Pair<java.lang.Character, java.lang.String> findMissingSequenceOrOffendingChar(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String line
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/util/LinkedList
       9: dup
      10: invokespecial #22                 // Method java/util/LinkedList."<init>":()V
      13: astore_1
      14: aload_0
      15: checkcast     #24                 // class java/lang/CharSequence
      18: astore_2
      19: iconst_0
      20: istore_3
      21: iconst_0
      22: istore        4
      24: iload         4
      26: aload_2
      27: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      32: if_icmpge     235
      35: aload_2
      36: iload         4
      38: invokeinterface #32,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      43: istore        5
      45: iload         5
      47: istore        6
      49: iconst_0
      50: istore        7
      52: iload         6
      54: lookupswitch  { // 8
                    40: 128
                    41: 176
                    60: 164
                    62: 176
                    91: 140
                    93: 176
                   123: 152
                   125: 176
               default: 227
          }
     128: aload_1
     129: bipush        41
     131: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     134: invokevirtual #42                 // Method java/util/LinkedList.addFirst:(Ljava/lang/Object;)V
     137: goto          227
     140: aload_1
     141: bipush        93
     143: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     146: invokevirtual #42                 // Method java/util/LinkedList.addFirst:(Ljava/lang/Object;)V
     149: goto          227
     152: aload_1
     153: bipush        125
     155: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     158: invokevirtual #42                 // Method java/util/LinkedList.addFirst:(Ljava/lang/Object;)V
     161: goto          227
     164: aload_1
     165: bipush        62
     167: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     170: invokevirtual #42                 // Method java/util/LinkedList.addFirst:(Ljava/lang/Object;)V
     173: goto          227
     176: aload_1
     177: checkcast     #44                 // class java/util/List
     180: invokestatic  #50                 // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/util/List;)Ljava/lang/Object;
     183: checkcast     #34                 // class java/lang/Character
     186: iload         6
     188: istore        8
     190: dup
     191: ifnonnull     198
     194: pop
     195: goto          216
     198: invokevirtual #54                 // Method java/lang/Character.charValue:()C
     201: iload         8
     203: if_icmpne     216
     206: aload_1
     207: invokevirtual #58                 // Method java/util/LinkedList.removeFirst:()Ljava/lang/Object;
     210: checkcast     #34                 // class java/lang/Character
     213: goto          226
     216: iload         6
     218: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     221: aconst_null
     222: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     225: areturn
     226: pop
     227: nop
     228: nop
     229: iinc          4, 1
     232: goto          24
     235: nop
     236: aconst_null
     237: aload_1
     238: checkcast     #66                 // class java/lang/Iterable
     241: ldc           #68                 // String
     243: checkcast     #24                 // class java/lang/CharSequence
     246: aconst_null
     247: aconst_null
     248: iconst_0
     249: aconst_null
     250: aconst_null
     251: bipush        62
     253: aconst_null
     254: invokestatic  #72                 // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     257: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     260: areturn

  public static final int sumScoreOfCorruptedLines(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #90                 // String lines
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #66                 // class java/lang/Iterable
      10: astore_1
      11: nop
      12: iconst_0
      13: istore_2
      14: aload_1
      15: astore_3
      16: new           #92                 // class java/util/ArrayList
      19: dup
      20: aload_1
      21: bipush        10
      23: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #101                // class java/util/Collection
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload_3
      38: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      43: astore        6
      45: aload         6
      47: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      52: ifeq          101
      55: aload         6
      57: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      62: astore        7
      64: aload         4
      66: aload         7
      68: checkcast     #85                 // class java/lang/String
      71: astore        8
      73: astore        10
      75: iconst_0
      76: istore        9
      78: aload         8
      80: invokestatic  #116                // Method findMissingSequenceOrOffendingChar:(Ljava/lang/String;)Lkotlin/Pair;
      83: invokevirtual #121                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      86: checkcast     #34                 // class java/lang/Character
      89: aload         10
      91: swap
      92: invokeinterface #125,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: goto          45
     101: aload         4
     103: checkcast     #44                 // class java/util/List
     106: nop
     107: checkcast     #66                 // class java/lang/Iterable
     110: astore_1
     111: iconst_0
     112: istore_2
     113: aload_1
     114: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     119: astore_3
     120: aload_3
     121: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     126: ifeq          204
     129: aload_3
     130: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        4
     137: iload_2
     138: aload         4
     140: checkcast     #34                 // class java/lang/Character
     143: astore        5
     145: istore        10
     147: iconst_0
     148: istore        6
     150: aload         5
     152: dup
     153: ifnull        191
     156: invokevirtual #54                 // Method java/lang/Character.charValue:()C
     159: istore        7
     161: iconst_0
     162: istore        8
     164: getstatic     #129                // Field syntaxCheckerScoreMap:Ljava/util/Map;
     167: iload         7
     169: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     172: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     177: checkcast     #137                // class java/lang/Integer
     180: nop
     181: dup
     182: ifnull        191
     185: invokevirtual #140                // Method java/lang/Integer.intValue:()I
     188: goto          193
     191: pop
     192: iconst_0
     193: istore        11
     195: iload         10
     197: iload         11
     199: iadd
     200: istore_2
     201: goto          120
     204: iload_2
     205: ireturn

  public static final long computeMiddleScoreOfIncompleteLinesMissingChars(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #90                 // String lines
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #66                 // class java/lang/Iterable
      10: astore_2
      11: nop
      12: iconst_0
      13: istore_3
      14: aload_2
      15: astore        4
      17: new           #92                 // class java/util/ArrayList
      20: dup
      21: aload_2
      22: bipush        10
      24: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      27: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
      30: checkcast     #101                // class java/util/Collection
      33: astore        5
      35: iconst_0
      36: istore        6
      38: aload         4
      40: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      45: astore        7
      47: aload         7
      49: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          103
      57: aload         7
      59: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      64: astore        8
      66: aload         5
      68: aload         8
      70: checkcast     #85                 // class java/lang/String
      73: astore        9
      75: astore        12
      77: iconst_0
      78: istore        10
      80: aload         9
      82: invokestatic  #116                // Method findMissingSequenceOrOffendingChar:(Ljava/lang/String;)Lkotlin/Pair;
      85: invokevirtual #162                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      88: checkcast     #85                 // class java/lang/String
      91: aload         12
      93: swap
      94: invokeinterface #125,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      99: pop
     100: goto          47
     103: aload         5
     105: checkcast     #44                 // class java/util/List
     108: nop
     109: checkcast     #66                 // class java/lang/Iterable
     112: astore_2
     113: nop
     114: iconst_0
     115: istore_3
     116: aload_2
     117: astore        4
     119: new           #92                 // class java/util/ArrayList
     122: dup
     123: invokespecial #163                // Method java/util/ArrayList."<init>":()V
     126: checkcast     #101                // class java/util/Collection
     129: astore        5
     131: iconst_0
     132: istore        6
     134: aload         4
     136: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     141: astore        7
     143: aload         7
     145: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     150: ifeq          214
     153: aload         7
     155: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     160: astore        8
     162: aload         8
     164: checkcast     #85                 // class java/lang/String
     167: astore        9
     169: iconst_0
     170: istore        10
     172: aload         9
     174: checkcast     #24                 // class java/lang/CharSequence
     177: astore        11
     179: aload         11
     181: ifnull        192
     184: aload         11
     186: invokestatic  #169                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
     189: ifeq          196
     192: iconst_1
     193: goto          197
     196: iconst_0
     197: nop
     198: ifne          143
     201: aload         5
     203: aload         8
     205: invokeinterface #125,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     210: pop
     211: goto          143
     214: aload         5
     216: checkcast     #44                 // class java/util/List
     219: nop
     220: checkcast     #66                 // class java/lang/Iterable
     223: astore_2
     224: nop
     225: iconst_0
     226: istore_3
     227: aload_2
     228: astore        4
     230: new           #92                 // class java/util/ArrayList
     233: dup
     234: aload_2
     235: bipush        10
     237: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     240: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
     243: checkcast     #101                // class java/util/Collection
     246: astore        5
     248: iconst_0
     249: istore        6
     251: aload         4
     253: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     258: astore        7
     260: aload         7
     262: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     267: ifeq          317
     270: aload         7
     272: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     277: astore        8
     279: aload         5
     281: aload         8
     283: checkcast     #85                 // class java/lang/String
     286: astore        9
     288: astore        12
     290: iconst_0
     291: istore        10
     293: aload         9
     295: dup
     296: invokestatic  #172                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     299: invokestatic  #176                // Method computeMiddleScoreOfIncompleteLinesMissingChars$computeScoreOfAutocomplete:(Ljava/lang/String;)J
     302: invokestatic  #181                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     305: aload         12
     307: swap
     308: invokeinterface #125,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     313: pop
     314: goto          260
     317: aload         5
     319: checkcast     #44                 // class java/util/List
     322: nop
     323: checkcast     #66                 // class java/lang/Iterable
     326: invokestatic  #185                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     329: astore_1
     330: aload_1
     331: aload_1
     332: invokeinterface #188,  1          // InterfaceMethod java/util/List.size:()I
     337: iconst_2
     338: idiv
     339: invokeinterface #191,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     344: checkcast     #193                // class java/lang/Number
     347: invokevirtual #197                // Method java/lang/Number.longValue:()J
     350: lreturn

  public static final void main();
    Code:
       0: new           #211                // class java/io/File
       3: dup
       4: ldc           #213                // String ./input/day10.txt
       6: invokespecial #216                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: getstatic     #222                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_1
      14: iconst_0
      15: istore_2
      16: aload_0
      17: astore_3
      18: sipush        8192
      21: istore        4
      23: aload_3
      24: astore        5
      26: new           #224                // class java/io/InputStreamReader
      29: dup
      30: new           #226                // class java/io/FileInputStream
      33: dup
      34: aload         5
      36: invokespecial #229                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      39: checkcast     #231                // class java/io/InputStream
      42: aload_1
      43: invokespecial #234                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      46: checkcast     #236                // class java/io/Reader
      49: astore        5
      51: aload         5
      53: instanceof    #238                // class java/io/BufferedReader
      56: ifeq          67
      59: aload         5
      61: checkcast     #238                // class java/io/BufferedReader
      64: goto          78
      67: new           #238                // class java/io/BufferedReader
      70: dup
      71: aload         5
      73: iload         4
      75: invokespecial #241                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      78: checkcast     #243                // class java/io/Closeable
      81: astore_3
      82: aconst_null
      83: astore        4
      85: nop
      86: aload_3
      87: checkcast     #238                // class java/io/BufferedReader
      90: astore        5
      92: iconst_0
      93: istore        6
      95: aload         5
      97: invokestatic  #249                // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     100: astore        7
     102: iconst_0
     103: istore        8
     105: aload         7
     107: invokestatic  #255                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     110: astore        9
     112: aload         9
     114: invokestatic  #257                // Method sumScoreOfCorruptedLines:(Ljava/util/List;)I
     117: istore        10
     119: getstatic     #263                // Field java/lang/System.out:Ljava/io/PrintStream;
     122: iload         10
     124: invokevirtual #268                // Method java/io/PrintStream.println:(I)V
     127: aload         9
     129: invokestatic  #270                // Method computeMiddleScoreOfIncompleteLinesMissingChars:(Ljava/util/List;)J
     132: lstore        11
     134: getstatic     #263                // Field java/lang/System.out:Ljava/io/PrintStream;
     137: lload         11
     139: invokevirtual #273                // Method java/io/PrintStream.println:(J)V
     142: nop
     143: getstatic     #279                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     146: astore        5
     148: aload_3
     149: aload         4
     151: invokestatic  #285                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     154: goto          177
     157: astore        6
     159: aload         6
     161: astore        4
     163: aload         6
     165: athrow
     166: astore        6
     168: aload_3
     169: aload         4
     171: invokestatic  #285                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     174: aload         6
     176: athrow
     177: nop
     178: return
    Exception table:
       from    to  target type
          85   148   157   Class java/lang/Throwable
          85   148   166   any
         157   166   166   any
         166   168   166   any

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

  private static final long computeMiddleScoreOfIncompleteLinesMissingChars$computeScoreOfAutocomplete(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #24                 // class java/lang/CharSequence
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore        4
      10: new           #92                 // class java/util/ArrayList
      13: dup
      14: aload_1
      15: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      20: invokespecial #99                 // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #101                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        7
      31: iconst_0
      32: istore        8
      34: iload         8
      36: aload         4
      38: invokeinterface #28,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      43: if_icmpge     109
      46: aload         4
      48: iload         8
      50: invokeinterface #32,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      55: istore        9
      57: aload         5
      59: iload         9
      61: istore        10
      63: astore        13
      65: iconst_0
      66: istore        11
      68: getstatic     #307                // Field autocompleteScoreMap:Ljava/util/Map;
      71: iload         10
      73: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      76: invokeinterface #135,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      81: dup
      82: invokestatic  #172                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      85: checkcast     #193                // class java/lang/Number
      88: invokevirtual #308                // Method java/lang/Number.intValue:()I
      91: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      94: aload         13
      96: swap
      97: invokeinterface #125,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     102: pop
     103: iinc          8, 1
     106: goto          34
     109: aload         5
     111: checkcast     #44                 // class java/util/List
     114: nop
     115: checkcast     #66                 // class java/lang/Iterable
     118: astore_1
     119: lconst_0
     120: lstore_2
     121: iconst_0
     122: istore        4
     124: lload_2
     125: lstore        5
     127: aload_1
     128: invokeinterface #105,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        7
     135: aload         7
     137: invokeinterface #111,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          186
     145: aload         7
     147: invokeinterface #114,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        8
     154: lload         5
     156: aload         8
     158: checkcast     #193                // class java/lang/Number
     161: invokevirtual #308                // Method java/lang/Number.intValue:()I
     164: istore        9
     166: lstore        10
     168: iconst_0
     169: istore        12
     171: lload         10
     173: ldc2_w        #312                // long 5l
     176: lmul
     177: iload         9
     179: i2l
     180: ladd
     181: lstore        5
     183: goto          135
     186: lload         5
     188: lreturn

  static {};
    Code:
       0: iconst_4
       1: anewarray     #118                // class kotlin/Pair
       4: astore_0
       5: aload_0
       6: iconst_0
       7: bipush        41
       9: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      12: iconst_3
      13: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      16: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      19: aastore
      20: aload_0
      21: iconst_1
      22: bipush        93
      24: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      27: bipush        57
      29: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      35: aastore
      36: aload_0
      37: iconst_2
      38: bipush        125
      40: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      43: sipush        1197
      46: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      49: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      52: aastore
      53: aload_0
      54: iconst_3
      55: bipush        62
      57: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      60: sipush        25137
      63: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      69: aastore
      70: aload_0
      71: invokestatic  #330                // Method kotlin/collections/MapsKt.mutableMapOf:([Lkotlin/Pair;)Ljava/util/Map;
      74: putstatic     #129                // Field syntaxCheckerScoreMap:Ljava/util/Map;
      77: iconst_4
      78: anewarray     #118                // class kotlin/Pair
      81: astore_0
      82: aload_0
      83: iconst_0
      84: bipush        41
      86: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
      89: iconst_1
      90: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      96: aastore
      97: aload_0
      98: iconst_1
      99: bipush        93
     101: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     104: iconst_2
     105: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     111: aastore
     112: aload_0
     113: iconst_2
     114: bipush        125
     116: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     119: iconst_3
     120: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     123: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     126: aastore
     127: aload_0
     128: iconst_3
     129: bipush        62
     131: invokestatic  #38                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     134: iconst_4
     135: invokestatic  #311                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: invokestatic  #64                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     141: aastore
     142: aload_0
     143: invokestatic  #333                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     146: putstatic     #307                // Field autocompleteScoreMap:Ljava/util/Map;
     149: return
}