import java.lang.Integer.max

fun main() {
    fun part1(input: List<String>): Int {
        val sumIndex = 0
        val maxSumIndex = 1
        val zeroCalorie = 0
        return input.map {
            it.toIntOrNull()
        }.foldRight(intArrayOf(0, 0)) { calorieOrNull, acc ->
            calorieOrNull ?.let { calorie ->
                intArrayOf(acc[sumIndex] + calorie, acc[maxSumIndex])
            } ?: run {
                intArrayOf(zeroCalorie, max(acc[maxSumIndex], acc[sumIndex]))
            }
        }[maxSumIndex]
    }

    fun part2(input: List<String>): Int {
        val sumIndex = 0
        val highSumIndex = 1
        val highHighSumIndex = 2
        val highHighHighSumIndex = 3
        val zeroCalorie = 0

        return input.map {
            it.toIntOrNull()
        }.foldRight(intArrayOf(0, 0, 0, 0)) { calorieOrNull, acc ->
            calorieOrNull?.let { calorie ->
                intArrayOf(acc[sumIndex] + calorie, acc[highSumIndex], acc[highHighSumIndex], acc[highHighHighSumIndex])
            } ?: run {
                when {
                    acc[sumIndex] > acc[highSumIndex] && acc[sumIndex] < acc[highHighSumIndex] -> intArrayOf(zeroCalorie, acc[sumIndex], acc[highHighSumIndex], acc[highHighHighSumIndex])
                    acc[sumIndex] > acc[highHighSumIndex] && acc[sumIndex] < acc[highHighHighSumIndex] -> intArrayOf(zeroCalorie, acc[highHighSumIndex], acc[sumIndex], acc[highHighHighSumIndex])
                    acc[sumIndex] > acc[3] -> intArrayOf(zeroCalorie, acc[highHighSumIndex], acc[highHighHighSumIndex], acc[sumIndex])
                    else -> intArrayOf(zeroCalorie, acc[highSumIndex], acc[highHighSumIndex], acc[highHighHighSumIndex])
                }
            }
        }
            .drop(1)
            .sum()
    }

    // test if implementation meets criteria from the description, like:
//    val testInput = readInput("Day01_test")
//    check(part1(testInput) == 24000)
//    check(part2(testInput) == 45000)
//
//    val input = readInput("Day01")
//    println(part1(input))
//    println(part2(input))
}

Compiled from "Day01.kt"
public final class Day01Kt {
  public static final void main();
    Code:
       0: return

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

