fun main() {
    val testInput = readInput("Day04_test")
    check(part1(testInput) == 2)
    check(part2(testInput) == 4)

    val input = readInput("Day04")
    println(part1(input))
    println(part2(input))
}

private fun part1(input: List<String>): Int {
    return input
        .map(String::parseSectionRanges)
        .count { it.first in it.second || it.second in it.first }
}

private fun part2(input: List<String>): Int {
    return input
        .map(String::parseSectionRanges)
        .count { it.first.first in it.second || it.second.first in it.first }
}

private val ROW_FORMAT = Regex("(\\d+)-(\\d+),(\\d+)-(\\d+)")

private fun String.parseSectionRanges(): Pair<IntRange, IntRange> {
    val match = ROW_FORMAT.find(this)
    val (a, b, c, d) = requireNotNull(match).destructured
    return IntRange(a.toInt(), b.toInt()) to IntRange(c.toInt(), d.toInt())
}

Compiled from "Day04.kt"
public final class Day04Kt {
  private static final kotlin.text.Regex ROW_FORMAT;

  public static final void main();
    Code:
       0: ldc           #8                  // String Day04_test
       2: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #18                 // Method part1:(Ljava/util/List;)I
      10: iconst_2
      11: if_icmpne     18
      14: iconst_1
      15: goto          19
      18: iconst_0
      19: ifne          32
      22: new           #20                 // class java/lang/IllegalStateException
      25: dup
      26: ldc           #22                 // String Check failed.
      28: invokespecial #26                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      31: athrow
      32: aload_0
      33: invokestatic  #29                 // Method part2:(Ljava/util/List;)I
      36: iconst_4
      37: if_icmpne     44
      40: iconst_1
      41: goto          45
      44: iconst_0
      45: ifne          58
      48: new           #20                 // class java/lang/IllegalStateException
      51: dup
      52: ldc           #22                 // String Check failed.
      54: invokespecial #26                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      57: athrow
      58: ldc           #31                 // String Day04
      60: invokestatic  #14                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      63: astore_1
      64: aload_1
      65: invokestatic  #18                 // Method part1:(Ljava/util/List;)I
      68: istore_2
      69: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
      72: iload_2
      73: invokevirtual #43                 // Method java/io/PrintStream.println:(I)V
      76: aload_1
      77: invokestatic  #29                 // Method part2:(Ljava/util/List;)I
      80: istore_2
      81: getstatic     #37                 // Field java/lang/System.out:Ljava/io/PrintStream;
      84: iload_2
      85: invokevirtual #43                 // Method java/io/PrintStream.println:(I)V
      88: return

  private static final int part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #51                 // class java/lang/Iterable
       4: astore_1
       5: nop
       6: iconst_0
       7: istore_2
       8: aload_1
       9: astore_3
      10: new           #53                 // class java/util/ArrayList
      13: dup
      14: aload_1
      15: bipush        10
      17: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #61                 // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #63                 // class java/util/Collection
      26: astore        4
      28: iconst_0
      29: istore        5
      31: aload_3
      32: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        6
      39: aload         6
      41: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          89
      49: aload         6
      51: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        7
      58: aload         4
      60: aload         7
      62: checkcast     #79                 // class java/lang/String
      65: astore        8
      67: astore        10
      69: iconst_0
      70: istore        9
      72: aload         8
      74: invokestatic  #83                 // Method parseSectionRanges:(Ljava/lang/String;)Lkotlin/Pair;
      77: aload         10
      79: swap
      80: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      85: pop
      86: goto          39
      89: aload         4
      91: checkcast     #48                 // class java/util/List
      94: nop
      95: checkcast     #51                 // class java/lang/Iterable
      98: astore_1
      99: nop
     100: iconst_0
     101: istore_2
     102: aload_1
     103: instanceof    #63                 // class java/util/Collection
     106: ifeq          125
     109: aload_1
     110: checkcast     #63                 // class java/util/Collection
     113: invokeinterface #90,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     118: ifeq          125
     121: iconst_0
     122: goto          230
     125: iconst_0
     126: istore_3
     127: aload_1
     128: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        4
     135: aload         4
     137: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          229
     145: aload         4
     147: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        5
     154: aload         5
     156: checkcast     #92                 // class kotlin/Pair
     159: astore        6
     161: iconst_0
     162: istore        7
     164: aload         6
     166: invokevirtual #95                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     169: checkcast     #97                 // class kotlin/ranges/IntRange
     172: aload         6
     174: invokevirtual #100                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     177: checkcast     #97                 // class kotlin/ranges/IntRange
     180: invokestatic  #104                // Method UtilsKt.contains:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Z
     183: ifne          208
     186: aload         6
     188: invokevirtual #100                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     191: checkcast     #97                 // class kotlin/ranges/IntRange
     194: aload         6
     196: invokevirtual #95                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     199: checkcast     #97                 // class kotlin/ranges/IntRange
     202: invokestatic  #104                // Method UtilsKt.contains:(Lkotlin/ranges/IntRange;Lkotlin/ranges/IntRange;)Z
     205: ifeq          212
     208: iconst_1
     209: goto          213
     212: iconst_0
     213: ifeq          135
     216: iinc          3, 1
     219: iload_3
     220: ifge          135
     223: invokestatic  #107                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     226: goto          135
     229: iload_3
     230: ireturn

