package day24

import java.io.File
import java.util.*

fun main() {
    val valley = Valley.parse(File("src/day24/input.txt").readLines())
    val there = solve(valley, Valley.START, valley.finish)
    println(there.first)
    val back = solve(there.second, valley.finish, Valley.START)
    val thereAgain = solve(back.second, Valley.START, valley.finish)
    println(there.first + back.first + thereAgain.first)
}

fun solve(valley: Valley, from: Pair<Int, Int>, to: Pair<Int, Int>): Pair<Int, Valley> {
    val maps = mutableListOf(valley)
    val visited = mutableSetOf<Pair<Int, Pair<Int, Int>>>()
    val queue = PriorityQueue<Pair<Int, Pair<Int, Int>>>(
        compareBy {
            it.first + (to.first - it.second.first) + (to.second - it.second.second)
        }
    )
    queue.add(Pair(0, from))
    while (queue.isNotEmpty()) {
        val pair = queue.poll()
        if (pair in visited) continue
        visited.add(pair)
        val (minute, location) = pair
        if (location == to) {
            return Pair(minute, maps[minute])
        }
        val nextMinute = minute + 1
        if (maps.size == nextMinute) {
            maps.add(maps.last().next())
        }
        val map = maps[nextMinute]
        queue.addAll(map.options(location).map { Pair(minute + 1, it) })
    }

    throw IllegalStateException("End never reached")
}

data class Valley(val width: Int, val height: Int, val blizzardsAndWalls: Map<Pair<Int, Int>, List<Char>>) {
    val finish = Pair(width - 2, height - 1)
    companion object {
        val START = Pair(1, 0)
        fun parse(lines: List<String>): Valley {
            val blizzardWalls = lines.mapIndexed { row, line ->
                line.mapIndexed { column, char ->
                    Pair(column, row) to listOf(char)
                }.filter { '.' !in it.second }.toMap()
            }.reduce { a, b -> a + b }
            return Valley(lines.first().length, lines.size, blizzardWalls)
        }
    }

    fun print(location: Pair<Int, Int>): String {
        val buffer = StringBuffer()
        for (row in (0 until height)) {
            for (column in (0 until width)) {
                val c = Pair(column, row)
                if (c == location) {
                    buffer.append("E")
                } else {
                    val b = blizzardsAndWalls[c] ?: emptyList()
                    buffer.append(if (b.isEmpty()) '.' else if (b.size == 1) b.first() else b.size)
                }
            }
            buffer.appendLine()
        }
        return buffer.toString()
    }

    fun next(): Valley {
        return Valley(width, height, blizzardsAndWalls.map { (c, l) -> l.map { d -> Pair(c, d) } }.flatten().map {
                p -> Pair(when (p.second) {
            '^' -> Pair(p.first.first, if (p.first.second == 1) (height - 2) else (p.first.second - 1))
            '>' -> Pair(if (p.first.first == width - 2) 1 else (p.first.first + 1), p.first.second)
            'v' -> Pair(p.first.first, if (p.first.second == height - 2) 1 else (p.first.second + 1))
            '<' -> Pair(if (p.first.first == 1) (width - 2) else (p.first.first - 1), p.first.second)
            '#' -> p.first
            else -> throw IllegalStateException("Unknown direction ${p.second}")
        }, p.second)
        }.fold(mutableMapOf()) { m, p -> m[p.first] = (m[p.first] ?: emptyList()) + p.second; m })
    }

    fun options(location: Pair<Int, Int>): List<Pair<Int, Int>> {
        val deltas = listOf(Pair(0, 0), Pair(0, -1), Pair(1, 0), Pair(0, 1), Pair(-1, 0))
        return deltas.map { d -> Pair(location.first + d.first, location.second + d.second) }
            .filter { c -> (c.first > 0 && c.first < width - 1 && c.second > 0 && c.second < height - 1) || c == finish || c == START }
            .filterNot { c -> c in blizzardsAndWalls }
    }
}

Compiled from "Comparisons.kt"
public final class day24.Day24Kt$solve$$inlined$compareBy$1<T> implements java.util.Comparator {
  final kotlin.Pair $to$inlined;

  public day24.Day24Kt$solve$$inlined$compareBy$1(kotlin.Pair);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #18                 // Field $to$inlined:Lkotlin/Pair;
       5: aload_0
       6: invokespecial #21                 // Method java/lang/Object."<init>":()V
       9: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #28                 // class kotlin/Pair
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      12: checkcast     #34                 // class java/lang/Number
      15: invokevirtual #38                 // Method java/lang/Number.intValue:()I
      18: aload_0
      19: getfield      #18                 // Field $to$inlined:Lkotlin/Pair;
      22: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      25: checkcast     #34                 // class java/lang/Number
      28: invokevirtual #38                 // Method java/lang/Number.intValue:()I
      31: aload_3
      32: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      35: checkcast     #28                 // class kotlin/Pair
      38: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      41: checkcast     #34                 // class java/lang/Number
      44: invokevirtual #38                 // Method java/lang/Number.intValue:()I
      47: isub
      48: iadd
      49: aload_0
      50: getfield      #18                 // Field $to$inlined:Lkotlin/Pair;
      53: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      56: checkcast     #34                 // class java/lang/Number
      59: invokevirtual #38                 // Method java/lang/Number.intValue:()I
      62: aload_3
      63: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      66: checkcast     #28                 // class kotlin/Pair
      69: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      72: checkcast     #34                 // class java/lang/Number
      75: invokevirtual #38                 // Method java/lang/Number.intValue:()I
      78: isub
      79: iadd
      80: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      83: checkcast     #49                 // class java/lang/Comparable
      86: aload_2
      87: checkcast     #28                 // class kotlin/Pair
      90: astore_3
      91: astore        5
      93: iconst_0
      94: istore        4
      96: aload_3
      97: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     100: checkcast     #34                 // class java/lang/Number
     103: invokevirtual #38                 // Method java/lang/Number.intValue:()I
     106: aload_0
     107: getfield      #18                 // Field $to$inlined:Lkotlin/Pair;
     110: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     113: checkcast     #34                 // class java/lang/Number
     116: invokevirtual #38                 // Method java/lang/Number.intValue:()I
     119: aload_3
     120: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     123: checkcast     #28                 // class kotlin/Pair
     126: invokevirtual #32                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     129: checkcast     #34                 // class java/lang/Number
     132: invokevirtual #38                 // Method java/lang/Number.intValue:()I
     135: isub
     136: iadd
     137: aload_0
     138: getfield      #18                 // Field $to$inlined:Lkotlin/Pair;
     141: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     144: checkcast     #34                 // class java/lang/Number
     147: invokevirtual #38                 // Method java/lang/Number.intValue:()I
     150: aload_3
     151: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     154: checkcast     #28                 // class kotlin/Pair
     157: invokevirtual #41                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     160: checkcast     #34                 // class java/lang/Number
     163: invokevirtual #38                 // Method java/lang/Number.intValue:()I
     166: isub
     167: iadd
     168: invokestatic  #47                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     171: checkcast     #49                 // class java/lang/Comparable
     174: aload         5
     176: swap
     177: invokestatic  #55                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
     180: ireturn
}

