package dk.aoc.day13

import java.io.File
import java.util.*

val LAYER_PATTERN = Regex("""(\d+): (\d+)""")

fun main(args: Array<String>) {
    val inputFile = File("src/main/resources/inputs/day13.txt")
    val lines = inputFile.readLines()
    val layers = parseLayers(lines)
    val severity = calculateSeverity(layers)
    println(severity)
}

fun parseLayers(lines: List<String>): SortedMap<Int, Int> {
    val res = TreeMap<Int, Int>()
    lines.forEach {
        val result = LAYER_PATTERN.find(it)
        if (result != null) {
            res.put(result.groupValues[1].toInt(), result.groupValues[2].toInt())
        }
    }
    return res
}

fun calculateSeverity(layers : SortedMap<Int, Int>) =
    layers.entries.sumBy {
        layerSeverity(it.key, it.value)
    }

fun layerSeverity(depth : Int, range : Int) =
        if (isCaught(depth, range))
            depth * range
        else
            0

fun isCaught(depth: Int, range: Int) : Boolean {
    val periodocity = (range - 1) * 2;
    return range == 1 || depth % periodocity == 0
}

Compiled from "day13.kt"
public final class dk.aoc.day13.Day13Kt {
  private static final kotlin.text.Regex LAYER_PATTERN;

  public static final kotlin.text.Regex getLAYER_PATTERN();
    Code:
       0: getstatic     #11                 // Field LAYER_PATTERN:Lkotlin/text/Regex;
       3: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #15                 // String args
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class java/io/File
       9: dup
      10: ldc           #25                 // String src/main/resources/inputs/day13.txt
      12: invokespecial #29                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: astore_1
      16: aload_1
      17: aconst_null
      18: iconst_1
      19: aconst_null
      20: invokestatic  #35                 // Method kotlin/io/FilesKt.readLines$default:(Ljava/io/File;Ljava/nio/charset/Charset;ILjava/lang/Object;)Ljava/util/List;
      23: astore_2
      24: aload_2
      25: invokestatic  #39                 // Method parseLayers:(Ljava/util/List;)Ljava/util/SortedMap;
      28: astore_3
      29: aload_3
      30: invokestatic  #43                 // Method calculateSeverity:(Ljava/util/SortedMap;)I
      33: istore        4
      35: getstatic     #49                 // Field java/lang/System.out:Ljava/io/PrintStream;
      38: iload         4
      40: invokevirtual #55                 // Method java/io/PrintStream.println:(I)V
      43: return

  public static final java.util.SortedMap<java.lang.Integer, java.lang.Integer> parseLayers(java.util.List<java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #66                 // String lines
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #68                 // class java/util/TreeMap
       9: dup
      10: invokespecial #71                 // Method java/util/TreeMap."<init>":()V
      13: astore_1
      14: aload_0
      15: checkcast     #73                 // class java/lang/Iterable
      18: astore_2
      19: iconst_0
      20: istore_3
      21: aload_2
      22: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      27: astore        4
      29: aload         4
      31: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      36: ifeq          133
      39: aload         4
      41: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      46: astore        5
      48: aload         5
      50: checkcast     #89                 // class java/lang/String
      53: astore        6
      55: iconst_0
      56: istore        7
      58: getstatic     #11                 // Field LAYER_PATTERN:Lkotlin/text/Regex;
      61: aload         6
      63: checkcast     #91                 // class java/lang/CharSequence
      66: iconst_0
      67: iconst_2
      68: aconst_null
      69: invokestatic  #97                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      72: astore        8
      74: aload         8
      76: ifnull        128
      79: aload_1
      80: aload         8
      82: invokeinterface #103,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
      87: iconst_1
      88: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      93: checkcast     #89                 // class java/lang/String
      96: invokestatic  #115                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      99: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     102: aload         8
     104: invokeinterface #103,  1          // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     109: iconst_2
     110: invokeinterface #109,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     115: checkcast     #89                 // class java/lang/String
     118: invokestatic  #115                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     121: invokestatic  #119                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     124: invokevirtual #123                // Method java/util/TreeMap.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     127: pop
     128: nop
     129: nop
     130: goto          29
     133: nop
     134: aload_1
     135: checkcast     #125                // class java/util/SortedMap
     138: areturn

  public static final int calculateSeverity(java.util.SortedMap<java.lang.Integer, java.lang.Integer>);
    Code:
       0: aload_0
       1: ldc           #139                // String layers
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokeinterface #143,  1          // InterfaceMethod java/util/SortedMap.entrySet:()Ljava/util/Set;
      12: dup
      13: ldc           #145                // String <get-entries>(...)
      15: invokestatic  #148                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      18: checkcast     #73                 // class java/lang/Iterable
      21: astore_1
      22: iconst_0
      23: istore_2
      24: iconst_0
      25: istore_3
      26: aload_1
      27: invokeinterface #77,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      32: astore        4
      34: aload         4
      36: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      41: ifeq          118
      44: aload         4
      46: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      51: astore        5
      53: iload_3
      54: aload         5
      56: checkcast     #150                // class java/util/Map$Entry
      59: astore        6
      61: istore        8
      63: iconst_0
      64: istore        7
      66: aload         6
      68: invokeinterface #153,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
      73: dup
      74: ldc           #155                // String <get-key>(...)
      76: invokestatic  #148                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      79: checkcast     #157                // class java/lang/Number
      82: invokevirtual #161                // Method java/lang/Number.intValue:()I
      85: aload         6
      87: invokeinterface #164,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
      92: dup
      93: ldc           #166                // String <get-value>(...)
      95: invokestatic  #148                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      98: checkcast     #157                // class java/lang/Number
     101: invokevirtual #161                // Method java/lang/Number.intValue:()I
     104: invokestatic  #170                // Method layerSeverity:(II)I
     107: istore        9
     109: iload         8
     111: iload         9
     113: iadd
     114: istore_3
     115: goto          34
     118: iload_3
     119: ireturn

  public static final int layerSeverity(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: invokestatic  #179                // Method isCaught:(II)Z
       5: ifeq          14
       8: iload_0
       9: iload_1
      10: imul
      11: goto          15
      14: iconst_0
      15: ireturn

  public static final boolean isCaught(int, int);
    Code:
       0: iload_1
       1: iconst_1
       2: isub
       3: iconst_2
       4: imul
       5: istore_2
       6: iload_1
       7: iconst_1
       8: if_icmpeq     17
      11: iload_0
      12: iload_2
      13: irem
      14: ifne          21
      17: iconst_1
      18: goto          22
      21: iconst_0
      22: ireturn

  static {};
    Code:
       0: new           #93                 // class kotlin/text/Regex
       3: dup
       4: ldc           #185                // String (\\d+): (\\d+)
       6: invokespecial #186                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
       9: putstatic     #11                 // Field LAYER_PATTERN:Lkotlin/text/Regex;
      12: return
}


package codeforces.round573

// https://codeforces.com/contest/1191/problem/B
fun main(args: Array<String>) {
    val listM = arrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0)
    val listP = arrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0)
    val listS = arrayOf(0, 0, 0, 0, 0, 0, 0, 0, 0)

    val input = readLine()!!.split(" ").map {
        Card(it[0].toString().toInt(), it[1].toString())
    }

    input.forEach {
        when(it.type) {
            "m" -> listM[it.number-1]++
            "p" -> listP[it.number-1]++
            "s" -> listS[it.number-1]++
        }
    }

    val koutsuM = listM.max()!!
    val shuntsuM = shuntsu(listM)

    if (koutsuM >= 3 || shuntsuM >= 3) {
        println("0")
        return
    }