  private static final int part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #51                 // class java/lang/Iterable
       4: astore_1
       5: nop
       6: iconst_0
       7: istore_2
       8: aload_1
       9: astore_3
      10: new           #53                 // class java/util/ArrayList
      13: dup
      14: aload_1
      15: bipush        10
      17: invokestatic  #59                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #61                 // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #63                 // class java/util/Collection
      26: astore        4
      28: iconst_0
      29: istore        5
      31: aload_3
      32: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      37: astore        6
      39: aload         6
      41: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      46: ifeq          89
      49: aload         6
      51: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      56: astore        7
      58: aload         4
      60: aload         7
      62: checkcast     #79                 // class java/lang/String
      65: astore        8
      67: astore        12
      69: iconst_0
      70: istore        9
      72: aload         8
      74: invokestatic  #83                 // Method parseSectionRanges:(Ljava/lang/String;)Lkotlin/Pair;
      77: aload         12
      79: swap
      80: invokeinterface #87,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      85: pop
      86: goto          39
      89: aload         4
      91: checkcast     #48                 // class java/util/List
      94: nop
      95: checkcast     #51                 // class java/lang/Iterable
      98: astore_1
      99: nop
     100: iconst_0
     101: istore_2
     102: aload_1
     103: instanceof    #63                 // class java/util/Collection
     106: ifeq          125
     109: aload_1
     110: checkcast     #63                 // class java/util/Collection
     113: invokeinterface #90,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
     118: ifeq          125
     121: iconst_0
     122: goto          312
     125: iconst_0
     126: istore_3
     127: aload_1
     128: invokeinterface #67,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     133: astore        4
     135: aload         4
     137: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     142: ifeq          311
     145: aload         4
     147: invokeinterface #77,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     152: astore        5
     154: aload         5
     156: checkcast     #92                 // class kotlin/Pair
     159: astore        6
     161: iconst_0
     162: istore        7
     164: aload         6
     166: invokevirtual #95                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     169: checkcast     #97                 // class kotlin/ranges/IntRange
     172: astore        8
     174: aload         8
     176: invokevirtual #130                // Method kotlin/ranges/IntRange.getFirst:()I
     179: istore        9
     181: aload         8
     183: invokevirtual #133                // Method kotlin/ranges/IntRange.getLast:()I
     186: istore        10
     188: aload         6
     190: invokevirtual #100                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     193: checkcast     #97                 // class kotlin/ranges/IntRange
     196: invokevirtual #130                // Method kotlin/ranges/IntRange.getFirst:()I
     199: istore        11
     201: iload         9
     203: iload         11
     205: if_icmpgt     223
     208: iload         11
     210: iload         10
     212: if_icmpgt     219
     215: iconst_1
     216: goto          224
     219: iconst_0
     220: goto          224
     223: iconst_0
     224: ifne          290
     227: aload         6
     229: invokevirtual #100                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     232: checkcast     #97                 // class kotlin/ranges/IntRange
     235: astore        8
     237: aload         8
     239: invokevirtual #130                // Method kotlin/ranges/IntRange.getFirst:()I
     242: istore        9
     244: aload         8
     246: invokevirtual #133                // Method kotlin/ranges/IntRange.getLast:()I
     249: istore        10
     251: aload         6
     253: invokevirtual #95                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     256: checkcast     #97                 // class kotlin/ranges/IntRange
     259: invokevirtual #130                // Method kotlin/ranges/IntRange.getFirst:()I
     262: istore        11
     264: iload         9
     266: iload         11
     268: if_icmpgt     286
     271: iload         11
     273: iload         10
     275: if_icmpgt     282
     278: iconst_1
     279: goto          287
     282: iconst_0
     283: goto          287
     286: iconst_0
     287: ifeq          294
     290: iconst_1
     291: goto          295
     294: iconst_0
     295: ifeq          135
     298: iinc          3, 1
     301: iload_3
     302: ifge          135
     305: invokestatic  #107                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     308: goto          135
     311: iload_3
     312: ireturn

