import java.io.File

fun main() {
  val result = File("inputs/day_11_1.txt").useLines { totalBusiness(monkeys(it), 10000, 1) }
  println(result)
}

fun totalBusiness(startState: Map<Int, Monkey>, times: Int = 20, divideBy: Int = 3) =
  (1..times)
    .fold(startState) { acc, _ -> simulateThrows(acc, divideBy, startState.values.totalDivides()) }
    .values.map { it.count }
    .sortedDescending()
    .take(2)
    .reduce(Long::times)

private fun Collection<Monkey>.totalDivides() = map { it.divisibleBy }.reduce(Int::times)

fun simulateThrows(monkeys: Map<Int, Monkey>, divideBy: Int, totalDivides: Int) =
  monkeys.keys.fold(monkeys) { acc, i -> rearrange(acc, acc[i]!!.throwStuff(divideBy, totalDivides)) }

fun rearrange(acc: Map<Int, Monkey>, newPositions: Map<Int, List<Long>>) =
  newPositions.entries.fold(acc) { a, (n, items) -> a + (n to a[n]!!.updateItems(items)) }

fun monkeys(lines: Sequence<String>) =
  lines.filter { it.isNotBlank() }
    .chunked(6)
    .map { parseMonkey(it) }
    .associateBy { it.n }
fun parseMonkey(lines: List<String>) = Monkey(
  n = lines[0].split(" ")[1].split(":")[0].toInt(),
  items = lines[1].split(": ")[1].split(", ").map { it.toLong() },
  operation = parseOp(lines[2].split("= ")[1].split(" ")),
  next = parseDivisible(lastInt(lines[3]), lastInt(lines[4]), lastInt(lines[5])),
  divisibleBy = lastInt(lines[3])
)

fun parseDivisible(divisibleBy: Int, option1: Int, option2: Int) = { n: Long ->
  if (n % divisibleBy == 0L) option1 else option2
}

private fun lastInt(line: String) = line.split(" ").last().toInt()

fun parseOp(s: List<String>) = when (s[1]) {
  "*" -> operation(s[0], s[2], Long::times)
  "+" -> operation(s[0], s[2], Long::plus)
  "-" -> operation(s[0], s[2], Long::minus)
  "/" -> operation(s[0], s[2], Long::div)
  else -> throw IllegalArgumentException()
}

fun operation(op1: String, op2: String, param: (Long, Long) -> Long) = op1.toLongOrNull()
  ?.let {operand1 ->  op2.toLongOrNull()?.let { { _: Long -> param(operand1, it) } } ?: { n: Long -> param(n, operand1) } }
  ?: op2.toLongOrNull()?.let { { n: Long -> param(n, it) } } ?: { n: Long -> param(n, n) }

data class Monkey(
  val n: Int, val items: List<Long>,
  val operation: Function1<Long, Long>,
  val next: (Long) -> Int,
  val divisibleBy: Int,
  val count: Long = 0) {
  fun throwStuff(divideBy: Int, totalDivides: Int) =
    items.map { (operation(it % totalDivides) / divideBy) }.groupBy { next(it) } + (n to listOf())

  fun updateItems(newItems: List<Long>) =
    if (newItems.isEmpty()) copy(items = listOf(), count = count + items.size)
    else copy(items = items + newItems)
  override fun toString(): String {
    return "Monkey(n=$n, items=$items, count=$count)"
  }
}

Compiled from "Day11.kt"
final class Day11Kt$parseOp$1 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Long, java.lang.Long, java.lang.Long> {
  public static final Day11Kt$parseOp$1 INSTANCE;

  Day11Kt$parseOp$1();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Long.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String times
       7: ldc           #19                 // String times(J)J
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Long invoke(long, long);
    Code:
       0: lload_1
       1: lload_3
       2: lmul
       3: invokestatic  #30                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.longValue:()J
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.longValue:()J
      15: invokevirtual #42                 // Method invoke:(JJ)Ljava/lang/Long;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class Day11Kt$parseOp$1
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:LDay11Kt$parseOp$1;
      10: return
}

Compiled from "Day11.kt"
final class Day11Kt$parseOp$3 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Long, java.lang.Long, java.lang.Long> {
  public static final Day11Kt$parseOp$3 INSTANCE;

  Day11Kt$parseOp$3();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Long.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String minus
       7: ldc           #19                 // String minus(J)J
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Long invoke(long, long);
    Code:
       0: lload_1
       1: lload_3
       2: lsub
       3: invokestatic  #30                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.longValue:()J
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.longValue:()J
      15: invokevirtual #42                 // Method invoke:(JJ)Ljava/lang/Long;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class Day11Kt$parseOp$3
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:LDay11Kt$parseOp$3;
      10: return
}

Compiled from "Day11.kt"
final class Day11Kt$parseOp$4 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Long, java.lang.Long, java.lang.Long> {
  public static final Day11Kt$parseOp$4 INSTANCE;

  Day11Kt$parseOp$4();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Long.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String div
       7: ldc           #19                 // String div(J)J
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Long invoke(long, long);
    Code:
       0: lload_1
       1: lload_3
       2: ldiv
       3: invokestatic  #30                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.longValue:()J
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.longValue:()J
      15: invokevirtual #42                 // Method invoke:(JJ)Ljava/lang/Long;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class Day11Kt$parseOp$4
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:LDay11Kt$parseOp$4;
      10: return
}

Compiled from "Day11.kt"
final class Day11Kt$parseOp$2 extends kotlin.jvm.internal.FunctionReferenceImpl implements kotlin.jvm.functions.Function2<java.lang.Long, java.lang.Long, java.lang.Long> {
  public static final Day11Kt$parseOp$2 INSTANCE;

  Day11Kt$parseOp$2();
    Code:
       0: aload_0
       1: iconst_2
       2: getstatic     #15                 // Field java/lang/Long.TYPE:Ljava/lang/Class;
       5: ldc           #17                 // String plus
       7: ldc           #19                 // String plus(J)J
       9: iconst_0
      10: invokespecial #22                 // Method kotlin/jvm/internal/FunctionReferenceImpl."<init>":(ILjava/lang/Class;Ljava/lang/String;Ljava/lang/String;I)V
      13: return

  public final java.lang.Long invoke(long, long);
    Code:
       0: lload_1
       1: lload_3
       2: ladd
       3: invokestatic  #30                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       6: areturn

