import java.io.File

class Matrix<T>(private val mtx: List<List<T>>) {
    fun dimensions(): Pair<Int, Int> = Pair(mtx.size, mtx[0].size)

    fun getRow(rowIdx: Int): List<T> = mtx[rowIdx]

    fun getColumn(colIdx: Int): List<T> = mtx.map { row -> row[colIdx] }

    fun forEachIndexed(f: (rowIndex: Int, columnIndex: Int, T) -> Unit) {
        this.mtx.forEachIndexed { rowIndex, row ->
            row.forEachIndexed { columnIndex, item ->
                f(rowIndex, columnIndex, item)
            }
        }
    }
}

fun main() {
    fun readInput(name: String) = File("src/day08", name)
        .readLines()

    fun smallerToLeft(mtx: Matrix<Int>, thisTree: Int, pos: Pair<Int, Int>): Int {
        val row = mtx.getRow(pos.first).subList(0, pos.second)
        return row.takeLastWhile { tree -> tree < thisTree }.count()
    }

    fun smallerToRight(mtx: Matrix<Int>, thisTree: Int, pos: Pair<Int, Int>): Int {
        val row = mtx.getRow(pos.first).subList(pos.second + 1, mtx.dimensions().second)
        return row.takeWhile { tree -> tree < thisTree }.count()
    }

    fun smallerAbove(mtx: Matrix<Int>, thisTree: Int, pos: Pair<Int, Int>): Int {
        val col = mtx.getColumn(pos.second).subList(0, pos.first)
        return col.takeLastWhile { tree -> tree < thisTree }.count()
    }

    fun smallerBelow(mtx: Matrix<Int>, thisTree: Int, pos: Pair<Int, Int>): Int {
        val col = mtx.getColumn(pos.second).subList(pos.first + 1, mtx.dimensions().first)
        return col.takeWhile { tree -> tree < thisTree }.count()
    }

    fun isVisibleFromADirection(mtx: Matrix<Int>, tree: Int, pos: Pair<Int, Int>): Boolean {
        val (height, width) = mtx.dimensions()

        return ((smallerToLeft(mtx, tree, pos) == pos.second)
                or (smallerToRight(mtx, tree, pos) == width - pos.second - 1)
                or (smallerAbove(mtx, tree, pos) == pos.first)
                or (smallerBelow(mtx, tree, pos) == height - pos.first - 1))
    }

    fun calculateVisibilityScore(mtx: Matrix<Int>, tree: Int, pos: Pair<Int, Int>): Int {
        val (row, col) = pos
        val (height, width) = mtx.dimensions()

        var stl = smallerToLeft(mtx, tree, pos)
        if (stl < col) { ++stl }

        var str = smallerToRight(mtx, tree, pos)
        if (str < width - col - 1) { ++str }

        var sa = smallerAbove(mtx, tree, pos)
        if (sa < row) { ++sa }

        var sb = smallerBelow(mtx, tree, pos)
        if (sb < height - row - 1) { ++sb }

        return (stl * str * sa * sb)
    }

    fun part1(input: List<String>): Int {
        val grid = Matrix(input.map { row -> row.map(Char::digitToInt) })

        val treesSeen = mutableSetOf<Pair<Int, Int>>()
        var count = 0
        grid.forEachIndexed { rowIdx, colIdx, tree ->
            if ((Pair(rowIdx, colIdx) !in treesSeen) and isVisibleFromADirection(grid, tree, Pair(rowIdx, colIdx))) {
                count += 1
                treesSeen.add(Pair(rowIdx, colIdx))
            }
        }

        return count
    }

    fun part2(input: List<String>): Int {
        val grid = Matrix(input.map { row -> row.map(Char::digitToInt) })

        val treesSeen = mutableSetOf<Pair<Int, Int>>()
        var maxScoreSeenSoFar = 0
        grid.forEachIndexed { rowIdx, colIdx, tree ->
            if (Pair(rowIdx, colIdx) !in treesSeen) {
                val visibilityScore = calculateVisibilityScore(grid, tree, Pair(rowIdx, colIdx))
                if (visibilityScore > maxScoreSeenSoFar) {
                    maxScoreSeenSoFar = visibilityScore
                }

                treesSeen.add(Pair(rowIdx, colIdx))
            }
        }

        return maxScoreSeenSoFar
    }

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

Compiled from "Day08.kt"
public final class Day08Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String input
       2: invokestatic  #12                 // Method main$readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #31                 // Method main$part2:(Ljava/util/List;)I
      22: istore_1
      23: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: iload_1
      27: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      30: return

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

  private static final java.util.List<java.lang.String> main$readInput(java.lang.String);
    Code:
       0: new           #40                 // class java/io/File
       3: dup
       4: ldc           #42                 // String src/day08
       6: aload_0
       7: invokespecial #46                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokestatic  #52                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      16: areturn

  private static final int main$smallerToLeft(Matrix<java.lang.Integer>, int, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_2
       2: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #65                 // class java/lang/Number
       8: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      11: invokevirtual #75                 // Method Matrix.getRow:(I)Ljava/util/List;
      14: iconst_0
      15: aload_2
      16: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      19: checkcast     #65                 // class java/lang/Number
      22: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      25: invokeinterface #84,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      30: astore_3
      31: aload_3
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload         4
      39: invokeinterface #88,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      44: ifeq          53
      47: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      50: goto          208
      53: aload         4
      55: aload         4
      57: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
      62: invokeinterface #101,  2          // InterfaceMethod java/util/List.listIterator:(I)Ljava/util/ListIterator;
      67: astore        6
      69: aload         6
      71: invokeinterface #106,  1          // InterfaceMethod java/util/ListIterator.hasPrevious:()Z
      76: ifeq          200
      79: aload         6
      81: invokeinterface #109,  1          // InterfaceMethod java/util/ListIterator.previous:()Ljava/lang/Object;
      86: checkcast     #65                 // class java/lang/Number
      89: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      92: istore        7
      94: iconst_0
      95: istore        8
      97: iload         7
      99: iload_1
     100: if_icmpge     107
     103: iconst_1
     104: goto          108
     107: iconst_0
     108: ifne          69
     111: aload         6
     113: invokeinterface #112,  1          // InterfaceMethod java/util/ListIterator.next:()Ljava/lang/Object;
     118: pop
     119: aload         4
     121: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
     126: aload         6
     128: invokeinterface #115,  1          // InterfaceMethod java/util/ListIterator.nextIndex:()I
     133: isub
     134: istore        9
     136: iload         9
     138: ifne          147
     141: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     144: goto          208
     147: new           #117                // class java/util/ArrayList
     150: dup
     151: iload         9
     153: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
     156: astore        10
     158: aload         10
     160: astore        11
     162: iconst_0
     163: istore        12
     165: aload         6
     167: invokeinterface #122,  1          // InterfaceMethod java/util/ListIterator.hasNext:()Z
     172: ifeq          191
     175: aload         11
     177: aload         6
     179: invokeinterface #112,  1          // InterfaceMethod java/util/ListIterator.next:()Ljava/lang/Object;
     184: invokevirtual #126                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     187: pop
     188: goto          165
     191: nop
     192: aload         10
     194: checkcast     #80                 // class java/util/List
     197: goto          208
     200: aload         4
     202: checkcast     #128                // class java/lang/Iterable
     205: invokestatic  #132                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     208: checkcast     #134                // class java/util/Collection
     211: invokeinterface #135,  1          // InterfaceMethod java/util/Collection.size:()I
     216: ireturn

  private static final int main$smallerToRight(Matrix<java.lang.Integer>, int, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_2
       2: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
       5: checkcast     #65                 // class java/lang/Number
       8: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      11: invokevirtual #75                 // Method Matrix.getRow:(I)Ljava/util/List;
      14: aload_2
      15: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      18: checkcast     #65                 // class java/lang/Number
      21: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      24: iconst_1
      25: iadd
      26: aload_0
      27: invokevirtual #157                // Method Matrix.dimensions:()Lkotlin/Pair;
      30: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      33: checkcast     #65                 // class java/lang/Number
      36: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      39: invokeinterface #84,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      44: astore_3
      45: aload_3
      46: checkcast     #128                // class java/lang/Iterable
      49: astore        4
      51: iconst_0
      52: istore        5
      54: new           #117                // class java/util/ArrayList
      57: dup
      58: invokespecial #159                // Method java/util/ArrayList."<init>":()V
      61: astore        6
      63: aload         4
      65: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      70: astore        7
      72: aload         7
      74: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      79: ifeq          132
      82: aload         7
      84: invokeinterface #167,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      89: astore        8
      91: aload         8
      93: checkcast     #65                 // class java/lang/Number
      96: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      99: istore        9
     101: iconst_0
     102: istore        10
     104: iload         9
     106: iload_1
     107: if_icmpge     114
     110: iconst_1
     111: goto          115
     114: iconst_0
     115: ifne          121
     118: goto          132
     121: aload         6
     123: aload         8
     125: invokevirtual #126                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     128: pop
     129: goto          72
     132: aload         6
     134: checkcast     #80                 // class java/util/List
     137: checkcast     #134                // class java/util/Collection
     140: invokeinterface #135,  1          // InterfaceMethod java/util/Collection.size:()I
     145: ireturn

  private static final int main$smallerAbove(Matrix<java.lang.Integer>, int, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_2
       2: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       5: checkcast     #65                 // class java/lang/Number
       8: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      11: invokevirtual #178                // Method Matrix.getColumn:(I)Ljava/util/List;
      14: iconst_0
      15: aload_2
      16: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      19: checkcast     #65                 // class java/lang/Number
      22: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      25: invokeinterface #84,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      30: astore_3
      31: aload_3
      32: astore        4
      34: iconst_0
      35: istore        5
      37: aload         4
      39: invokeinterface #88,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      44: ifeq          53
      47: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      50: goto          208
      53: aload         4
      55: aload         4
      57: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
      62: invokeinterface #101,  2          // InterfaceMethod java/util/List.listIterator:(I)Ljava/util/ListIterator;
      67: astore        6
      69: aload         6
      71: invokeinterface #106,  1          // InterfaceMethod java/util/ListIterator.hasPrevious:()Z
      76: ifeq          200
      79: aload         6
      81: invokeinterface #109,  1          // InterfaceMethod java/util/ListIterator.previous:()Ljava/lang/Object;
      86: checkcast     #65                 // class java/lang/Number
      89: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      92: istore        7
      94: iconst_0
      95: istore        8
      97: iload         7
      99: iload_1
     100: if_icmpge     107
     103: iconst_1
     104: goto          108
     107: iconst_0
     108: ifne          69
     111: aload         6
     113: invokeinterface #112,  1          // InterfaceMethod java/util/ListIterator.next:()Ljava/lang/Object;
     118: pop
     119: aload         4
     121: invokeinterface #97,  1           // InterfaceMethod java/util/List.size:()I
     126: aload         6
     128: invokeinterface #115,  1          // InterfaceMethod java/util/ListIterator.nextIndex:()I
     133: isub
     134: istore        9
     136: iload         9
     138: ifne          147
     141: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     144: goto          208
     147: new           #117                // class java/util/ArrayList
     150: dup
     151: iload         9
     153: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
     156: astore        10
     158: aload         10
     160: astore        11
     162: iconst_0
     163: istore        12
     165: aload         6
     167: invokeinterface #122,  1          // InterfaceMethod java/util/ListIterator.hasNext:()Z
     172: ifeq          191
     175: aload         11
     177: aload         6
     179: invokeinterface #112,  1          // InterfaceMethod java/util/ListIterator.next:()Ljava/lang/Object;
     184: invokevirtual #126                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     187: pop
     188: goto          165
     191: nop
     192: aload         10
     194: checkcast     #80                 // class java/util/List
     197: goto          208
     200: aload         4
     202: checkcast     #128                // class java/lang/Iterable
     205: invokestatic  #132                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     208: checkcast     #134                // class java/util/Collection
     211: invokeinterface #135,  1          // InterfaceMethod java/util/Collection.size:()I
     216: ireturn

  private static final int main$smallerBelow(Matrix<java.lang.Integer>, int, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: aload_2
       2: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
       5: checkcast     #65                 // class java/lang/Number
       8: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      11: invokevirtual #178                // Method Matrix.getColumn:(I)Ljava/util/List;
      14: aload_2
      15: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      18: checkcast     #65                 // class java/lang/Number
      21: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      24: iconst_1
      25: iadd
      26: aload_0
      27: invokevirtual #157                // Method Matrix.dimensions:()Lkotlin/Pair;
      30: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      33: checkcast     #65                 // class java/lang/Number
      36: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      39: invokeinterface #84,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
      44: astore_3
      45: aload_3
      46: checkcast     #128                // class java/lang/Iterable
      49: astore        4
      51: iconst_0
      52: istore        5
      54: new           #117                // class java/util/ArrayList
      57: dup
      58: invokespecial #159                // Method java/util/ArrayList."<init>":()V
      61: astore        6
      63: aload         4
      65: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      70: astore        7
      72: aload         7
      74: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      79: ifeq          132
      82: aload         7
      84: invokeinterface #167,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      89: astore        8
      91: aload         8
      93: checkcast     #65                 // class java/lang/Number
      96: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      99: istore        9
     101: iconst_0
     102: istore        10
     104: iload         9
     106: iload_1
     107: if_icmpge     114
     110: iconst_1
     111: goto          115
     114: iconst_0
     115: ifne          121
     118: goto          132
     121: aload         6
     123: aload         8
     125: invokevirtual #126                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     128: pop
     129: goto          72
     132: aload         6
     134: checkcast     #80                 // class java/util/List
     137: checkcast     #134                // class java/util/Collection
     140: invokeinterface #135,  1          // InterfaceMethod java/util/Collection.size:()I
     145: ireturn

  private static final boolean main$isVisibleFromADirection(Matrix<java.lang.Integer>, int, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: invokevirtual #157                // Method Matrix.dimensions:()Lkotlin/Pair;
       4: astore_3
       5: aload_3
       6: invokevirtual #188                // Method kotlin/Pair.component1:()Ljava/lang/Object;
       9: checkcast     #65                 // class java/lang/Number
      12: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      15: istore        4
      17: aload_3
      18: invokevirtual #191                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      21: checkcast     #65                 // class java/lang/Number
      24: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      27: istore        5
      29: aload_0
      30: iload_1
      31: aload_2
      32: invokestatic  #193                // Method main$smallerToLeft:(LMatrix;ILkotlin/Pair;)I
      35: aload_2
      36: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      39: checkcast     #65                 // class java/lang/Number
      42: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      45: if_icmpne     52
      48: iconst_1
      49: goto          53
      52: iconst_0
      53: aload_0
      54: iload_1
      55: aload_2
      56: invokestatic  #195                // Method main$smallerToRight:(LMatrix;ILkotlin/Pair;)I
      59: iload         5
      61: aload_2
      62: invokevirtual #78                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      65: checkcast     #65                 // class java/lang/Number
      68: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      71: isub
      72: iconst_1
      73: isub
      74: if_icmpne     81
      77: iconst_1
      78: goto          82
      81: iconst_0
      82: ior
      83: aload_0
      84: iload_1
      85: aload_2
      86: invokestatic  #197                // Method main$smallerAbove:(LMatrix;ILkotlin/Pair;)I
      89: aload_2
      90: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      93: checkcast     #65                 // class java/lang/Number
      96: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      99: if_icmpne     106
     102: iconst_1
     103: goto          107
     106: iconst_0
     107: ior
     108: aload_0
     109: iload_1
     110: aload_2
     111: invokestatic  #199                // Method main$smallerBelow:(LMatrix;ILkotlin/Pair;)I
     114: iload         4
     116: aload_2
     117: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     120: checkcast     #65                 // class java/lang/Number
     123: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     126: isub
     127: iconst_1
     128: isub
     129: if_icmpne     136
     132: iconst_1
     133: goto          137
     136: iconst_0
     137: ior
     138: ireturn

  private static final int main$calculateVisibilityScore(Matrix<java.lang.Integer>, int, kotlin.Pair<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_2
       1: invokevirtual #188                // Method kotlin/Pair.component1:()Ljava/lang/Object;
       4: checkcast     #65                 // class java/lang/Number
       7: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      10: istore_3
      11: aload_2
      12: invokevirtual #191                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      15: checkcast     #65                 // class java/lang/Number
      18: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      21: istore        4
      23: aload_0
      24: invokevirtual #157                // Method Matrix.dimensions:()Lkotlin/Pair;
      27: astore        5
      29: aload         5
      31: invokevirtual #188                // Method kotlin/Pair.component1:()Ljava/lang/Object;
      34: checkcast     #65                 // class java/lang/Number
      37: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      40: istore        6
      42: aload         5
      44: invokevirtual #191                // Method kotlin/Pair.component2:()Ljava/lang/Object;
      47: checkcast     #65                 // class java/lang/Number
      50: invokevirtual #69                 // Method java/lang/Number.intValue:()I
      53: istore        7
      55: aload_0
      56: iload_1
      57: aload_2
      58: invokestatic  #193                // Method main$smallerToLeft:(LMatrix;ILkotlin/Pair;)I
      61: istore        8
      63: iload         8
      65: iload         4
      67: if_icmpge     73
      70: iinc          8, 1
      73: aload_0
      74: iload_1
      75: aload_2
      76: invokestatic  #195                // Method main$smallerToRight:(LMatrix;ILkotlin/Pair;)I
      79: istore        9
      81: iload         9
      83: iload         7
      85: iload         4
      87: isub
      88: iconst_1
      89: isub
      90: if_icmpge     96
      93: iinc          9, 1
      96: aload_0
      97: iload_1
      98: aload_2
      99: invokestatic  #197                // Method main$smallerAbove:(LMatrix;ILkotlin/Pair;)I
     102: istore        10
     104: iload         10
     106: iload_3
     107: if_icmpge     113
     110: iinc          10, 1
     113: aload_0
     114: iload_1
     115: aload_2
     116: invokestatic  #199                // Method main$smallerBelow:(LMatrix;ILkotlin/Pair;)I
     119: istore        11
     121: iload         11
     123: iload         6
     125: iload_3
     126: isub
     127: iconst_1
     128: isub
     129: if_icmpge     135
     132: iinc          11, 1
     135: iload         8
     137: iload         9
     139: imul
     140: iload         10
     142: imul
     143: iload         11
     145: imul
     146: ireturn

  private static final kotlin.Unit main$part1$lambda$5(java.util.Set, Matrix, kotlin.jvm.internal.Ref$IntRef, int, int, int);
    Code:
       0: aload_0
       1: new           #59                 // class kotlin/Pair
       4: dup
       5: iload_3
       6: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       9: iload         4
      11: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokespecial #217                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      17: invokeinterface #222,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      22: ifne          29
      25: iconst_1
      26: goto          30
      29: iconst_0
      30: aload_1
      31: iload         5
      33: new           #59                 // class kotlin/Pair
      36: dup
      37: iload_3
      38: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: iload         4
      43: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: invokespecial #217                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      49: invokestatic  #224                // Method main$isVisibleFromADirection:(LMatrix;ILkotlin/Pair;)Z
      52: iand
      53: ifeq          89
      56: aload_2
      57: aload_2
      58: getfield      #229                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      61: iconst_1
      62: iadd
      63: putfield      #229                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      66: aload_0
      67: new           #59                 // class kotlin/Pair
      70: dup
      71: iload_3
      72: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      75: iload         4
      77: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      80: invokespecial #217                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      83: invokeinterface #230,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      88: pop
      89: getstatic     #236                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      92: areturn

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #128                // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #117                // class java/util/ArrayList
      13: dup
      14: aload_2
      15: bipush        10
      17: invokestatic  #248                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #134                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          188
      50: aload         7
      52: invokeinterface #167,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         5
      61: aload         8
      63: checkcast     #250                // class java/lang/String
      66: astore        9
      68: astore        21
      70: iconst_0
      71: istore        10
      73: aload         9
      75: checkcast     #252                // class java/lang/CharSequence
      78: astore        11
      80: iconst_0
      81: istore        12
      83: aload         11
      85: astore        13
      87: new           #117                // class java/util/ArrayList
      90: dup
      91: aload         11
      93: invokeinterface #255,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      98: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
     101: checkcast     #134                // class java/util/Collection
     104: astore        14
     106: iconst_0
     107: istore        15
     109: iconst_0
     110: istore        16
     112: iload         16
     114: aload         13
     116: invokeinterface #255,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     121: if_icmpge     169
     124: aload         13
     126: iload         16
     128: invokeinterface #259,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     133: istore        17
     135: aload         14
     137: iload         17
     139: istore        18
     141: astore        19
     143: iconst_0
     144: istore        20
     146: iload         18
     148: invokestatic  #265                // Method kotlin/text/CharsKt.digitToInt:(C)I
     151: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: aload         19
     156: swap
     157: invokeinterface #266,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     162: pop
     163: iinc          16, 1
     166: goto          112
     169: aload         14
     171: checkcast     #80                 // class java/util/List
     174: nop
     175: nop
     176: aload         21
     178: swap
     179: invokeinterface #266,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          40
     188: aload         5
     190: checkcast     #80                 // class java/util/List
     193: nop
     194: astore        22
     196: new           #71                 // class Matrix
     199: dup
     200: aload         22
     202: invokespecial #269                // Method Matrix."<init>":(Ljava/util/List;)V
     205: astore_1
     206: new           #271                // class java/util/LinkedHashSet
     209: dup
     210: invokespecial #272                // Method java/util/LinkedHashSet."<init>":()V
     213: checkcast     #219                // class java/util/Set
     216: astore_2
     217: new           #226                // class kotlin/jvm/internal/Ref$IntRef
     220: dup
     221: invokespecial #273                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     224: astore_3
     225: aload_1
     226: aload_2
     227: aload_1
     228: aload_3
     229: invokedynamic #291,  0            // InvokeDynamic #0:invoke:(Ljava/util/Set;LMatrix;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function3;
     234: invokevirtual #295                // Method Matrix.forEachIndexed:(Lkotlin/jvm/functions/Function3;)V
     237: aload_3
     238: getfield      #229                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     241: ireturn

  private static final kotlin.Unit main$part2$lambda$8(java.util.Set, Matrix, kotlin.jvm.internal.Ref$IntRef, int, int, int);
    Code:
       0: aload_0
       1: new           #59                 // class kotlin/Pair
       4: dup
       5: iload_3
       6: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
       9: iload         4
      11: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      14: invokespecial #217                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      17: invokeinterface #222,  2          // InterfaceMethod java/util/Set.contains:(Ljava/lang/Object;)Z
      22: ifne          87
      25: aload_1
      26: iload         5
      28: new           #59                 // class kotlin/Pair
      31: dup
      32: iload_3
      33: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      36: iload         4
      38: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      41: invokespecial #217                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      44: invokestatic  #313                // Method main$calculateVisibilityScore:(LMatrix;ILkotlin/Pair;)I
      47: istore        6
      49: iload         6
      51: aload_2
      52: getfield      #229                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      55: if_icmple     64
      58: aload_2
      59: iload         6
      61: putfield      #229                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      64: aload_0
      65: new           #59                 // class kotlin/Pair
      68: dup
      69: iload_3
      70: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      73: iload         4
      75: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokespecial #217                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      81: invokeinterface #230,  2          // InterfaceMethod java/util/Set.add:(Ljava/lang/Object;)Z
      86: pop
      87: getstatic     #236                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      90: areturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: checkcast     #128                // class java/lang/Iterable
       4: astore_2
       5: iconst_0
       6: istore_3
       7: aload_2
       8: astore        4
      10: new           #117                // class java/util/ArrayList
      13: dup
      14: aload_2
      15: bipush        10
      17: invokestatic  #248                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      20: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
      23: checkcast     #134                // class java/util/Collection
      26: astore        5
      28: iconst_0
      29: istore        6
      31: aload         4
      33: invokeinterface #163,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      38: astore        7
      40: aload         7
      42: invokeinterface #166,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      47: ifeq          188
      50: aload         7
      52: invokeinterface #167,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      57: astore        8
      59: aload         5
      61: aload         8
      63: checkcast     #250                // class java/lang/String
      66: astore        9
      68: astore        21
      70: iconst_0
      71: istore        10
      73: aload         9
      75: checkcast     #252                // class java/lang/CharSequence
      78: astore        11
      80: iconst_0
      81: istore        12
      83: aload         11
      85: astore        13
      87: new           #117                // class java/util/ArrayList
      90: dup
      91: aload         11
      93: invokeinterface #255,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      98: invokespecial #119                // Method java/util/ArrayList."<init>":(I)V
     101: checkcast     #134                // class java/util/Collection
     104: astore        14
     106: iconst_0
     107: istore        15
     109: iconst_0
     110: istore        16
     112: iload         16
     114: aload         13
     116: invokeinterface #255,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     121: if_icmpge     169
     124: aload         13
     126: iload         16
     128: invokeinterface #259,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     133: istore        17
     135: aload         14
     137: iload         17
     139: istore        18
     141: astore        19
     143: iconst_0
     144: istore        20
     146: iload         18
     148: invokestatic  #265                // Method kotlin/text/CharsKt.digitToInt:(C)I
     151: invokestatic  #214                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     154: aload         19
     156: swap
     157: invokeinterface #266,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     162: pop
     163: iinc          16, 1
     166: goto          112
     169: aload         14
     171: checkcast     #80                 // class java/util/List
     174: nop
     175: nop
     176: aload         21
     178: swap
     179: invokeinterface #266,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     184: pop
     185: goto          40
     188: aload         5
     190: checkcast     #80                 // class java/util/List
     193: nop
     194: astore        22
     196: new           #71                 // class Matrix
     199: dup
     200: aload         22
     202: invokespecial #269                // Method Matrix."<init>":(Ljava/util/List;)V
     205: astore_1
     206: new           #271                // class java/util/LinkedHashSet
     209: dup
     210: invokespecial #272                // Method java/util/LinkedHashSet."<init>":()V
     213: checkcast     #219                // class java/util/Set
     216: astore_2
     217: new           #226                // class kotlin/jvm/internal/Ref$IntRef
     220: dup
     221: invokespecial #273                // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     224: astore_3
     225: aload_1
     226: aload_2
     227: aload_1
     228: aload_3
     229: invokedynamic #319,  0            // InvokeDynamic #1:invoke:(Ljava/util/Set;LMatrix;Lkotlin/jvm/internal/Ref$IntRef;)Lkotlin/jvm/functions/Function3;
     234: invokevirtual #295                // Method Matrix.forEachIndexed:(Lkotlin/jvm/functions/Function3;)V
     237: aload_3
     238: getfield      #229                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     241: ireturn
}


import java.io.File

fun main() {
    fun readInput(name: String) = File("src/day01", name)
        .readLines()

    fun part1(input: List<String>): Int {
        var maxSoFar = 0
        var currentSum = 0
        for (line in input) {
            if (line.isEmpty()) {
                if (currentSum > maxSoFar) {
                    maxSoFar = currentSum
                }

                currentSum = 0
            } else {
                currentSum += line.toInt()
            }
        }

        return if (currentSum > maxSoFar) currentSum else maxSoFar
    }

    fun part2(input: List<String>): Int {
        val maxesSoFar = intArrayOf(0, 0, 0)
        var currentSum = 0
        for (line in input) {
            if (line.isEmpty()) {
                val (idx, smallestMaxSoFar) = maxesSoFar.withIndex().minBy { (_, maxVal) -> maxVal }
                if (currentSum > smallestMaxSoFar) {
                    maxesSoFar[idx] = currentSum
                }

                currentSum = 0
            } else {
                currentSum += line.toInt()
            }
        }

        val (idx, smallestMaxSoFar) = maxesSoFar.withIndex().minBy { (_, maxVal) -> maxVal }
        if (currentSum > smallestMaxSoFar) {
            maxesSoFar[idx] = currentSum
        }

        return maxesSoFar.sum()
    }

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

Compiled from "Day01.kt"
public final class Day01Kt {
  public static final void main();
    Code:
       0: ldc           #8                  // String input
       2: invokestatic  #12                 // Method main$readInput:(Ljava/lang/String;)Ljava/util/List;
       5: astore_0
       6: aload_0
       7: invokestatic  #16                 // Method main$part1:(Ljava/util/List;)I
      10: istore_1
      11: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      14: iload_1
      15: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      18: aload_0
      19: invokestatic  #31                 // Method main$part2:(Ljava/util/List;)I
      22: istore_1
      23: getstatic     #22                 // Field java/lang/System.out:Ljava/io/PrintStream;
      26: iload_1
      27: invokevirtual #28                 // Method java/io/PrintStream.println:(I)V
      30: return

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

  private static final java.util.List<java.lang.String> main$readInput(java.lang.String);
    Code:
       0: new           #40                 // class java/io/File
       3: dup
       4: ldc           #42                 // String src/day01
       6: aload_0
       7: invokespecial #46                 // Method java/io/File."<init>":(Ljava/lang/String;Ljava/lang/String;)V
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokestatic  #52                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      16: areturn

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: aload_0
       5: invokeinterface #61,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      10: astore_3
      11: aload_3
      12: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      17: ifeq          75
      20: aload_3
      21: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      26: checkcast     #73                 // class java/lang/String
      29: astore        4
      31: aload         4
      33: checkcast     #75                 // class java/lang/CharSequence
      36: invokeinterface #79,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      41: ifne          48
      44: iconst_1
      45: goto          49
      48: iconst_0
      49: ifeq          64
      52: iload_2
      53: iload_1
      54: if_icmple     59
      57: iload_2
      58: istore_1
      59: iconst_0
      60: istore_2
      61: goto          11
      64: iload_2
      65: aload         4
      67: invokestatic  #85                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      70: iadd
      71: istore_2
      72: goto          11
      75: iload_2
      76: iload_1
      77: if_icmple     84
      80: iload_2
      81: goto          85
      84: iload_1
      85: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: iconst_3
       1: newarray       int
       3: astore_2
       4: aload_2
       5: iconst_0
       6: iconst_0
       7: iastore
       8: aload_2
       9: iconst_1
      10: iconst_0
      11: iastore
      12: aload_2
      13: iconst_2
      14: iconst_0
      15: iastore
      16: aload_2
      17: astore_1
      18: iconst_0
      19: istore_2
      20: aload_0
      21: invokeinterface #61,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      26: astore_3
      27: aload_3
      28: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      33: ifeq          270
      36: aload_3
      37: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      42: checkcast     #73                 // class java/lang/String
      45: astore        4
      47: aload         4
      49: checkcast     #75                 // class java/lang/CharSequence
      52: invokeinterface #79,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      57: ifne          64
      60: iconst_1
      61: goto          65
      64: iconst_0
      65: ifeq          259
      68: aload_1
      69: invokestatic  #95                 // Method kotlin/collections/ArraysKt.withIndex:([I)Ljava/lang/Iterable;
      72: astore        6
      74: iconst_0
      75: istore        7
      77: aload         6
      79: invokeinterface #98,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      84: astore        8
      86: aload         8
      88: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      93: ifne          104
      96: new           #100                // class java/util/NoSuchElementException
      99: dup
     100: invokespecial #102                // Method java/util/NoSuchElementException."<init>":()V
     103: athrow
     104: aload         8
     106: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     111: astore        9
     113: aload         8
     115: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     120: ifne          128
     123: aload         9
     125: goto          218
     128: aload         9
     130: checkcast     #104                // class kotlin/collections/IndexedValue
     133: astore        10
     135: iconst_0
     136: istore        11
     138: aload         10
     140: invokevirtual #107                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     143: checkcast     #109                // class java/lang/Number
     146: invokevirtual #112                // Method java/lang/Number.intValue:()I
     149: istore        12
     151: iload         12
     153: istore        10
     155: aload         8
     157: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     162: astore        11
     164: aload         11
     166: checkcast     #104                // class kotlin/collections/IndexedValue
     169: astore        12
     171: iconst_0
     172: istore        13
     174: aload         12
     176: invokevirtual #107                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     179: checkcast     #109                // class java/lang/Number
     182: invokevirtual #112                // Method java/lang/Number.intValue:()I
     185: istore        14
     187: iload         14
     189: istore        12
     191: iload         10
     193: iload         12
     195: if_icmple     206
     198: aload         11
     200: astore        9
     202: iload         12
     204: istore        10
     206: aload         8
     208: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     213: ifne          155
     216: aload         9
     218: checkcast     #104                // class kotlin/collections/IndexedValue
     221: astore        5
     223: aload         5
     225: invokevirtual #115                // Method kotlin/collections/IndexedValue.component1:()I
     228: istore        6
     230: aload         5
     232: invokevirtual #107                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     235: checkcast     #109                // class java/lang/Number
     238: invokevirtual #112                // Method java/lang/Number.intValue:()I
     241: istore        7
     243: iload_2
     244: iload         7
     246: if_icmple     254
     249: aload_1
     250: iload         6
     252: iload_2
     253: iastore
     254: iconst_0
     255: istore_2
     256: goto          27
     259: iload_2
     260: aload         4
     262: invokestatic  #85                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     265: iadd
     266: istore_2
     267: goto          27
     270: aload_1
     271: invokestatic  #95                 // Method kotlin/collections/ArraysKt.withIndex:([I)Ljava/lang/Iterable;
     274: astore        4
     276: iconst_0
     277: istore        5
     279: aload         4
     281: invokeinterface #98,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     286: astore        6
     288: aload         6
     290: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     295: ifne          306
     298: new           #100                // class java/util/NoSuchElementException
     301: dup
     302: invokespecial #102                // Method java/util/NoSuchElementException."<init>":()V
     305: athrow
     306: aload         6
     308: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     313: astore        7
     315: aload         6
     317: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     322: ifne          330
     325: aload         7
     327: goto          420
     330: aload         7
     332: checkcast     #104                // class kotlin/collections/IndexedValue
     335: astore        8
     337: iconst_0
     338: istore        9
     340: aload         8
     342: invokevirtual #107                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     345: checkcast     #109                // class java/lang/Number
     348: invokevirtual #112                // Method java/lang/Number.intValue:()I
     351: istore        10
     353: iload         10
     355: istore        8
     357: aload         6
     359: invokeinterface #71,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     364: astore        9
     366: aload         9
     368: checkcast     #104                // class kotlin/collections/IndexedValue
     371: astore        10
     373: iconst_0
     374: istore        11
     376: aload         10
     378: invokevirtual #107                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     381: checkcast     #109                // class java/lang/Number
     384: invokevirtual #112                // Method java/lang/Number.intValue:()I
     387: istore        12
     389: iload         12
     391: istore        10
     393: iload         8
     395: iload         10
     397: if_icmple     408
     400: aload         9
     402: astore        7
     404: iload         10
     406: istore        8
     408: aload         6
     410: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     415: ifne          357
     418: aload         7
     420: checkcast     #104                // class kotlin/collections/IndexedValue
     423: astore_3
     424: aload_3
     425: invokevirtual #115                // Method kotlin/collections/IndexedValue.component1:()I
     428: istore        4
     430: aload_3
     431: invokevirtual #107                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     434: checkcast     #109                // class java/lang/Number
     437: invokevirtual #112                // Method java/lang/Number.intValue:()I
     440: istore        5
     442: iload_2
     443: iload         5
     445: if_icmple     453
     448: aload_1
     449: iload         4
     451: iload_2
     452: iastore
     453: aload_1
     454: invokestatic  #119                // Method kotlin/collections/ArraysKt.sum:([I)I
     457: ireturn
}


import java.io.File
import java.util.Scanner

fun scheduleO2CMax(p1: List<Long>, p2: List<Long>): Pair<Long, List<List<Long>>> {
    fun fill(schedule: MutableList<Long>, times: List<Long>, indices: Sequence<Int>, init: Long = 0) =
        indices.fold(init) { sum, index ->
            schedule[index] = sum
            sum + times[index]
        }

    fun i() = p1.asSequence().withIndex().filter { (index, i) -> i <= p2[index] }.map { it.index }
    fun j() = p1.asSequence().withIndex().filter { (index, i) -> i > p2[index] }.map { it.index }

    val x = i().maxByOrNull { p1[it] }
    val y = j().maxByOrNull { p2[it] }

    return if (x == null || y != null && p1[x] < p2[y]) {
        val (cMax, schedule) = scheduleO2CMax(p2, p1)
        cMax to listOf(schedule[1], schedule[0])
    } else {
        val cMax = maxOf(p1.sum(), p2.sum(), p1.asSequence().zip(p2.asSequence()).maxOf { (a, b) -> a + b })

        val first = MutableList(p1.size) { 0L }
        fill(first, p1, i() - x)
        fill(first, p1, sequenceOf(x), cMax - p1[x])
        fill(first, p1, j(), cMax - p1[x] - j().sumOf { p1[it] })

        val second = MutableList(p2.size) { 0L }
        fill(second, p2, sequenceOf(x))
        fill(second, p2, i() - x, p2[x])
        fill(second, p2, j(), cMax - j().sumOf { p2[it] })

        cMax to listOf(first, second)
    }
}

fun main() {
    val input = Scanner(File("o2cmax.in").bufferedReader())

    val n = input.nextInt()
    val p1 = List(n) { input.nextLong() }
    val p2 = List(n) { input.nextLong() }

    val (c, schedule) = scheduleO2CMax(p1, p2)

    File("o2cmax.out").printWriter().use { output ->
        output.println(c)
        schedule.forEach { line ->
            line.forEach { output.print("$it ") }
            output.println()
        }
    }
}

Compiled from "bO2CMax.kt"
public final class BO2CMaxKt {
  public static final kotlin.Pair<java.lang.Long, java.util.List<java.util.List<java.lang.Long>>> scheduleO2CMax(java.util.List<java.lang.Long>, java.util.List<java.lang.Long>);
    Code:
       0: aload_0
       1: ldc           #10                 // String p1
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String p2
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: invokestatic  #22                 // Method scheduleO2CMax$i:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
      17: astore_3
      18: iconst_0
      19: istore        4
      21: aload_3
      22: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      27: astore        5
      29: aload         5
      31: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifne          43
      39: aconst_null
      40: goto          162
      43: aload         5
      45: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      50: astore        6
      52: aload         5
      54: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      59: ifne          67
      62: aload         6
      64: goto          162
      67: aload         6
      69: checkcast     #40                 // class java/lang/Number
      72: invokevirtual #44                 // Method java/lang/Number.intValue:()I
      75: istore        7
      77: iconst_0
      78: istore        9
      80: aload_0
      81: iload         7
      83: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      88: checkcast     #40                 // class java/lang/Number
      91: invokevirtual #54                 // Method java/lang/Number.longValue:()J
      94: lstore        7
      96: aload         5
      98: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     103: astore        9
     105: aload         9
     107: checkcast     #40                 // class java/lang/Number
     110: invokevirtual #44                 // Method java/lang/Number.intValue:()I
     113: istore        11
     115: iconst_0
     116: istore        13
     118: aload_0
     119: iload         11
     121: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     126: checkcast     #40                 // class java/lang/Number
     129: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     132: lstore        11
     134: lload         7
     136: lload         11
     138: lcmp
     139: ifge          150
     142: aload         9
     144: astore        6
     146: lload         11
     148: lstore        7
     150: aload         5
     152: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     157: ifne          96
     160: aload         6
     162: checkcast     #56                 // class java/lang/Integer
     165: astore_2
     166: aload_0
     167: aload_1
     168: invokestatic  #59                 // Method scheduleO2CMax$j:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
     171: astore        4
     173: iconst_0
     174: istore        5
     176: aload         4
     178: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     183: astore        6
     185: aload         6
     187: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     192: ifne          199
     195: aconst_null
     196: goto          318
     199: aload         6
     201: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     206: astore        7
     208: aload         6
     210: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     215: ifne          223
     218: aload         7
     220: goto          318
     223: aload         7
     225: checkcast     #40                 // class java/lang/Number
     228: invokevirtual #44                 // Method java/lang/Number.intValue:()I
     231: istore        9
     233: iconst_0
     234: istore        11
     236: aload_1
     237: iload         9
     239: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     244: checkcast     #40                 // class java/lang/Number
     247: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     250: lstore        9
     252: aload         6
     254: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     259: astore        11
     261: aload         11
     263: checkcast     #40                 // class java/lang/Number
     266: invokevirtual #44                 // Method java/lang/Number.intValue:()I
     269: istore        13
     271: iconst_0
     272: istore        15
     274: aload_1
     275: iload         13
     277: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     282: checkcast     #40                 // class java/lang/Number
     285: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     288: lstore        13
     290: lload         9
     292: lload         13
     294: lcmp
     295: ifge          306
     298: aload         11
     300: astore        7
     302: lload         13
     304: lstore        9
     306: aload         6
     308: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     313: ifne          252
     316: aload         7
     318: checkcast     #56                 // class java/lang/Integer
     321: astore_3
     322: aload_2
     323: ifnull        366
     326: aload_3
     327: ifnull        442
     330: aload_0
     331: aload_2
     332: invokevirtual #60                 // Method java/lang/Integer.intValue:()I
     335: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     340: checkcast     #40                 // class java/lang/Number
     343: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     346: aload_1
     347: aload_3
     348: invokevirtual #60                 // Method java/lang/Integer.intValue:()I
     351: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     356: checkcast     #40                 // class java/lang/Number
     359: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     362: lcmp
     363: ifge          442
     366: aload_1
     367: aload_0
     368: invokestatic  #62                 // Method scheduleO2CMax:(Ljava/util/List;Ljava/util/List;)Lkotlin/Pair;
     371: astore        4
     373: aload         4
     375: invokevirtual #67                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     378: checkcast     #40                 // class java/lang/Number
     381: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     384: lstore        5
     386: aload         4
     388: invokevirtual #70                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     391: checkcast     #46                 // class java/util/List
     394: astore        7
     396: lload         5
     398: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     401: iconst_2
     402: anewarray     #46                 // class java/util/List
     405: astore        9
     407: aload         9
     409: iconst_0
     410: aload         7
     412: iconst_1
     413: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     418: aastore
     419: aload         9
     421: iconst_1
     422: aload         7
     424: iconst_0
     425: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     430: aastore
     431: aload         9
     433: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     436: invokestatic  #88                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     439: goto          1182
     442: aload_0
     443: checkcast     #90                 // class java/lang/Iterable
     446: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
     449: lstore        6
     451: aload_1
     452: checkcast     #90                 // class java/lang/Iterable
     455: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.sumOfLong:(Ljava/lang/Iterable;)J
     458: lstore        9
     460: aload_0
     461: checkcast     #90                 // class java/lang/Iterable
     464: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     467: aload_1
     468: checkcast     #90                 // class java/lang/Iterable
     471: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
     474: invokestatic  #104                // Method kotlin/sequences/SequencesKt.zip:(Lkotlin/sequences/Sequence;Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
     477: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     482: astore        15
     484: aload         15
     486: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     491: ifne          502
     494: new           #106                // class java/util/NoSuchElementException
     497: dup
     498: invokespecial #110                // Method java/util/NoSuchElementException."<init>":()V
     501: athrow
     502: aload         15
     504: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     509: checkcast     #64                 // class kotlin/Pair
     512: astore        16
     514: iconst_0
     515: istore        18
     517: aload         16
     519: invokevirtual #67                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     522: checkcast     #40                 // class java/lang/Number
     525: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     528: lstore        20
     530: aload         16
     532: invokevirtual #70                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     535: checkcast     #40                 // class java/lang/Number
     538: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     541: lstore        22
     543: lload         20
     545: lload         22
     547: ladd
     548: lstore        16
     550: aload         15
     552: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     557: ifeq          623
     560: aload         15
     562: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     567: checkcast     #64                 // class kotlin/Pair
     570: astore        18
     572: iconst_0
     573: istore        24
     575: aload         18
     577: invokevirtual #67                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     580: checkcast     #40                 // class java/lang/Number
     583: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     586: lstore        25
     588: aload         18
     590: invokevirtual #70                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     593: checkcast     #40                 // class java/lang/Number
     596: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     599: lstore        27
     601: lload         25
     603: lload         27
     605: ladd
     606: lstore        18
     608: lload         16
     610: lload         18
     612: lcmp
     613: ifge          550
     616: lload         18
     618: lstore        16
     620: goto          550
     623: lload         16
     625: lstore        13
     627: lload         6
     629: lload         9
     631: lload         13
     633: invokestatic  #116                // Method java/lang/Math.max:(JJ)J
     636: invokestatic  #116                // Method java/lang/Math.max:(JJ)J
     639: lstore        4
     641: aload_0
     642: invokeinterface #119,  1          // InterfaceMethod java/util/List.size:()I
     647: istore        7
     649: new           #121                // class java/util/ArrayList
     652: dup
     653: iload         7
     655: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
     658: astore        9
     660: iconst_0
     661: istore        11
     663: iload         11
     665: iload         7
     667: if_icmpge     702
     670: iload         11
     672: istore        13
     674: aload         9
     676: iload         13
     678: istore        15
     680: astore        29
     682: iconst_0
     683: istore        16
     685: lconst_0
     686: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     689: aload         29
     691: swap
     692: invokevirtual #128                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     695: pop
     696: iinc          11, 1
     699: goto          663
     702: aload         9
     704: checkcast     #46                 // class java/util/List
     707: astore        6
     709: aload         6
     711: aload_0
     712: aload_0
     713: aload_1
     714: invokestatic  #22                 // Method scheduleO2CMax$i:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
     717: aload_2
     718: invokestatic  #132                // Method kotlin/sequences/SequencesKt.minus:(Lkotlin/sequences/Sequence;Ljava/lang/Object;)Lkotlin/sequences/Sequence;
     721: lconst_0
     722: bipush        8
     724: aconst_null
     725: invokestatic  #136                // Method scheduleO2CMax$fill$default:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;JILjava/lang/Object;)J
     728: pop2
     729: aload         6
     731: aload_0
     732: iconst_1
     733: anewarray     #56                 // class java/lang/Integer
     736: astore        7
     738: aload         7
     740: iconst_0
     741: aload_2
     742: aastore
     743: aload         7
     745: invokestatic  #140                // Method kotlin/sequences/SequencesKt.sequenceOf:([Ljava/lang/Object;)Lkotlin/sequences/Sequence;
     748: lload         4
     750: aload_0
     751: aload_2
     752: invokevirtual #60                 // Method java/lang/Integer.intValue:()I
     755: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     760: checkcast     #40                 // class java/lang/Number
     763: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     766: lsub
     767: invokestatic  #144                // Method scheduleO2CMax$fill:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;J)J
     770: pop2
     771: aload         6
     773: aload_0
     774: aload_0
     775: aload_1
     776: invokestatic  #59                 // Method scheduleO2CMax$j:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
     779: lload         4
     781: aload_0
     782: aload_2
     783: invokevirtual #60                 // Method java/lang/Integer.intValue:()I
     786: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     791: checkcast     #40                 // class java/lang/Number
     794: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     797: lsub
     798: aload_0
     799: aload_1
     800: invokestatic  #59                 // Method scheduleO2CMax$j:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
     803: astore        7
     805: lstore        32
     807: astore        31
     809: astore        30
     811: astore        29
     813: lconst_0
     814: lstore        9
     816: aload         7
     818: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     823: astore        13
     825: aload         13
     827: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     832: ifeq          887
     835: aload         13
     837: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     842: astore        15
     844: lload         9
     846: aload         15
     848: checkcast     #40                 // class java/lang/Number
     851: invokevirtual #44                 // Method java/lang/Number.intValue:()I
     854: istore        16
     856: lstore        34
     858: iconst_0
     859: istore        18
     861: aload_0
     862: iload         16
     864: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     869: checkcast     #40                 // class java/lang/Number
     872: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     875: lstore        36
     877: lload         34
     879: lload         36
     881: ladd
     882: lstore        9
     884: goto          825
     887: lload         9
     889: lstore        34
     891: aload         29
     893: aload         30
     895: aload         31
     897: lload         32
     899: lload         34
     901: lsub
     902: invokestatic  #144                // Method scheduleO2CMax$fill:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;J)J
     905: pop2
     906: aload_1
     907: invokeinterface #119,  1          // InterfaceMethod java/util/List.size:()I
     912: istore        9
     914: new           #121                // class java/util/ArrayList
     917: dup
     918: iload         9
     920: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
     923: astore        11
     925: iconst_0
     926: istore        13
     928: iload         13
     930: iload         9
     932: if_icmpge     967
     935: iload         13
     937: istore        15
     939: aload         11
     941: iload         15
     943: istore        16
     945: astore        29
     947: iconst_0
     948: istore        18
     950: lconst_0
     951: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     954: aload         29
     956: swap
     957: invokevirtual #128                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     960: pop
     961: iinc          13, 1
     964: goto          928
     967: aload         11
     969: checkcast     #46                 // class java/util/List
     972: astore        7
     974: aload         7
     976: aload_1
     977: iconst_1
     978: anewarray     #56                 // class java/lang/Integer
     981: astore        9
     983: aload         9
     985: iconst_0
     986: aload_2
     987: aastore
     988: aload         9
     990: invokestatic  #140                // Method kotlin/sequences/SequencesKt.sequenceOf:([Ljava/lang/Object;)Lkotlin/sequences/Sequence;
     993: lconst_0
     994: bipush        8
     996: aconst_null
     997: invokestatic  #136                // Method scheduleO2CMax$fill$default:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;JILjava/lang/Object;)J
    1000: pop2
    1001: aload         7
    1003: aload_1
    1004: aload_0
    1005: aload_1
    1006: invokestatic  #22                 // Method scheduleO2CMax$i:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
    1009: aload_2
    1010: invokestatic  #132                // Method kotlin/sequences/SequencesKt.minus:(Lkotlin/sequences/Sequence;Ljava/lang/Object;)Lkotlin/sequences/Sequence;
    1013: aload_1
    1014: aload_2
    1015: invokevirtual #60                 // Method java/lang/Integer.intValue:()I
    1018: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1023: checkcast     #40                 // class java/lang/Number
    1026: invokevirtual #54                 // Method java/lang/Number.longValue:()J
    1029: invokestatic  #144                // Method scheduleO2CMax$fill:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;J)J
    1032: pop2
    1033: aload         7
    1035: aload_1
    1036: aload_0
    1037: aload_1
    1038: invokestatic  #59                 // Method scheduleO2CMax$j:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
    1041: lload         4
    1043: aload_0
    1044: aload_1
    1045: invokestatic  #59                 // Method scheduleO2CMax$j:(Ljava/util/List;Ljava/util/List;)Lkotlin/sequences/Sequence;
    1048: astore        9
    1050: lstore        32
    1052: astore        31
    1054: astore        30
    1056: astore        29
    1058: lconst_0
    1059: lstore        11
    1061: aload         9
    1063: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
    1068: astore        15
    1070: aload         15
    1072: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
    1077: ifeq          1132
    1080: aload         15
    1082: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    1087: astore        16
    1089: lload         11
    1091: aload         16
    1093: checkcast     #40                 // class java/lang/Number
    1096: invokevirtual #44                 // Method java/lang/Number.intValue:()I
    1099: istore        18
    1101: lstore        34
    1103: iconst_0
    1104: istore        20
    1106: aload_1
    1107: iload         18
    1109: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
    1114: checkcast     #40                 // class java/lang/Number
    1117: invokevirtual #54                 // Method java/lang/Number.longValue:()J
    1120: lstore        36
    1122: lload         34
    1124: lload         36
    1126: ladd
    1127: lstore        11
    1129: goto          1070
    1132: lload         11
    1134: lstore        34
    1136: aload         29
    1138: aload         30
    1140: aload         31
    1142: lload         32
    1144: lload         34
    1146: lsub
    1147: invokestatic  #144                // Method scheduleO2CMax$fill:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;J)J
    1150: pop2
    1151: lload         4
    1153: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
    1156: iconst_2
    1157: anewarray     #46                 // class java/util/List
    1160: astore        9
    1162: aload         9
    1164: iconst_0
    1165: aload         6
    1167: aastore
    1168: aload         9
    1170: iconst_1
    1171: aload         7
    1173: aastore
    1174: aload         9
    1176: invokestatic  #82                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
    1179: invokestatic  #88                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
    1182: areturn

  public static final void main();
    Code:
       0: new           #181                // class java/util/Scanner
       3: dup
       4: new           #183                // class java/io/File
       7: dup
       8: ldc           #185                // String o2cmax.in
      10: invokespecial #188                // Method java/io/File."<init>":(Ljava/lang/String;)V
      13: astore_1
      14: getstatic     #194                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      17: astore_2
      18: sipush        8192
      21: istore_3
      22: aload_1
      23: astore        4
      25: new           #196                // class java/io/InputStreamReader
      28: dup
      29: new           #198                // class java/io/FileInputStream
      32: dup
      33: aload         4
      35: invokespecial #201                // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      38: checkcast     #203                // class java/io/InputStream
      41: aload_2
      42: invokespecial #206                // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      45: checkcast     #208                // class java/io/Reader
      48: astore        4
      50: aload         4
      52: instanceof    #210                // class java/io/BufferedReader
      55: ifeq          66
      58: aload         4
      60: checkcast     #210                // class java/io/BufferedReader
      63: goto          76
      66: new           #210                // class java/io/BufferedReader
      69: dup
      70: aload         4
      72: iload_3
      73: invokespecial #213                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      76: checkcast     #215                // class java/lang/Readable
      79: invokespecial #218                // Method java/util/Scanner."<init>":(Ljava/lang/Readable;)V
      82: astore_0
      83: aload_0
      84: invokevirtual #221                // Method java/util/Scanner.nextInt:()I
      87: istore_1
      88: new           #121                // class java/util/ArrayList
      91: dup
      92: iload_1
      93: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
      96: astore_3
      97: iconst_0
      98: istore        4
     100: iload         4
     102: iload_1
     103: if_icmpge     140
     106: iload         4
     108: istore        5
     110: aload_3
     111: iload         5
     113: istore        6
     115: astore        25
     117: iconst_0
     118: istore        7
     120: aload_0
     121: invokevirtual #224                // Method java/util/Scanner.nextLong:()J
     124: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     127: aload         25
     129: swap
     130: invokevirtual #128                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     133: pop
     134: iinc          4, 1
     137: goto          100
     140: aload_3
     141: checkcast     #46                 // class java/util/List
     144: astore_2
     145: new           #121                // class java/util/ArrayList
     148: dup
     149: iload_1
     150: invokespecial #124                // Method java/util/ArrayList."<init>":(I)V
     153: astore        4
     155: iconst_0
     156: istore        5
     158: iload         5
     160: iload_1
     161: if_icmpge     199
     164: iload         5
     166: istore        6
     168: aload         4
     170: iload         6
     172: istore        7
     174: astore        25
     176: iconst_0
     177: istore        8
     179: aload_0
     180: invokevirtual #224                // Method java/util/Scanner.nextLong:()J
     183: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     186: aload         25
     188: swap
     189: invokevirtual #128                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     192: pop
     193: iinc          5, 1
     196: goto          158
     199: aload         4
     201: checkcast     #46                 // class java/util/List
     204: astore_3
     205: aload_2
     206: aload_3
     207: invokestatic  #62                 // Method scheduleO2CMax:(Ljava/util/List;Ljava/util/List;)Lkotlin/Pair;
     210: astore        4
     212: aload         4
     214: invokevirtual #67                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
     217: checkcast     #40                 // class java/lang/Number
     220: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     223: lstore        5
     225: aload         4
     227: invokevirtual #70                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
     230: checkcast     #46                 // class java/util/List
     233: astore        7
     235: new           #183                // class java/io/File
     238: dup
     239: ldc           #226                // String o2cmax.out
     241: invokespecial #188                // Method java/io/File."<init>":(Ljava/lang/String;)V
     244: astore        8
     246: getstatic     #194                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
     249: astore        9
     251: new           #228                // class java/io/PrintWriter
     254: dup
     255: aload         8
     257: astore        10
     259: sipush        8192
     262: istore        11
     264: aload         10
     266: astore        12
     268: new           #230                // class java/io/OutputStreamWriter
     271: dup
     272: new           #232                // class java/io/FileOutputStream
     275: dup
     276: aload         12
     278: invokespecial #233                // Method java/io/FileOutputStream."<init>":(Ljava/io/File;)V
     281: checkcast     #235                // class java/io/OutputStream
     284: aload         9
     286: invokespecial #238                // Method java/io/OutputStreamWriter."<init>":(Ljava/io/OutputStream;Ljava/nio/charset/Charset;)V
     289: checkcast     #240                // class java/io/Writer
     292: astore        12
     294: aload         12
     296: instanceof    #242                // class java/io/BufferedWriter
     299: ifeq          310
     302: aload         12
     304: checkcast     #242                // class java/io/BufferedWriter
     307: goto          321
     310: new           #242                // class java/io/BufferedWriter
     313: dup
     314: aload         12
     316: iload         11
     318: invokespecial #245                // Method java/io/BufferedWriter."<init>":(Ljava/io/Writer;I)V
     321: checkcast     #240                // class java/io/Writer
     324: invokespecial #248                // Method java/io/PrintWriter."<init>":(Ljava/io/Writer;)V
     327: checkcast     #250                // class java/io/Closeable
     330: astore        8
     332: aconst_null
     333: astore        9
     335: nop
     336: aload         8
     338: checkcast     #228                // class java/io/PrintWriter
     341: astore        10
     343: iconst_0
     344: istore        11
     346: aload         10
     348: lload         5
     350: invokevirtual #254                // Method java/io/PrintWriter.println:(J)V
     353: aload         7
     355: checkcast     #90                 // class java/lang/Iterable
     358: astore        12
     360: iconst_0
     361: istore        13
     363: aload         12
     365: invokeinterface #255,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     370: astore        14
     372: aload         14
     374: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     379: ifeq          492
     382: aload         14
     384: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     389: astore        15
     391: aload         15
     393: checkcast     #46                 // class java/util/List
     396: astore        16
     398: iconst_0
     399: istore        17
     401: aload         16
     403: checkcast     #90                 // class java/lang/Iterable
     406: astore        18
     408: iconst_0
     409: istore        19
     411: aload         18
     413: invokeinterface #255,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     418: astore        20
     420: aload         20
     422: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     427: ifeq          481
     430: aload         20
     432: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     437: astore        21
     439: aload         21
     441: checkcast     #40                 // class java/lang/Number
     444: invokevirtual #54                 // Method java/lang/Number.longValue:()J
     447: lstore        22
     449: iconst_0
     450: istore        24
     452: aload         10
     454: new           #257                // class java/lang/StringBuilder
     457: dup
     458: invokespecial #258                // Method java/lang/StringBuilder."<init>":()V
     461: lload         22
     463: invokevirtual #262                // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     466: bipush        32
     468: invokevirtual #265                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     471: invokevirtual #269                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     474: invokevirtual #272                // Method java/io/PrintWriter.print:(Ljava/lang/String;)V
     477: nop
     478: goto          420
     481: nop
     482: aload         10
     484: invokevirtual #274                // Method java/io/PrintWriter.println:()V
     487: nop
     488: nop
     489: goto          372
     492: nop
     493: nop
     494: getstatic     #280                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     497: astore        10
     499: aload         8
     501: aload         9
     503: invokestatic  #286                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     506: goto          530
     509: astore        11
     511: aload         11
     513: astore        9
     515: aload         11
     517: athrow
     518: astore        11
     520: aload         8
     522: aload         9
     524: invokestatic  #286                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
     527: aload         11
     529: athrow
     530: return
    Exception table:
       from    to  target type
         335   499   509   Class java/lang/Throwable
         335   499   518   any
         509   518   518   any
         518   520   518   any

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

  private static final long scheduleO2CMax$fill(java.util.List<java.lang.Long>, java.util.List<java.lang.Long>, kotlin.sequences.Sequence<java.lang.Integer>, long);
    Code:
       0: aload_2
       1: astore        5
       3: lload_3
       4: lstore        6
       6: iconst_0
       7: istore        8
       9: lload         6
      11: lstore        9
      13: aload         5
      15: invokeinterface #28,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
      20: astore        11
      22: aload         11
      24: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      29: ifeq          94
      32: aload         11
      34: invokeinterface #38,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      39: astore        12
      41: lload         9
      43: aload         12
      45: checkcast     #40                 // class java/lang/Number
      48: invokevirtual #44                 // Method java/lang/Number.intValue:()I
      51: istore        13
      53: lstore        14
      55: iconst_0
      56: istore        16
      58: aload_0
      59: iload         13
      61: lload         14
      63: invokestatic  #76                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      66: invokeinterface #314,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
      71: pop
      72: lload         14
      74: aload_1
      75: iload         13
      77: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      82: checkcast     #40                 // class java/lang/Number
      85: invokevirtual #54                 // Method java/lang/Number.longValue:()J
      88: ladd
      89: lstore        9
      91: goto          22
      94: lload         9
      96: lreturn

  static long scheduleO2CMax$fill$default(java.util.List, java.util.List, kotlin.sequences.Sequence, long, int, java.lang.Object);
    Code:
       0: iload         5
       2: bipush        8
       4: iand
       5: ifeq          10
       8: lconst_0
       9: lstore_3
      10: aload_0
      11: aload_1
      12: aload_2
      13: lload_3
      14: invokestatic  #144                // Method scheduleO2CMax$fill:(Ljava/util/List;Ljava/util/List;Lkotlin/sequences/Sequence;J)J
      17: lreturn

  private static final boolean scheduleO2CMax$i$lambda$1(java.util.List, kotlin.collections.IndexedValue);
    Code:
       0: aload_1
       1: ldc_w         #328                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #332                // Method kotlin/collections/IndexedValue.component1:()I
      11: istore_2
      12: aload_1
      13: invokevirtual #333                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
      16: checkcast     #40                 // class java/lang/Number
      19: invokevirtual #54                 // Method java/lang/Number.longValue:()J
      22: lstore_3
      23: lload_3
      24: aload_0
      25: iload_2
      26: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      31: checkcast     #40                 // class java/lang/Number
      34: invokevirtual #54                 // Method java/lang/Number.longValue:()J
      37: lcmp
      38: ifgt          45
      41: iconst_1
      42: goto          46
      45: iconst_0
      46: ireturn

  private static final int scheduleO2CMax$i$lambda$2(kotlin.collections.IndexedValue);
    Code:
       0: aload_0
       1: ldc_w         #338                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #341                // Method kotlin/collections/IndexedValue.getIndex:()I
      11: ireturn

  private static final kotlin.sequences.Sequence<java.lang.Integer> scheduleO2CMax$i(java.util.List<java.lang.Long>, java.util.List<java.lang.Long>);
    Code:
       0: aload_0
       1: checkcast     #90                 // class java/lang/Iterable
       4: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
       7: invokestatic  #347                // Method kotlin/sequences/SequencesKt.withIndex:(Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
      10: aload_1
      11: invokedynamic #365,  0            // InvokeDynamic #0:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
      16: invokestatic  #369                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      19: invokedynamic #377,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      24: invokestatic  #380                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      27: areturn

  private static final boolean scheduleO2CMax$j$lambda$3(java.util.List, kotlin.collections.IndexedValue);
    Code:
       0: aload_1
       1: ldc_w         #328                // String <destruct>
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_1
       8: invokevirtual #332                // Method kotlin/collections/IndexedValue.component1:()I
      11: istore_2
      12: aload_1
      13: invokevirtual #333                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
      16: checkcast     #40                 // class java/lang/Number
      19: invokevirtual #54                 // Method java/lang/Number.longValue:()J
      22: lstore_3
      23: lload_3
      24: aload_0
      25: iload_2
      26: invokeinterface #50,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      31: checkcast     #40                 // class java/lang/Number
      34: invokevirtual #54                 // Method java/lang/Number.longValue:()J
      37: lcmp
      38: ifle          45
      41: iconst_1
      42: goto          46
      45: iconst_0
      46: ireturn

  private static final int scheduleO2CMax$j$lambda$4(kotlin.collections.IndexedValue);
    Code:
       0: aload_0
       1: ldc_w         #338                // String it
       4: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       7: aload_0
       8: invokevirtual #341                // Method kotlin/collections/IndexedValue.getIndex:()I
      11: ireturn

  private static final kotlin.sequences.Sequence<java.lang.Integer> scheduleO2CMax$j(java.util.List<java.lang.Long>, java.util.List<java.lang.Long>);
    Code:
       0: aload_0
       1: checkcast     #90                 // class java/lang/Iterable
       4: invokestatic  #98                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
       7: invokestatic  #347                // Method kotlin/sequences/SequencesKt.withIndex:(Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
      10: aload_1
      11: invokedynamic #387,  0            // InvokeDynamic #2:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
      16: invokestatic  #369                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      19: invokedynamic #391,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function1;
      24: invokestatic  #380                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      27: areturn
}