  private static final kotlin.Pair<kotlin.ranges.IntRange, kotlin.ranges.IntRange> parseSectionRanges(java.lang.String);
    Code:
       0: getstatic     #140                // Field ROW_FORMAT:Lkotlin/text/Regex;
       3: aload_0
       4: checkcast     #142                // class java/lang/CharSequence
       7: iconst_0
       8: iconst_2
       9: aconst_null
      10: invokestatic  #148                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      13: astore_1
      14: aload_1
      15: dup
      16: ifnonnull     35
      19: pop
      20: ldc           #150                // String Required value was null.
      22: astore_3
      23: new           #152                // class java/lang/IllegalArgumentException
      26: dup
      27: aload_3
      28: invokevirtual #156                // Method java/lang/Object.toString:()Ljava/lang/String;
      31: invokespecial #157                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      34: athrow
      35: invokeinterface #163,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      40: astore_2
      41: aload_2
      42: invokevirtual #169                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      45: invokeinterface #173,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      50: iconst_1
      51: invokeinterface #177,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #79                 // class java/lang/String
      59: astore_3
      60: aload_2
      61: invokevirtual #169                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      64: invokeinterface #173,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      69: iconst_2
      70: invokeinterface #177,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      75: checkcast     #79                 // class java/lang/String
      78: astore        4
      80: aload_2
      81: invokevirtual #169                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
      84: invokeinterface #173,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      89: iconst_3
      90: invokeinterface #177,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      95: checkcast     #79                 // class java/lang/String
      98: astore        5
     100: aload_2
     101: invokevirtual #169                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     104: invokeinterface #173,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     109: iconst_4
     110: invokeinterface #177,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     115: checkcast     #79                 // class java/lang/String
     118: astore        6
     120: new           #97                 // class kotlin/ranges/IntRange
     123: dup
     124: aload_3
     125: invokestatic  #183                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     128: aload         4
     130: invokestatic  #183                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     133: invokespecial #186                // Method kotlin/ranges/IntRange."<init>":(II)V
     136: new           #97                 // class kotlin/ranges/IntRange
     139: dup
     140: aload         5
     142: invokestatic  #183                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     145: aload         6
     147: invokestatic  #183                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     150: invokespecial #186                // Method kotlin/ranges/IntRange."<init>":(II)V
     153: invokestatic  #192                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     156: areturn

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

  static {};
    Code:
       0: new           #144                // class kotlin/text/Regex
       3: dup
       4: ldc           #207                // String (\\d+)-(\\d+),(\\d+)-(\\d+)
       6: invokespecial #208                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: putstatic     #140                // Field ROW_FORMAT:Lkotlin/text/Regex;
      12: return
}


import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.time.ExperimentalTime