    val koutsuP = listP.max()!!
    val shuntsuP = shuntsu(listP)
    if (koutsuP >= 3 || shuntsuP >= 3) {
        println("0")
        return
    }

    val koutsuS = listS.max()!!
    val shuntsuS = shuntsu(listS)
    if (koutsuS >= 3 || shuntsuS >= 3) {
        println("0")
        return
    }

    if (koutsuM >= 2 || shuntsuM >= 2 ||
            koutsuS >= 2 || shuntsuS >= 2 ||
            koutsuP >= 2 || shuntsuP >= 2) {
        println("1")
        return
    }

    println("2")
}

// return the number of subsequence > 0
fun shuntsu(list: Array<Int>): Int {
    val seq = ArrayList<Triple<Int, Int, Int>>()
    for (i in 0 until 7) {
        seq.add(Triple(list[i], list[i+1], list[i+2]))
    }
    var one = 0
    var two = 0
    for (triple in seq) {
        if (triple.first > 0 && triple.second > 0 && triple.third > 0) {
            return 3
        } else if (triple.first > 0 && triple.second > 0) {
            two++
        } else if (triple.first > 0 && triple.third > 0) {
            two++
        } else if (triple.second > 0 && triple.third > 0) {
            two++
        } else if (triple.first > 0 || triple.second > 0 || triple.third > 0) {
            one++
        }
    }
    if (two > 0) return 2
    if (one > 0) return 1
    return 0
}

class Card(val number: Int, val type: String)

Compiled from "TokitsukazeMadjong.kt"
public final class codeforces.round573.TokitsukazeMadjongKt {
  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: bipush        9
       8: anewarray     #17                 // class java/lang/Integer
      11: astore_2
      12: aload_2
      13: iconst_0
      14: iconst_0
      15: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      18: aastore
      19: aload_2
      20: iconst_1
      21: iconst_0
      22: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      25: aastore
      26: aload_2
      27: iconst_2
      28: iconst_0
      29: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      32: aastore
      33: aload_2
      34: iconst_3
      35: iconst_0
      36: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      39: aastore
      40: aload_2
      41: iconst_4
      42: iconst_0
      43: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      46: aastore
      47: aload_2
      48: iconst_5
      49: iconst_0
      50: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      53: aastore
      54: aload_2
      55: bipush        6
      57: iconst_0
      58: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      61: aastore
      62: aload_2
      63: bipush        7
      65: iconst_0
      66: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      69: aastore
      70: aload_2
      71: bipush        8
      73: iconst_0
      74: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: aastore
      78: aload_2
      79: astore_1
      80: bipush        9
      82: anewarray     #17                 // class java/lang/Integer
      85: astore_3
      86: aload_3
      87: iconst_0
      88: iconst_0
      89: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      92: aastore
      93: aload_3
      94: iconst_1
      95: iconst_0
      96: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      99: aastore
     100: aload_3
     101: iconst_2
     102: iconst_0
     103: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aastore
     107: aload_3
     108: iconst_3
     109: iconst_0
     110: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     113: aastore
     114: aload_3
     115: iconst_4
     116: iconst_0
     117: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: aastore
     121: aload_3
     122: iconst_5
     123: iconst_0
     124: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     127: aastore
     128: aload_3
     129: bipush        6
     131: iconst_0
     132: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     135: aastore
     136: aload_3
     137: bipush        7
     139: iconst_0
     140: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: aastore
     144: aload_3
     145: bipush        8
     147: iconst_0
     148: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     151: aastore
     152: aload_3
     153: astore_2
     154: bipush        9
     156: anewarray     #17                 // class java/lang/Integer
     159: astore        4
     161: aload         4
     163: iconst_0
     164: iconst_0
     165: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     168: aastore
     169: aload         4
     171: iconst_1
     172: iconst_0
     173: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     176: aastore
     177: aload         4
     179: iconst_2
     180: iconst_0
     181: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     184: aastore
     185: aload         4
     187: iconst_3
     188: iconst_0
     189: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     192: aastore
     193: aload         4
     195: iconst_4
     196: iconst_0
     197: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     200: aastore
     201: aload         4
     203: iconst_5
     204: iconst_0
     205: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     208: aastore
     209: aload         4
     211: bipush        6
     213: iconst_0
     214: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     217: aastore
     218: aload         4
     220: bipush        7
     222: iconst_0
     223: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     226: aastore
     227: aload         4
     229: bipush        8
     231: iconst_0
     232: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     235: aastore
     236: aload         4
     238: astore_3
     239: invokestatic  #27                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     242: dup
     243: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     246: checkcast     #33                 // class java/lang/CharSequence
     249: iconst_1
     250: anewarray     #35                 // class java/lang/String
     253: astore        5
     255: aload         5
     257: iconst_0
     258: ldc           #37                 // String
     260: aastore
     261: aload         5
     263: iconst_0
     264: iconst_0
     265: bipush        6
     267: aconst_null
     268: invokestatic  #43                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     271: checkcast     #45                 // class java/lang/Iterable
     274: astore        5
     276: iconst_0
     277: istore        6
     279: aload         5
     281: astore        7
     283: new           #47                 // class java/util/ArrayList
     286: dup
     287: aload         5
     289: bipush        10
     291: invokestatic  #53                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     294: invokespecial #57                 // Method java/util/ArrayList."<init>":(I)V
     297: checkcast     #59                 // class java/util/Collection
     300: astore        8
     302: iconst_0
     303: istore        9
     305: aload         7
     307: invokeinterface #63,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     312: astore        10
     314: aload         10
     316: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     321: ifeq          387
     324: aload         10
     326: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     331: astore        11
     333: aload         8
     335: aload         11
     337: checkcast     #35                 // class java/lang/String
     340: astore        12
     342: astore        14
     344: iconst_0
     345: istore        13
     347: new           #75                 // class codeforces/round573/Card
     350: dup
     351: aload         12
     353: iconst_0
     354: invokevirtual #79                 // Method java/lang/String.charAt:(I)C
     357: invokestatic  #82                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     360: invokestatic  #86                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     363: aload         12
     365: iconst_1
     366: invokevirtual #79                 // Method java/lang/String.charAt:(I)C
     369: invokestatic  #82                 // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     372: invokespecial #89                 // Method codeforces/round573/Card."<init>":(ILjava/lang/String;)V
     375: aload         14
     377: swap
     378: invokeinterface #93,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     383: pop
     384: goto          314
     387: aload         8
     389: checkcast     #95                 // class java/util/List
     392: nop
     393: astore        4
     395: aload         4
     397: checkcast     #45                 // class java/lang/Iterable
     400: astore        5
     402: iconst_0
     403: istore        6
     405: aload         5
     407: invokeinterface #63,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     412: astore        7
     414: aload         7
     416: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     421: ifeq          622
     424: aload         7
     426: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     431: astore        8
     433: aload         8
     435: checkcast     #75                 // class codeforces/round573/Card
     438: astore        9
     440: iconst_0
     441: istore        10
     443: aload         9
     445: invokevirtual #98                 // Method codeforces/round573/Card.getType:()Ljava/lang/String;
     448: astore        11
     450: aload         11
     452: invokevirtual #102                // Method java/lang/String.hashCode:()I
     455: lookupswitch  { // 3
                   109: 514
                   112: 488
                   115: 501
               default: 617
          }
     488: aload         11
     490: ldc           #104                // String p
     492: invokevirtual #107                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     495: ifne          556
     498: goto          617
     501: aload         11
     503: ldc           #109                // String s
     505: invokevirtual #107                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     508: ifne          588
     511: goto          617
     514: aload         11
     516: ldc           #111                // String m
     518: invokevirtual #107                // Method java/lang/String.equals:(Ljava/lang/Object;)Z
     521: ifeq          617
     524: aload         9
     526: invokevirtual #114                // Method codeforces/round573/Card.getNumber:()I
     529: iconst_1
     530: isub
     531: istore        12
     533: aload_1
     534: iload         12
     536: aaload
     537: invokevirtual #117                // Method java/lang/Integer.intValue:()I
     540: istore        13
     542: aload_1
     543: iload         12
     545: iload         13
     547: iconst_1
     548: iadd
     549: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     552: aastore
     553: goto          617
     556: aload         9
     558: invokevirtual #114                // Method codeforces/round573/Card.getNumber:()I
     561: iconst_1
     562: isub
     563: istore        12
     565: aload_2
     566: iload         12
     568: aaload
     569: invokevirtual #117                // Method java/lang/Integer.intValue:()I
     572: istore        13
     574: aload_2
     575: iload         12
     577: iload         13
     579: iconst_1
     580: iadd
     581: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     584: aastore
     585: goto          617
     588: aload         9
     590: invokevirtual #114                // Method codeforces/round573/Card.getNumber:()I
     593: iconst_1
     594: isub
     595: istore        12
     597: aload_3
     598: iload         12
     600: aaload
     601: invokevirtual #117                // Method java/lang/Integer.intValue:()I
     604: istore        13
     606: aload_3
     607: iload         12
     609: iload         13
     611: iconst_1
     612: iadd
     613: invokestatic  #21                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     616: aastore
     617: nop
     618: nop
     619: goto          414
     622: nop
     623: aload_1
     624: checkcast     #119                // class "[Ljava/lang/Comparable;"
     627: invokestatic  #125                // Method kotlin/collections/ArraysKt.maxOrThrow:([Ljava/lang/Comparable;)Ljava/lang/Comparable;
     630: dup
     631: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     634: checkcast     #127                // class java/lang/Number
     637: invokevirtual #128                // Method java/lang/Number.intValue:()I
     640: istore        5
     642: aload_1
     643: invokestatic  #132                // Method shuntsu:([Ljava/lang/Integer;)I
     646: istore        6
     648: iload         5
     650: iconst_3
     651: if_icmpge     660
     654: iload         6
     656: iconst_3
     657: if_icmplt     670
     660: ldc           #134                // String 0
     662: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     665: swap
     666: invokevirtual #145                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     669: return
     670: aload_2
     671: checkcast     #119                // class "[Ljava/lang/Comparable;"
     674: invokestatic  #125                // Method kotlin/collections/ArraysKt.maxOrThrow:([Ljava/lang/Comparable;)Ljava/lang/Comparable;
     677: dup
     678: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     681: checkcast     #127                // class java/lang/Number
     684: invokevirtual #128                // Method java/lang/Number.intValue:()I
     687: istore        7
     689: aload_2
     690: invokestatic  #132                // Method shuntsu:([Ljava/lang/Integer;)I
     693: istore        8
     695: iload         7
     697: iconst_3
     698: if_icmpge     707
     701: iload         8
     703: iconst_3
     704: if_icmplt     717
     707: ldc           #134                // String 0
     709: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     712: swap
     713: invokevirtual #145                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     716: return
     717: aload_3
     718: checkcast     #119                // class "[Ljava/lang/Comparable;"
     721: invokestatic  #125                // Method kotlin/collections/ArraysKt.maxOrThrow:([Ljava/lang/Comparable;)Ljava/lang/Comparable;
     724: dup
     725: invokestatic  #31                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     728: checkcast     #127                // class java/lang/Number
     731: invokevirtual #128                // Method java/lang/Number.intValue:()I
     734: istore        9
     736: aload_3
     737: invokestatic  #132                // Method shuntsu:([Ljava/lang/Integer;)I
     740: istore        10
     742: iload         9
     744: iconst_3
     745: if_icmpge     754
     748: iload         10
     750: iconst_3
     751: if_icmplt     764
     754: ldc           #134                // String 0
     756: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     759: swap
     760: invokevirtual #145                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     763: return
     764: iload         5
     766: iconst_2
     767: if_icmpge     800
     770: iload         6
     772: iconst_2
     773: if_icmpge     800
     776: iload         9
     778: iconst_2
     779: if_icmpge     800
     782: iload         10
     784: iconst_2
     785: if_icmpge     800
     788: iload         7
     790: iconst_2
     791: if_icmpge     800
     794: iload         8
     796: iconst_2
     797: if_icmplt     810
     800: ldc           #147                // String 1
     802: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     805: swap
     806: invokevirtual #145                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     809: return
     810: ldc           #149                // String 2
     812: getstatic     #140                // Field java/lang/System.out:Ljava/io/PrintStream;
     815: swap
     816: invokevirtual #145                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     819: return

