import kotlin.math.abs

fun main() = Beacons.solve(0..4_000_000)

private object Beacons {
    fun solve(possibleCoordinates: IntRange) {
        val sensors = readInput()
        val distress = findDistressBeacon(sensors, possibleCoordinates)
        println("Distress breacon at $distress, freq: ${distress.x.toBigInteger() * 4_000_000.toBigInteger() + distress.y.toBigInteger()}")
    }

    private fun findDistressBeacon(sensors: List<Sensor>, possibleCoordinates: IntRange): Pos {
        for (y in possibleCoordinates) {
            val ranges: List<IntRange> = rangesAtRow(sensors, y)
            var prev: IntRange? = null
            for (range in ranges) {
                if (prev == null) {
                    prev = range
                    continue
                }
                if (range.last <= prev.last) {
                    continue
                } else if (range.first <= prev.last) {
                    prev = prev.first..range.last
                } else {
                    if (prev.last in possibleCoordinates) {
                        return Pos(prev.last + 1, y)
                    }
                }
            }
        }
        throw Error("Distress beacon not found")
    }

    // Problem 1
    private fun solveIntersections(sensors: List<Sensor>, targetRow: Int) {
        val ranges: List<IntRange> = rangesAtRow(sensors, targetRow)
        // Calculate intersections
        var result = 0
        var currentRange: IntRange? = null
        for (range in ranges) {
            if (currentRange == null) {
                currentRange = range
            } else {
                if (range.last <= currentRange.last) continue
                else if (range.first <= currentRange.last) {
                    currentRange = currentRange.first..range.last
                } else {
                    result += currentRange.last - currentRange.start + 1
                    currentRange = range
                }
            }
        }
        if (currentRange != null) {
            result += currentRange.last - currentRange.start + 1
        }
        println("Beacon cannot take $result positions in row $targetRow")
    }

    private fun readInput(): List<Sensor> = generateSequence(::readLine).map {
        val groupValues =
            "Sensor at x=([-\\d]+), y=([-\\d]+): closest beacon is at x=([-\\d]+), y=([-\\d]+)".toRegex()
                .matchEntire(it)!!.groupValues
        Sensor(
            Pos(groupValues[1].toInt(10), groupValues[2].toInt(10)),
            Pos(groupValues[3].toInt(10), groupValues[4].toInt(10))
        )
    }.toList()

    private fun rangesAtRow(sensors: List<Sensor>, targetRow: Int): List<IntRange> =
        sensors.filter { abs(targetRow - it.pos.y) <= it.distanceToBeacon() }.map {
            val dx = it.distanceToBeacon() - abs(targetRow - it.pos.y)
            (it.pos.x - dx)..(it.pos.x + dx)
        }.sortedBy { it.start }

    data class Pos(val x: Int, val y: Int) {
        fun distanceTo(other: Pos): Int = abs(x - other.x) + abs(y - other.y)
    }

    data class Sensor(val pos: Pos, val nearestBeacon: Pos) {
        fun distanceToBeacon(): Int = pos.distanceTo(nearestBeacon)
    }
}

Compiled from "Beacons.kt"
public final class Beacons$Sensor {
  private final Beacons$Pos pos;

  private final Beacons$Pos nearestBeacon;

  public Beacons$Sensor(Beacons$Pos, Beacons$Pos);
    Code:
       0: aload_1
       1: ldc           #9                  // String pos
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #17                 // String nearestBeacon
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokespecial #20                 // Method java/lang/Object."<init>":()V
      16: aload_0
      17: aload_1
      18: putfield      #23                 // Field pos:LBeacons$Pos;
      21: aload_0
      22: aload_2
      23: putfield      #25                 // Field nearestBeacon:LBeacons$Pos;
      26: return

  public final Beacons$Pos getPos();
    Code:
       0: aload_0
       1: getfield      #23                 // Field pos:LBeacons$Pos;
       4: areturn

  public final Beacons$Pos getNearestBeacon();
    Code:
       0: aload_0
       1: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
       4: areturn