@ExperimentalTime
fun main() {
    val testInput = readInput("Day15_test")
    val (testSensors, testBeacons) = parseInput(testInput)
    check(part1(testSensors, testBeacons, targetLine = 10) == 26)
    check(part2(testSensors, bound = 20) == 56000011L)

    val input = readInput("Day15")
    val (sensors, beacons) = parseInput(input)
    println(part1(sensors, beacons, targetLine = 2_000_000))
    println(part2(sensors, bound = 4_000_000))
}

private fun part1(sensors: List<Sensor>, beacons: Set<XY>, targetLine: Int): Int {
    val intervals = calculateLineCoverage(sensors, targetLine)

    val beaconsOnLine = beacons.filter { beacon ->
        beacon.y == targetLine
    }.count()

    return intervals.sumOf { it.size } - beaconsOnLine
}

private fun part2(sensors: List<Sensor>, bound: Int): Long {
    for (y in 0..bound) {
        val intervals = calculateLineCoverage(sensors, y)

        if (intervals[0].first > 0) {
            return y.toLong()
        }

        for (i in 1..intervals.lastIndex) {
            if (intervals[i].first - intervals[i - 1].last > 1) {
                return (intervals[i - 1].last + 1) * 4_000_000L + y
            }
        }

        if (intervals.last().last < bound) {
            return (intervals.last().last + 1) * 4_000_000L + y
        }
    }

    error("Not found")
}

private val ROW_FORMAT = Regex("Sensor at x=(-?\\d+), y=(-?\\d+): closest beacon is at x=(-?\\d+), y=(-?\\d+)")
private fun parseInput(input: List<String>): Pair<List<Sensor>, Set<XY>> {
    val sensors = mutableListOf<Sensor>()
    val beacons = mutableSetOf<XY>()

    input.forEach {
        val match = ROW_FORMAT.find(it)
        val (x, y, beaconX, beaconY) = requireNotNull(match).destructured

        val radius = abs(x.toInt() - beaconX.toInt()) + abs(y.toInt() - beaconY.toInt())
        sensors.add(Sensor(x = x.toInt(), y = y.toInt(), radius = radius))

        beacons.add(XY(x = beaconX.toInt(), y = beaconY.toInt()))
    }

    return Pair(sensors, beacons)
}

private fun calculateLineCoverage(sensors: List<Sensor>, line: Int): List<IntRange> {
    val intervals = sensors
        .mapNotNull { sensor ->
            val count = sensor.radius - abs(sensor.y - line)

            if (count > 0) {
                ((sensor.x - count)..(sensor.x + count))
            } else {
                null
            }
        }
        .sortedBy { it.first }

    val result = LinkedList<IntRange>()

    //collapse intervals if possible
    result.addLast(intervals.first())
    for (i in 1..intervals.lastIndex) {
        if (result.last.last >= intervals[i].first) {
            val tmp = result.pollLast()
            result.addLast(tmp.first..max(tmp.last, intervals[i].last))
        } else {
            result.addLast(intervals[i])
        }
    }

    return result
}

private data class Sensor(
    val x: Int,
    val y: Int,
    val radius: Int,
)

Compiled from "Comparisons.kt"
public final class Day15Kt$calculateLineCoverage$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public Day15Kt$calculateLineCoverage$$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/IntRange
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method kotlin/ranges/IntRange.getFirst:()I
      12: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_2
      19: checkcast     #23                 // class kotlin/ranges/IntRange
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method kotlin/ranges/IntRange.getFirst:()I
      32: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}

Compiled from "Day15.kt"
public final class Day15Kt {
  private static final kotlin.text.Regex ROW_FORMAT;

