import java.lang.Math.abs
import java.lang.Math.pow
import kotlin.math.roundToInt
import kotlin.math.sqrt

fun main(args: Array<String>) {
    println(findManhattanDistance(368078))
}

fun findManhattanDistance(start: Int) : Int {
    val size = getSpiralArraySize(start)
    val center = getSpiralArrayCenter(size) // q1, q2 == center, center
    val last = (pow((size).toDouble(), 2.0)).toInt()
    val bottomLeft = last - size + 1
    val topLeft = bottomLeft - size + 1
    val topRight = topLeft - size + 1

    /*
    1,1 ... size,1
    .
    .
    .
    1,size ... size,size
     */
    val location =  when {
        start >= bottomLeft -> Pair(size - (last - start), size)
        start >= topLeft -> Pair(1, size - (bottomLeft - start))
        start >= topRight -> Pair(topLeft - start + 1, 1)
        else -> Pair(size, topRight - start + 1)
    }

    return abs(location.first - center) + abs(location.second - center)
}

fun getSpiralArrayCenter(size: Int): Int {
    val center = roundUp(size / 2.0) // q1, q2 == center, center
    return center
}

fun getSpiralArraySize(start: Int): Int {
    val sqrtStart = roundUp(sqrt(start.toDouble()))
    val size = if (sqrtStart % 2 == 0) sqrtStart + 1 else sqrtStart
    return size
}

fun roundUp(num : Double) : Int {
    val rounded = num.roundToInt()

    return if (num > rounded) rounded + 1 else rounded
}

Compiled from "star05.kt"
public final class Star05Kt {
  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: ldc           #16                 // int 368078
       8: invokestatic  #20                 // Method findManhattanDistance:(I)I
      11: istore_1
      12: getstatic     #26                 // Field java/lang/System.out:Ljava/io/PrintStream;
      15: iload_1
      16: invokevirtual #32                 // Method java/io/PrintStream.println:(I)V
      19: return

  public static final int findManhattanDistance(int);
    Code:
       0: iload_0
       1: invokestatic  #36                 // Method getSpiralArraySize:(I)I
       4: istore_1
       5: iload_1
       6: invokestatic  #39                 // Method getSpiralArrayCenter:(I)I
       9: istore_2
      10: iload_1
      11: i2d
      12: ldc2_w        #40                 // double 2.0d
      15: invokestatic  #47                 // Method java/lang/Math.pow:(DD)D
      18: d2i
      19: istore_3
      20: iload_3
      21: iload_1
      22: isub
      23: iconst_1
      24: iadd
      25: istore        4
      27: iload         4
      29: iload_1
      30: isub
      31: iconst_1
      32: iadd
      33: istore        5
      35: iload         5
      37: iload_1
      38: isub
      39: iconst_1
      40: iadd
      41: istore        6
      43: nop
      44: iload_0
      45: iload         4
      47: if_icmplt     72
      50: new           #49                 // class kotlin/Pair
      53: dup
      54: iload_1
      55: iload_3
      56: iload_0
      57: isub
      58: isub
      59: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      62: iload_1
      63: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      66: invokespecial #59                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      69: goto          150
      72: iload_0
      73: iload         5
      75: if_icmplt     101
      78: new           #49                 // class kotlin/Pair
      81: dup
      82: iconst_1
      83: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      86: iload_1
      87: iload         4
      89: iload_0
      90: isub
      91: isub
      92: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      95: invokespecial #59                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
      98: goto          150
     101: iload_0
     102: iload         6
     104: if_icmplt     130
     107: new           #49                 // class kotlin/Pair
     110: dup
     111: iload         5
     113: iload_0
     114: isub
     115: iconst_1
     116: iadd
     117: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     120: iconst_1
     121: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     124: invokespecial #59                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     127: goto          150
     130: new           #49                 // class kotlin/Pair
     133: dup
     134: iload_1
     135: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     138: iload         6
     140: iload_0
     141: isub
     142: iconst_1
     143: iadd
     144: invokestatic  #55                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     147: invokespecial #59                 // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     150: astore        7
     152: aload         7
     154: invokevirtual #63                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     157: checkcast     #65                 // class java/lang/Number
     160: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     163: iload_2
     164: isub
     165: invokestatic  #72                 // Method java/lang/Math.abs:(I)I
     168: aload         7
     170: invokevirtual #75                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     173: checkcast     #65                 // class java/lang/Number
     176: invokevirtual #69                 // Method java/lang/Number.intValue:()I
     179: iload_2
     180: isub
     181: invokestatic  #72                 // Method java/lang/Math.abs:(I)I
     184: iadd
     185: ireturn

  public static final int getSpiralArrayCenter(int);
    Code:
       0: iload_0
       1: i2d
       2: ldc2_w        #40                 // double 2.0d
       5: ddiv
       6: invokestatic  #89                 // Method roundUp:(D)I
       9: istore_1
      10: iload_1
      11: ireturn

  public static final int getSpiralArraySize(int);
    Code:
       0: iload_0
       1: i2d
       2: invokestatic  #93                 // Method java/lang/Math.sqrt:(D)D
       5: invokestatic  #89                 // Method roundUp:(D)I
       8: istore_1
       9: iload_1
      10: iconst_2
      11: irem
      12: ifne          21
      15: iload_1
      16: iconst_1
      17: iadd
      18: goto          22
      21: iload_1
      22: istore_2
      23: iload_2
      24: ireturn

  public static final int roundUp(double);
    Code:
       0: dload_0
       1: invokestatic  #99                 // Method kotlin/math/MathKt.roundToInt:(D)I
       4: istore_2
       5: dload_0
       6: iload_2
       7: i2d
       8: dcmpl
       9: ifle          18
      12: iload_2
      13: iconst_1
      14: iadd
      15: goto          19
      18: iload_2
      19: ireturn
}


import java.io.File

data class LongNumberProblem(
    var n: Int,
    var a: String,
    var fm: List<Int>,
)

fun main(args: Array<String>) {
    // read input
//    val n = readLine()!!.toInt()
//    val a = readLine()!!
//    val fm = readLine()!!.split(" ").map { it.toInt() }

    // read input from file
    // Using BufferedReader
    val bf = File("./long-number01.txt").bufferedReader()
    val problems = mutableListOf<LongNumberProblem>()
    var i = 0
    var n: Int = 0
    var a: String = ""
    var fm: List<Int> = emptyList()
    bf.forEachLine {
        when (i++ % 3) {
            0 -> n = it.toInt()
            1 -> a = it
            2 -> {
                fm = it.split(" ").map { c -> c.toInt() }
                problems.add(LongNumberProblem(n, a, fm))
            }
        }
    }
//    bf.useLines { lines ->
//        lines.forEach {
//            when (i++ % 3) {
//                0 -> n = it.toInt()
//                1 -> a = it
//                2 -> {
//                    fm = it.split(" ").map { c -> c.toInt() }
//                    problems.add(LongNumberProblem(n, a, fm))
//                }
//            }
//        }
//    }

    for (p in problems) {
        println(solveLongNumber(p))
    }
}

private fun solveLongNumber(problem: LongNumberProblem): String {
    fun f(c: Char) = '0' + problem.fm[c - '1']

    // greedy maximum search
    val s = problem.a.indexOfFirst { f(it) > it }
        .takeIf { it >= 0 } ?: problem.a.length
    val e = problem.a.withIndex().indexOfFirst { (i, c) -> i > s && f(c) < c }
        .takeIf { it >= 0 } ?: problem.a.length
    val result = problem.a.slice(0 until s) +
            problem.a.slice(s until e).map { f(it) }.joinToString("") +
            problem.a.slice(e until problem.a.length)
    return result
}