  public final int distanceToBeacon();
    Code:
       0: aload_0
       1: getfield      #23                 // Field pos:LBeacons$Pos;
       4: aload_0
       5: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
       8: invokevirtual #38                 // Method Beacons$Pos.distanceTo:(LBeacons$Pos;)I
      11: ireturn

  public final Beacons$Pos component1();
    Code:
       0: aload_0
       1: getfield      #23                 // Field pos:LBeacons$Pos;
       4: areturn

  public final Beacons$Pos component2();
    Code:
       0: aload_0
       1: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
       4: areturn

  public final Beacons$Sensor copy(Beacons$Pos, Beacons$Pos);
    Code:
       0: aload_1
       1: ldc           #9                  // String pos
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #17                 // String nearestBeacon
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: new           #2                  // class Beacons$Sensor
      15: dup
      16: aload_1
      17: aload_2
      18: invokespecial #44                 // Method "<init>":(LBeacons$Pos;LBeacons$Pos;)V
      21: areturn

  public static Beacons$Sensor copy$default(Beacons$Sensor, Beacons$Pos, Beacons$Pos, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #23                 // Field pos:LBeacons$Pos;
      10: astore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
      21: astore_2
      22: aload_0
      23: aload_1
      24: aload_2
      25: invokevirtual #48                 // Method copy:(LBeacons$Pos;LBeacons$Pos;)LBeacons$Sensor;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #52                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #55                 // String Sensor(pos=
       9: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #23                 // Field pos:LBeacons$Pos;
      16: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      19: ldc           #64                 // String , nearestBeacon=
      21: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
      28: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #67                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #23                 // Field pos:LBeacons$Pos;
       4: invokevirtual #72                 // Method Beacons$Pos.hashCode:()I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
      16: invokevirtual #72                 // Method Beacons$Pos.hashCode:()I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Beacons$Sensor
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Beacons$Sensor
      20: astore_2
      21: aload_0
      22: getfield      #23                 // Field pos:LBeacons$Pos;
      25: aload_2
      26: getfield      #23                 // Field pos:LBeacons$Pos;
      29: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      32: ifne          37
      35: iconst_0
      36: ireturn
      37: aload_0
      38: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
      41: aload_2
      42: getfield      #25                 // Field nearestBeacon:LBeacons$Pos;
      45: invokestatic  #81                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      48: ifne          53
      51: iconst_0
      52: ireturn
      53: iconst_1
      54: ireturn
}

Compiled from "Beacons.kt"
public final class Beacons$Pos {
  private final int x;

  private final int y;

  public Beacons$Pos(int, int);
    Code:
       0: aload_0
       1: invokespecial #9                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iload_1
       6: putfield      #13                 // Field x:I
       9: aload_0
      10: iload_2
      11: putfield      #16                 // Field y:I
      14: return

  public final int getX();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: ireturn

  public final int getY();
    Code:
       0: aload_0
       1: getfield      #16                 // Field y:I
       4: ireturn

  public final int distanceTo(Beacons$Pos);
    Code:
       0: aload_1
       1: ldc           #26                 // String other
       3: invokestatic  #32                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #13                 // Field x:I
      10: aload_1
      11: getfield      #13                 // Field x:I
      14: isub
      15: invokestatic  #38                 // Method java/lang/Math.abs:(I)I
      18: aload_0
      19: getfield      #16                 // Field y:I
      22: aload_1
      23: getfield      #16                 // Field y:I
      26: isub
      27: invokestatic  #38                 // Method java/lang/Math.abs:(I)I
      30: iadd
      31: ireturn

  public final int component1();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: ireturn

  public final int component2();
    Code:
       0: aload_0
       1: getfield      #16                 // Field y:I
       4: ireturn

  public final Beacons$Pos copy(int, int);
    Code:
       0: new           #2                  // class Beacons$Pos
       3: dup
       4: iload_1
       5: iload_2
       6: invokespecial #44                 // Method "<init>":(II)V
       9: areturn