  private static final int main$part1(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_1
       3: istore_2
       4: iconst_0
       5: istore_3
       6: aload_0
       7: checkcast     #16                 // class java/lang/Iterable
      10: astore        4
      12: iconst_0
      13: istore        5
      15: aload         4
      17: astore        6
      19: new           #18                 // class java/util/ArrayList
      22: dup
      23: aload         4
      25: bipush        10
      27: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      30: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      33: checkcast     #30                 // class java/util/Collection
      36: astore        7
      38: iconst_0
      39: istore        8
      41: aload         6
      43: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      48: astore        9
      50: aload         9
      52: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      57: ifeq          100
      60: aload         9
      62: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      67: astore        10
      69: aload         7
      71: aload         10
      73: checkcast     #46                 // class java/lang/String
      76: astore        11
      78: astore        16
      80: iconst_0
      81: istore        12
      83: aload         11
      85: invokestatic  #52                 // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      88: aload         16
      90: swap
      91: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      96: pop
      97: goto          50
     100: aload         7
     102: checkcast     #58                 // class java/util/List
     105: nop
     106: astore        4
     108: iconst_2
     109: newarray       int
     111: astore        5
     113: aload         5
     115: iconst_0
     116: iconst_0
     117: iastore
     118: aload         5
     120: iconst_1
     121: iconst_0
     122: iastore
     123: aload         5
     125: astore        5
     127: iconst_0
     128: istore        6
     130: aload         5
     132: astore        7
     134: aload         4
     136: invokeinterface #61,  1           // InterfaceMethod java/util/List.isEmpty:()Z
     141: ifne          274
     144: aload         4
     146: aload         4
     148: invokeinterface #65,  1           // InterfaceMethod java/util/List.size:()I
     153: invokeinterface #69,  2           // InterfaceMethod java/util/List.listIterator:(I)Ljava/util/ListIterator;
     158: astore        8
     160: aload         8
     162: invokeinterface #74,  1           // InterfaceMethod java/util/ListIterator.hasPrevious:()Z
     167: ifeq          274
     170: aload         8
     172: invokeinterface #77,  1           // InterfaceMethod java/util/ListIterator.previous:()Ljava/lang/Object;
     177: aload         7
     179: astore        9
     181: checkcast     #79                 // class java/lang/Integer
     184: astore        10
     186: iconst_0
     187: istore        11
     189: aload         10
     191: dup
     192: ifnull        236
     195: checkcast     #81                 // class java/lang/Number
     198: invokevirtual #84                 // Method java/lang/Number.intValue:()I
     201: istore        12
     203: iconst_0
     204: istore        13
     206: iconst_2
     207: newarray       int
     209: astore        14
     211: aload         14
     213: iconst_0
     214: aload         9
     216: iload_1
     217: iaload
     218: iload         12
     220: iadd
     221: iastore
     222: aload         14
     224: iconst_1
     225: aload         9
     227: iload_2
     228: iaload
     229: iastore
     230: aload         14
     232: nop
     233: goto          268
     236: pop
     237: iconst_0
     238: istore        15
     240: iconst_2
     241: newarray       int
     243: astore        12
     245: aload         12
     247: iconst_0
     248: iload_3
     249: iastore
     250: aload         12
     252: iconst_1
     253: aload         9
     255: iload_2
     256: iaload
     257: aload         9
     259: iload_1
     260: iaload
     261: invokestatic  #88                 // Method java/lang/Integer.max:(II)I
     264: iastore
     265: aload         12
     267: nop
     268: nop
     269: astore        7
     271: goto          160
     274: aload         7
     276: iload_2
     277: iaload
     278: ireturn

  private static final int main$part2(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_1
       3: istore_2
       4: iconst_2
       5: istore_3
       6: iconst_3
       7: istore        4
       9: iconst_0
      10: istore        5
      12: aload_0
      13: checkcast     #16                 // class java/lang/Iterable
      16: astore        6
      18: iconst_0
      19: istore        7
      21: aload         6
      23: astore        8
      25: new           #18                 // class java/util/ArrayList
      28: dup
      29: aload         6
      31: bipush        10
      33: invokestatic  #24                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      36: invokespecial #28                 // Method java/util/ArrayList."<init>":(I)V
      39: checkcast     #30                 // class java/util/Collection
      42: astore        9
      44: iconst_0
      45: istore        10
      47: aload         8
      49: invokeinterface #34,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      54: astore        11
      56: aload         11
      58: invokeinterface #40,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      63: ifeq          106
      66: aload         11
      68: invokeinterface #44,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      73: astore        12
      75: aload         9
      77: aload         12
      79: checkcast     #46                 // class java/lang/String
      82: astore        13
      84: astore        18
      86: iconst_0
      87: istore        14
      89: aload         13
      91: invokestatic  #52                 // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
      94: aload         18
      96: swap
      97: invokeinterface #56,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     102: pop
     103: goto          56
     106: aload         9
     108: checkcast     #58                 // class java/util/List
     111: nop
     112: astore        6
     114: iconst_4
     115: newarray       int
     117: astore        7
     119: aload         7
     121: iconst_0
     122: iconst_0
     123: iastore
     124: aload         7
     126: iconst_1
     127: iconst_0
     128: iastore
     129: aload         7
     131: iconst_2
     132: iconst_0
     133: iastore
     134: aload         7
     136: iconst_3
     137: iconst_0
     138: iastore
     139: aload         7
     141: astore        7
     143: iconst_0
     144: istore        8
     146: aload         7
     148: astore        9
     150: aload         6
     152: invokeinterface #61,  1           // InterfaceMethod java/util/List.isEmpty:()Z
     157: ifne          499
     160: aload         6
     162: aload         6
     164: invokeinterface #65,  1           // InterfaceMethod java/util/List.size:()I
     169: invokeinterface #69,  2           // InterfaceMethod java/util/List.listIterator:(I)Ljava/util/ListIterator;
     174: astore        10
     176: aload         10
     178: invokeinterface #74,  1           // InterfaceMethod java/util/ListIterator.hasPrevious:()Z
     183: ifeq          499
     186: aload         10
     188: invokeinterface #77,  1           // InterfaceMethod java/util/ListIterator.previous:()Ljava/lang/Object;
     193: aload         9
     195: astore        11
     197: checkcast     #79                 // class java/lang/Integer
     200: astore        12
     202: iconst_0
     203: istore        13
     205: aload         12
     207: dup
     208: ifnull        269
     211: checkcast     #81                 // class java/lang/Number
     214: invokevirtual #84                 // Method java/lang/Number.intValue:()I
     217: istore        14
     219: iconst_0
     220: istore        15
     222: iconst_4
     223: newarray       int
     225: astore        16
     227: aload         16
     229: iconst_0
     230: aload         11
     232: iload_1
     233: iaload
     234: iload         14
     236: iadd
     237: iastore
     238: aload         16
     240: iconst_1
     241: aload         11
     243: iload_2
     244: iaload
     245: iastore
     246: aload         16
     248: iconst_2
     249: aload         11
     251: iload_3
     252: iaload
     253: iastore
     254: aload         16
     256: iconst_3
     257: aload         11
     259: iload         4
     261: iaload
     262: iastore
     263: aload         16
     265: nop
     266: goto          493
     269: pop
     270: iconst_0
     271: istore        17
     273: nop
     274: aload         11
     276: iload_1
     277: iaload
     278: aload         11
     280: iload_2
     281: iaload
     282: if_icmple     337
     285: aload         11
     287: iload_1
     288: iaload
     289: aload         11
     291: iload_3
     292: iaload
     293: if_icmpge     337
     296: iconst_4
     297: newarray       int
     299: astore        14
     301: aload         14
     303: iconst_0
     304: iload         5
     306: iastore
     307: aload         14
     309: iconst_1
     310: aload         11
     312: iload_1
     313: iaload
     314: iastore
     315: aload         14
     317: iconst_2
     318: aload         11
     320: iload_3
     321: iaload
     322: iastore
     323: aload         14
     325: iconst_3
     326: aload         11
     328: iload         4
     330: iaload
     331: iastore
     332: aload         14
     334: goto          491
     337: aload         11
     339: iload_1
     340: iaload
     341: aload         11
     343: iload_3
     344: iaload
     345: if_icmple     401
     348: aload         11
     350: iload_1
     351: iaload
     352: aload         11
     354: iload         4
     356: iaload
     357: if_icmpge     401
     360: iconst_4
     361: newarray       int
     363: astore        14
     365: aload         14
     367: iconst_0
     368: iload         5
     370: iastore
     371: aload         14
     373: iconst_1
     374: aload         11
     376: iload_3
     377: iaload
     378: iastore
     379: aload         14
     381: iconst_2
     382: aload         11
     384: iload_1
     385: iaload
     386: iastore
     387: aload         14
     389: iconst_3
     390: aload         11
     392: iload         4
     394: iaload
     395: iastore
     396: aload         14
     398: goto          491
     401: aload         11
     403: iload_1
     404: iaload
     405: aload         11
     407: iconst_3
     408: iaload
     409: if_icmple     453
     412: iconst_4
     413: newarray       int
     415: astore        14
     417: aload         14
     419: iconst_0
     420: iload         5
     422: iastore
     423: aload         14
     425: iconst_1
     426: aload         11
     428: iload_3
     429: iaload
     430: iastore
     431: aload         14
     433: iconst_2
     434: aload         11
     436: iload         4
     438: iaload
     439: iastore
     440: aload         14
     442: iconst_3
     443: aload         11
     445: iload_1
     446: iaload
     447: iastore
     448: aload         14
     450: goto          491
     453: iconst_4
     454: newarray       int
     456: astore        14
     458: aload         14
     460: iconst_0
     461: iload         5
     463: iastore
     464: aload         14
     466: iconst_1
     467: aload         11
     469: iload_2
     470: iaload
     471: iastore
     472: aload         14
     474: iconst_2
     475: aload         11
     477: iload_3
     478: iaload
     479: iastore
     480: aload         14
     482: iconst_3
     483: aload         11
     485: iload         4
     487: iaload
     488: iastore
     489: aload         14
     491: nop
     492: nop
     493: nop
     494: astore        9
     496: goto          176
     499: aload         9
     501: iconst_1
     502: invokestatic  #128                // Method kotlin/collections/ArraysKt.drop:([II)Ljava/util/List;
     505: checkcast     #16                 // class java/lang/Iterable
     508: invokestatic  #132                // Method kotlin/collections/CollectionsKt.sumOfInt:(Ljava/lang/Iterable;)I
     511: ireturn
}


import java.io.File

fun main() {

    fun part1(input: String): Int {
        val data = input.split("\r\n")
        var result = 0
        for (d in data) {
            val temp = d.split(",").map { it.split("-") }
            val first = temp[0]
            val second = temp[1]
            if (
                (first[0].toInt() <= second[0].toInt() && first[1].toInt() >= second[1].toInt()) ||
                (first[0].toInt() >= second[0].toInt() && first[1].toInt() <= second[1].toInt())
            ) {
                result++
            }
        }
        return result
    }

    fun part2(input: String): Int {
        val data = input.split("\r\n")
        var result = 0
        for (d in data) {
            val temp = d.split(",").map { it.split("-") }
            val first = temp[0].map { it.toInt() }
            val second = temp[1].map { it.toInt() }
            if (
                (first[0] in second[0]..second[1]) ||
                (first[1] in second[0]..second[1]) ||
                (second[0] in first[0]..first[1]) ||
                (second[0] in first[0]..first[1])
                )
            {
                result++
            }
        }
        return result
    }

    val testInput = File("src/Day04_test.txt").readText()
    check(part2(testInput) == 4)

    val input = File("src/Day04.txt").readText()
    println(part1(input))
    println(part2(input))

}

Compiled from "Day04.kt"
public final class Day04Kt {
  public static final void main();
    Code:
       0: new           #8                  // class java/io/File
       3: dup
       4: ldc           #10                 // String src/Day04_test.txt
       6: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
       9: aconst_null
      10: iconst_1
      11: aconst_null
      12: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      15: astore_0
      16: aload_0
      17: invokestatic  #24                 // Method main$part2:(Ljava/lang/String;)I
      20: iconst_4
      21: if_icmpne     28
      24: iconst_1
      25: goto          29
      28: iconst_0
      29: ifne          42
      32: new           #26                 // class java/lang/IllegalStateException
      35: dup
      36: ldc           #28                 // String Check failed.
      38: invokespecial #29                 // Method java/lang/IllegalStateException."<init>":(Ljava/lang/String;)V
      41: athrow
      42: new           #8                  // class java/io/File
      45: dup
      46: ldc           #31                 // String src/Day04.txt
      48: invokespecial #14                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      51: aconst_null
      52: iconst_1
      53: aconst_null
      54: invokestatic  #20                 // Method kotlin/io/FilesKt.readText$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/lang/String;
      57: astore_1
      58: aload_1
      59: invokestatic  #34                 // Method main$part1:(Ljava/lang/String;)I
      62: istore_2
      63: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      66: iload_2
      67: invokevirtual #46                 // Method java/io/PrintStream.println:(I)V
      70: aload_1
      71: invokestatic  #24                 // Method main$part2:(Ljava/lang/String;)I
      74: istore_2
      75: getstatic     #40                 // Field java/lang/System.out:Ljava/io/PrintStream;
      78: iload_2
      79: invokevirtual #46                 // Method java/io/PrintStream.println:(I)V
      82: return

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

  private static final int main$part1(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #58                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #51                 // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #60                 // String \r\n
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #66                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: astore_1
      24: iconst_0
      25: istore_2
      26: aload_1
      27: invokeinterface #72,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      32: astore_3
      33: aload_3
      34: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          359
      42: aload_3
      43: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: checkcast     #51                 // class java/lang/String
      51: astore        4
      53: aload         4
      55: checkcast     #58                 // class java/lang/CharSequence
      58: iconst_1
      59: anewarray     #51                 // class java/lang/String
      62: astore        6
      64: aload         6
      66: iconst_0
      67: ldc           #84                 // String ,
      69: aastore
      70: aload         6
      72: iconst_0
      73: iconst_0
      74: bipush        6
      76: aconst_null
      77: invokestatic  #66                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      80: checkcast     #86                 // class java/lang/Iterable
      83: astore        6
      85: iconst_0
      86: istore        7
      88: aload         6
      90: astore        8
      92: new           #88                 // class java/util/ArrayList
      95: dup
      96: aload         6
      98: bipush        10
     100: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     103: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
     106: checkcast     #98                 // class java/util/Collection
     109: astore        9
     111: iconst_0
     112: istore        10
     114: aload         8
     116: invokeinterface #99,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     121: astore        11
     123: aload         11
     125: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          195
     133: aload         11
     135: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     140: astore        12
     142: aload         9
     144: aload         12
     146: checkcast     #51                 // class java/lang/String
     149: astore        13
     151: astore        16
     153: iconst_0
     154: istore        14
     156: aload         13
     158: checkcast     #58                 // class java/lang/CharSequence
     161: iconst_1
     162: anewarray     #51                 // class java/lang/String
     165: astore        15
     167: aload         15
     169: iconst_0
     170: ldc           #101                // String -
     172: aastore
     173: aload         15
     175: iconst_0
     176: iconst_0
     177: bipush        6
     179: aconst_null
     180: invokestatic  #66                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     183: aload         16
     185: swap
     186: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     191: pop
     192: goto          123
     195: aload         9
     197: checkcast     #68                 // class java/util/List
     200: nop
     201: astore        5
     203: aload         5
     205: iconst_0
     206: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     211: checkcast     #68                 // class java/util/List
     214: astore        6
     216: aload         5
     218: iconst_1
     219: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     224: checkcast     #68                 // class java/util/List
     227: astore        7
     229: aload         6
     231: iconst_0
     232: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     237: checkcast     #51                 // class java/lang/String
     240: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     243: aload         7
     245: iconst_0
     246: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     251: checkcast     #51                 // class java/lang/String
     254: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     257: if_icmpgt     291
     260: aload         6
     262: iconst_1
     263: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     268: checkcast     #51                 // class java/lang/String
     271: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     274: aload         7
     276: iconst_1
     277: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     282: checkcast     #51                 // class java/lang/String
     285: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     288: if_icmpge     353
     291: aload         6
     293: iconst_0
     294: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     299: checkcast     #51                 // class java/lang/String
     302: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     305: aload         7
     307: iconst_0
     308: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     313: checkcast     #51                 // class java/lang/String
     316: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     319: if_icmplt     33
     322: aload         6
     324: iconst_1
     325: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     330: checkcast     #51                 // class java/lang/String
     333: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     336: aload         7
     338: iconst_1
     339: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     344: checkcast     #51                 // class java/lang/String
     347: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     350: if_icmpgt     33
     353: iinc          2, 1
     356: goto          33
     359: iload_2
     360: ireturn

  private static final int main$part2(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #58                 // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #51                 // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #60                 // String \r\n
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #66                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: astore_1
      24: iconst_0
      25: istore_2
      26: aload_1
      27: invokeinterface #72,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      32: astore_3
      33: aload_3
      34: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      39: ifeq          731
      42: aload_3
      43: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      48: checkcast     #51                 // class java/lang/String
      51: astore        4
      53: aload         4
      55: checkcast     #58                 // class java/lang/CharSequence
      58: iconst_1
      59: anewarray     #51                 // class java/lang/String
      62: astore        6
      64: aload         6
      66: iconst_0
      67: ldc           #84                 // String ,
      69: aastore
      70: aload         6
      72: iconst_0
      73: iconst_0
      74: bipush        6
      76: aconst_null
      77: invokestatic  #66                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      80: checkcast     #86                 // class java/lang/Iterable
      83: astore        6
      85: iconst_0
      86: istore        7
      88: aload         6
      90: astore        8
      92: new           #88                 // class java/util/ArrayList
      95: dup
      96: aload         6
      98: bipush        10
     100: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     103: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
     106: checkcast     #98                 // class java/util/Collection
     109: astore        9
     111: iconst_0
     112: istore        10
     114: aload         8
     116: invokeinterface #99,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     121: astore        11
     123: aload         11
     125: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     130: ifeq          195
     133: aload         11
     135: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     140: astore        12
     142: aload         9
     144: aload         12
     146: checkcast     #51                 // class java/lang/String
     149: astore        13
     151: astore        17
     153: iconst_0
     154: istore        14
     156: aload         13
     158: checkcast     #58                 // class java/lang/CharSequence
     161: iconst_1
     162: anewarray     #51                 // class java/lang/String
     165: astore        15
     167: aload         15
     169: iconst_0
     170: ldc           #101                // String -
     172: aastore
     173: aload         15
     175: iconst_0
     176: iconst_0
     177: bipush        6
     179: aconst_null
     180: invokestatic  #66                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     183: aload         17
     185: swap
     186: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     191: pop
     192: goto          123
     195: aload         9
     197: checkcast     #68                 // class java/util/List
     200: nop
     201: astore        5
     203: aload         5
     205: iconst_0
     206: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     211: checkcast     #86                 // class java/lang/Iterable
     214: astore        7
     216: iconst_0
     217: istore        8
     219: aload         7
     221: astore        9
     223: new           #88                 // class java/util/ArrayList
     226: dup
     227: aload         7
     229: bipush        10
     231: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     234: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
     237: checkcast     #98                 // class java/util/Collection
     240: astore        10
     242: iconst_0
     243: istore        11
     245: aload         9
     247: invokeinterface #99,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     252: astore        12
     254: aload         12
     256: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     261: ifeq          308
     264: aload         12
     266: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     271: astore        13
     273: aload         10
     275: aload         13
     277: checkcast     #51                 // class java/lang/String
     280: astore        14
     282: astore        17
     284: iconst_0
     285: istore        15
     287: aload         14
     289: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     292: nop
     293: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     296: aload         17
     298: swap
     299: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     304: pop
     305: goto          254
     308: aload         10
     310: checkcast     #68                 // class java/util/List
     313: nop
     314: astore        6
     316: aload         5
     318: iconst_1
     319: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     324: checkcast     #86                 // class java/lang/Iterable
     327: astore        8
     329: iconst_0
     330: istore        9
     332: aload         8
     334: astore        10
     336: new           #88                 // class java/util/ArrayList
     339: dup
     340: aload         8
     342: bipush        10
     344: invokestatic  #94                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     347: invokespecial #96                 // Method java/util/ArrayList."<init>":(I)V
     350: checkcast     #98                 // class java/util/Collection
     353: astore        11
     355: iconst_0
     356: istore        12
     358: aload         10
     360: invokeinterface #99,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     365: astore        13
     367: aload         13
     369: invokeinterface #78,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     374: ifeq          421
     377: aload         13
     379: invokeinterface #82,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     384: astore        14
     386: aload         11
     388: aload         14
     390: checkcast     #51                 // class java/lang/String
     393: astore        15
     395: astore        17
     397: iconst_0
     398: istore        16
     400: aload         15
     402: invokestatic  #114                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     405: nop
     406: invokestatic  #137                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     409: aload         17
     411: swap
     412: invokeinterface #105,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     417: pop
     418: goto          367
     421: aload         11
     423: checkcast     #68                 // class java/util/List
     426: nop
     427: astore        7
     429: aload         7
     431: iconst_0
     432: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     437: checkcast     #139                // class java/lang/Number
     440: invokevirtual #143                // Method java/lang/Number.intValue:()I
     443: istore        8
     445: aload         7
     447: iconst_1
     448: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     453: checkcast     #139                // class java/lang/Number
     456: invokevirtual #143                // Method java/lang/Number.intValue:()I
     459: istore        9
     461: aload         6
     463: iconst_0
     464: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     469: checkcast     #139                // class java/lang/Number
     472: invokevirtual #143                // Method java/lang/Number.intValue:()I
     475: istore        10
     477: iload         8
     479: iload         10
     481: if_icmpgt     499
     484: iload         10
     486: iload         9
     488: if_icmpgt     495
     491: iconst_1
     492: goto          500
     495: iconst_0
     496: goto          500
     499: iconst_0
     500: ifne          725
     503: aload         7
     505: iconst_0
     506: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     511: checkcast     #139                // class java/lang/Number
     514: invokevirtual #143                // Method java/lang/Number.intValue:()I
     517: istore        8
     519: aload         7
     521: iconst_1
     522: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     527: checkcast     #139                // class java/lang/Number
     530: invokevirtual #143                // Method java/lang/Number.intValue:()I
     533: istore        9
     535: aload         6
     537: iconst_1
     538: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     543: checkcast     #139                // class java/lang/Number
     546: invokevirtual #143                // Method java/lang/Number.intValue:()I
     549: istore        10
     551: iload         8
     553: iload         10
     555: if_icmpgt     573
     558: iload         10
     560: iload         9
     562: if_icmpgt     569
     565: iconst_1
     566: goto          574
     569: iconst_0
     570: goto          574
     573: iconst_0
     574: ifne          725
     577: aload         6
     579: iconst_0
     580: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     585: checkcast     #139                // class java/lang/Number
     588: invokevirtual #143                // Method java/lang/Number.intValue:()I
     591: istore        8
     593: aload         6
     595: iconst_1
     596: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     601: checkcast     #139                // class java/lang/Number
     604: invokevirtual #143                // Method java/lang/Number.intValue:()I
     607: istore        9
     609: aload         7
     611: iconst_0
     612: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     617: checkcast     #139                // class java/lang/Number
     620: invokevirtual #143                // Method java/lang/Number.intValue:()I
     623: istore        10
     625: iload         8
     627: iload         10
     629: if_icmpgt     647
     632: iload         10
     634: iload         9
     636: if_icmpgt     643
     639: iconst_1
     640: goto          648
     643: iconst_0
     644: goto          648
     647: iconst_0
     648: ifne          725
     651: aload         6
     653: iconst_0
     654: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     659: checkcast     #139                // class java/lang/Number
     662: invokevirtual #143                // Method java/lang/Number.intValue:()I
     665: istore        8
     667: aload         6
     669: iconst_1
     670: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     675: checkcast     #139                // class java/lang/Number
     678: invokevirtual #143                // Method java/lang/Number.intValue:()I
     681: istore        9
     683: aload         7
     685: iconst_0
     686: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     691: checkcast     #139                // class java/lang/Number
     694: invokevirtual #143                // Method java/lang/Number.intValue:()I
     697: istore        10
     699: iload         8
     701: iload         10
     703: if_icmpgt     721
     706: iload         10
     708: iload         9
     710: if_icmpgt     717
     713: iconst_1
     714: goto          722
     717: iconst_0
     718: goto          722
     721: iconst_0
     722: ifeq          33
     725: iinc          2, 1
     728: goto          33
     731: iload_2
     732: ireturn
}


fun main(args: Array<String>) {
    val jobs = buildJobs(args)
    if (jobs.isNullOrEmpty()) {
        println("Usage: please provide a list of profits and a list of deadlines")
    } else {
        println(maxProfit(jobs))
    }
}

/**
 * Calculates the maximum profit of a list of jobs
 */
private fun maxProfit(jobs: List<Job>): Int {
    val scheduled = hashSetOf<Int>()
    var profit = 0
    jobs.sortedByDescending { it.profit }.forEach {
        for (i in it.deadline downTo 1) {
            if (scheduled.add(i)) {
                profit += it.profit
                break
            }
        }
    }
    return profit
}

/**
 * Builds job list with input arguments
 */
private fun buildJobs(args: Array<String>): List<Job>? {
    if (args.run { isNullOrEmpty() || size < 2 || any { it.isBlank() } }) return null

    val profits = args[0].toIntArray()
    val deadlines = args[1].toIntArray()

    if (profits.size != deadlines.size) return null
    return profits.mapIndexed { index, profit -> Job(profit, deadlines[index]) }
}

/**
 * Represents the information of a job
 */
class Job(val profit: Int, val deadline: Int)

/**
 * Extracts an array of integers from the string
 */
fun String.toIntArray() = split(",").mapNotNull { it.trim().toIntOrNull() }

Compiled from "JobSequencing.kt"
public final class JobSequencingKt {
  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #19                 // Method buildJobs:([Ljava/lang/String;)Ljava/util/List;
      10: astore_1
      11: aload_1
      12: checkcast     #21                 // class java/util/Collection
      15: astore_2
      16: aload_2
      17: ifnull        29
      20: aload_2
      21: invokeinterface #25,  1           // InterfaceMethod java/util/Collection.isEmpty:()Z
      26: ifeq          33
      29: iconst_1
      30: goto          34
      33: iconst_0
      34: ifeq          49
      37: ldc           #27                 // String Usage: please provide a list of profits and a list of deadlines
      39: getstatic     #33                 // Field java/lang/System.out:Ljava/io/PrintStream;
      42: swap
      43: invokevirtual #39                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      46: goto          61
      49: aload_1
      50: invokestatic  #43                 // Method maxProfit:(Ljava/util/List;)I
      53: istore_2
      54: getstatic     #33                 // Field java/lang/System.out:Ljava/io/PrintStream;
      57: iload_2
      58: invokevirtual #46                 // Method java/io/PrintStream.println:(I)V
      61: return

  private static final int maxProfit(java.util.List<Job>);
    Code:
       0: new           #54                 // class java/util/HashSet
       3: dup
       4: invokespecial #58                 // Method java/util/HashSet."<init>":()V
       7: astore_1
       8: iconst_0
       9: istore_2
      10: aload_0
      11: checkcast     #60                 // class java/lang/Iterable
      14: astore_3
      15: iconst_0
      16: istore        4
      18: aload_3
      19: new           #62                 // class JobSequencingKt$maxProfit$$inlined$sortedByDescending$1
      22: dup
      23: invokespecial #63                 // Method JobSequencingKt$maxProfit$$inlined$sortedByDescending$1."<init>":()V
      26: checkcast     #65                 // class java/util/Comparator
      29: invokestatic  #71                 // Method kotlin/collections/CollectionsKt.sortedWith:(Ljava/lang/Iterable;Ljava/util/Comparator;)Ljava/util/List;
      32: checkcast     #60                 // class java/lang/Iterable
      35: astore_3
      36: nop
      37: iconst_0
      38: istore        4
      40: aload_3
      41: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      46: astore        5
      48: aload         5
      50: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      55: ifeq          124
      58: aload         5
      60: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      65: astore        6
      67: aload         6
      69: checkcast     #86                 // class Job
      72: astore        7
      74: iconst_0
      75: istore        8
      77: aload         7
      79: invokevirtual #90                 // Method Job.getDeadline:()I
      82: istore        9
      84: iconst_0
      85: iload         9
      87: if_icmpge     119
      90: aload_1
      91: iload         9
      93: invokestatic  #96                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      96: invokevirtual #100                // Method java/util/HashSet.add:(Ljava/lang/Object;)Z
      99: ifeq          113
     102: iload_2
     103: aload         7
     105: invokevirtual #103                // Method Job.getProfit:()I
     108: iadd
     109: istore_2
     110: goto          119
     113: iinc          9, -1
     116: goto          84
     119: nop
     120: nop
     121: goto          48
     124: nop
     125: iload_2
     126: ireturn

  private static final java.util.List<Job> buildJobs(java.lang.String[]);
    Code:
       0: aload_0
       1: astore_2
       2: iconst_0
       3: istore_3
       4: aload_2
       5: astore        4
       7: aload         4
       9: ifnull        26
      12: aload         4
      14: arraylength
      15: ifne          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifeq          30
      26: iconst_1
      27: goto          31
      30: iconst_0
      31: ifne          100
      34: aload_2
      35: arraylength
      36: iconst_2
      37: if_icmplt     100
      40: aload_2
      41: astore        4
      43: iconst_0
      44: istore        5
      46: iconst_0
      47: istore        6
      49: aload         4
      51: arraylength
      52: istore        7
      54: iload         6
      56: iload         7
      58: if_icmpge     96
      61: aload         4
      63: iload         6
      65: aaload
      66: astore        8
      68: aload         8
      70: astore        9
      72: iconst_0
      73: istore        10
      75: aload         9
      77: checkcast     #121                // class java/lang/CharSequence
      80: invokestatic  #127                // Method kotlin/text/StringsKt.isBlank:(Ljava/lang/CharSequence;)Z
      83: ifeq          90
      86: iconst_1
      87: goto          97
      90: iinc          6, 1
      93: goto          54
      96: iconst_0
      97: ifeq          104
     100: iconst_1
     101: goto          105
     104: iconst_0
     105: nop
     106: ifeq          111
     109: aconst_null
     110: areturn
     111: aload_0
     112: iconst_0
     113: aaload
     114: invokestatic  #131                // Method toIntArray:(Ljava/lang/String;)Ljava/util/List;
     117: astore_1
     118: aload_0
     119: iconst_1
     120: aaload
     121: invokestatic  #131                // Method toIntArray:(Ljava/lang/String;)Ljava/util/List;
     124: astore_2
     125: aload_1
     126: invokeinterface #134,  1          // InterfaceMethod java/util/List.size:()I
     131: aload_2
     132: invokeinterface #134,  1          // InterfaceMethod java/util/List.size:()I
     137: if_icmpeq     142
     140: aconst_null
     141: areturn
     142: aload_1
     143: checkcast     #60                 // class java/lang/Iterable
     146: astore_3
     147: iconst_0
     148: istore        4
     150: aload_3
     151: astore        5
     153: new           #136                // class java/util/ArrayList
     156: dup
     157: aload_3
     158: bipush        10
     160: invokestatic  #140                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     163: invokespecial #142                // Method java/util/ArrayList."<init>":(I)V
     166: checkcast     #21                 // class java/util/Collection
     169: astore        6
     171: iconst_0
     172: istore        7
     174: iconst_0
     175: istore        8
     177: aload         5
     179: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     184: astore        9
     186: aload         9
     188: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     193: ifeq          276
     196: aload         9
     198: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     203: astore        10
     205: aload         6
     207: iload         8
     209: iinc          8, 1
     212: istore        11
     214: iload         11
     216: ifge          222
     219: invokestatic  #145                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     222: iload         11
     224: aload         10
     226: checkcast     #147                // class java/lang/Number
     229: invokevirtual #150                // Method java/lang/Number.intValue:()I
     232: istore        12
     234: istore        13
     236: astore        15
     238: iconst_0
     239: istore        14
     241: new           #86                 // class Job
     244: dup
     245: iload         12
     247: aload_2
     248: iload         13
     250: invokeinterface #154,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     255: checkcast     #147                // class java/lang/Number
     258: invokevirtual #150                // Method java/lang/Number.intValue:()I
     261: invokespecial #157                // Method Job."<init>":(II)V
     264: aload         15
     266: swap
     267: invokeinterface #158,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     272: pop
     273: goto          186
     276: aload         6
     278: checkcast     #51                 // class java/util/List
     281: nop
     282: areturn

  public static final java.util.List<java.lang.Integer> toIntArray(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #183                // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #121                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #180                // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #185                // String ,
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #189                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #60                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #136                // class java/util/ArrayList
      40: dup
      41: invokespecial #190                // Method java/util/ArrayList."<init>":()V
      44: checkcast     #21                 // class java/util/Collection
      47: astore        4
      49: iconst_0
      50: istore        5
      52: aload_3
      53: astore        6
      55: iconst_0
      56: istore        7
      58: aload         6
      60: invokeinterface #75,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      65: astore        8
      67: aload         8
      69: invokeinterface #80,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      74: ifeq          144
      77: aload         8
      79: invokeinterface #84,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      84: astore        9
      86: aload         9
      88: astore        10
      90: iconst_0
      91: istore        11
      93: aload         10
      95: checkcast     #180                // class java/lang/String
      98: astore        12
     100: iconst_0
     101: istore        13
     103: aload         12
     105: checkcast     #121                // class java/lang/CharSequence
     108: invokestatic  #194                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     111: invokevirtual #198                // Method java/lang/Object.toString:()Ljava/lang/String;
     114: invokestatic  #202                // Method kotlin/text/StringsKt.toIntOrNull:(Ljava/lang/String;)Ljava/lang/Integer;
     117: dup
     118: ifnull        139
     121: astore        14
     123: iconst_0
     124: istore        15
     126: aload         4
     128: aload         14
     130: invokeinterface #158,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     135: pop
     136: goto          140
     139: pop
     140: nop
     141: goto          67
     144: nop
     145: aload         4
     147: checkcast     #51                 // class java/util/List
     150: nop
     151: areturn
}

Compiled from "Comparisons.kt"
public final class JobSequencingKt$maxProfit$$inlined$sortedByDescending$1<T> implements java.util.Comparator {
  public JobSequencingKt$maxProfit$$inlined$sortedByDescending$1();
    Code:
       0: aload_0
       1: invokespecial #16                 // Method java/lang/Object."<init>":()V
       4: return

  public final int compare(T, T);
    Code:
       0: aload_2
       1: checkcast     #23                 // class Job
       4: astore_3
       5: iconst_0
       6: istore        4
       8: aload_3
       9: invokevirtual #27                 // Method Job.getProfit:()I
      12: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      15: checkcast     #35                 // class java/lang/Comparable
      18: aload_1
      19: checkcast     #23                 // class Job
      22: astore_3
      23: astore        5
      25: iconst_0
      26: istore        4
      28: aload_3
      29: invokevirtual #27                 // Method Job.getProfit:()I
      32: invokestatic  #33                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: aload         5
      37: swap
      38: checkcast     #35                 // class java/lang/Comparable
      41: invokestatic  #41                 // Method kotlin/comparisons/ComparisonsKt.compareValues:(Ljava/lang/Comparable;Ljava/lang/Comparable;)I
      44: ireturn
}


data class EncodingBounds(val lowerBound: Int, val upperBound: Int)

fun encodingBoundsForCharValue(c: Char): EncodingBounds? {
    val lowerCaseBounds = EncodingBounds('a'.toInt(), 'z'.toInt())
    val upperCaseBounds = EncodingBounds('A'.toInt(), 'Z'.toInt())
    return when (c) {
        in 'a'..'z' -> lowerCaseBounds
        in 'A'..'Z' -> upperCaseBounds
        else -> null
    }
}

fun calculateRotatedChar(char: Char, rotation: Int, bounds: EncodingBounds): Char {
    val rotatedCharVal = char.toInt() + rotation
    val remainder = rotatedCharVal - (bounds.upperBound + 1)
    return (if (rotatedCharVal > bounds.upperBound) bounds.lowerBound + remainder else rotatedCharVal).toChar()
}

fun parseInput(args: Array<String>): String? {
    if (args.isEmpty()) {
        return null
    }
    val text = args[0]
    if (text.isEmpty()) {
        return null
    }
    return text
}

fun rot13Encode(text: String): String {
    val rotation = 13

    return text.map { c ->
        val bounds = encodingBoundsForCharValue(c)
        if (bounds == null) {
            c.toString()
        } else {
            calculateRotatedChar(c, rotation, bounds).toString()
        }
    }.reduce { encodedText, encodedChar ->
        encodedText + encodedChar
    }

}

fun main(args: Array<String>) {
    val strToEncode = parseInput(args)
    if (strToEncode == null) {
        println("Usage: please provide a string to encrypt")
    } else {
        println(rot13Encode(strToEncode))
    }
}

Compiled from "Rot13.kt"
public final class Rot13Kt {
  public static final EncodingBounds encodingBoundsForCharValue(char);
    Code:
       0: new           #9                  // class EncodingBounds
       3: dup
       4: bipush        97
       6: bipush        122
       8: invokespecial #13                 // Method EncodingBounds."<init>":(II)V
      11: astore_1
      12: new           #9                  // class EncodingBounds
      15: dup
      16: bipush        65
      18: bipush        90
      20: invokespecial #13                 // Method EncodingBounds."<init>":(II)V
      23: astore_2
      24: iload_0
      25: istore_3
      26: bipush        97
      28: iload_3
      29: if_icmpgt     46
      32: iload_3
      33: bipush        123
      35: if_icmpge     42
      38: iconst_1
      39: goto          47
      42: iconst_0
      43: goto          47
      46: iconst_0
      47: ifeq          54
      50: aload_1
      51: goto          83
      54: bipush        65
      56: iload_3
      57: if_icmpgt     74
      60: iload_3
      61: bipush        91
      63: if_icmpge     70
      66: iconst_1
      67: goto          75
      70: iconst_0
      71: goto          75
      74: iconst_0
      75: ifeq          82
      78: aload_2
      79: goto          83
      82: aconst_null
      83: areturn

  public static final char calculateRotatedChar(char, int, EncodingBounds);
    Code:
       0: aload_2
       1: ldc           #23                 // String bounds
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iload_0
       7: iload_1
       8: iadd
       9: istore_3
      10: iload_3
      11: aload_2
      12: invokevirtual #33                 // Method EncodingBounds.getUpperBound:()I
      15: iconst_1
      16: iadd
      17: isub
      18: istore        4
      20: iload_3
      21: aload_2
      22: invokevirtual #33                 // Method EncodingBounds.getUpperBound:()I
      25: if_icmple     38
      28: aload_2
      29: invokevirtual #36                 // Method EncodingBounds.getLowerBound:()I
      32: iload         4
      34: iadd
      35: goto          39
      38: iload_3
      39: i2c
      40: ireturn

  public static final java.lang.String parseInput(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #45                 // String args
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: arraylength
       8: ifne          15
      11: iconst_1
      12: goto          16
      15: iconst_0
      16: ifeq          21
      19: aconst_null
      20: areturn
      21: aload_0
      22: iconst_0
      23: aaload
      24: astore_1
      25: aload_1
      26: checkcast     #47                 // class java/lang/CharSequence
      29: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      34: ifne          41
      37: iconst_1
      38: goto          42
      41: iconst_0
      42: ifeq          47
      45: aconst_null
      46: areturn
      47: aload_1
      48: areturn

  public static final java.lang.String rot13Encode(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #58                 // String text
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: bipush        13
       8: istore_1
       9: aload_0
      10: checkcast     #47                 // class java/lang/CharSequence
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_2
      17: astore        4
      19: new           #60                 // class java/util/ArrayList
      22: dup
      23: aload_2
      24: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      29: invokespecial #63                 // Method java/util/ArrayList."<init>":(I)V
      32: checkcast     #65                 // class java/util/Collection
      35: astore        5
      37: iconst_0
      38: istore        6
      40: iconst_0
      41: istore        7
      43: iload         7
      45: aload         4
      47: invokeinterface #50,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      52: if_icmpge     124
      55: aload         4
      57: iload         7
      59: invokeinterface #69,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      64: istore        8
      66: aload         5
      68: iload         8
      70: istore        9
      72: astore        12
      74: iconst_0
      75: istore        10
      77: iload         9
      79: invokestatic  #71                 // Method encodingBoundsForCharValue:(C)LEncodingBounds;
      82: astore        11
      84: aload         11
      86: ifnonnull     97
      89: iload         9
      91: invokestatic  #75                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      94: goto          108
      97: iload         9
      99: iload_1
     100: aload         11
     102: invokestatic  #77                 // Method calculateRotatedChar:(CILEncodingBounds;)C
     105: invokestatic  #75                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     108: nop
     109: aload         12
     111: swap
     112: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     117: pop
     118: iinc          7, 1
     121: goto          43
     124: aload         5
     126: checkcast     #83                 // class java/util/List
     129: nop
     130: checkcast     #85                 // class java/lang/Iterable
     133: astore_2
     134: nop
     135: iconst_0
     136: istore_3
     137: aload_2
     138: invokeinterface #89,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     143: astore        4
     145: aload         4
     147: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     152: ifne          165
     155: new           #97                 // class java/lang/UnsupportedOperationException
     158: dup
     159: ldc           #99                 // String Empty collection can\'t be reduced.
     161: invokespecial #102                // Method java/lang/UnsupportedOperationException."<init>":(Ljava/lang/String;)V
     164: athrow
     165: aload         4
     167: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     172: astore        5
     174: aload         4
     176: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     181: ifeq          231
     184: aload         5
     186: aload         4
     188: invokeinterface #106,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     193: checkcast     #55                 // class java/lang/String
     196: astore        6
     198: checkcast     #55                 // class java/lang/String
     201: astore        7
     203: iconst_0
     204: istore        8
     206: new           #108                // class java/lang/StringBuilder
     209: dup
     210: invokespecial #111                // Method java/lang/StringBuilder."<init>":()V
     213: aload         7
     215: invokevirtual #115                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     218: aload         6
     220: invokevirtual #115                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     223: invokevirtual #119                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     226: astore        5
     228: goto          174
     231: aload         5
     233: checkcast     #55                 // class java/lang/String
     236: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #45                 // String args
       3: invokestatic  #29                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokestatic  #142                // Method parseInput:([Ljava/lang/String;)Ljava/lang/String;
      10: astore_1
      11: aload_1
      12: ifnonnull     27
      15: ldc           #144                // String Usage: please provide a string to encrypt
      17: getstatic     #150                // Field java/lang/System.out:Ljava/io/PrintStream;
      20: swap
      21: invokevirtual #156                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      24: goto          38
      27: aload_1
      28: invokestatic  #158                // Method rot13Encode:(Ljava/lang/String;)Ljava/lang/String;
      31: getstatic     #150                // Field java/lang/System.out:Ljava/io/PrintStream;
      34: swap
      35: invokevirtual #156                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      38: return
}