enum class InequationType {
    LT, // <
    GT, // >
    KT, // Nothing
}

data class Minmax(val min: Long, val max: Long)

fun solve(previous: Int, choice: Long, seq: List<InequationType>, available: Set<Int>): Minmax {
    var min = 9999999999L
    var max = 0L
    if (seq.isEmpty()) {
        return Minmax(choice, choice)
    }
    for (i in available) {
        val canUse = when (seq[0]) {
            InequationType.KT -> true
            InequationType.LT -> previous < i
            InequationType.GT -> previous > i
        }
        if (!canUse) {
            continue
        }
        val result = solve(i, choice * 10 + i, seq.subList(1, seq.size), available - i)
        min = minOf(min, result.min)
        max = maxOf(max, result.max)
    }
    return Minmax(min, max)
}

fun main(args: Array<out String>) {
    val k = readLine()!!.toInt()
    val a = listOf(InequationType.KT) + readLine()!!.split(' ')
        .asSequence()
        .filter { it.isNotEmpty() }
        .map { if (it == "<") InequationType.LT else InequationType.GT }
        .toList()

    val (min, max) = solve(0, 0L, a, (0..9).toSet())
    println(max.toString().padStart(k + 1, '0'))
    println(min.toString().padStart(k + 1, '0'))
}

Compiled from "P2529.kt"
public final class P2529Kt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method InequationType.values:()[LInequationType;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field InequationType.KT:LInequationType;
      12: invokevirtual #22                 // Method InequationType.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field InequationType.LT:LInequationType;
      26: invokevirtual #22                 // Method InequationType.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field InequationType.GT:LInequationType;
      40: invokevirtual #22                 // Method InequationType.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: aload_0
      50: putstatic     #32                 // Field $EnumSwitchMapping$0:[I
      53: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
}

Compiled from "P2529.kt"
public final class P2529Kt {
  public static final Minmax solve(int, long, java.util.List<? extends InequationType>, java.util.Set<java.lang.Integer>);
    Code:
       0: aload_3
       1: ldc           #10                 // String seq
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload         4
       8: ldc           #18                 // String available
      10: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      13: ldc2_w        #19                 // long 9999999999l
      16: lstore        5
      18: lconst_0
      19: lstore        7
      21: aload_3
      22: invokeinterface #26,  1           // InterfaceMethod java/util/List.isEmpty:()Z
      27: ifeq          40
      30: new           #28                 // class Minmax
      33: dup
      34: lload_1
      35: lload_1
      36: invokespecial #32                 // Method Minmax."<init>":(JJ)V
      39: areturn
      40: aload         4
      42: invokeinterface #38,  1           // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
      47: astore        9
      49: aload         9
      51: invokeinterface #43,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      56: ifeq          236
      59: aload         9
      61: invokeinterface #47,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      66: checkcast     #49                 // class java/lang/Number
      69: invokevirtual #53                 // Method java/lang/Number.intValue:()I
      72: istore        10
      74: aload_3
      75: iconst_0
      76: invokeinterface #57,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      81: checkcast     #59                 // class InequationType
      84: getstatic     #65                 // Field P2529Kt$WhenMappings.$EnumSwitchMapping$0:[I
      87: swap
      88: invokevirtual #68                 // Method InequationType.ordinal:()I
      91: iaload
      92: tableswitch   { // 1 to 3
                     1: 120
                     2: 124
                     3: 138
               default: 152
          }
     120: iconst_1
     121: goto          160
     124: iload_0
     125: iload         10
     127: if_icmpge     134
     130: iconst_1
     131: goto          160
     134: iconst_0
     135: goto          160
     138: iload_0
     139: iload         10
     141: if_icmple     148
     144: iconst_1
     145: goto          160
     148: iconst_0
     149: goto          160
     152: new           #70                 // class kotlin/NoWhenBranchMatchedException
     155: dup
     156: invokespecial #73                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     159: athrow
     160: istore        11
     162: iload         11
     164: ifne          170
     167: goto          49
     170: iload         10
     172: lload_1
     173: bipush        10
     175: i2l
     176: lmul
     177: iload         10
     179: i2l
     180: ladd
     181: aload_3
     182: iconst_1
     183: aload_3
     184: invokeinterface #76,  1           // InterfaceMethod java/util/List.size:()I
     189: invokeinterface #80,  3           // InterfaceMethod java/util/List.subList:(II)Ljava/util/List;
     194: aload         4
     196: iload         10
     198: invokestatic  #86                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     201: invokestatic  #92                 // Method kotlin/collections/SetsKt.minus:(Ljava/util/Set;Ljava/lang/Object;)Ljava/util/Set;
     204: invokestatic  #94                 // Method solve:(IJLjava/util/List;Ljava/util/Set;)LMinmax;
     207: astore        12
     209: lload         5
     211: aload         12
     213: invokevirtual #98                 // Method Minmax.getMin:()J
     216: invokestatic  #104                // Method java/lang/Math.min:(JJ)J
     219: lstore        5
     221: lload         7
     223: aload         12
     225: invokevirtual #107                // Method Minmax.getMax:()J
     228: invokestatic  #110                // Method java/lang/Math.max:(JJ)J
     231: lstore        7
     233: goto          49
     236: new           #28                 // class Minmax
     239: dup
     240: lload         5
     242: lload         7
     244: invokespecial #32                 // Method Minmax."<init>":(JJ)V
     247: areturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #125                // String args
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: invokestatic  #131                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       9: dup
      10: invokestatic  #135                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      13: invokestatic  #139                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      16: istore_1
      17: getstatic     #143                // Field InequationType.KT:LInequationType;
      20: invokestatic  #149                // Method kotlin/collections/CollectionsKt.listOf:(Ljava/lang/Object;)Ljava/util/List;
      23: checkcast     #151                // class java/util/Collection
      26: invokestatic  #131                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      29: dup
      30: invokestatic  #135                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      33: checkcast     #153                // class java/lang/CharSequence
      36: iconst_1
      37: newarray       char
      39: astore_3
      40: aload_3
      41: iconst_0
      42: bipush        32
      44: castore
      45: aload_3
      46: iconst_0
      47: iconst_0
      48: bipush        6
      50: aconst_null
      51: invokestatic  #159                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[CZIILjava/lang/Object;)Ljava/util/List;
      54: checkcast     #161                // class java/lang/Iterable
      57: invokestatic  #165                // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      60: invokedynamic #185,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      65: invokestatic  #191                // Method kotlin/sequences/SequencesKt.filter:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      68: invokedynamic #198,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
      73: invokestatic  #201                // Method kotlin/sequences/SequencesKt.map:(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence;
      76: invokestatic  #205                // Method kotlin/sequences/SequencesKt.toList:(Lkotlin/sequences/Sequence;)Ljava/util/List;
      79: checkcast     #161                // class java/lang/Iterable
      82: invokestatic  #209                // Method kotlin/collections/CollectionsKt.plus:(Ljava/util/Collection;Ljava/lang/Iterable;)Ljava/util/List;
      85: astore_2
      86: iconst_0
      87: lconst_0
      88: aload_2
      89: new           #211                // class kotlin/ranges/IntRange
      92: dup
      93: iconst_0
      94: bipush        9
      96: invokespecial #214                // Method kotlin/ranges/IntRange."<init>":(II)V
      99: checkcast     #161                // class java/lang/Iterable
     102: invokestatic  #218                // Method kotlin/collections/CollectionsKt.toSet:(Ljava/lang/Iterable;)Ljava/util/Set;
     105: invokestatic  #94                 // Method solve:(IJLjava/util/List;Ljava/util/Set;)LMinmax;
     108: astore_3
     109: aload_3
     110: invokevirtual #221                // Method Minmax.component1:()J
     113: lstore        4
     115: aload_3
     116: invokevirtual #224                // Method Minmax.component2:()J
     119: lstore        6
     121: lload         6
     123: invokestatic  #229                // Method java/lang/String.valueOf:(J)Ljava/lang/String;
     126: iload_1
     127: iconst_1
     128: iadd
     129: bipush        48
     131: invokestatic  #233                // Method kotlin/text/StringsKt.padStart:(Ljava/lang/String;IC)Ljava/lang/String;
     134: getstatic     #239                // Field java/lang/System.out:Ljava/io/PrintStream;
     137: swap
     138: invokevirtual #244                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     141: lload         4
     143: invokestatic  #229                // Method java/lang/String.valueOf:(J)Ljava/lang/String;
     146: iload_1
     147: iconst_1
     148: iadd
     149: bipush        48
     151: invokestatic  #233                // Method kotlin/text/StringsKt.padStart:(Ljava/lang/String;IC)Ljava/lang/String;
     154: getstatic     #239                // Field java/lang/System.out:Ljava/io/PrintStream;
     157: swap
     158: invokevirtual #244                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     161: return