  public static final int shuntsu(java.lang.Integer[]);
    Code:
       0: aload_0
       1: ldc           #184                // String list
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #47                 // class java/util/ArrayList
       9: dup
      10: invokespecial #187                // Method java/util/ArrayList."<init>":()V
      13: astore_1
      14: iconst_0
      15: istore_2
      16: iload_2
      17: bipush        7
      19: if_icmpge     53
      22: aload_1
      23: new           #189                // class kotlin/Triple
      26: dup
      27: aload_0
      28: iload_2
      29: aaload
      30: aload_0
      31: iload_2
      32: iconst_1
      33: iadd
      34: aaload
      35: aload_0
      36: iload_2
      37: iconst_2
      38: iadd
      39: aaload
      40: invokespecial #192                // Method kotlin/Triple."<init>":(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
      43: invokevirtual #193                // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
      46: pop
      47: iinc          2, 1
      50: goto          16
      53: iconst_0
      54: istore_2
      55: iconst_0
      56: istore_3
      57: aload_1
      58: invokevirtual #194                // Method java/util/ArrayList.iterator:()Ljava/util/Iterator;
      61: dup
      62: ldc           #196                // String iterator(...)
      64: invokestatic  #199                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      67: astore        4
      69: aload         4
      71: invokeinterface #69,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          291
      79: aload         4
      81: invokeinterface #73,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: dup
      87: ldc           #201                // String next(...)
      89: invokestatic  #199                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      92: checkcast     #189                // class kotlin/Triple
      95: astore        5
      97: aload         5
      99: invokevirtual #204                // Method kotlin/Triple.getFirst:()Ljava/lang/Object;
     102: checkcast     #127                // class java/lang/Number
     105: invokevirtual #128                // Method java/lang/Number.intValue:()I
     108: ifle          141
     111: aload         5
     113: invokevirtual #207                // Method kotlin/Triple.getSecond:()Ljava/lang/Object;
     116: checkcast     #127                // class java/lang/Number
     119: invokevirtual #128                // Method java/lang/Number.intValue:()I
     122: ifle          141
     125: aload         5
     127: invokevirtual #210                // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     130: checkcast     #127                // class java/lang/Number
     133: invokevirtual #128                // Method java/lang/Number.intValue:()I
     136: ifle          141
     139: iconst_3
     140: ireturn
     141: aload         5
     143: invokevirtual #204                // Method kotlin/Triple.getFirst:()Ljava/lang/Object;
     146: checkcast     #127                // class java/lang/Number
     149: invokevirtual #128                // Method java/lang/Number.intValue:()I
     152: ifle          175
     155: aload         5
     157: invokevirtual #207                // Method kotlin/Triple.getSecond:()Ljava/lang/Object;
     160: checkcast     #127                // class java/lang/Number
     163: invokevirtual #128                // Method java/lang/Number.intValue:()I
     166: ifle          175
     169: iinc          3, 1
     172: goto          69
     175: aload         5
     177: invokevirtual #204                // Method kotlin/Triple.getFirst:()Ljava/lang/Object;
     180: checkcast     #127                // class java/lang/Number
     183: invokevirtual #128                // Method java/lang/Number.intValue:()I
     186: ifle          209
     189: aload         5
     191: invokevirtual #210                // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     194: checkcast     #127                // class java/lang/Number
     197: invokevirtual #128                // Method java/lang/Number.intValue:()I
     200: ifle          209
     203: iinc          3, 1
     206: goto          69
     209: aload         5
     211: invokevirtual #207                // Method kotlin/Triple.getSecond:()Ljava/lang/Object;
     214: checkcast     #127                // class java/lang/Number
     217: invokevirtual #128                // Method java/lang/Number.intValue:()I
     220: ifle          243
     223: aload         5
     225: invokevirtual #210                // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     228: checkcast     #127                // class java/lang/Number
     231: invokevirtual #128                // Method java/lang/Number.intValue:()I
     234: ifle          243
     237: iinc          3, 1
     240: goto          69
     243: aload         5
     245: invokevirtual #204                // Method kotlin/Triple.getFirst:()Ljava/lang/Object;
     248: checkcast     #127                // class java/lang/Number
     251: invokevirtual #128                // Method java/lang/Number.intValue:()I
     254: ifgt          285
     257: aload         5
     259: invokevirtual #207                // Method kotlin/Triple.getSecond:()Ljava/lang/Object;
     262: checkcast     #127                // class java/lang/Number
     265: invokevirtual #128                // Method java/lang/Number.intValue:()I
     268: ifgt          285
     271: aload         5
     273: invokevirtual #210                // Method kotlin/Triple.getThird:()Ljava/lang/Object;
     276: checkcast     #127                // class java/lang/Number
     279: invokevirtual #128                // Method java/lang/Number.intValue:()I
     282: ifle          69
     285: iinc          2, 1
     288: goto          69
     291: iload_3
     292: ifle          297
     295: iconst_2
     296: ireturn
     297: iload_2
     298: ifle          303
     301: iconst_1
     302: ireturn
     303: iconst_0
     304: ireturn
}


