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

/**
 * Reads lines from the given input txt file.
 */
fun readInput(name: String) = File("src", "$name.txt")
    .readLines()

/**
 * Reads input separated by empty line
 */
fun readGroupedInput(name: String) = File("src", "$name.txt").readText().split("\n\n")

fun List<String>.splitLinesToInts() = map { it.split("\n").toListOfInts() }

fun List<String>.toListOfInts() = map { it.toInt() }

fun <T> List<T>.allDistinct() = distinct().size == size

fun <T> List<T>.pair(): Pair<T, T> =
    if (size == 2) Pair(this[0], this[1]) else throw IllegalArgumentException("Input array has wrong size")

fun String.remove(regex: Regex) = replace(regex, "")
fun String.splitWords() = split(" ")

fun <T> List<List<T>>.transpose(): List<List<T>> {
    val desiredSize = maxOf { it.size }
    val resultList = List<MutableList<T>>(desiredSize) { mutableListOf() }
    forEach { list ->
        list.forEachIndexed { index, item ->
            resultList[index].add(item)
        }
    }
    return resultList
}

fun <T> List<T>.head() = first()
fun <T> List<T>.dropHead() = drop(1)

fun String.getAllInts() = "(-?\\d+)".toRegex().findAll(this).map { it.value.toInt() }.toList()

fun String.getAllByRegex(regex: Regex) = regex.findAll(this).map { it.value }.toList()

fun List<Long>.factorial() = reduce { acc, it -> acc * it }
fun List<Int>.factorial() = reduce { acc, it -> acc * it }

typealias Position = Pair<Int, Int>

operator fun Position.plus(other: Position) = Position(x + other.x, y + other.y)
operator fun Position.minus(other: Position) = Position(x - other.x, y - other.y)
val Position.x: Int
    get() = first
val Position.y: Int
    get() = second

fun Position.manhattanDistanceTo(other: Position) = abs(x - other.x) + abs(y - other.y)
fun <T> MutableList<T>.popHead(): T {
    val head = head()
    removeFirst()
    return head
}

fun IntRange.limitValuesInRange(valueRange: IntRange): IntRange {
    return first.coerceAtLeast(valueRange.first)..last.coerceAtMost(valueRange.last)
}

fun List<Int>.valueRange(): IntRange {
    return min()..max()
}