  public java.lang.Object invoke(java.lang.Object, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: checkcast     #36                 // class java/lang/Number
       5: invokevirtual #40                 // Method java/lang/Number.longValue:()J
       8: aload_2
       9: checkcast     #36                 // class java/lang/Number
      12: invokevirtual #40                 // Method java/lang/Number.longValue:()J
      15: invokevirtual #42                 // Method invoke:(JJ)Ljava/lang/Long;
      18: areturn

  static {};
    Code:
       0: new           #2                  // class Day11Kt$parseOp$2
       3: dup
       4: invokespecial #47                 // Method "<init>":()V
       7: putstatic     #50                 // Field INSTANCE:LDay11Kt$parseOp$2;
      10: return
}

Compiled from "Day11.kt"
public final class Day11Kt {
  public static final void main();
    Code:
       0: new           #10                 // class java/io/File
       3: dup
       4: ldc           #12                 // String inputs/day_11_1.txt
       6: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_2
      10: getstatic     #22                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_3
      14: iconst_0
      15: istore        4
      17: aload_2
      18: astore        5
      20: sipush        8192
      23: istore        6
      25: aload         5
      27: astore        7
      29: new           #24                 // class java/io/InputStreamReader
      32: dup
      33: new           #26                 // class java/io/FileInputStream
      36: dup
      37: aload         7
      39: invokespecial #29                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      42: checkcast     #31                 // class java/io/InputStream
      45: aload_3
      46: invokespecial #34                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      49: checkcast     #36                 // class java/io/Reader
      52: astore        7
      54: aload         7
      56: instanceof    #38                 // class java/io/BufferedReader
      59: ifeq          70
      62: aload         7
      64: checkcast     #38                 // class java/io/BufferedReader
      67: goto          81
      70: new           #38                 // class java/io/BufferedReader
      73: dup
      74: aload         7
      76: iload         6
      78: invokespecial #41                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      81: checkcast     #43                 // class java/io/Closeable
      84: astore        5
      86: aconst_null
      87: astore        6
      89: nop
      90: aload         5
      92: checkcast     #38                 // class java/io/BufferedReader
      95: astore        7
      97: iconst_0
      98: istore        9
     100: aload         7
     102: invokestatic  #49                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     105: astore        10
     107: iconst_0
     108: istore        11
     110: aload         10
     112: invokestatic  #53                 // Method monkeys:(Lkotlin/sequences/Sequence;)Ljava/util/Map;
     115: sipush        10000
     118: iconst_1
     119: invokestatic  #57                 // Method totalBusiness:(Ljava/util/Map;II)J
     122: lstore        7
     124: aload         5
     126: aload         6
     128: invokestatic  #63                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     131: lload         7
     133: goto          157
     136: astore        9
     138: aload         9
     140: astore        6
     142: aload         9
     144: athrow
     145: astore        9
     147: aload         5
     149: aload         6
     151: invokestatic  #63                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     154: aload         9
     156: athrow
     157: nop
     158: lstore_0
     159: getstatic     #69                 // Field java/lang/System.out:Ljava/io/PrintStream;
     162: lload_0
     163: invokevirtual #75                 // Method java/io/PrintStream.println:(J)V
     166: return
    Exception table:
       from    to  target type
          89   124   136   Class java/lang/Throwable
          89   124   145   any
         136   145   145   any
         145   147   145   any

  public static final long totalBusiness(java.util.Map<java.lang.Integer, Monkey>, int, int);
    Code:
       0: aload_0
       1: ldc           #96                 // String startState
       3: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #104                // class kotlin/ranges/IntRange
       9: dup
      10: iconst_1
      11: iload_1
      12: invokespecial #107                // Method kotlin/ranges/IntRange."<init>":(II)V
      15: checkcast     #109                // class java/lang/Iterable
      18: astore_3
      19: nop
      20: iconst_0
      21: istore        4
      23: aload_0
      24: astore        5
      26: aload_3
      27: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        6
      34: aload         6
      36: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          81
      44: aload         6
      46: checkcast     #121                // class kotlin/collections/IntIterator
      49: invokevirtual #125                // Method kotlin/collections/IntIterator.nextInt:()I
      52: istore        7
      54: aload         5
      56: astore        9
      58: iconst_0
      59: istore        10
      61: aload         9
      63: iload_2
      64: aload_0
      65: invokeinterface #131,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      70: invokestatic  #135                // Method totalDivides:(Ljava/util/Collection;)I
      73: invokestatic  #139                // Method simulateThrows:(Ljava/util/Map;II)Ljava/util/Map;
      76: astore        5
      78: goto          34
      81: aload         5
      83: invokeinterface #131,  1          // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      88: checkcast     #109                // class java/lang/Iterable
      91: astore_3
      92: iconst_0
      93: istore        4
      95: aload_3
      96: astore        5
      98: new           #141                // class java/util/ArrayList
     101: dup
     102: aload_3
     103: bipush        10
     105: invokestatic  #147                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     108: invokespecial #150                // Method java/util/ArrayList."<init>":(I)V
     111: checkcast     #152                // class java/util/Collection
     114: astore        6
     116: iconst_0
     117: istore        7
     119: aload         5
     121: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     126: astore        8
     128: aload         8
     130: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     135: ifeq          181
     138: aload         8
     140: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     145: astore        9
     147: aload         6
     149: aload         9
     151: checkcast     #158                // class Monkey
     154: astore        10
     156: astore        12
     158: iconst_0
     159: istore        11
     161: aload         10
     163: invokevirtual #162                // Method Monkey.getCount:()J
     166: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     169: aload         12
     171: swap
     172: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     177: pop
     178: goto          128
     181: aload         6
     183: checkcast     #174                // class java/util/List
     186: nop
     187: checkcast     #109                // class java/lang/Iterable
     190: invokestatic  #178                // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
     193: checkcast     #109                // class java/lang/Iterable
     196: iconst_2
     197: invokestatic  #182                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     200: checkcast     #109                // class java/lang/Iterable
     203: astore_3
     204: nop
     205: iconst_0
     206: istore        4
     208: aload_3
     209: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     214: astore        5
     216: aload         5
     218: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     223: ifne          236
     226: new           #184                // class java/lang/UnsupportedOperationException
     229: dup
     230: ldc           #186                // String Empty collection can\'t be reduced.
     232: invokespecial #187                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     235: athrow
     236: aload         5
     238: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     243: astore        6
     245: aload         5
     247: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     252: ifeq          296
     255: aload         6
     257: aload         5
     259: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     264: checkcast     #189                // class java/lang/Number
     267: invokevirtual #192                // Method java/lang/Number.longValue:()J
     270: lstore        7
     272: checkcast     #189                // class java/lang/Number
     275: invokevirtual #192                // Method java/lang/Number.longValue:()J
     278: lstore        9
     280: iconst_0
     281: istore        11
     283: lload         9
     285: lload         7
     287: lmul
     288: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     291: astore        6
     293: goto          245
     296: aload         6
     298: checkcast     #189                // class java/lang/Number
     301: invokevirtual #192                // Method java/lang/Number.longValue:()J
     304: lreturn