Compiled from "Main.kt"
public final class MainKt {
  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: new           #17                 // class java/io/File
       9: dup
      10: ldc           #19                 // String ./long-number01.txt
      12: invokespecial #23                 // Method java/io/File."<init>":(Ljava/lang/String;)V
      15: astore_2
      16: getstatic     #29                 // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      19: astore_3
      20: sipush        8192
      23: istore        4
      25: aload_2
      26: astore        5
      28: new           #31                 // class java/io/InputStreamReader
      31: dup
      32: new           #33                 // class java/io/FileInputStream
      35: dup
      36: aload         5
      38: invokespecial #36                 // Method java/io/FileInputStream."<init>":(Ljava/io/File;)V
      41: checkcast     #38                 // class java/io/InputStream
      44: aload_3
      45: invokespecial #41                 // Method java/io/InputStreamReader."<init>":(Ljava/io/InputStream;Ljava/nio/charset/Charset;)V
      48: checkcast     #43                 // class java/io/Reader
      51: astore        5
      53: aload         5
      55: instanceof    #45                 // class java/io/BufferedReader
      58: ifeq          69
      61: aload         5
      63: checkcast     #45                 // class java/io/BufferedReader
      66: goto          80
      69: new           #45                 // class java/io/BufferedReader
      72: dup
      73: aload         5
      75: iload         4
      77: invokespecial #48                 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;I)V
      80: astore_1
      81: new           #50                 // class java/util/ArrayList
      84: dup
      85: invokespecial #53                 // Method java/util/ArrayList."<init>":()V
      88: checkcast     #55                 // class java/util/List
      91: astore_2
      92: new           #57                 // class kotlin/jvm/internal/Ref$IntRef
      95: dup
      96: invokespecial #58                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
      99: astore_3
     100: new           #57                 // class kotlin/jvm/internal/Ref$IntRef
     103: dup
     104: invokespecial #58                 // Method kotlin/jvm/internal/Ref$IntRef."<init>":()V
     107: astore        4
     109: new           #60                 // class kotlin/jvm/internal/Ref$ObjectRef
     112: dup
     113: invokespecial #61                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     116: astore        5
     118: aload         5
     120: ldc           #63                 // String
     122: putfield      #67                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     125: new           #60                 // class kotlin/jvm/internal/Ref$ObjectRef
     128: dup
     129: invokespecial #61                 // Method kotlin/jvm/internal/Ref$ObjectRef."<init>":()V
     132: astore        6
     134: aload         6
     136: invokestatic  #73                 // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
     139: putfield      #67                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     142: aload_1
     143: checkcast     #43                 // class java/io/Reader
     146: aload_3
     147: aload         4
     149: aload         5
     151: aload         6
     153: aload_2
     154: invokedynamic #93,  0             // InvokeDynamic #0:invoke:(Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$IntRef;Lkotlin/jvm/internal/Ref$ObjectRef;Lkotlin/jvm/internal/Ref$ObjectRef;Ljava/util/List;)Lkotlin/jvm/functions/Function1;
     159: invokestatic  #99                 // Method kotlin/io/TextStreamsKt.forEachLine:(Ljava/io/Reader;Lkotlin/jvm/functions/Function1;)V
     162: aload_2
     163: invokeinterface #103,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     168: astore        7
     170: aload         7
     172: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     177: ifeq          207
     180: aload         7
     182: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     187: checkcast     #115                // class LongNumberProblem
     190: astore        8
     192: aload         8
     194: invokestatic  #119                // Method solveLongNumber:(LLongNumberProblem;)Ljava/lang/String;
     197: getstatic     #125                // Field java/lang/System.out:Ljava/io/PrintStream;
     200: swap
     201: invokevirtual #131                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     204: goto          170
     207: return

  private static final java.lang.String solveLongNumber(LongNumberProblem);
    Code:
       0: aload_0
       1: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
       4: checkcast     #153                // class java/lang/CharSequence
       7: astore_3
       8: iconst_0
       9: istore        4
      11: iconst_0
      12: istore        5
      14: aload_3
      15: invokeinterface #157,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      20: istore        6
      22: iload         5
      24: iload         6
      26: if_icmpge     75
      29: aload_3
      30: iload         5
      32: invokeinterface #161,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      37: istore        7
      39: iconst_0
      40: istore        8
      42: aload_0
      43: iload         7
      45: invokestatic  #165                // Method solveLongNumber$f:(LLongNumberProblem;C)C
      48: iload         7
      50: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
      53: ifle          60
      56: iconst_1
      57: goto          61
      60: iconst_0
      61: ifeq          69
      64: iload         5
      66: goto          76
      69: iinc          5, 1
      72: goto          22
      75: iconst_m1
      76: invokestatic  #175                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      79: astore_3
      80: aload_3
      81: checkcast     #177                // class java/lang/Number
      84: invokevirtual #180                // Method java/lang/Number.intValue:()I
      87: istore        4
      89: iconst_0
      90: istore        5
      92: iload         4
      94: iflt          101
      97: iconst_1
      98: goto          102
     101: iconst_0
     102: ifeq          109
     105: aload_3
     106: goto          110
     109: aconst_null
     110: dup
     111: ifnull        120
     114: invokevirtual #181                // Method java/lang/Integer.intValue:()I
     117: goto          128
     120: pop
     121: aload_0
     122: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     125: invokevirtual #184                // Method java/lang/String.length:()I
     128: istore_1
     129: aload_0
     130: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     133: checkcast     #153                // class java/lang/CharSequence
     136: invokestatic  #190                // Method kotlin/text/StringsKt.withIndex:(Ljava/lang/CharSequence;)Ljava/lang/Iterable;
     139: astore        4
     141: iconst_0
     142: istore        5
     144: iconst_0
     145: istore        6
     147: aload         4
     149: invokeinterface #193,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     154: astore        7
     156: aload         7
     158: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     163: ifeq          252
     166: aload         7
     168: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     173: astore        8
     175: iload         6
     177: ifge          183
     180: invokestatic  #196                // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     183: aload         8
     185: checkcast     #198                // class kotlin/collections/IndexedValue
     188: astore        9
     190: iconst_0
     191: istore        10
     193: aload         9
     195: invokevirtual #201                // Method kotlin/collections/IndexedValue.component1:()I
     198: istore        11
     200: aload         9
     202: invokevirtual #204                // Method kotlin/collections/IndexedValue.component2:()Ljava/lang/Object;
     205: checkcast     #206                // class java/lang/Character
     208: invokevirtual #210                // Method java/lang/Character.charValue:()C
     211: istore        12
     213: iload         11
     215: iload_1
     216: if_icmple     237
     219: aload_0
     220: iload         12
     222: invokestatic  #165                // Method solveLongNumber$f:(LLongNumberProblem;C)C
     225: iload         12
     227: invokestatic  #169                // Method kotlin/jvm/internal/Intrinsics.compare:(II)I
     230: ifge          237
     233: iconst_1
     234: goto          238
     237: iconst_0
     238: ifeq          246
     241: iload         6
     243: goto          253
     246: iinc          6, 1
     249: goto          156
     252: iconst_m1
     253: invokestatic  #175                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     256: astore        4
     258: aload         4
     260: checkcast     #177                // class java/lang/Number
     263: invokevirtual #180                // Method java/lang/Number.intValue:()I
     266: istore        5
     268: iconst_0
     269: istore        6
     271: iload         5
     273: iflt          280
     276: iconst_1
     277: goto          281
     280: iconst_0
     281: ifeq          289
     284: aload         4
     286: goto          290
     289: aconst_null
     290: dup
     291: ifnull        300
     294: invokevirtual #181                // Method java/lang/Integer.intValue:()I
     297: goto          308
     300: pop
     301: aload_0
     302: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     305: invokevirtual #184                // Method java/lang/String.length:()I
     308: istore_2
     309: new           #212                // class java/lang/StringBuilder
     312: dup
     313: invokespecial #213                // Method java/lang/StringBuilder."<init>":()V
     316: aload_0
     317: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     320: iconst_0
     321: iload_1
     322: invokestatic  #219                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     325: invokestatic  #223                // Method kotlin/text/StringsKt.slice:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
     328: invokevirtual #227                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     331: aload_0
     332: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     335: iload_1
     336: iload_2
     337: invokestatic  #219                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     340: invokestatic  #223                // Method kotlin/text/StringsKt.slice:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
     343: checkcast     #153                // class java/lang/CharSequence
     346: astore        4
     348: astore        13
     350: iconst_0
     351: istore        5
     353: aload         4
     355: astore        6
     357: new           #50                 // class java/util/ArrayList
     360: dup
     361: aload         4
     363: invokeinterface #157,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     368: invokespecial #230                // Method java/util/ArrayList."<init>":(I)V
     371: checkcast     #232                // class java/util/Collection
     374: astore        7
     376: iconst_0
     377: istore        8
     379: iconst_0
     380: istore        9
     382: iload         9
     384: aload         6
     386: invokeinterface #157,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     391: if_icmpge     440
     394: aload         6
     396: iload         9
     398: invokeinterface #161,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     403: istore        10
     405: aload         7
     407: iload         10
     409: istore        11
     411: astore        14
     413: iconst_0
     414: istore        12
     416: aload_0
     417: iload         11
     419: invokestatic  #165                // Method solveLongNumber$f:(LLongNumberProblem;C)C
     422: invokestatic  #235                // Method java/lang/Character.valueOf:(C)Ljava/lang/Character;
     425: aload         14
     427: swap
     428: invokeinterface #239,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     433: pop
     434: iinc          9, 1
     437: goto          382
     440: aload         7
     442: checkcast     #55                 // class java/util/List
     445: nop
     446: aload         13
     448: swap
     449: checkcast     #192                // class java/lang/Iterable
     452: ldc           #63                 // String
     454: checkcast     #153                // class java/lang/CharSequence
     457: aconst_null
     458: aconst_null
     459: iconst_0
     460: aconst_null
     461: aconst_null
     462: bipush        62
     464: aconst_null
     465: invokestatic  #243                // 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;
     468: invokevirtual #227                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     471: aload_0
     472: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     475: iload_2
     476: aload_0
     477: invokevirtual #151                // Method LongNumberProblem.getA:()Ljava/lang/String;
     480: invokevirtual #184                // Method java/lang/String.length:()I
     483: invokestatic  #219                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
     486: invokestatic  #223                // Method kotlin/text/StringsKt.slice:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
     489: invokevirtual #227                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     492: invokevirtual #246                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     495: astore_3
     496: aload_3
     497: areturn