Compiled from "Utils.kt"
public final class UtilsKt {
  public static final java.util.List<java.lang.String> readInput(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String name
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/io/File
       9: dup
      10: ldc           #20                 // String src
      12: new           #22                 // class java/lang/StringBuilder
      15: dup
      16: invokespecial #26                 // Method java/lang/StringBuilder."<init>":()V
      19: aload_0
      20: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      23: ldc           #32                 // String .txt
      25: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      28: invokevirtual #36                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      31: invokespecial #39                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      34: aconst_null
      35: iconst_1
      36: aconst_null
      37: invokestatic  #45                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      40: areturn

  public static final java.util.List<java.lang.String> readGroupedInput(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #10                 // String name
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #18                 // class java/io/File
       9: dup
      10: ldc           #20                 // String src
      12: new           #22                 // class java/lang/StringBuilder
      15: dup
      16: invokespecial #26                 // Method java/lang/StringBuilder."<init>":()V
      19: aload_0
      20: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      23: ldc           #32                 // String .txt
      25: invokevirtual #30                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      28: invokevirtual #36                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      31: invokespecial #39                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      34: aconst_null
      35: iconst_1
      36: aconst_null
      37: invokestatic  #51                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      40: checkcast     #53                 // class java/lang/CharSequence
      43: iconst_1
      44: anewarray     #55                 // class java/lang/String
      47: astore_1
      48: aload_1
      49: iconst_0
      50: ldc           #57                 // String \n\n
      52: aastore
      53: aload_1
      54: iconst_0
      55: iconst_0
      56: bipush        6
      58: aconst_null
      59: invokestatic  #63                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      62: areturn

  public static final java.util.List<java.util.List<java.lang.Integer>> splitLinesToInts(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #72                 // class java/util/ArrayList
      18: dup
      19: aload_1
      20: bipush        10
      22: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      25: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
      28: checkcast     #83                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          119
      54: aload         6
      56: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         4
      65: aload         7
      67: checkcast     #55                 // class java/lang/String
      70: astore        8
      72: astore        11
      74: iconst_0
      75: istore        9
      77: aload         8
      79: checkcast     #53                 // class java/lang/CharSequence
      82: iconst_1
      83: anewarray     #55                 // class java/lang/String
      86: astore        10
      88: aload         10
      90: iconst_0
      91: ldc           #99                 // String \n
      93: aastore
      94: aload         10
      96: iconst_0
      97: iconst_0
      98: bipush        6
     100: aconst_null
     101: invokestatic  #63                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     104: invokestatic  #102                // Method toListOfInts:(Ljava/util/List;)Ljava/util/List;
     107: aload         11
     109: swap
     110: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     115: pop
     116: goto          44
     119: aload         4
     121: checkcast     #108                // class java/util/List
     124: nop
     125: areturn

  public static final java.util.List<java.lang.Integer> toListOfInts(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: astore_3
      15: new           #72                 // class java/util/ArrayList
      18: dup
      19: aload_1
      20: bipush        10
      22: invokestatic  #78                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      25: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
      28: checkcast     #83                 // class java/util/Collection
      31: astore        4
      33: iconst_0
      34: istore        5
      36: aload_3
      37: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        6
      44: aload         6
      46: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          98
      54: aload         6
      56: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        7
      63: aload         4
      65: aload         7
      67: checkcast     #55                 // class java/lang/String
      70: astore        8
      72: astore        10
      74: iconst_0
      75: istore        9
      77: aload         8
      79: invokestatic  #129                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      82: nop
      83: invokestatic  #133                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: aload         10
      88: swap
      89: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      94: pop
      95: goto          44
      98: aload         4
     100: checkcast     #108                // class java/util/List
     103: nop
     104: areturn

  public static final <T> boolean allDistinct(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: invokestatic  #142                // Method kotlin/collections/CollectionsKt.distinct:(Ljava/lang/Iterable;)Ljava/util/List;
      13: invokeinterface #146,  1          // InterfaceMethod java/util/List.size:()I
      18: aload_0
      19: invokeinterface #146,  1          // InterfaceMethod java/util/List.size:()I
      24: if_icmpne     31
      27: iconst_1
      28: goto          32
      31: iconst_0
      32: ireturn

  public static final <T> kotlin.Pair<T, T> pair(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #146,  1          // InterfaceMethod java/util/List.size:()I
      12: iconst_2
      13: if_icmpne     40
      16: new           #152                // class kotlin/Pair
      19: dup
      20: aload_0
      21: iconst_0
      22: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      27: aload_0
      28: iconst_1
      29: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      34: invokespecial #159                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      37: goto          50
      40: new           #161                // class java/lang/IllegalArgumentException
      43: dup
      44: ldc           #163                // String Input array has wrong size
      46: invokespecial #166                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      49: athrow
      50: areturn

  public static final java.lang.String remove(java.lang.String, kotlin.text.Regex);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #171                // String regex
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #53                 // class java/lang/CharSequence
      16: astore_2
      17: ldc           #173                // String
      19: astore_3
      20: aload_1
      21: aload_2
      22: aload_3
      23: invokevirtual #179                // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      26: areturn

  public static final java.util.List<java.lang.String> splitWords(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #53                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #55                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #184                // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #63                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: areturn

  public static final <T> java.util.List<java.util.List<T>> transpose(java.util.List<? extends java.util.List<? extends T>>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore_3
      16: aload_3
      17: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifne          33
      25: new           #189                // class java/util/NoSuchElementException
      28: dup
      29: invokespecial #190                // Method java/util/NoSuchElementException."<init>":()V
      32: athrow
      33: aload_3
      34: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #108                // class java/util/List
      42: astore        4
      44: iconst_0
      45: istore        5
      47: aload         4
      49: invokeinterface #146,  1          // InterfaceMethod java/util/List.size:()I
      54: istore        4
      56: aload_3
      57: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      62: ifeq          102
      65: aload_3
      66: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      71: checkcast     #108                // class java/util/List
      74: astore        5
      76: iconst_0
      77: istore        6
      79: aload         5
      81: invokeinterface #146,  1          // InterfaceMethod java/util/List.size:()I
      86: istore        5
      88: iload         4
      90: iload         5
      92: if_icmpge     56
      95: iload         5
      97: istore        4
      99: goto          56
     102: iload         4
     104: istore_1
     105: new           #72                 // class java/util/ArrayList
     108: dup
     109: iload_1
     110: invokespecial #81                 // Method java/util/ArrayList."<init>":(I)V
     113: astore_3
     114: iconst_0
     115: istore        4
     117: iload         4
     119: iload_1
     120: if_icmpge     161
     123: iload         4
     125: istore        5
     127: aload_3
     128: iload         5
     130: istore        6
     132: astore        18
     134: iconst_0
     135: istore        7
     137: new           #72                 // class java/util/ArrayList
     140: dup
     141: invokespecial #191                // Method java/util/ArrayList."<init>":()V
     144: checkcast     #108                // class java/util/List
     147: nop
     148: aload         18
     150: swap
     151: invokevirtual #192                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     154: pop
     155: iinc          4, 1
     158: goto          117
     161: aload_3
     162: checkcast     #108                // class java/util/List
     165: astore_2
     166: aload_0
     167: checkcast     #70                 // class java/lang/Iterable
     170: astore_3
     171: iconst_0
     172: istore        4
     174: aload_3
     175: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     180: astore        5
     182: aload         5
     184: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     189: ifeq          308
     192: aload         5
     194: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     199: astore        6
     201: aload         6
     203: checkcast     #108                // class java/util/List
     206: astore        7
     208: iconst_0
     209: istore        8
     211: aload         7
     213: checkcast     #70                 // class java/lang/Iterable
     216: astore        9
     218: iconst_0
     219: istore        10
     221: iconst_0
     222: istore        11
     224: aload         9
     226: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     231: astore        12
     233: aload         12
     235: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     240: ifeq          302
     243: aload         12
     245: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     250: astore        13
     252: iload         11
     254: iinc          11, 1
     257: istore        14
     259: iload         14
     261: ifge          267
     264: invokestatic  #195                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     267: iload         14
     269: aload         13
     271: astore        15
     273: istore        16
     275: iconst_0
     276: istore        17
     278: aload_2
     279: iload         16
     281: invokeinterface #156,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     286: checkcast     #108                // class java/util/List
     289: aload         15
     291: invokeinterface #196,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     296: pop
     297: nop
     298: nop
     299: goto          233
     302: nop
     303: nop
     304: nop
     305: goto          182
     308: nop
     309: aload_2
     310: areturn

  public static final <T> T head(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #219                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
      10: areturn

  public static final <T> java.util.List<T> dropHead(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: iconst_1
      11: invokestatic  #226                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
      14: areturn

  public static final java.util.List<java.lang.Integer> getAllInts(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #175                // class kotlin/text/Regex
       9: dup
      10: ldc           #231                // String (-?\\d+)
      12: invokespecial #232                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      15: aload_0
      16: checkcast     #53                 // class java/lang/CharSequence
      19: iconst_0
      20: iconst_2
      21: aconst_null
      22: invokestatic  #236                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      25: invokedynamic #256,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      30: invokestatic  #262                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      33: invokestatic  #266                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      36: areturn

  public static final java.util.List<java.lang.String> getAllByRegex(java.lang.String, kotlin.text.Regex);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #171                // String regex
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: aload_0
      14: checkcast     #53                 // class java/lang/CharSequence
      17: iconst_0
      18: iconst_2
      19: aconst_null
      20: invokestatic  #236                // Method kotlin/text/Regex.findAll$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/sequences/Sequence;
      23: invokedynamic #277,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      28: invokestatic  #262                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      31: invokestatic  #266                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      34: areturn

  public static final long factorial(java.util.List<java.lang.Long>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifne          40
      29: new           #283                // class java/lang/UnsupportedOperationException
      32: dup
      33: ldc_w         #285                // String Empty collection can\'t be reduced.
      36: invokespecial #286                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
      39: athrow
      40: aload_3
      41: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        4
      48: aload_3
      49: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          97
      57: aload         4
      59: aload_3
      60: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      65: checkcast     #288                // class java/lang/Number
      68: invokevirtual #292                // Method java/lang/Number.longValue:()J
      71: lstore        5
      73: checkcast     #288                // class java/lang/Number
      76: invokevirtual #292                // Method java/lang/Number.longValue:()J
      79: lstore        7
      81: iconst_0
      82: istore        9
      84: lload         7
      86: lload         5
      88: lmul
      89: invokestatic  #297                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      92: astore        4
      94: goto          48
      97: aload         4
      99: checkcast     #288                // class java/lang/Number
     102: invokevirtual #292                // Method java/lang/Number.longValue:()J
     105: lreturn

  public static final int factorial(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #70                 // class java/lang/Iterable
      10: astore_1
      11: iconst_0
      12: istore_2
      13: aload_1
      14: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      19: astore_3
      20: aload_3
      21: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      26: ifne          40
      29: new           #283                // class java/lang/UnsupportedOperationException
      32: dup
      33: ldc_w         #285                // String Empty collection can\'t be reduced.
      36: invokespecial #286                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
      39: athrow
      40: aload_3
      41: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        4
      48: aload_3
      49: invokeinterface #93,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      54: ifeq          97
      57: aload         4
      59: aload_3
      60: invokeinterface #97,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      65: checkcast     #288                // class java/lang/Number
      68: invokevirtual #311                // Method java/lang/Number.intValue:()I
      71: istore        5
      73: checkcast     #288                // class java/lang/Number
      76: invokevirtual #311                // Method java/lang/Number.intValue:()I
      79: istore        6
      81: iconst_0
      82: istore        7
      84: iload         6
      86: iload         5
      88: imul
      89: invokestatic  #133                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: astore        4
      94: goto          48
      97: aload         4
      99: checkcast     #288                // class java/lang/Number
     102: invokevirtual #311                // Method java/lang/Number.intValue:()I
     105: ireturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> plus(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #317                // String other
      10: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: new           #152                // class kotlin/Pair
      16: dup
      17: aload_0
      18: invokestatic  #321                // Method getX:(Lkotlin/Pair;)I
      21: aload_1
      22: invokestatic  #321                // Method getX:(Lkotlin/Pair;)I
      25: iadd
      26: invokestatic  #133                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: aload_0
      30: invokestatic  #324                // Method getY:(Lkotlin/Pair;)I
      33: aload_1
      34: invokestatic  #324                // Method getY:(Lkotlin/Pair;)I
      37: iadd
      38: invokestatic  #133                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokespecial #159                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      44: areturn

  public static final kotlin.Pair<java.lang.Integer, java.lang.Integer> minus(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #317                // String other
      10: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: new           #152                // class kotlin/Pair
      16: dup
      17: aload_0
      18: invokestatic  #321                // Method getX:(Lkotlin/Pair;)I
      21: aload_1
      22: invokestatic  #321                // Method getX:(Lkotlin/Pair;)I
      25: isub
      26: invokestatic  #133                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      29: aload_0
      30: invokestatic  #324                // Method getY:(Lkotlin/Pair;)I
      33: aload_1
      34: invokestatic  #324                // Method getY:(Lkotlin/Pair;)I
      37: isub
      38: invokestatic  #133                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokespecial #159                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      44: areturn

  public static final int getX(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #332                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      10: checkcast     #288                // class java/lang/Number
      13: invokevirtual #311                // Method java/lang/Number.intValue:()I
      16: ireturn

  public static final int getY(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #336                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      10: checkcast     #288                // class java/lang/Number
      13: invokevirtual #311                // Method java/lang/Number.intValue:()I
      16: ireturn

  public static final int manhattanDistanceTo(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #317                // String other
      10: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: aload_0
      14: invokestatic  #321                // Method getX:(Lkotlin/Pair;)I
      17: aload_1
      18: invokestatic  #321                // Method getX:(Lkotlin/Pair;)I
      21: isub
      22: invokestatic  #346                // Method java/lang/Math.abs:(I)I
      25: aload_0
      26: invokestatic  #324                // Method getY:(Lkotlin/Pair;)I
      29: aload_1
      30: invokestatic  #324                // Method getY:(Lkotlin/Pair;)I
      33: isub
      34: invokestatic  #346                // Method java/lang/Math.abs:(I)I
      37: iadd
      38: ireturn

  public static final <T> T popHead(java.util.List<T>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #351                // Method head:(Ljava/util/List;)Ljava/lang/Object;
      10: astore_1
      11: aload_0
      12: invokeinterface #354,  1          // InterfaceMethod java/util/List.removeFirst:()Ljava/lang/Object;
      17: pop
      18: aload_1
      19: areturn

  public static final kotlin.ranges.IntRange limitValuesInRange(kotlin.ranges.IntRange, kotlin.ranges.IntRange);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc_w         #359                // String valueRange
      10: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: new           #361                // class kotlin/ranges/IntRange
      16: dup
      17: aload_0
      18: invokevirtual #363                // Method kotlin/ranges/IntRange.getFirst:()I
      21: aload_1
      22: invokevirtual #363                // Method kotlin/ranges/IntRange.getFirst:()I
      25: invokestatic  #369                // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      28: aload_0
      29: invokevirtual #372                // Method kotlin/ranges/IntRange.getLast:()I
      32: aload_1
      33: invokevirtual #372                // Method kotlin/ranges/IntRange.getLast:()I
      36: invokestatic  #375                // Method kotlin/ranges/RangesKt.coerceAtMost:(II)I
      39: invokespecial #378                // Method kotlin/ranges/IntRange."<init>":(II)V
      42: areturn

  public static final kotlin.ranges.IntRange valueRange(java.util.List<java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #68                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #361                // class kotlin/ranges/IntRange
       9: dup
      10: aload_0
      11: checkcast     #70                 // class java/lang/Iterable
      14: invokestatic  #386                // Method kotlin/collections/CollectionsKt.minOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      17: checkcast     #288                // class java/lang/Number
      20: invokevirtual #311                // Method java/lang/Number.intValue:()I
      23: aload_0
      24: checkcast     #70                 // class java/lang/Iterable
      27: invokestatic  #389                // Method kotlin/collections/CollectionsKt.maxOrThrow:(Ljava/lang/Iterable;)Ljava/lang/Comparable;
      30: checkcast     #288                // class java/lang/Number
      33: invokevirtual #311                // Method java/lang/Number.intValue:()I
      36: invokespecial #378                // Method kotlin/ranges/IntRange."<init>":(II)V
      39: areturn

  private static final int getAllInts$lambda$6(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #391                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #396,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      13: invokestatic  #129                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      16: ireturn

  private static final java.lang.String getAllByRegex$lambda$7(kotlin.text.MatchResult);
    Code:
       0: aload_0
       1: ldc_w         #391                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokeinterface #396,  1          // InterfaceMethod kotlin/text/MatchResult.getValue:()Ljava/lang/String;
      13: areturn
}


import java.lang.Integer.max
import java.lang.Integer.min

private typealias Path = List<Position>
private typealias MutableMatrix<T> = MutableList<MutableList<T>>

private val Pair<Int, Int>.depth: Int
    get() = second

private fun List<Path>.getMaxValue(selector: (Position) -> Int) =
    flatten().maxOf { selector(it) }

private fun List<Path>.toFieldMatrix(): MutableMatrix<FieldType> {
    val maxDepth = getMaxValue { it.depth }
    val maxWidth = getMaxValue { it.x }
    val matrix = MutableList(maxDepth + 1) { MutableList(maxWidth * 2) { FieldType.AIR } }
    forEach { path ->
        path.windowed(2).forEach { (start, end) ->
            val xRange = min(start.x, end.x)..max(start.x, end.x)
            val depthRange = min(start.depth, end.depth)..max(start.depth, end.depth)
            for (x in xRange) {
                for (y in depthRange) {
                    matrix[y][x] = FieldType.ROCK
                }
            }
        }
    }
    return matrix
}

private fun MutableList<MutableList<FieldType>>.addRow(type: FieldType) {
    add(MutableList(first().size) { type })
}

fun main() {
    fun parseInput(name: String) =
        readInput(name)
            .map { line ->
                line.split(" -> ")
                    .map { path ->
                        path.split(",")
                            .toListOfInts()
                            .pair()
                    }
            }

    fun simulate(fieldMatrix: MutableMatrix<FieldType>): Int {
        fun nextPosition(position: Position): Position? {
            val directionsToCheck = listOf(Position(0, 1), Position(-1, 1), Position(1, 1))
            for (direction in directionsToCheck) {
                val newPosition = position + direction
                if (fieldMatrix[newPosition.depth][newPosition.x] == FieldType.AIR) {
                    return newPosition
                }
            }
            return null
        }

        val maxDepth = fieldMatrix.size - 1
        val sandStartPosition = Position(500, 0)
        var position = sandStartPosition

        while (position.depth < maxDepth && fieldMatrix[sandStartPosition.depth][sandStartPosition.x] == FieldType.AIR) {
            with(nextPosition(position)) {
                if (this == null) {
                    fieldMatrix[position.depth][position.x] = FieldType.SAND
                    position = sandStartPosition
                } else {
                    position = this
                }
            }
        }
        return fieldMatrix.flatten().count { it == FieldType.SAND }
    }

    fun part1(fieldMatrix: MutableMatrix<FieldType>) = simulate(fieldMatrix)

    fun part2(fieldMatrix: MutableMatrix<FieldType>): Int {
        fieldMatrix.apply {
            addRow(FieldType.AIR)
            addRow(FieldType.ROCK)
        }
        return simulate(fieldMatrix)
    }

    val testInput = parseInput("Day14_test").toFieldMatrix()
    check(part1(testInput) == 24)
    check(part2(testInput) == 93)

    val input = parseInput("Day14").toFieldMatrix()
    println(part1(input))
    println(part2(input))
}

private enum class FieldType {
    AIR,
    SAND,
    ROCK
}

Compiled from "Day14.kt"
public final class Day14Kt {
  private static final int getDepth(kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #13                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       4: checkcast     #15                 // class java/lang/Number
       7: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      10: ireturn

  private static final int getMaxValue(java.util.List<? extends java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>>, kotlin.jvm.functions.Function1<? super kotlin.Pair<java.lang.Integer, java.lang.Integer>, java.lang.Integer>);
    Code:
       0: aload_0
       1: checkcast     #26                 // class java/lang/Iterable
       4: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
       7: checkcast     #26                 // class java/lang/Iterable
      10: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      15: astore_2
      16: aload_2
      17: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      22: ifne          33
      25: new           #44                 // class java/util/NoSuchElementException
      28: dup
      29: invokespecial #48                 // Method java/util/NoSuchElementException."<init>":()V
      32: athrow
      33: aload_2
      34: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: checkcast     #9                  // class kotlin/Pair
      42: astore_3
      43: iconst_0
      44: istore        4
      46: aload_1
      47: aload_3
      48: invokeinterface #57,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      53: checkcast     #15                 // class java/lang/Number
      56: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      59: istore_3
      60: aload_2
      61: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      66: ifeq          111
      69: aload_2
      70: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: checkcast     #9                  // class kotlin/Pair
      78: astore        4
      80: iconst_0
      81: istore        5
      83: aload_1
      84: aload         4
      86: invokeinterface #57,  2           // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      91: checkcast     #15                 // class java/lang/Number
      94: invokevirtual #19                 // Method java/lang/Number.intValue:()I
      97: istore        4
      99: iload_3
     100: iload         4
     102: if_icmpge     60
     105: iload         4
     107: istore_3
     108: goto          60
     111: iload_3
     112: ireturn

  private static final java.util.List<java.util.List<FieldType>> toFieldMatrix(java.util.List<? extends java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>>);
    Code:
       0: aload_0
       1: invokedynamic #84,  0             // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
       6: invokestatic  #86                 // Method getMaxValue:(Ljava/util/List;Lkotlin/jvm/functions/Function1;)I
       9: istore_1
      10: aload_0
      11: invokedynamic #91,  0             // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      16: invokestatic  #86                 // Method getMaxValue:(Ljava/util/List;Lkotlin/jvm/functions/Function1;)I
      19: istore_2
      20: iload_1
      21: iconst_1
      22: iadd
      23: istore        4
      25: new           #93                 // class java/util/ArrayList
      28: dup
      29: iload         4
      31: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
      34: astore        5
      36: iconst_0
      37: istore        6
      39: iload         6
      41: iload         4
      43: if_icmpge     137
      46: iload         6
      48: istore        7
      50: aload         5
      52: iload         7
      54: istore        8
      56: astore        24
      58: iconst_0
      59: istore        9
      61: iload_2
      62: iconst_2
      63: imul
      64: istore        10
      66: new           #93                 // class java/util/ArrayList
      69: dup
      70: iload         10
      72: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
      75: astore        11
      77: iconst_0
      78: istore        12
      80: iload         12
      82: iload         10
      84: if_icmpge     118
      87: iload         12
      89: istore        13
      91: aload         11
      93: iload         13
      95: istore        14
      97: astore        15
      99: iconst_0
     100: istore        16
     102: getstatic     #102                // Field FieldType.AIR:LFieldType;
     105: aload         15
     107: swap
     108: invokevirtual #106                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     111: pop
     112: iinc          12, 1
     115: goto          80
     118: aload         11
     120: checkcast     #108                // class java/util/List
     123: nop
     124: aload         24
     126: swap
     127: invokevirtual #106                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     130: pop
     131: iinc          6, 1
     134: goto          39
     137: aload         5
     139: checkcast     #108                // class java/util/List
     142: astore_3
     143: aload_0
     144: checkcast     #26                 // class java/lang/Iterable
     147: astore        4
     149: iconst_0
     150: istore        5
     152: aload         4
     154: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     159: astore        6
     161: aload         6
     163: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     168: ifeq          447
     171: aload         6
     173: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     178: astore        7
     180: aload         7
     182: checkcast     #108                // class java/util/List
     185: astore        8
     187: iconst_0
     188: istore        9
     190: aload         8
     192: checkcast     #26                 // class java/lang/Iterable
     195: iconst_2
     196: iconst_0
     197: iconst_0
     198: bipush        6
     200: aconst_null
     201: invokestatic  #112                // Method kotlin/collections/CollectionsKt.windowed$default:(Ljava/lang/Iterable;IIZILjava/lang/Object;)Ljava/util/List;
     204: checkcast     #26                 // class java/lang/Iterable
     207: astore        10
     209: iconst_0
     210: istore        11
     212: aload         10
     214: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     219: astore        12
     221: aload         12
     223: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     228: ifeq          441
     231: aload         12
     233: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     238: astore        13
     240: aload         13
     242: checkcast     #108                // class java/util/List
     245: astore        14
     247: iconst_0
     248: istore        15
     250: aload         14
     252: iconst_0
     253: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     258: checkcast     #9                  // class kotlin/Pair
     261: astore        16
     263: aload         14
     265: iconst_1
     266: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     271: checkcast     #9                  // class kotlin/Pair
     274: astore        17
     276: new           #118                // class kotlin/ranges/IntRange
     279: dup
     280: aload         16
     282: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     285: aload         17
     287: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     290: invokestatic  #129                // Method java/lang/Integer.min:(II)I
     293: aload         16
     295: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     298: aload         17
     300: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     303: invokestatic  #132                // Method java/lang/Integer.max:(II)I
     306: invokespecial #135                // Method kotlin/ranges/IntRange."<init>":(II)V
     309: astore        18
     311: new           #118                // class kotlin/ranges/IntRange
     314: dup
     315: aload         16
     317: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
     320: aload         17
     322: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
     325: invokestatic  #129                // Method java/lang/Integer.min:(II)I
     328: aload         16
     330: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
     333: aload         17
     335: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
     338: invokestatic  #132                // Method java/lang/Integer.max:(II)I
     341: invokespecial #135                // Method kotlin/ranges/IntRange."<init>":(II)V
     344: astore        19
     346: aload         18
     348: invokevirtual #140                // Method kotlin/ranges/IntRange.getFirst:()I
     351: istore        20
     353: aload         18
     355: invokevirtual #143                // Method kotlin/ranges/IntRange.getLast:()I
     358: istore        21
     360: iload         20
     362: iload         21
     364: if_icmpgt     436
     367: aload         19
     369: invokevirtual #140                // Method kotlin/ranges/IntRange.getFirst:()I
     372: istore        22
     374: aload         19
     376: invokevirtual #143                // Method kotlin/ranges/IntRange.getLast:()I
     379: istore        23
     381: iload         22
     383: iload         23
     385: if_icmpgt     423
     388: aload_3
     389: iload         22
     391: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     396: checkcast     #108                // class java/util/List
     399: iload         20
     401: getstatic     #146                // Field FieldType.ROCK:LFieldType;
     404: invokeinterface #150,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     409: pop
     410: iload         22
     412: iload         23
     414: if_icmpeq     423
     417: iinc          22, 1
     420: goto          388
     423: iload         20
     425: iload         21
     427: if_icmpeq     436
     430: iinc          20, 1
     433: goto          367
     436: nop
     437: nop
     438: goto          221
     441: nop
     442: nop
     443: nop
     444: goto          161
     447: nop
     448: aload_3
     449: areturn

  private static final void addRow(java.util.List<java.util.List<FieldType>>, FieldType);
    Code:
       0: aload_0
       1: aload_0
       2: invokestatic  #178                // Method kotlin/collections/CollectionsKt.first:(Ljava/util/List;)Ljava/lang/Object;
       5: checkcast     #108                // class java/util/List
       8: invokeinterface #181,  1          // InterfaceMethod java/util/List.size:()I
      13: istore_2
      14: astore        8
      16: new           #93                 // class java/util/ArrayList
      19: dup
      20: iload_2
      21: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
      24: astore_3
      25: iconst_0
      26: istore        4
      28: iload         4
      30: iload_2
      31: if_icmpge     62
      34: iload         4
      36: istore        5
      38: aload_3
      39: iload         5
      41: istore        6
      43: astore        9
      45: iconst_0
      46: istore        7
      48: aload_1
      49: aload         9
      51: swap
      52: invokevirtual #106                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      55: pop
      56: iinc          4, 1
      59: goto          28
      62: aload_3
      63: checkcast     #108                // class java/util/List
      66: aload         8
      68: swap
      69: invokeinterface #182,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      74: pop
      75: return

  public static final void main();
    Code:
       0: ldc           #188                // String Day14_test
       2: invokestatic  #192                // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
       5: invokestatic  #194                // Method toFieldMatrix:(Ljava/util/List;)Ljava/util/List;
       8: astore_0
       9: aload_0
      10: invokestatic  #198                // Method main$part1:(Ljava/util/List;)I
      13: bipush        24
      15: if_icmpne     22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifne          36
      26: new           #200                // class java/lang/IllegalStateException
      29: dup
      30: ldc           #202                // String Check failed.
      32: invokespecial #205                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      35: athrow
      36: aload_0
      37: invokestatic  #208                // Method main$part2:(Ljava/util/List;)I
      40: bipush        93
      42: if_icmpne     49
      45: iconst_1
      46: goto          50
      49: iconst_0
      50: ifne          63
      53: new           #200                // class java/lang/IllegalStateException
      56: dup
      57: ldc           #202                // String Check failed.
      59: invokespecial #205                // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      62: athrow
      63: ldc           #210                // String Day14
      65: invokestatic  #192                // Method main$parseInput:(Ljava/lang/String;)Ljava/util/List;
      68: invokestatic  #194                // Method toFieldMatrix:(Ljava/util/List;)Ljava/util/List;
      71: astore_1
      72: aload_1
      73: invokestatic  #198                // Method main$part1:(Ljava/util/List;)I
      76: istore_2
      77: getstatic     #216                // Field java/lang/System.out:Ljava/io/PrintStream;
      80: iload_2
      81: invokevirtual #221                // Method java/io/PrintStream.println:(I)V
      84: aload_1
      85: invokestatic  #208                // Method main$part2:(Ljava/util/List;)I
      88: istore_2
      89: getstatic     #216                // Field java/lang/System.out:Ljava/io/PrintStream;
      92: iload_2
      93: invokevirtual #221                // Method java/io/PrintStream.println:(I)V
      96: return

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

  private static final int toFieldMatrix$lambda$1(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc           #229                // String it
       3: invokestatic  #235                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
      10: ireturn

  private static final int toFieldMatrix$lambda$2(kotlin.Pair);
    Code:
       0: aload_0
       1: ldc           #229                // String it
       3: invokestatic  #235                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
      10: ireturn

  private static final java.util.List<java.util.List<kotlin.Pair<java.lang.Integer, java.lang.Integer>>> main$parseInput(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #239                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       4: checkcast     #26                 // class java/lang/Iterable
       7: astore_1
       8: nop
       9: iconst_0
      10: istore_2
      11: aload_1
      12: astore_3
      13: new           #93                 // class java/util/ArrayList
      16: dup
      17: aload_1
      18: bipush        10
      20: invokestatic  #243                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #245                // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          244
      52: aload         6
      54: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         4
      63: aload         7
      65: checkcast     #247                // class java/lang/String
      68: astore        8
      70: astore        21
      72: iconst_0
      73: istore        9
      75: aload         8
      77: checkcast     #249                // class java/lang/CharSequence
      80: iconst_1
      81: anewarray     #247                // class java/lang/String
      84: astore        10
      86: aload         10
      88: iconst_0
      89: ldc           #251                // String  ->
      91: aastore
      92: aload         10
      94: iconst_0
      95: iconst_0
      96: bipush        6
      98: aconst_null
      99: invokestatic  #257                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     102: checkcast     #26                 // class java/lang/Iterable
     105: astore        10
     107: nop
     108: iconst_0
     109: istore        11
     111: aload         10
     113: astore        12
     115: new           #93                 // class java/util/ArrayList
     118: dup
     119: aload         10
     121: bipush        10
     123: invokestatic  #243                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     126: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
     129: checkcast     #245                // class java/util/Collection
     132: astore        13
     134: iconst_0
     135: istore        14
     137: aload         12
     139: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     144: astore        15
     146: aload         15
     148: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     153: ifeq          225
     156: aload         15
     158: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     163: astore        16
     165: aload         13
     167: aload         16
     169: checkcast     #247                // class java/lang/String
     172: astore        17
     174: astore        18
     176: iconst_0
     177: istore        19
     179: aload         17
     181: checkcast     #249                // class java/lang/CharSequence
     184: iconst_1
     185: anewarray     #247                // class java/lang/String
     188: astore        20
     190: aload         20
     192: iconst_0
     193: ldc_w         #259                // String ,
     196: aastore
     197: aload         20
     199: iconst_0
     200: iconst_0
     201: bipush        6
     203: aconst_null
     204: invokestatic  #257                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     207: invokestatic  #262                // Method UtilsKt.toListOfInts:(Ljava/util/List;)Ljava/util/List;
     210: invokestatic  #266                // Method UtilsKt.pair:(Ljava/util/List;)Lkotlin/Pair;
     213: aload         18
     215: swap
     216: invokeinterface #267,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     221: pop
     222: goto          146
     225: aload         13
     227: checkcast     #108                // class java/util/List
     230: nop
     231: nop
     232: aload         21
     234: swap
     235: invokeinterface #267,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     240: pop
     241: goto          42
     244: aload         4
     246: checkcast     #108                // class java/util/List
     249: nop
     250: areturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> main$simulate$nextPosition(java.util.List<java.util.List<FieldType>>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: iconst_3
       1: anewarray     #9                  // class kotlin/Pair
       4: astore_3
       5: aload_3
       6: iconst_0
       7: new           #9                  // class kotlin/Pair
      10: dup
      11: iconst_0
      12: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: iconst_1
      16: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: invokespecial #289                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      22: aastore
      23: aload_3
      24: iconst_1
      25: new           #9                  // class kotlin/Pair
      28: dup
      29: iconst_m1
      30: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: iconst_1
      34: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      37: invokespecial #289                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      40: aastore
      41: aload_3
      42: iconst_2
      43: new           #9                  // class kotlin/Pair
      46: dup
      47: iconst_1
      48: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      51: iconst_1
      52: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: invokespecial #289                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      58: aastore
      59: aload_3
      60: invokestatic  #293                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
      63: astore_2
      64: aload_2
      65: invokeinterface #294,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      70: astore_3
      71: aload_3
      72: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      77: ifeq          132
      80: aload_3
      81: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: checkcast     #9                  // class kotlin/Pair
      89: astore        4
      91: aload_1
      92: aload         4
      94: invokestatic  #298                // Method UtilsKt.plus:(Lkotlin/Pair;Lkotlin/Pair;)Lkotlin/Pair;
      97: astore        5
      99: aload_0
     100: aload         5
     102: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
     105: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     110: checkcast     #108                // class java/util/List
     113: aload         5
     115: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
     118: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     123: getstatic     #102                // Field FieldType.AIR:LFieldType;
     126: if_acmpne     71
     129: aload         5
     131: areturn
     132: aconst_null
     133: areturn

  private static final int main$simulate(java.util.List<java.util.List<FieldType>>);
    Code:
       0: aload_0
       1: invokeinterface #181,  1          // InterfaceMethod java/util/List.size:()I
       6: iconst_1
       7: isub
       8: istore_1
       9: new           #9                  // class kotlin/Pair
      12: dup
      13: sipush        500
      16: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      19: iconst_0
      20: invokestatic  #286                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      23: invokespecial #289                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      26: astore_2
      27: aconst_null
      28: astore_3
      29: aload_2
      30: astore_3
      31: aload_3
      32: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
      35: iload_1
      36: if_icmpge     120
      39: aload_0
      40: aload_2
      41: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
      44: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      49: checkcast     #108                // class java/util/List
      52: aload_2
      53: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
      56: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      61: getstatic     #102                // Field FieldType.AIR:LFieldType;
      64: if_acmpne     120
      67: aload_0
      68: aload_3
      69: invokestatic  #307                // Method main$simulate$nextPosition:(Ljava/util/List;Lkotlin/Pair;)Lkotlin/Pair;
      72: astore        5
      74: iconst_0
      75: istore        6
      77: aload         5
      79: ifnonnull     113
      82: aload_0
      83: aload_3
      84: invokestatic  #137                // Method getDepth:(Lkotlin/Pair;)I
      87: invokeinterface #116,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      92: checkcast     #108                // class java/util/List
      95: aload_3
      96: invokestatic  #123                // Method UtilsKt.getX:(Lkotlin/Pair;)I
      99: getstatic     #310                // Field FieldType.SAND:LFieldType;
     102: invokeinterface #150,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     107: pop
     108: aload_2
     109: astore_3
     110: goto          116
     113: aload         5
     115: astore_3
     116: nop
     117: goto          31
     120: aload_0
     121: checkcast     #26                 // class java/lang/Iterable
     124: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     127: checkcast     #26                 // class java/lang/Iterable
     130: astore        4
     132: iconst_0
     133: istore        5
     135: aload         4
     137: instanceof    #245                // class java/util/Collection
     140: ifeq          160
     143: aload         4
     145: checkcast     #245                // class java/util/Collection
     148: invokeinterface #313,  1          // InterfaceMethod java/util/Collection.isEmpty:()Z
     153: ifeq          160
     156: iconst_0
     157: goto          233
     160: iconst_0
     161: istore        6
     163: aload         4
     165: invokeinterface #36,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     170: astore        7
     172: aload         7
     174: invokeinterface #42,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     179: ifeq          231
     182: aload         7
     184: invokeinterface #51,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     189: astore        8
     191: aload         8
     193: checkcast     #98                 // class FieldType
     196: astore        9
     198: iconst_0
     199: istore        10
     201: aload         9
     203: getstatic     #310                // Field FieldType.SAND:LFieldType;
     206: if_acmpne     213
     209: iconst_1
     210: goto          214
     213: iconst_0
     214: ifeq          172
     217: iinc          6, 1
     220: iload         6
     222: ifge          172
     225: invokestatic  #316                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     228: goto          172
     231: iload         6
     233: ireturn

  private static final int main$part1(java.util.List<java.util.List<FieldType>>);
    Code:
       0: aload_0
       1: invokestatic  #326                // Method main$simulate:(Ljava/util/List;)I
       4: ireturn

  private static final int main$part2(java.util.List<java.util.List<FieldType>>);
    Code:
       0: aload_0
       1: astore_1
       2: aload_1
       3: astore_2
       4: iconst_0
       5: istore_3
       6: aload_2
       7: getstatic     #102                // Field FieldType.AIR:LFieldType;
      10: invokestatic  #328                // Method addRow:(Ljava/util/List;LFieldType;)V
      13: aload_2
      14: getstatic     #146                // Field FieldType.ROCK:LFieldType;
      17: invokestatic  #328                // Method addRow:(Ljava/util/List;LFieldType;)V
      20: nop
      21: nop
      22: aload_0
      23: invokestatic  #326                // Method main$simulate:(Ljava/util/List;)I
      26: ireturn
}


typealias SectionRange = Pair<Int, Int>

fun main() {
    infix fun SectionRange.contains(range: SectionRange): Boolean {
        return first <= range.first && this.second >= range.second
    }

    infix fun SectionRange.overlap(range: SectionRange): Boolean {
        return first <= range.second && range.first <= second
    }

    fun part1(input: List<Pair<SectionRange, SectionRange>>) =
        input.count { it.first contains it.second || it.second contains it.first }

    fun part2(input: List<Pair<SectionRange, SectionRange>>) =
        input.count { it.first overlap it.second || it.second overlap it.first }

    fun parseInput(name: String): List<Pair<SectionRange, SectionRange>> {
        fun parseSectionRange(input: String) =
            input.split("-").map { it.toInt() }.pair()

        return readInput(name)
            .map {
                it.split(",").pair()
                    .let { ranges ->
                        Pair(parseSectionRange(ranges.first), parseSectionRange(ranges.second))
                    }
            }
    }

    val testInput = parseInput("Day04_test")
    check(part1(testInput) == 2)
    check(part2(testInput) == 4)

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

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

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

  private static final boolean main$contains(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #62                 // class java/lang/Number
       7: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      10: aload_1
      11: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      14: checkcast     #62                 // class java/lang/Number
      17: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      20: if_icmpgt     50
      23: aload_0
      24: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      27: checkcast     #62                 // class java/lang/Number
      30: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      33: aload_1
      34: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      37: checkcast     #62                 // class java/lang/Number
      40: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      43: if_icmplt     50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: ireturn

  private static final boolean main$overlap(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       4: checkcast     #62                 // class java/lang/Number
       7: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      10: aload_1
      11: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      14: checkcast     #62                 // class java/lang/Number
      17: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      20: if_icmpgt     50
      23: aload_1
      24: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      27: checkcast     #62                 // class java/lang/Number
      30: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      33: aload_0
      34: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      37: checkcast     #62                 // class java/lang/Number
      40: invokevirtual #66                 // Method java/lang/Number.intValue:()I
      43: if_icmpgt     50
      46: iconst_1
      47: goto          51
      50: iconst_0
      51: ireturn

  private static final int main$part1(java.util.List<kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>>);
    Code:
       0: aload_0
       1: checkcast     #77                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: instanceof    #79                 // class java/util/Collection
      11: ifeq          30
      14: aload_1
      15: checkcast     #79                 // class java/util/Collection
      18: invokeinterface #83,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      23: ifeq          30
      26: iconst_0
      27: goto          135
      30: iconst_0
      31: istore_3
      32: aload_1
      33: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        4
      40: aload         4
      42: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          134
      50: aload         4
      52: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        5
      59: aload         5
      61: checkcast     #56                 // class kotlin/Pair
      64: astore        6
      66: iconst_0
      67: istore        7
      69: aload         6
      71: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      74: checkcast     #56                 // class kotlin/Pair
      77: aload         6
      79: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      82: checkcast     #56                 // class kotlin/Pair
      85: invokestatic  #97                 // Method main$contains:(Lkotlin/Pair;Lkotlin/Pair;)Z
      88: ifne          113
      91: aload         6
      93: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      96: checkcast     #56                 // class kotlin/Pair
      99: aload         6
     101: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     104: checkcast     #56                 // class kotlin/Pair
     107: invokestatic  #97                 // Method main$contains:(Lkotlin/Pair;Lkotlin/Pair;)Z
     110: ifeq          117
     113: iconst_1
     114: goto          118
     117: iconst_0
     118: ifeq          40
     121: iinc          3, 1
     124: iload_3
     125: ifge          40
     128: invokestatic  #102                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     131: goto          40
     134: iload_3
     135: ireturn

  private static final int main$part2(java.util.List<kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>>);
    Code:
       0: aload_0
       1: checkcast     #77                 // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: instanceof    #79                 // class java/util/Collection
      11: ifeq          30
      14: aload_1
      15: checkcast     #79                 // class java/util/Collection
      18: invokeinterface #83,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      23: ifeq          30
      26: iconst_0
      27: goto          135
      30: iconst_0
      31: istore_3
      32: aload_1
      33: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        4
      40: aload         4
      42: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          134
      50: aload         4
      52: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        5
      59: aload         5
      61: checkcast     #56                 // class kotlin/Pair
      64: astore        6
      66: iconst_0
      67: istore        7
      69: aload         6
      71: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      74: checkcast     #56                 // class kotlin/Pair
      77: aload         6
      79: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      82: checkcast     #56                 // class kotlin/Pair
      85: invokestatic  #113                // Method main$overlap:(Lkotlin/Pair;Lkotlin/Pair;)Z
      88: ifne          113
      91: aload         6
      93: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      96: checkcast     #56                 // class kotlin/Pair
      99: aload         6
     101: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     104: checkcast     #56                 // class kotlin/Pair
     107: invokestatic  #113                // Method main$overlap:(Lkotlin/Pair;Lkotlin/Pair;)Z
     110: ifeq          117
     113: iconst_1
     114: goto          118
     117: iconst_0
     118: ifeq          40
     121: iinc          3, 1
     124: iload_3
     125: ifge          40
     128: invokestatic  #102                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     131: goto          40
     134: iload_3
     135: ireturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> main$parseInput$parseSectionRange(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #119                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #121                // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc           #123                // String -
      13: aastore
      14: aload_1
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #129                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #77                 // class java/lang/Iterable
      26: astore_1
      27: iconst_0
      28: istore_2
      29: aload_1
      30: astore_3
      31: new           #131                // class java/util/ArrayList
      34: dup
      35: aload_1
      36: bipush        10
      38: invokestatic  #135                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      41: invokespecial #137                // Method java/util/ArrayList."<init>":(I)V
      44: checkcast     #79                 // class java/util/Collection
      47: astore        4
      49: iconst_0
      50: istore        5
      52: aload_3
      53: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        6
      60: aload         6
      62: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          114
      70: aload         6
      72: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        7
      79: aload         4
      81: aload         7
      83: checkcast     #121                // class java/lang/String
      86: astore        8
      88: astore        10
      90: iconst_0
      91: istore        9
      93: aload         8
      95: invokestatic  #143                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      98: nop
      99: invokestatic  #147                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: aload         10
     104: swap
     105: invokeinterface #151,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     110: pop
     111: goto          60
     114: aload         4
     116: checkcast     #46                 // class java/util/List
     119: nop
     120: invokestatic  #157                // Method UtilsKt.pair:(Ljava/util/List;)Lkotlin/Pair;
     123: areturn

  private static final java.util.List<kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>>> main$parseInput(java.lang.String);
    Code:
       0: aload_0
       1: invokestatic  #170                // Method UtilsKt.readInput:(Ljava/lang/String;)Ljava/util/List;
       4: checkcast     #77                 // class java/lang/Iterable
       7: astore_1
       8: nop
       9: iconst_0
      10: istore_2
      11: aload_1
      12: astore_3
      13: new           #131                // class java/util/ArrayList
      16: dup
      17: aload_1
      18: bipush        10
      20: invokestatic  #135                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokespecial #137                // Method java/util/ArrayList."<init>":(I)V
      26: checkcast     #79                 // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #87,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #92,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          153
      52: aload         6
      54: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         4
      63: aload         7
      65: checkcast     #121                // class java/lang/String
      68: astore        8
      70: astore        13
      72: iconst_0
      73: istore        9
      75: aload         8
      77: checkcast     #119                // class java/lang/CharSequence
      80: iconst_1
      81: anewarray     #121                // class java/lang/String
      84: astore        10
      86: aload         10
      88: iconst_0
      89: ldc           #172                // String ,
      91: aastore
      92: aload         10
      94: iconst_0
      95: iconst_0
      96: bipush        6
      98: aconst_null
      99: invokestatic  #129                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     102: invokestatic  #157                // Method UtilsKt.pair:(Ljava/util/List;)Lkotlin/Pair;
     105: astore        11
     107: iconst_0
     108: istore        12
     110: new           #56                 // class kotlin/Pair
     113: dup
     114: aload         11
     116: invokevirtual #60                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     119: checkcast     #121                // class java/lang/String
     122: invokestatic  #174                // Method main$parseInput$parseSectionRange:(Ljava/lang/String;)Lkotlin/Pair;
     125: aload         11
     127: invokevirtual #69                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     130: checkcast     #121                // class java/lang/String
     133: invokestatic  #174                // Method main$parseInput$parseSectionRange:(Ljava/lang/String;)Lkotlin/Pair;
     136: invokespecial #177                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     139: nop
     140: nop
     141: aload         13
     143: swap
     144: invokeinterface #151,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     149: pop
     150: goto          42
     153: aload         4
     155: checkcast     #46                 // class java/util/List
     158: nop
     159: areturn
}