package codeforces.eduround68

import java.io.PrintWriter
import kotlin.math.min

// https://codeforces.com/contest/1194/problem/B
// this is mine
//fun eduround68.eduround68.eduround68.round567.round567.round573.codeforces.codeforces.codeforces.eduround69.kotlinheroes.kotlinheroes.main(args: Array<String>) {
//    val q = eduround68.readInt()
//    val matrices = mutableListOf<Matrix>()
//    for (i in 0 until q) {
//        val (n, m) = eduround68.readInts()
//        val matrix = Matrix(n, m)
//        for (j in 0 until n) {
//            matrix.fillRow(j, readLine()!!)
//        }
//        matrices.add(matrix)
//    }
//    matrices.forEach {
//        println("${it.findMinMinutesForCrosses()}")
//    }
//}
//
//class Matrix(val n: Int, val m: Int) {
//
//    private val body = Array(n) {
//        IntArray(m)
//    }
//
//    private val tbody = Array(m) {
//        IntArray(n)
//    }
//
//    fun fillRow(row: Int, symbols: String) {
//        val r = body[row]
//        symbols.forEachIndexed { index, c ->
//            r[index] = if (c == '*') 1 else 0
//            tbody[index][row] = if (c == '*') 1 else 0
//        }
//    }
//
//    fun findMinMinutesForCrosses(): Int {
//        var minSum = Int.MAX_VALUE
//        for (i in 0 until n) {
//            val rowSum = m - body[i].sum()
//            for (j in 0 until m) {
//                val colSum = n - tbody[j].sum()
//                val sub = 1 - body[i][j]
//                val sum = rowSum + colSum - sub
//                if (sum < minSum) {
//                    minSum = sum
//                }
//            }
//        }
//        return minSum
//    }
//}

// this is elizarov's
fun main() {
    val q = readInt()
    bufferOut {
        repeat(q) { solveQuery() }
    }
}

private fun PrintWriter.solveQuery() {
    val (n, m) = readInts()
    val a = Array(n) { readLine()!!.map { it == '*' }.toBooleanArray() }
    val rowSums = IntArray(n)
    val colSums = IntArray(m)
    for (i in 0 until n) {
        for(j in 0 until m) {
            if (a[i][j]) {
                rowSums[i]++
                colSums[j]++
            }
        }
    }
    if (rowSums.any { it == m } && colSums.any { it == n }) {
        println(0)
        return
    }
    var ans = Int.MAX_VALUE
    for (i in 0 until n) {
        for(j in 0 until m) {
            var d = n + m - rowSums[i] - colSums[j]
            if (!a[i][j]) d--
            ans = min(ans, d)
        }
    }
    println(ans)
}

private fun readInt() = readLine()!!.toInt()

private fun readInts() = readLine()!!.split(" ").map(String::toInt)

// for the future
private fun bufferOut(block: PrintWriter.() -> Unit) = PrintWriter(System.out).use { block(it) }

Compiled from "YetAnotherCrossesProblem.kt"
public final class codeforces.eduround68.YetAnotherCrossesProblemKt {
  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInt:()I
       3: istore_0
       4: iload_0
       5: invokedynamic #30,  0             // InvokeDynamic #0:invoke:(I)Lkotlin/jvm/functions/Function1;
      10: invokestatic  #34                 // Method bufferOut:(Lkotlin/jvm/functions/Function1;)V
      13: return