  public static final void main();
    Code:
       0: ldc           #9                  // String Day15_test
       2: invokestatic  #15                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #19                 // Method parseInput:(Ljava/util/List;)Lkotlin/Pair;
      10: astore_1
      11: aload_1
      12: invokevirtual #25                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
      15: checkcast     #27                 // class java/util/List
      18: astore_2
      19: aload_1
      20: invokevirtual #30                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      23: checkcast     #32                 // class java/util/Set
      26: astore_3
      27: aload_2
      28: aload_3
      29: bipush        10
      31: invokestatic  #36                 // Method part1:(Ljava/util/List;Ljava/util/Set;I)I
      34: bipush        26
      36: if_icmpne     43
      39: iconst_1
      40: goto          44
      43: iconst_0
      44: ifne          57
      47: new           #38                 // class java/lang/IllegalStateException
      50: dup
      51: ldc           #40                 // String Check failed.
      53: invokespecial #44                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      56: athrow
      57: aload_2
      58: bipush        20
      60: invokestatic  #48                 // Method part2:(Ljava/util/List;I)J
      63: ldc2_w        #49                 // long 56000011l
      66: lcmp
      67: ifne          74
      70: iconst_1
      71: goto          75
      74: iconst_0
      75: ifne          88
      78: new           #38                 // class java/lang/IllegalStateException
      81: dup
      82: ldc           #40                 // String Check failed.
      84: invokespecial #44                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      87: athrow
      88: ldc           #52                 // String Day15
      90: invokestatic  #15                 // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
      93: astore        4
      95: aload         4
      97: invokestatic  #19                 // Method parseInput:(Ljava/util/List;)Lkotlin/Pair;
     100: astore        5
     102: aload         5
     104: invokevirtual #25                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     107: checkcast     #27                 // class java/util/List
     110: astore        6
     112: aload         5
     114: invokevirtual #30                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     117: checkcast     #32                 // class java/util/Set
     120: astore        7
     122: aload         6
     124: aload         7
     126: ldc           #53                 // int 2000000
     128: invokestatic  #36                 // Method part1:(Ljava/util/List;Ljava/util/Set;I)I
     131: istore        8
     133: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     136: iload         8
     138: invokevirtual #65                 // Method java/io/PrintStream.println:(I)V
     141: aload         6
     143: ldc           #66                 // int 4000000
     145: invokestatic  #48                 // Method part2:(Ljava/util/List;I)J
     148: lstore        8
     150: getstatic     #59                 // Field java/lang/System.out:Ljava/io/PrintStream;
     153: lload         8
     155: invokevirtual #69                 // Method java/io/PrintStream.println:(J)V
     158: return

  private static final int part1(java.util.List<Sensor>, java.util.Set<XY>, int);
    Code:
       0: aload_0
       1: iload_2
       2: invokestatic  #82                 // Method calculateLineCoverage:(Ljava/util/List;I)Ljava/util/List;
       5: astore_3
       6: aload_1
       7: checkcast     #84                 // class java/lang/Iterable
      10: astore        5
      12: iconst_0
      13: istore        6
      15: aload         5
      17: astore        7
      19: new           #86                 // class java/util/ArrayList
      22: dup
      23: invokespecial #88                 // Method java/util/ArrayList."<init>":()V
      26: checkcast     #90                 // class java/util/Collection
      29: astore        8
      31: iconst_0
      32: istore        9
      34: aload         7
      36: invokeinterface #94,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        10
      43: aload         10
      45: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          102
      53: aload         10
      55: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        11
      62: aload         11
      64: checkcast     #105                // class XY
      67: astore        12
      69: iconst_0
      70: istore        13
      72: aload         12
      74: invokevirtual #109                // Method XY.getY:()I
      77: iload_2
      78: if_icmpne     85
      81: iconst_1
      82: goto          86
      85: iconst_0
      86: ifeq          43
      89: aload         8
      91: aload         11
      93: invokeinterface #113,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      98: pop
      99: goto          43
     102: aload         8
     104: checkcast     #27                 // class java/util/List
     107: nop
     108: checkcast     #90                 // class java/util/Collection
     111: invokeinterface #116,  1          // InterfaceMethod java/util/Collection.size:()I
     116: istore        4
     118: aload_3
     119: checkcast     #84                 // class java/lang/Iterable
     122: astore        5
     124: iconst_0
     125: istore        6
     127: aload         5
     129: invokeinterface #94,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     134: astore        7
     136: aload         7
     138: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     143: ifeq          186
     146: aload         7
     148: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     153: astore        8
     155: iload         6
     157: aload         8
     159: checkcast     #118                // class kotlin/ranges/IntRange
     162: astore        9
     164: istore        14
     166: iconst_0
     167: istore        10
     169: aload         9
     171: invokestatic  #122                // Method UtilsKt.getSize:(Lkotlin/ranges/IntRange;)I
     174: istore        15
     176: iload         14
     178: iload         15
     180: iadd
     181: istore        6
     183: goto          136
     186: iload         6
     188: iload         4
     190: isub
     191: ireturn