  private static final boolean main$lambda$0(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #249                // String it
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #153                // class java/lang/CharSequence
      10: invokeinterface #252,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      15: ifle          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ireturn

  private static final InequationType main$lambda$1(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #249                // String it
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: ldc           #255                // String <
       9: invokestatic  #259                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      12: ifeq          21
      15: getstatic     #262                // Field InequationType.LT:LInequationType;
      18: goto          24
      21: getstatic     #265                // Field InequationType.GT:LInequationType;
      24: areturn
}


fun main(args: Array<out String>) {
    val (height, width) = readLine()!!.split(" ").map { it.toInt() }
    val realMap = List(height * 2) {
        if (it % 2 == 0) {
            List(width * 2) { 0L }
        } else {
            readLine()!!.split(" ").flatMap { listOf(0L, it.toLong()) }
        }
    }

    fun getSafe(map: List<List<Long>>, x: Int, y: Int): Long =
        if (y in 0 until 2 * height && x in 0 until 2 * width) map[y][x]
        else 0

    val intDP = List(height * 2) {
        MutableList(width * 2) { 0L }
    }

    for (x in (0 until width * 2).reversed()) {
        for (y in (0 until height * 2).reversed()) {
            val here = realMap[y][x]
            val best = maxOf(
                getSafe(realMap, x + 1, y - 1) + getSafe(intDP, x + 2, y - 2),
                getSafe(realMap, x + 2, y) + getSafe(intDP, x + 4, y),
                getSafe(realMap, x + 1, y + 1) + getSafe(intDP, x + 2, y + 2)
            )
            intDP[y][x] = here + best
        }
    }

    val max = (0 until height * 2).fold(0L) { acc, y -> maxOf(acc, getSafe(intDP, 0, y), getSafe(intDP, 1, y)) }

    println(max)
}

Compiled from "solution.kt"
public final class SolutionKt {
  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: invokestatic  #21                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       9: dup
      10: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      13: checkcast     #27                 // class java/lang/CharSequence
      16: iconst_1
      17: anewarray     #29                 // class java/lang/String
      20: astore_2
      21: aload_2
      22: iconst_0
      23: ldc           #31                 // String
      25: aastore
      26: aload_2
      27: iconst_0
      28: iconst_0
      29: bipush        6
      31: aconst_null
      32: invokestatic  #37                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      35: checkcast     #39                 // class java/lang/Iterable
      38: astore_2
      39: iconst_0
      40: istore_3
      41: aload_2
      42: astore        4
      44: new           #41                 // class java/util/ArrayList
      47: dup
      48: aload_2
      49: bipush        10
      51: invokestatic  #47                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      54: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
      57: checkcast     #53                 // class java/util/Collection
      60: astore        5
      62: iconst_0
      63: istore        6
      65: aload         4
      67: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      72: astore        7
      74: aload         7
      76: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      81: ifeq          128
      84: aload         7
      86: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      91: astore        8
      93: aload         5
      95: aload         8
      97: checkcast     #29                 // class java/lang/String
     100: astore        9
     102: astore        24
     104: iconst_0
     105: istore        11
     107: aload         9
     109: invokestatic  #73                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     112: nop
     113: invokestatic  #77                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     116: aload         24
     118: swap
     119: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     124: pop
     125: goto          74
     128: aload         5
     130: checkcast     #83                 // class java/util/List
     133: nop
     134: astore_1
     135: aload_1
     136: iconst_0
     137: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     142: checkcast     #89                 // class java/lang/Number
     145: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     148: istore_2
     149: aload_1
     150: iconst_1
     151: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     156: checkcast     #89                 // class java/lang/Number
     159: invokevirtual #93                 // Method java/lang/Number.intValue:()I
     162: istore_3
     163: iload_2
     164: iconst_2
     165: imul
     166: istore        5
     168: new           #41                 // class java/util/ArrayList
     171: dup
     172: iload         5
     174: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     177: astore        6
     179: iconst_0
     180: istore        7
     182: iload         7
     184: iload         5
     186: if_icmpge     441
     189: iload         7
     191: istore        8
     193: aload         6
     195: iload         8
     197: istore        9
     199: astore        24
     201: iconst_0
     202: istore        11
     204: iload         9
     206: iconst_2
     207: irem
     208: ifne          277
     211: iload_3
     212: iconst_2
     213: imul
     214: istore        12
     216: new           #41                 // class java/util/ArrayList
     219: dup
     220: iload         12
     222: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     225: astore        14
     227: iconst_0
     228: istore        15
     230: iload         15
     232: iload         12
     234: if_icmpge     269
     237: iload         15
     239: istore        16
     241: aload         14
     243: iload         16
     245: istore        17
     247: astore        18
     249: iconst_0
     250: istore        19
     252: lconst_0
     253: invokestatic  #98                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     256: aload         18
     258: swap
     259: invokevirtual #99                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     262: pop
     263: iinc          15, 1
     266: goto          230
     269: aload         14
     271: checkcast     #83                 // class java/util/List
     274: goto          427
     277: invokestatic  #21                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     280: dup
     281: invokestatic  #25                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     284: checkcast     #27                 // class java/lang/CharSequence
     287: iconst_1
     288: anewarray     #29                 // class java/lang/String
     291: astore        12
     293: aload         12
     295: iconst_0
     296: ldc           #31                 // String
     298: aastore
     299: aload         12
     301: iconst_0
     302: iconst_0
     303: bipush        6
     305: aconst_null
     306: invokestatic  #37                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     309: checkcast     #39                 // class java/lang/Iterable
     312: astore        12
     314: iconst_0
     315: istore        14
     317: aload         12
     319: astore        15
     321: new           #41                 // class java/util/ArrayList
     324: dup
     325: invokespecial #102                // Method java/util/ArrayList."<init>":()V
     328: checkcast     #53                 // class java/util/Collection
     331: astore        16
     333: iconst_0
     334: istore        17
     336: aload         15
     338: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     343: astore        19
     345: aload         19
     347: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     352: ifeq          421
     355: aload         19
     357: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     362: astore        20
     364: aload         20
     366: checkcast     #29                 // class java/lang/String
     369: astore        21
     371: iconst_0
     372: istore        22
     374: iconst_2
     375: anewarray     #95                 // class java/lang/Long
     378: astore        23
     380: aload         23
     382: iconst_0
     383: lconst_0
     384: invokestatic  #98                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     387: aastore
     388: aload         23
     390: iconst_1
     391: aload         21
     393: invokestatic  #106                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     396: invokestatic  #98                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     399: aastore
     400: aload         23
     402: invokestatic  #110                // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     405: checkcast     #39                 // class java/lang/Iterable
     408: astore        21
     410: aload         16
     412: aload         21
     414: invokestatic  #114                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
     417: pop
     418: goto          345
     421: aload         16
     423: checkcast     #83                 // class java/util/List
     426: nop
     427: nop
     428: aload         24
     430: swap
     431: invokevirtual #99                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     434: pop
     435: iinc          7, 1
     438: goto          182
     441: aload         6
     443: checkcast     #83                 // class java/util/List
     446: astore        4
     448: iload_2
     449: iconst_2
     450: imul
     451: istore        6
     453: new           #41                 // class java/util/ArrayList
     456: dup
     457: iload         6
     459: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     462: astore        7
     464: iconst_0
     465: istore        8
     467: iload         8
     469: iload         6
     471: if_icmpge     566
     474: iload         8
     476: istore        9
     478: aload         7
     480: iload         9
     482: istore        11
     484: astore        24
     486: iconst_0
     487: istore        12
     489: iload_3
     490: iconst_2
     491: imul
     492: istore        14
     494: new           #41                 // class java/util/ArrayList
     497: dup
     498: iload         14
     500: invokespecial #51                 // Method java/util/ArrayList."<init>":(I)V
     503: astore        15
     505: iconst_0
     506: istore        16
     508: iload         16
     510: iload         14
     512: if_icmpge     547
     515: iload         16
     517: istore        17
     519: aload         15
     521: iload         17
     523: istore        18
     525: astore        19
     527: iconst_0
     528: istore        20
     530: lconst_0
     531: invokestatic  #98                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     534: aload         19
     536: swap
     537: invokevirtual #99                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     540: pop
     541: iinc          16, 1
     544: goto          508
     547: aload         15
     549: checkcast     #83                 // class java/util/List
     552: nop
     553: aload         24
     555: swap
     556: invokevirtual #99                 // Method java/util/ArrayList.add:(Ljava/lang/Object;)Z
     559: pop
     560: iinc          8, 1
     563: goto          467
     566: aload         7
     568: checkcast     #83                 // class java/util/List
     571: astore        5
     573: iconst_0
     574: iload_3
     575: iconst_2
     576: imul
     577: invokestatic  #120                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     580: checkcast     #122                // class kotlin/ranges/IntProgression
     583: invokestatic  #126                // Method kotlin/ranges/RangesKt.reversed:(Lkotlin/ranges/IntProgression;)Lkotlin/ranges/IntProgression;
     586: astore        6
     588: aload         6
     590: invokevirtual #129                // Method kotlin/ranges/IntProgression.getFirst:()I
     593: istore        7
     595: aload         6
     597: invokevirtual #132                // Method kotlin/ranges/IntProgression.getLast:()I
     600: istore        8
     602: aload         6
     604: invokevirtual #135                // Method kotlin/ranges/IntProgression.getStep:()I
     607: istore        9
     609: iload         9
     611: ifle          621
     614: iload         7
     616: iload         8
     618: if_icmple     633
     621: iload         9
     623: ifge          880
     626: iload         8
     628: iload         7
     630: if_icmpgt     880
     633: iconst_0
     634: iload_2
     635: iconst_2
     636: imul
     637: invokestatic  #120                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     640: checkcast     #122                // class kotlin/ranges/IntProgression
     643: invokestatic  #126                // Method kotlin/ranges/RangesKt.reversed:(Lkotlin/ranges/IntProgression;)Lkotlin/ranges/IntProgression;
     646: astore        11
     648: aload         11
     650: invokevirtual #129                // Method kotlin/ranges/IntProgression.getFirst:()I
     653: istore        12
     655: aload         11
     657: invokevirtual #132                // Method kotlin/ranges/IntProgression.getLast:()I
     660: istore        14
     662: aload         11
     664: invokevirtual #135                // Method kotlin/ranges/IntProgression.getStep:()I
     667: istore        15
     669: iload         15
     671: ifle          681
     674: iload         12
     676: iload         14
     678: if_icmple     693
     681: iload         15
     683: ifge          863
     686: iload         14
     688: iload         12
     690: if_icmpgt     863
     693: aload         4
     695: iload         12
     697: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     702: checkcast     #83                 // class java/util/List
     705: iload         7
     707: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     712: checkcast     #89                 // class java/lang/Number
     715: invokevirtual #139                // Method java/lang/Number.longValue:()J
     718: lstore        16
     720: nop
     721: iload_2
     722: iload_3
     723: aload         4
     725: iload         7
     727: iconst_1
     728: iadd
     729: iload         12
     731: iconst_1
     732: isub
     733: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     736: iload_2
     737: iload_3
     738: aload         5
     740: iload         7
     742: iconst_2
     743: iadd
     744: iload         12
     746: iconst_2
     747: isub
     748: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     751: ladd
     752: iload_2
     753: iload_3
     754: aload         4
     756: iload         7
     758: iconst_2
     759: iadd
     760: iload         12
     762: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     765: iload_2
     766: iload_3
     767: aload         5
     769: iload         7
     771: iconst_4
     772: iadd
     773: iload         12
     775: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     778: ladd
     779: iload_2
     780: iload_3
     781: aload         4
     783: iload         7
     785: iconst_1
     786: iadd
     787: iload         12
     789: iconst_1
     790: iadd
     791: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     794: iload_2
     795: iload_3
     796: aload         5
     798: iload         7
     800: iconst_2
     801: iadd
     802: iload         12
     804: iconst_2
     805: iadd
     806: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     809: ladd
     810: invokestatic  #149                // Method java/lang/Math.max:(JJ)J
     813: invokestatic  #149                // Method java/lang/Math.max:(JJ)J
     816: lstore        18
     818: aload         5
     820: iload         12
     822: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     827: checkcast     #83                 // class java/util/List
     830: iload         7
     832: lload         16
     834: lload         18
     836: ladd
     837: invokestatic  #98                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     840: invokeinterface #153,  3          // InterfaceMethod java/util/List.set:(ILjava/lang/Object;)Ljava/lang/Object;
     845: pop
     846: iload         12
     848: iload         14
     850: if_icmpeq     863
     853: iload         12
     855: iload         15
     857: iadd
     858: istore        12
     860: goto          693
     863: iload         7
     865: iload         8
     867: if_icmpeq     880
     870: iload         7
     872: iload         9
     874: iadd
     875: istore        7
     877: goto          633
     880: iconst_0
     881: iload_2
     882: iconst_2
     883: imul
     884: invokestatic  #120                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     887: checkcast     #39                 // class java/lang/Iterable
     890: astore        8
     892: lconst_0
     893: lstore        9
     895: iconst_0
     896: istore        11
     898: lload         9
     900: lstore        12
     902: aload         8
     904: invokeinterface #57,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     909: astore        14
     911: aload         14
     913: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     918: ifeq          976
     921: aload         14
     923: checkcast     #155                // class kotlin/collections/IntIterator
     926: invokevirtual #158                // Method kotlin/collections/IntIterator.nextInt:()I
     929: istore        15
     931: lload         12
     933: iload         15
     935: istore        16
     937: lstore        17
     939: iconst_0
     940: istore        19
     942: lload         17
     944: iload_2
     945: iload_3
     946: aload         5
     948: iconst_0
     949: iload         16
     951: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     954: iload_2
     955: iload_3
     956: aload         5
     958: iconst_1
     959: iload         16
     961: invokestatic  #143                // Method main$getSafe:(IILjava/util/List;II)J
     964: invokestatic  #149                // Method java/lang/Math.max:(JJ)J
     967: invokestatic  #149                // Method java/lang/Math.max:(JJ)J
     970: nop
     971: lstore        12
     973: goto          911
     976: lload         12
     978: lstore        6
     980: getstatic     #164                // Field java/lang/System.out:Ljava/io/PrintStream;
     983: lload         6
     985: invokevirtual #170                // Method java/io/PrintStream.println:(J)V
     988: return

  private static final long main$getSafe(int, int, java.util.List<? extends java.util.List<java.lang.Long>>, int, int);
    Code:
       0: iconst_0
       1: iload         4
       3: if_icmpgt     22
       6: iload         4
       8: iconst_2
       9: iload_0
      10: imul
      11: if_icmpge     18
      14: iconst_1
      15: goto          23
      18: iconst_0
      19: goto          23
      22: iconst_0
      23: ifeq          76
      26: iconst_0
      27: iload_3
      28: if_icmpgt     46
      31: iload_3
      32: iconst_2
      33: iload_1
      34: imul
      35: if_icmpge     42
      38: iconst_1
      39: goto          47
      42: iconst_0
      43: goto          47
      46: iconst_0
      47: ifeq          76
      50: aload_2
      51: iload         4
      53: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      58: checkcast     #83                 // class java/util/List
      61: iload_3
      62: invokeinterface #87,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      67: checkcast     #89                 // class java/lang/Number
      70: invokevirtual #139                // Method java/lang/Number.longValue:()J
      73: goto          77
      76: lconst_0
      77: lreturn
}


import kotlin.math.*

data class QuadraticEquation(val a: Long, val b: Long, val c: Long) {
    fun solve(): Set<Double> {
        val discriminant = b.toDouble() * b.toDouble() - 4.0 * a.toDouble() * c.toDouble()
        if (discriminant < 0) {
            return emptySet()
        }
        val sqrtedDiscriminant = sqrt(discriminant)
        return setOf((-b + sqrtedDiscriminant) / 2 / a, (-b - sqrtedDiscriminant) / 2 / a)
    }
}

fun syntheticDivision(a: Long, b: Long, c: Long, d: Long): Set<Double> {
    if (d == 0L) {
        return setOf(0.0) + QuadraticEquation(a, b, c).solve()
    }
    for (i in 1..sqrt(abs(d.toDouble())).toLong()) {
        if (d % i != 0L) {
            continue
        }
        for (e in listOf(i, -i, d / i, -d / i)) {
            val newA = a
            val newB = e * newA + b
            val newC = e * newB + c
            val newD = e * newC + d
            if (newD == 0L) {
                return setOf(e.toDouble()) + QuadraticEquation(newA, newB, newC).solve()
            }
        }
    }
    return emptySet()
}

fun gcd(a: Long, b: Long): Long =
    if (b == 0L) a
    else gcd(b, a % b)

fun main(args: Array<out String>) {
    (0 until readLine()!!.toLong()).joinToString("\n") {
        val (a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
        syntheticDivision(a, b, c, d).toList().sorted().joinToString(" ") { String.format("%f", it) }
    }.let(::println)
}

Compiled from "P9735.kt"
public final class P9735Kt {
  public static final java.util.Set<java.lang.Double> syntheticDivision(long, long, long, long);
    Code:
       0: lload         6
       2: lconst_0
       3: lcmp
       4: ifne          35
       7: dconst_0
       8: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      11: invokestatic  #20                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
      14: new           #22                 // class QuadraticEquation
      17: dup
      18: lload_0
      19: lload_2
      20: lload         4
      22: invokespecial #26                 // Method QuadraticEquation."<init>":(JJJ)V
      25: invokevirtual #30                 // Method QuadraticEquation.solve:()Ljava/util/Set;
      28: checkcast     #32                 // class java/lang/Iterable
      31: invokestatic  #36                 // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
      34: areturn
      35: lconst_1
      36: lstore        8
      38: lload         6
      40: l2d
      41: invokestatic  #42                 // Method java/lang/Math.abs:(D)D
      44: invokestatic  #45                 // Method java/lang/Math.sqrt:(D)D
      47: d2l
      48: lstore        10
      50: lload         8
      52: lload         10
      54: lcmp
      55: ifgt          246
      58: lload         6
      60: lload         8
      62: lrem
      63: lconst_0
      64: lcmp
      65: ifeq          71
      68: goto          229
      71: iconst_4
      72: anewarray     #47                 // class java/lang/Long
      75: astore        13
      77: aload         13
      79: iconst_0
      80: lload         8
      82: invokestatic  #50                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      85: aastore
      86: aload         13
      88: iconst_1
      89: lload         8
      91: lneg
      92: invokestatic  #50                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
      95: aastore
      96: aload         13
      98: iconst_2
      99: lload         6
     101: lload         8
     103: ldiv
     104: invokestatic  #50                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     107: aastore
     108: aload         13
     110: iconst_3
     111: lload         6
     113: lneg
     114: lload         8
     116: ldiv
     117: invokestatic  #50                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     120: aastore
     121: aload         13
     123: invokestatic  #56                 // Method kotlin/collections/CollectionsKt.listOf:([Ljava/lang/Object;)Ljava/util/List;
     126: invokeinterface #62,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     131: astore        12
     133: aload         12
     135: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     140: ifeq          229
     143: aload         12
     145: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     150: checkcast     #74                 // class java/lang/Number
     153: invokevirtual #78                 // Method java/lang/Number.longValue:()J
     156: lstore        13
     158: lload_0
     159: lstore        15
     161: lload         13
     163: lload         15
     165: lmul
     166: lload_2
     167: ladd
     168: lstore        17
     170: lload         13
     172: lload         17
     174: lmul
     175: lload         4
     177: ladd
     178: lstore        19
     180: lload         13
     182: lload         19
     184: lmul
     185: lload         6
     187: ladd
     188: lstore        21
     190: lload         21
     192: lconst_0
     193: lcmp
     194: ifne          133
     197: lload         13
     199: l2d
     200: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
     203: invokestatic  #20                 // Method kotlin/collections/SetsKt.setOf:(Ljava/lang/Object;)Ljava/util/Set;
     206: new           #22                 // class QuadraticEquation
     209: dup
     210: lload         15
     212: lload         17
     214: lload         19
     216: invokespecial #26                 // Method QuadraticEquation."<init>":(JJJ)V
     219: invokevirtual #30                 // Method QuadraticEquation.solve:()Ljava/util/Set;
     222: checkcast     #32                 // class java/lang/Iterable
     225: invokestatic  #36                 // Method kotlin/collections/SetsKt.plus:(Ljava/util/Set;Ljava/lang/Iterable;)Ljava/util/Set;
     228: areturn
     229: lload         8
     231: lload         10
     233: lcmp
     234: ifeq          246
     237: lload         8
     239: lconst_1
     240: ladd
     241: lstore        8
     243: goto          58
     246: invokestatic  #81                 // Method kotlin/collections/SetsKt.emptySet:()Ljava/util/Set;
     249: areturn

  public static final long gcd(long, long);
    Code:
       0: lload_2
       1: lconst_0
       2: lcmp
       3: ifne          10
       6: lload_0
       7: goto          17
      10: lload_2
      11: lload_0
      12: lload_2
      13: lrem
      14: invokestatic  #96                 // Method gcd:(JJ)J
      17: lreturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #100                // String args
       3: invokestatic  #106                // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_0
       7: invokestatic  #112                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
      10: dup
      11: invokestatic  #116                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      14: invokestatic  #120                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
      17: invokestatic  #126                // Method kotlin/ranges/RangesKt.until:(IJ)Lkotlin/ranges/LongRange;
      20: checkcast     #32                 // class java/lang/Iterable
      23: ldc           #128                // String \n
      25: checkcast     #130                // class java/lang/CharSequence
      28: aconst_null
      29: aconst_null
      30: iconst_0
      31: aconst_null
      32: invokedynamic #150,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function1;
      37: bipush        30
      39: aconst_null
      40: invokestatic  #154                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
      43: astore_1
      44: iconst_0
      45: istore_2
      46: getstatic     #160                // Field java/lang/System.out:Ljava/io/PrintStream;
      49: aload_1
      50: invokevirtual #165                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      53: nop
      54: nop
      55: return

  private static final java.lang.CharSequence main$lambda$2$lambda$1(double);
    Code:
       0: getstatic     #178                // Field kotlin/jvm/internal/StringCompanionObject.INSTANCE:Lkotlin/jvm/internal/StringCompanionObject;
       3: pop
       4: ldc           #180                // String %f
       6: astore_2
       7: iconst_1
       8: anewarray     #4                  // class java/lang/Object
      11: astore_3
      12: aload_3
      13: iconst_0
      14: dload_0
      15: invokestatic  #14                 // Method java/lang/Double.valueOf:(D)Ljava/lang/Double;
      18: aastore
      19: aload_3
      20: astore_3
      21: aload_2
      22: aload_3
      23: aload_3
      24: arraylength
      25: invokestatic  #186                // Method java/util/Arrays.copyOf:([Ljava/lang/Object;I)[Ljava/lang/Object;
      28: invokestatic  #192                // Method java/lang/String.format:(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;
      31: dup
      32: ldc           #194                // String format(...)
      34: invokestatic  #197                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      37: checkcast     #130                // class java/lang/CharSequence
      40: areturn

  private static final java.lang.CharSequence main$lambda$2(long);
    Code:
       0: invokestatic  #112                // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #116                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #130                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #188                // class java/lang/String
      14: astore_3
      15: aload_3
      16: iconst_0
      17: ldc           #201                // String
      19: aastore
      20: aload_3
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #207                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      29: checkcast     #32                 // class java/lang/Iterable
      32: astore_3
      33: iconst_0
      34: istore        4
      36: aload_3
      37: astore        5
      39: new           #209                // class java/util/ArrayList
      42: dup
      43: aload_3
      44: bipush        10
      46: invokestatic  #213                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      49: invokespecial #216                // Method java/util/ArrayList."<init>":(I)V
      52: checkcast     #218                // class java/util/Collection
      55: astore        6
      57: iconst_0
      58: istore        7
      60: aload         5
      62: invokeinterface #219,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      67: astore        8
      69: aload         8
      71: invokeinterface #68,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      76: ifeq          123
      79: aload         8
      81: invokeinterface #72,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      86: astore        9
      88: aload         6
      90: aload         9
      92: checkcast     #188                // class java/lang/String
      95: astore        10
      97: astore        12
      99: iconst_0
     100: istore        11
     102: aload         10
     104: invokestatic  #120                // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     107: nop
     108: invokestatic  #50                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     111: aload         12
     113: swap
     114: invokeinterface #223,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     119: pop
     120: goto          69
     123: aload         6
     125: checkcast     #58                 // class java/util/List
     128: nop
     129: astore_2
     130: aload_2
     131: iconst_0
     132: invokeinterface #227,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     137: checkcast     #74                 // class java/lang/Number
     140: invokevirtual #78                 // Method java/lang/Number.longValue:()J
     143: lstore_3
     144: aload_2
     145: iconst_1
     146: invokeinterface #227,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     151: checkcast     #74                 // class java/lang/Number
     154: invokevirtual #78                 // Method java/lang/Number.longValue:()J
     157: lstore        5
     159: aload_2
     160: iconst_2
     161: invokeinterface #227,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     166: checkcast     #74                 // class java/lang/Number
     169: invokevirtual #78                 // Method java/lang/Number.longValue:()J
     172: lstore        7
     174: aload_2
     175: iconst_3
     176: invokeinterface #227,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     181: checkcast     #74                 // class java/lang/Number
     184: invokevirtual #78                 // Method java/lang/Number.longValue:()J
     187: lstore        9
     189: lload_3
     190: lload         5
     192: lload         7
     194: lload         9
     196: invokestatic  #229                // Method syntheticDivision:(JJJJ)Ljava/util/Set;
     199: checkcast     #32                 // class java/lang/Iterable
     202: invokestatic  #233                // Method kotlin/collections/CollectionsKt.toList:(Ljava/lang/Iterable;)Ljava/util/List;
     205: checkcast     #32                 // class java/lang/Iterable
     208: invokestatic  #236                // Method kotlin/collections/CollectionsKt.sorted:(Ljava/lang/Iterable;)Ljava/util/List;
     211: checkcast     #32                 // class java/lang/Iterable
     214: ldc           #201                // String
     216: checkcast     #130                // class java/lang/CharSequence
     219: aconst_null
     220: aconst_null
     221: iconst_0
     222: aconst_null
     223: invokedynamic #242,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function1;
     228: bipush        30
     230: aconst_null
     231: invokestatic  #154                // Method kotlin/collections/CollectionsKt.joinToString$default:(Ljava/lang/Iterable;Ljava/lang/CharSequence;Ljava/lang/CharSequence;Ljava/lang/CharSequence;ILjava/lang/CharSequence;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/String;
     234: checkcast     #130                // class java/lang/CharSequence
     237: areturn
}


/**
* Verificador de soluciones para el problema del vendedor viajero
* Recibe como argumentos el archivo de instancia y el archivo de solucion
* Imprime si la solucion es correcta o no y muestra algunos errores si los hay
*/

import java.io.BufferedReader
import java.io.File
import java.io.FileReader

/**
* Funcion: distancia2D(p1: Pair<Int, Int>, p2: Pair<Int, Int>)
* Entradas: p1 y p2, dos pares de enteros que representan las coordenadas de dos puntos
* Salidas: La distancia euclidiana entre los dos puntos
* Descripcion: Calcula la distancia euclidiana entre dos puntos en el plano
*/
fun distancia2D(p1: Pair<Double, Double>, p2: Pair<Double, Double>): Double {
    val x = p1.first - p2.first
    val y = p1.second - p2.second
    return Math.sqrt((x * x + y * y).toDouble())
}

/**
* Funcion: distanciaRuta(ciudades: Array<Pair<Int, Int>>)
* Entradas: ciudades, un arreglo de pares de enteros que representan las coordenadas de las ciudades
* Salidas: La distancia total de la ruta que recorre todas las ciudades en el orden dado
* Descripcion: Calcula la distancia total de la ruta que recorre todas las ciudades en el orden dado
*/
fun distanciaRuta(ciudades: Array<Pair<Double, Double>>): Int {
    var acc: Double = 0.0
    for (i in 0 until ciudades.size - 1) {
        acc += distancia2D(ciudades[i], ciudades[i + 1])
    }
    return acc.toInt()
}

/**
* Funcion: checkSolution(ciudadesInstancia: Array<Pair<Int, Int>>, ciudadesSolucion: Array<Pair<Int, Int>>)
* Entradas: ciudadesInstancia, un arreglo de pares de enteros que representan las coordenadas de las ciudades de la instancia
*           ciudadesSolucion, un arreglo de pares de enteros que representan las coordenadas de las ciudades de la solucion
* Salidas: true si la solucion es correcta, false en otro caso
* Descripcion: Verifica que la solucion dada sea correcta
*/
fun checkSolution(indicesInstancia: Array<Int>, indicesSolucion: Array<Int>): Boolean {
    // Verificar que la solucion tenga todas las ciudades de la instancia
    for (i in 0 until indicesInstancia.size) {
        if (!indicesInstancia.contains(indicesSolucion[i])) {
            println("La solución no contiene la ciudad ${indicesSolucion[i] + 1}.")
            return false
        }
    }
    // Verificar que la solucion no tenga ciudades repetidas
    for (i in 0 until indicesSolucion.size) {
        for (j in i + 1 until indicesSolucion.size) {
            if (indicesSolucion[i] == indicesSolucion[j]) {
                println("La solución tiene la ciudad ${indicesSolucion[i] + 1} repetida.")
                return false
            }
        }
    }
    return true
}

/**
* Funcion: ciudadesFaltantes(ciudadesInstancia: Array<Pair<Int, Int>>, ciudadesSolucion: Array<Pair<Int, Int>>)
* Entradas: indicesInstancia, un arreglo de pares de enteros que representan las coordenadas de las ciudades de la instancia
*           indicesSolucion, un arreglo de pares de enteros que representan las coordenadas de las ciudades de la solucion
* Salidas: Imprime (en caso de que sea necesario) las ciudades que faltan en la solucion
*/
fun ciudadesFaltantes(indicesInstancia: Array<Int>, indicesSolucion: Array<Int>){
    for (i in 0 until indicesSolucion.size){
        if (!indicesInstancia.contains(indicesSolucion[i])){
            println("La ciudad ${indicesSolucion[i]+1} no se encuentra en la instancia")
        }
    }
}

fun main(args: Array<String>) {
    // args[0] es el archivo de instancia
    // args[1] es el archivo de solucion

    val archivoInstancia = File(args[0])
    val archivoSolucion = File(args[1])

    // Leer las ciudades de la instancia
    val lectorInstancia = BufferedReader(FileReader(archivoInstancia, Charsets.UTF_8))
    lectorInstancia.readLine() // Ignorar primera linea. Es el nombre del archivo
    lectorInstancia.readLine() // Ignorar segunda linea. Es el comentario
    val numeroCiudadesInstancia = lectorInstancia.readLine().split(":")[1].trim().toInt()
    lectorInstancia.readLine() // Ignorar linea. Es el comentario
    val indicesInstancia = Array<Int>(numeroCiudadesInstancia, { 0 })
    for (i in 0 until numeroCiudadesInstancia) {
        val indice = lectorInstancia.readLine().trim().toInt()
        indicesInstancia[i] = indice - 1
    }
    lectorInstancia.close()

    // Leer las ciudades de la solucion
    val lectorSolucion = BufferedReader(FileReader(archivoSolucion, Charsets.UTF_8))
    lectorSolucion.readLine() // Ignorar primera linea. Es el nombre del archivo
    lectorSolucion.readLine() // Ignorar segunda linea. Es el comentario
    val numeroCiudadesSolucion = lectorSolucion.readLine().split(":")[1].trim().toInt()
    lectorSolucion.readLine() // Ignorar linea. Es el comentario
    val indicesSolucion = Array<Int>(numeroCiudadesSolucion, { 0 })
    for (i in 0 until numeroCiudadesSolucion) {
        val indice = lectorSolucion.readLine().trim().toInt()
        indicesSolucion[i] = indice-1
    }
    lectorSolucion.close()

    // Verificar que la solucion sea correcta
    if (!checkSolution(indicesInstancia, indicesSolucion)) {
        // Si la solucion no es correcta, terminar el programa
        println("Solución incorrecta!!")
        ciudadesFaltantes(indicesInstancia, indicesSolucion)
        return
    }
    println("Es una solución correcta!!")
    println("Se visitaron todas las ciudades de la instancia, solo una vez cada una.")
}

Compiled from "VerificadorTSP.kt"
public final class VerificadorTSPKt {
  public static final double distancia2D(kotlin.Pair<java.lang.Double, java.lang.Double>, kotlin.Pair<java.lang.Double, java.lang.Double>);
    Code:
       0: aload_0
       1: ldc           #10                 // String p1
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String p2
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokevirtual #24                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      16: checkcast     #26                 // class java/lang/Number
      19: invokevirtual #30                 // Method java/lang/Number.doubleValue:()D
      22: aload_1
      23: invokevirtual #24                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
      26: checkcast     #26                 // class java/lang/Number
      29: invokevirtual #30                 // Method java/lang/Number.doubleValue:()D
      32: dsub
      33: dstore_2
      34: aload_0
      35: invokevirtual #33                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      38: checkcast     #26                 // class java/lang/Number
      41: invokevirtual #30                 // Method java/lang/Number.doubleValue:()D
      44: aload_1
      45: invokevirtual #33                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
      48: checkcast     #26                 // class java/lang/Number
      51: invokevirtual #30                 // Method java/lang/Number.doubleValue:()D
      54: dsub
      55: dstore        4
      57: dload_2
      58: dload_2
      59: dmul
      60: dload         4
      62: dload         4
      64: dmul
      65: dadd
      66: invokestatic  #39                 // Method java/lang/Math.sqrt:(D)D
      69: dreturn

  public static final int distanciaRuta(kotlin.Pair<java.lang.Double, java.lang.Double>[]);
    Code:
       0: aload_0
       1: ldc           #48                 // String ciudades
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: dconst_0
       7: dstore_1
       8: iconst_0
       9: istore_3
      10: aload_0
      11: arraylength
      12: iconst_1
      13: isub
      14: istore        4
      16: iload_3
      17: iload         4
      19: if_icmpge     42
      22: dload_1
      23: aload_0
      24: iload_3
      25: aaload
      26: aload_0
      27: iload_3
      28: iconst_1
      29: iadd
      30: aaload
      31: invokestatic  #50                 // Method distancia2D:(Lkotlin/Pair;Lkotlin/Pair;)D
      34: dadd
      35: dstore_1
      36: iinc          3, 1
      39: goto          16
      42: dload_1
      43: d2i
      44: ireturn

  public static final boolean checkSolution(java.lang.Integer[], java.lang.Integer[]);
    Code:
       0: aload_0
       1: ldc           #58                 // String indicesInstancia
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #60                 // String indicesSolucion
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: aload_0
      15: arraylength
      16: istore_3
      17: iload_2
      18: iload_3
      19: if_icmpge     78
      22: aload_0
      23: aload_1
      24: iload_2
      25: aaload
      26: invokestatic  #66                 // Method kotlin/collections/ArraysKt.contains:([Ljava/lang/Object;Ljava/lang/Object;)Z
      29: ifne          72
      32: new           #68                 // class java/lang/StringBuilder
      35: dup
      36: invokespecial #72                 // Method java/lang/StringBuilder."<init>":()V
      39: ldc           #74                 // String La solución no contiene la ciudad
      41: invokevirtual #78                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      44: aload_1
      45: iload_2
      46: aaload
      47: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
      50: iconst_1
      51: iadd
      52: invokevirtual #87                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      55: bipush        46
      57: invokevirtual #90                 // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
      60: invokevirtual #94                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      63: getstatic     #100                // Field java/lang/System.out:Ljava/io/PrintStream;
      66: swap
      67: invokevirtual #106                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      70: iconst_0
      71: ireturn
      72: iinc          2, 1
      75: goto          17
      78: iconst_0
      79: istore_2
      80: aload_1
      81: arraylength
      82: istore_3
      83: iload_2
      84: iload_3
      85: if_icmpge     172
      88: iload_2
      89: iconst_1
      90: iadd
      91: istore        4
      93: aload_1
      94: arraylength
      95: istore        5
      97: iload         4
      99: iload         5
     101: if_icmpge     166
     104: aload_1
     105: iload_2
     106: aaload
     107: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     110: aload_1
     111: iload         4
     113: aaload
     114: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     117: if_icmpne     160
     120: new           #68                 // class java/lang/StringBuilder
     123: dup
     124: invokespecial #72                 // Method java/lang/StringBuilder."<init>":()V
     127: ldc           #108                // String La solución tiene la ciudad
     129: invokevirtual #78                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     132: aload_1
     133: iload_2
     134: aaload
     135: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
     138: iconst_1
     139: iadd
     140: invokevirtual #87                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
     143: ldc           #110                // String  repetida.
     145: invokevirtual #78                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     148: invokevirtual #94                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     151: getstatic     #100                // Field java/lang/System.out:Ljava/io/PrintStream;
     154: swap
     155: invokevirtual #106                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     158: iconst_0
     159: ireturn
     160: iinc          4, 1
     163: goto          97
     166: iinc          2, 1
     169: goto          83
     172: iconst_1
     173: ireturn

  public static final void ciudadesFaltantes(java.lang.Integer[], java.lang.Integer[]);
    Code:
       0: aload_0
       1: ldc           #58                 // String indicesInstancia
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #60                 // String indicesSolucion
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iconst_0
      13: istore_2
      14: aload_1
      15: arraylength
      16: istore_3
      17: iload_2
      18: iload_3
      19: if_icmpge     76
      22: aload_0
      23: aload_1
      24: iload_2
      25: aaload
      26: invokestatic  #66                 // Method kotlin/collections/ArraysKt.contains:([Ljava/lang/Object;Ljava/lang/Object;)Z
      29: ifne          70
      32: new           #68                 // class java/lang/StringBuilder
      35: dup
      36: invokespecial #72                 // Method java/lang/StringBuilder."<init>":()V
      39: ldc           #116                // String La ciudad
      41: invokevirtual #78                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      44: aload_1
      45: iload_2
      46: aaload
      47: invokevirtual #84                 // Method java/lang/Integer.intValue:()I
      50: iconst_1
      51: iadd
      52: invokevirtual #87                 // Method java/lang/StringBuilder.append:(I)Ljava/lang/StringBuilder;
      55: ldc           #118                // String  no se encuentra en la instancia
      57: invokevirtual #78                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      60: invokevirtual #94                 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      63: getstatic     #100                // Field java/lang/System.out:Ljava/io/PrintStream;
      66: swap
      67: invokevirtual #106                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      70: iinc          2, 1
      73: goto          17
      76: return

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #122                // String args
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #124                // class java/io/File
       9: dup
      10: aload_0
      11: iconst_0
      12: aaload
      13: invokespecial #127                // Method java/io/File."<init>":(Ljava/lang/String;)V
      16: astore_1
      17: new           #124                // class java/io/File
      20: dup
      21: aload_0
      22: iconst_1
      23: aaload
      24: invokespecial #127                // Method java/io/File."<init>":(Ljava/lang/String;)V
      27: astore_2
      28: new           #129                // class java/io/BufferedReader
      31: dup
      32: new           #131                // class java/io/FileReader
      35: dup
      36: aload_1
      37: getstatic     #137                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      40: invokespecial #140                // Method java/io/FileReader."<init>":(Ljava/io/File;Ljava/nio/charset/Charset;)V
      43: checkcast     #142                // class java/io/Reader
      46: invokespecial #145                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V
      49: astore_3
      50: aload_3
      51: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
      54: pop
      55: aload_3
      56: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
      59: pop
      60: aload_3
      61: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
      64: dup
      65: ldc           #150                // String readLine(...)
      67: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      70: checkcast     #155                // class java/lang/CharSequence
      73: iconst_1
      74: anewarray     #157                // class java/lang/String
      77: astore        5
      79: aload         5
      81: iconst_0
      82: ldc           #159                // String :
      84: aastore
      85: aload         5
      87: iconst_0
      88: iconst_0
      89: bipush        6
      91: aconst_null
      92: invokestatic  #165                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      95: iconst_1
      96: invokeinterface #171,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     101: checkcast     #157                // class java/lang/String
     104: checkcast     #155                // class java/lang/CharSequence
     107: invokestatic  #175                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     110: invokevirtual #176                // Method java/lang/Object.toString:()Ljava/lang/String;
     113: invokestatic  #180                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     116: istore        4
     118: aload_3
     119: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     122: pop
     123: iconst_0
     124: istore        6
     126: iload         4
     128: anewarray     #80                 // class java/lang/Integer
     131: astore        7
     133: iload         6
     135: iload         4
     137: if_icmpge     159
     140: iload         6
     142: istore        8
     144: aload         7
     146: iload         8
     148: iconst_0
     149: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     152: aastore
     153: iinc          6, 1
     156: goto          133
     159: aload         7
     161: astore        5
     163: iconst_0
     164: istore        6
     166: iload         6
     168: iload         4
     170: if_icmpge     215
     173: aload_3
     174: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     177: dup
     178: ldc           #150                // String readLine(...)
     180: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     183: checkcast     #155                // class java/lang/CharSequence
     186: invokestatic  #175                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     189: invokevirtual #176                // Method java/lang/Object.toString:()Ljava/lang/String;
     192: invokestatic  #180                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     195: istore        7
     197: aload         5
     199: iload         6
     201: iload         7
     203: iconst_1
     204: isub
     205: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     208: aastore
     209: iinc          6, 1
     212: goto          166
     215: aload_3
     216: invokevirtual #187                // Method java/io/BufferedReader.close:()V
     219: new           #129                // class java/io/BufferedReader
     222: dup
     223: new           #131                // class java/io/FileReader
     226: dup
     227: aload_2
     228: getstatic     #137                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
     231: invokespecial #140                // Method java/io/FileReader."<init>":(Ljava/io/File;Ljava/nio/charset/Charset;)V
     234: checkcast     #142                // class java/io/Reader
     237: invokespecial #145                // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V
     240: astore        6
     242: aload         6
     244: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     247: pop
     248: aload         6
     250: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     253: pop
     254: aload         6
     256: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     259: dup
     260: ldc           #150                // String readLine(...)
     262: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     265: checkcast     #155                // class java/lang/CharSequence
     268: iconst_1
     269: anewarray     #157                // class java/lang/String
     272: astore        8
     274: aload         8
     276: iconst_0
     277: ldc           #159                // String :
     279: aastore
     280: aload         8
     282: iconst_0
     283: iconst_0
     284: bipush        6
     286: aconst_null
     287: invokestatic  #165                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     290: iconst_1
     291: invokeinterface #171,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     296: checkcast     #157                // class java/lang/String
     299: checkcast     #155                // class java/lang/CharSequence
     302: invokestatic  #175                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     305: invokevirtual #176                // Method java/lang/Object.toString:()Ljava/lang/String;
     308: invokestatic  #180                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     311: istore        7
     313: aload         6
     315: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     318: pop
     319: iconst_0
     320: istore        9
     322: iload         7
     324: anewarray     #80                 // class java/lang/Integer
     327: astore        10
     329: iload         9
     331: iload         7
     333: if_icmpge     355
     336: iload         9
     338: istore        11
     340: aload         10
     342: iload         11
     344: iconst_0
     345: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     348: aastore
     349: iinc          9, 1
     352: goto          329
     355: aload         10
     357: astore        8
     359: iconst_0
     360: istore        9
     362: iload         9
     364: iload         7
     366: if_icmpge     412
     369: aload         6
     371: invokevirtual #148                // Method java/io/BufferedReader.readLine:()Ljava/lang/String;
     374: dup
     375: ldc           #150                // String readLine(...)
     377: invokestatic  #153                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     380: checkcast     #155                // class java/lang/CharSequence
     383: invokestatic  #175                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     386: invokevirtual #176                // Method java/lang/Object.toString:()Ljava/lang/String;
     389: invokestatic  #180                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     392: istore        10
     394: aload         8
     396: iload         9
     398: iload         10
     400: iconst_1
     401: isub
     402: invokestatic  #184                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     405: aastore
     406: iinc          9, 1
     409: goto          362
     412: aload         6
     414: invokevirtual #187                // Method java/io/BufferedReader.close:()V
     417: aload         5
     419: aload         8
     421: invokestatic  #189                // Method checkSolution:([Ljava/lang/Integer;[Ljava/lang/Integer;)Z
     424: ifne          444
     427: ldc           #191                // String Solución incorrecta!!
     429: getstatic     #100                // Field java/lang/System.out:Ljava/io/PrintStream;
     432: swap
     433: invokevirtual #106                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     436: aload         5
     438: aload         8
     440: invokestatic  #193                // Method ciudadesFaltantes:([Ljava/lang/Integer;[Ljava/lang/Integer;)V
     443: return
     444: ldc           #195                // String Es una solución correcta!!
     446: getstatic     #100                // Field java/lang/System.out:Ljava/io/PrintStream;
     449: swap
     450: invokevirtual #106                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     453: ldc           #197                // String Se visitaron todas las ciudades de la instancia, solo una vez cada una.
     455: getstatic     #100                // Field java/lang/System.out:Ljava/io/PrintStream;
     458: swap
     459: invokevirtual #106                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     462: return
}


fun swapDual(A: Array<Int>, B: Array<Int>, i: Int, j: Int): Unit {
    val aux: Int = A[i]
    A[i] = A[j]
    A[j] = aux
    val temp: Int = B[i]
    B[i] = B[j]
    B[j] = temp
}

fun compararEstudiantes(A: Array<Int>, B: Array<Int>, i: Int, j: Int): Boolean{
    return A[i] < A[j] || (A[i] == A[j] && B[i] <= B[j])
}

fun parent(i: Int): Int {
    return i / 2
}

fun left(i: Int): Int {
    return 2 * i
}

fun right(i: Int): Int {
    return 2 * i + 1
}

fun maxHeapify(A: Array<Int>, B: Array<Int>, i: Int, heapSize: Int): Unit {
    val l: Int = left(i)
    val r: Int = right(i)
    var largest: Int = i
    if (l <= heapSize && compararEstudiantes(A, B, i, l)) {
        largest = l
    }
    if (r <= heapSize && compararEstudiantes(A, B, largest, r)) {
        largest = r
    }
    if (largest != i) {
        swapDual(A, B, i, largest)
        maxHeapify(A, B, largest, heapSize)
    }
}

fun buildMaxHeap(A: Array<Int>, B: Array<Int>, heapSize: Int): Unit {
    for (i in heapSize / 2 downTo 0) {
        maxHeapify(A, B, i, heapSize)
    }
}

fun heapSort(A: Array<Int>, B: Array<Int>): Unit {
    val heapSize: Int = A.size - 1
    buildMaxHeap(A, B, heapSize)
    for (i in heapSize downTo 1) {
        swapDual(A, B, 0, i)
        maxHeapify(A, B, 0, i - 1)
    }
}

fun main(args: Array<String>) {
    val cupos = args[0].toInt()
    if (cupos < 0){
        throw Exception("El número de cupos debe ser positivo")
    }
    else if (cupos == 0){
        println("NO HAY CUPOS")
        return
    }
    if ((args.size)%2 != 1){
        throw Exception("Falta un estudiante por NFC o carnet")
    }
    val numeroEstudiantes = (args.size - 1)/2
    if (cupos >= numeroEstudiantes){
        println("TODOS FUERON ADMITIDOS")
        return
    }
    val carnets: Array<Int> = Array(numeroEstudiantes){0}
    val NCFs: Array<Int> = Array(numeroEstudiantes){0}
    for (i in 0 until numeroEstudiantes){
        carnets[i] = args[i*2 + 1].toInt()
        NCFs[i] = args[i*2 + 2].toInt()
    }
    heapSort(NCFs, carnets)
    for (i in 0 until cupos){
        println(carnets[i])
    }
}

Compiled from "AsignarCupo.kt"
public final class AsignarCupoKt {
  public static final void swapDual(java.lang.Integer[], java.lang.Integer[], int, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String A
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String B
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iload_2
      14: aaload
      15: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      18: istore        4
      20: aload_0
      21: iload_2
      22: aload_0
      23: iload_3
      24: aaload
      25: aastore
      26: aload_0
      27: iload_3
      28: iload         4
      30: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      33: aastore
      34: aload_1
      35: iload_2
      36: aaload
      37: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      40: istore        5
      42: aload_1
      43: iload_2
      44: aload_1
      45: iload_3
      46: aaload
      47: aastore
      48: aload_1
      49: iload_3
      50: iload         5
      52: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      55: aastore
      56: return

  public static final boolean compararEstudiantes(java.lang.Integer[], java.lang.Integer[], int, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String A
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String B
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: iload_2
      14: aaload
      15: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      18: aload_0
      19: iload_3
      20: aaload
      21: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      24: if_icmplt     57
      27: aload_0
      28: iload_2
      29: aaload
      30: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      33: aload_0
      34: iload_3
      35: aaload
      36: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      39: if_icmpne     61
      42: aload_1
      43: iload_2
      44: aaload
      45: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      48: aload_1
      49: iload_3
      50: aaload
      51: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
      54: if_icmpgt     61
      57: iconst_1
      58: goto          62
      61: iconst_0
      62: ireturn

  public static final int parent(int);
    Code:
       0: iload_0
       1: iconst_2
       2: idiv
       3: ireturn

  public static final int left(int);
    Code:
       0: iconst_2
       1: iload_0
       2: imul
       3: ireturn

  public static final int right(int);
    Code:
       0: iconst_2
       1: iload_0
       2: imul
       3: iconst_1
       4: iadd
       5: ireturn

  public static final void maxHeapify(java.lang.Integer[], java.lang.Integer[], int, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String A
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String B
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: invokestatic  #42                 // Method left:(I)I
      16: istore        4
      18: iload_2
      19: invokestatic  #44                 // Method right:(I)I
      22: istore        5
      24: iload_2
      25: istore        6
      27: iload         4
      29: iload_3
      30: if_icmpgt     48
      33: aload_0
      34: aload_1
      35: iload_2
      36: iload         4
      38: invokestatic  #46                 // Method compararEstudiantes:([Ljava/lang/Integer;[Ljava/lang/Integer;II)Z
      41: ifeq          48
      44: iload         4
      46: istore        6
      48: iload         5
      50: iload_3
      51: if_icmpgt     70
      54: aload_0
      55: aload_1
      56: iload         6
      58: iload         5
      60: invokestatic  #46                 // Method compararEstudiantes:([Ljava/lang/Integer;[Ljava/lang/Integer;II)Z
      63: ifeq          70
      66: iload         5
      68: istore        6
      70: iload         6
      72: iload_2
      73: if_icmpeq     92
      76: aload_0
      77: aload_1
      78: iload_2
      79: iload         6
      81: invokestatic  #48                 // Method swapDual:([Ljava/lang/Integer;[Ljava/lang/Integer;II)V
      84: aload_0
      85: aload_1
      86: iload         6
      88: iload_3
      89: invokestatic  #50                 // Method maxHeapify:([Ljava/lang/Integer;[Ljava/lang/Integer;II)V
      92: return

  public static final void buildMaxHeap(java.lang.Integer[], java.lang.Integer[], int);
    Code:
       0: aload_0
       1: ldc           #9                  // String A
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String B
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: iload_2
      13: iconst_2
      14: idiv
      15: istore_3
      16: iconst_m1
      17: iload_3
      18: if_icmpge     34
      21: aload_0
      22: aload_1
      23: iload_3
      24: iload_2
      25: invokestatic  #50                 // Method maxHeapify:([Ljava/lang/Integer;[Ljava/lang/Integer;II)V
      28: iinc          3, -1
      31: goto          16
      34: return

  public static final void heapSort(java.lang.Integer[], java.lang.Integer[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String A
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String B
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: arraylength
      14: iconst_1
      15: isub
      16: istore_2
      17: aload_0
      18: aload_1
      19: iload_2
      20: invokestatic  #60                 // Method buildMaxHeap:([Ljava/lang/Integer;[Ljava/lang/Integer;I)V
      23: iload_2
      24: istore_3
      25: iconst_0
      26: iload_3
      27: if_icmpge     52
      30: aload_0
      31: aload_1
      32: iconst_0
      33: iload_3
      34: invokestatic  #48                 // Method swapDual:([Ljava/lang/Integer;[Ljava/lang/Integer;II)V
      37: aload_0
      38: aload_1
      39: iconst_0
      40: iload_3
      41: iconst_1
      42: isub
      43: invokestatic  #50                 // Method maxHeapify:([Ljava/lang/Integer;[Ljava/lang/Integer;II)V
      46: iinc          3, -1
      49: goto          25
      52: return

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #64                 // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: iconst_0
       8: aaload
       9: invokestatic  #68                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      12: istore_1
      13: iload_1
      14: ifge          27
      17: new           #70                 // class java/lang/Exception
      20: dup
      21: ldc           #72                 // String El número de cupos debe ser positivo
      23: invokespecial #76                 // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
      26: athrow
      27: iload_1
      28: ifne          41
      31: ldc           #78                 // String NO HAY CUPOS
      33: getstatic     #84                 // Field java/lang/System.out:Ljava/io/PrintStream;
      36: swap
      37: invokevirtual #90                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      40: return
      41: aload_0
      42: arraylength
      43: iconst_2
      44: irem
      45: iconst_1
      46: if_icmpeq     59
      49: new           #70                 // class java/lang/Exception
      52: dup
      53: ldc           #92                 // String Falta un estudiante por NFC o carnet
      55: invokespecial #76                 // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
      58: athrow
      59: aload_0
      60: arraylength
      61: iconst_1
      62: isub
      63: iconst_2
      64: idiv
      65: istore_2
      66: iload_1
      67: iload_2
      68: if_icmplt     81
      71: ldc           #94                 // String TODOS FUERON ADMITIDOS
      73: getstatic     #84                 // Field java/lang/System.out:Ljava/io/PrintStream;
      76: swap
      77: invokevirtual #90                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      80: return
      81: iconst_0
      82: istore        4
      84: iload_2
      85: anewarray     #19                 // class java/lang/Integer
      88: astore        5
      90: iload         4
      92: iload_2
      93: if_icmpge     115
      96: iload         4
      98: istore        6
     100: aload         5
     102: iload         6
     104: iconst_0
     105: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aastore
     109: iinc          4, 1
     112: goto          90
     115: aload         5
     117: astore_3
     118: iconst_0
     119: istore        5
     121: iload_2
     122: anewarray     #19                 // class java/lang/Integer
     125: astore        6
     127: iload         5
     129: iload_2
     130: if_icmpge     152
     133: iload         5
     135: istore        7
     137: aload         6
     139: iload         7
     141: iconst_0
     142: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     145: aastore
     146: iinc          5, 1
     149: goto          127
     152: aload         6
     154: astore        4
     156: iconst_0
     157: istore        5
     159: iload         5
     161: iload_2
     162: if_icmpge     208
     165: aload_3
     166: iload         5
     168: aload_0
     169: iload         5
     171: iconst_2
     172: imul
     173: iconst_1
     174: iadd
     175: aaload
     176: invokestatic  #68                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     179: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     182: aastore
     183: aload         4
     185: iload         5
     187: aload_0
     188: iload         5
     190: iconst_2
     191: imul
     192: iconst_2
     193: iadd
     194: aaload
     195: invokestatic  #68                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     198: invokestatic  #27                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     201: aastore
     202: iinc          5, 1
     205: goto          159
     208: aload         4
     210: aload_3
     211: invokestatic  #96                 // Method heapSort:([Ljava/lang/Integer;[Ljava/lang/Integer;)V
     214: iconst_0
     215: istore        5
     217: iload         5
     219: iload_1
     220: if_icmpge     246
     223: aload_3
     224: iload         5
     226: aaload
     227: invokevirtual #23                 // Method java/lang/Integer.intValue:()I
     230: istore        6
     232: getstatic     #84                 // Field java/lang/System.out:Ljava/io/PrintStream;
     235: iload         6
     237: invokevirtual #99                 // Method java/io/PrintStream.println:(I)V
     240: iinc          5, 1
     243: goto          217
     246: return
}