  private static final void solveQuery(java.io.PrintWriter);
    Code:
       0: invokestatic  #42                 // Method readInts:()Ljava/util/List;
       3: astore_1
       4: aload_1
       5: iconst_0
       6: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      11: checkcast     #50                 // class java/lang/Number
      14: invokevirtual #53                 // Method java/lang/Number.intValue:()I
      17: istore_2
      18: aload_1
      19: iconst_1
      20: invokeinterface #48,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      25: checkcast     #50                 // class java/lang/Number
      28: invokevirtual #53                 // Method java/lang/Number.intValue:()I
      31: istore_3
      32: iconst_0
      33: istore        5
      35: iload_2
      36: anewarray     #55                 // class "[Z"
      39: astore        6
      41: iload         5
      43: iload_2
      44: if_icmpge     194
      47: iload         5
      49: istore        7
      51: aload         6
      53: iload         7
      55: invokestatic  #61                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      58: dup
      59: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      62: checkcast     #69                 // class java/lang/CharSequence
      65: astore        8
      67: istore        18
      69: astore        17
      71: iconst_0
      72: istore        9
      74: aload         8
      76: astore        10
      78: new           #71                 // class java/util/ArrayList
      81: dup
      82: aload         8
      84: invokeinterface #74,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      89: invokespecial #78                 // Method java/util/ArrayList."<init>":(I)V
      92: checkcast     #80                 // class java/util/Collection
      95: astore        11
      97: iconst_0
      98: istore        12
     100: iconst_0
     101: istore        13
     103: iload         13
     105: aload         10
     107: invokeinterface #74,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     112: if_icmpge     167
     115: aload         10
     117: iload         13
     119: invokeinterface #84,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     124: istore        14
     126: aload         11
     128: iload         14
     130: istore        15
     132: astore        19
     134: iconst_0
     135: istore        16
     137: iload         15
     139: bipush        42
     141: if_icmpne     148
     144: iconst_1
     145: goto          149
     148: iconst_0
     149: invokestatic  #90                 // Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
     152: aload         19
     154: swap
     155: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     160: pop
     161: iinc          13, 1
     164: goto          103
     167: aload         11
     169: checkcast     #44                 // class java/util/List
     172: nop
     173: astore        19
     175: aload         17
     177: iload         18
     179: aload         19
     181: checkcast     #80                 // class java/util/Collection
     184: invokestatic  #100                // Method kotlin/collections/CollectionsKt.toBooleanArray:(Ljava/util/Collection;)[Z
     187: aastore
     188: iinc          5, 1
     191: goto          41
     194: aload         6
     196: astore        4
     198: iload_2
     199: newarray       int
     201: astore        5
     203: iload_3
     204: newarray       int
     206: astore        6
     208: iconst_0
     209: istore        7
     211: iload         7
     213: iload_2
     214: if_icmpge     289
     217: iconst_0
     218: istore        8
     220: iload         8
     222: iload_3
     223: if_icmpge     283
     226: aload         4
     228: iload         7
     230: aaload
     231: iload         8
     233: baload
     234: ifeq          277
     237: iload         7
     239: istore        9
     241: aload         5
     243: iload         9
     245: iaload
     246: istore        10
     248: aload         5
     250: iload         9
     252: iload         10
     254: iconst_1
     255: iadd
     256: iastore
     257: iload         8
     259: istore        11
     261: aload         6
     263: iload         11
     265: iaload
     266: istore        12
     268: aload         6
     270: iload         11
     272: iload         12
     274: iconst_1
     275: iadd
     276: iastore
     277: iinc          8, 1
     280: goto          220
     283: iinc          7, 1
     286: goto          211
     289: aload         5
     291: astore        7
     293: iconst_0
     294: istore        8
     296: iconst_0
     297: istore        9
     299: aload         7
     301: arraylength
     302: istore        10
     304: iload         9
     306: iload         10
     308: if_icmpge     349
     311: aload         7
     313: iload         9
     315: iaload
     316: istore        11
     318: iload         11
     320: istore        12
     322: iconst_0
     323: istore        13
     325: iload         12
     327: iload_3
     328: if_icmpne     335
     331: iconst_1
     332: goto          336
     335: iconst_0
     336: ifeq          343
     339: iconst_1
     340: goto          350
     343: iinc          9, 1
     346: goto          304
     349: iconst_0
     350: ifeq          423
     353: aload         6
     355: astore        7
     357: iconst_0
     358: istore        8
     360: iconst_0
     361: istore        9
     363: aload         7
     365: arraylength
     366: istore        10
     368: iload         9
     370: iload         10
     372: if_icmpge     413
     375: aload         7
     377: iload         9
     379: iaload
     380: istore        11
     382: iload         11
     384: istore        12
     386: iconst_0
     387: istore        13
     389: iload         12
     391: iload_2
     392: if_icmpne     399
     395: iconst_1
     396: goto          400
     399: iconst_0
     400: ifeq          407
     403: iconst_1
     404: goto          414
     407: iinc          9, 1
     410: goto          368
     413: iconst_0
     414: ifeq          423
     417: aload_0
     418: iconst_0
     419: invokevirtual #105                // Method java/io/PrintWriter.println:(I)V
     422: return
     423: ldc           #106                // int 2147483647
     425: istore        7
     427: iconst_0
     428: istore        8
     430: iload         8
     432: iload_2
     433: if_icmpge     497
     436: iconst_0
     437: istore        9
     439: iload         9
     441: iload_3
     442: if_icmpge     491
     445: iload_2
     446: iload_3
     447: iadd
     448: aload         5
     450: iload         8
     452: iaload
     453: isub
     454: aload         6
     456: iload         9
     458: iaload
     459: isub
     460: istore        10
     462: aload         4
     464: iload         8
     466: aaload
     467: iload         9
     469: baload
     470: ifne          476
     473: iinc          10, -1
     476: iload         7
     478: iload         10
     480: invokestatic  #112                // Method java/lang/Math.min:(II)I
     483: istore        7
     485: iinc          9, 1
     488: goto          439
     491: iinc          8, 1
     494: goto          430
     497: aload_0
     498: iload         7
     500: invokevirtual #105                // Method java/io/PrintWriter.println:(I)V
     503: return

  private static final int readInt();
    Code:
       0: invokestatic  #61                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      10: ireturn

  private static final java.util.List<java.lang.Integer> readInts();
    Code:
       0: invokestatic  #61                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #67                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #69                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #152                // class java/lang/String
      14: astore_0
      15: aload_0
      16: iconst_0
      17: ldc           #154                // String
      19: aastore
      20: aload_0
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #160                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #162                // class java/lang/Iterable
      32: astore_0
      33: iconst_0
      34: istore_1
      35: aload_0
      36: astore_2
      37: new           #71                 // class java/util/ArrayList
      40: dup
      41: aload_0
      42: bipush        10
      44: invokestatic  #166                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #78                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #80                 // class java/util/Collection
      53: astore_3
      54: iconst_0
      55: istore        4
      57: aload_2
      58: invokeinterface #170,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        5
      65: aload         5
      67: invokeinterface #176,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          118
      75: aload         5
      77: invokeinterface #180,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        6
      84: aload_3
      85: aload         6
      87: checkcast     #152                // class java/lang/String
      90: astore        7
      92: astore        9
      94: iconst_0
      95: istore        8
      97: aload         7
      99: invokestatic  #149                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     102: nop
     103: invokestatic  #183                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aload         9
     108: swap
     109: invokeinterface #94,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          65
     118: aload_3
     119: checkcast     #44                 // class java/util/List
     122: nop
     123: areturn

  private static final void bufferOut(kotlin.jvm.functions.Function1<? super java.io.PrintWriter, kotlin.Unit>);
    Code:
       0: new           #102                // class java/io/PrintWriter
       3: dup
       4: getstatic     #197                // Field java/lang/System.out:Ljava/io/PrintStream;
       7: checkcast     #199                // class java/io/OutputStream
      10: invokespecial #202                // Method java/io/PrintWriter."<init>":(Ljava/io/OutputStream;)V
      13: checkcast     #204                // class java/io/Closeable
      16: astore_1
      17: aconst_null
      18: astore_2
      19: nop
      20: aload_1
      21: checkcast     #102                // class java/io/PrintWriter
      24: astore_3
      25: iconst_0
      26: istore        4
      28: aload_0
      29: aload_3
      30: invokeinterface #208,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
      35: pop
      36: getstatic     #214                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      39: astore_3
      40: aload_1
      41: aload_2
      42: invokestatic  #220                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
      45: goto          66
      48: astore        4
      50: aload         4
      52: astore_2
      53: aload         4
      55: athrow
      56: astore        4
      58: aload_1
      59: aload_2
      60: invokestatic  #220                // Method kotlin/io/CloseableKt.closeFinally:(Ljava/io/Closeable;Ljava/lang/Throwable;)V
      63: aload         4
      65: athrow
      66: return
    Exception table:
       from    to  target type
          19    40    48   Class java/lang/Throwable
          19    40    56   any
          48    56    56   any
          56    58    56   any

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

  private static final kotlin.Unit main$lambda$1(int, java.io.PrintWriter);
    Code:
       0: aload_1
       1: ldc           #230                // String $this$bufferOut
       3: invokestatic  #234                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: istore_2
       8: iload_2
       9: iload_0
      10: if_icmpge     28
      13: iload_2
      14: istore_3
      15: iconst_0
      16: istore        4
      18: aload_1
      19: invokestatic  #236                // Method solveQuery:(Ljava/io/PrintWriter;)V
      22: iinc          2, 1
      25: goto          8
      28: getstatic     #214                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      31: areturn
}