  private static final long part2(java.util.List<Sensor>, int);
    Code:
       0: iconst_0
       1: istore_2
       2: iload_2
       3: iload_1
       4: if_icmpgt     169
       7: aload_0
       8: iload_2
       9: invokestatic  #82                 // Method calculateLineCoverage:(Ljava/util/List;I)Ljava/util/List;
      12: astore_3
      13: aload_3
      14: iconst_0
      15: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      20: checkcast     #118                // class kotlin/ranges/IntRange
      23: invokevirtual #149                // Method kotlin/ranges/IntRange.getFirst:()I
      26: ifle          32
      29: iload_2
      30: i2l
      31: lreturn
      32: iconst_1
      33: istore        4
      35: aload_3
      36: invokestatic  #155                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
      39: istore        5
      41: iload         4
      43: iload         5
      45: if_icmpgt     123
      48: aload_3
      49: iload         4
      51: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      56: checkcast     #118                // class kotlin/ranges/IntRange
      59: invokevirtual #149                // Method kotlin/ranges/IntRange.getFirst:()I
      62: aload_3
      63: iload         4
      65: iconst_1
      66: isub
      67: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: checkcast     #118                // class kotlin/ranges/IntRange
      75: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
      78: isub
      79: iconst_1
      80: if_icmple     110
      83: aload_3
      84: iload         4
      86: iconst_1
      87: isub
      88: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      93: checkcast     #118                // class kotlin/ranges/IntRange
      96: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
      99: iconst_1
     100: iadd
     101: i2l
     102: ldc2_w        #159                // long 4000000l
     105: lmul
     106: iload_2
     107: i2l
     108: ladd
     109: lreturn
     110: iload         4
     112: iload         5
     114: if_icmpeq     123
     117: iinc          4, 1
     120: goto          48
     123: aload_3
     124: invokestatic  #164                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     127: checkcast     #118                // class kotlin/ranges/IntRange
     130: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
     133: iload_1
     134: if_icmpge     158
     137: aload_3
     138: invokestatic  #164                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
     141: checkcast     #118                // class kotlin/ranges/IntRange
     144: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
     147: iconst_1
     148: iadd
     149: i2l
     150: ldc2_w        #159                // long 4000000l
     153: lmul
     154: iload_2
     155: i2l
     156: ladd
     157: lreturn
     158: iload_2
     159: iload_1
     160: if_icmpeq     169
     163: iinc          2, 1
     166: goto          7
     169: new           #38                 // class java/lang/IllegalStateException
     172: dup
     173: ldc           #166                // String Not found
     175: invokevirtual #170                // Method java/lang/Object.toString:()Ljava/lang/String;
     178: invokespecial #44                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
     181: athrow

