package day12

import java.io.File

fun main() {
    val data = parse("src/main/kotlin/day12/Day12.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 12 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private data class Heightmap(
    val nodes: String,
    val width: Int,
    val height: Int,
)

@Suppress("SameParameterValue")
private fun parse(path: String): Heightmap {
    val data = File(path).readLines()

    val width = data[0].length
    val height = data.size

    return Heightmap(data.joinToString(separator = ""), width, height)
}

private fun Char.toElevation(): Char =
    when (this) {
        'S' -> 'a'
        'E' -> 'z'
        else -> this
    }

private fun Char.reaches(other: Char): Boolean =
    (other.toElevation() - this.toElevation()) <= 1

private fun Heightmap.neighborsOf(index: Int): List<Int> {
    val x = index % width
    val y = index / width

    val current = nodes[index]

    val result = mutableListOf<Int>()
    if (x > 0 && current.reaches(nodes[index - 1])) {
        result.add(index - 1)
    }
    if (y > 0 && current.reaches(nodes[index - width])) {
        result.add(index - width)
    }
    if (x < width - 1 && current.reaches(nodes[index + 1])) {
        result.add(index + 1)
    }
    if (y < height - 1 && current.reaches(nodes[index + width])) {
        result.add(index + width)
    }

    return result
}

private fun Heightmap.solve(source: Int): Int? {
    val queue = ArrayDeque<Int>()
    val distances = Array(nodes.length) { Int.MAX_VALUE }

    queue.add(source)
    distances[source] = 0

    while (queue.isNotEmpty()) {
        val vertex = queue.removeFirst()
        for (neighbor in neighborsOf(vertex)) {
            if (nodes[neighbor] == 'E') {
                return distances[vertex] + 1
            }
            if (distances[neighbor] > distances[vertex] + 1) {
                distances[neighbor] = distances[vertex] + 1
                queue.add(neighbor)
            }
        }
    }

    return null
}

private fun part1(graph: Heightmap): Int {
    val source = graph.nodes.indexOfFirst { it == 'S' }
    return graph.solve(source) ?: error("Path not found.")
}

private fun part2(graph: Heightmap): Int {
    val distances = mutableListOf<Int>()
    for ((source, c) in graph.nodes.withIndex()) {
        if (c == 'a' || c == 'S') {
            distances.add(graph.solve(source) ?: continue)
        }
    }
    return distances.min()
}

Compiled from "Day12.kt"
public final class day12.Day12Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day12/Day12.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Lday12/Heightmap;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Lday12/Heightmap;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Lday12/Heightmap;)I
      15: istore_2
      16: ldc           #21                 // String 🎄 Day 12 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: iload_2
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final day12.Heightmap parse(java.lang.String);
    Code:
       0: new           #64                 // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #67                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #73                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: astore_1
      15: aload_1
      16: iconst_0
      17: invokeinterface #79,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      22: checkcast     #81                 // class java/lang/String
      25: invokevirtual #85                 // Method java/lang/String.length:()I
      28: istore_2
      29: aload_1
      30: invokeinterface #88,  1           // InterfaceMethod java/util/List.size:()I
      35: istore_3
      36: new           #90                 // class day12/Heightmap
      39: dup
      40: aload_1
      41: checkcast     #92                 // class java/lang/Iterable
      44: ldc           #94                 // String
      46: checkcast     #96                 // class java/lang/CharSequence
      49: aconst_null
      50: aconst_null
      51: iconst_0
      52: aconst_null
      53: aconst_null
      54: bipush        62
      56: aconst_null
      57: invokestatic  #102                // 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;
      60: iload_2
      61: iload_3
      62: invokespecial #105                // Method day12/Heightmap."<init>":(Ljava/lang/String;II)V
      65: areturn

  private static final char toElevation(char);
    Code:
       0: iload_0
       1: lookupswitch  { // 2
                    69: 33
                    83: 28
               default: 38
          }
      28: bipush        97
      30: goto          39
      33: bipush        122
      35: goto          39
      38: iload_0
      39: ireturn

  private static final boolean reaches(char, char);
    Code:
       0: iload_1
       1: invokestatic  #118                // Method toElevation:(C)C
       4: iload_0
       5: invokestatic  #118                // Method toElevation:(C)C
       8: isub
       9: iconst_1
      10: if_icmpgt     17
      13: iconst_1
      14: goto          18
      17: iconst_0
      18: ireturn

  private static final java.util.List<java.lang.Integer> neighborsOf(day12.Heightmap, int);
    Code:
       0: iload_1
       1: aload_0
       2: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
       5: irem
       6: istore_2
       7: iload_1
       8: aload_0
       9: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
      12: idiv
      13: istore_3
      14: aload_0
      15: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
      18: iload_1
      19: invokevirtual #133                // Method java/lang/String.charAt:(I)C
      22: istore        4
      24: new           #135                // class java/util/ArrayList
      27: dup
      28: invokespecial #136                // Method java/util/ArrayList."<init>":()V
      31: checkcast     #75                 // class java/util/List
      34: astore        5
      36: iload_2
      37: ifle          72
      40: iload         4
      42: aload_0
      43: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
      46: iload_1
      47: iconst_1
      48: isub
      49: invokevirtual #133                // Method java/lang/String.charAt:(I)C
      52: invokestatic  #138                // Method reaches:(CC)Z
      55: ifeq          72
      58: aload         5
      60: iload_1
      61: iconst_1
      62: isub
      63: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokeinterface #148,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      71: pop
      72: iload_3
      73: ifle          114
      76: iload         4
      78: aload_0
      79: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
      82: iload_1
      83: aload_0
      84: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
      87: isub
      88: invokevirtual #133                // Method java/lang/String.charAt:(I)C
      91: invokestatic  #138                // Method reaches:(CC)Z
      94: ifeq          114
      97: aload         5
      99: iload_1
     100: aload_0
     101: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
     104: isub
     105: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: invokeinterface #148,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     113: pop
     114: iload_2
     115: aload_0
     116: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
     119: iconst_1
     120: isub
     121: if_icmpge     156
     124: iload         4
     126: aload_0
     127: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
     130: iload_1
     131: iconst_1
     132: iadd
     133: invokevirtual #133                // Method java/lang/String.charAt:(I)C
     136: invokestatic  #138                // Method reaches:(CC)Z
     139: ifeq          156
     142: aload         5
     144: iload_1
     145: iconst_1
     146: iadd
     147: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     150: invokeinterface #148,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     155: pop
     156: iload_3
     157: aload_0
     158: invokevirtual #151                // Method day12/Heightmap.getHeight:()I
     161: iconst_1
     162: isub
     163: if_icmpge     204
     166: iload         4
     168: aload_0
     169: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
     172: iload_1
     173: aload_0
     174: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
     177: iadd
     178: invokevirtual #133                // Method java/lang/String.charAt:(I)C
     181: invokestatic  #138                // Method reaches:(CC)Z
     184: ifeq          204
     187: aload         5
     189: iload_1
     190: aload_0
     191: invokevirtual #126                // Method day12/Heightmap.getWidth:()I
     194: iadd
     195: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     198: invokeinterface #148,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     203: pop
     204: aload         5
     206: areturn

  private static final java.lang.Integer solve(day12.Heightmap, int);
    Code:
       0: new           #161                // class kotlin/collections/ArrayDeque
       3: dup
       4: invokespecial #162                // Method kotlin/collections/ArrayDeque."<init>":()V
       7: astore_2
       8: iconst_0
       9: istore        4
      11: aload_0
      12: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
      15: invokevirtual #85                 // Method java/lang/String.length:()I
      18: istore        5
      20: iload         5
      22: anewarray     #140                // class java/lang/Integer
      25: astore        6
      27: iload         4
      29: iload         5
      31: if_icmpge     54
      34: iload         4
      36: istore        7
      38: aload         6
      40: iload         7
      42: ldc           #163                // int 2147483647
      44: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      47: aastore
      48: iinc          4, 1
      51: goto          27
      54: aload         6
      56: astore_3
      57: aload_2
      58: iload_1
      59: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: invokevirtual #164                // Method kotlin/collections/ArrayDeque.add:(Ljava/lang/Object;)Z
      65: pop
      66: aload_3
      67: iload_1
      68: iconst_0
      69: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: aastore
      73: aload_2
      74: checkcast     #166                // class java/util/Collection
      77: invokeinterface #170,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
      82: ifne          89
      85: iconst_1
      86: goto          90
      89: iconst_0
      90: ifeq          218
      93: aload_2
      94: invokevirtual #174                // Method kotlin/collections/ArrayDeque.removeFirst:()Ljava/lang/Object;
      97: checkcast     #176                // class java/lang/Number
     100: invokevirtual #179                // Method java/lang/Number.intValue:()I
     103: istore        4
     105: aload_0
     106: iload         4
     108: invokestatic  #181                // Method neighborsOf:(Lday12/Heightmap;I)Ljava/util/List;
     111: invokeinterface #185,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     116: astore        5
     118: aload         5
     120: invokeinterface #190,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          73
     128: aload         5
     130: invokeinterface #193,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: checkcast     #176                // class java/lang/Number
     138: invokevirtual #179                // Method java/lang/Number.intValue:()I
     141: istore        6
     143: aload_0
     144: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
     147: iload         6
     149: invokevirtual #133                // Method java/lang/String.charAt:(I)C
     152: bipush        69
     154: if_icmpne     170
     157: aload_3
     158: iload         4
     160: aaload
     161: invokevirtual #194                // Method java/lang/Integer.intValue:()I
     164: iconst_1
     165: iadd
     166: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     169: areturn
     170: aload_3
     171: iload         6
     173: aaload
     174: invokevirtual #194                // Method java/lang/Integer.intValue:()I
     177: aload_3
     178: iload         4
     180: aaload
     181: invokevirtual #194                // Method java/lang/Integer.intValue:()I
     184: iconst_1
     185: iadd
     186: if_icmple     118
     189: aload_3
     190: iload         6
     192: aload_3
     193: iload         4
     195: aaload
     196: invokevirtual #194                // Method java/lang/Integer.intValue:()I
     199: iconst_1
     200: iadd
     201: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     204: aastore
     205: aload_2
     206: iload         6
     208: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     211: invokevirtual #164                // Method kotlin/collections/ArrayDeque.add:(Ljava/lang/Object;)Z
     214: pop
     215: goto          118
     218: aconst_null
     219: areturn

  private static final int part1(day12.Heightmap);
    Code:
       0: aload_0
       1: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
       4: checkcast     #96                 // class java/lang/CharSequence
       7: astore_2
       8: iconst_0
       9: istore_3
      10: iconst_0
      11: istore        4
      13: aload_2
      14: invokeinterface #204,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      19: istore        5
      21: iload         4
      23: iload         5
      25: if_icmpge     67
      28: aload_2
      29: iload         4
      31: invokeinterface #205,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      36: istore        6
      38: iconst_0
      39: istore        7
      41: iload         6
      43: bipush        83
      45: if_icmpne     52
      48: iconst_1
      49: goto          53
      52: iconst_0
      53: ifeq          61
      56: iload         4
      58: goto          68
      61: iinc          4, 1
      64: goto          21
      67: iconst_m1
      68: istore_1
      69: aload_0
      70: iload_1
      71: invokestatic  #207                // Method solve:(Lday12/Heightmap;I)Ljava/lang/Integer;
      74: dup
      75: ifnull        84
      78: invokevirtual #194                // Method java/lang/Integer.intValue:()I
      81: goto          98
      84: pop
      85: new           #209                // class java/lang/IllegalStateException
      88: dup
      89: ldc           #211                // String Path not found.
      91: invokevirtual #212                // Method java/lang/Object.toString:()Ljava/lang/String;
      94: invokespecial #213                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      97: athrow
      98: ireturn

  private static final int part2(day12.Heightmap);
    Code:
       0: new           #135                // class java/util/ArrayList
       3: dup
       4: invokespecial #136                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #75                 // class java/util/List
      10: astore_1
      11: aload_0
      12: invokevirtual #129                // Method day12/Heightmap.getNodes:()Ljava/lang/String;
      15: astore_2
      16: iconst_0
      17: istore_3
      18: aload_2
      19: invokevirtual #85                 // Method java/lang/String.length:()I
      22: istore        4
      24: iload_3
      25: iload         4
      27: if_icmpge     105
      30: iload_3
      31: istore        5
      33: aload_2
      34: iload_3
      35: invokevirtual #133                // Method java/lang/String.charAt:(I)C
      38: istore        6
      40: iload         6
      42: lookupswitch  { // 2
                    83: 68
                    97: 68
               default: 99
          }
      68: aload_1
      69: aload_0
      70: iload         5
      72: invokestatic  #207                // Method solve:(Lday12/Heightmap;I)Ljava/lang/Integer;
      75: dup
      76: ifnull        85
      79: invokevirtual #194                // Method java/lang/Integer.intValue:()I
      82: goto          90
      85: pop
      86: pop
      87: goto          99
      90: invokestatic  #144                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      93: invokeinterface #148,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      98: pop
      99: iinc          3, 1
     102: goto          24
     105: aload_1
     106: checkcast     #92                 // class java/lang/Iterable
     109: invokestatic  #224                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
     112: checkcast     #176                // class java/lang/Number
     115: invokevirtual #179                // Method java/lang/Number.intValue:()I
     118: ireturn

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