  private static final kotlin.Unit main$lambda$1(kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$IntRef, kotlin.jvm.internal.Ref$ObjectRef, kotlin.jvm.internal.Ref$ObjectRef, java.util.List, java.lang.String);
    Code:
       0: aload         5
       2: ldc_w         #274                // String it
       5: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       8: aload_0
       9: getfield      #276                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      12: istore        6
      14: aload_0
      15: iload         6
      17: iconst_1
      18: iadd
      19: putfield      #276                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      22: iload         6
      24: iconst_3
      25: irem
      26: tableswitch   { // 0 to 2
                     0: 52
                     1: 64
                     2: 73
               default: 246
          }
      52: aload_1
      53: aload         5
      55: invokestatic  #280                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      58: putfield      #276                // Field kotlin/jvm/internal/Ref$IntRef.element:I
      61: goto          246
      64: aload_2
      65: aload         5
      67: putfield      #67                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
      70: goto          246
      73: aload_3
      74: aload         5
      76: checkcast     #153                // class java/lang/CharSequence
      79: iconst_1
      80: anewarray     #183                // class java/lang/String
      83: astore        6
      85: aload         6
      87: iconst_0
      88: ldc_w         #282                // String
      91: aastore
      92: aload         6
      94: iconst_0
      95: iconst_0
      96: bipush        6
      98: aconst_null
      99: invokestatic  #286                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     102: checkcast     #192                // class java/lang/Iterable
     105: astore        6
     107: astore        15
     109: iconst_0
     110: istore        7
     112: aload         6
     114: astore        8
     116: new           #50                 // class java/util/ArrayList
     119: dup
     120: aload         6
     122: bipush        10
     124: invokestatic  #290                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     127: invokespecial #230                // Method java/util/ArrayList."<init>":(I)V
     130: checkcast     #232                // class java/util/Collection
     133: astore        9
     135: iconst_0
     136: istore        10
     138: aload         8
     140: invokeinterface #193,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     145: astore        11
     147: aload         11
     149: invokeinterface #109,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     154: ifeq          201
     157: aload         11
     159: invokeinterface #113,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     164: astore        12
     166: aload         9
     168: aload         12
     170: checkcast     #183                // class java/lang/String
     173: astore        13
     175: astore        16
     177: iconst_0
     178: istore        14
     180: aload         13
     182: invokestatic  #280                // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     185: nop
     186: invokestatic  #175                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     189: aload         16
     191: swap
     192: invokeinterface #239,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     197: pop
     198: goto          147
     201: aload         9
     203: checkcast     #55                 // class java/util/List
     206: nop
     207: aload         15
     209: swap
     210: putfield      #67                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     213: aload         4
     215: new           #115                // class LongNumberProblem
     218: dup
     219: aload_1
     220: getfield      #276                // Field kotlin/jvm/internal/Ref$IntRef.element:I
     223: aload_2
     224: getfield      #67                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     227: checkcast     #183                // class java/lang/String
     230: aload_3
     231: getfield      #67                 // Field kotlin/jvm/internal/Ref$ObjectRef.element:Ljava/lang/Object;
     234: checkcast     #55                 // class java/util/List
     237: invokespecial #293                // Method LongNumberProblem."<init>":(ILjava/lang/String;Ljava/util/List;)V
     240: invokeinterface #294,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     245: pop
     246: getstatic     #300                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
     249: areturn

  private static final char solveLongNumber$f(LongNumberProblem, char);
    Code:
       0: bipush        48
       2: aload_0
       3: invokevirtual #309                // Method LongNumberProblem.getFm:()Ljava/util/List;
       6: iload_1
       7: bipush        49
       9: isub
      10: invokeinterface #313,  2          // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      15: checkcast     #177                // class java/lang/Number
      18: invokevirtual #180                // Method java/lang/Number.intValue:()I
      21: iadd
      22: i2c
      23: ireturn
}


julianferres__Codeforces__14e8369/Kotlin Heroes 6 -Practice/G.kt

data class Edge(val from: Int, val to: Int, val cost: Long)

class DSU(val n: Int){
    var par: MutableList<Int> = MutableList<Int>(n){ it }
    var sz: MutableList<Int> = MutableList<Int>(n){ 1 }

    fun find(x: Int): Int {
        if(par[x] != x) par[x] = find(par[x])
        return par[x]
    }

    fun join(ii: Int, jj: Int): Boolean{
        var i=find(ii); var j=find(jj);
        if(i == j) return false;
        if(sz[i] < sz[j]){
            run { val temp = i; i = j; j = temp }
        }
        sz[i] += sz[j];
        par[j] = i;
        return true
    }
}