  private static final kotlin.Pair<java.util.List<Sensor>, java.util.Set<XY>> parseInput(java.util.List<java.lang.String>);
    Code:
       0: new           #86                 // class java/util/ArrayList
       3: dup
       4: invokespecial #88                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #27                 // class java/util/List
      10: astore_1
      11: new           #176                // class java/util/LinkedHashSet
      14: dup
      15: invokespecial #177                // Method java/util/LinkedHashSet."<init>":()V
      18: checkcast     #32                 // class java/util/Set
      21: astore_2
      22: aload_0
      23: checkcast     #84                 // class java/lang/Iterable
      26: astore_3
      27: iconst_0
      28: istore        4
      30: aload_3
      31: invokeinterface #94,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        5
      38: aload         5
      40: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          284
      48: aload         5
      50: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        6
      57: aload         6
      59: checkcast     #179                // class java/lang/String
      62: astore        7
      64: iconst_0
      65: istore        8
      67: getstatic     #183                // Field ROW_FORMAT:Lkotlin/text/Regex;
      70: aload         7
      72: checkcast     #185                // class java/lang/CharSequence
      75: iconst_0
      76: iconst_2
      77: aconst_null
      78: invokestatic  #191                // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      81: astore        9
      83: aload         9
      85: dup
      86: ifnonnull     107
      89: pop
      90: ldc           #193                // String Required value was null.
      92: astore        10
      94: new           #195                // class java/lang/IllegalArgumentException
      97: dup
      98: aload         10
     100: invokevirtual #170                // Method java/lang/Object.toString:()Ljava/lang/String;
     103: invokespecial #196                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     106: athrow
     107: invokeinterface #202,  1          // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
     112: astore        11
     114: aload         11
     116: invokevirtual #208                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     119: invokeinterface #212,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     124: iconst_1
     125: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     130: checkcast     #179                // class java/lang/String
     133: astore        10
     135: aload         11
     137: invokevirtual #208                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     140: invokeinterface #212,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     145: iconst_2
     146: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #179                // class java/lang/String
     154: astore        12
     156: aload         11
     158: invokevirtual #208                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     161: invokeinterface #212,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     166: iconst_3
     167: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     172: checkcast     #179                // class java/lang/String
     175: astore        13
     177: aload         11
     179: invokevirtual #208                // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     182: invokeinterface #212,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     187: iconst_4
     188: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     193: checkcast     #179                // class java/lang/String
     196: astore        14
     198: aload         10
     200: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     203: aload         13
     205: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     208: isub
     209: invokestatic  #224                // Method java/lang/Math.abs:(I)I
     212: aload         12
     214: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     217: aload         14
     219: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     222: isub
     223: invokestatic  #224                // Method java/lang/Math.abs:(I)I
     226: iadd
     227: istore        15
     229: aload_1
     230: new           #226                // class Sensor
     233: dup
     234: aload         10
     236: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     239: aload         12
     241: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     244: iload         15
     246: invokespecial #229                // Method Sensor."<init>":(III)V
     249: invokeinterface #230,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     254: pop
     255: aload_2
     256: new           #105                // class XY
     259: dup
     260: aload         13
     262: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     265: aload         14
     267: invokestatic  #218                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     270: invokespecial #233                // Method XY."<init>":(II)V
     273: invokeinterface #234,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
     278: pop
     279: nop
     280: nop
     281: goto          38
     284: nop
     285: new           #21                 // class kotlin/Pair
     288: dup
     289: aload_1
     290: aload_2
     291: invokespecial #237                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     294: areturn

