package dev.kosmx.aoc23.garden

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

typealias Offset = Pair<OpenEndRange<BigInteger>, BigInteger>

val OpenEndRange<BigInteger>.size: BigInteger
    get() = endExclusive - start

val Offset.destination: OpenEndRange<BigInteger>
    get() = (first.start + second) ..< (first.endExclusive + second)

fun List<Offset>.binarySearch(i: BigInteger) = binarySearch { (range, _) ->
    if (i in range) {
        0
    } else {
        range.start.compareTo(i)
    }
}

operator fun List<OpenEndRange<BigInteger>>.contains(item: BigInteger): Boolean {
    val idx = binarySearch { range ->
        if (item in range) {
            0
        } else {
            range.start.compareTo(item)
        }
    }
    return this.getOrNull(idx)?.contains(item) ?: false
}

fun min(a: BigInteger, b: BigInteger): BigInteger = if (a < b) a else b
class RangeMapping(ranges: List<Offset> = listOf()) {
    val rangesList: List<Offset>

    init {
        rangesList = ranges.sortedBy { it.first.start }
    }

    operator fun get(i: BigInteger): BigInteger {
        val r = this.rangesList.binarySearch(i)

        return if (r >= 0) {
            i + rangesList[r].second
        } else i
    }

    override fun toString(): String {
        return "RangeMapping(rangesList=$rangesList)"
    }

    // one step of simplify
    operator fun plus(rhs: RangeMapping): RangeMapping {
        val newRanges = mutableListOf<Offset>()
        val newRangesB = rhs.rangesList.toMutableList()

        for (range in rangesList) {
            val currentRange = range.destination
            var current = currentRange.start

            var targetRangeIdx = abs(newRangesB.binarySearch(current))

            while (current < currentRange.endExclusive && targetRangeIdx < newRangesB.size) {
                val dest = newRangesB[targetRangeIdx]
                if (current in dest.first) { // two ranges intersect, cut both range

                    // cut destination range if necessary
                    if (current > dest.first.start) {
                        newRangesB.add(targetRangeIdx, dest.first.start ..< current to dest.second)
                        targetRangeIdx++
                    }

                    val newEnd = min(currentRange.endExclusive, dest.first.endExclusive)
                    newRanges += current-range.second ..< newEnd-range.second to range.second + dest.second
                    current = newEnd

                    if (newEnd < dest.first.endExclusive) {
                        newRangesB[targetRangeIdx] = newEnd ..< dest.first.endExclusive to dest.second
                        targetRangeIdx++
                    } else {
                        newRangesB.removeAt(targetRangeIdx)
                    }
                } else {
                    val newEnd = min(currentRange.endExclusive, dest.first.start)
                    newRanges += current-range.second ..< newEnd-range.second to range.second
                    current = newEnd

                }
            }
            if (current < range.first.endExclusive) {
                newRanges += current-range.second ..< range.first.endExclusive to range.second
            }
        }

        newRanges.removeIf { it.first.isEmpty() }

        run {
            var i = 0
            while (i < newRangesB.size) {
                val r = newRangesB[i]
                val pos = abs(newRanges.binarySearch(r.first.start))
                if (r.first.isEmpty() || newRanges.size > pos && newRanges[pos].first.start < r.first.endExclusive) {
                    // there is some intersection
                    // new r range start after the other range
                    if (r.first.isEmpty() || r.first.start >= newRanges[pos].first.start) {
                        if (r.first.isEmpty() || r.first.endExclusive <= newRanges[pos].first.endExclusive) {
                            newRangesB.removeAt(i) // just throw it away
                        } else {
                            newRangesB[i] = newRanges[pos].first.endExclusive ..< r.first.endExclusive to r.second // trim it
                        }
                    } else { // the current range starts before the other, we cut it always
                        newRangesB[i] = r.first.start ..< newRanges[pos].first.start to r.second // this range is okay

                        // add the following part, next iteration can handle it.
                        newRangesB.add(i + 1, newRanges[pos].first.start ..< r.first.endExclusive to r.second)
                        i++
                    }

                } else {
                    i++
                }
            }
        }

        newRanges += newRangesB // now, these shouldn't intersect
        // make it sorted
        newRanges.sortBy { it.first.start }

        // optimise this mess
        var i = 0
        while (i < newRanges.size - 1) {
            val current = newRanges[i]
            val next by lazy { newRanges[i + 1] }
            when {
                current.second == BigInteger.ZERO || current.first.isEmpty() -> {
                    newRanges.removeAt(i)
                }
                current.first.endExclusive == next.first.start && current.second == next.second -> {
                    newRanges[i] = current.first.start ..< next.first.endExclusive to current.second
                    newRanges.removeAt(i + 1)
                }
                else -> i++
            }
        }
        return RangeMapping(newRanges)
    }

}

fun main() {
    val lines = File("mapping.txt").readLines().filter { it.isNotBlank() }

    val seeds = mutableListOf<BigInteger>()

    val conversionSequence = mutableListOf<RangeMapping>()

    // parse seeds
    seeds += lines[0].split(" ").drop(1).map { BigInteger(it) }

    val p = Regex("^(?<from>\\w+)-to-(?<to>\\w+) map:$")

    var i = 1
    while (lines.size > i) {
        val rangeList = mutableListOf<Pair<OpenEndRange<BigInteger>, BigInteger>>()
        while (lines.size > i && !p.matches(lines[i])) {
            val l = lines[i].split(" ").map { BigInteger(it) }
            rangeList += (l[1] ..< (l[1] + l[2])) to l[0] - l[1]
            i++
        }
        if (rangeList.isNotEmpty()) {
            conversionSequence += RangeMapping(rangeList)
        }
        i++
    }

    println(conversionSequence)
    val min = seeds.map { conversionSequence[it] }.toList().min()
    println("The lowest number Id is $min")

    val range = conversionSequence.simplify()

    val seedRanges = lines[0].split(" ").asSequence().drop(1).map { BigInteger(it) }.windowed(2, 2).map { (start, len) ->
        start ..< start + len
    }.sortedBy { it.start }.toList()

    var minSeed = range[seedRanges[0].start]
    (range.rangesList.asSequence().map { it.first.start } + seedRanges.asSequence().map { it.start }).filter {
        it in seedRanges
    }.forEach {
        val new = conversionSequence[it]
        if (new < minSeed) {
            minSeed = new
        }
    }

    println("Part2: $minSeed")

}

// This is the key for Part2
// Something is still not okay, but I don't care right now
fun List<RangeMapping>.simplify(): RangeMapping = fold(RangeMapping()) { acc, rangeMapping ->
    acc + rangeMapping
}

operator fun List<RangeMapping>.get(i: BigInteger, debug: Boolean = false): BigInteger {
    if (debug) print(i)
    return fold(i) {acc, rangeMapping ->
        rangeMapping[acc].also {
            if(debug) print(" -> $it")
        }
    }.also {
        if (debug) println()
    }
}

Compiled from "Comparisons.kt"
public final class dev.kosmx.aoc23.garden.VirtualMemoryKt$main$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public dev.kosmx.aoc23.garden.VirtualMemoryKt$main$$inlined$sortedBy$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_1
       1: checkcast     #23                 // class kotlin/ranges/OpenEndRange
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      14: checkcast     #29                 // class java/math/BigInteger
      17: checkcast     #31                 // class java/lang/Comparable
      20: aload_2
      21: checkcast     #23                 // class kotlin/ranges/OpenEndRange
      24: astore_3
      25: astore        5
      27: iconst_0
      28: istore        4
      30: aload_3
      31: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      36: checkcast     #29                 // class java/math/BigInteger
      39: aload         5
      41: swap
      42: checkcast     #31                 // class java/lang/Comparable
      45: invokestatic  #37                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      48: ireturn
}