package stepik.sportprogramming

import java.io.File

fun main() {
    val rooms = IntArray(33000) { 0 }
    val applications = readFromFile()
    println("Max of applications is ${count(rooms, applications)}")
}

private fun readFromFile(): MutableList<AudienceApplication> {
    val applications = mutableListOf<AudienceApplication>()
    File("stepik/sportprogramming/request2unlim.in").forEachLine {
        applications.add(readApplication(it))
    }
    return applications
}

private fun readFromInput(): MutableList<AudienceApplication> {
    val applications = mutableListOf<AudienceApplication>()
    val n = readInt()
    repeat(n) {
        applications.add(readApplication(readLine()!!))
    }
    return applications
}

private fun count(rooms: IntArray, applications: List<AudienceApplication>): Int {
    for (application in applications) {
        for (i in application.left until application.right) {
            rooms[i]++
        }
    }
    return rooms.max()!!
}

private class AudienceApplication(val left: Int, val right: Int)

private fun readInt() = readLine()!!.trim().toInt()

private fun readApplication(string: String): AudienceApplication {
    val ints = string.split(" ").map { it.trim().toInt() }.toIntArray()
    return AudienceApplication(ints[0], ints[1])
}

private fun readInts() = readLine()!!.split(" ").map(String::toInt).toIntArray()

Compiled from "UnlimitedAudienceApplicationsGreedyAlgorithm.kt"
public final class stepik.sportprogramming.UnlimitedAudienceApplicationsGreedyAlgorithmKt {
  public static final void main();
    Code:
       0: iconst_0
       1: istore_1
       2: ldc           #7                  // int 33000
       4: newarray       int
       6: astore_2
       7: iload_1
       8: ldc           #7                  // int 33000
      10: if_icmpge     25
      13: iload_1
      14: istore_3
      15: aload_2
      16: iload_3
      17: iconst_0
      18: iastore
      19: iinc          1, 1
      22: goto          7
      25: aload_2
      26: astore_0
      27: invokestatic  #11                 // Method readFromFile:()Ljava/util/List;
      30: astore_1
      31: new           #13                 // class java/lang/StringBuilder
      34: dup
      35: invokespecial #16                 // Method java/lang/StringBuilder."<init>":()V
      38: ldc           #18                 // String Max of applications is
      40: invokevirtual #22                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      43: aload_0
      44: aload_1
      45: invokestatic  #26                 // Method count:([ILjava/util/List;)I
      48: invokevirtual #29                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      51: invokevirtual #33                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      54: getstatic     #39                 // Field java/lang/System.out:Ljava/io/PrintStream;
      57: swap
      58: invokevirtual #45                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      61: return

  private static final java.util.List<stepik.sportprogramming.AudienceApplication> readFromFile();
    Code:
       0: new           #53                 // class java/util/ArrayList
       3: dup
       4: invokespecial #54                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #56                 // class java/util/List
      10: astore_0
      11: new           #58                 // class java/io/File
      14: dup
      15: ldc           #60                 // String stepik/sportprogramming/request2unlim.in
      17: invokespecial #63                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      20: aconst_null
      21: aload_0
      22: invokedynamic #83,  0             // InvokeDynamic #0:invoke:(Ljava/util/List;)Lkotlin/jvm/functions/Function1;
      27: iconst_1
      28: aconst_null
      29: invokestatic  #89                 // Method kotlin/io/FilesKt.forEachLine$default:(Ljava/io/File;Ljava/nio/charset/Charset;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
      32: aload_0
      33: areturn

  private static final java.util.List<stepik.sportprogramming.AudienceApplication> readFromInput();
    Code:
       0: new           #53                 // class java/util/ArrayList
       3: dup
       4: invokespecial #54                 // Method java/util/ArrayList."<init>":()V
       7: checkcast     #56                 // class java/util/List
      10: astore_0
      11: invokestatic  #94                 // Method readInt:()I
      14: istore_1
      15: iconst_0
      16: istore_2
      17: iload_2
      18: iload_1
      19: if_icmpge     51
      22: iload_2
      23: istore_3
      24: iconst_0
      25: istore        4
      27: aload_0
      28: invokestatic  #99                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      31: dup
      32: invokestatic  #104                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      35: invokestatic  #108                // Method readApplication:(Ljava/lang/String;)Lstepik/sportprogramming/AudienceApplication;
      38: invokeinterface #112,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      43: pop
      44: nop
      45: iinc          2, 1
      48: goto          17
      51: aload_0
      52: areturn

  private static final int count(int[], java.util.List<stepik.sportprogramming.AudienceApplication>);
    Code:
       0: aload_1
       1: invokeinterface #121,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
       6: astore_2
       7: aload_2
       8: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      13: ifeq          69
      16: aload_2
      17: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      22: checkcast     #133                // class stepik/sportprogramming/AudienceApplication
      25: astore_3
      26: aload_3
      27: invokevirtual #136                // Method stepik/sportprogramming/AudienceApplication.getLeft:()I
      30: istore        4
      32: aload_3
      33: invokevirtual #139                // Method stepik/sportprogramming/AudienceApplication.getRight:()I
      36: istore        5
      38: iload         4
      40: iload         5
      42: if_icmpge     7
      45: iload         4
      47: istore        6
      49: aload_0
      50: iload         6
      52: iaload
      53: istore        7
      55: aload_0
      56: iload         6
      58: iload         7
      60: iconst_1
      61: iadd
      62: iastore
      63: iinc          4, 1
      66: goto          38
      69: aload_0
      70: invokestatic  #145                // Method kotlin/collections/ArraysKt.maxOrThrow:([I)I
      73: ireturn

  private static final int readInt();
    Code:
       0: nop
       1: invokestatic  #99                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       4: dup
       5: invokestatic  #104                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       8: checkcast     #150                // class java/lang/CharSequence
      11: invokestatic  #156                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      14: invokevirtual #157                // Method java/lang/Object.toString:()Ljava/lang/String;
      17: invokestatic  #163                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      20: ireturn

  private static final stepik.sportprogramming.AudienceApplication readApplication(java.lang.String);
    Code:
       0: aload_0
       1: checkcast     #150                // class java/lang/CharSequence
       4: iconst_1
       5: anewarray     #165                // class java/lang/String
       8: astore_2
       9: aload_2
      10: iconst_0
      11: ldc           #167                // String
      13: aastore
      14: aload_2
      15: iconst_0
      16: iconst_0
      17: bipush        6
      19: aconst_null
      20: invokestatic  #171                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      23: checkcast     #173                // class java/lang/Iterable
      26: astore_2
      27: iconst_0
      28: istore_3
      29: aload_2
      30: astore        4
      32: new           #53                 // class java/util/ArrayList
      35: dup
      36: aload_2
      37: bipush        10
      39: invokestatic  #179                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      42: invokespecial #182                // Method java/util/ArrayList."<init>":(I)V
      45: checkcast     #184                // class java/util/Collection
      48: astore        5
      50: iconst_0
      51: istore        6
      53: aload         4
      55: invokeinterface #185,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      60: astore        7
      62: aload         7
      64: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      69: ifeq          126
      72: aload         7
      74: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      79: astore        8
      81: aload         5
      83: aload         8
      85: checkcast     #165                // class java/lang/String
      88: astore        9
      90: astore        11
      92: iconst_0
      93: istore        10
      95: nop
      96: aload         9
      98: checkcast     #150                // class java/lang/CharSequence
     101: invokestatic  #156                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     104: invokevirtual #157                // Method java/lang/Object.toString:()Ljava/lang/String;
     107: invokestatic  #163                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     110: nop
     111: invokestatic  #189                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     114: aload         11
     116: swap
     117: invokeinterface #190,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     122: pop
     123: goto          62
     126: aload         5
     128: checkcast     #56                 // class java/util/List
     131: nop
     132: checkcast     #184                // class java/util/Collection
     135: invokestatic  #194                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     138: astore_1
     139: new           #133                // class stepik/sportprogramming/AudienceApplication
     142: dup
     143: aload_1
     144: iconst_0
     145: iaload
     146: aload_1
     147: iconst_1
     148: iaload
     149: invokespecial #197                // Method stepik/sportprogramming/AudienceApplication."<init>":(II)V
     152: areturn