  private static final java.util.List<kotlin.ranges.IntRange> calculateLineCoverage(java.util.List<Sensor>, int);
    Code:
       0: aload_0
       1: checkcast     #84                 // class java/lang/Iterable
       4: astore_3
       5: nop
       6: iconst_0
       7: istore        4
       9: aload_3
      10: astore        5
      12: new           #86                 // class java/util/ArrayList
      15: dup
      16: invokespecial #88                 // Method java/util/ArrayList."<init>":()V
      19: checkcast     #90                 // class java/util/Collection
      22: astore        6
      24: iconst_0
      25: istore        7
      27: aload         5
      29: astore        8
      31: iconst_0
      32: istore        9
      34: aload         8
      36: invokeinterface #94,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      41: astore        10
      43: aload         10
      45: invokeinterface #100,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      50: ifeq          157
      53: aload         10
      55: invokeinterface #103,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      60: astore        11
      62: aload         11
      64: astore        12
      66: iconst_0
      67: istore        13
      69: aload         12
      71: checkcast     #226                // class Sensor
      74: astore        14
      76: iconst_0
      77: istore        15
      79: aload         14
      81: invokevirtual #252                // Method Sensor.getRadius:()I
      84: aload         14
      86: invokevirtual #253                // Method Sensor.getY:()I
      89: iload_1
      90: isub
      91: invokestatic  #224                // Method java/lang/Math.abs:(I)I
      94: isub
      95: istore        16
      97: iload         16
      99: ifle          128
     102: new           #118                // class kotlin/ranges/IntRange
     105: dup
     106: aload         14
     108: invokevirtual #256                // Method Sensor.getX:()I
     111: iload         16
     113: isub
     114: aload         14
     116: invokevirtual #256                // Method Sensor.getX:()I
     119: iload         16
     121: iadd
     122: invokespecial #257                // Method kotlin/ranges/IntRange."<init>":(II)V
     125: goto          129
     128: aconst_null
     129: nop
     130: dup
     131: ifnull        152
     134: astore        17
     136: iconst_0
     137: istore        18
     139: aload         6
     141: aload         17
     143: invokeinterface #113,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     148: pop
     149: goto          153
     152: pop
     153: nop
     154: goto          43
     157: nop
     158: aload         6
     160: checkcast     #27                 // class java/util/List
     163: nop
     164: checkcast     #84                 // class java/lang/Iterable
     167: astore_3
     168: nop
     169: iconst_0
     170: istore        4
     172: aload_3
     173: new           #259                // class Day15Kt$calculateLineCoverage$$inlined$sortedBy$1
     176: dup
     177: invokespecial #260                // Method Day15Kt$calculateLineCoverage$$inlined$sortedBy$1."<init>":()V
     180: checkcast     #262                // class java/util/Comparator
     183: invokestatic  #266                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     186: astore_2
     187: new           #268                // class java/util/LinkedList
     190: dup
     191: invokespecial #269                // Method java/util/LinkedList."<init>":()V
     194: astore_3
     195: aload_3
     196: aload_2
     197: invokestatic  #272                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
     200: invokevirtual #276                // Method java/util/LinkedList.addLast:(Ljava/lang/Object;)V
     203: iconst_1
     204: istore        4
     206: aload_2
     207: invokestatic  #155                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     210: istore        5
     212: iload         4
     214: iload         5
     216: if_icmpgt     321
     219: aload_3
     220: invokevirtual #278                // Method java/util/LinkedList.getLast:()Ljava/lang/Object;
     223: checkcast     #118                // class kotlin/ranges/IntRange
     226: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
     229: aload_2
     230: iload         4
     232: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     237: checkcast     #118                // class kotlin/ranges/IntRange
     240: invokevirtual #149                // Method kotlin/ranges/IntRange.getFirst:()I
     243: if_icmplt     296
     246: aload_3
     247: invokevirtual #281                // Method java/util/LinkedList.pollLast:()Ljava/lang/Object;
     250: checkcast     #118                // class kotlin/ranges/IntRange
     253: astore        6
     255: aload_3
     256: new           #118                // class kotlin/ranges/IntRange
     259: dup
     260: aload         6
     262: invokevirtual #149                // Method kotlin/ranges/IntRange.getFirst:()I
     265: aload         6
     267: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
     270: aload_2
     271: iload         4
     273: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     278: checkcast     #118                // class kotlin/ranges/IntRange
     281: invokevirtual #158                // Method kotlin/ranges/IntRange.getLast:()I
     284: invokestatic  #285                // Method java/lang/Math.max:(II)I
     287: invokespecial #257                // Method kotlin/ranges/IntRange."<init>":(II)V
     290: invokevirtual #276                // Method java/util/LinkedList.addLast:(Ljava/lang/Object;)V
     293: goto          308
     296: aload_3
     297: aload_2
     298: iload         4
     300: invokeinterface #146,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     305: invokevirtual #276                // Method java/util/LinkedList.addLast:(Ljava/lang/Object;)V
     308: iload         4
     310: iload         5
     312: if_icmpeq     321
     315: iinc          4, 1
     318: goto          219
     321: aload_3
     322: checkcast     #27                 // class java/util/List
     325: areturn

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

  static {};
    Code:
       0: new           #187                // class kotlin/text/Regex
       3: dup
       4: ldc_w         #312                // String Sensor at x=(-?\\d+), y=(-?\\d+): closest beacon is at x=(-?\\d+), y=(-?\\d+)
       7: invokespecial #313                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      10: putstatic     #183                // Field ROW_FORMAT:Lkotlin/text/Regex;
      13: return
}