fun main() {
    var (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var a = readLine()!!.split(" ").map { it.toLong() }

    var mindex = a.indexOf(a.minBy{ it })

    var edges = mutableListOf<Edge>()

    repeat(m){
        var line = readLine()!!.split(" ")
        var from = line[0].toInt()
        var to = line[1].toInt()
        var cost = line[2].toLong()

        edges.add(Edge(from-1, to-1, cost))
    }

    for (i in 0 until n){
        edges.add(Edge(i, mindex, a[mindex] + a[i]))
    }

    edges.sortWith(compareBy {it.cost})
    var dsu = DSU(n)
    var ans = 0L

    for(edge in edges){
        if(dsu.find(edge.from) == dsu.find(edge.to)) continue
        else{
            ans += edge.cost
            dsu.join(edge.from, edge.to)
        }
    }

    println(ans)
}

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

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

Compiled from "G.kt"
public final class GKt {
  public static final void main();
    Code:
       0: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
       3: dup
       4: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
       7: checkcast     #20                 // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #22                 // class java/lang/String
      14: astore_1
      15: aload_1
      16: iconst_0
      17: ldc           #24                 // String
      19: aastore
      20: aload_1
      21: iconst_0
      22: iconst_0
      23: bipush        6
      25: aconst_null
      26: invokestatic  #30                 // 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_1
      33: iconst_0
      34: istore_2
      35: aload_1
      36: astore_3
      37: new           #34                 // class java/util/ArrayList
      40: dup
      41: aload_1
      42: bipush        10
      44: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      47: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
      50: checkcast     #46                 // class java/util/Collection
      53: astore        4
      55: iconst_0
      56: istore        5
      58: aload_3
      59: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      64: astore        6
      66: aload         6
      68: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      73: ifeq          120
      76: aload         6
      78: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      83: astore        7
      85: aload         4
      87: aload         7
      89: checkcast     #22                 // class java/lang/String
      92: astore        8
      94: astore        19
      96: iconst_0
      97: istore        9
      99: aload         8
     101: invokestatic  #66                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     104: nop
     105: invokestatic  #70                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     108: aload         19
     110: swap
     111: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     116: pop
     117: goto          66
     120: aload         4
     122: checkcast     #76                 // class java/util/List
     125: nop
     126: astore_0
     127: aload_0
     128: iconst_0
     129: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     134: checkcast     #82                 // class java/lang/Number
     137: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     140: istore_1
     141: aload_0
     142: iconst_1
     143: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     148: checkcast     #82                 // class java/lang/Number
     151: invokevirtual #86                 // Method java/lang/Number.intValue:()I
     154: istore_2
     155: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     158: dup
     159: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     162: checkcast     #20                 // class java/lang/CharSequence
     165: iconst_1
     166: anewarray     #22                 // class java/lang/String
     169: astore        4
     171: aload         4
     173: iconst_0
     174: ldc           #24                 // String
     176: aastore
     177: aload         4
     179: iconst_0
     180: iconst_0
     181: bipush        6
     183: aconst_null
     184: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     187: checkcast     #32                 // class java/lang/Iterable
     190: astore        4
     192: iconst_0
     193: istore        5
     195: aload         4
     197: astore        6
     199: new           #34                 // class java/util/ArrayList
     202: dup
     203: aload         4
     205: bipush        10
     207: invokestatic  #40                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     210: invokespecial #44                 // Method java/util/ArrayList."<init>":(I)V
     213: checkcast     #46                 // class java/util/Collection
     216: astore        7
     218: iconst_0
     219: istore        8
     221: aload         6
     223: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     228: astore        9
     230: aload         9
     232: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     237: ifeq          284
     240: aload         9
     242: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     247: astore        10
     249: aload         7
     251: aload         10
     253: checkcast     #22                 // class java/lang/String
     256: astore        11
     258: astore        19
     260: iconst_0
     261: istore        13
     263: aload         11
     265: invokestatic  #92                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     268: nop
     269: invokestatic  #95                 // Method java/lang/Long.valueOf:(J)Ljava/lang/Long;
     272: aload         19
     274: swap
     275: invokeinterface #74,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     280: pop
     281: goto          230
     284: aload         7
     286: checkcast     #76                 // class java/util/List
     289: nop
     290: astore_3
     291: aload_3
     292: aload_3
     293: checkcast     #32                 // class java/lang/Iterable
     296: astore        5
     298: astore        19
     300: iconst_0
     301: istore        6
     303: aload         5
     305: invokeinterface #50,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     310: astore        7
     312: aload         7
     314: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     319: ifne          330
     322: new           #97                 // class java/util/NoSuchElementException
     325: dup
     326: invokespecial #99                 // Method java/util/NoSuchElementException."<init>":()V
     329: athrow
     330: aload         7
     332: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     337: astore        8
     339: aload         7
     341: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     346: ifne          354
     349: aload         8
     351: goto          425
     354: aload         8
     356: checkcast     #82                 // class java/lang/Number
     359: invokevirtual #103                // Method java/lang/Number.longValue:()J
     362: lstore        9
     364: iconst_0
     365: istore        11
     367: lload         9
     369: lstore        13
     371: aload         7
     373: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     378: astore        15
     380: aload         15
     382: checkcast     #82                 // class java/lang/Number
     385: invokevirtual #103                // Method java/lang/Number.longValue:()J
     388: lstore        16
     390: iconst_0
     391: istore        18
     393: lload         16
     395: lstore        11
     397: lload         13
     399: lload         11
     401: lcmp
     402: ifle          413
     405: aload         15
     407: astore        8
     409: lload         11
     411: lstore        13
     413: aload         7
     415: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     420: ifne          371
     423: aload         8
     425: aload         19
     427: swap
     428: invokeinterface #107,  2          // InterfaceMethod java/util/List.indexOf:(Ljava/lang/Object;)I
     433: istore        4
     435: aconst_null
     436: astore        5
     438: new           #34                 // class java/util/ArrayList
     441: dup
     442: invokespecial #108                // Method java/util/ArrayList."<init>":()V
     445: checkcast     #76                 // class java/util/List
     448: astore        5
     450: iconst_0
     451: istore        6
     453: iload         6
     455: iload_2
     456: if_icmpge     580
     459: iload         6
     461: istore        7
     463: iconst_0
     464: istore        8
     466: invokestatic  #12                 // Method kotlin/io/ConsoleKt.readLine:()Ljava/lang/String;
     469: dup
     470: invokestatic  #18                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     473: checkcast     #20                 // class java/lang/CharSequence
     476: iconst_1
     477: anewarray     #22                 // class java/lang/String
     480: astore        9
     482: aload         9
     484: iconst_0
     485: ldc           #24                 // String
     487: aastore
     488: aload         9
     490: iconst_0
     491: iconst_0
     492: bipush        6
     494: aconst_null
     495: invokestatic  #30                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     498: astore        10
     500: aload         10
     502: iconst_0
     503: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     508: checkcast     #22                 // class java/lang/String
     511: invokestatic  #66                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     514: istore        9
     516: aload         10
     518: iconst_1
     519: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     524: checkcast     #22                 // class java/lang/String
     527: invokestatic  #66                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     530: istore        11
     532: aload         10
     534: iconst_2
     535: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     540: checkcast     #22                 // class java/lang/String
     543: invokestatic  #92                 // Method java/lang/Long.parseLong:(Ljava/lang/String;)J
     546: lstore        13
     548: aload         5
     550: new           #110                // class Edge
     553: dup
     554: iload         9
     556: iconst_1
     557: isub
     558: iload         11
     560: iconst_1
     561: isub
     562: lload         13
     564: invokespecial #113                // Method Edge."<init>":(IIJ)V
     567: invokeinterface #114,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     572: pop
     573: nop
     574: iinc          6, 1
     577: goto          453
     580: iconst_0
     581: istore        6
     583: iload_1
     584: istore        7
     586: iload         6
     588: iload         7
     590: if_icmpge     647
     593: aload         5
     595: new           #110                // class Edge
     598: dup
     599: iload         6
     601: iload         4
     603: aload_3
     604: iload         4
     606: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     611: checkcast     #82                 // class java/lang/Number
     614: invokevirtual #103                // Method java/lang/Number.longValue:()J
     617: aload_3
     618: iload         6
     620: invokeinterface #80,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     625: checkcast     #82                 // class java/lang/Number
     628: invokevirtual #103                // Method java/lang/Number.longValue:()J
     631: ladd
     632: invokespecial #113                // Method Edge."<init>":(IIJ)V
     635: invokeinterface #114,  2          // InterfaceMethod java/util/List.add:(Ljava/lang/Object;)Z
     640: pop
     641: iinc          6, 1
     644: goto          586
     647: aload         5
     649: new           #116                // class GKt$main$$inlined$compareBy$1
     652: dup
     653: invokespecial #117                // Method GKt$main$$inlined$compareBy$1."<init>":()V
     656: checkcast     #119                // class java/util/Comparator
     659: invokestatic  #123                // Method kotlin/collections/CollectionsKt.sortWith:(Ljava/util/List;Ljava/util/Comparator;)V
     662: new           #125                // class DSU
     665: dup
     666: iload_1
     667: invokespecial #126                // Method DSU."<init>":(I)V
     670: astore        6
     672: lconst_0
     673: lstore        7
     675: aload         5
     677: invokeinterface #127,  1          // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
     682: astore        9
     684: aload         9
     686: invokeinterface #56,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     691: ifeq          758
     694: aload         9
     696: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     701: checkcast     #110                // class Edge
     704: astore        10
     706: aload         6
     708: aload         10
     710: invokevirtual #130                // Method Edge.getFrom:()I
     713: invokevirtual #134                // Method DSU.find:(I)I
     716: aload         6
     718: aload         10
     720: invokevirtual #137                // Method Edge.getTo:()I
     723: invokevirtual #134                // Method DSU.find:(I)I
     726: if_icmpeq     684
     729: lload         7
     731: aload         10
     733: invokevirtual #140                // Method Edge.getCost:()J
     736: ladd
     737: lstore        7
     739: aload         6
     741: aload         10
     743: invokevirtual #130                // Method Edge.getFrom:()I
     746: aload         10
     748: invokevirtual #137                // Method Edge.getTo:()I
     751: invokevirtual #144                // Method DSU.join:(II)Z
     754: pop
     755: goto          684
     758: getstatic     #150                // Field java/lang/System.out:Ljava/io/PrintStream;
     761: lload         7
     763: invokevirtual #156                // Method java/io/PrintStream.println:(J)V
     766: return

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


import java.util.Scanner
import kotlin.system.exitProcess

fun main(args : Array<String>) {
  val game = Game()
  game.play()
}

/**
 * Represents the result of one game turn:
 * PLAYER1 if player 1 wins this round,
 * PLAYER2 if player 2 wins this round,
 * WAR if the two cards played are of equal value
 * */
enum class Result {
  PLAYER1,
  PLAYER2,
  WAR
}

class Card(val value: String, val suit: String) : Comparable<Card> {
  companion object {
    val intValues: HashMap<String, Int> = hashMapOf(
        "2" to 2, "3" to 3, "4" to 4, "5" to 5, "6" to 6, "7" to 7, "8" to 8, "9" to 9, "10" to 10,
        "J" to 11,  "Q" to 12, "K" to 13, "A" to 14
    )
  }

  override fun compareTo(other: Card): Int {
    val value1 = intValues.getOrDefault(value, 0)
    val value2 = intValues.getOrDefault(other.value, 0)
    return value1 - value2
  }
}

class Game {
  val input = Scanner(System.`in`)
  var deck1 = readGameInput()
  var deck2 = readGameInput()
  var nbRounds = 0

  fun readGameInput(): List<Card> {
    val n = input.nextInt() // the number of cards for the player
    val cards = ArrayList<Card>(n)
    for (i in 0 until n) {
      val valueSuit = input.next()
      val value = valueSuit.substring(0, valueSuit.length - 1)
      val suit = valueSuit.substring(valueSuit.length - 1)
      cards.add(Card(value, suit))
    }
    return cards
  }

  fun play() {
    var index = 0
    while (true) {
      val result = playTurn(index)
      val rotateIndex = index + 1
      if (result == Result.PLAYER1) {
        nbRounds++
        deck1 = rotate(deck1, rotateIndex)
        deck1 += deck2.take(rotateIndex) // take other player's cards
        deck2 = deck2.drop(rotateIndex) // remove other player's cards
        index = 0
      } else if (result == Result.PLAYER2) {
        nbRounds++
        deck2 += deck1.take(rotateIndex) // take other player's cards
        deck1 = deck1.drop(rotateIndex) // remove other player's cards
        deck2 = rotate(deck2, rotateIndex)
        index = 0
      } else {
        // WAR
        index += 4
      }
    }
  }

  fun rotate(deck: List<Card>, index: Int): List<Card> {
    return deck.drop(index) + deck.take(index)
  }

  /** Returns the result of one game turn */
  fun playTurn(index: Int): Result {
    if (index > deck1.size || index > deck2.size) {
      println("PAT")
      exitProcess(0)
    }

    checkGameOver()

    val card1 = deck1[index]
    val card2 = deck2[index]

    return when {
      card2 < card1 -> Result.PLAYER1
      card1 < card2 -> Result.PLAYER2
      else -> Result.WAR
    }
  }

  fun checkGameOver() {
    if (deck1.isEmpty()) {
      println("2 $nbRounds")
      exitProcess(0)
    }

    if (deck2.isEmpty()) {
      println("1 $nbRounds")
      exitProcess(0)
    }
  }
}

Compiled from "war.kt"
public final class WarKt {
  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: new           #17                 // class Game
       9: dup
      10: invokespecial #21                 // Method Game."<init>":()V
      13: astore_1
      14: aload_1
      15: invokevirtual #24                 // Method Game.play:()V
      18: return
}


import java.util.Scanner
import java.util.ArrayDeque

const val LAND = '#'
const val WATER = 'O'
const val DEFAULT_INDEX = -1

fun main(args : Array<String>) {
  val grid = Grid()
  grid.readGameInput()
  grid.test()
}

data class Square(val x: Int, val y: Int, val terrain: Char, var lakeIndex: Int = DEFAULT_INDEX)

class Grid {
  val input = Scanner(System.`in`)
  var width = 0
  var height = 0
  val nodes = ArrayList<List<Square>>()
  val lakes = HashMap<Int, Int>() // lake_index -> surface area

  fun readGameInput() {
    width = input.nextInt()
    height = input.nextInt()
    if (input.hasNextLine()) {
      input.nextLine()
    }
    for (y in 0 until height) {
      val row = input.nextLine().withIndex().map { Square(it.index, y, it.value) }
      nodes.add(row)
    }
  }

  fun test() {
    val n = input.nextInt()
    for (i in 0 until n) {
      val x = input.nextInt()
      val y = input.nextInt()
      println(area(x, y))
    }
  }

  fun area(x: Int, y: Int): Int {
    val node = nodes[y][x]
    if (node.terrain == LAND) {
      return 0
    }
    if (node.lakeIndex == DEFAULT_INDEX) {
      floodFill(node)
    }
    return lakes.getOrDefault(node.lakeIndex, 0)
  }

  // Source https://en.wikipedia.org/wiki/Flood_fill
  fun floodFill(start: Square) {
    val queue = ArrayDeque<Square>()
    var totalArea = 0
    start.lakeIndex = start.y * width + start.x
    queue.add(start)

    while (!queue.isEmpty()) {
      totalArea++
      val current = queue.poll()
      fillNeighbors(queue, current, start.lakeIndex)
    }

    lakes.put(start.lakeIndex, totalArea)
  }

  fun fillNeighbors(queue: ArrayDeque<Square>, square: Square, lakeIndex: Int) {
    if (square.x + 1 < width) {
      val rightNeighbor = nodes[square.y][square.x + 1]
      fill(queue, rightNeighbor, lakeIndex)
    }

    if (square.x > 0) {
      val leftNeighbor = nodes[square.y][square.x - 1]
      fill(queue, leftNeighbor, lakeIndex)
    }

    if (square.y + 1 < height) {
      val downNeighbor = nodes[square.y + 1][square.x]
      fill(queue, downNeighbor, lakeIndex)
    }

    if (square.y > 0) {
      val upNeighbor = nodes[square.y - 1][square.x]
      fill(queue, upNeighbor, lakeIndex)
    }
  }

  fun fill(queue: ArrayDeque<Square>, square: Square, lakeIndex: Int) {
    if (square.terrain == WATER && square.lakeIndex == DEFAULT_INDEX) {
      square.lakeIndex = lakeIndex
      queue.add(square)
    }
  }
}

Compiled from "surface.kt"
public final class SurfaceKt {
  public static final char LAND;

  public static final char WATER;

  public static final int DEFAULT_INDEX;

  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: new           #17                 // class Grid
       9: dup
      10: invokespecial #21                 // Method Grid."<init>":()V
      13: astore_1
      14: aload_1
      15: invokevirtual #24                 // Method Grid.readGameInput:()V
      18: aload_1
      19: invokevirtual #27                 // Method Grid.test:()V
      22: return
}


fun overlaps(ventsLines: Array<String>): Int {
    val lines = Lines()
    return if (ventsLines.size >= 2) {
        repeat(ventsLines.size){
            lines.mergeWith(Line.fromLineOfVent(LineOfVent.fromString(ventsLines[it])))
        }
        return lines.overlaps()
    } else 0
}
data class Lines(private val data:MutableMap<Int,Line> = mutableMapOf()
){
     fun mergeWith(line: Line){
            data.merge(line.y,line,Line::mergeWith)
    }

    fun overlaps(): Int {
        println(data)
        return data.values.sumOf { it.overlaps() }
    }
}
data class Line(val y: Int, private val xValues: Map<Int, Int> = mutableMapOf()) {
    fun mergeWith(other:Line): Line {

val mergedXValues = xValues.toMutableMap()
        other.xValues.forEach{
            if(mergedXValues.containsKey(it.key)){
                mergedXValues[it.key]=it.value+mergedXValues[it.key]!!
            }else{
                mergedXValues[it.key]=it.value
            }
        }
        return Line(y, mergedXValues)
    }

    fun overlaps(): Int {
        return xValues.values.count { it > 1 }
    }

    companion object{
    fun fromLineOfVent(lineOfVent: LineOfVent):Line{
        val xValues = mutableMapOf<Int, Int>()
        (lineOfVent.x1 .. lineOfVent.x2).forEach{xValues[it]=1}
        println("fromlineofvent: "+xValues)
        return Line(lineOfVent.y1, xValues.toMap())
    }
}
}

class LineOfVent(
    val x1: Int,
    val y1: Int,
    val x2: Int,
    val y2: Int
) {

    fun numberOfOverlapsWith(other: LineOfVent): Int {
        return if (!onTheSameYCoordinate(other))
            0
        else
            arrayOf(this.x2, other.x2)
                .minOrNull()!! - arrayOf(
                this.x1,
                other.x1
            ).maxOrNull()!! + 1
    }

    private fun onTheSameYCoordinate(other: LineOfVent) = this.y1 == other.y1

    companion object {
        fun fromString(string: String): LineOfVent {
            val (left, right) = string.split(" -> ")
            val (x1, y1) = left.split(",").map(String::toInt)
            val (x2, y2) = right.split(",").map(String::toInt)
            return LineOfVent(x1, y1, x2, y2)
        }
    }

}

Compiled from "Task.kt"
public final class TaskKt {
  public static final int overlaps(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #9                  // String ventsLines
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #17                 // class Lines
       9: dup
      10: aconst_null
      11: iconst_1
      12: aconst_null
      13: invokespecial #21                 // Method Lines."<init>":(Ljava/util/Map;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      16: astore_1
      17: aload_0
      18: arraylength
      19: iconst_2
      20: if_icmplt     71
      23: aload_0
      24: arraylength
      25: istore_2
      26: iconst_0
      27: istore_3
      28: iload_3
      29: iload_2
      30: if_icmpge     66
      33: iload_3
      34: istore        4
      36: iconst_0
      37: istore        5
      39: aload_1
      40: getstatic     #27                 // Field Line.Companion:LLine$Companion;
      43: getstatic     #32                 // Field LineOfVent.Companion:LLineOfVent$Companion;
      46: aload_0
      47: iload         4
      49: aaload
      50: invokevirtual #38                 // Method LineOfVent$Companion.fromString:(Ljava/lang/String;)LLineOfVent;
      53: invokevirtual #44                 // Method Line$Companion.fromLineOfVent:(LLineOfVent;)LLine;
      56: invokevirtual #48                 // Method Lines.mergeWith:(LLine;)V
      59: nop
      60: iinc          3, 1
      63: goto          28
      66: aload_1
      67: invokevirtual #51                 // Method Lines.overlaps:()I
      70: ireturn
      71: iconst_0
      72: ireturn
}


/*
* Challenge #2
*
* Date: 15/08/2022
* Difficulty: Medium
* Create a function that translate from natural text to Morse code and vice versa.
* - Must be automatically detect what type it is and perform the conversion.
* - In Morse, dash "—", dot ".", a space " " between letters or symbols, and two spaces between words " " are supported.
* - The supported morse alphabet will be the one shown in https://es.wikipedia.org/wiki/Código_morse.
*/

lateinit var naturalDictionary: Map<String, String>
var morseDictionary = mutableMapOf<String, String>()

fun main() {
    createDictionaries()
    val naturalText = "<NAME>"
    val morseText = ".... --- .-.. .-  ---- . -.-. ---"
    println(decoder(naturalText))
    println(decoder(morseText))
}

private fun createDictionaries() {
    naturalDictionary = mapOf(
        "A" to ".-", "N" to "-.", "0" to "-----",
        "B" to "-...", "Ñ" to "--.--", "1" to ".----",
        "C" to "-.-.", "O" to "---", "2" to "..---",
        "CH" to "----", "P" to ".--.", "3" to "...--",
        "D" to "-..", "Q" to "--.-", "4" to "....-",
        "E" to ".", "R" to ".-.", "5" to ".....",
        "F" to "..-.", "S" to "...", "6" to "-....",
        "G" to "--.", "T" to "-", "7" to "--...",
        "H" to "....", "U" to "..-", "8" to "---..",
        "I" to "..", "V" to "...-", "9" to "----.",
        "J" to ".---", "W" to ".--", "." to ".-.-.-",
        "K" to "-.-", "X" to "-..-", "," to "--..--",
        "L" to ".-..", "Y" to "-.--", "?" to "..--..",
        "M" to "--", "Z" to "--..", "\"" to ".-..-.", "/" to "-..-."
    )
    naturalDictionary.forEach {
        morseDictionary[it.value] = it.key
    }
}

private fun decoder(input: String): String {
    var output = ""

    if (input.contains(Regex("[a-zA-Z0-9]"))) {
        // texto
        output = getMorse(input)
    } else if (input.contains(".") || input.contains("-")) {
        // morse
        output = getNatural(input)
    }
    return output
}

private fun getMorse(input: String): String {
    var index = 0
    var ch = false

    var output = ""
    input.uppercase().forEach { character ->
        if (!ch && character.toString() != " ") {
            val next = index + 1
            if (character.toString() == "C" && next < input.length && input.uppercase()[next].toString() == "H") {
                output += naturalDictionary["CH"]
                ch = true
            } else {
                output += naturalDictionary[character.toString()]
            }
            output += " "
        } else {
            if (!ch) {
                output += " "
            }
            ch = false
        }
        index++
    }
    return output
}

private fun getNatural(input: String): String {
    var output = ""
    input.split("  ").forEach { word ->
        word.split(" ").forEach { symbol ->
            if (symbol.isNotEmpty()) {
                output += morseDictionary[symbol]
            }
        }
        output += " "
    }
    return output
}

Compiled from "Challenge2.kt"
public final class Challenge2Kt {
  public static java.util.Map<java.lang.String, java.lang.String> naturalDictionary;

  private static java.util.Map<java.lang.String, java.lang.String> morseDictionary;

  public static final java.util.Map<java.lang.String, java.lang.String> getNaturalDictionary();
    Code:
       0: getstatic     #12                 // Field naturalDictionary:Ljava/util/Map;
       3: dup
       4: ifnull        8
       7: areturn
       8: pop
       9: ldc           #13                 // String naturalDictionary
      11: invokestatic  #19                 // Method kotlin/jvm/internal/Intrinsics.throwUninitializedPropertyAccessException:(Ljava/lang/String;)V
      14: aconst_null
      15: areturn

  public static final void setNaturalDictionary(java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #26                 // String <set-?>
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #12                 // Field naturalDictionary:Ljava/util/Map;
      10: return

  public static final java.util.Map<java.lang.String, java.lang.String> getMorseDictionary();
    Code:
       0: getstatic     #34                 // Field morseDictionary:Ljava/util/Map;
       3: areturn

  public static final void setMorseDictionary(java.util.Map<java.lang.String, java.lang.String>);
    Code:
       0: aload_0
       1: ldc           #26                 // String <set-?>
       3: invokestatic  #30                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: putstatic     #34                 // Field morseDictionary:Ljava/util/Map;
      10: return

  public static final void main();
    Code:
       0: invokestatic  #40                 // Method createDictionaries:()V
       3: ldc           #42                 // String <NAME>
       5: astore_0
       6: ldc           #44                 // String .... --- .-.. .-  ---- . -.-. ---
       8: astore_1
       9: aload_0
      10: invokestatic  #48                 // Method decoder:(Ljava/lang/String;)Ljava/lang/String;
      13: getstatic     #54                 // Field java/lang/System.out:Ljava/io/PrintStream;
      16: swap
      17: invokevirtual #60                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      20: aload_1
      21: invokestatic  #48                 // Method decoder:(Ljava/lang/String;)Ljava/lang/String;
      24: getstatic     #54                 // Field java/lang/System.out:Ljava/io/PrintStream;
      27: swap
      28: invokevirtual #60                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      31: return

  private static final void createDictionaries();
    Code:
       0: bipush        43
       2: anewarray     #65                 // class kotlin/Pair
       5: astore_0
       6: aload_0
       7: iconst_0
       8: ldc           #67                 // String A
      10: ldc           #69                 // String .-
      12: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      15: aastore
      16: aload_0
      17: iconst_1
      18: ldc           #77                 // String N
      20: ldc           #79                 // String -.
      22: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      25: aastore
      26: aload_0
      27: iconst_2
      28: ldc           #81                 // String 0
      30: ldc           #83                 // String -----
      32: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      35: aastore
      36: aload_0
      37: iconst_3
      38: ldc           #85                 // String B
      40: ldc           #87                 // String -...
      42: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      45: aastore
      46: aload_0
      47: iconst_4
      48: ldc           #89                 // String Ñ
      50: ldc           #91                 // String --.--
      52: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      55: aastore
      56: aload_0
      57: iconst_5
      58: ldc           #93                 // String 1
      60: ldc           #95                 // String .----
      62: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      65: aastore
      66: aload_0
      67: bipush        6
      69: ldc           #97                 // String C
      71: ldc           #99                 // String -.-.
      73: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      76: aastore
      77: aload_0
      78: bipush        7
      80: ldc           #101                // String O
      82: ldc           #103                // String ---
      84: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      87: aastore
      88: aload_0
      89: bipush        8
      91: ldc           #105                // String 2
      93: ldc           #107                // String ..---
      95: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      98: aastore
      99: aload_0
     100: bipush        9
     102: ldc           #109                // String CH
     104: ldc           #111                // String ----
     106: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     109: aastore
     110: aload_0
     111: bipush        10
     113: ldc           #113                // String P
     115: ldc           #115                // String .--.
     117: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     120: aastore
     121: aload_0
     122: bipush        11
     124: ldc           #117                // String 3
     126: ldc           #119                // String ...--
     128: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     131: aastore
     132: aload_0
     133: bipush        12
     135: ldc           #121                // String D
     137: ldc           #123                // String -..
     139: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     142: aastore
     143: aload_0
     144: bipush        13
     146: ldc           #125                // String Q
     148: ldc           #127                // String --.-
     150: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     153: aastore
     154: aload_0
     155: bipush        14
     157: ldc           #129                // String 4
     159: ldc           #131                // String ....-
     161: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     164: aastore
     165: aload_0
     166: bipush        15
     168: ldc           #133                // String E
     170: ldc           #135                // String .
     172: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     175: aastore
     176: aload_0
     177: bipush        16
     179: ldc           #137                // String R
     181: ldc           #139                // String .-.
     183: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     186: aastore
     187: aload_0
     188: bipush        17
     190: ldc           #141                // String 5
     192: ldc           #143                // String .....
     194: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     197: aastore
     198: aload_0
     199: bipush        18
     201: ldc           #145                // String F
     203: ldc           #147                // String ..-.
     205: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     208: aastore
     209: aload_0
     210: bipush        19
     212: ldc           #149                // String S
     214: ldc           #151                // String ...
     216: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     219: aastore
     220: aload_0
     221: bipush        20
     223: ldc           #153                // String 6
     225: ldc           #155                // String -....
     227: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     230: aastore
     231: aload_0
     232: bipush        21
     234: ldc           #157                // String G
     236: ldc           #159                // String --.
     238: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     241: aastore
     242: aload_0
     243: bipush        22
     245: ldc           #161                // String T
     247: ldc           #163                // String -
     249: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     252: aastore
     253: aload_0
     254: bipush        23
     256: ldc           #165                // String 7
     258: ldc           #167                // String --...
     260: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     263: aastore
     264: aload_0
     265: bipush        24
     267: ldc           #169                // String H
     269: ldc           #171                // String ....
     271: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     274: aastore
     275: aload_0
     276: bipush        25
     278: ldc           #173                // String U
     280: ldc           #175                // String ..-
     282: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     285: aastore
     286: aload_0
     287: bipush        26
     289: ldc           #177                // String 8
     291: ldc           #179                // String ---..
     293: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     296: aastore
     297: aload_0
     298: bipush        27
     300: ldc           #181                // String I
     302: ldc           #183                // String ..
     304: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     307: aastore
     308: aload_0
     309: bipush        28
     311: ldc           #185                // String V
     313: ldc           #187                // String ...-
     315: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     318: aastore
     319: aload_0
     320: bipush        29
     322: ldc           #189                // String 9
     324: ldc           #191                // String ----.
     326: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     329: aastore
     330: aload_0
     331: bipush        30
     333: ldc           #193                // String J
     335: ldc           #195                // String .---
     337: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     340: aastore
     341: aload_0
     342: bipush        31
     344: ldc           #197                // String W
     346: ldc           #199                // String .--
     348: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     351: aastore
     352: aload_0
     353: bipush        32
     355: ldc           #135                // String .
     357: ldc           #201                // String .-.-.-
     359: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     362: aastore
     363: aload_0
     364: bipush        33
     366: ldc           #203                // String K
     368: ldc           #205                // String -.-
     370: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     373: aastore
     374: aload_0
     375: bipush        34
     377: ldc           #207                // String X
     379: ldc           #209                // String -..-
     381: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     384: aastore
     385: aload_0
     386: bipush        35
     388: ldc           #211                // String ,
     390: ldc           #213                // String --..--
     392: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     395: aastore
     396: aload_0
     397: bipush        36
     399: ldc           #215                // String L
     401: ldc           #217                // String .-..
     403: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     406: aastore
     407: aload_0
     408: bipush        37
     410: ldc           #219                // String Y
     412: ldc           #221                // String -.--
     414: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     417: aastore
     418: aload_0
     419: bipush        38
     421: ldc           #223                // String ?
     423: ldc           #225                // String ..--..
     425: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     428: aastore
     429: aload_0
     430: bipush        39
     432: ldc           #227                // String M
     434: ldc           #229                // String --
     436: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     439: aastore
     440: aload_0
     441: bipush        40
     443: ldc           #231                // String Z
     445: ldc           #233                // String --..
     447: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     450: aastore
     451: aload_0
     452: bipush        41
     454: ldc           #235                // String \"
     456: ldc           #237                // String .-..-.
     458: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     461: aastore
     462: aload_0
     463: bipush        42
     465: ldc           #239                // String /
     467: ldc           #241                // String -..-.
     469: invokestatic  #75                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     472: aastore
     473: aload_0
     474: invokestatic  #247                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
     477: invokestatic  #249                // Method setNaturalDictionary:(Ljava/util/Map;)V
     480: invokestatic  #251                // Method getNaturalDictionary:()Ljava/util/Map;
     483: astore_0
     484: iconst_0
     485: istore_1
     486: aload_0
     487: invokeinterface #255,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     492: invokeinterface #261,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     497: astore_2
     498: aload_2
     499: invokeinterface #267,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     504: ifeq          551
     507: aload_2
     508: invokeinterface #271,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     513: checkcast     #273                // class java/util/Map$Entry
     516: astore_3
     517: aload_3
     518: astore        4
     520: iconst_0
     521: istore        5
     523: getstatic     #34                 // Field morseDictionary:Ljava/util/Map;
     526: aload         4
     528: invokeinterface #276,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     533: aload         4
     535: invokeinterface #279,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     540: invokeinterface #283,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     545: pop
     546: nop
     547: nop
     548: goto          498
     551: nop
     552: return

  private static final java.lang.String decoder(java.lang.String);
    Code:
       0: ldc_w         #291                // String
       3: astore_1
       4: aload_0
       5: checkcast     #293                // class java/lang/CharSequence
       8: astore_2
       9: new           #295                // class kotlin/text/Regex
      12: dup
      13: ldc_w         #297                // String [a-zA-Z0-9]
      16: invokespecial #300                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      19: aload_2
      20: invokevirtual #304                // Method kotlin/text/Regex.containsMatchIn:(Ljava/lang/CharSequence;)Z
      23: ifeq          34
      26: aload_0
      27: invokestatic  #307                // Method getMorse:(Ljava/lang/String;)Ljava/lang/String;
      30: astore_1
      31: goto          75
      34: aload_0
      35: checkcast     #293                // class java/lang/CharSequence
      38: ldc           #135                // String .
      40: checkcast     #293                // class java/lang/CharSequence
      43: iconst_0
      44: iconst_2
      45: aconst_null
      46: invokestatic  #313                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
      49: ifne          70
      52: aload_0
      53: checkcast     #293                // class java/lang/CharSequence
      56: ldc           #163                // String -
      58: checkcast     #293                // class java/lang/CharSequence
      61: iconst_0
      62: iconst_2
      63: aconst_null
      64: invokestatic  #313                // Method kotlin/text/StringsKt.contains$default:(Ljava/lang/CharSequence;Ljava/lang/CharSequence;ZILjava/lang/Object;)Z
      67: ifeq          75
      70: aload_0
      71: invokestatic  #316                // Method getNatural:(Ljava/lang/String;)Ljava/lang/String;
      74: astore_1
      75: aload_1
      76: areturn

  private static final java.lang.String getMorse(java.lang.String);
    Code:
       0: iconst_0
       1: istore_1
       2: iconst_0
       3: istore_2
       4: aconst_null
       5: astore_3
       6: ldc_w         #291                // String
       9: astore_3
      10: aload_0
      11: getstatic     #326                // Field java/util/Locale.ROOT:Ljava/util/Locale;
      14: invokevirtual #330                // Method java/lang/String.toUpperCase:(Ljava/util/Locale;)Ljava/lang/String;
      17: dup
      18: ldc_w         #332                // String toUpperCase(...)
      21: invokestatic  #335                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      24: checkcast     #293                // class java/lang/CharSequence
      27: astore        4
      29: nop
      30: iconst_0
      31: istore        5
      33: iconst_0
      34: istore        6
      36: iload         6
      38: aload         4
      40: invokeinterface #339,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      45: if_icmpge     272
      48: aload         4
      50: iload         6
      52: invokeinterface #343,  2          // InterfaceMethod java/lang/CharSequence.charAt:(I)C
      57: istore        7
      59: iload         7
      61: istore        8
      63: iconst_0
      64: istore        9
      66: iload_2
      67: ifne          234
      70: iload         8
      72: invokestatic  #347                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      75: ldc_w         #349                // String
      78: invokestatic  #353                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      81: ifne          234
      84: iload_1
      85: iconst_1
      86: iadd
      87: istore        10
      89: iload         8
      91: invokestatic  #347                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
      94: ldc           #97                 // String C
      96: invokestatic  #353                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      99: ifeq          177
     102: iload         10
     104: aload_0
     105: invokevirtual #354                // Method java/lang/String.length:()I
     108: if_icmpge     177
     111: aload_0
     112: getstatic     #326                // Field java/util/Locale.ROOT:Ljava/util/Locale;
     115: invokevirtual #330                // Method java/lang/String.toUpperCase:(Ljava/util/Locale;)Ljava/lang/String;
     118: dup
     119: ldc_w         #332                // String toUpperCase(...)
     122: invokestatic  #335                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     125: iload         10
     127: invokevirtual #355                // Method java/lang/String.charAt:(I)C
     130: invokestatic  #347                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     133: ldc           #169                // String H
     135: invokestatic  #353                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     138: ifeq          177
     141: new           #357                // class java/lang/StringBuilder
     144: dup
     145: invokespecial #359                // Method java/lang/StringBuilder."<init>":()V
     148: aload_3
     149: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     152: invokestatic  #251                // Method getNaturalDictionary:()Ljava/util/Map;
     155: ldc           #109                // String CH
     157: invokeinterface #367,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     162: checkcast     #320                // class java/lang/String
     165: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     168: invokevirtual #371                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     171: astore_3
     172: iconst_1
     173: istore_2
     174: goto          211
     177: new           #357                // class java/lang/StringBuilder
     180: dup
     181: invokespecial #359                // Method java/lang/StringBuilder."<init>":()V
     184: aload_3
     185: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     188: invokestatic  #251                // Method getNaturalDictionary:()Ljava/util/Map;
     191: iload         8
     193: invokestatic  #347                // Method java/lang/String.valueOf:(C)Ljava/lang/String;
     196: invokeinterface #367,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     201: checkcast     #320                // class java/lang/String
     204: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     207: invokevirtual #371                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     210: astore_3
     211: new           #357                // class java/lang/StringBuilder
     214: dup
     215: invokespecial #359                // Method java/lang/StringBuilder."<init>":()V
     218: aload_3
     219: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     222: bipush        32
     224: invokevirtual #374                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     227: invokevirtual #371                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     230: astore_3
     231: goto          260
     234: iload_2
     235: ifne          258
     238: new           #357                // class java/lang/StringBuilder
     241: dup
     242: invokespecial #359                // Method java/lang/StringBuilder."<init>":()V
     245: aload_3
     246: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     249: bipush        32
     251: invokevirtual #374                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     254: invokevirtual #371                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     257: astore_3
     258: iconst_0
     259: istore_2
     260: iload_1
     261: iconst_1
     262: iadd
     263: istore_1
     264: nop
     265: nop
     266: iinc          6, 1
     269: goto          36
     272: nop
     273: aload_3
     274: areturn

  private static final java.lang.String getNatural(java.lang.String);
    Code:
       0: aconst_null
       1: astore_1
       2: ldc_w         #291                // String
       5: astore_1
       6: aload_0
       7: checkcast     #293                // class java/lang/CharSequence
      10: iconst_1
      11: anewarray     #320                // class java/lang/String
      14: astore_2
      15: aload_2
      16: iconst_0
      17: ldc_w         #382                // String
      20: aastore
      21: aload_2
      22: iconst_0
      23: iconst_0
      24: bipush        6
      26: aconst_null
      27: invokestatic  #386                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      30: checkcast     #388                // class java/lang/Iterable
      33: astore_2
      34: iconst_0
      35: istore_3
      36: aload_2
      37: invokeinterface #389,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      42: astore        4
      44: aload         4
      46: invokeinterface #267,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
      51: ifeq          230
      54: aload         4
      56: invokeinterface #271,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      61: astore        5
      63: aload         5
      65: checkcast     #320                // class java/lang/String
      68: astore        6
      70: iconst_0
      71: istore        7
      73: aload         6
      75: checkcast     #293                // class java/lang/CharSequence
      78: iconst_1
      79: anewarray     #320                // class java/lang/String
      82: astore        8
      84: aload         8
      86: iconst_0
      87: ldc_w         #349                // String
      90: aastore
      91: aload         8
      93: iconst_0
      94: iconst_0
      95: bipush        6
      97: aconst_null
      98: invokestatic  #386                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
     101: checkcast     #388                // class java/lang/Iterable
     104: astore        8
     106: iconst_0
     107: istore        9
     109: aload         8
     111: invokeinterface #389,  1          // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     116: astore        10
     118: aload         10
     120: invokeinterface #267,  1          // InterfaceMethod java/util/Iterator.hasNext:()Z
     125: ifeq          204
     128: aload         10
     130: invokeinterface #271,  1          // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     135: astore        11
     137: aload         11
     139: checkcast     #320                // class java/lang/String
     142: astore        12
     144: iconst_0
     145: istore        13
     147: aload         12
     149: checkcast     #293                // class java/lang/CharSequence
     152: invokeinterface #339,  1          // InterfaceMethod java/lang/CharSequence.length:()I
     157: ifle          164
     160: iconst_1
     161: goto          165
     164: iconst_0
     165: ifeq          199
     168: new           #357                // class java/lang/StringBuilder
     171: dup
     172: invokespecial #359                // Method java/lang/StringBuilder."<init>":()V
     175: aload_1
     176: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     179: getstatic     #34                 // Field morseDictionary:Ljava/util/Map;
     182: aload         12
     184: invokeinterface #367,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     189: checkcast     #320                // class java/lang/String
     192: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     195: invokevirtual #371                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     198: astore_1
     199: nop
     200: nop
     201: goto          118
     204: nop
     205: new           #357                // class java/lang/StringBuilder
     208: dup
     209: invokespecial #359                // Method java/lang/StringBuilder."<init>":()V
     212: aload_1
     213: invokevirtual #363                // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     216: bipush        32
     218: invokevirtual #374                // Method java/lang/StringBuilder.append:(C)Ljava/lang/StringBuilder;
     221: invokevirtual #371                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     224: astore_1
     225: nop
     226: nop
     227: goto          44
     230: nop
     231: aload_1
     232: areturn

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

  static {};
    Code:
       0: new           #402                // class java/util/LinkedHashMap
       3: dup
       4: invokespecial #403                // Method java/util/LinkedHashMap."<init>":()V
       7: checkcast     #21                 // class java/util/Map
      10: putstatic     #34                 // Field morseDictionary:Ljava/util/Map;
      13: return
}