  private static final int[] readInts();
    Code:
       0: invokestatic  #99                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #104                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #150                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #165                // class java/lang/String
      14: astore_0
      15: aload_0
      16: iconst_0
      17: ldc           #167                // String
      19: aastore
      20: aload_0
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #171                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #173                // class java/lang/Iterable
      32: astore_0
      33: iconst_0
      34: istore_1
      35: aload_0
      36: astore_2
      37: new           #53                 // class java/util/ArrayList
      40: dup
      41: aload_0
      42: bipush        10
      44: invokestatic  #179                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #182                // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #184                // class java/util/Collection
      53: astore_3
      54: iconst_0
      55: istore        4
      57: aload_2
      58: invokeinterface #185,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      63: astore        5
      65: aload         5
      67: invokeinterface #127,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      72: ifeq          118
      75: aload         5
      77: invokeinterface #131,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      82: astore        6
      84: aload_3
      85: aload         6
      87: checkcast     #165                // class java/lang/String
      90: astore        7
      92: astore        9
      94: iconst_0
      95: istore        8
      97: aload         7
      99: invokestatic  #163                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     102: nop
     103: invokestatic  #189                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     106: aload         9
     108: swap
     109: invokeinterface #190,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     114: pop
     115: goto          65
     118: aload_3
     119: checkcast     #56                 // class java/util/List
     122: nop
     123: checkcast     #184                // class java/util/Collection
     126: invokestatic  #194                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     129: areturn

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

  private static final kotlin.Unit readFromFile$lambda$0(java.util.List, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #220                // String it
       3: invokestatic  #224                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokestatic  #108                // Method readApplication:(Ljava/lang/String;)Lstepik/sportprogramming/AudienceApplication;
      11: invokeinterface #112,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      16: pop
      17: getstatic     #230                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      20: areturn
}


package stepik.sportprogramming

private const val MAX_DAYS = 5000

private val used: BooleanArray = BooleanArray(MAX_DAYS) { false }
private val orders = mutableListOf<Order>()

fun main() {
    val n = readInt()
    repeat(n) {
        orders.add(readOrder())
    }
    val sortedByDeadlineOrders = orders.sortedDescending()
    var sum: Long = 0
    for (i in 0 until sortedByDeadlineOrders.size) {
        val order = sortedByDeadlineOrders[i]
        var k = order.deadline
        while (k >= 1 && used[k]) {
            k--
        }
        if (k == 0) {
            continue
        }
        used[k] = true
        sum += order.cost
    }
    println("Maximum sum of all orders will be $sum")
}

private class Order(val deadline: Int, val cost: Int) : Comparable<Order> {

    override fun compareTo(other: Order): Int {
        return cost - other.cost
    }
}

private fun readInt() = readLine()!!.toInt()

private fun readOrder(): Order {
    val pairOfInts = readLine()!!.split(" ").map(String::toInt).toIntArray()
    return Order(pairOfInts[0], pairOfInts[1])
}

Compiled from "ScheduleGreedyAlgorithm.kt"
public final class stepik.sportprogramming.ScheduleGreedyAlgorithmKt {
  private static final int MAX_DAYS;

  private static final boolean[] used;

  private static final java.util.List<stepik.sportprogramming.Order> orders;

  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readInt:()I
       3: istore_0
       4: iconst_0
       5: istore_1
       6: iload_1
       7: iload_0
       8: if_icmpge     34
      11: iload_1
      12: istore_2
      13: iconst_0
      14: istore_3
      15: getstatic     #14                 // Field orders:Ljava/util/List;
      18: invokestatic  #18                 // Method readOrder:()Lstepik/sportprogramming/Order;
      21: invokeinterface #24,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      26: pop
      27: nop
      28: iinc          1, 1
      31: goto          6
      34: getstatic     #14                 // Field orders:Ljava/util/List;
      37: checkcast     #26                 // class java/lang/Iterable
      40: invokestatic  #32                 // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
      43: astore_1
      44: lconst_0
      45: lstore_2
      46: iconst_0
      47: istore        4
      49: aload_1
      50: invokeinterface #35,  1           // InterfaceMethod java/util/List.size:()I
      55: istore        5
      57: iload         4
      59: iload         5
      61: if_icmpge     135
      64: aload_1
      65: iload         4
      67: invokeinterface #39,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      72: checkcast     #41                 // class stepik/sportprogramming/Order
      75: astore        6
      77: aload         6
      79: invokevirtual #44                 // Method stepik/sportprogramming/Order.getDeadline:()I
      82: istore        7
      84: iload         7
      86: iconst_1
      87: if_icmplt     105
      90: getstatic     #48                 // Field used:[Z
      93: iload         7
      95: baload
      96: ifeq          105
      99: iinc          7, -1
     102: goto          84
     105: iload         7
     107: ifne          113
     110: goto          129
     113: getstatic     #48                 // Field used:[Z
     116: iload         7
     118: iconst_1
     119: bastore
     120: lload_2
     121: aload         6
     123: invokevirtual #51                 // Method stepik/sportprogramming/Order.getCost:()I
     126: i2l
     127: ladd
     128: lstore_2
     129: iinc          4, 1
     132: goto          57
     135: new           #53                 // class java/lang/StringBuilder
     138: dup
     139: invokespecial #56                 // Method java/lang/StringBuilder."<init>":()V
     142: ldc           #58                 // String Maximum sum of all orders will be
     144: invokevirtual #62                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     147: lload_2
     148: invokevirtual #65                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     151: invokevirtual #69                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     154: getstatic     #75                 // Field java/lang/System.out:Ljava/io/PrintStream;
     157: swap
     158: invokevirtual #81                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     161: return

  private static final int readInt();
    Code:
       0: invokestatic  #97                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      10: ireturn

  private static final stepik.sportprogramming.Order readOrder();
    Code:
       0: invokestatic  #97                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #102                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #110                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #112                // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #114                // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #120                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #26                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #122                // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #126                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #129                // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #131                // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #135,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #141,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #145,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #112                // class java/lang/String
      92: astore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #108                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #149                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         10
     110: swap
     111: invokeinterface #150,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #20                 // class java/util/List
     125: nop
     126: checkcast     #131                // class java/util/Collection
     129: invokestatic  #154                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     132: astore_0
     133: new           #41                 // class stepik/sportprogramming/Order
     136: dup
     137: aload_0
     138: iconst_0
     139: iaload
     140: aload_0
     141: iconst_1
     142: iaload
     143: invokespecial #157                // Method stepik/sportprogramming/Order."<init>":(II)V
     146: areturn

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