  public static Beacons$Pos copy$default(Beacons$Pos, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_1
       2: iand
       3: ifeq          11
       6: aload_0
       7: getfield      #13                 // Field x:I
      10: istore_1
      11: iload_3
      12: iconst_2
      13: iand
      14: ifeq          22
      17: aload_0
      18: getfield      #16                 // Field y:I
      21: istore_2
      22: aload_0
      23: iload_1
      24: iload_2
      25: invokevirtual #48                 // Method copy:(II)LBeacons$Pos;
      28: areturn

  public java.lang.String toString();
    Code:
       0: new           #52                 // class java/lang/StringBuilder
       3: dup
       4: invokespecial #53                 // Method java/lang/StringBuilder."<init>":()V
       7: ldc           #55                 // String Pos(x=
       9: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      12: aload_0
      13: getfield      #13                 // Field x:I
      16: invokevirtual #62                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      19: ldc           #64                 // String , y=
      21: invokevirtual #59                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      24: aload_0
      25: getfield      #16                 // Field y:I
      28: invokevirtual #62                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      31: bipush        41
      33: invokevirtual #67                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      36: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      39: areturn

  public int hashCode();
    Code:
       0: aload_0
       1: getfield      #13                 // Field x:I
       4: invokestatic  #74                 // Method java/lang/Integer.hashCode:(I)I
       7: istore_1
       8: iload_1
       9: bipush        31
      11: imul
      12: aload_0
      13: getfield      #16                 // Field y:I
      16: invokestatic  #74                 // Method java/lang/Integer.hashCode:(I)I
      19: iadd
      20: istore_1
      21: iload_1
      22: ireturn

  public boolean equals(java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: if_acmpne     7
       5: iconst_1
       6: ireturn
       7: aload_1
       8: instanceof    #2                  // class Beacons$Pos
      11: ifne          16
      14: iconst_0
      15: ireturn
      16: aload_1
      17: checkcast     #2                  // class Beacons$Pos
      20: astore_2
      21: aload_0
      22: getfield      #13                 // Field x:I
      25: aload_2
      26: getfield      #13                 // Field x:I
      29: if_icmpeq     34
      32: iconst_0
      33: ireturn
      34: aload_0
      35: getfield      #16                 // Field y:I
      38: aload_2
      39: getfield      #16                 // Field y:I
      42: if_icmpeq     47
      45: iconst_0
      46: ireturn
      47: iconst_1
      48: ireturn
}

Compiled from "Comparisons.kt"
public final class Beacons$rangesAtRow$$inlined$sortedBy$1<T> implements java.util.Comparator {
  public Beacons$rangesAtRow$$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.getStart:()Ljava/lang/Integer;
      12: checkcast     #29                 // class java/lang/Comparable
      15: aload_2
      16: checkcast     #23                 // class kotlin/ranges/IntRange
      19: astore_3
      20: astore        5
      22: iconst_0
      23: istore        4
      25: aload_3
      26: invokevirtual #27                 // Method kotlin/ranges/IntRange.getStart:()Ljava/lang/Integer;
      29: aload         5
      31: swap
      32: checkcast     #29                 // class java/lang/Comparable
      35: invokestatic  #35                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      38: ireturn
}

Compiled from "Beacons.kt"
final class Beacons$readInput$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function0<java.lang.String> {
  public static final Beacons$readInput$1 INSTANCE;

  Beacons$readInput$1();
    Code:
       0: aload_0
       1: iconst_0
       2: ldc           #11                 // class kotlin/io/ConsoleKt
       4: ldc           #13                 // String readLine
       6: ldc           #15                 // String readLine()Ljava/lang/String;
       8: iconst_1
       9: invokespecial #18                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      12: return

  public final java.lang.String invoke();
    Code:
       0: invokestatic  #24                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: areturn

  public java.lang.Object invoke();
    Code:
       0: aload_0
       1: invokevirtual #27                 // Method invoke:()Ljava/lang/String;
       4: areturn

  static {};
    Code:
       0: new           #2                  // class Beacons$readInput$1
       3: dup
       4: invokespecial #30                 // Method "<init>":()V
       7: putstatic     #33                 // Field INSTANCE:LBeacons$readInput$1;
      10: return
}

Compiled from "Beacons.kt"
final class Beacons {
  public static final Beacons INSTANCE;

  private Beacons();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final void solve(kotlin.ranges.IntRange);
    Code:
       0: aload_1
       1: ldc           #15                 // String possibleCoordinates
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #25                 // Method readInput:()Ljava/util/List;
      10: astore_2
      11: aload_0
      12: aload_2
      13: aload_1
      14: invokespecial #29                 // Method findDistressBeacon:(Ljava/util/List;Lkotlin/ranges/IntRange;)LBeacons$Pos;
      17: astore_3
      18: new           #31                 // class java/lang/StringBuilder
      21: dup
      22: invokespecial #32                 // Method java/lang/StringBuilder."<init>":()V
      25: ldc           #34                 // String Distress breacon at
      27: invokevirtual #38                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      30: aload_3
      31: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
      34: ldc           #43                 // String , freq:
      36: invokevirtual #38                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      39: nop
      40: aload_3
      41: invokevirtual #49                 // Method Beacons$Pos.getX:()I
      44: i2l
      45: invokestatic  #55                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      48: dup
      49: ldc           #57                 // String valueOf(...)
      51: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      54: ldc           #61                 // int 4000000
      56: i2l
      57: invokestatic  #55                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      60: dup
      61: ldc           #57                 // String valueOf(...)
      63: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      66: invokevirtual #65                 // Method java/math/BigInteger.multiply:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      69: dup
      70: ldc           #67                 // String multiply(...)
      72: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      75: aload_3
      76: invokevirtual #70                 // Method Beacons$Pos.getY:()I
      79: i2l
      80: invokestatic  #55                 // Method java/math/BigInteger.valueOf:(J)Ljava/math/BigInteger;
      83: dup
      84: ldc           #57                 // String valueOf(...)
      86: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      89: invokevirtual #73                 // Method java/math/BigInteger.add:(Ljava/math/BigInteger;)Ljava/math/BigInteger;
      92: dup
      93: ldc           #75                 // String add(...)
      95: invokestatic  #60                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      98: invokevirtual #41                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     101: invokevirtual #79                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     104: getstatic     #85                 // Field java/lang/System.out:Ljava/io/PrintStream;
     107: swap
     108: invokevirtual #91                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     111: return

  private final Beacons$Pos findDistressBeacon(java.util.List<Beacons$Sensor>, kotlin.ranges.IntRange);
    Code:
       0: aload_2
       1: invokevirtual #102                // Method kotlin/ranges/IntRange.getFirst:()I
       4: istore_3
       5: aload_2
       6: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
       9: istore        4
      11: iload_3
      12: iload         4
      14: if_icmpgt     195
      17: aload_0
      18: aload_1
      19: iload_3
      20: invokespecial #109                // Method rangesAtRow:(Ljava/util/List;I)Ljava/util/List;
      23: astore        5
      25: aconst_null
      26: astore        6
      28: aload         5
      30: invokeinterface #115,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      35: astore        7
      37: aload         7
      39: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          183
      47: aload         7
      49: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: checkcast     #99                 // class kotlin/ranges/IntRange
      57: astore        8
      59: aload         6
      61: ifnonnull     71
      64: aload         8
      66: astore        6
      68: goto          37
      71: aload         8
      73: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      76: aload         6
      78: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      81: if_icmpgt     87
      84: goto          37
      87: aload         8
      89: invokevirtual #102                // Method kotlin/ranges/IntRange.getFirst:()I
      92: aload         6
      94: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      97: if_icmpgt     122
     100: new           #99                 // class kotlin/ranges/IntRange
     103: dup
     104: aload         6
     106: invokevirtual #102                // Method kotlin/ranges/IntRange.getFirst:()I
     109: aload         8
     111: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
     114: invokespecial #128                // Method kotlin/ranges/IntRange."<init>":(II)V
     117: astore        6
     119: goto          37
     122: aload_2
     123: invokevirtual #102                // Method kotlin/ranges/IntRange.getFirst:()I
     126: istore        9
     128: aload_2
     129: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
     132: istore        10
     134: aload         6
     136: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
     139: istore        11
     141: iload         9
     143: iload         11
     145: if_icmpgt     163
     148: iload         11
     150: iload         10
     152: if_icmpgt     159
     155: iconst_1
     156: goto          164
     159: iconst_0
     160: goto          164
     163: iconst_0
     164: ifeq          37
     167: new           #45                 // class Beacons$Pos
     170: dup
     171: aload         6
     173: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
     176: iconst_1
     177: iadd
     178: iload_3
     179: invokespecial #129                // Method Beacons$Pos."<init>":(II)V
     182: areturn
     183: iload_3
     184: iload         4
     186: if_icmpeq     195
     189: iinc          3, 1
     192: goto          17
     195: new           #131                // class java/lang/Error
     198: dup
     199: ldc           #133                // String Distress beacon not found
     201: invokespecial #136                // Method java/lang/Error."<init>":(Ljava/lang/String;)V
     204: athrow

  private final void solveIntersections(java.util.List<Beacons$Sensor>, int);
    Code:
       0: aload_0
       1: aload_1
       2: iload_2
       3: invokespecial #109                // Method rangesAtRow:(Ljava/util/List;I)Ljava/util/List;
       6: astore_3
       7: iconst_0
       8: istore        4
      10: aconst_null
      11: astore        5
      13: aload_3
      14: invokeinterface #115,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      19: astore        6
      21: aload         6
      23: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      28: ifeq          131
      31: aload         6
      33: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      38: checkcast     #99                 // class kotlin/ranges/IntRange
      41: astore        7
      43: aload         5
      45: ifnonnull     55
      48: aload         7
      50: astore        5
      52: goto          21
      55: aload         7
      57: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      60: aload         5
      62: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      65: if_icmple     21
      68: aload         7
      70: invokevirtual #102                // Method kotlin/ranges/IntRange.getFirst:()I
      73: aload         5
      75: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      78: if_icmpgt     103
      81: new           #99                 // class kotlin/ranges/IntRange
      84: dup
      85: aload         5
      87: invokevirtual #102                // Method kotlin/ranges/IntRange.getFirst:()I
      90: aload         7
      92: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
      95: invokespecial #128                // Method kotlin/ranges/IntRange."<init>":(II)V
      98: astore        5
     100: goto          21
     103: iload         4
     105: aload         5
     107: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
     110: aload         5
     112: invokevirtual #148                // Method kotlin/ranges/IntRange.getStart:()Ljava/lang/Integer;
     115: invokevirtual #153                // Method java/lang/Integer.intValue:()I
     118: isub
     119: iconst_1
     120: iadd
     121: iadd
     122: istore        4
     124: aload         7
     126: astore        5
     128: goto          21
     131: aload         5
     133: ifnull        157
     136: iload         4
     138: aload         5
     140: invokevirtual #105                // Method kotlin/ranges/IntRange.getLast:()I
     143: aload         5
     145: invokevirtual #148                // Method kotlin/ranges/IntRange.getStart:()Ljava/lang/Integer;
     148: invokevirtual #153                // Method java/lang/Integer.intValue:()I
     151: isub
     152: iconst_1
     153: iadd
     154: iadd
     155: istore        4
     157: new           #31                 // class java/lang/StringBuilder
     160: dup
     161: invokespecial #32                 // Method java/lang/StringBuilder."<init>":()V
     164: ldc           #155                // String Beacon cannot take
     166: invokevirtual #38                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     169: iload         4
     171: invokevirtual #158                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     174: ldc           #160                // String  positions in row
     176: invokevirtual #38                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     179: iload_2
     180: invokevirtual #158                // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     183: invokevirtual #79                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     186: getstatic     #85                 // Field java/lang/System.out:Ljava/io/PrintStream;
     189: swap
     190: invokevirtual #91                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     193: return

  private final java.util.List<Beacons$Sensor> readInput();
    Code:
       0: getstatic     #170                // Field Beacons$readInput$1.INSTANCE:LBeacons$readInput$1;
       3: checkcast     #172                // class kotlin/jvm/functions/Function0
       6: invokestatic  #178                // Method kotlin/sequences/SequencesKt.generateSequence:(Lkotlin/jvm/functions/Function0;)Lkotlin/sequences/Sequence;
       9: invokedynamic #197,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      14: invokestatic  #201                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      17: invokestatic  #205                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      20: areturn

  private final java.util.List<kotlin.ranges.IntRange> rangesAtRow(java.util.List<Beacons$Sensor>, int);
    Code:
       0: aload_1
       1: checkcast     #208                // class java/lang/Iterable
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: astore        5
      11: new           #210                // class java/util/ArrayList
      14: dup
      15: invokespecial #211                // Method java/util/ArrayList."<init>":()V
      18: checkcast     #213                // class java/util/Collection
      21: astore        6
      23: iconst_0
      24: istore        7
      26: aload         5
      28: invokeinterface #214,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      33: astore        8
      35: aload         8
      37: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      42: ifeq          106
      45: aload         8
      47: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      52: astore        9
      54: aload         9
      56: checkcast     #216                // class Beacons$Sensor
      59: astore        10
      61: iconst_0
      62: istore        11
      64: iload_2
      65: aload         10
      67: invokevirtual #220                // Method Beacons$Sensor.getPos:()LBeacons$Pos;
      70: invokevirtual #70                 // Method Beacons$Pos.getY:()I
      73: isub
      74: invokestatic  #226                // Method java/lang/Math.abs:(I)I
      77: aload         10
      79: invokevirtual #229                // Method Beacons$Sensor.distanceToBeacon:()I
      82: if_icmpgt     89
      85: iconst_1
      86: goto          90
      89: iconst_0
      90: ifeq          35
      93: aload         6
      95: aload         9
      97: invokeinterface #232,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     102: pop
     103: goto          35
     106: aload         6
     108: checkcast     #111                // class java/util/List
     111: nop
     112: checkcast     #208                // class java/lang/Iterable
     115: astore_3
     116: nop
     117: iconst_0
     118: istore        4
     120: aload_3
     121: astore        5
     123: new           #210                // class java/util/ArrayList
     126: dup
     127: aload_3
     128: bipush        10
     130: invokestatic  #238                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     133: invokespecial #241                // Method java/util/ArrayList."<init>":(I)V
     136: checkcast     #213                // class java/util/Collection
     139: astore        6
     141: iconst_0
     142: istore        7
     144: aload         5
     146: invokeinterface #214,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     151: astore        8
     153: aload         8
     155: invokeinterface #121,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     160: ifeq          248
     163: aload         8
     165: invokeinterface #125,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     170: astore        9
     172: aload         6
     174: aload         9
     176: checkcast     #216                // class Beacons$Sensor
     179: astore        10
     181: astore        13
     183: iconst_0
     184: istore        11
     186: aload         10
     188: invokevirtual #229                // Method Beacons$Sensor.distanceToBeacon:()I
     191: iload_2
     192: aload         10
     194: invokevirtual #220                // Method Beacons$Sensor.getPos:()LBeacons$Pos;
     197: invokevirtual #70                 // Method Beacons$Pos.getY:()I
     200: isub
     201: invokestatic  #226                // Method java/lang/Math.abs:(I)I
     204: isub
     205: istore        12
     207: new           #99                 // class kotlin/ranges/IntRange
     210: dup
     211: aload         10
     213: invokevirtual #220                // Method Beacons$Sensor.getPos:()LBeacons$Pos;
     216: invokevirtual #49                 // Method Beacons$Pos.getX:()I
     219: iload         12
     221: isub
     222: aload         10
     224: invokevirtual #220                // Method Beacons$Sensor.getPos:()LBeacons$Pos;
     227: invokevirtual #49                 // Method Beacons$Pos.getX:()I
     230: iload         12
     232: iadd
     233: invokespecial #128                // Method kotlin/ranges/IntRange."<init>":(II)V
     236: aload         13
     238: swap
     239: invokeinterface #232,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     244: pop
     245: goto          153
     248: aload         6
     250: checkcast     #111                // class java/util/List
     253: nop
     254: checkcast     #208                // class java/lang/Iterable
     257: astore_3
     258: nop
     259: iconst_0
     260: istore        4
     262: aload_3
     263: new           #243                // class Beacons$rangesAtRow$$inlined$sortedBy$1
     266: dup
     267: invokespecial #244                // Method Beacons$rangesAtRow$$inlined$sortedBy$1."<init>":()V
     270: checkcast     #246                // class java/util/Comparator
     273: invokestatic  #250                // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
     276: areturn

  private static final Beacons$Sensor readInput$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #272                // String it
       4: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: new           #274                // class kotlin/text/Regex
      10: dup
      11: ldc_w         #276                // String Sensor at x=([-\\d]+), y=([-\\d]+): closest beacon is at x=([-\\d]+), y=([-\\d]+)
      14: invokespecial #277                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      17: aload_0
      18: checkcast     #279                // class java/lang/CharSequence
      21: invokevirtual #283                // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
      24: dup
      25: invokestatic  #286                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      28: invokeinterface #291,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      33: astore_1
      34: new           #216                // class Beacons$Sensor
      37: dup
      38: new           #45                 // class Beacons$Pos
      41: dup
      42: aload_1
      43: iconst_1
      44: invokeinterface #295,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      49: checkcast     #297                // class java/lang/String
      52: bipush        10
      54: invokestatic  #302                // Method kotlin/text/CharsKt.checkRadix:(I)I
      57: invokestatic  #306                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      60: aload_1
      61: iconst_2
      62: invokeinterface #295,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #297                // class java/lang/String
      70: bipush        10
      72: invokestatic  #302                // Method kotlin/text/CharsKt.checkRadix:(I)I
      75: invokestatic  #306                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
      78: invokespecial #129                // Method Beacons$Pos."<init>":(II)V
      81: new           #45                 // class Beacons$Pos
      84: dup
      85: aload_1
      86: iconst_3
      87: invokeinterface #295,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      92: checkcast     #297                // class java/lang/String
      95: bipush        10
      97: invokestatic  #302                // Method kotlin/text/CharsKt.checkRadix:(I)I
     100: invokestatic  #306                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     103: aload_1
     104: iconst_4
     105: invokeinterface #295,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: checkcast     #297                // class java/lang/String
     113: bipush        10
     115: invokestatic  #302                // Method kotlin/text/CharsKt.checkRadix:(I)I
     118: invokestatic  #306                // Method java/lang/Integer.parseInt:(Ljava/lang/String;I)I
     121: invokespecial #129                // Method Beacons$Pos."<init>":(II)V
     124: invokespecial #309                // Method Beacons$Sensor."<init>":(LBeacons$Pos;LBeacons$Pos;)V
     127: areturn

  static {};
    Code:
       0: new           #2                  // class Beacons
       3: dup
       4: invokespecial #313                // Method "<init>":()V
       7: putstatic     #315                // Field INSTANCE:LBeacons;
      10: return
}

Compiled from "Beacons.kt"
public final class BeaconsKt {
  public static final void main();
    Code:
       0: getstatic     #12                 // Field Beacons.INSTANCE:LBeacons;
       3: new           #14                 // class kotlin/ranges/IntRange
       6: dup
       7: iconst_0
       8: ldc           #15                 // int 4000000
      10: invokespecial #19                 // Method kotlin/ranges/IntRange."<init>":(II)V
      13: invokevirtual #23                 // Method Beacons.solve:(Lkotlin/ranges/IntRange;)V
      16: return

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