Compiled from "VirtualMemory.kt"
public final class dev.kosmx.aoc23.garden.VirtualMemoryKt {
  public static final java.math.BigInteger getSize(kotlin.ranges.OpenEndRange<java.math.BigInteger>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #22,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getEndExclusive:()Ljava/lang/Comparable;
      12: checkcast     #24                 // class java/math/BigInteger
      15: aload_0
      16: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      21: checkcast     #24                 // class java/math/BigInteger
      24: invokevirtual #31                 // Method java/math/BigInteger.subtract:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      27: dup
      28: ldc           #33                 // String subtract(...)
      30: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      33: areturn

  public static final kotlin.ranges.OpenEndRange<java.math.BigInteger> getDestination(kotlin.Pair<? extends kotlin.ranges.OpenEndRange<java.math.BigInteger>, ? extends java.math.BigInteger>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #47                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      10: checkcast     #18                 // class kotlin/ranges/OpenEndRange
      13: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      18: checkcast     #24                 // class java/math/BigInteger
      21: aload_0
      22: invokevirtual #50                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      25: checkcast     #24                 // class java/math/BigInteger
      28: invokevirtual #53                 // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      31: dup
      32: ldc           #55                 // String add(...)
      34: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      37: checkcast     #57                 // class java/lang/Comparable
      40: aload_0
      41: invokevirtual #47                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      44: checkcast     #18                 // class kotlin/ranges/OpenEndRange
      47: invokeinterface #22,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getEndExclusive:()Ljava/lang/Comparable;
      52: checkcast     #24                 // class java/math/BigInteger
      55: aload_0
      56: invokevirtual #50                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      59: checkcast     #24                 // class java/math/BigInteger
      62: invokevirtual #53                 // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      65: dup
      66: ldc           #55                 // String add(...)
      68: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      71: checkcast     #57                 // class java/lang/Comparable
      74: invokestatic  #63                 // Method kotlin/ranges/RangesKt.rangeUntil:(Ljava/lang/Comparable;Ljava/lang/Comparable;)Lkotlin/ranges/OpenEndRange;
      77: areturn

  public static final int binarySearch(java.util.List<? extends kotlin.Pair<? extends kotlin.ranges.OpenEndRange<java.math.BigInteger>, ? extends java.math.BigInteger>>, java.math.BigInteger);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #70                 // String i
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_0
      14: iconst_0
      15: aload_1
      16: invokedynamic #90,  0             // InvokeDynamic #0:invoke:(Ljava/math/BigInteger;)Lkotlin/jvm/functions/Function1;
      21: iconst_3
      22: aconst_null
      23: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.binarySearch$default:(Ljava/util/List;IILkotlin/jvm/functions/Function1;ILjava/lang/Object;)I
      26: ireturn

  public static final boolean contains(java.util.List<? extends kotlin.ranges.OpenEndRange<java.math.BigInteger>>, java.math.BigInteger);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #104                // String item
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iconst_0
      14: iconst_0
      15: aload_1
      16: invokedynamic #112,  0            // InvokeDynamic #1:invoke:(Ljava/math/BigInteger;)Lkotlin/jvm/functions/Function1;
      21: iconst_3
      22: aconst_null
      23: invokestatic  #96                 // Method kotlin/collections/CollectionsKt.binarySearch$default:(Ljava/util/List;IILkotlin/jvm/functions/Function1;ILjava/lang/Object;)I
      26: istore_2
      27: aload_0
      28: iload_2
      29: invokestatic  #116                // Method kotlin/collections/CollectionsKt.getOrNull:(Ljava/util/List;I)Ljava/lang/Object;
      32: checkcast     #18                 // class kotlin/ranges/OpenEndRange
      35: dup
      36: ifnull        51
      39: aload_1
      40: checkcast     #57                 // class java/lang/Comparable
      43: invokeinterface #119,  2          // InterfaceMethod kotlin/ranges/OpenEndRange.contains:(Ljava/lang/Comparable;)Z
      48: goto          53
      51: pop
      52: iconst_0
      53: ireturn

  public static final java.math.BigInteger min(java.math.BigInteger, java.math.BigInteger);
    Code:
       0: aload_0
       1: ldc           #128                // String a
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #130                // String b
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokevirtual #134                // Method java/math/BigInteger.compareTo:(Ljava/math/BigInteger;)I
      17: ifge          24
      20: aload_0
      21: goto          25
      24: aload_1
      25: areturn

  public static final void main();
    Code:
       0: new           #138                // class java/io/File
       3: dup
       4: ldc           #140                // String mapping.txt
       6: invokespecial #144                // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #150                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      15: checkcast     #152                // class java/lang/Iterable
      18: astore_1
      19: iconst_0
      20: istore_2
      21: aload_1
      22: astore_3
      23: new           #154                // class java/util/ArrayList
      26: dup
      27: invokespecial #156                // Method java/util/ArrayList."<init>":()V
      30: checkcast     #158                // class java/util/Collection
      33: astore        4
      35: iconst_0
      36: istore        5
      38: aload_3
      39: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        6
      46: aload         6
      48: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          108
      56: aload         6
      58: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        7
      65: aload         7
      67: checkcast     #173                // class java/lang/String
      70: astore        8
      72: iconst_0
      73: istore        9
      75: aload         8
      77: checkcast     #175                // class java/lang/CharSequence
      80: invokestatic  #181                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      83: ifne          90
      86: iconst_1
      87: goto          91
      90: iconst_0
      91: nop
      92: ifeq          46
      95: aload         4
      97: aload         7
      99: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     104: pop
     105: goto          46
     108: aload         4
     110: checkcast     #124                // class java/util/List
     113: nop
     114: astore_0
     115: new           #154                // class java/util/ArrayList
     118: dup
     119: invokespecial #156                // Method java/util/ArrayList."<init>":()V
     122: checkcast     #124                // class java/util/List
     125: astore_1
     126: new           #154                // class java/util/ArrayList
     129: dup
     130: invokespecial #156                // Method java/util/ArrayList."<init>":()V
     133: checkcast     #124                // class java/util/List
     136: astore_2
     137: aload_1
     138: checkcast     #158                // class java/util/Collection
     141: astore_3
     142: aload_0
     143: iconst_0
     144: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     149: checkcast     #175                // class java/lang/CharSequence
     152: iconst_1
     153: anewarray     #173                // class java/lang/String
     156: astore        4
     158: aload         4
     160: iconst_0
     161: ldc           #190                // String
     163: aastore
     164: aload         4
     166: iconst_0
     167: iconst_0
     168: bipush        6
     170: aconst_null
     171: invokestatic  #194                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     174: checkcast     #152                // class java/lang/Iterable
     177: iconst_1
     178: invokestatic  #198                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     181: checkcast     #152                // class java/lang/Iterable
     184: astore        4
     186: iconst_0
     187: istore        5
     189: aload         4
     191: astore        6
     193: new           #154                // class java/util/ArrayList
     196: dup
     197: aload         4
     199: bipush        10
     201: invokestatic  #202                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     204: invokespecial #205                // Method java/util/ArrayList."<init>":(I)V
     207: checkcast     #158                // class java/util/Collection
     210: astore        7
     212: iconst_0
     213: istore        8
     215: aload         6
     217: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     222: astore        9
     224: aload         9
     226: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     231: ifeq          278
     234: aload         9
     236: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     241: astore        10
     243: aload         7
     245: aload         10
     247: checkcast     #173                // class java/lang/String
     250: astore        11
     252: astore        16
     254: iconst_0
     255: istore        12
     257: new           #24                 // class java/math/BigInteger
     260: dup
     261: aload         11
     263: invokespecial #206                // Method java/math/BigInteger."<init>":(Ljava/lang/String;)V
     266: aload         16
     268: swap
     269: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     274: pop
     275: goto          224
     278: aload         7
     280: checkcast     #124                // class java/util/List
     283: nop
     284: checkcast     #152                // class java/lang/Iterable
     287: astore        4
     289: aload_3
     290: aload         4
     292: invokestatic  #210                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     295: pop
     296: new           #212                // class kotlin/text/Regex
     299: dup
     300: ldc           #214                // String ^(?<from>\\w+)-to-(?<to>\\w+) map:$
     302: invokespecial #215                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
     305: astore_3
     306: iconst_1
     307: istore        4
     309: aload_0
     310: invokeinterface #219,  1          // InterfaceMethod java/util/List.size:()I
     315: iload         4
     317: if_icmple     644
     320: new           #154                // class java/util/ArrayList
     323: dup
     324: invokespecial #156                // Method java/util/ArrayList."<init>":()V
     327: checkcast     #124                // class java/util/List
     330: astore        5
     332: aload_0
     333: invokeinterface #219,  1          // InterfaceMethod java/util/List.size:()I
     338: iload         4
     340: if_icmple     598
     343: aload_3
     344: aload_0
     345: iload         4
     347: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     352: checkcast     #175                // class java/lang/CharSequence
     355: invokevirtual #222                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
     358: ifne          598
     361: aload_0
     362: iload         4
     364: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     369: checkcast     #175                // class java/lang/CharSequence
     372: iconst_1
     373: anewarray     #173                // class java/lang/String
     376: astore        7
     378: aload         7
     380: iconst_0
     381: ldc           #190                // String
     383: aastore
     384: aload         7
     386: iconst_0
     387: iconst_0
     388: bipush        6
     390: aconst_null
     391: invokestatic  #194                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     394: checkcast     #152                // class java/lang/Iterable
     397: astore        7
     399: iconst_0
     400: istore        8
     402: aload         7
     404: astore        9
     406: new           #154                // class java/util/ArrayList
     409: dup
     410: aload         7
     412: bipush        10
     414: invokestatic  #202                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     417: invokespecial #205                // Method java/util/ArrayList."<init>":(I)V
     420: checkcast     #158                // class java/util/Collection
     423: astore        10
     425: iconst_0
     426: istore        11
     428: aload         9
     430: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     435: astore        12
     437: aload         12
     439: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     444: ifeq          491
     447: aload         12
     449: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     454: astore        13
     456: aload         10
     458: aload         13
     460: checkcast     #173                // class java/lang/String
     463: astore        14
     465: astore        16
     467: iconst_0
     468: istore        15
     470: new           #24                 // class java/math/BigInteger
     473: dup
     474: aload         14
     476: invokespecial #206                // Method java/math/BigInteger."<init>":(Ljava/lang/String;)V
     479: aload         16
     481: swap
     482: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     487: pop
     488: goto          437
     491: aload         10
     493: checkcast     #124                // class java/util/List
     496: nop
     497: astore        6
     499: aload         5
     501: checkcast     #158                // class java/util/Collection
     504: aload         6
     506: iconst_1
     507: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     512: checkcast     #57                 // class java/lang/Comparable
     515: aload         6
     517: iconst_1
     518: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     523: checkcast     #24                 // class java/math/BigInteger
     526: aload         6
     528: iconst_2
     529: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     534: checkcast     #24                 // class java/math/BigInteger
     537: invokevirtual #53                 // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     540: dup
     541: ldc           #55                 // String add(...)
     543: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     546: checkcast     #57                 // class java/lang/Comparable
     549: invokestatic  #63                 // Method kotlin/ranges/RangesKt.rangeUntil:(Ljava/lang/Comparable;Ljava/lang/Comparable;)Lkotlin/ranges/OpenEndRange;
     552: aload         6
     554: iconst_0
     555: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     560: checkcast     #24                 // class java/math/BigInteger
     563: aload         6
     565: iconst_1
     566: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     571: checkcast     #24                 // class java/math/BigInteger
     574: invokevirtual #31                 // Method java/math/BigInteger.subtract:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     577: dup
     578: ldc           #33                 // String subtract(...)
     580: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     583: invokestatic  #228                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     586: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     591: pop
     592: iinc          4, 1
     595: goto          332
     598: aload         5
     600: checkcast     #158                // class java/util/Collection
     603: invokeinterface #231,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     608: ifne          615
     611: iconst_1
     612: goto          616
     615: iconst_0
     616: ifeq          638
     619: aload_2
     620: checkcast     #158                // class java/util/Collection
     623: new           #233                // class dev/kosmx/aoc23/garden/RangeMapping
     626: dup
     627: aload         5
     629: invokespecial #236                // Method dev/kosmx/aoc23/garden/RangeMapping."<init>":(Ljava/util/List;)V
     632: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     637: pop
     638: iinc          4, 1
     641: goto          309
     644: getstatic     #242                // Field java/lang/System.out:Ljava/io/PrintStream;
     647: aload_2
     648: invokevirtual #248                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     651: aload_1
     652: checkcast     #152                // class java/lang/Iterable
     655: astore        6
     657: iconst_0
     658: istore        7
     660: aload         6
     662: astore        8
     664: new           #154                // class java/util/ArrayList
     667: dup
     668: aload         6
     670: bipush        10
     672: invokestatic  #202                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     675: invokespecial #205                // Method java/util/ArrayList."<init>":(I)V
     678: checkcast     #158                // class java/util/Collection
     681: astore        9
     683: iconst_0
     684: istore        10
     686: aload         8
     688: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     693: astore        11
     695: aload         11
     697: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     702: ifeq          749
     705: aload         11
     707: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     712: astore        12
     714: aload         9
     716: aload         12
     718: checkcast     #24                 // class java/math/BigInteger
     721: astore        13
     723: astore        16
     725: iconst_0
     726: istore        14
     728: aload_2
     729: aload         13
     731: iconst_0
     732: iconst_2
     733: aconst_null
     734: invokestatic  #252                // Method get$default:(Ljava/util/List;Ljava/math/BigInteger;ZILjava/lang/Object;)Ljava/math/BigInteger;
     737: aload         16
     739: swap
     740: invokeinterface #184,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     745: pop
     746: goto          695
     749: aload         9
     751: checkcast     #124                // class java/util/List
     754: nop
     755: checkcast     #152                // class java/lang/Iterable
     758: invokestatic  #256                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     761: checkcast     #152                // class java/lang/Iterable
     764: invokestatic  #260                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     767: checkcast     #24                 // class java/math/BigInteger
     770: astore        5
     772: new           #262                // class java/lang/StringBuilder
     775: dup
     776: invokespecial #263                // Method java/lang/StringBuilder."<init>":()V
     779: ldc_w         #265                // String The lowest number Id is
     782: invokevirtual #269                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     785: aload         5
     787: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     790: invokevirtual #276                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     793: getstatic     #242                // Field java/lang/System.out:Ljava/io/PrintStream;
     796: swap
     797: invokevirtual #248                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     800: aload_2
     801: invokestatic  #280                // Method simplify:(Ljava/util/List;)Ldev/kosmx/aoc23/garden/RangeMapping;
     804: astore        6
     806: aload_0
     807: iconst_0
     808: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     813: checkcast     #175                // class java/lang/CharSequence
     816: iconst_1
     817: anewarray     #173                // class java/lang/String
     820: astore        8
     822: aload         8
     824: iconst_0
     825: ldc           #190                // String
     827: aastore
     828: aload         8
     830: iconst_0
     831: iconst_0
     832: bipush        6
     834: aconst_null
     835: invokestatic  #194                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     838: checkcast     #152                // class java/lang/Iterable
     841: invokestatic  #284                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     844: iconst_1
     845: invokestatic  #289                // Method kotlin/sequences/SequencesKt.drop:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
     848: invokedynamic #298,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function1;
     853: invokestatic  #302                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     856: iconst_2
     857: iconst_2
     858: iconst_0
     859: iconst_4
     860: aconst_null
     861: invokestatic  #306                // Method kotlin/sequences/SequencesKt.windowed$default:(Lkotlin/sequences/Sequence;IIZILjava/lang/Object;)Lkotlin/sequences/Sequence;
     864: invokedynamic #313,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function1;
     869: invokestatic  #302                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     872: astore        8
     874: nop
     875: iconst_0
     876: istore        9
     878: aload         8
     880: new           #315                // class dev/kosmx/aoc23/garden/VirtualMemoryKt$main$$inlined$sortedBy$1
     883: dup
     884: invokespecial #316                // Method dev/kosmx/aoc23/garden/VirtualMemoryKt$main$$inlined$sortedBy$1."<init>":()V
     887: checkcast     #318                // class java/util/Comparator
     890: invokestatic  #322                // Method kotlin/sequences/SequencesKt.sortedWith:(Lkotlin/sequences/Sequence;Ljava/util/Comparator;)Lkotlin/sequences/Sequence;
     893: invokestatic  #325                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     896: astore        7
     898: aconst_null
     899: astore        8
     901: aload         6
     903: aload         7
     905: iconst_0
     906: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     911: checkcast     #18                 // class kotlin/ranges/OpenEndRange
     914: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
     919: checkcast     #24                 // class java/math/BigInteger
     922: invokevirtual #327                // Method dev/kosmx/aoc23/garden/RangeMapping.get:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     925: astore        8
     927: aload         6
     929: invokevirtual #331                // Method dev/kosmx/aoc23/garden/RangeMapping.getRangesList:()Ljava/util/List;
     932: checkcast     #152                // class java/lang/Iterable
     935: invokestatic  #284                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     938: invokedynamic #338,  0            // InvokeDynamic #4:invoke:()Lkotlin/jvm/functions/Function1;
     943: invokestatic  #302                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     946: aload         7
     948: checkcast     #152                // class java/lang/Iterable
     951: invokestatic  #284                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     954: invokedynamic #344,  0            // InvokeDynamic #5:invoke:()Lkotlin/jvm/functions/Function1;
     959: invokestatic  #302                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     962: invokestatic  #348                // Method kotlin/sequences/SequencesKt.plus:(Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
     965: aload         7
     967: invokedynamic #357,  0            // InvokeDynamic #6:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     972: invokestatic  #360                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     975: astore        9
     977: nop
     978: iconst_0
     979: istore        10
     981: aload         9
     983: invokeinterface #363,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     988: astore        11
     990: aload         11
     992: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     997: ifeq          1049
    1000: aload         11
    1002: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1007: astore        12
    1009: aload         12
    1011: checkcast     #24                 // class java/math/BigInteger
    1014: astore        13
    1016: iconst_0
    1017: istore        14
    1019: aload_2
    1020: aload         13
    1022: iconst_0
    1023: iconst_2
    1024: aconst_null
    1025: invokestatic  #252                // Method get$default:(Ljava/util/List;Ljava/math/BigInteger;ZILjava/lang/Object;)Ljava/math/BigInteger;
    1028: astore        15
    1030: aload         15
    1032: aload         8
    1034: invokevirtual #134                // Method java/math/BigInteger.compareTo:(Ljava/math/BigInteger;)I
    1037: ifge          1044
    1040: aload         15
    1042: astore        8
    1044: nop
    1045: nop
    1046: goto          990
    1049: nop
    1050: new           #262                // class java/lang/StringBuilder
    1053: dup
    1054: invokespecial #263                // Method java/lang/StringBuilder."<init>":()V
    1057: ldc_w         #365                // String Part2:
    1060: invokevirtual #269                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
    1063: aload         8
    1065: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    1068: invokevirtual #276                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
    1071: getstatic     #242                // Field java/lang/System.out:Ljava/io/PrintStream;
    1074: swap
    1075: invokevirtual #248                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
    1078: return

  public static final dev.kosmx.aoc23.garden.RangeMapping simplify(java.util.List<dev.kosmx.aoc23.garden.RangeMapping>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #152                // class java/lang/Iterable
      10: astore_1
      11: new           #233                // class dev/kosmx/aoc23/garden/RangeMapping
      14: dup
      15: aconst_null
      16: iconst_1
      17: aconst_null
      18: invokespecial #408                // Method dev/kosmx/aoc23/garden/RangeMapping."<init>":(Ljava/util/List;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      21: astore_2
      22: iconst_0
      23: istore_3
      24: aload_2
      25: astore        4
      27: aload_1
      28: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        5
      35: aload         5
      37: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          80
      45: aload         5
      47: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        6
      54: aload         4
      56: aload         6
      58: checkcast     #233                // class dev/kosmx/aoc23/garden/RangeMapping
      61: astore        7
      63: astore        8
      65: iconst_0
      66: istore        9
      68: aload         8
      70: aload         7
      72: invokevirtual #411                // Method dev/kosmx/aoc23/garden/RangeMapping.plus:(Ldev/kosmx/aoc23/garden/RangeMapping;)Ldev/kosmx/aoc23/garden/RangeMapping;
      75: astore        4
      77: goto          35
      80: aload         4
      82: areturn

  public static final java.math.BigInteger get(java.util.List<dev.kosmx.aoc23.garden.RangeMapping>, java.math.BigInteger, boolean);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #70                 // String i
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: ifeq          23
      16: getstatic     #242                // Field java/lang/System.out:Ljava/io/PrintStream;
      19: aload_1
      20: invokevirtual #424                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
      23: aload_0
      24: checkcast     #152                // class java/lang/Iterable
      27: astore_3
      28: iconst_0
      29: istore        4
      31: aload_1
      32: astore        5
      34: aload_3
      35: invokeinterface #162,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #168,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          132
      52: aload         6
      54: invokeinterface #171,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         5
      63: aload         7
      65: checkcast     #233                // class dev/kosmx/aoc23/garden/RangeMapping
      68: astore        8
      70: astore        9
      72: iconst_0
      73: istore        10
      75: aload         8
      77: aload         9
      79: invokevirtual #327                // Method dev/kosmx/aoc23/garden/RangeMapping.get:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      82: astore        11
      84: aload         11
      86: astore        12
      88: iconst_0
      89: istore        13
      91: iload_2
      92: ifeq          123
      95: new           #262                // class java/lang/StringBuilder
      98: dup
      99: invokespecial #263                // Method java/lang/StringBuilder."<init>":()V
     102: ldc_w         #426                // String  ->
     105: invokevirtual #269                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     108: aload         12
     110: invokevirtual #272                // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     113: invokevirtual #276                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     116: getstatic     #242                // Field java/lang/System.out:Ljava/io/PrintStream;
     119: swap
     120: invokevirtual #424                // Method java/io/PrintStream.print:(Ljava/lang/Object;)V
     123: nop
     124: aload         11
     126: nop
     127: astore        5
     129: goto          42
     132: aload         5
     134: astore_3
     135: aload_3
     136: astore        4
     138: iconst_0
     139: istore        5
     141: iload_2
     142: ifeq          151
     145: getstatic     #242                // Field java/lang/System.out:Ljava/io/PrintStream;
     148: invokevirtual #428                // Method java/io/PrintStream.println:()V
     151: nop
     152: aload_3
     153: areturn

  public static java.math.BigInteger get$default(java.util.List, java.math.BigInteger, boolean, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_0
       7: istore_2
       8: aload_0
       9: aload_1
      10: iload_2
      11: invokestatic  #436                // Method get:(Ljava/util/List;Ljava/math/BigInteger;Z)Ljava/math/BigInteger;
      14: areturn

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

  private static final int binarySearch$lambda$0(java.math.BigInteger, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #443                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #446                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #18                 // class kotlin/ranges/OpenEndRange
      14: astore_2
      15: aload_2
      16: aload_0
      17: checkcast     #57                 // class java/lang/Comparable
      20: invokeinterface #119,  2          // InterfaceMethod kotlin/ranges/OpenEndRange.contains:(Ljava/lang/Comparable;)Z
      25: ifeq          32
      28: iconst_0
      29: goto          45
      32: aload_2
      33: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      38: checkcast     #24                 // class java/math/BigInteger
      41: aload_0
      42: invokevirtual #134                // Method java/math/BigInteger.compareTo:(Ljava/math/BigInteger;)I
      45: ireturn

  private static final int contains$lambda$1(java.math.BigInteger, kotlin.ranges.OpenEndRange);
    Code:
       0: aload_1
       1: ldc_w         #448                // String range
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: aload_0
       9: checkcast     #57                 // class java/lang/Comparable
      12: invokeinterface #119,  2          // InterfaceMethod kotlin/ranges/OpenEndRange.contains:(Ljava/lang/Comparable;)Z
      17: ifeq          24
      20: iconst_0
      21: goto          37
      24: aload_1
      25: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      30: checkcast     #24                 // class java/math/BigInteger
      33: aload_0
      34: invokevirtual #134                // Method java/math/BigInteger.compareTo:(Ljava/math/BigInteger;)I
      37: ireturn

  private static final java.math.BigInteger main$lambda$6(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #450                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #24                 // class java/math/BigInteger
      10: dup
      11: aload_0
      12: invokespecial #206                // Method java/math/BigInteger."<init>":(Ljava/lang/String;)V
      15: areturn

  private static final kotlin.ranges.OpenEndRange main$lambda$7(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #443                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: iconst_0
       9: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      14: checkcast     #24                 // class java/math/BigInteger
      17: astore_1
      18: aload_0
      19: iconst_1
      20: invokeinterface #188,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      25: checkcast     #24                 // class java/math/BigInteger
      28: astore_2
      29: aload_1
      30: checkcast     #57                 // class java/lang/Comparable
      33: aload_1
      34: aload_2
      35: invokevirtual #53                 // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      38: dup
      39: ldc           #55                 // String add(...)
      41: invokestatic  #36                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      44: checkcast     #57                 // class java/lang/Comparable
      47: invokestatic  #63                 // Method kotlin/ranges/RangesKt.rangeUntil:(Ljava/lang/Comparable;Ljava/lang/Comparable;)Lkotlin/ranges/OpenEndRange;
      50: areturn

  private static final java.math.BigInteger main$lambda$9(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc_w         #450                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #47                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      11: checkcast     #18                 // class kotlin/ranges/OpenEndRange
      14: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      19: checkcast     #24                 // class java/math/BigInteger
      22: areturn

  private static final java.math.BigInteger main$lambda$10(kotlin.ranges.OpenEndRange);
    Code:
       0: aload_0
       1: ldc_w         #450                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #27,  1           // InterfaceMethod kotlin/ranges/OpenEndRange.getStart:()Ljava/lang/Comparable;
      13: checkcast     #24                 // class java/math/BigInteger
      16: areturn

  private static final boolean main$lambda$11(java.util.List, java.math.BigInteger);
    Code:
       0: aload_1
       1: ldc_w         #450                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: aload_1
       9: invokestatic  #454                // Method contains:(Ljava/util/List;Ljava/math/BigInteger;)Z
      12: ireturn
}


package dev.kosmx.aoc23.stars

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

operator fun MutableList<MutableList<Char>>.get(x: Int, y: Int): Char {
    return this[y][x]
}

fun <T> List<T>.allPairings() = sequence {
    for (a in indices) {
        for (b in a + 1 ..< size) {
            yield(get(a) to get(b))
        }
    }
}

fun main() {
    val starMap = File("stars.txt").useLines {
        it.map { it.toCharArray().toMutableList() }.toMutableList()
    }

    // insert rows
    for (x in starMap.indices.reversed()) {
        if (starMap.all { it[x] == '.' }) {
            starMap.forEach {
                it.add(x, '+')
            }
        }
    }

    // insert columns
    for (y in starMap.indices.reversed()) {
        if (starMap[y].all { it == '.' || it == '+' }) {
            starMap.add(y, MutableList(starMap[y].size) { '+' })
        }
    }

    // print map for debug
    //*
    starMap.forEach {
        println(it.joinToString(""))
    }// */

    // collect stars
    val stars = mutableListOf<Pair<Int, Int>>()
    for (y in starMap.indices) {
        for (x in starMap[y].indices) {
            if (starMap[x, y] == '#') {
                stars.add(x to y)
            }
        }
    }

    val distances = stars.allPairings().map { (a, b) ->
        abs(a.first - b.first) + abs(a.second - b.second)
    }.toList()

    println(distances.fold(BigInteger.ZERO) { acc, i -> acc + i.toBigInteger() })

    // now part 2

    val distances2 = stars.allPairings().map { (a, b) ->
        var holes = 0
        for (i in a.first progress b.first) {
            if (starMap[i, a.second] == '+') {
                holes++
            }
        }
        for (i in a.second progress b.second) {
            if (starMap[b.first, i] == '+') {
                holes++
            }
        }
        abs(a.first - b.first) + abs(a.second - b.second) + (holes*(1000000-2))
    }.toList()

    println(distances2.fold(BigInteger.ZERO) { acc, i -> acc + i.toBigInteger() })

}

private infix fun Int.progress(first: Int): IntProgression {
    return if (this < first) {
        first downTo this
    } else {
        first..this
    }
}

Compiled from "StarField.kt"
public final class dev.kosmx.aoc23.stars.StarFieldKt {
  public static final char get(java.util.List<java.util.List<java.lang.Character>>, int, int);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iload_2
       8: invokeinterface #21,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      13: checkcast     #18                 // class java/util/List
      16: iload_1
      17: invokeinterface #21,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: checkcast     #23                 // class java/lang/Character
      25: invokevirtual #27                 // Method java/lang/Character.charValue:()C
      28: ireturn

  public static final <T> kotlin.sequences.Sequence<kotlin.Pair<T, T>> allPairings(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #37                 // class dev/kosmx/aoc23/stars/StarFieldKt$allPairings$1
       9: dup
      10: aload_0
      11: aconst_null
      12: invokespecial #41                 // Method dev/kosmx/aoc23/stars/StarFieldKt$allPairings$1."<init>":(Ljava/util/List;Lkotlin/coroutines/Continuation;)V
      15: checkcast     #43                 // class kotlin/jvm/functions/Function2
      18: invokestatic  #49                 // Method kotlin/sequences/SequencesKt.sequence:(Lkotlin/jvm/functions/Function2;)Lkotlin/sequences/Sequence;
      21: areturn

  public static final void main();
    Code:
       0: new           #56                 // class java/io/File
       3: dup
       4: ldc           #58                 // String stars.txt
       6: invokespecial #61                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: getstatic     #67                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_1
      17: astore        4
      19: sipush        8192
      22: istore        5
      24: aload         4
      26: astore        6
      28: new           #69                 // class java/io/InputStreamReader
      31: dup
      32: new           #71                 // class java/io/FileInputStream
      35: dup
      36: aload         6
      38: invokespecial #74                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      41: checkcast     #76                 // class java/io/InputStream
      44: aload_2
      45: invokespecial #79                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      48: checkcast     #81                 // class java/io/Reader
      51: astore        6
      53: aload         6
      55: instanceof    #83                 // class java/io/BufferedReader
      58: ifeq          69
      61: aload         6
      63: checkcast     #83                 // class java/io/BufferedReader
      66: goto          80
      69: new           #83                 // class java/io/BufferedReader
      72: dup
      73: aload         6
      75: iload         5
      77: invokespecial #86                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      80: checkcast     #88                 // class java/io/Closeable
      83: astore        4
      85: aconst_null
      86: astore        5
      88: nop
      89: aload         4
      91: checkcast     #83                 // class java/io/BufferedReader
      94: astore        6
      96: iconst_0
      97: istore        7
      99: aload         6
     101: invokestatic  #94                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     104: astore        8
     106: iconst_0
     107: istore        9
     109: aload         8
     111: invokedynamic #113,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
     116: invokestatic  #117                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     119: invokestatic  #121                // Method kotlin/sequences/SequencesKt.toMutableList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     122: astore        6
     124: aload         4
     126: aload         5
     128: invokestatic  #127                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     131: aload         6
     133: goto          157
     136: astore        7
     138: aload         7
     140: astore        5
     142: aload         7
     144: athrow
     145: astore        7
     147: aload         4
     149: aload         5
     151: invokestatic  #127                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     154: aload         7
     156: athrow
     157: nop
     158: astore_0
     159: aload_0
     160: checkcast     #129                // class java/util/Collection
     163: invokeinterface #133,  1          // InterfaceMethod java/util/Collection.size:()I
     168: iconst_m1
     169: iadd
     170: istore_1
     171: iconst_0
     172: iload_1
     173: if_icmpgt     353
     176: iload_1
     177: istore_2
     178: iinc          1, -1
     181: aload_0
     182: checkcast     #135                // class java/lang/Iterable
     185: astore_3
     186: iconst_0
     187: istore        4
     189: aload_3
     190: instanceof    #129                // class java/util/Collection
     193: ifeq          212
     196: aload_3
     197: checkcast     #129                // class java/util/Collection
     200: invokeinterface #139,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     205: ifeq          212
     208: iconst_1
     209: goto          281
     212: aload_3
     213: invokeinterface #143,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     218: astore        5
     220: aload         5
     222: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     227: ifeq          280
     230: aload         5
     232: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     237: astore        6
     239: aload         6
     241: checkcast     #18                 // class java/util/List
     244: astore        7
     246: iconst_0
     247: istore        8
     249: aload         7
     251: iload_2
     252: invokeinterface #21,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     257: checkcast     #23                 // class java/lang/Character
     260: invokevirtual #27                 // Method java/lang/Character.charValue:()C
     263: bipush        46
     265: if_icmpne     272
     268: iconst_1
     269: goto          273
     272: iconst_0
     273: ifne          220
     276: iconst_0
     277: goto          281
     280: iconst_1
     281: ifeq          348
     284: aload_0
     285: checkcast     #135                // class java/lang/Iterable
     288: astore_3
     289: iconst_0
     290: istore        4
     292: aload_3
     293: invokeinterface #143,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     298: astore        5
     300: aload         5
     302: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     307: ifeq          347
     310: aload         5
     312: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     317: astore        6
     319: aload         6
     321: checkcast     #18                 // class java/util/List
     324: astore        7
     326: iconst_0
     327: istore        8
     329: aload         7
     331: iload_2
     332: bipush        43
     334: invokestatic  #156                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     337: invokeinterface #160,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     342: nop
     343: nop
     344: goto          300
     347: nop
     348: iconst_0
     349: iload_1
     350: if_icmple     176
     353: aload_0
     354: checkcast     #129                // class java/util/Collection
     357: invokeinterface #133,  1          // InterfaceMethod java/util/Collection.size:()I
     362: iconst_m1
     363: iadd
     364: istore_1
     365: iconst_0
     366: iload_1
     367: if_icmpgt     579
     370: iload_1
     371: istore_2
     372: iinc          1, -1
     375: aload_0
     376: iload_2
     377: invokeinterface #21,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     382: checkcast     #135                // class java/lang/Iterable
     385: astore_3
     386: iconst_0
     387: istore        4
     389: aload_3
     390: instanceof    #129                // class java/util/Collection
     393: ifeq          412
     396: aload_3
     397: checkcast     #129                // class java/util/Collection
     400: invokeinterface #139,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     405: ifeq          412
     408: iconst_1
     409: goto          479
     412: aload_3
     413: invokeinterface #143,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     418: astore        5
     420: aload         5
     422: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     427: ifeq          478
     430: aload         5
     432: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     437: astore        6
     439: aload         6
     441: checkcast     #23                 // class java/lang/Character
     444: invokevirtual #27                 // Method java/lang/Character.charValue:()C
     447: istore        7
     449: iconst_0
     450: istore        8
     452: iload         7
     454: bipush        46
     456: if_icmpeq     466
     459: iload         7
     461: bipush        43
     463: if_icmpne     470
     466: iconst_1
     467: goto          471
     470: iconst_0
     471: ifne          420
     474: iconst_0
     475: goto          479
     478: iconst_1
     479: ifeq          574
     482: aload_0
     483: iload_2
     484: aload_0
     485: iload_2
     486: invokeinterface #21,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     491: checkcast     #18                 // class java/util/List
     494: invokeinterface #161,  1          // InterfaceMethod java/util/List.size:()I
     499: istore_3
     500: istore        14
     502: astore        13
     504: new           #163                // class java/util/ArrayList
     507: dup
     508: iload_3
     509: invokespecial #166                // Method java/util/ArrayList."<init>":(I)V
     512: astore        4
     514: iconst_0
     515: istore        5
     517: iload         5
     519: iload_3
     520: if_icmpge     556
     523: iload         5
     525: istore        6
     527: aload         4
     529: iload         6
     531: istore        7
     533: astore        15
     535: iconst_0
     536: istore        8
     538: bipush        43
     540: invokestatic  #156                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     543: aload         15
     545: swap
     546: invokevirtual #169                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     549: pop
     550: iinc          5, 1
     553: goto          517
     556: aload         4
     558: checkcast     #18                 // class java/util/List
     561: astore        15
     563: aload         13
     565: iload         14
     567: aload         15
     569: invokeinterface #160,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
     574: iconst_0
     575: iload_1
     576: if_icmple     370
     579: aload_0
     580: checkcast     #135                // class java/lang/Iterable
     583: astore_1
     584: iconst_0
     585: istore_2
     586: aload_1
     587: invokeinterface #143,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     592: astore_3
     593: aload_3
     594: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     599: ifeq          653
     602: aload_3
     603: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     608: astore        4
     610: aload         4
     612: checkcast     #18                 // class java/util/List
     615: astore        5
     617: iconst_0
     618: istore        6
     620: aload         5
     622: checkcast     #135                // class java/lang/Iterable
     625: ldc           #171                // String
     627: checkcast     #173                // class java/lang/CharSequence
     630: aconst_null
     631: aconst_null
     632: iconst_0
     633: aconst_null
     634: aconst_null
     635: bipush        62
     637: aconst_null
     638: invokestatic  #179                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     641: getstatic     #185                // Field java/lang/System.out:Ljava/io/PrintStream;
     644: swap
     645: invokevirtual #191                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     648: nop
     649: nop
     650: goto          593
     653: nop
     654: new           #163                // class java/util/ArrayList
     657: dup
     658: invokespecial #193                // Method java/util/ArrayList."<init>":()V
     661: checkcast     #18                 // class java/util/List
     664: astore_1
     665: iconst_0
     666: istore_2
     667: aload_0
     668: checkcast     #129                // class java/util/Collection
     671: invokeinterface #133,  1          // InterfaceMethod java/util/Collection.size:()I
     676: istore_3
     677: iload_2
     678: iload_3
     679: if_icmpge     752
     682: iconst_0
     683: istore        4
     685: aload_0
     686: iload_2
     687: invokeinterface #21,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     692: checkcast     #129                // class java/util/Collection
     695: invokeinterface #133,  1          // InterfaceMethod java/util/Collection.size:()I
     700: istore        5
     702: iload         4
     704: iload         5
     706: if_icmpge     746
     709: aload_0
     710: iload         4
     712: iload_2
     713: invokestatic  #195                // Method get:(Ljava/util/List;II)C
     716: bipush        35
     718: if_icmpne     740
     721: aload_1
     722: iload         4
     724: invokestatic  #200                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     727: iload_2
     728: invokestatic  #200                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     731: invokestatic  #206                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     734: invokeinterface #207,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     739: pop
     740: iinc          4, 1
     743: goto          702
     746: iinc          2, 1
     749: goto          677
     752: aload_1
     753: invokestatic  #209                // Method allPairings:(Ljava/util/List;)Lkotlin/sequences/Sequence;
     756: invokedynamic #217,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     761: invokestatic  #117                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     764: invokestatic  #220                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     767: astore_2
     768: aload_2
     769: checkcast     #135                // class java/lang/Iterable
     772: astore_3
     773: getstatic     #226                // Field java/math/BigInteger.ZERO:Ljava/math/BigInteger;
     776: astore        4
     778: iconst_0
     779: istore        5
     781: aload         4
     783: astore        6
     785: aload_3
     786: invokeinterface #143,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     791: astore        7
     793: aload         7
     795: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     800: ifeq          864
     803: aload         7
     805: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     810: astore        8
     812: aload         6
     814: aload         8
     816: checkcast     #228                // class java/lang/Number
     819: invokevirtual #231                // Method java/lang/Number.intValue:()I
     822: istore        9
     824: astore        10
     826: iconst_0
     827: istore        11
     829: nop
     830: aload         10
     832: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     835: aload         10
     837: iload         9
     839: i2l
     840: invokestatic  #237                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     843: dup
     844: ldc           #239                // String valueOf(...)
     846: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     849: invokevirtual #245                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     852: dup
     853: ldc           #247                // String add(...)
     855: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     858: nop
     859: astore        6
     861: goto          793
     864: aload         6
     866: astore_3
     867: getstatic     #185                // Field java/lang/System.out:Ljava/io/PrintStream;
     870: aload_3
     871: invokevirtual #191                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     874: aload_1
     875: invokestatic  #209                // Method allPairings:(Ljava/util/List;)Lkotlin/sequences/Sequence;
     878: aload_0
     879: invokedynamic #255,  0            // InvokeDynamic #2:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     884: invokestatic  #117                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
     887: invokestatic  #220                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
     890: astore_3
     891: aload_3
     892: checkcast     #135                // class java/lang/Iterable
     895: astore        4
     897: getstatic     #226                // Field java/math/BigInteger.ZERO:Ljava/math/BigInteger;
     900: astore        5
     902: iconst_0
     903: istore        6
     905: aload         5
     907: astore        7
     909: aload         4
     911: invokeinterface #143,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     916: astore        8
     918: aload         8
     920: invokeinterface #148,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     925: ifeq          989
     928: aload         8
     930: invokeinterface #152,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     935: astore        9
     937: aload         7
     939: aload         9
     941: checkcast     #228                // class java/lang/Number
     944: invokevirtual #231                // Method java/lang/Number.intValue:()I
     947: istore        10
     949: astore        11
     951: iconst_0
     952: istore        12
     954: nop
     955: aload         11
     957: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     960: aload         11
     962: iload         10
     964: i2l
     965: invokestatic  #237                // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
     968: dup
     969: ldc           #239                // String valueOf(...)
     971: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     974: invokevirtual #245                // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
     977: dup
     978: ldc           #247                // String add(...)
     980: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     983: nop
     984: astore        7
     986: goto          918
     989: aload         7
     991: astore        4
     993: getstatic     #185                // Field java/lang/System.out:Ljava/io/PrintStream;
     996: aload         4
     998: invokevirtual #191                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
    1001: return
    Exception table:
       from    to  target type
          88   124   136   Class java/lang/Throwable
          88   124   145   any
         136   145   145   any
         145   147   145   any

  private static final kotlin.ranges.IntProgression progress(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: if_icmpge     13
       5: iload_1
       6: iload_0
       7: invokestatic  #301                // Method kotlin/ranges/RangesKt.downTo:(II)Lkotlin/ranges/IntProgression;
      10: goto          25
      13: new           #303                // class kotlin/ranges/IntRange
      16: dup
      17: iload_1
      18: iload_0
      19: invokespecial #306                // Method kotlin/ranges/IntRange."<init>":(II)V
      22: checkcast     #308                // class kotlin/ranges/IntProgression
      25: areturn

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

  private static final java.util.List main$lambda$1$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #316                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #322                // Method java/lang/String.toCharArray:()[C
      11: dup
      12: ldc_w         #324                // String toCharArray(...)
      15: invokestatic  #242                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: invokestatic  #329                // Method kotlin/collections/ArraysKt.toMutableList:([C)Ljava/util/List;
      21: areturn

  private static final int main$lambda$7(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc_w         #332                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #337                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #334                // class kotlin/Pair
      14: astore_1
      15: aload_0
      16: invokevirtual #340                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      19: checkcast     #334                // class kotlin/Pair
      22: astore_2
      23: aload_1
      24: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      27: checkcast     #228                // class java/lang/Number
      30: invokevirtual #231                // Method java/lang/Number.intValue:()I
      33: aload_2
      34: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      37: checkcast     #228                // class java/lang/Number
      40: invokevirtual #231                // Method java/lang/Number.intValue:()I
      43: isub
      44: invokestatic  #349                // Method java/lang/Math.abs:(I)I
      47: aload_1
      48: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      51: checkcast     #228                // class java/lang/Number
      54: invokevirtual #231                // Method java/lang/Number.intValue:()I
      57: aload_2
      58: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      61: checkcast     #228                // class java/lang/Number
      64: invokevirtual #231                // Method java/lang/Number.intValue:()I
      67: isub
      68: invokestatic  #349                // Method java/lang/Math.abs:(I)I
      71: iadd
      72: ireturn

  private static final int main$lambda$9(java.util.List, kotlin.Pair);
    Code:
       0: aload_1
       1: ldc_w         #332                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #337                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      11: checkcast     #334                // class kotlin/Pair
      14: astore_2
      15: aload_1
      16: invokevirtual #340                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      19: checkcast     #334                // class kotlin/Pair
      22: astore_3
      23: iconst_0
      24: istore        4
      26: aload_2
      27: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      30: checkcast     #228                // class java/lang/Number
      33: invokevirtual #231                // Method java/lang/Number.intValue:()I
      36: aload_3
      37: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      40: checkcast     #228                // class java/lang/Number
      43: invokevirtual #231                // Method java/lang/Number.intValue:()I
      46: invokestatic  #357                // Method progress:(II)Lkotlin/ranges/IntProgression;
      49: astore        5
      51: aload         5
      53: invokevirtual #359                // Method kotlin/ranges/IntProgression.getFirst:()I
      56: istore        6
      58: aload         5
      60: invokevirtual #362                // Method kotlin/ranges/IntProgression.getLast:()I
      63: istore        7
      65: aload         5
      67: invokevirtual #365                // Method kotlin/ranges/IntProgression.getStep:()I
      70: istore        8
      72: iload         8
      74: ifle          84
      77: iload         6
      79: iload         7
      81: if_icmple     96
      84: iload         8
      86: ifge          137
      89: iload         7
      91: iload         6
      93: if_icmpgt     137
      96: aload_0
      97: iload         6
      99: aload_2
     100: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     103: checkcast     #228                // class java/lang/Number
     106: invokevirtual #231                // Method java/lang/Number.intValue:()I
     109: invokestatic  #195                // Method get:(Ljava/util/List;II)C
     112: bipush        43
     114: if_icmpne     120
     117: iinc          4, 1
     120: iload         6
     122: iload         7
     124: if_icmpeq     137
     127: iload         6
     129: iload         8
     131: iadd
     132: istore        6
     134: goto          96
     137: aload_2
     138: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     141: checkcast     #228                // class java/lang/Number
     144: invokevirtual #231                // Method java/lang/Number.intValue:()I
     147: aload_3
     148: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     151: checkcast     #228                // class java/lang/Number
     154: invokevirtual #231                // Method java/lang/Number.intValue:()I
     157: invokestatic  #357                // Method progress:(II)Lkotlin/ranges/IntProgression;
     160: astore        5
     162: aload         5
     164: invokevirtual #359                // Method kotlin/ranges/IntProgression.getFirst:()I
     167: istore        6
     169: aload         5
     171: invokevirtual #362                // Method kotlin/ranges/IntProgression.getLast:()I
     174: istore        7
     176: aload         5
     178: invokevirtual #365                // Method kotlin/ranges/IntProgression.getStep:()I
     181: istore        8
     183: iload         8
     185: ifle          195
     188: iload         6
     190: iload         7
     192: if_icmple     207
     195: iload         8
     197: ifge          248
     200: iload         7
     202: iload         6
     204: if_icmpgt     248
     207: aload_0
     208: aload_3
     209: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     212: checkcast     #228                // class java/lang/Number
     215: invokevirtual #231                // Method java/lang/Number.intValue:()I
     218: iload         6
     220: invokestatic  #195                // Method get:(Ljava/util/List;II)C
     223: bipush        43
     225: if_icmpne     231
     228: iinc          4, 1
     231: iload         6
     233: iload         7
     235: if_icmpeq     248
     238: iload         6
     240: iload         8
     242: iadd
     243: istore        6
     245: goto          207
     248: aload_2
     249: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     252: checkcast     #228                // class java/lang/Number
     255: invokevirtual #231                // Method java/lang/Number.intValue:()I
     258: aload_3
     259: invokevirtual #343                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     262: checkcast     #228                // class java/lang/Number
     265: invokevirtual #231                // Method java/lang/Number.intValue:()I
     268: isub
     269: invokestatic  #349                // Method java/lang/Math.abs:(I)I
     272: aload_2
     273: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     276: checkcast     #228                // class java/lang/Number
     279: invokevirtual #231                // Method java/lang/Number.intValue:()I
     282: aload_3
     283: invokevirtual #352                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     286: checkcast     #228                // class java/lang/Number
     289: invokevirtual #231                // Method java/lang/Number.intValue:()I
     292: isub
     293: invokestatic  #349                // Method java/lang/Math.abs:(I)I
     296: iadd
     297: iload         4
     299: ldc_w         #366                // int 999998
     302: imul
     303: iadd
     304: ireturn
}

Compiled from "StarField.kt"
final class dev.kosmx.aoc23.stars.StarFieldKt$allPairings$1 extends kotlin.coroutines.jvm.internal.RestrictedSuspendLambda implements kotlin.jvm.functions.Function2<kotlin.sequences.SequenceScope<? super kotlin.Pair<? extends T, ? extends T>>, kotlin.coroutines.Continuation<? super kotlin.Unit>, java.lang.Object> {
  int I$0;

  int I$1;

  int I$2;

  int I$3;

  int label;

  private java.lang.Object L$0;

  final java.util.List<T> $this_allPairings;

  dev.kosmx.aoc23.stars.StarFieldKt$allPairings$1(java.util.List<? extends T>, kotlin.coroutines.Continuation<? super dev.kosmx.aoc23.stars.StarFieldKt$allPairings$1>);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #14                 // Field $this_allPairings:Ljava/util/List;
       5: aload_0
       6: iconst_2
       7: aload_2
       8: invokespecial #17                 // Method kotlin/coroutines/jvm/internal/RestrictedSuspendLambda."<init>":(ILkotlin/coroutines/Continuation;)V
      11: return

  public final java.lang.Object invokeSuspend(java.lang.Object);
    Code:
       0: invokestatic  #51                 // Method kotlin/coroutines/intrinsics/IntrinsicsKt.getCOROUTINE_SUSPENDED:()Ljava/lang/Object;
       3: astore        7
       5: aload_0
       6: getfield      #54                 // Field label:I
       9: tableswitch   { // 0 to 1
                     0: 32
                     1: 163
               default: 216
          }
      32: aload_1
      33: invokestatic  #60                 // Method kotlin/ResultKt.throwOnFailure:(Ljava/lang/Object;)V
      36: aload_0
      37: getfield      #63                 // Field L$0:Ljava/lang/Object;
      40: checkcast     #65                 // class kotlin/sequences/SequenceScope
      43: astore_2
      44: iconst_0
      45: istore_3
      46: aload_0
      47: getfield      #14                 // Field $this_allPairings:Ljava/util/List;
      50: checkcast     #67                 // class java/util/Collection
      53: invokeinterface #71,  1           // InterfaceMethod java/util/Collection.size:()I
      58: istore        4
      60: iload_3
      61: iload         4
      63: if_icmpge     212
      66: iload_3
      67: iconst_1
      68: iadd
      69: istore        5
      71: aload_0
      72: getfield      #14                 // Field $this_allPairings:Ljava/util/List;
      75: invokeinterface #74,  1           // InterfaceMethod java/util/List.size:()I
      80: istore        6
      82: iload         5
      84: iload         6
      86: if_icmpge     206
      89: aload_2
      90: aload_0
      91: getfield      #14                 // Field $this_allPairings:Ljava/util/List;
      94: iload_3
      95: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     100: aload_0
     101: getfield      #14                 // Field $this_allPairings:Ljava/util/List;
     104: iload         5
     106: invokeinterface #78,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     111: invokestatic  #84                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     114: aload_0
     115: checkcast     #86                 // class kotlin/coroutines/Continuation
     118: aload_0
     119: aload_2
     120: putfield      #63                 // Field L$0:Ljava/lang/Object;
     123: aload_0
     124: iload_3
     125: putfield      #88                 // Field I$0:I
     128: aload_0
     129: iload         4
     131: putfield      #90                 // Field I$1:I
     134: aload_0
     135: iload         5
     137: putfield      #92                 // Field I$2:I
     140: aload_0
     141: iload         6
     143: putfield      #94                 // Field I$3:I
     146: aload_0
     147: iconst_1
     148: putfield      #54                 // Field label:I
     151: invokevirtual #98                 // Method kotlin/sequences/SequenceScope.yield:(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
     154: dup
     155: aload         7
     157: if_acmpne     199
     160: aload         7
     162: areturn
     163: aload_0
     164: getfield      #94                 // Field I$3:I
     167: istore        6
     169: aload_0
     170: getfield      #92                 // Field I$2:I
     173: istore        5
     175: aload_0
     176: getfield      #90                 // Field I$1:I
     179: istore        4
     181: aload_0
     182: getfield      #88                 // Field I$0:I
     185: istore_3
     186: aload_0
     187: getfield      #63                 // Field L$0:Ljava/lang/Object;
     190: checkcast     #65                 // class kotlin/sequences/SequenceScope
     193: astore_2
     194: aload_1
     195: invokestatic  #60                 // Method kotlin/ResultKt.throwOnFailure:(Ljava/lang/Object;)V
     198: aload_1
     199: pop
     200: iinc          5, 1
     203: goto          82
     206: iinc          3, 1
     209: goto          60
     212: getstatic     #104                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     215: areturn
     216: new           #106                // class java/lang/IllegalStateException
     219: dup
     220: ldc           #108                // String call to \'resume\' before \'invoke\' with coroutine
     222: invokespecial #111                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     225: athrow

  public final kotlin.coroutines.Continuation<kotlin.Unit> create(java.lang.Object, kotlin.coroutines.Continuation<?>);
    Code:
       0: new           #2                  // class dev/kosmx/aoc23/stars/StarFieldKt$allPairings$1
       3: dup
       4: aload_0
       5: getfield      #14                 // Field $this_allPairings:Ljava/util/List;
       8: aload_2
       9: invokespecial #120                // Method "<init>":(Ljava/util/List;Lkotlin/coroutines/Continuation;)V
      12: astore_3
      13: aload_3
      14: aload_1
      15: putfield      #63                 // Field L$0:Ljava/lang/Object;
      18: aload_3
      19: checkcast     #86                 // class kotlin/coroutines/Continuation
      22: areturn

  public final java.lang.Object invoke(kotlin.sequences.SequenceScope<? super kotlin.Pair<? extends T, ? extends T>>, kotlin.coroutines.Continuation<? super kotlin.Unit>);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokevirtual #126                // Method create:(Ljava/lang/Object;Lkotlin/coroutines/Continuation;)Lkotlin/coroutines/Continuation;
       6: checkcast     #2                  // class dev/kosmx/aoc23/stars/StarFieldKt$allPairings$1
       9: getstatic     #104                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      12: invokevirtual #128                // Method invokeSuspend:(Ljava/lang/Object;)Ljava/lang/Object;
      15: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #65                 // class kotlin/sequences/SequenceScope
       5: aload_2
       6: checkcast     #86                 // class kotlin/coroutines/Continuation
       9: invokevirtual #133                // Method invoke:(Lkotlin/sequences/SequenceScope;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
      12: areturn
}