  static {};
    Code:
       0: iconst_0
       1: istore_0
       2: sipush        5000
       5: newarray       boolean
       7: astore_1
       8: iload_0
       9: sipush        5000
      12: if_icmpge     27
      15: iload_0
      16: istore_2
      17: aload_1
      18: iload_2
      19: iconst_0
      20: bastore
      21: iinc          0, 1
      24: goto          8
      27: aload_1
      28: putstatic     #48                 // Field used:[Z
      31: new           #122                // class java/util/ArrayList
      34: dup
      35: invokespecial #178                // Method java/util/ArrayList."<init>":()V
      38: checkcast     #20                 // class java/util/List
      41: putstatic     #14                 // Field orders:Ljava/util/List;
      44: return
}


package stepik.sportprogramming

private val things = mutableListOf<Thing>()

fun main() {
    val (n, maxWeight) = readPair()
    repeat(n) {
        things.add(readThing())
    }
    println("Maximum value of all things is ${solution(maxWeight)}")
}

private fun solution(maxWeight: Int): Int {
    val sortedByValue = things.sortedDescending()
    var sum = 0
    var sumWeight: Int = maxWeight
    for (i in 0 until sortedByValue.size) {
        if (sumWeight <= 0) {
            break
        }
        val thing = sortedByValue[i]
        if (sumWeight >= thing.weight) {
            sumWeight -= thing.weight
            sum += thing.cost
        } else {
            sum += (sumWeight * thing.getValue())
            sumWeight -= thing.weight
        }
    }
    return sum
}

private class Thing(val weight: Int, val cost: Int) : Comparable<Thing> {

    override fun compareTo(other: Thing): Int {
        return getValue() - other.getValue()
    }

    fun getValue(): Int {
        return cost / weight
    }
}

private fun readPair(): Pair<Int, Int> {
    val conditions = readLine()!!.split(" ").map(String::toInt).toIntArray()
    return Pair(conditions[0], conditions[1])
}

private fun readThing(): Thing {
    val thing = readLine()!!.split(" ").map(String::toInt).toIntArray()
    return Thing(thing[0], thing[1])
}

Compiled from "ContuneousBagProblemGreedyAlgorithm.kt"
public final class stepik.sportprogramming.ContuneousBagProblemGreedyAlgorithmKt {
  private static final java.util.List<stepik.sportprogramming.Thing> things;

  public static final void main();
    Code:
       0: invokestatic  #10                 // Method readPair:()Lkotlin/Pair;
       3: astore_0
       4: aload_0
       5: invokevirtual #16                 // Method kotlin/Pair.component1:()Ljava/lang/Object;
       8: checkcast     #18                 // class java/lang/Number
      11: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      14: istore_1
      15: aload_0
      16: invokevirtual #25                 // Method kotlin/Pair.component2:()Ljava/lang/Object;
      19: checkcast     #18                 // class java/lang/Number
      22: invokevirtual #22                 // Method java/lang/Number.intValue:()I
      25: istore_2
      26: iconst_0
      27: istore_3
      28: iload_3
      29: iload_1
      30: if_icmpge     58
      33: iload_3
      34: istore        4
      36: iconst_0
      37: istore        5
      39: getstatic     #29                 // Field things:Ljava/util/List;
      42: invokestatic  #33                 // Method readThing:()Lstepik/sportprogramming/Thing;
      45: invokeinterface #39,  2           // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
      50: pop
      51: nop
      52: iinc          3, 1
      55: goto          28
      58: new           #41                 // class java/lang/StringBuilder
      61: dup
      62: invokespecial #44                 // Method java/lang/StringBuilder."<init>":()V
      65: ldc           #46                 // String Maximum value of all things is
      67: invokevirtual #50                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      70: iload_2
      71: invokestatic  #54                 // Method solution:(I)I
      74: invokevirtual #57                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      77: invokevirtual #61                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      80: getstatic     #67                 // Field java/lang/System.out:Ljava/io/PrintStream;
      83: swap
      84: invokevirtual #73                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      87: return

  private static final int solution(int);
    Code:
       0: getstatic     #29                 // Field things:Ljava/util/List;
       3: checkcast     #80                 // class java/lang/Iterable
       6: invokestatic  #86                 // Method kotlin/collections/CollectionsKt.sortedDescending:(Ljava/lang/Iterable;)Ljava/util/List;
       9: astore_1
      10: iconst_0
      11: istore_2
      12: iload_0
      13: istore_3
      14: iconst_0
      15: istore        4
      17: aload_1
      18: invokeinterface #89,  1           // InterfaceMethod java/util/List.size:()I
      23: istore        5
      25: iload         4
      27: iload         5
      29: if_icmpge     104
      32: iload_3
      33: ifgt          39
      36: goto          104
      39: aload_1
      40: iload         4
      42: invokeinterface #93,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      47: checkcast     #95                 // class stepik/sportprogramming/Thing
      50: astore        6
      52: iload_3
      53: aload         6
      55: invokevirtual #98                 // Method stepik/sportprogramming/Thing.getWeight:()I
      58: if_icmplt     80
      61: iload_3
      62: aload         6
      64: invokevirtual #98                 // Method stepik/sportprogramming/Thing.getWeight:()I
      67: isub
      68: istore_3
      69: iload_2
      70: aload         6
      72: invokevirtual #101                // Method stepik/sportprogramming/Thing.getCost:()I
      75: iadd
      76: istore_2
      77: goto          98
      80: iload_2
      81: iload_3
      82: aload         6
      84: invokevirtual #104                // Method stepik/sportprogramming/Thing.getValue:()I
      87: imul
      88: iadd
      89: istore_2
      90: iload_3
      91: aload         6
      93: invokevirtual #98                 // Method stepik/sportprogramming/Thing.getWeight:()I
      96: isub
      97: istore_3
      98: iinc          4, 1
     101: goto          25
     104: iload_2
     105: ireturn

  private static final kotlin.Pair<java.lang.Integer, java.lang.Integer> readPair();
    Code:
       0: invokestatic  #116                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #123                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #125                // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #127                // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #133                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #80                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #135                // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #139                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #142                // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #144                // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #148,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #154,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #157,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #125                // class java/lang/String
      92: astore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #163                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         10
     110: swap
     111: invokeinterface #168,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #35                 // class java/util/List
     125: nop
     126: checkcast     #144                // class java/util/Collection
     129: invokestatic  #172                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     132: astore_0
     133: new           #12                 // class kotlin/Pair
     136: dup
     137: aload_0
     138: iconst_0
     139: iaload
     140: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     143: aload_0
     144: iconst_1
     145: iaload
     146: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     149: invokespecial #175                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     152: areturn

  private static final stepik.sportprogramming.Thing readThing();
    Code:
       0: invokestatic  #116                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #121                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #123                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #125                // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #127                // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #133                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #80                 // class java/lang/Iterable
      32: astore_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #135                // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #139                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #142                // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #144                // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #148,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #154,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #157,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #125                // class java/lang/String
      92: astore        8
      94: astore        10
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #163                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #167                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         10
     110: swap
     111: invokeinterface #168,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #35                 // class java/util/List
     125: nop
     126: checkcast     #144                // class java/util/Collection
     129: invokestatic  #172                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     132: astore_0
     133: new           #95                 // class stepik/sportprogramming/Thing
     136: dup
     137: aload_0
     138: iconst_0
     139: iaload
     140: aload_0
     141: iconst_1
     142: iaload
     143: invokespecial #192                // Method stepik/sportprogramming/Thing."<init>":(II)V
     146: areturn

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

  static {};
    Code:
       0: new           #135                // class java/util/ArrayList
       3: dup
       4: invokespecial #200                // Method java/util/ArrayList."<init>":()V
       7: checkcast     #35                 // class java/util/List
      10: putstatic     #29                 // Field things:Ljava/util/List;
      13: return
}