package day15

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

fun main() {
    val data = parse("src/main/kotlin/day15/Day15.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 15 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private data class Sensor(
    val sx: Int,
    val sy: Int,
    val bx: Int,
    val by: Int,
)

@Suppress("SameParameterValue")
private fun parse(path: String): List<Sensor> {
    val pattern = Regex("""Sensor at x=(-?\d+), y=(-?\d+): closest beacon is at x=(-?\d+), y=(-?\d+)""")
    return File(path).readLines().map { line ->
        val (sx, sy, bx, by) = pattern.matchEntire(line)!!.groupValues
            .drop(1)
            .map { it.toInt() }

        Sensor(sx, sy, bx, by)
    }
}

private data class Range(
    val from: Int,
    val to: Int,
)

private fun findCoverage(data: List<Sensor>, y: Int): List<Range> {
    val ranges = mutableListOf<Range>()
    for ((sx, sy, bx, by) in data) {
        val distance = abs(sx - bx) + abs(sy - by)
        val dx = distance - abs(sy - y)
        if (dx >= 0) {
            ranges += Range(sx - dx, sx + dx)
        }
    }

    ranges.sortWith(compareBy(Range::from, Range::to))
    val mergedRanges = mutableListOf<Range>()

    var merged = ranges[0]
    for (i in 1..ranges.lastIndex) {
        val range = ranges[i]
        if (merged.to >= range.to) {
            continue
        }
        if (merged.to >= range.from) {
            merged = Range(merged.from, range.to)
            continue
        }

        mergedRanges += merged
        merged = range
    }

    mergedRanges += merged
    return mergedRanges
}

private fun part1(data: List<Sensor>, target: Int = 2_000_000): Int {
    val covered = findCoverage(data, target)
        .sumOf { (from, to) -> abs(to) + abs(from) + 1 }

    val beacons = data.mapTo(HashSet()) { it.by }
        .count { it == target }

    return covered - beacons
}

private fun part2(data: List<Sensor>, size: Int = 4_000_000): Long {
    for (y in 0..size) {
        val ranges = findCoverage(data, y)
        if (ranges.size > 1) {
            val x = ranges[0].to + 1
            return x.toLong() * 4_000_000L + y.toLong()
        }
    }
    error("Beacon not found!")
}

Compiled from "Day15.kt"
public final class day15.Day15Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day15/Day15.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: iconst_0
       8: iconst_2
       9: aconst_null
      10: invokestatic  #16                 // Method part1$default:(Ljava/util/List;IILjava/lang/Object;)I
      13: istore_1
      14: aload_0
      15: iconst_0
      16: iconst_2
      17: aconst_null
      18: invokestatic  #20                 // Method part2$default:(Ljava/util/List;IILjava/lang/Object;)J
      21: lstore_2
      22: ldc           #22                 // String 🎄 Day 15 🎄
      24: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      27: swap
      28: invokevirtual #34                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      31: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      34: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      37: ldc           #38                 // String [Part 1]
      39: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      42: swap
      43: invokevirtual #34                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      46: new           #40                 // class java/lang/StringBuilder
      49: dup
      50: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
      53: ldc           #45                 // String Answer:
      55: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      58: iload_1
      59: invokevirtual #52                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      62: invokevirtual #56                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      65: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      68: swap
      69: invokevirtual #34                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      72: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      75: invokevirtual #36                 // Method java/io/PrintStream.println:()V
      78: ldc           #58                 // String [Part 2]
      80: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
      83: swap
      84: invokevirtual #34                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      87: new           #40                 // class java/lang/StringBuilder
      90: dup
      91: invokespecial #43                 // Method java/lang/StringBuilder."<init>":()V
      94: ldc           #45                 // String Answer:
      96: invokevirtual #49                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      99: lload_2
     100: invokevirtual #61                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     103: invokevirtual #56                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     106: getstatic     #28                 // Field java/lang/System.out:Ljava/io/PrintStream;
     109: swap
     110: invokevirtual #34                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     113: return

  private static final java.util.List<day15.Sensor> parse(java.lang.String);
    Code:
       0: new           #70                 // class kotlin/text/Regex
       3: dup
       4: ldc           #72                 // String Sensor at x=(-?\\d+), y=(-?\\d+): closest beacon is at x=(-?\\d+), y=(-?\\d+)
       6: invokespecial #75                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: new           #77                 // class java/io/File
      13: dup
      14: aload_0
      15: invokespecial #78                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      18: aconst_null
      19: iconst_1
      20: aconst_null
      21: invokestatic  #84                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      24: checkcast     #86                 // class java/lang/Iterable
      27: astore_2
      28: iconst_0
      29: istore_3
      30: aload_2
      31: astore        4
      33: new           #88                 // class java/util/ArrayList
      36: dup
      37: aload_2
      38: bipush        10
      40: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      43: invokespecial #97                 // Method java/util/ArrayList."<init>":(I)V
      46: checkcast     #99                 // class java/util/Collection
      49: astore        5
      51: iconst_0
      52: istore        6
      54: aload         4
      56: invokeinterface #103,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      61: astore        7
      63: aload         7
      65: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      70: ifeq          318
      73: aload         7
      75: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      80: astore        8
      82: aload         5
      84: aload         8
      86: checkcast     #115                // class java/lang/String
      89: astore        9
      91: astore        22
      93: iconst_0
      94: istore        10
      96: aload_1
      97: aload         9
      99: checkcast     #117                // class java/lang/CharSequence
     102: invokevirtual #121                // Method kotlin/text/Regex.matchEntire:(Ljava/lang/CharSequence;)Lkotlin/text/MatchResult;
     105: dup
     106: invokestatic  #126                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     109: invokeinterface #132,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     114: checkcast     #86                 // class java/lang/Iterable
     117: iconst_1
     118: invokestatic  #136                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     121: checkcast     #86                 // class java/lang/Iterable
     124: astore        11
     126: nop
     127: iconst_0
     128: istore        12
     130: aload         11
     132: astore        13
     134: new           #88                 // class java/util/ArrayList
     137: dup
     138: aload         11
     140: bipush        10
     142: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     145: invokespecial #97                 // Method java/util/ArrayList."<init>":(I)V
     148: checkcast     #99                 // class java/util/Collection
     151: astore        14
     153: iconst_0
     154: istore        15
     156: aload         13
     158: invokeinterface #103,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     163: astore        16
     165: aload         16
     167: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     172: ifeq          219
     175: aload         16
     177: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     182: astore        17
     184: aload         14
     186: aload         17
     188: checkcast     #115                // class java/lang/String
     191: astore        18
     193: astore        19
     195: iconst_0
     196: istore        20
     198: aload         18
     200: invokestatic  #142                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     203: nop
     204: invokestatic  #146                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     207: aload         19
     209: swap
     210: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     215: pop
     216: goto          165
     219: aload         14
     221: checkcast     #152                // class java/util/List
     224: nop
     225: astore        21
     227: aload         21
     229: iconst_0
     230: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     235: checkcast     #158                // class java/lang/Number
     238: invokevirtual #162                // Method java/lang/Number.intValue:()I
     241: istore        11
     243: aload         21
     245: iconst_1
     246: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     251: checkcast     #158                // class java/lang/Number
     254: invokevirtual #162                // Method java/lang/Number.intValue:()I
     257: istore        12
     259: aload         21
     261: iconst_2
     262: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     267: checkcast     #158                // class java/lang/Number
     270: invokevirtual #162                // Method java/lang/Number.intValue:()I
     273: istore        13
     275: aload         21
     277: iconst_3
     278: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     283: checkcast     #158                // class java/lang/Number
     286: invokevirtual #162                // Method java/lang/Number.intValue:()I
     289: istore        14
     291: new           #164                // class day15/Sensor
     294: dup
     295: iload         11
     297: iload         12
     299: iload         13
     301: iload         14
     303: invokespecial #167                // Method day15/Sensor."<init>":(IIII)V
     306: aload         22
     308: swap
     309: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     314: pop
     315: goto          63
     318: aload         5
     320: checkcast     #152                // class java/util/List
     323: nop
     324: areturn

  private static final java.util.List<day15.Range> findCoverage(java.util.List<day15.Sensor>, int);
    Code:
       0: new           #88                 // class java/util/ArrayList
       3: dup
       4: invokespecial #192                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #152                // class java/util/List
      10: astore_2
      11: aload_0
      12: invokeinterface #193,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      17: astore_3
      18: aload_3
      19: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          132
      27: aload_3
      28: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #164                // class day15/Sensor
      36: astore        4
      38: aload         4
      40: invokevirtual #196                // Method day15/Sensor.component1:()I
      43: istore        5
      45: aload         4
      47: invokevirtual #199                // Method day15/Sensor.component2:()I
      50: istore        6
      52: aload         4
      54: invokevirtual #202                // Method day15/Sensor.component3:()I
      57: istore        7
      59: aload         4
      61: invokevirtual #205                // Method day15/Sensor.component4:()I
      64: istore        8
      66: iload         5
      68: iload         7
      70: isub
      71: invokestatic  #211                // Method java/lang/Math.abs:(I)I
      74: iload         6
      76: iload         8
      78: isub
      79: invokestatic  #211                // Method java/lang/Math.abs:(I)I
      82: iadd
      83: istore        9
      85: iload         9
      87: iload         6
      89: iload_1
      90: isub
      91: invokestatic  #211                // Method java/lang/Math.abs:(I)I
      94: isub
      95: istore        10
      97: iload         10
      99: iflt          18
     102: aload_2
     103: checkcast     #99                 // class java/util/Collection
     106: new           #213                // class day15/Range
     109: dup
     110: iload         5
     112: iload         10
     114: isub
     115: iload         5
     117: iload         10
     119: iadd
     120: invokespecial #216                // Method day15/Range."<init>":(II)V
     123: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     128: pop
     129: goto          18
     132: aload_2
     133: iconst_2
     134: anewarray     #218                // class kotlin/jvm/functions/Function1
     137: astore_3
     138: aload_3
     139: iconst_0
     140: getstatic     #224                // Field day15/Day15Kt$findCoverage$1.INSTANCE:Lday15/Day15Kt$findCoverage$1;
     143: aastore
     144: aload_3
     145: iconst_1
     146: getstatic     #229                // Field day15/Day15Kt$findCoverage$2.INSTANCE:Lday15/Day15Kt$findCoverage$2;
     149: aastore
     150: aload_3
     151: invokestatic  #235                // Method kotlin/comparisons/ComparisonsKt.compareBy:([Lkotlin/jvm/functions/Function1;)Ljava/util/Comparator;
     154: invokestatic  #239                // Method kotlin/collections/CollectionsKt.sortWith:(Ljava/util/List;Ljava/util/Comparator;)V
     157: new           #88                 // class java/util/ArrayList
     160: dup
     161: invokespecial #192                // Method java/util/ArrayList."<init>":()V
     164: checkcast     #152                // class java/util/List
     167: astore_3
     168: aload_2
     169: iconst_0
     170: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     175: checkcast     #213                // class day15/Range
     178: astore        4
     180: iconst_1
     181: istore        5
     183: aload_2
     184: invokestatic  #243                // Method kotlin/collections/CollectionsKt.getLastIndex:(Ljava/util/List;)I
     187: istore        6
     189: iload         5
     191: iload         6
     193: if_icmpgt     289
     196: aload_2
     197: iload         5
     199: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     204: checkcast     #213                // class day15/Range
     207: astore        7
     209: aload         4
     211: invokevirtual #246                // Method day15/Range.getTo:()I
     214: aload         7
     216: invokevirtual #246                // Method day15/Range.getTo:()I
     219: if_icmplt     225
     222: goto          276
     225: aload         4
     227: invokevirtual #246                // Method day15/Range.getTo:()I
     230: aload         7
     232: invokevirtual #249                // Method day15/Range.getFrom:()I
     235: if_icmplt     260
     238: new           #213                // class day15/Range
     241: dup
     242: aload         4
     244: invokevirtual #249                // Method day15/Range.getFrom:()I
     247: aload         7
     249: invokevirtual #246                // Method day15/Range.getTo:()I
     252: invokespecial #216                // Method day15/Range."<init>":(II)V
     255: astore        4
     257: goto          276
     260: aload_3
     261: checkcast     #99                 // class java/util/Collection
     264: aload         4
     266: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     271: pop
     272: aload         7
     274: astore        4
     276: iload         5
     278: iload         6
     280: if_icmpeq     289
     283: iinc          5, 1
     286: goto          196
     289: aload_3
     290: checkcast     #99                 // class java/util/Collection
     293: aload         4
     295: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     300: pop
     301: aload_3
     302: areturn

  private static final int part1(java.util.List<day15.Sensor>, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokestatic  #263                // Method findCoverage:(Ljava/util/List;I)Ljava/util/List;
       5: checkcast     #86                 // class java/lang/Iterable
       8: astore_3
       9: iconst_0
      10: istore        4
      12: aload_3
      13: invokeinterface #103,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      18: astore        5
      20: aload         5
      22: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      27: ifeq          92
      30: aload         5
      32: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      37: astore        6
      39: iload         4
      41: aload         6
      43: checkcast     #213                // class day15/Range
      46: astore        7
      48: istore        11
      50: iconst_0
      51: istore        8
      53: aload         7
      55: invokevirtual #264                // Method day15/Range.component1:()I
      58: istore        9
      60: aload         7
      62: invokevirtual #265                // Method day15/Range.component2:()I
      65: istore        10
      67: iload         10
      69: invokestatic  #211                // Method java/lang/Math.abs:(I)I
      72: iload         9
      74: invokestatic  #211                // Method java/lang/Math.abs:(I)I
      77: iadd
      78: iconst_1
      79: iadd
      80: istore        12
      82: iload         11
      84: iload         12
      86: iadd
      87: istore        4
      89: goto          20
      92: iload         4
      94: istore_2
      95: aload_0
      96: checkcast     #86                 // class java/lang/Iterable
      99: astore        4
     101: new           #267                // class java/util/HashSet
     104: dup
     105: invokespecial #268                // Method java/util/HashSet."<init>":()V
     108: checkcast     #99                 // class java/util/Collection
     111: astore        5
     113: iconst_0
     114: istore        6
     116: aload         4
     118: invokeinterface #103,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     123: astore        7
     125: aload         7
     127: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     132: ifeq          178
     135: aload         7
     137: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     142: astore        8
     144: aload         5
     146: aload         8
     148: checkcast     #164                // class day15/Sensor
     151: astore        9
     153: astore        11
     155: iconst_0
     156: istore        10
     158: aload         9
     160: invokevirtual #271                // Method day15/Sensor.getBy:()I
     163: invokestatic  #146                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     166: aload         11
     168: swap
     169: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     174: pop
     175: goto          125
     178: aload         5
     180: checkcast     #86                 // class java/lang/Iterable
     183: astore        4
     185: nop
     186: iconst_0
     187: istore        5
     189: aload         4
     191: instanceof    #99                 // class java/util/Collection
     194: ifeq          214
     197: aload         4
     199: checkcast     #99                 // class java/util/Collection
     202: invokeinterface #274,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     207: ifeq          214
     210: iconst_0
     211: goto          288
     214: iconst_0
     215: istore        6
     217: aload         4
     219: invokeinterface #103,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     224: astore        7
     226: aload         7
     228: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     233: ifeq          286
     236: aload         7
     238: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     243: astore        8
     245: aload         8
     247: checkcast     #158                // class java/lang/Number
     250: invokevirtual #162                // Method java/lang/Number.intValue:()I
     253: istore        9
     255: iconst_0
     256: istore        10
     258: iload         9
     260: iload_1
     261: if_icmpne     268
     264: iconst_1
     265: goto          269
     268: iconst_0
     269: ifeq          226
     272: iinc          6, 1
     275: iload         6
     277: ifge          226
     280: invokestatic  #277                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     283: goto          226
     286: iload         6
     288: istore_3
     289: iload_2
     290: iload_3
     291: isub
     292: ireturn

  static int part1$default(java.util.List, int, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_2
       2: iand
       3: ifeq          10
       6: ldc_w         #294                // int 2000000
       9: istore_1
      10: aload_0
      11: iload_1
      12: invokestatic  #296                // Method part1:(Ljava/util/List;I)I
      15: ireturn

  private static final long part2(java.util.List<day15.Sensor>, int);
    Code:
       0: iconst_0
       1: istore_2
       2: iload_2
       3: iload_1
       4: if_icmpgt     62
       7: aload_0
       8: iload_2
       9: invokestatic  #263                // Method findCoverage:(Ljava/util/List;I)Ljava/util/List;
      12: astore_3
      13: aload_3
      14: invokeinterface #302,  1          // InterfaceMethod java/util/List.size:()I
      19: iconst_1
      20: if_icmple     51
      23: aload_3
      24: iconst_0
      25: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      30: checkcast     #213                // class day15/Range
      33: invokevirtual #246                // Method day15/Range.getTo:()I
      36: iconst_1
      37: iadd
      38: istore        4
      40: iload         4
      42: i2l
      43: ldc2_w        #303                // long 4000000l
      46: lmul
      47: iload_2
      48: i2l
      49: ladd
      50: lreturn
      51: iload_2
      52: iload_1
      53: if_icmpeq     62
      56: iinc          2, 1
      59: goto          7
      62: new           #306                // class java/lang/IllegalStateException
      65: dup
      66: ldc_w         #308                // String Beacon not found!
      69: invokevirtual #309                // Method java/lang/Object.toString:()Ljava/lang/String;
      72: invokespecial #310                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      75: athrow

  static long part2$default(java.util.List, int, int, java.lang.Object);
    Code:
       0: iload_2
       1: iconst_2
       2: iand
       3: ifeq          10
       6: ldc_w         #312                // int 4000000
       9: istore_1
      10: aload_0
      11: iload_1
      12: invokestatic  #314                // Method part2:(Ljava/util/List;I)J
      15: lreturn

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

Compiled from "Day15.kt"
final class day15.Day15Kt$findCoverage$1 extends kotlin.jvm.internal.PropertyReference1Impl {
  public static final day15.Day15Kt$findCoverage$1 INSTANCE;

  day15.Day15Kt$findCoverage$1();
    Code:
       0: aload_0
       1: ldc           #8                  // class day15/Range
       3: ldc           #10                 // String from
       5: ldc           #12                 // String getFrom()I
       7: iconst_0
       8: invokespecial #15                 // Method kotlin/jvm/internal/PropertyReference1Impl."<init>":(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      11: return

  public java.lang.Object get(java.lang.Object);
    Code:
       0: aload_1
       1: checkcast     #8                  // class day15/Range
       4: invokevirtual #23                 // Method day15/Range.getFrom:()I
       7: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      10: areturn

  static {};
    Code:
       0: new           #2                  // class day15/Day15Kt$findCoverage$1
       3: dup
       4: invokespecial #34                 // Method "<init>":()V
       7: putstatic     #37                 // Field INSTANCE:Lday15/Day15Kt$findCoverage$1;
      10: return
}

Compiled from "Day15.kt"
final class day15.Day15Kt$findCoverage$2 extends kotlin.jvm.internal.PropertyReference1Impl {
  public static final day15.Day15Kt$findCoverage$2 INSTANCE;

  day15.Day15Kt$findCoverage$2();
    Code:
       0: aload_0
       1: ldc           #8                  // class day15/Range
       3: ldc           #10                 // String to
       5: ldc           #12                 // String getTo()I
       7: iconst_0
       8: invokespecial #15                 // Method kotlin/jvm/internal/PropertyReference1Impl."<init>":(Ljava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      11: return

  public java.lang.Object get(java.lang.Object);
    Code:
       0: aload_1
       1: checkcast     #8                  // class day15/Range
       4: invokevirtual #23                 // Method day15/Range.getTo:()I
       7: invokestatic  #29                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      10: areturn

  static {};
    Code:
       0: new           #2                  // class day15/Day15Kt$findCoverage$2
       3: dup
       4: invokespecial #34                 // Method "<init>":()V
       7: putstatic     #37                 // Field INSTANCE:Lday15/Day15Kt$findCoverage$2;
      10: return
}


package day14

import java.io.File
import kotlin.math.min
import kotlin.math.max

fun main() {
    val data = parse("src/main/kotlin/day14/Day14.txt")

    val answer1 = part1(data)
    val answer2 = part2(data)

    println("🎄 Day 14 🎄")

    println()

    println("[Part 1]")
    println("Answer: $answer1")

    println()

    println("[Part 2]")
    println("Answer: $answer2")
}

private data class Segment(
    val points: List<Pair<Int, Int>>,
)

private fun String.toSegment(): Segment =
    split(" -> ")
        .map { it.split(",").let { (a, b) -> a.toInt() to b.toInt() } }
        .let { points -> Segment(points) }

@Suppress("SameParameterValue")
private fun parse(path: String): Set<Pair<Int, Int>> =
    File(path).readLines().map { it.toSegment() }.toObstacles()

private fun List<Segment>.toObstacles(): Set<Pair<Int, Int>> {
    val obstacles = mutableSetOf<Pair<Int, Int>>()
    for ((points) in this) {
        for ((a, b) in points.zipWithNext()) {
            val (ax, ay) = a
            val (bx, by) = b

            if (ax == bx) {
                for (dy in min(ay, by)..max(ay, by)) {
                    obstacles += ax to dy
                }
            } else {
                for (dx in min(ax, bx)..max(ax, bx)) {
                    obstacles += dx to ay
                }
            }
        }
    }
    return obstacles
}

private fun part1(data: Set<Pair<Int, Int>>): Int {
    val obstacles = data.toMutableSet()
    val maxy = obstacles.maxBy { (_, y) -> y }.second

    var sandCount = 0
    outer@while (true) {
        var sx = 500
        var sy = 0

        inner@while (sx to sy !in obstacles) {
            sy += 1

            if (sx to sy in obstacles) {
                if ((sx - 1) to sy !in obstacles) {
                    sx -= 1
                } else if ((sx + 1) to sy !in obstacles) {
                    sx += 1
                } else {
                    sy -= 1
                    break@inner
                }
            }

            if (sy >= maxy) {
                break@outer
            }
        }

        obstacles += sx to sy
        sandCount += 1
    }

    return sandCount
}

private fun part2(data: Set<Pair<Int, Int>>): Int {
    val obstacles = data.toMutableSet()
    val maxy = obstacles.maxBy { (_, y) -> y }.second

    var sandCount = 0
    outer@while (true) {
        var sx = 500
        var sy = 0

        inner@while (sx to sy !in obstacles) {
            sy += 1

            if (sx to sy in obstacles) {
                if ((sx - 1) to sy !in obstacles) {
                    sx -= 1
                } else if ((sx + 1) to sy !in obstacles) {
                    sx += 1
                } else {
                    sy -= 1
                    break@inner
                }
            }

            if (sy == maxy + 2) {
                sy -= 1
                break@inner
            }
        }

        obstacles += sx to sy
        sandCount += 1

        if (sx == 500 && sy == 0) {
            break@outer
        }
    }

    return sandCount
}

Compiled from "Day14.kt"
public final class day14.Day14Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String src/main/kotlin/day14/Day14.txt
       2: invokestatic  #12                 // Method parse:(Ljava/lang/String;)Ljava/util/Set;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method part1:(Ljava/util/Set;)I
      10: istore_1
      11: aload_0
      12: invokestatic  #19                 // Method part2:(Ljava/util/Set;)I
      15: istore_2
      16: ldc           #21                 // String 🎄 Day 14 🎄
      18: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      21: swap
      22: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      25: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      28: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      31: ldc           #37                 // String [Part 1]
      33: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: new           #39                 // class java/lang/StringBuilder
      43: dup
      44: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      47: ldc           #44                 // String Answer:
      49: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      52: iload_1
      53: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      56: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      59: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      62: swap
      63: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      66: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      69: invokevirtual #35                 // Method java/io/PrintStream.println:()V
      72: ldc           #57                 // String [Part 2]
      74: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
      77: swap
      78: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      81: new           #39                 // class java/lang/StringBuilder
      84: dup
      85: invokespecial #42                 // Method java/lang/StringBuilder."<init>":()V
      88: ldc           #44                 // String Answer:
      90: invokevirtual #48                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      93: iload_2
      94: invokevirtual #51                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      97: invokevirtual #55                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     100: getstatic     #27                 // Field java/lang/System.out:Ljava/io/PrintStream;
     103: swap
     104: invokevirtual #33                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     107: return

  private static final day14.Segment toSegment(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #66                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #68                 // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #70                 // String  ->
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #76                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #78                 // class java/lang/Iterable
      26: astore_1
      27: nop
      28: iconst_0
      29: istore_2
      30: aload_1
      31: astore_3
      32: new           #80                 // class java/util/ArrayList
      35: dup
      36: aload_1
      37: bipush        10
      39: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #89                 // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #91                 // class java/util/Collection
      48: astore        4
      50: iconst_0
      51: istore        5
      53: aload_3
      54: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      59: astore        6
      61: aload         6
      63: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      68: ifeq          185
      71: aload         6
      73: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      78: astore        7
      80: aload         4
      82: aload         7
      84: checkcast     #68                 // class java/lang/String
      87: astore        8
      89: astore        15
      91: iconst_0
      92: istore        9
      94: aload         8
      96: checkcast     #66                 // class java/lang/CharSequence
      99: iconst_1
     100: anewarray     #68                 // class java/lang/String
     103: astore        10
     105: aload         10
     107: iconst_0
     108: ldc           #107                // String ,
     110: aastore
     111: aload         10
     113: iconst_0
     114: iconst_0
     115: bipush        6
     117: aconst_null
     118: invokestatic  #76                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     121: astore        11
     123: iconst_0
     124: istore        12
     126: aload         11
     128: iconst_0
     129: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #68                 // class java/lang/String
     137: astore        13
     139: aload         11
     141: iconst_1
     142: invokeinterface #113,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     147: checkcast     #68                 // class java/lang/String
     150: astore        14
     152: aload         13
     154: invokestatic  #119                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     157: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     160: aload         14
     162: invokestatic  #119                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     165: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     168: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     171: nop
     172: nop
     173: aload         15
     175: swap
     176: invokeinterface #133,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     181: pop
     182: goto          61
     185: aload         4
     187: checkcast     #109                // class java/util/List
     190: nop
     191: astore_2
     192: iconst_0
     193: istore_3
     194: new           #135                // class day14/Segment
     197: dup
     198: aload_2
     199: invokespecial #138                // Method day14/Segment."<init>":(Ljava/util/List;)V
     202: nop
     203: areturn

  private static final java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>> parse(java.lang.String);
    Code:
       0: new           #160                // class java/io/File
       3: dup
       4: aload_0
       5: invokespecial #163                // Method java/io/File."<init>":(Ljava/lang/String;)V
       8: aconst_null
       9: iconst_1
      10: aconst_null
      11: invokestatic  #169                // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      14: checkcast     #78                 // class java/lang/Iterable
      17: astore_1
      18: iconst_0
      19: istore_2
      20: aload_1
      21: astore_3
      22: new           #80                 // class java/util/ArrayList
      25: dup
      26: aload_1
      27: bipush        10
      29: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      32: invokespecial #89                 // Method java/util/ArrayList."<init>":(I)V
      35: checkcast     #91                 // class java/util/Collection
      38: astore        4
      40: iconst_0
      41: istore        5
      43: aload_3
      44: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      49: astore        6
      51: aload         6
      53: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifeq          101
      61: aload         6
      63: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      68: astore        7
      70: aload         4
      72: aload         7
      74: checkcast     #68                 // class java/lang/String
      77: astore        8
      79: astore        10
      81: iconst_0
      82: istore        9
      84: aload         8
      86: invokestatic  #171                // Method toSegment:(Ljava/lang/String;)Lday14/Segment;
      89: aload         10
      91: swap
      92: invokeinterface #133,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      97: pop
      98: goto          51
     101: aload         4
     103: checkcast     #109                // class java/util/List
     106: nop
     107: invokestatic  #175                // Method toObstacles:(Ljava/util/List;)Ljava/util/Set;
     110: areturn

  private static final java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>> toObstacles(java.util.List<day14.Segment>);
    Code:
       0: new           #180                // class java/util/LinkedHashSet
       3: dup
       4: invokespecial #181                // Method java/util/LinkedHashSet."<init>":()V
       7: checkcast     #183                // class java/util/Set
      10: astore_1
      11: aload_0
      12: invokeinterface #184,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      17: astore_2
      18: aload_2
      19: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      24: ifeq          277
      27: aload_2
      28: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      33: checkcast     #135                // class day14/Segment
      36: invokevirtual #188                // Method day14/Segment.component1:()Ljava/util/List;
      39: astore_3
      40: aload_3
      41: checkcast     #78                 // class java/lang/Iterable
      44: invokestatic  #192                // Method kotlin/collections/CollectionsKt.zipWithNext:(Ljava/lang/Iterable;)Ljava/util/List;
      47: invokeinterface #184,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      52: astore        4
      54: aload         4
      56: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      61: ifeq          18
      64: aload         4
      66: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: checkcast     #194                // class kotlin/Pair
      74: astore        5
      76: aload         5
      78: invokevirtual #196                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      81: checkcast     #194                // class kotlin/Pair
      84: astore        6
      86: aload         5
      88: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      91: checkcast     #194                // class kotlin/Pair
      94: astore        7
      96: aload         6
      98: invokevirtual #196                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     101: checkcast     #201                // class java/lang/Number
     104: invokevirtual #205                // Method java/lang/Number.intValue:()I
     107: istore        8
     109: aload         6
     111: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     114: checkcast     #201                // class java/lang/Number
     117: invokevirtual #205                // Method java/lang/Number.intValue:()I
     120: istore        9
     122: aload         7
     124: invokevirtual #196                // Method kotlin/Pair.component1:()Ljava/lang/Object;
     127: checkcast     #201                // class java/lang/Number
     130: invokevirtual #205                // Method java/lang/Number.intValue:()I
     133: istore        10
     135: aload         7
     137: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     140: checkcast     #201                // class java/lang/Number
     143: invokevirtual #205                // Method java/lang/Number.intValue:()I
     146: istore        11
     148: iload         8
     150: iload         10
     152: if_icmpne     216
     155: iload         9
     157: iload         11
     159: invokestatic  #211                // Method java/lang/Math.min:(II)I
     162: istore        12
     164: iload         9
     166: iload         11
     168: invokestatic  #214                // Method java/lang/Math.max:(II)I
     171: istore        13
     173: iload         12
     175: iload         13
     177: if_icmpgt     54
     180: aload_1
     181: checkcast     #91                 // class java/util/Collection
     184: iload         8
     186: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: iload         12
     191: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     194: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     197: invokeinterface #133,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     202: pop
     203: iload         12
     205: iload         13
     207: if_icmpeq     54
     210: iinc          12, 1
     213: goto          180
     216: iload         8
     218: iload         10
     220: invokestatic  #211                // Method java/lang/Math.min:(II)I
     223: istore        12
     225: iload         8
     227: iload         10
     229: invokestatic  #214                // Method java/lang/Math.max:(II)I
     232: istore        13
     234: iload         12
     236: iload         13
     238: if_icmpgt     54
     241: aload_1
     242: checkcast     #91                 // class java/util/Collection
     245: iload         12
     247: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     250: iload         9
     252: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     255: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     258: invokeinterface #133,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     263: pop
     264: iload         12
     266: iload         13
     268: if_icmpeq     54
     271: iinc          12, 1
     274: goto          241
     277: aload_1
     278: areturn

  private static final int part1(java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: checkcast     #78                 // class java/lang/Iterable
       4: invokestatic  #228                // Method kotlin/collections/CollectionsKt.toMutableSet:(Ljava/lang/Iterable;)Ljava/util/Set;
       7: astore_1
       8: aload_1
       9: checkcast     #78                 // class java/lang/Iterable
      12: astore_3
      13: iconst_0
      14: istore        4
      16: aload_3
      17: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        5
      24: aload         5
      26: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifne          42
      34: new           #230                // class java/util/NoSuchElementException
      37: dup
      38: invokespecial #231                // Method java/util/NoSuchElementException."<init>":()V
      41: athrow
      42: aload         5
      44: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        6
      51: aload         5
      53: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifne          66
      61: aload         6
      63: goto          156
      66: aload         6
      68: checkcast     #194                // class kotlin/Pair
      71: astore        7
      73: iconst_0
      74: istore        8
      76: aload         7
      78: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      81: checkcast     #201                // class java/lang/Number
      84: invokevirtual #205                // Method java/lang/Number.intValue:()I
      87: istore        9
      89: iload         9
      91: istore        7
      93: aload         5
      95: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: astore        8
     102: aload         8
     104: checkcast     #194                // class kotlin/Pair
     107: astore        9
     109: iconst_0
     110: istore        10
     112: aload         9
     114: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     117: checkcast     #201                // class java/lang/Number
     120: invokevirtual #205                // Method java/lang/Number.intValue:()I
     123: istore        11
     125: iload         11
     127: istore        9
     129: iload         7
     131: iload         9
     133: if_icmpge     144
     136: aload         8
     138: astore        6
     140: iload         9
     142: istore        7
     144: aload         5
     146: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifne          93
     154: aload         6
     156: checkcast     #194                // class kotlin/Pair
     159: invokevirtual #234                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     162: checkcast     #201                // class java/lang/Number
     165: invokevirtual #205                // Method java/lang/Number.intValue:()I
     168: istore_2
     169: iconst_0
     170: istore_3
     171: nop
     172: sipush        500
     175: istore        4
     177: iconst_0
     178: istore        5
     180: aload_1
     181: iload         4
     183: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     186: iload         5
     188: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     191: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     194: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     199: ifne          302
     202: iinc          5, 1
     205: aload_1
     206: iload         4
     208: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     211: iload         5
     213: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     216: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     219: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     224: ifeq          293
     227: aload_1
     228: iload         4
     230: iconst_1
     231: isub
     232: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: iload         5
     237: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     240: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     243: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     248: ifne          257
     251: iinc          4, -1
     254: goto          293
     257: aload_1
     258: iload         4
     260: iconst_1
     261: iadd
     262: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     265: iload         5
     267: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     270: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     273: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     278: ifne          287
     281: iinc          4, 1
     284: goto          293
     287: iinc          5, -1
     290: goto          302
     293: iload         5
     295: iload_2
     296: if_icmplt     180
     299: goto          331
     302: aload_1
     303: checkcast     #91                 // class java/util/Collection
     306: iload         4
     308: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     311: iload         5
     313: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     319: invokeinterface #133,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     324: pop
     325: iinc          3, 1
     328: goto          171
     331: iload_3
     332: ireturn

  private static final int part2(java.util.Set<kotlin.Pair<java.lang.Integer, java.lang.Integer>>);
    Code:
       0: aload_0
       1: checkcast     #78                 // class java/lang/Iterable
       4: invokestatic  #228                // Method kotlin/collections/CollectionsKt.toMutableSet:(Ljava/lang/Iterable;)Ljava/util/Set;
       7: astore_1
       8: aload_1
       9: checkcast     #78                 // class java/lang/Iterable
      12: astore_3
      13: iconst_0
      14: istore        4
      16: aload_3
      17: invokeinterface #95,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      22: astore        5
      24: aload         5
      26: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      31: ifne          42
      34: new           #230                // class java/util/NoSuchElementException
      37: dup
      38: invokespecial #231                // Method java/util/NoSuchElementException."<init>":()V
      41: athrow
      42: aload         5
      44: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      49: astore        6
      51: aload         5
      53: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      58: ifne          66
      61: aload         6
      63: goto          156
      66: aload         6
      68: checkcast     #194                // class kotlin/Pair
      71: astore        7
      73: iconst_0
      74: istore        8
      76: aload         7
      78: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      81: checkcast     #201                // class java/lang/Number
      84: invokevirtual #205                // Method java/lang/Number.intValue:()I
      87: istore        9
      89: iload         9
      91: istore        7
      93: aload         5
      95: invokeinterface #105,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     100: astore        8
     102: aload         8
     104: checkcast     #194                // class kotlin/Pair
     107: astore        9
     109: iconst_0
     110: istore        10
     112: aload         9
     114: invokevirtual #199                // Method kotlin/Pair.component2:()Ljava/lang/Object;
     117: checkcast     #201                // class java/lang/Number
     120: invokevirtual #205                // Method java/lang/Number.intValue:()I
     123: istore        11
     125: iload         11
     127: istore        9
     129: iload         7
     131: iload         9
     133: if_icmpge     144
     136: aload         8
     138: astore        6
     140: iload         9
     142: istore        7
     144: aload         5
     146: invokeinterface #101,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     151: ifne          93
     154: aload         6
     156: checkcast     #194                // class kotlin/Pair
     159: invokevirtual #234                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     162: checkcast     #201                // class java/lang/Number
     165: invokevirtual #205                // Method java/lang/Number.intValue:()I
     168: istore_2
     169: iconst_0
     170: istore_3
     171: nop
     172: sipush        500
     175: istore        4
     177: iconst_0
     178: istore        5
     180: aload_1
     181: iload         4
     183: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     186: iload         5
     188: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     191: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     194: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     199: ifne          307
     202: iinc          5, 1
     205: aload_1
     206: iload         4
     208: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     211: iload         5
     213: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     216: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     219: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     224: ifeq          293
     227: aload_1
     228: iload         4
     230: iconst_1
     231: isub
     232: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: iload         5
     237: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     240: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     243: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     248: ifne          257
     251: iinc          4, -1
     254: goto          293
     257: aload_1
     258: iload         4
     260: iconst_1
     261: iadd
     262: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     265: iload         5
     267: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     270: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     273: invokeinterface #237,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
     278: ifne          287
     281: iinc          4, 1
     284: goto          293
     287: iinc          5, -1
     290: goto          307
     293: iload         5
     295: iload_2
     296: iconst_2
     297: iadd
     298: if_icmpne     180
     301: iinc          5, -1
     304: goto          307
     307: aload_1
     308: checkcast     #91                 // class java/util/Collection
     311: iload         4
     313: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     316: iload         5
     318: invokestatic  #123                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     321: invokestatic  #129                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     324: invokeinterface #133,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     329: pop
     330: iinc          3, 1
     333: iload         4
     335: sipush        500
     338: if_icmpne     171
     341: iload         5
     343: ifne          171
     346: goto          349
     349: iload_3
     350: ireturn

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