Compiled from "Day24.kt"
public final class day24.Day24Kt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field day24/Valley.Companion:Lday24/Valley$Companion;
       3: new           #14                 // class java/io/File
       6: dup
       7: ldc           #16                 // String src/day24/input.txt
       9: invokespecial #20                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      12: aconst_null
      13: iconst_1
      14: aconst_null
      15: invokestatic  #26                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      18: invokevirtual #32                 // Method day24/Valley$Companion.parse:(Ljava/util/List;)Lday24/Valley;
      21: astore_0
      22: aload_0
      23: getstatic     #12                 // Field day24/Valley.Companion:Lday24/Valley$Companion;
      26: invokevirtual #36                 // Method day24/Valley$Companion.getSTART:()Lkotlin/Pair;
      29: aload_0
      30: invokevirtual #39                 // Method day24/Valley.getFinish:()Lkotlin/Pair;
      33: invokestatic  #43                 // Method solve:(Lday24/Valley;Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
      36: astore_1
      37: aload_1
      38: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      41: checkcast     #51                 // class java/lang/Number
      44: invokevirtual #55                 // Method java/lang/Number.intValue:()I
      47: istore_2
      48: getstatic     #61                 // Field java/lang/System.out:Ljava/io/PrintStream;
      51: iload_2
      52: invokevirtual #67                 // Method java/io/PrintStream.println:(I)V
      55: aload_1
      56: invokevirtual #70                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      59: checkcast     #8                  // class day24/Valley
      62: aload_0
      63: invokevirtual #39                 // Method day24/Valley.getFinish:()Lkotlin/Pair;
      66: getstatic     #12                 // Field day24/Valley.Companion:Lday24/Valley$Companion;
      69: invokevirtual #36                 // Method day24/Valley$Companion.getSTART:()Lkotlin/Pair;
      72: invokestatic  #43                 // Method solve:(Lday24/Valley;Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
      75: astore_2
      76: aload_2
      77: invokevirtual #70                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      80: checkcast     #8                  // class day24/Valley
      83: getstatic     #12                 // Field day24/Valley.Companion:Lday24/Valley$Companion;
      86: invokevirtual #36                 // Method day24/Valley$Companion.getSTART:()Lkotlin/Pair;
      89: aload_0
      90: invokevirtual #39                 // Method day24/Valley.getFinish:()Lkotlin/Pair;
      93: invokestatic  #43                 // Method solve:(Lday24/Valley;Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
      96: astore_3
      97: aload_1
      98: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     101: checkcast     #51                 // class java/lang/Number
     104: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     107: aload_2
     108: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     111: checkcast     #51                 // class java/lang/Number
     114: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     117: iadd
     118: aload_3
     119: invokevirtual #49                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     122: checkcast     #51                 // class java/lang/Number
     125: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     128: iadd
     129: istore        4
     131: getstatic     #61                 // Field java/lang/System.out:Ljava/io/PrintStream;
     134: iload         4
     136: invokevirtual #67                 // Method java/io/PrintStream.println:(I)V
     139: return

  public static final kotlin.Pair<java.lang.Integer, day24.Valley> solve(day24.Valley, kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #79                 // String valley
       3: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #87                 // String from
       9: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_2
      13: ldc           #89                 // String to
      15: invokestatic  #85                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      18: iconst_1
      19: anewarray     #8                  // class day24/Valley
      22: astore        4
      24: aload         4
      26: iconst_0
      27: aload_0
      28: aastore
      29: aload         4
      31: invokestatic  #95                 // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
      34: astore_3
      35: new           #97                 // class java/util/LinkedHashSet
      38: dup
      39: invokespecial #99                 // Method java/util/LinkedHashSet."<init>":()V
      42: checkcast     #101                // class java/util/Set
      45: astore        4
      47: new           #103                // class java/util/PriorityQueue
      50: dup
      51: new           #105                // class day24/Day24Kt$solve$$inlined$compareBy$1
      54: dup
      55: aload_2
      56: invokespecial #108                // Method day24/Day24Kt$solve$$inlined$compareBy$1."<init>":(Lkotlin/Pair;)V
      59: checkcast     #110                // class java/util/Comparator
      62: invokespecial #113                // Method java/util/PriorityQueue."<init>":(Ljava/util/Comparator;)V
      65: astore        5
      67: aload         5
      69: new           #45                 // class kotlin/Pair
      72: dup
      73: iconst_0
      74: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: aload_1
      78: invokespecial #122                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      81: invokevirtual #126                // Method java/util/PriorityQueue.add:(Ljava/lang/Object;)Z
      84: pop
      85: aload         5
      87: checkcast     #128                // class java/util/Collection
      90: invokeinterface #132,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      95: ifne          102
      98: iconst_1
      99: goto          103
     102: iconst_0
     103: ifeq          377
     106: aload         5
     108: invokevirtual #135                // Method java/util/PriorityQueue.poll:()Ljava/lang/Object;
     111: checkcast     #45                 // class kotlin/Pair
     114: astore        6
     116: aload         4
     118: aload         6
     120: invokeinterface #138,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     125: ifne          85
     128: aload         4
     130: aload         6
     132: invokestatic  #142                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     135: aload         6
     137: invokeinterface #143,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     142: pop
     143: aload         6
     145: invokevirtual #146                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     148: checkcast     #51                 // class java/lang/Number
     151: invokevirtual #55                 // Method java/lang/Number.intValue:()I
     154: istore        7
     156: aload         6
     158: invokevirtual #149                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     161: checkcast     #45                 // class kotlin/Pair
     164: astore        8
     166: aload         8
     168: aload_2
     169: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     172: ifeq          196
     175: new           #45                 // class kotlin/Pair
     178: dup
     179: iload         7
     181: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: aload_3
     185: iload         7
     187: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     192: invokespecial #122                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     195: areturn
     196: iload         7
     198: iconst_1
     199: iadd
     200: istore        9
     202: aload_3
     203: invokeinterface #162,  1          // InterfaceMethod java/util/List.size:()I
     208: iload         9
     210: if_icmpne     230
     213: aload_3
     214: aload_3
     215: invokestatic  #166                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     218: checkcast     #8                  // class day24/Valley
     221: invokevirtual #170                // Method day24/Valley.next:()Lday24/Valley;
     224: invokeinterface #171,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     229: pop
     230: aload_3
     231: iload         9
     233: invokeinterface #159,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     238: checkcast     #8                  // class day24/Valley
     241: astore        10
     243: aload         5
     245: aload         10
     247: aload         8
     249: invokevirtual #175                // Method day24/Valley.options:(Lkotlin/Pair;)Ljava/util/List;
     252: checkcast     #177                // class java/lang/Iterable
     255: astore        11
     257: astore        20
     259: iconst_0
     260: istore        12
     262: aload         11
     264: astore        13
     266: new           #179                // class java/util/ArrayList
     269: dup
     270: aload         11
     272: bipush        10
     274: invokestatic  #183                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     277: invokespecial #185                // Method java/util/ArrayList."<init>":(I)V
     280: checkcast     #128                // class java/util/Collection
     283: astore        14
     285: iconst_0
     286: istore        15
     288: aload         13
     290: invokeinterface #189,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     295: astore        16
     297: aload         16
     299: invokeinterface #194,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     304: ifeq          358
     307: aload         16
     309: invokeinterface #196,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     314: astore        17
     316: aload         14
     318: aload         17
     320: checkcast     #45                 // class kotlin/Pair
     323: astore        18
     325: astore        21
     327: iconst_0
     328: istore        19
     330: new           #45                 // class kotlin/Pair
     333: dup
     334: iload         7
     336: iconst_1
     337: iadd
     338: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     341: aload         18
     343: invokespecial #122                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     346: aload         21
     348: swap
     349: invokeinterface #197,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     354: pop
     355: goto          297
     358: aload         14
     360: checkcast     #155                // class java/util/List
     363: nop
     364: aload         20
     366: swap
     367: checkcast     #128                // class java/util/Collection
     370: invokevirtual #201                // Method java/util/PriorityQueue.addAll:(Ljava/util/Collection;)Z
     373: pop
     374: goto          85
     377: new           #203                // class java/lang/IllegalStateException
     380: dup
     381: ldc           #205                // String End never reached
     383: invokespecial #206                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     386: athrow

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


package day12

import java.io.File

fun main() {
    val grid = File("src/day12/input.txt").readLines().mapIndexed {
        y, line -> line.mapIndexed {
            x, c -> Pair(x, y) to c
        }
    }.flatten().toMap()

    val start = grid.filter { it.value == 'S' }.map { it.key }.first()
    val end = grid.filter { it.value == 'E' }.map { it.key }.first()
    val lowest = grid.filter { height(it.value) == 0 }.map { it.key }.toSet()

    println(solve(start, setOf(end), grid) { last, next -> next <= last + 1 })
    println(solve(end, lowest, grid) { last, next -> next >= last - 1 })
}

private fun solve(
    start: Pair<Int, Int>,
    end: Set<Pair<Int, Int>>,
    grid: Map<Pair<Int, Int>, Char>,
    validTransition: (Int, Int) -> Boolean
): Int {
    val directions = listOf(Pair(-1, 0), Pair(1, 0), Pair(0, -1), Pair(0, 1))

    val visited = mutableSetOf<Pair<Int, Int>>()
    val stack = mutableListOf(listOf(start))
    while (stack.isNotEmpty()) {
        val path = stack.removeAt(0)
        if (path.last() in end) {
            return (path.size - 1)
        }
        if (path.last() in visited) {
            continue
        }
        visited.add(path.last())
        val options = directions
            .asSequence()
            .map { direction -> Pair(path.last().first + direction.first, path.last().second + direction.second) }
            .filter { next -> next in grid.keys }
            .filter { next -> validTransition(height(grid[path.last()]!!), height(grid[next]!!)) }
            .map { next -> path + next }
            .toList()
        stack.addAll(options)
    }

    throw IllegalStateException("No solution")
}

fun height(c: Char): Int {
    return when (c) {
        'S' -> 0
        'E' -> 25
        else -> c - 'a'
    }
}

Compiled from "Day12.kt"
public final class day12.Day12Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/day12/input.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #22                 // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #24                 // class java/util/ArrayList
      26: dup
      27: aload_1
      28: bipush        10
      30: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      33: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
      36: checkcast     #35                 // class java/util/Collection
      39: astore        4
      41: iconst_0
      42: istore        5
      44: iconst_0
      45: istore        6
      47: aload_3
      48: invokeinterface #39,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      53: astore        7
      55: aload         7
      57: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          249
      65: aload         7
      67: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      72: astore        8
      74: aload         4
      76: iload         6
      78: iinc          6, 1
      81: istore        9
      83: iload         9
      85: ifge          91
      88: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
      91: iload         9
      93: aload         8
      95: checkcast     #54                 // class java/lang/String
      98: astore        10
     100: istore        11
     102: astore        25
     104: iconst_0
     105: istore        12
     107: aload         10
     109: checkcast     #56                 // class java/lang/CharSequence
     112: astore        13
     114: iconst_0
     115: istore        14
     117: aload         13
     119: astore        15
     121: new           #24                 // class java/util/ArrayList
     124: dup
     125: aload         13
     127: invokeinterface #60,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     132: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     135: checkcast     #35                 // class java/util/Collection
     138: astore        16
     140: iconst_0
     141: istore        17
     143: iconst_0
     144: istore        18
     146: iconst_0
     147: istore        19
     149: iload         19
     151: aload         15
     153: invokeinterface #60,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     158: if_icmpge     230
     161: aload         15
     163: iload         19
     165: invokeinterface #64,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     170: istore        20
     172: aload         16
     174: iload         18
     176: iinc          18, 1
     179: iload         20
     181: istore        21
     183: istore        22
     185: astore        23
     187: iconst_0
     188: istore        24
     190: new           #66                 // class kotlin/Pair
     193: dup
     194: iload         22
     196: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     199: iload         11
     201: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     204: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     207: iload         21
     209: invokestatic  #80                 // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     212: invokestatic  #86                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     215: aload         23
     217: swap
     218: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     223: pop
     224: iinc          19, 1
     227: goto          149
     230: aload         16
     232: checkcast     #92                 // class java/util/List
     235: nop
     236: nop
     237: aload         25
     239: swap
     240: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     245: pop
     246: goto          55
     249: aload         4
     251: checkcast     #92                 // class java/util/List
     254: nop
     255: checkcast     #22                 // class java/lang/Iterable
     258: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     261: checkcast     #22                 // class java/lang/Iterable
     264: invokestatic  #102                // Method kotlin/collections/MapsKt.toMap:(Ljava/lang/Iterable;)Ljava/util/Map;
     267: astore_0
     268: aload_0
     269: astore_2
     270: iconst_0
     271: istore_3
     272: aload_2
     273: astore        4
     275: new           #104                // class java/util/LinkedHashMap
     278: dup
     279: invokespecial #106                // Method java/util/LinkedHashMap."<init>":()V
     282: checkcast     #108                // class java/util/Map
     285: astore        5
     287: iconst_0
     288: istore        6
     290: aload         4
     292: invokeinterface #112,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     297: invokeinterface #115,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     302: astore        7
     304: aload         7
     306: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     311: ifeq          384
     314: aload         7
     316: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     321: checkcast     #117                // class java/util/Map$Entry
     324: astore        8
     326: aload         8
     328: astore        9
     330: iconst_0
     331: istore        10
     333: aload         9
     335: invokeinterface #120,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     340: checkcast     #77                 // class java/lang/Character
     343: invokevirtual #124                // Method java/lang/Character.charValue:()C
     346: bipush        83
     348: if_icmpne     355
     351: iconst_1
     352: goto          356
     355: iconst_0
     356: ifeq          304
     359: aload         5
     361: aload         8
     363: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     368: aload         8
     370: invokeinterface #120,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     375: invokeinterface #131,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     380: pop
     381: goto          304
     384: aload         5
     386: nop
     387: astore_2
     388: nop
     389: iconst_0
     390: istore_3
     391: aload_2
     392: astore        4
     394: new           #24                 // class java/util/ArrayList
     397: dup
     398: aload_2
     399: invokeinterface #134,  1          // InterfaceMethod java/util/Map.size:()I
     404: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     407: checkcast     #35                 // class java/util/Collection
     410: astore        5
     412: iconst_0
     413: istore        6
     415: aload         4
     417: invokeinterface #112,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     422: invokeinterface #115,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     427: astore        7
     429: aload         7
     431: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     436: ifeq          484
     439: aload         7
     441: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     446: checkcast     #117                // class java/util/Map$Entry
     449: astore        8
     451: aload         5
     453: aload         8
     455: astore        9
     457: astore        25
     459: iconst_0
     460: istore        10
     462: aload         9
     464: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     469: checkcast     #66                 // class kotlin/Pair
     472: aload         25
     474: swap
     475: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     480: pop
     481: goto          429
     484: aload         5
     486: checkcast     #92                 // class java/util/List
     489: nop
     490: invokestatic  #138                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     493: checkcast     #66                 // class kotlin/Pair
     496: astore_1
     497: aload_0
     498: astore_3
     499: iconst_0
     500: istore        4
     502: aload_3
     503: astore        5
     505: new           #104                // class java/util/LinkedHashMap
     508: dup
     509: invokespecial #106                // Method java/util/LinkedHashMap."<init>":()V
     512: checkcast     #108                // class java/util/Map
     515: astore        6
     517: iconst_0
     518: istore        7
     520: aload         5
     522: invokeinterface #112,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     527: invokeinterface #115,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     532: astore        8
     534: aload         8
     536: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     541: ifeq          614
     544: aload         8
     546: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     551: checkcast     #117                // class java/util/Map$Entry
     554: astore        9
     556: aload         9
     558: astore        10
     560: iconst_0
     561: istore        11
     563: aload         10
     565: invokeinterface #120,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     570: checkcast     #77                 // class java/lang/Character
     573: invokevirtual #124                // Method java/lang/Character.charValue:()C
     576: bipush        69
     578: if_icmpne     585
     581: iconst_1
     582: goto          586
     585: iconst_0
     586: ifeq          534
     589: aload         6
     591: aload         9
     593: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     598: aload         9
     600: invokeinterface #120,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     605: invokeinterface #131,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     610: pop
     611: goto          534
     614: aload         6
     616: nop
     617: astore_3
     618: nop
     619: iconst_0
     620: istore        4
     622: aload_3
     623: astore        5
     625: new           #24                 // class java/util/ArrayList
     628: dup
     629: aload_3
     630: invokeinterface #134,  1          // InterfaceMethod java/util/Map.size:()I
     635: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     638: checkcast     #35                 // class java/util/Collection
     641: astore        6
     643: iconst_0
     644: istore        7
     646: aload         5
     648: invokeinterface #112,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     653: invokeinterface #115,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     658: astore        8
     660: aload         8
     662: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     667: ifeq          715
     670: aload         8
     672: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     677: checkcast     #117                // class java/util/Map$Entry
     680: astore        9
     682: aload         6
     684: aload         9
     686: astore        10
     688: astore        25
     690: iconst_0
     691: istore        11
     693: aload         10
     695: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     700: checkcast     #66                 // class kotlin/Pair
     703: aload         25
     705: swap
     706: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     711: pop
     712: goto          660
     715: aload         6
     717: checkcast     #92                 // class java/util/List
     720: nop
     721: invokestatic  #138                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     724: checkcast     #66                 // class kotlin/Pair
     727: astore_2
     728: aload_0
     729: astore        4
     731: iconst_0
     732: istore        5
     734: aload         4
     736: astore        6
     738: new           #104                // class java/util/LinkedHashMap
     741: dup
     742: invokespecial #106                // Method java/util/LinkedHashMap."<init>":()V
     745: checkcast     #108                // class java/util/Map
     748: astore        7
     750: iconst_0
     751: istore        8
     753: aload         6
     755: invokeinterface #112,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     760: invokeinterface #115,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     765: astore        9
     767: aload         9
     769: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     774: ifeq          848
     777: aload         9
     779: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     784: checkcast     #117                // class java/util/Map$Entry
     787: astore        10
     789: aload         10
     791: astore        11
     793: iconst_0
     794: istore        12
     796: aload         11
     798: invokeinterface #120,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     803: checkcast     #77                 // class java/lang/Character
     806: invokevirtual #124                // Method java/lang/Character.charValue:()C
     809: invokestatic  #142                // Method height:(C)I
     812: ifne          819
     815: iconst_1
     816: goto          820
     819: iconst_0
     820: ifeq          767
     823: aload         7
     825: aload         10
     827: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     832: aload         10
     834: invokeinterface #120,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     839: invokeinterface #131,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     844: pop
     845: goto          767
     848: aload         7
     850: nop
     851: astore        4
     853: nop
     854: iconst_0
     855: istore        5
     857: aload         4
     859: astore        6
     861: new           #24                 // class java/util/ArrayList
     864: dup
     865: aload         4
     867: invokeinterface #134,  1          // InterfaceMethod java/util/Map.size:()I
     872: invokespecial #33                 // Method java/util/ArrayList."<init>":(I)V
     875: checkcast     #35                 // class java/util/Collection
     878: astore        7
     880: iconst_0
     881: istore        8
     883: aload         6
     885: invokeinterface #112,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     890: invokeinterface #115,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     895: astore        9
     897: aload         9
     899: invokeinterface #45,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     904: ifeq          952
     907: aload         9
     909: invokeinterface #49,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     914: checkcast     #117                // class java/util/Map$Entry
     917: astore        10
     919: aload         7
     921: aload         10
     923: astore        11
     925: astore        25
     927: iconst_0
     928: istore        12
     930: aload         11
     932: invokeinterface #127,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     937: checkcast     #66                 // class kotlin/Pair
     940: aload         25
     942: swap
     943: invokeinterface #90,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     948: pop
     949: goto          897
     952: aload         7
     954: checkcast     #92                 // class java/util/List
     957: nop
     958: checkcast     #22                 // class java/lang/Iterable
     961: invokestatic  #146                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     964: astore_3
     965: aload_1
     966: aload_2
     967: invokestatic  #152                // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
     970: aload_0
     971: invokedynamic #171,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
     976: invokestatic  #175                // Method solve:(Lkotlin/Pair;Ljava/util/Set;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)I
     979: istore        4
     981: getstatic     #181                // Field java/lang/System.out:Ljava/io/PrintStream;
     984: iload         4
     986: invokevirtual #186                // Method java/io/PrintStream.println:(I)V
     989: aload_2
     990: aload_3
     991: aload_0
     992: invokedynamic #191,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function2;
     997: invokestatic  #175                // Method solve:(Lkotlin/Pair;Ljava/util/Set;Ljava/util/Map;Lkotlin/jvm/functions/Function2;)I
    1000: istore        4
    1002: getstatic     #181                // Field java/lang/System.out:Ljava/io/PrintStream;
    1005: iload         4
    1007: invokevirtual #186                // Method java/io/PrintStream.println:(I)V
    1010: return

  private static final int solve(kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>, java.util.Map<kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Character>, kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Integer, java.lang.Boolean>);
    Code:
       0: iconst_4
       1: anewarray     #66                 // class kotlin/Pair
       4: astore        5
       6: aload         5
       8: iconst_0
       9: new           #66                 // class kotlin/Pair
      12: dup
      13: iconst_m1
      14: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      17: iconst_0
      18: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      21: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      24: aastore
      25: aload         5
      27: iconst_1
      28: new           #66                 // class kotlin/Pair
      31: dup
      32: iconst_1
      33: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: iconst_0
      37: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      40: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      43: aastore
      44: aload         5
      46: iconst_2
      47: new           #66                 // class kotlin/Pair
      50: dup
      51: iconst_0
      52: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: iconst_m1
      56: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      59: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      62: aastore
      63: aload         5
      65: iconst_3
      66: new           #66                 // class kotlin/Pair
      69: dup
      70: iconst_0
      71: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      74: iconst_1
      75: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      81: aastore
      82: aload         5
      84: invokestatic  #240                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      87: astore        4
      89: new           #242                // class java/util/LinkedHashSet
      92: dup
      93: invokespecial #243                // Method java/util/LinkedHashSet."<init>":()V
      96: checkcast     #114                // class java/util/Set
      99: astore        5
     101: iconst_1
     102: anewarray     #92                 // class java/util/List
     105: astore        7
     107: aload         7
     109: iconst_0
     110: aload_0
     111: invokestatic  #246                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
     114: aastore
     115: aload         7
     117: invokestatic  #249                // Method kotlin/collections/CollectionsKt.mutableListOf:([Ljava/lang/Object;)Ljava/util/List;
     120: astore        6
     122: aload         6
     124: checkcast     #35                 // class java/util/Collection
     127: invokeinterface #252,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     132: ifne          139
     135: iconst_1
     136: goto          140
     139: iconst_0
     140: ifeq          281
     143: aload         6
     145: iconst_0
     146: invokeinterface #256,  2          // InterfaceMethod java/util/List.remove:(I)Ljava/lang/Object;
     151: checkcast     #92                 // class java/util/List
     154: astore        7
     156: aload_1
     157: aload         7
     159: invokestatic  #259                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     162: invokeinterface #262,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     167: ifeq          180
     170: aload         7
     172: invokeinterface #263,  1          // InterfaceMethod java/util/List.size:()I
     177: iconst_1
     178: isub
     179: ireturn
     180: aload         5
     182: aload         7
     184: invokestatic  #259                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     187: invokeinterface #262,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     192: ifeq          198
     195: goto          122
     198: aload         5
     200: aload         7
     202: invokestatic  #259                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     205: invokeinterface #264,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     210: pop
     211: aload         4
     213: checkcast     #22                 // class java/lang/Iterable
     216: invokestatic  #268                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     219: aload         7
     221: invokedynamic #280,  0            // InvokeDynamic #2:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     226: invokestatic  #286                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     229: aload_2
     230: invokedynamic #296,  0            // InvokeDynamic #3:invoke:(Ljava/util/Map;)Lkotlin/jvm/functions/Function1;
     235: invokestatic  #299                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     238: aload_3
     239: aload_2
     240: aload         7
     242: invokedynamic #307,  0            // InvokeDynamic #4:invoke:(Lkotlin/jvm/functions/Function2;Ljava/util/Map;Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     247: invokestatic  #299                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     250: aload         7
     252: invokedynamic #315,  0            // InvokeDynamic #5:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     257: invokestatic  #286                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     260: invokestatic  #319                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     263: astore        8
     265: aload         6
     267: aload         8
     269: checkcast     #35                 // class java/util/Collection
     272: invokeinterface #323,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     277: pop
     278: goto          122
     281: new           #325                // class java/lang/IllegalStateException
     284: dup
     285: ldc_w         #327                // String No solution
     288: invokespecial #328                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     291: athrow

  public static final int height(char);
    Code:
       0: iload_0
       1: lookupswitch  { // 2
                    69: 32
                    83: 28
               default: 37
          }
      28: iconst_0
      29: goto          41
      32: bipush        25
      34: goto          41
      37: iload_0
      38: bipush        97
      40: isub
      41: ireturn

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

  private static final boolean main$lambda$8(int, int);
    Code:
       0: iload_1
       1: iload_0
       2: iconst_1
       3: iadd
       4: if_icmpgt     11
       7: iconst_1
       8: goto          12
      11: iconst_0
      12: ireturn

  private static final boolean main$lambda$9(int, int);
    Code:
       0: iload_1
       1: iload_0
       2: iconst_1
       3: isub
       4: if_icmplt     11
       7: iconst_1
       8: goto          12
      11: iconst_0
      12: ireturn

  private static final kotlin.Pair solve$lambda$10(java.util.List, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #345                // String direction
       4: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #66                 // class kotlin/Pair
      10: dup
      11: aload_0
      12: invokestatic  #259                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      15: checkcast     #66                 // class kotlin/Pair
      18: invokevirtual #354                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      21: checkcast     #356                // class java/lang/Number
      24: invokevirtual #359                // Method java/lang/Number.intValue:()I
      27: aload_1
      28: invokevirtual #354                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      31: checkcast     #356                // class java/lang/Number
      34: invokevirtual #359                // Method java/lang/Number.intValue:()I
      37: iadd
      38: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: aload_0
      42: invokestatic  #259                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      45: checkcast     #66                 // class kotlin/Pair
      48: invokevirtual #362                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      51: checkcast     #356                // class java/lang/Number
      54: invokevirtual #359                // Method java/lang/Number.intValue:()I
      57: aload_1
      58: invokevirtual #362                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      61: checkcast     #356                // class java/lang/Number
      64: invokevirtual #359                // Method java/lang/Number.intValue:()I
      67: iadd
      68: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      71: invokespecial #75                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      74: areturn

  private static final boolean solve$lambda$11(java.util.Map, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #364                // String next
       4: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #367,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      13: aload_1
      14: invokeinterface #262,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      19: ireturn

  private static final boolean solve$lambda$12(kotlin.jvm.functions.Function2, java.util.Map, java.util.List, kotlin.Pair);
    Code:
       0: aload_3
       1: ldc_w         #364                // String next
       4: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: aload_2
      10: invokestatic  #259                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      13: invokeinterface #371,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      18: dup
      19: invokestatic  #375                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      22: checkcast     #77                 // class java/lang/Character
      25: invokevirtual #124                // Method java/lang/Character.charValue:()C
      28: invokestatic  #142                // Method height:(C)I
      31: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      34: aload_1
      35: aload_3
      36: invokeinterface #371,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      41: dup
      42: invokestatic  #375                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      45: checkcast     #77                 // class java/lang/Character
      48: invokevirtual #124                // Method java/lang/Character.charValue:()C
      51: invokestatic  #142                // Method height:(C)I
      54: invokestatic  #72                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      57: invokeinterface #377,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      62: checkcast     #379                // class java/lang/Boolean
      65: invokevirtual #382                // Method java/lang/Boolean.booleanValue:()Z
      68: ireturn

  private static final java.util.List solve$lambda$13(java.util.List, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #364                // String next
       4: invokestatic  #351                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #35                 // class java/util/Collection
      11: aload_1
      12: invokestatic  #387                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Object;)Ljava/util/List;
      15: areturn
}


package day15

import java.io.File
import kotlin.math.abs

fun main() {
    val regexp = Regex("Sensor at x=(-?\\d*), y=(-?\\d*): closest beacon is at x=(-?\\d*), y=(-?\\d*)")
    val sensors = File("src/day15/input.txt").readLines()
        .map { regexp.matchEntire(it)!!.groupValues }
        .map { values ->
            Sensor(Pair(values[1].toInt(), values[2].toInt()), Pair(values[3].toInt(), values[4].toInt()))
        }.toSet()

    val row = 2000000 // 10
    println(sensors.map { it.excludes(row) }.reduce().sumOf { it.last - it.first })

    val max = 4000000 // 20

    // Part 2 using the fact everything must be excluded by a single range in every other row
    for (row in 0 .. max) {
        val exclusions = sensors.map { sensor -> sensor.excludes(row) }.reduce()
        if (exclusions.size > 1) {
            val column = (0..max).firstOrNull { exclusions.none { exclusion -> exclusion.contains(it) } } ?: continue
            println(column * 4000000L + row)
            break
        }
    }

    // Part 2 using the fact that the beacon must be just outside a sensor's exclusion range
    for (row in 0 .. max) {
        val exclusions = sensors.map { sensor -> sensor.excludes(row) }
        val options = exclusions.map { range -> listOf(range.first - 1, range.last + 1) }.flatten().filter { it in 0..max }
        val column = options.firstOrNull { option -> exclusions.none { exclusion -> exclusion.contains(option) } }
        if (column != null) {
            println(column * 4000000L + row)
            break
        }
    }
}

fun List<IntRange>.reduce(): List<IntRange> {
    if (size < 2) return this
    for (i in 0 until size - 1) {
        for (j in i + 1 until size) {
            if (this[i].overlap(this[j]) || this[i].adjacent(this[j])) {
                val result = this.subList(0, i).toMutableList()
                result.addAll(this.subList(i + 1, j))
                result.addAll(this.subList(j + 1, size))
                result.addAll(this[i].merge(this[j]))
                return result.reduce()
            }
        }
    }
    return this
}

fun IntRange.overlap(other: IntRange): Boolean {
    return first <= other.last && last >= other.first
}

fun IntRange.adjacent(other: IntRange): Boolean {
    return first == other.last + 1 || last == other.first - 1
}

fun IntRange.merge(other: IntRange): List<IntRange> {
    return if (overlap(other) || adjacent(other)) listOf(IntRange(kotlin.math.min(first, other.first), kotlin.math.max(last, other.last))) else listOf(this, other)
}

data class Sensor(val sensor: Pair<Int, Int>, val beacon: Pair<Int, Int>) {
    private val distance = abs(sensor.first - beacon.first) + abs(sensor.second - beacon.second)
    fun excludes(row: Int): IntRange {
        val distanceFromRow = abs(sensor.second - row)
        val difference = distance - distanceFromRow
        if (difference < 0) return IntRange.EMPTY
        return (sensor.first - difference .. sensor.first + difference)
    }
}

Compiled from "Day15.kt"
public final class day15.Day15Kt {
  public static final void main();
    Code:
       0: new           #8                  // class kotlin/text/Regex
       3: dup
       4: ldc           #10                 // String Sensor at x=(-?\\d*), y=(-?\\d*): closest beacon is at x=(-?\\d*), y=(-?\\d*)
       6: invokespecial #14                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: astore_0
      10: new           #16                 // class java/io/File
      13: dup
      14: ldc           #18                 // String src/day15/input.txt
      16: invokespecial #19                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      19: aconst_null
      20: iconst_1
      21: aconst_null
      22: invokestatic  #25                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      25: checkcast     #27                 // class java/lang/Iterable
      28: astore_2
      29: nop
      30: iconst_0
      31: istore_3
      32: aload_2
      33: astore        4
      35: new           #29                 // class java/util/ArrayList
      38: dup
      39: aload_2
      40: bipush        10
      42: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      45: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
      48: checkcast     #40                 // class java/util/Collection
      51: astore        5
      53: iconst_0
      54: istore        6
      56: aload         4
      58: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        7
      65: aload         7
      67: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          128
      75: aload         7
      77: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        8
      84: aload         5
      86: aload         8
      88: checkcast     #56                 // class java/lang/String
      91: astore        9
      93: astore        20
      95: iconst_0
      96: istore        10
      98: aload_0
      99: aload         9
     101: checkcast     #58                 // class java/lang/CharSequence
     104: invokevirtual #62                 // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
     107: dup
     108: invokestatic  #68                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     111: invokeinterface #74,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     116: aload         20
     118: swap
     119: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     124: pop
     125: goto          65
     128: aload         5
     130: checkcast     #80                 // class java/util/List
     133: nop
     134: checkcast     #27                 // class java/lang/Iterable
     137: astore_2
     138: nop
     139: iconst_0
     140: istore_3
     141: aload_2
     142: astore        4
     144: new           #29                 // class java/util/ArrayList
     147: dup
     148: aload_2
     149: bipush        10
     151: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     154: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     157: checkcast     #40                 // class java/util/Collection
     160: astore        5
     162: iconst_0
     163: istore        6
     165: aload         4
     167: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     172: astore        7
     174: aload         7
     176: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     181: ifeq          308
     184: aload         7
     186: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     191: astore        8
     193: aload         5
     195: aload         8
     197: checkcast     #80                 // class java/util/List
     200: astore        9
     202: astore        20
     204: iconst_0
     205: istore        10
     207: new           #82                 // class day15/Sensor
     210: dup
     211: new           #84                 // class kotlin/Pair
     214: dup
     215: aload         9
     217: iconst_1
     218: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     223: checkcast     #56                 // class java/lang/String
     226: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     229: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     232: aload         9
     234: iconst_2
     235: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     240: checkcast     #56                 // class java/lang/String
     243: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     246: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     249: invokespecial #101                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     252: new           #84                 // class kotlin/Pair
     255: dup
     256: aload         9
     258: iconst_3
     259: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     264: checkcast     #56                 // class java/lang/String
     267: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     270: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     273: aload         9
     275: iconst_4
     276: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     281: checkcast     #56                 // class java/lang/String
     284: invokestatic  #94                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     287: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     290: invokespecial #101                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     293: invokespecial #104                // Method day15/Sensor."<init>":(Lkotlin/Pair;Lkotlin/Pair;)V
     296: aload         20
     298: swap
     299: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     304: pop
     305: goto          174
     308: aload         5
     310: checkcast     #80                 // class java/util/List
     313: nop
     314: checkcast     #27                 // class java/lang/Iterable
     317: invokestatic  #108                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     320: astore_1
     321: ldc           #109                // int 2000000
     323: istore_2
     324: aload_1
     325: checkcast     #27                 // class java/lang/Iterable
     328: astore_3
     329: iconst_0
     330: istore        4
     332: aload_3
     333: astore        5
     335: new           #29                 // class java/util/ArrayList
     338: dup
     339: aload_3
     340: bipush        10
     342: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     345: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     348: checkcast     #40                 // class java/util/Collection
     351: astore        6
     353: iconst_0
     354: istore        7
     356: aload         5
     358: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     363: astore        8
     365: aload         8
     367: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     372: ifeq          416
     375: aload         8
     377: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     382: astore        9
     384: aload         6
     386: aload         9
     388: checkcast     #82                 // class day15/Sensor
     391: astore        10
     393: astore        20
     395: iconst_0
     396: istore        11
     398: aload         10
     400: iload_2
     401: invokevirtual #113                // Method day15/Sensor.excludes:(I)Lkotlin/ranges/IntRange;
     404: aload         20
     406: swap
     407: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     412: pop
     413: goto          365
     416: aload         6
     418: checkcast     #80                 // class java/util/List
     421: nop
     422: invokestatic  #117                // Method reduce:(Ljava/util/List;)Ljava/util/List;
     425: checkcast     #27                 // class java/lang/Iterable
     428: astore_3
     429: iconst_0
     430: istore        4
     432: aload_3
     433: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     438: astore        5
     440: aload         5
     442: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     447: ifeq          496
     450: aload         5
     452: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     457: astore        6
     459: iload         4
     461: aload         6
     463: checkcast     #119                // class kotlin/ranges/IntRange
     466: astore        7
     468: istore        20
     470: iconst_0
     471: istore        8
     473: aload         7
     475: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
     478: aload         7
     480: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
     483: isub
     484: istore        21
     486: iload         20
     488: iload         21
     490: iadd
     491: istore        4
     493: goto          440
     496: iload         4
     498: istore_3
     499: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
     502: iload_3
     503: invokevirtual #137                // Method java/io/PrintStream.println:(I)V
     506: ldc           #138                // int 4000000
     508: istore_3
     509: iconst_0
     510: istore        4
     512: aload_1
     513: checkcast     #27                 // class java/lang/Iterable
     516: astore        6
     518: iconst_0
     519: istore        7
     521: aload         6
     523: astore        8
     525: new           #29                 // class java/util/ArrayList
     528: dup
     529: aload         6
     531: bipush        10
     533: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     536: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     539: checkcast     #40                 // class java/util/Collection
     542: astore        9
     544: iconst_0
     545: istore        10
     547: aload         8
     549: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     554: astore        11
     556: aload         11
     558: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     563: ifeq          608
     566: aload         11
     568: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     573: astore        12
     575: aload         9
     577: aload         12
     579: checkcast     #82                 // class day15/Sensor
     582: astore        13
     584: astore        20
     586: iconst_0
     587: istore        14
     589: aload         13
     591: iload         4
     593: invokevirtual #113                // Method day15/Sensor.excludes:(I)Lkotlin/ranges/IntRange;
     596: aload         20
     598: swap
     599: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     604: pop
     605: goto          556
     608: aload         9
     610: checkcast     #80                 // class java/util/List
     613: nop
     614: invokestatic  #117                // Method reduce:(Ljava/util/List;)Ljava/util/List;
     617: astore        5
     619: aload         5
     621: invokeinterface #141,  1          // InterfaceMethod java/util/List.size:()I
     626: iconst_1
     627: if_icmple     829
     630: new           #119                // class kotlin/ranges/IntRange
     633: dup
     634: iconst_0
     635: iload_3
     636: invokespecial #144                // Method kotlin/ranges/IntRange."<init>":(II)V
     639: checkcast     #27                 // class java/lang/Iterable
     642: astore        8
     644: iconst_0
     645: istore        9
     647: aload         8
     649: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     654: astore        10
     656: aload         10
     658: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     663: ifeq          785
     666: aload         10
     668: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     673: astore        11
     675: aload         11
     677: checkcast     #146                // class java/lang/Number
     680: invokevirtual #149                // Method java/lang/Number.intValue:()I
     683: istore        12
     685: iconst_0
     686: istore        13
     688: aload         5
     690: checkcast     #27                 // class java/lang/Iterable
     693: astore        14
     695: iconst_0
     696: istore        15
     698: aload         14
     700: instanceof    #40                 // class java/util/Collection
     703: ifeq          723
     706: aload         14
     708: checkcast     #40                 // class java/util/Collection
     711: invokeinterface #152,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     716: ifeq          723
     719: iconst_1
     720: goto          776
     723: aload         14
     725: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     730: astore        16
     732: aload         16
     734: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     739: ifeq          775
     742: aload         16
     744: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     749: astore        17
     751: aload         17
     753: checkcast     #119                // class kotlin/ranges/IntRange
     756: astore        18
     758: iconst_0
     759: istore        19
     761: aload         18
     763: iload         12
     765: invokevirtual #156                // Method kotlin/ranges/IntRange.contains:(I)Z
     768: ifeq          732
     771: iconst_0
     772: goto          776
     775: iconst_1
     776: nop
     777: ifeq          656
     780: aload         11
     782: goto          786
     785: aconst_null
     786: checkcast     #90                 // class java/lang/Integer
     789: dup
     790: ifnull        799
     793: invokevirtual #157                // Method java/lang/Integer.intValue:()I
     796: goto          803
     799: pop
     800: goto          829
     803: istore        6
     805: iload         6
     807: i2l
     808: ldc2_w        #158                // long 4000000l
     811: lmul
     812: iload         4
     814: i2l
     815: ladd
     816: lstore        7
     818: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
     821: lload         7
     823: invokevirtual #162                // Method java/io/PrintStream.println:(J)V
     826: goto          841
     829: iload         4
     831: iload_3
     832: if_icmpeq     841
     835: iinc          4, 1
     838: goto          512
     841: iconst_0
     842: istore        4
     844: aload_1
     845: checkcast     #27                 // class java/lang/Iterable
     848: astore        6
     850: iconst_0
     851: istore        7
     853: aload         6
     855: astore        8
     857: new           #29                 // class java/util/ArrayList
     860: dup
     861: aload         6
     863: bipush        10
     865: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     868: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     871: checkcast     #40                 // class java/util/Collection
     874: astore        9
     876: iconst_0
     877: istore        10
     879: aload         8
     881: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     886: astore        11
     888: aload         11
     890: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     895: ifeq          940
     898: aload         11
     900: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     905: astore        12
     907: aload         9
     909: aload         12
     911: checkcast     #82                 // class day15/Sensor
     914: astore        13
     916: astore        20
     918: iconst_0
     919: istore        14
     921: aload         13
     923: iload         4
     925: invokevirtual #113                // Method day15/Sensor.excludes:(I)Lkotlin/ranges/IntRange;
     928: aload         20
     930: swap
     931: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     936: pop
     937: goto          888
     940: aload         9
     942: checkcast     #80                 // class java/util/List
     945: nop
     946: astore        5
     948: aload         5
     950: checkcast     #27                 // class java/lang/Iterable
     953: astore        7
     955: iconst_0
     956: istore        8
     958: aload         7
     960: astore        9
     962: new           #29                 // class java/util/ArrayList
     965: dup
     966: aload         7
     968: bipush        10
     970: invokestatic  #35                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     973: invokespecial #38                 // Method java/util/ArrayList."<init>":(I)V
     976: checkcast     #40                 // class java/util/Collection
     979: astore        10
     981: iconst_0
     982: istore        11
     984: aload         9
     986: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     991: astore        12
     993: aload         12
     995: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1000: ifeq          1077
    1003: aload         12
    1005: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1010: astore        13
    1012: aload         10
    1014: aload         13
    1016: checkcast     #119                // class kotlin/ranges/IntRange
    1019: astore        14
    1021: astore        20
    1023: iconst_0
    1024: istore        15
    1026: iconst_2
    1027: anewarray     #90                 // class java/lang/Integer
    1030: astore        16
    1032: aload         16
    1034: iconst_0
    1035: aload         14
    1037: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
    1040: iconst_1
    1041: isub
    1042: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1045: aastore
    1046: aload         16
    1048: iconst_1
    1049: aload         14
    1051: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
    1054: iconst_1
    1055: iadd
    1056: invokestatic  #98                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
    1059: aastore
    1060: aload         16
    1062: invokestatic  #166                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
    1065: aload         20
    1067: swap
    1068: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
    1073: pop
    1074: goto          993
    1077: aload         10
    1079: checkcast     #80                 // class java/util/List
    1082: nop
    1083: checkcast     #27                 // class java/lang/Iterable
    1086: invokestatic  #170                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
    1089: checkcast     #27                 // class java/lang/Iterable
    1092: astore        7
    1094: iconst_0
    1095: istore        8
    1097: aload         7
    1099: astore        9
    1101: new           #29                 // class java/util/ArrayList
    1104: dup
    1105: invokespecial #172                // Method java/util/ArrayList."<init>":()V
    1108: checkcast     #40                 // class java/util/Collection
    1111: astore        10
    1113: iconst_0
    1114: istore        11
    1116: aload         9
    1118: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1123: astore        12
    1125: aload         12
    1127: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1132: ifeq          1194
    1135: aload         12
    1137: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1142: astore        13
    1144: aload         13
    1146: checkcast     #146                // class java/lang/Number
    1149: invokevirtual #149                // Method java/lang/Number.intValue:()I
    1152: istore        14
    1154: iconst_0
    1155: istore        15
    1157: iconst_0
    1158: iload         14
    1160: if_icmpgt     1177
    1163: iload         14
    1165: iload_3
    1166: if_icmpgt     1173
    1169: iconst_1
    1170: goto          1178
    1173: iconst_0
    1174: goto          1178
    1177: iconst_0
    1178: ifeq          1125
    1181: aload         10
    1183: aload         13
    1185: invokeinterface #78,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
    1190: pop
    1191: goto          1125
    1194: aload         10
    1196: checkcast     #80                 // class java/util/List
    1199: nop
    1200: astore        6
    1202: aload         6
    1204: checkcast     #27                 // class java/lang/Iterable
    1207: astore        8
    1209: iconst_0
    1210: istore        9
    1212: aload         8
    1214: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1219: astore        10
    1221: aload         10
    1223: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1228: ifeq          1350
    1231: aload         10
    1233: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1238: astore        11
    1240: aload         11
    1242: checkcast     #146                // class java/lang/Number
    1245: invokevirtual #149                // Method java/lang/Number.intValue:()I
    1248: istore        12
    1250: iconst_0
    1251: istore        13
    1253: aload         5
    1255: checkcast     #27                 // class java/lang/Iterable
    1258: astore        14
    1260: iconst_0
    1261: istore        15
    1263: aload         14
    1265: instanceof    #40                 // class java/util/Collection
    1268: ifeq          1288
    1271: aload         14
    1273: checkcast     #40                 // class java/util/Collection
    1276: invokeinterface #152,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
    1281: ifeq          1288
    1284: iconst_1
    1285: goto          1341
    1288: aload         14
    1290: invokeinterface #44,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
    1295: astore        16
    1297: aload         16
    1299: invokeinterface #50,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1304: ifeq          1340
    1307: aload         16
    1309: invokeinterface #54,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1314: astore        17
    1316: aload         17
    1318: checkcast     #119                // class kotlin/ranges/IntRange
    1321: astore        18
    1323: iconst_0
    1324: istore        19
    1326: aload         18
    1328: iload         12
    1330: invokevirtual #156                // Method kotlin/ranges/IntRange.contains:(I)Z
    1333: ifeq          1297
    1336: iconst_0
    1337: goto          1341
    1340: iconst_1
    1341: nop
    1342: ifeq          1221
    1345: aload         11
    1347: goto          1351
    1350: aconst_null
    1351: checkcast     #90                 // class java/lang/Integer
    1354: astore        7
    1356: aload         7
    1358: ifnull        1388
    1361: aload         7
    1363: invokevirtual #157                // Method java/lang/Integer.intValue:()I
    1366: i2l
    1367: ldc2_w        #158                // long 4000000l
    1370: lmul
    1371: iload         4
    1373: i2l
    1374: ladd
    1375: lstore        8
    1377: getstatic     #132                // Field java/lang/System.out:Ljava/io/PrintStream;
    1380: lload         8
    1382: invokevirtual #162                // Method java/io/PrintStream.println:(J)V
    1385: goto          1400
    1388: iload         4
    1390: iload_3
    1391: if_icmpeq     1400
    1394: iinc          4, 1
    1397: goto          844
    1400: return

  public static final java.util.List<kotlin.ranges.IntRange> reduce(java.util.List<kotlin.ranges.IntRange>);
    Code:
       0: aload_0
       1: ldc           #230                // String <this>
       3: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #141,  1          // InterfaceMethod java/util/List.size:()I
      12: iconst_2
      13: if_icmpge     18
      16: aload_0
      17: areturn
      18: iconst_0
      19: istore_1
      20: aload_0
      21: invokeinterface #141,  1          // InterfaceMethod java/util/List.size:()I
      26: iconst_1
      27: isub
      28: istore_2
      29: iload_1
      30: iload_2
      31: if_icmpge     219
      34: iload_1
      35: iconst_1
      36: iadd
      37: istore_3
      38: aload_0
      39: invokeinterface #141,  1          // InterfaceMethod java/util/List.size:()I
      44: istore        4
      46: iload_3
      47: iload         4
      49: if_icmpge     213
      52: aload_0
      53: iload_1
      54: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      59: checkcast     #119                // class kotlin/ranges/IntRange
      62: aload_0
      63: iload_3
      64: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      69: checkcast     #119                // class kotlin/ranges/IntRange
      72: invokestatic  #238                // Method overlap:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Z
      75: ifne          104
      78: aload_0
      79: iload_1
      80: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      85: checkcast     #119                // class kotlin/ranges/IntRange
      88: aload_0
      89: iload_3
      90: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      95: checkcast     #119                // class kotlin/ranges/IntRange
      98: invokestatic  #241                // Method adjacent:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Z
     101: ifeq          207
     104: aload_0
     105: iconst_0
     106: iload_1
     107: invokeinterface #245,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     112: checkcast     #40                 // class java/util/Collection
     115: invokestatic  #249                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     118: astore        5
     120: aload         5
     122: aload_0
     123: iload_1
     124: iconst_1
     125: iadd
     126: iload_3
     127: invokeinterface #245,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     132: checkcast     #40                 // class java/util/Collection
     135: invokeinterface #253,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     140: pop
     141: aload         5
     143: aload_0
     144: iload_3
     145: iconst_1
     146: iadd
     147: aload_0
     148: invokeinterface #141,  1          // InterfaceMethod java/util/List.size:()I
     153: invokeinterface #245,  3          // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     158: checkcast     #40                 // class java/util/Collection
     161: invokeinterface #253,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     166: pop
     167: aload         5
     169: aload_0
     170: iload_1
     171: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     176: checkcast     #119                // class kotlin/ranges/IntRange
     179: aload_0
     180: iload_3
     181: invokeinterface #88,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     186: checkcast     #119                // class kotlin/ranges/IntRange
     189: invokestatic  #257                // Method merge:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Ljava/util/List;
     192: checkcast     #40                 // class java/util/Collection
     195: invokeinterface #253,  2          // InterfaceMethod java/util/List.addAll:(Ljava/util/Collection;)Z
     200: pop
     201: aload         5
     203: invokestatic  #117                // Method reduce:(Ljava/util/List;)Ljava/util/List;
     206: areturn
     207: iinc          3, 1
     210: goto          46
     213: iinc          1, 1
     216: goto          29
     219: aload_0
     220: areturn

  public static final boolean overlap(kotlin.ranges.IntRange, kotlin.ranges.IntRange);
    Code:
       0: aload_0
       1: ldc           #230                // String <this>
       3: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #263                // String other
      10: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: aload_0
      14: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
      17: aload_1
      18: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
      21: if_icmpgt     39
      24: aload_0
      25: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
      28: aload_1
      29: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
      32: if_icmplt     39
      35: iconst_1
      36: goto          40
      39: iconst_0
      40: ireturn

  public static final boolean adjacent(kotlin.ranges.IntRange, kotlin.ranges.IntRange);
    Code:
       0: aload_0
       1: ldc           #230                // String <this>
       3: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #263                // String other
      10: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: aload_0
      14: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
      17: aload_1
      18: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
      21: iconst_1
      22: iadd
      23: if_icmpeq     39
      26: aload_0
      27: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
      30: aload_1
      31: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
      34: iconst_1
      35: isub
      36: if_icmpne     43
      39: iconst_1
      40: goto          44
      43: iconst_0
      44: ireturn

  public static final java.util.List<kotlin.ranges.IntRange> merge(kotlin.ranges.IntRange, kotlin.ranges.IntRange);
    Code:
       0: aload_0
       1: ldc           #230                // String <this>
       3: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #263                // String other
      10: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: aload_0
      14: aload_1
      15: invokestatic  #238                // Method overlap:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Z
      18: ifne          29
      21: aload_0
      22: aload_1
      23: invokestatic  #241                // Method adjacent:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Z
      26: ifeq          64
      29: new           #119                // class kotlin/ranges/IntRange
      32: dup
      33: aload_0
      34: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
      37: aload_1
      38: invokevirtual #126                // Method kotlin/ranges/IntRange.getFirst:()I
      41: invokestatic  #272                // Method java/lang/Math.min:(II)I
      44: aload_0
      45: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
      48: aload_1
      49: invokevirtual #123                // Method kotlin/ranges/IntRange.getLast:()I
      52: invokestatic  #274                // Method java/lang/Math.max:(II)I
      55: invokespecial #144                // Method kotlin/ranges/IntRange."<init>":(II)V
      58: invokestatic  #277                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      61: goto          81
      64: iconst_2
      65: anewarray     #119                // class kotlin/ranges/IntRange
      68: astore_2
      69: aload_2
      70: iconst_0
      71: aload_0
      72: aastore
      73: aload_2
      74: iconst_1
      75: aload_1
      76: aastore
      77: aload_2
      78: invokestatic  #166                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      81: areturn

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