  public static long totalBusiness$default(java.util.Map, int, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          9
       6: bipush        20
       8: istore_1
       9: iload_3
      10: iconst_4
      11: iand
      12: ifeq          17
      15: iconst_3
      16: istore_2
      17: aload_0
      18: iload_1
      19: iload_2
      20: invokestatic  #57                 // Method totalBusiness:(Ljava/util/Map;II)J
      23: lreturn

  private static final int totalDivides(java.util.Collection<Monkey>);
    Code:
       0: aload_0
       1: checkcast     #109                // class java/lang/Iterable
       4: astore_1
       5: iconst_0
       6: istore_2
       7: aload_1
       8: astore_3
       9: new           #141                // class java/util/ArrayList
      12: dup
      13: aload_1
      14: bipush        10
      16: invokestatic  #147                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      19: invokespecial #150                // Method java/util/ArrayList."<init>":(I)V
      22: checkcast     #152                // class java/util/Collection
      25: astore        4
      27: iconst_0
      28: istore        5
      30: aload_3
      31: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      36: astore        6
      38: aload         6
      40: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      45: ifeq          91
      48: aload         6
      50: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      55: astore        7
      57: aload         4
      59: aload         7
      61: checkcast     #158                // class Monkey
      64: astore        8
      66: astore        10
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokevirtual #225                // Method Monkey.getDivisibleBy:()I
      76: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: aload         10
      81: swap
      82: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      87: pop
      88: goto          38
      91: aload         4
      93: checkcast     #174                // class java/util/List
      96: nop
      97: checkcast     #109                // class java/lang/Iterable
     100: astore_1
     101: nop
     102: iconst_0
     103: istore_2
     104: aload_1
     105: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     110: astore_3
     111: aload_3
     112: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     117: ifne          130
     120: new           #184                // class java/lang/UnsupportedOperationException
     123: dup
     124: ldc           #186                // String Empty collection can\'t be reduced.
     126: invokespecial #187                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     129: athrow
     130: aload_3
     131: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     136: astore        4
     138: aload_3
     139: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          187
     147: aload         4
     149: aload_3
     150: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     155: checkcast     #189                // class java/lang/Number
     158: invokevirtual #233                // Method java/lang/Number.intValue:()I
     161: istore        5
     163: checkcast     #189                // class java/lang/Number
     166: invokevirtual #233                // Method java/lang/Number.intValue:()I
     169: istore        6
     171: iconst_0
     172: istore        7
     174: iload         6
     176: iload         5
     178: imul
     179: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     182: astore        4
     184: goto          138
     187: aload         4
     189: checkcast     #189                // class java/lang/Number
     192: invokevirtual #233                // Method java/lang/Number.intValue:()I
     195: ireturn

  public static final java.util.Map<java.lang.Integer, Monkey> simulateThrows(java.util.Map<java.lang.Integer, Monkey>, int, int);
    Code:
       0: aload_0
       1: ldc           #238                // String monkeys
       3: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #242,  1          // InterfaceMethod java/util/Map.keySet:()Ljava/util/Set;
      12: checkcast     #109                // class java/lang/Iterable
      15: astore_3
      16: iconst_0
      17: istore        4
      19: aload_0
      20: astore        5
      22: aload_3
      23: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      28: astore        6
      30: aload         6
      32: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      37: ifeq          100
      40: aload         6
      42: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      47: astore        7
      49: aload         5
      51: aload         7
      53: checkcast     #189                // class java/lang/Number
      56: invokevirtual #233                // Method java/lang/Number.intValue:()I
      59: istore        8
      61: astore        9
      63: iconst_0
      64: istore        10
      66: aload         9
      68: aload         9
      70: iload         8
      72: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      75: invokeinterface #246,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
      80: dup
      81: invokestatic  #250                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      84: checkcast     #158                // class Monkey
      87: iload_1
      88: iload_2
      89: invokevirtual #254                // Method Monkey.throwStuff:(II)Ljava/util/Map;
      92: invokestatic  #258                // Method rearrange:(Ljava/util/Map;Ljava/util/Map;)Ljava/util/Map;
      95: astore        5
      97: goto          30
     100: aload         5
     102: areturn

  public static final java.util.Map<java.lang.Integer, Monkey> rearrange(java.util.Map<java.lang.Integer, Monkey>, java.util.Map<java.lang.Integer, ? extends java.util.List<java.lang.Long>>);
    Code:
       0: aload_0
       1: ldc_w         #262                // String acc
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #264                // String newPositions
      11: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_1
      15: invokeinterface #267,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
      20: checkcast     #109                // class java/lang/Iterable
      23: astore_2
      24: iconst_0
      25: istore_3
      26: aload_0
      27: astore        4
      29: aload_2
      30: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      35: astore        5
      37: aload         5
      39: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      44: ifeq          139
      47: aload         5
      49: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      54: astore        6
      56: aload         4
      58: aload         6
      60: checkcast     #269                // class java/util/Map$Entry
      63: astore        7
      65: astore        8
      67: iconst_0
      68: istore        9
      70: aload         7
      72: invokeinterface #272,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      77: checkcast     #189                // class java/lang/Number
      80: invokevirtual #233                // Method java/lang/Number.intValue:()I
      83: istore        10
      85: aload         7
      87: invokeinterface #275,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      92: checkcast     #174                // class java/util/List
      95: astore        11
      97: aload         8
      99: iload         10
     101: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     104: aload         8
     106: iload         10
     108: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     111: invokeinterface #246,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     116: dup
     117: invokestatic  #250                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     120: checkcast     #158                // class Monkey
     123: aload         11
     125: invokevirtual #279                // Method Monkey.updateItems:(Ljava/util/List;)LMonkey;
     128: invokestatic  #285                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     131: invokestatic  #291                // Method kotlin/collections/MapsKt.plus:(Ljava/util/Map;Lkotlin/Pair;)Ljava/util/Map;
     134: astore        4
     136: goto          37
     139: aload         4
     141: areturn

  public static final java.util.Map<java.lang.Integer, Monkey> monkeys(kotlin.sequences.Sequence<java.lang.String>);
    Code:
       0: aload_0
       1: ldc_w         #299                // String lines
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokedynamic #318,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      13: invokestatic  #324                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      16: bipush        6
      18: invokestatic  #328                // Method kotlin/sequences/SequencesKt.chunked:(Lkotlin/sequences/Sequence;I)Lkotlin/sequences/Sequence;
      21: invokedynamic #334,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      26: invokestatic  #337                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      29: astore_1
      30: nop
      31: iconst_0
      32: istore_2
      33: aload_1
      34: astore_3
      35: new           #339                // class java/util/LinkedHashMap
      38: dup
      39: invokespecial #341                // Method java/util/LinkedHashMap."<init>":()V
      42: checkcast     #127                // class java/util/Map
      45: astore        4
      47: iconst_0
      48: istore        5
      50: aload_3
      51: invokeinterface #342,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      56: astore        6
      58: aload         6
      60: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      65: ifeq          113
      68: aload         6
      70: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      75: astore        7
      77: aload         4
      79: aload         7
      81: checkcast     #158                // class Monkey
      84: astore        8
      86: astore        10
      88: iconst_0
      89: istore        9
      91: aload         8
      93: invokevirtual #345                // Method Monkey.getN:()I
      96: invokestatic  #230                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: aload         10
     101: swap
     102: aload         7
     104: invokeinterface #349,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     109: pop
     110: goto          58
     113: aload         4
     115: nop
     116: areturn

  public static final Monkey parseMonkey(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc_w         #299                // String lines
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: iconst_0
       9: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      14: checkcast     #362                // class java/lang/CharSequence
      17: iconst_1
      18: anewarray     #364                // class java/lang/String
      21: astore_1
      22: aload_1
      23: iconst_0
      24: ldc_w         #366                // String
      27: aastore
      28: aload_1
      29: iconst_0
      30: iconst_0
      31: bipush        6
      33: aconst_null
      34: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      37: iconst_1
      38: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      43: checkcast     #362                // class java/lang/CharSequence
      46: iconst_1
      47: anewarray     #364                // class java/lang/String
      50: astore_1
      51: aload_1
      52: iconst_0
      53: ldc_w         #374                // String :
      56: aastore
      57: aload_1
      58: iconst_0
      59: iconst_0
      60: bipush        6
      62: aconst_null
      63: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      66: iconst_0
      67: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: checkcast     #364                // class java/lang/String
      75: invokestatic  #378                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      78: aload_0
      79: iconst_1
      80: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      85: checkcast     #362                // class java/lang/CharSequence
      88: iconst_1
      89: anewarray     #364                // class java/lang/String
      92: astore_1
      93: aload_1
      94: iconst_0
      95: ldc_w         #380                // String :
      98: aastore
      99: aload_1
     100: iconst_0
     101: iconst_0
     102: bipush        6
     104: aconst_null
     105: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     108: iconst_1
     109: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     114: checkcast     #362                // class java/lang/CharSequence
     117: iconst_1
     118: anewarray     #364                // class java/lang/String
     121: astore_1
     122: aload_1
     123: iconst_0
     124: ldc_w         #382                // String ,
     127: aastore
     128: aload_1
     129: iconst_0
     130: iconst_0
     131: bipush        6
     133: aconst_null
     134: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     137: checkcast     #109                // class java/lang/Iterable
     140: astore_1
     141: istore        10
     143: iconst_0
     144: istore_2
     145: aload_1
     146: astore_3
     147: new           #141                // class java/util/ArrayList
     150: dup
     151: aload_1
     152: bipush        10
     154: invokestatic  #147                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     157: invokespecial #150                // Method java/util/ArrayList."<init>":(I)V
     160: checkcast     #152                // class java/util/Collection
     163: astore        4
     165: iconst_0
     166: istore        5
     168: aload_3
     169: invokeinterface #113,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     174: astore        6
     176: aload         6
     178: invokeinterface #119,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     183: ifeq          230
     186: aload         6
     188: invokeinterface #156,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     193: astore        7
     195: aload         4
     197: aload         7
     199: checkcast     #364                // class java/lang/String
     202: astore        8
     204: astore        11
     206: iconst_0
     207: istore        9
     209: aload         8
     211: invokestatic  #386                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     214: nop
     215: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     218: aload         11
     220: swap
     221: invokeinterface #172,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     226: pop
     227: goto          176
     230: aload         4
     232: checkcast     #174                // class java/util/List
     235: nop
     236: astore        11
     238: iload         10
     240: aload         11
     242: aload_0
     243: iconst_2
     244: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     249: checkcast     #362                // class java/lang/CharSequence
     252: iconst_1
     253: anewarray     #364                // class java/lang/String
     256: astore_1
     257: aload_1
     258: iconst_0
     259: ldc_w         #388                // String =
     262: aastore
     263: aload_1
     264: iconst_0
     265: iconst_0
     266: bipush        6
     268: aconst_null
     269: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     272: iconst_1
     273: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     278: checkcast     #362                // class java/lang/CharSequence
     281: iconst_1
     282: anewarray     #364                // class java/lang/String
     285: astore_1
     286: aload_1
     287: iconst_0
     288: ldc_w         #366                // String
     291: aastore
     292: aload_1
     293: iconst_0
     294: iconst_0
     295: bipush        6
     297: aconst_null
     298: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     301: invokestatic  #392                // Method parseOp:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     304: aload_0
     305: iconst_3
     306: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     311: checkcast     #364                // class java/lang/String
     314: invokestatic  #395                // Method lastInt:(Ljava/lang/String;)I
     317: aload_0
     318: iconst_4
     319: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     324: checkcast     #364                // class java/lang/String
     327: invokestatic  #395                // Method lastInt:(Ljava/lang/String;)I
     330: aload_0
     331: iconst_5
     332: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     337: checkcast     #364                // class java/lang/String
     340: invokestatic  #395                // Method lastInt:(Ljava/lang/String;)I
     343: invokestatic  #399                // Method parseDivisible:(III)Lkotlin/jvm/functions/Function1;
     346: aload_0
     347: iconst_3
     348: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     353: checkcast     #364                // class java/lang/String
     356: invokestatic  #395                // Method lastInt:(Ljava/lang/String;)I
     359: lconst_0
     360: bipush        32
     362: aconst_null
     363: astore        12
     365: istore        13
     367: lstore        14
     369: istore        16
     371: astore        17
     373: astore        18
     375: astore        19
     377: istore        20
     379: new           #158                // class Monkey
     382: dup
     383: iload         20
     385: aload         19
     387: aload         18
     389: aload         17
     391: iload         16
     393: lload         14
     395: iload         13
     397: aload         12
     399: invokespecial #402                // Method Monkey."<init>":(ILjava/util/List;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;IJILkotlin/jvm/internal/DefaultConstructorMarker;)V
     402: areturn

  public static final kotlin.jvm.functions.Function1<java.lang.Long, java.lang.Integer> parseDivisible(int, int, int);
    Code:
       0: iload_0
       1: iload_1
       2: iload_2
       3: invokedynamic #414,  0            // InvokeDynamic #2:invoke:(III)Lkotlin/jvm/functions/Function1;
       8: areturn

  private static final int lastInt(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #362                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #364                // class java/lang/String
       8: astore_1
       9: aload_1
      10: iconst_0
      11: ldc_w         #366                // String
      14: aastore
      15: aload_1
      16: iconst_0
      17: iconst_0
      18: bipush        6
      20: aconst_null
      21: invokestatic  #372                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      24: invokestatic  #421                // Method kotlin/collections/CollectionsKt.last:(Ljava/util/List;)Ljava/lang/Object;
      27: checkcast     #364                // class java/lang/String
      30: invokestatic  #378                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      33: ireturn

  public static final kotlin.jvm.functions.Function1<java.lang.Long, java.lang.Long> parseOp(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc_w         #425                // String s
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: iconst_1
       9: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      14: checkcast     #364                // class java/lang/String
      17: astore_1
      18: aload_1
      19: invokevirtual #428                // Method java/lang/String.hashCode:()I
      22: tableswitch   { // 42 to 47
                    42: 60
                    43: 73
                    44: 240
                    45: 86
                    46: 240
                    47: 99
               default: 240
          }
      60: aload_1
      61: ldc_w         #430                // String *
      64: invokevirtual #433                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      67: ifne          112
      70: goto          240
      73: aload_1
      74: ldc_w         #435                // String +
      77: invokevirtual #433                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      80: ifne          144
      83: goto          240
      86: aload_1
      87: ldc_w         #437                // String -
      90: invokevirtual #433                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
      93: ifne          176
      96: goto          240
      99: aload_1
     100: ldc_w         #439                // String /
     103: invokevirtual #433                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     106: ifne          208
     109: goto          240
     112: aload_0
     113: iconst_0
     114: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     119: checkcast     #364                // class java/lang/String
     122: aload_0
     123: iconst_2
     124: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     129: checkcast     #364                // class java/lang/String
     132: getstatic     #445                // Field Day11Kt$parseOp$1.INSTANCE:LDay11Kt$parseOp$1;
     135: checkcast     #447                // class kotlin/jvm/functions/Function2
     138: invokestatic  #451                // Method operation:(Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1;
     141: goto          248
     144: aload_0
     145: iconst_0
     146: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #364                // class java/lang/String
     154: aload_0
     155: iconst_2
     156: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     161: checkcast     #364                // class java/lang/String
     164: getstatic     #456                // Field Day11Kt$parseOp$2.INSTANCE:LDay11Kt$parseOp$2;
     167: checkcast     #447                // class kotlin/jvm/functions/Function2
     170: invokestatic  #451                // Method operation:(Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1;
     173: goto          248
     176: aload_0
     177: iconst_0
     178: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     183: checkcast     #364                // class java/lang/String
     186: aload_0
     187: iconst_2
     188: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     193: checkcast     #364                // class java/lang/String
     196: getstatic     #461                // Field Day11Kt$parseOp$3.INSTANCE:LDay11Kt$parseOp$3;
     199: checkcast     #447                // class kotlin/jvm/functions/Function2
     202: invokestatic  #451                // Method operation:(Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1;
     205: goto          248
     208: aload_0
     209: iconst_0
     210: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     215: checkcast     #364                // class java/lang/String
     218: aload_0
     219: iconst_2
     220: invokeinterface #360,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     225: checkcast     #364                // class java/lang/String
     228: getstatic     #466                // Field Day11Kt$parseOp$4.INSTANCE:LDay11Kt$parseOp$4;
     231: checkcast     #447                // class kotlin/jvm/functions/Function2
     234: invokestatic  #451                // Method operation:(Ljava/lang/String;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1;
     237: goto          248
     240: new           #468                // class java/lang/IllegalArgumentException
     243: dup
     244: invokespecial #469                // Method java/lang/IllegalArgumentException."<init>":()V
     247: athrow
     248: areturn

  public static final kotlin.jvm.functions.Function1<java.lang.Long, java.lang.Long> operation(java.lang.String, java.lang.String, kotlin.jvm.functions.Function2<? super java.lang.Long, ? super java.lang.Long, java.lang.Long>);
    Code:
       0: aload_0
       1: ldc_w         #474                // String op1
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: ldc_w         #476                // String op2
      11: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      14: aload_2
      15: ldc_w         #478                // String param
      18: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      21: aload_0
      22: invokestatic  #482                // Method kotlin/text/StringsKt.toLongOrNull:(Ljava/lang/String;)Ljava/lang/Long;
      25: astore_3
      26: aload_3
      27: ifnull        98
      30: aload_3
      31: checkcast     #189                // class java/lang/Number
      34: invokevirtual #192                // Method java/lang/Number.longValue:()J
      37: lstore        5
      39: iconst_0
      40: istore        7
      42: aload_1
      43: invokestatic  #482                // Method kotlin/text/StringsKt.toLongOrNull:(Ljava/lang/String;)Ljava/lang/Long;
      46: dup
      47: ifnull        76
      50: checkcast     #189                // class java/lang/Number
      53: invokevirtual #192                // Method java/lang/Number.longValue:()J
      56: lstore        8
      58: iconst_0
      59: istore        10
      61: aload_2
      62: lload         5
      64: lload         8
      66: invokedynamic #492,  0            // InvokeDynamic #3:invoke:(Lkotlin/jvm/functions/Function2;JJ)Lkotlin/jvm/functions/Function1;
      71: nop
      72: dup
      73: ifnonnull     85
      76: pop
      77: aload_2
      78: lload         5
      80: invokedynamic #500,  0            // InvokeDynamic #4:invoke:(Lkotlin/jvm/functions/Function2;J)Lkotlin/jvm/functions/Function1;
      85: nop
      86: astore        4
      88: aload         4
      90: ifnull        98
      93: aload         4
      95: goto          136
      98: aload_1
      99: invokestatic  #482                // Method kotlin/text/StringsKt.toLongOrNull:(Ljava/lang/String;)Ljava/lang/Long;
     102: dup
     103: ifnull        128
     106: checkcast     #189                // class java/lang/Number
     109: invokevirtual #192                // Method java/lang/Number.longValue:()J
     112: lstore        6
     114: iconst_0
     115: istore        8
     117: aload_2
     118: lload         6
     120: invokedynamic #505,  0            // InvokeDynamic #5:invoke:(Lkotlin/jvm/functions/Function2;J)Lkotlin/jvm/functions/Function1;
     125: goto          136
     128: pop
     129: nop
     130: aload_2
     131: invokedynamic #513,  0            // InvokeDynamic #6:invoke:(Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function1;
     136: areturn

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

  private static final boolean monkeys$lambda$7(java.lang.String);
    Code:
       0: aload_0
       1: ldc_w         #524                // String it
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: checkcast     #362                // class java/lang/CharSequence
      11: invokestatic  #528                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      14: ifne          21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ireturn

  private static final Monkey monkeys$lambda$8(java.util.List);
    Code:
       0: aload_0
       1: ldc_w         #524                // String it
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokestatic  #530                // Method parseMonkey:(Ljava/util/List;)LMonkey;
      11: areturn

  private static final int parseDivisible$lambda$11(int, int, int, long);
    Code:
       0: lload_3
       1: iload_0
       2: i2l
       3: lrem
       4: lconst_0
       5: lcmp
       6: ifne          13
       9: iload_1
      10: goto          14
      13: iload_2
      14: ireturn

  private static final long operation$lambda$15$lambda$13$lambda$12(kotlin.jvm.functions.Function2, long, long, long);
    Code:
       0: aload_0
       1: lload_1
       2: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       5: lload_3
       6: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       9: invokeinterface #535,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      14: checkcast     #189                // class java/lang/Number
      17: invokevirtual #192                // Method java/lang/Number.longValue:()J
      20: lreturn

  private static final long operation$lambda$15$lambda$14(kotlin.jvm.functions.Function2, long, long);
    Code:
       0: aload_0
       1: lload_3
       2: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       5: lload_1
       6: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       9: invokeinterface #535,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      14: checkcast     #189                // class java/lang/Number
      17: invokevirtual #192                // Method java/lang/Number.longValue:()J
      20: lreturn

  private static final long operation$lambda$17$lambda$16(kotlin.jvm.functions.Function2, long, long);
    Code:
       0: aload_0
       1: lload_3
       2: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       5: lload_1
       6: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       9: invokeinterface #535,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      14: checkcast     #189                // class java/lang/Number
      17: invokevirtual #192                // Method java/lang/Number.longValue:()J
      20: lreturn

  private static final long operation$lambda$18(kotlin.jvm.functions.Function2, long);
    Code:
       0: aload_0
       1: lload_1
       2: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       5: lload_1
       6: invokestatic  #168                // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
       9: invokeinterface #535,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      14: checkcast     #189                // class java/lang/Number
      17: invokevirtual #192                // Method java/lang/Number.longValue:()J
      20: lreturn
}


import java.io.File

fun main() {
  val result = File("inputs/day_4.txt").useLines { computeOverlaps(it) }
  println(result)
}

fun computeFullOverlaps(lines: Sequence<String>) =
  lines.map { toPairs(it) }
    .count { it.first.contains(it.second) || it.second.contains(it.first)}

fun computeOverlaps(lines: Sequence<String>) =
  lines.map { toPairs(it) }
    .count { it.first.overlaps(it.second) || it.second.overlaps(it.first)}

fun toPairs(it: String) =
  it.split(",")
    .map { it.split("-").map { it.toInt() } }
    .map { it.toPair() }
    .toPair()

fun <T> List<T>.toPair() = Pair(this[0], this[1])
fun Pair<Int, Int>.contains(that: Pair<Int, Int>) =
  this.first <= that.first && this.second >= that.second

fun Pair<Int, Int>.overlaps(that: Pair<Int, Int>) =
  this.first <= that.first && this.second >= that.first ||
    this.first >= that.first && this.first <= that.second

Compiled from "Day4.kt"
public final class Day4Kt {
  public static final void main();
    Code:
       0: new           #10                 // class java/io/File
       3: dup
       4: ldc           #12                 // String inputs/day_4.txt
       6: invokespecial #16                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: astore_1
      10: getstatic     #22                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_1
      17: astore        4
      19: sipush        8192
      22: istore        5
      24: aload         4
      26: astore        6
      28: new           #24                 // class java/io/InputStreamReader
      31: dup
      32: new           #26                 // class java/io/FileInputStream
      35: dup
      36: aload         6
      38: invokespecial #29                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      41: checkcast     #31                 // class java/io/InputStream
      44: aload_2
      45: invokespecial #34                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      48: checkcast     #36                 // class java/io/Reader
      51: astore        6
      53: aload         6
      55: instanceof    #38                 // class java/io/BufferedReader
      58: ifeq          69
      61: aload         6
      63: checkcast     #38                 // class java/io/BufferedReader
      66: goto          80
      69: new           #38                 // class java/io/BufferedReader
      72: dup
      73: aload         6
      75: iload         5
      77: invokespecial #41                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      80: checkcast     #43                 // class java/io/Closeable
      83: astore        4
      85: aconst_null
      86: astore        5
      88: nop
      89: aload         4
      91: checkcast     #38                 // class java/io/BufferedReader
      94: astore        6
      96: iconst_0
      97: istore        7
      99: aload         6
     101: invokestatic  #49                 // Method kotlin/io/TextStreamsKt.lineSequence:(Ljava/io/BufferedReader;)Lkotlin/sequences/Sequence;
     104: astore        8
     106: iconst_0
     107: istore        9
     109: aload         8
     111: invokestatic  #53                 // Method computeOverlaps:(Lkotlin/sequences/Sequence;)I
     114: istore        6
     116: aload         4
     118: aload         5
     120: invokestatic  #59                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     123: iload         6
     125: goto          149
     128: astore        7
     130: aload         7
     132: astore        5
     134: aload         7
     136: athrow
     137: astore        7
     139: aload         4
     141: aload         5
     143: invokestatic  #59                 // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     146: aload         7
     148: athrow
     149: nop
     150: istore_0
     151: getstatic     #65                 // Field java/lang/System.out:Ljava/io/PrintStream;
     154: iload_0
     155: invokevirtual #71                 // Method java/io/PrintStream.println:(I)V
     158: return
    Exception table:
       from    to  target type
          88   116   128   Class java/lang/Throwable
          88   116   137   any
         128   137   137   any
         137   139   137   any

  public static final int computeFullOverlaps(kotlin.sequences.Sequence<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #92                 // String lines
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokedynamic #117,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      12: invokestatic  #123                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      15: astore_1
      16: nop
      17: iconst_0
      18: istore_2
      19: iconst_0
      20: istore_3
      21: aload_1
      22: invokeinterface #127,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      27: astore        4
      29: aload         4
      31: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          123
      39: aload         4
      41: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        5
      48: aload         5
      50: checkcast     #139                // class kotlin/Pair
      53: astore        6
      55: iconst_0
      56: istore        7
      58: aload         6
      60: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      63: checkcast     #139                // class kotlin/Pair
      66: aload         6
      68: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      71: checkcast     #139                // class kotlin/Pair
      74: invokestatic  #149                // Method contains:(Lkotlin/Pair;Lkotlin/Pair;)Z
      77: ifne          102
      80: aload         6
      82: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      85: checkcast     #139                // class kotlin/Pair
      88: aload         6
      90: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      93: checkcast     #139                // class kotlin/Pair
      96: invokestatic  #149                // Method contains:(Lkotlin/Pair;Lkotlin/Pair;)Z
      99: ifeq          106
     102: iconst_1
     103: goto          107
     106: iconst_0
     107: ifeq          29
     110: iinc          3, 1
     113: iload_3
     114: ifge          29
     117: invokestatic  #154                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     120: goto          29
     123: iload_3
     124: ireturn

  public static final int computeOverlaps(kotlin.sequences.Sequence<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #92                 // String lines
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokedynamic #166,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      12: invokestatic  #123                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      15: astore_1
      16: nop
      17: iconst_0
      18: istore_2
      19: iconst_0
      20: istore_3
      21: aload_1
      22: invokeinterface #127,  1          // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      27: astore        4
      29: aload         4
      31: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          123
      39: aload         4
      41: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        5
      48: aload         5
      50: checkcast     #139                // class kotlin/Pair
      53: astore        6
      55: iconst_0
      56: istore        7
      58: aload         6
      60: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      63: checkcast     #139                // class kotlin/Pair
      66: aload         6
      68: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      71: checkcast     #139                // class kotlin/Pair
      74: invokestatic  #169                // Method overlaps:(Lkotlin/Pair;Lkotlin/Pair;)Z
      77: ifne          102
      80: aload         6
      82: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      85: checkcast     #139                // class kotlin/Pair
      88: aload         6
      90: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      93: checkcast     #139                // class kotlin/Pair
      96: invokestatic  #169                // Method overlaps:(Lkotlin/Pair;Lkotlin/Pair;)Z
      99: ifeq          106
     102: iconst_1
     103: goto          107
     106: iconst_0
     107: ifeq          29
     110: iinc          3, 1
     113: iload_3
     114: ifge          29
     117: invokestatic  #154                // Method kotlin/collections/CollectionsKt.throwCountOverflow:()V
     120: goto          29
     123: iload_3
     124: ireturn

  public static final kotlin.Pair<kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>> toPairs(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #173                // String it
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #175                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #177                // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #179                // String ,
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #185                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #187                // class java/lang/Iterable
      32: astore_1
      33: nop
      34: iconst_0
      35: istore_2
      36: aload_1
      37: astore_3
      38: new           #189                // class java/util/ArrayList
      41: dup
      42: aload_1
      43: bipush        10
      45: invokestatic  #193                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      48: invokespecial #195                // Method java/util/ArrayList."<init>":(I)V
      51: checkcast     #197                // class java/util/Collection
      54: astore        4
      56: iconst_0
      57: istore        5
      59: aload_3
      60: invokeinterface #198,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      65: astore        6
      67: aload         6
      69: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      74: ifeq          243
      77: aload         6
      79: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: astore        7
      86: aload         4
      88: aload         7
      90: checkcast     #177                // class java/lang/String
      93: astore        8
      95: astore        20
      97: iconst_0
      98: istore        9
     100: aload         8
     102: checkcast     #175                // class java/lang/CharSequence
     105: iconst_1
     106: anewarray     #177                // class java/lang/String
     109: astore        10
     111: aload         10
     113: iconst_0
     114: ldc           #200                // String -
     116: aastore
     117: aload         10
     119: iconst_0
     120: iconst_0
     121: bipush        6
     123: aconst_null
     124: invokestatic  #185                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     127: checkcast     #187                // class java/lang/Iterable
     130: astore        10
     132: iconst_0
     133: istore        11
     135: aload         10
     137: astore        12
     139: new           #189                // class java/util/ArrayList
     142: dup
     143: aload         10
     145: bipush        10
     147: invokestatic  #193                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     150: invokespecial #195                // Method java/util/ArrayList."<init>":(I)V
     153: checkcast     #197                // class java/util/Collection
     156: astore        13
     158: iconst_0
     159: istore        14
     161: aload         12
     163: invokeinterface #198,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     168: astore        15
     170: aload         15
     172: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     177: ifeq          224
     180: aload         15
     182: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     187: astore        16
     189: aload         13
     191: aload         16
     193: checkcast     #177                // class java/lang/String
     196: astore        17
     198: astore        18
     200: iconst_0
     201: istore        19
     203: aload         17
     205: invokestatic  #206                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     208: nop
     209: invokestatic  #210                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     212: aload         18
     214: swap
     215: invokeinterface #214,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     220: pop
     221: goto          170
     224: aload         13
     226: checkcast     #216                // class java/util/List
     229: nop
     230: nop
     231: aload         20
     233: swap
     234: invokeinterface #214,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     239: pop
     240: goto          67
     243: aload         4
     245: checkcast     #216                // class java/util/List
     248: nop
     249: checkcast     #187                // class java/lang/Iterable
     252: astore_1
     253: nop
     254: iconst_0
     255: istore_2
     256: aload_1
     257: astore_3
     258: new           #189                // class java/util/ArrayList
     261: dup
     262: aload_1
     263: bipush        10
     265: invokestatic  #193                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     268: invokespecial #195                // Method java/util/ArrayList."<init>":(I)V
     271: checkcast     #197                // class java/util/Collection
     274: astore        4
     276: iconst_0
     277: istore        5
     279: aload_3
     280: invokeinterface #198,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     285: astore        6
     287: aload         6
     289: invokeinterface #133,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     294: ifeq          337
     297: aload         6
     299: invokeinterface #137,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     304: astore        7
     306: aload         4
     308: aload         7
     310: checkcast     #216                // class java/util/List
     313: astore        8
     315: astore        20
     317: iconst_0
     318: istore        9
     320: aload         8
     322: invokestatic  #220                // Method toPair:(Ljava/util/List;)Lkotlin/Pair;
     325: aload         20
     327: swap
     328: invokeinterface #214,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     333: pop
     334: goto          287
     337: aload         4
     339: checkcast     #216                // class java/util/List
     342: nop
     343: invokestatic  #220                // Method toPair:(Ljava/util/List;)Lkotlin/Pair;
     346: areturn

  public static final <T> kotlin.Pair<T, T> toPair(java.util.List<? extends T>);
    Code:
       0: aload_0
       1: ldc           #236                // String <this>
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #139                // class kotlin/Pair
       9: dup
      10: aload_0
      11: iconst_0
      12: invokeinterface #240,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      17: aload_0
      18: iconst_1
      19: invokeinterface #240,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      24: invokespecial #243                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      27: areturn

  public static final boolean contains(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #236                // String <this>
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #247                // String that
       9: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #249                // class java/lang/Number
      19: invokevirtual #253                // Method java/lang/Number.intValue:()I
      22: aload_1
      23: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: checkcast     #249                // class java/lang/Number
      29: invokevirtual #253                // Method java/lang/Number.intValue:()I
      32: if_icmpgt     62
      35: aload_0
      36: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #249                // class java/lang/Number
      42: invokevirtual #253                // Method java/lang/Number.intValue:()I
      45: aload_1
      46: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      49: checkcast     #249                // class java/lang/Number
      52: invokevirtual #253                // Method java/lang/Number.intValue:()I
      55: if_icmplt     62
      58: iconst_1
      59: goto          63
      62: iconst_0
      63: ireturn

  public static final boolean overlaps(kotlin.Pair<java.lang.Integer, java.lang.Integer>, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #236                // String <this>
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #247                // String that
       9: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #249                // class java/lang/Number
      19: invokevirtual #253                // Method java/lang/Number.intValue:()I
      22: aload_1
      23: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: checkcast     #249                // class java/lang/Number
      29: invokevirtual #253                // Method java/lang/Number.intValue:()I
      32: if_icmpgt     58
      35: aload_0
      36: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #249                // class java/lang/Number
      42: invokevirtual #253                // Method java/lang/Number.intValue:()I
      45: aload_1
      46: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      49: checkcast     #249                // class java/lang/Number
      52: invokevirtual #253                // Method java/lang/Number.intValue:()I
      55: if_icmpge     104
      58: aload_0
      59: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      62: checkcast     #249                // class java/lang/Number
      65: invokevirtual #253                // Method java/lang/Number.intValue:()I
      68: aload_1
      69: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      72: checkcast     #249                // class java/lang/Number
      75: invokevirtual #253                // Method java/lang/Number.intValue:()I
      78: if_icmplt     108
      81: aload_0
      82: invokevirtual #142                // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      85: checkcast     #249                // class java/lang/Number
      88: invokevirtual #253                // Method java/lang/Number.intValue:()I
      91: aload_1
      92: invokevirtual #145                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      95: checkcast     #249                // class java/lang/Number
      98: invokevirtual #253                // Method java/lang/Number.intValue:()I
     101: if_icmpgt     108
     104: iconst_1
     105: goto          109
     108: iconst_0
     109: ireturn

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

  private static final kotlin.Pair computeFullOverlaps$lambda$1(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #173                // String it
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #262                // Method toPairs:(Ljava/lang/String;)Lkotlin/Pair;
      10: areturn

  private static final kotlin.Pair computeOverlaps$lambda$3(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #173                // String it
       3: invokestatic  #98                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #262                // Method toPairs:(Ljava/lang/String;)Lkotlin/Pair;
      10: areturn
}


fun solve(lines: Sequence<String>, part1: Boolean) =
  lines.fold(Input()) { acc, line -> acc.merge(acc.parse(line)) }
    .arrangeCrates()
    .rearrange(part1)
    .top()

data class Input(
  val crates: Map<Int, List<String>> = mapOf(),
  val instructions: List<Instruction> = listOf(),
  private val parsedCrates: Boolean = false) {
  fun merge(that: Input) = when {
    parsedCrates -> copy(instructions = instructions + that.instructions)
    that.parsedCrates -> copy(parsedCrates = true)
    else -> Input(
      (this.crates.keys + that.crates.keys).associateWith {
        this.crates.getOrDefault(it, listOf()) + that.crates.getValue(it)
      })
  }

  fun arrangeCrates() = copy(
    crates = crates.mapValues { it.value.filter { it.startsWith("[") }
      .map { it.substring(1,2) }
    }
  )

  fun parse(line: String) = when {
    line.isBlank() -> Input(parsedCrates = true)
    parsedCrates -> Input(instructions = parseInstruction(line))
    else -> Input(parseCrate(line))
  }

  private fun parseInstruction(line: String) =
    listOf(line.split(" ").toInstruction())

  fun parseCrate(line: String) =
    line.chunked(4).withIndex().associate { v -> (v.index + 1) to listOf(v.value.trim()) }

  fun rearrange(inOrder: Boolean) =
    instructions.fold(crates) { acc, next -> acc.mapValues { when (it.key) {
      next.from -> it.value.subList(next.count, it.value.size)
      next.to -> acc.getValue(next.from).subList(0, next.count).let {
        if (inOrder) it.reversed() else it
      } + it.value
      else -> it.value
    }}}
}

fun Map<Int, List<String>>.top() = values.mapNotNull { it.firstOrNull() }.joinToString("")
private fun List<String>.toInstruction() = Instruction(this[1].toInt(), this[3].toInt(), this[5].toInt())

data class Instruction(val count: Int, val from: Int, val to: Int)

Compiled from "Day5.kt"
public final class Day5Kt {
  public static final java.lang.String solve(kotlin.sequences.Sequence<java.lang.String>, boolean);
    Code:
       0: aload_0
       1: ldc           #10                 // String lines
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_2
       8: new           #18                 // class Input
      11: dup
      12: aconst_null
      13: aconst_null
      14: iconst_0
      15: bipush        7
      17: aconst_null
      18: invokespecial #22                 // Method Input."<init>":(Ljava/util/Map;Ljava/util/List;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
      21: astore_3
      22: iconst_0
      23: istore        4
      25: aload_3
      26: astore        5
      28: aload_2
      29: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      34: astore        6
      36: aload         6
      38: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      43: ifeq          86
      46: aload         6
      48: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      53: astore        7
      55: aload         5
      57: aload         7
      59: checkcast     #40                 // class java/lang/String
      62: astore        8
      64: astore        9
      66: iconst_0
      67: istore        10
      69: aload         9
      71: aload         9
      73: aload         8
      75: invokevirtual #44                 // Method Input.parse:(Ljava/lang/String;)LInput;
      78: invokevirtual #48                 // Method Input.merge:(LInput;)LInput;
      81: astore        5
      83: goto          36
      86: aload         5
      88: invokevirtual #52                 // Method Input.arrangeCrates:()LInput;
      91: iload_1
      92: invokevirtual #56                 // Method Input.rearrange:(Z)Ljava/util/Map;
      95: invokestatic  #60                 // Method top:(Ljava/util/Map;)Ljava/lang/String;
      98: areturn

  public static final java.lang.String top(java.util.Map<java.lang.Integer, ? extends java.util.List<java.lang.String>>);
    Code:
       0: aload_0
       1: ldc           #78                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #84,  1           // InterfaceMethod java/util/Map.values:()Ljava/util/Collection;
      12: checkcast     #86                 // class java/lang/Iterable
      15: astore_1
      16: iconst_0
      17: istore_2
      18: aload_1
      19: astore_3
      20: new           #88                 // class java/util/ArrayList
      23: dup
      24: invokespecial #91                 // Method java/util/ArrayList."<init>":()V
      27: checkcast     #93                 // class java/util/Collection
      30: astore        4
      32: iconst_0
      33: istore        5
      35: aload_3
      36: astore        6
      38: iconst_0
      39: istore        7
      41: aload         6
      43: invokeinterface #94,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        8
      50: aload         8
      52: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          121
      60: aload         8
      62: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        9
      69: aload         9
      71: astore        10
      73: iconst_0
      74: istore        11
      76: aload         10
      78: checkcast     #96                 // class java/util/List
      81: astore        12
      83: iconst_0
      84: istore        13
      86: aload         12
      88: invokestatic  #102                // Method kotlin/collections/CollectionsKt.firstOrNull:(Ljava/util/List;)Ljava/lang/Object;
      91: checkcast     #40                 // class java/lang/String
      94: dup
      95: ifnull        116
      98: astore        14
     100: iconst_0
     101: istore        15
     103: aload         4
     105: aload         14
     107: invokeinterface #106,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     112: pop
     113: goto          117
     116: pop
     117: nop
     118: goto          50
     121: nop
     122: aload         4
     124: checkcast     #96                 // class java/util/List
     127: nop
     128: checkcast     #86                 // class java/lang/Iterable
     131: ldc           #108                // String
     133: checkcast     #110                // class java/lang/CharSequence
     136: aconst_null
     137: aconst_null
     138: iconst_0
     139: aconst_null
     140: aconst_null
     141: bipush        62
     143: aconst_null
     144: invokestatic  #114                // 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;
     147: areturn

  private static final Instruction toInstruction(java.util.List<java.lang.String>);
    Code:
       0: new           #138                // class Instruction
       3: dup
       4: aload_0
       5: iconst_1
       6: invokeinterface #142,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #40                 // class java/lang/String
      14: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      17: aload_0
      18: iconst_3
      19: invokeinterface #142,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      24: checkcast     #40                 // class java/lang/String
      27: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      30: aload_0
      31: iconst_5
      32: invokeinterface #142,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      37: checkcast     #40                 // class java/lang/String
      40: invokestatic  #148                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      43: invokespecial #151                // Method Instruction."<init>":(III)V
      46: areturn

  public static final Instruction access$toInstruction(java.util.List);
    Code:
       0: aload_0
       1: invokestatic  #155                // Method toInstruction:(Ljava/util/List;)LInstruction;
       4: areturn
}