import kotlin.math.*

data class ComplexNumber(val real: Double = 0.0, val imag: Double = 0.0) {
    val abs = sqrt(real * real + imag * imag)

    operator fun plus(other: ComplexNumber): ComplexNumber {
        return ComplexNumber(this.real + other.real, this.imag + other.imag)
    }

    operator fun minus(other: ComplexNumber): ComplexNumber {
        return ComplexNumber(this.real - other.real, this.imag - other.imag)
    }

    operator fun times(other: ComplexNumber): ComplexNumber {
        val real = this.real * other.real - this.imag * other.imag
        val imag = this.real * other.imag + this.imag * other.real
        return ComplexNumber(real, imag)
    }

    operator fun div(other: ComplexNumber): ComplexNumber {
        val real =
            (this.real * other.real + this.imag * other.imag) / (other.real * other.real + other.imag * other.imag)
        val imag =
            (this.imag * other.real - this.real * other.imag) / (other.real * other.real + other.imag * other.imag)
        return ComplexNumber(real, imag)
    }

    fun conjugate(): ComplexNumber = ComplexNumber(this.real, -this.imag)
}

fun exponential(c: ComplexNumber): ComplexNumber = if (c.real == 0.0) {
    ComplexNumber(cos(c.imag), sin(c.imag))
} else {
    ComplexNumber(E.pow(c.real)) * exponential(ComplexNumber(imag = c.imag))
}

Compiled from "ComplexNumbers.kt"
public final class ComplexNumbersKt {
  public static final ComplexNumber exponential(ComplexNumber);
    Code:
       0: aload_0
       1: ldc           #9                  // String c
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #21                 // Method ComplexNumber.getReal:()D
      10: dconst_0
      11: dcmpg
      12: ifne          19
      15: iconst_1
      16: goto          20
      19: iconst_0
      20: ifeq          47
      23: new           #17                 // class ComplexNumber
      26: dup
      27: aload_0
      28: invokevirtual #24                 // Method ComplexNumber.getImag:()D
      31: invokestatic  #30                 // Method java/lang/Math.cos:(D)D
      34: aload_0
      35: invokevirtual #24                 // Method ComplexNumber.getImag:()D
      38: invokestatic  #33                 // Method java/lang/Math.sin:(D)D
      41: invokespecial #37                 // Method ComplexNumber."<init>":(DD)V
      44: goto          87
      47: new           #17                 // class ComplexNumber
      50: dup
      51: ldc2_w        #38                 // double 2.718281828459045d
      54: aload_0
      55: invokevirtual #21                 // Method ComplexNumber.getReal:()D
      58: invokestatic  #43                 // Method java/lang/Math.pow:(DD)D
      61: dconst_0
      62: iconst_2
      63: aconst_null
      64: invokespecial #46                 // Method ComplexNumber."<init>":(DDILkotlin/jvm/internal/DefaultConstructorMarker;)V
      67: new           #17                 // class ComplexNumber
      70: dup
      71: dconst_0
      72: aload_0
      73: invokevirtual #24                 // Method ComplexNumber.getImag:()D
      76: iconst_1
      77: aconst_null
      78: invokespecial #46                 // Method ComplexNumber."<init>":(DDILkotlin/jvm/internal/DefaultConstructorMarker;)V
      81: invokestatic  #48                 // Method exponential:(LComplexNumber;)LComplexNumber;
      84: invokevirtual #51                 // Method ComplexNumber.times:(LComplexNumber;)LComplexNumber;
      87: areturn
}


import kotlin.math.pow

object Wordy {
    private const val PREFIX = "What is "
    private const val SUFFIX = "?"

    private val operations = mapOf<String, (a: Int, b: Int) -> Int>(
        "+" to { a, b -> a + b },
        "-" to { a, b -> a - b },
        "*" to { a, b -> a * b },
        "/" to { a, b -> a / b },
        "^" to { a, b -> a.toDouble().pow(b).toInt() },
    )

    fun answer(input: String): Int {
        return clearInput(input)
            .also { validateInput(it) }
            .split(" ")
            .asSequence()
            .also { if (it.count() == 1) return it.first().toInt() }
            .zipWithNext()
            .foldIndexed(0) { index, acc, piece ->
                when {
                    index == 0 -> piece.first.toInt()
                    index % 2 == 1 -> operations[piece.first]!!.invoke(acc, piece.second.toInt())
                    else -> acc
                }
            }
    }

    private fun validateInput(input: String) {
        if (!input.matches(Regex("^-?\\d+( [+\\-*/^] -?\\d+)*"))) {
            throw IllegalArgumentException("Wrong input")
        }
    }

    private fun clearInput(input: String): String = input
        .replace(PREFIX, "")
        .replace("plus", "+")
        .replace("minus", "-")
        .replace("multiplied by", "*")
        .replace("divided by", "/")
        .replace(Regex("raised to the (\\d+)th power"), "^ $1")
        .replace(SUFFIX, "")
}

Compiled from "Wordy.kt"
public final class Wordy {
  public static final Wordy INSTANCE;

  private static final java.lang.String PREFIX;

  private static final java.lang.String SUFFIX;

  private static final java.util.Map<java.lang.String, kotlin.jvm.functions.Function2<java.lang.Integer, java.lang.Integer, java.lang.Integer>> operations;

  private Wordy();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final int answer(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String input
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: aload_1
       8: invokespecial #25                 // Method clearInput:(Ljava/lang/String;)Ljava/lang/String;
      11: astore_2
      12: aload_2
      13: astore_3
      14: iconst_0
      15: istore        4
      17: getstatic     #28                 // Field INSTANCE:LWordy;
      20: aload_3
      21: invokespecial #32                 // Method validateInput:(Ljava/lang/String;)V
      24: aload_2
      25: checkcast     #34                 // class java/lang/CharSequence
      28: iconst_1
      29: anewarray     #36                 // class java/lang/String
      32: astore_2
      33: aload_2
      34: iconst_0
      35: ldc           #38                 // String
      37: aastore
      38: aload_2
      39: iconst_0
      40: iconst_0
      41: bipush        6
      43: aconst_null
      44: invokestatic  #44                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      47: checkcast     #46                 // class java/lang/Iterable
      50: invokestatic  #52                 // Method kotlin/collections/CollectionsKt.asSequence:(Ljava/lang/Iterable;)Lkotlin/sequences/Sequence;
      53: astore_2
      54: aload_2
      55: astore_3
      56: iconst_0
      57: istore        4
      59: aload_3
      60: invokestatic  #58                 // Method kotlin/sequences/SequencesKt.count:(Lkotlin/sequences/Sequence;)I
      63: iconst_1
      64: if_icmpne     78
      67: aload_3
      68: invokestatic  #62                 // Method kotlin/sequences/SequencesKt.first:(Lkotlin/sequences/Sequence;)Ljava/lang/Object;
      71: checkcast     #36                 // class java/lang/String
      74: invokestatic  #67                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      77: ireturn
      78: aload_2
      79: invokestatic  #71                 // Method kotlin/sequences/SequencesKt.zipWithNext:(Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
      82: astore_2
      83: iconst_0
      84: istore_3
      85: iconst_0
      86: istore        4
      88: iconst_0
      89: istore        5
      91: iload_3
      92: istore        6
      94: aload_2
      95: invokeinterface #77,  1           // InterfaceMethod kotlin/sequences/Sequence.iterator:()Ljava/util/Iterator;
     100: astore        7
     102: aload         7
     104: invokeinterface #83,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     109: ifeq          243
     112: aload         7
     114: invokeinterface #87,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     119: astore        8
     121: iload         5
     123: iinc          5, 1
     126: istore        9
     128: iload         9
     130: ifge          136
     133: invokestatic  #90                 // Method kotlin/collections/CollectionsKt.throwIndexOverflow:()V
     136: iload         9
     138: iload         6
     140: aload         8
     142: checkcast     #92                 // class kotlin/Pair
     145: astore        10
     147: istore        11
     149: istore        12
     151: iconst_0
     152: istore        13
     154: nop
     155: iload         12
     157: ifne          174
     160: aload         10
     162: invokevirtual #95                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     165: checkcast     #36                 // class java/lang/String
     168: invokestatic  #67                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     171: goto          237
     174: iload         12
     176: iconst_2
     177: irem
     178: iconst_1
     179: if_icmpne     235
     182: getstatic     #99                 // Field operations:Ljava/util/Map;
     185: aload         10
     187: invokevirtual #95                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     190: invokeinterface #105,  2          // InterfaceMethod java/util/Map.get:(Ljava/lang/Object;)Ljava/lang/Object;
     195: dup
     196: invokestatic  #109                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     199: checkcast     #111                // class kotlin/jvm/functions/Function2
     202: iload         11
     204: invokestatic  #115                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     207: aload         10
     209: invokevirtual #118                // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     212: checkcast     #36                 // class java/lang/String
     215: invokestatic  #67                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     218: invokestatic  #115                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     221: invokeinterface #122,  3          // InterfaceMethod kotlin/jvm/functions/Function2.invoke:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     226: checkcast     #124                // class java/lang/Number
     229: invokevirtual #128                // Method java/lang/Number.intValue:()I
     232: goto          237
     235: iload         11
     237: nop
     238: istore        6
     240: goto          102
     243: iload         6
     245: ireturn

  private final void validateInput(java.lang.String);
    Code:
       0: aload_1
       1: checkcast     #34                 // class java/lang/CharSequence
       4: astore_2
       5: new           #148                // class kotlin/text/Regex
       8: dup
       9: ldc           #150                // String ^-?\\d+( [+\\-*/^] -?\\d+)*
      11: invokespecial #152                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      14: aload_2
      15: invokevirtual #156                // Method kotlin/text/Regex.matches:(Ljava/lang/CharSequence;)Z
      18: ifne          31
      21: new           #158                // class java/lang/IllegalArgumentException
      24: dup
      25: ldc           #160                // String Wrong input
      27: invokespecial #161                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
      30: athrow
      31: return

  private final java.lang.String clearInput(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #163                // String What is
       3: ldc           #165                // String
       5: iconst_0
       6: iconst_4
       7: aconst_null
       8: invokestatic  #169                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      11: ldc           #171                // String plus
      13: ldc           #173                // String +
      15: iconst_0
      16: iconst_4
      17: aconst_null
      18: invokestatic  #169                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      21: ldc           #175                // String minus
      23: ldc           #177                // String -
      25: iconst_0
      26: iconst_4
      27: aconst_null
      28: invokestatic  #169                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      31: ldc           #179                // String multiplied by
      33: ldc           #181                // String *
      35: iconst_0
      36: iconst_4
      37: aconst_null
      38: invokestatic  #169                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      41: ldc           #183                // String divided by
      43: ldc           #185                // String /
      45: iconst_0
      46: iconst_4
      47: aconst_null
      48: invokestatic  #169                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      51: checkcast     #34                 // class java/lang/CharSequence
      54: astore_2
      55: new           #148                // class kotlin/text/Regex
      58: dup
      59: ldc           #187                // String raised to the (\\d+)th power
      61: invokespecial #152                // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      64: astore_3
      65: ldc           #189                // String ^ $1
      67: astore        4
      69: aload_3
      70: aload_2
      71: aload         4
      73: invokevirtual #193                // Method kotlin/text/Regex.replace:(Ljava/lang/CharSequence;Ljava/lang/String;)Ljava/lang/String;
      76: ldc           #195                // String ?
      78: ldc           #165                // String
      80: iconst_0
      81: iconst_4
      82: aconst_null
      83: invokestatic  #169                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      86: areturn

  private static final int operations$lambda$0(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: iadd
       3: ireturn

  private static final int operations$lambda$1(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: isub
       3: ireturn

  private static final int operations$lambda$2(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: imul
       3: ireturn

  private static final int operations$lambda$3(int, int);
    Code:
       0: iload_0
       1: iload_1
       2: idiv
       3: ireturn

  private static final int operations$lambda$4(int, int);
    Code:
       0: iload_0
       1: i2d
       2: iload_1
       3: i2d
       4: invokestatic  #209                // Method java/lang/Math.pow:(DD)D
       7: d2i
       8: ireturn

  static {};
    Code:
       0: new           #2                  // class Wordy
       3: dup
       4: invokespecial #211                // Method "<init>":()V
       7: putstatic     #28                 // Field INSTANCE:LWordy;
      10: iconst_5
      11: anewarray     #92                 // class kotlin/Pair
      14: astore_0
      15: aload_0
      16: iconst_0
      17: ldc           #173                // String +
      19: invokedynamic #227,  0            // InvokeDynamic #0:invoke:()Lkotlin/jvm/functions/Function2;
      24: invokestatic  #233                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      27: aastore
      28: aload_0
      29: iconst_1
      30: ldc           #177                // String -
      32: invokedynamic #237,  0            // InvokeDynamic #1:invoke:()Lkotlin/jvm/functions/Function2;
      37: invokestatic  #233                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      40: aastore
      41: aload_0
      42: iconst_2
      43: ldc           #181                // String *
      45: invokedynamic #241,  0            // InvokeDynamic #2:invoke:()Lkotlin/jvm/functions/Function2;
      50: invokestatic  #233                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      53: aastore
      54: aload_0
      55: iconst_3
      56: ldc           #185                // String /
      58: invokedynamic #245,  0            // InvokeDynamic #3:invoke:()Lkotlin/jvm/functions/Function2;
      63: invokestatic  #233                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      66: aastore
      67: aload_0
      68: iconst_4
      69: ldc           #247                // String ^
      71: invokedynamic #251,  0            // InvokeDynamic #4:invoke:()Lkotlin/jvm/functions/Function2;
      76: invokestatic  #233                // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
      79: aastore
      80: aload_0
      81: invokestatic  #257                // Method kotlin/collections/MapsKt.mapOf:([Lkotlin/Pair;)Ljava/util/Map;
      84: putstatic     #99                 // Field operations:Ljava/util/Map;
      87: return
}


class Solution {
    class Some () {
        val parent = IntArray(26) {it}
        val rank = IntArray(26) {it}

        fun union(a: Int, b: Int): Unit {
            val pa = find(a)
            val pb = find(b)
            if (rank[a] > rank[b]) {
                parent[pb] = pa
                rank[pa] += rank[pb]
            } else {
                parent[pa] = pb
                rank[pb] += rank[pa]
            }

        }

        fun find (n: Int): Int {
            var p = parent[n]
            while (p != parent[p]) {
                parent[p] = parent[parent[p]]
                p = parent[p]
            }
            return p
        }
    }
    fun equationsPossible(equations: Array<String>): Boolean {
        val s = Some()
        for (eq in equations) {
            if (eq[1] == '=') {
                s.union(eq[0] - 'a', eq[3] - 'a')
            }
        }
        for (eq in equations) {
            if (eq[1] == '!') {
                val a = s.find(eq[0] - 'a')
                val b = s.find(eq[3] - 'a')
                if (a == b) {
                    return false
                }
            }
        }
        return true
    }
}

//class Solution {
//    fun CharArray.replace(from: Char, to: Char) {
//        for (i in this.indices) {
//            if (this[i] == from) {
//                this[i] = to
//            }
//        }
//    }
//
//
//    fun equationsPossible(equations: Array<String>): Boolean {
//        val vars = "abcdefghijklmnopqrstuvwxyz".toCharArray()
//        val vals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray()
//        for (rel in equations) {
//            val v1 = rel[0].toInt() - 'a'.toInt();
//            val v2 = rel[3].toInt() - 'a'.toInt();
//            if (rel[1] == '=') {
//                if (vals[v1] != vals[v2]) {
//                    vals.replace(vals[v1], vals[v2])
//                }
//            }
//        }
//        for (rel in equations) {
//            val v1 = rel[0].toInt() - 'a'.toInt();
//            val v2 = rel[3].toInt() - 'a'.toInt();
//            if (rel[1] == '!') {
//                if (vals[v1] == vals[v2]) {
//                    return false
//                }
//            }
//        }
//        return true
//    }
//}

Compiled from "Solution.kt"
public final class Solution {
  public Solution();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public final boolean equationsPossible(java.lang.String[]);
    Code:
       0: aload_1
       1: ldc           #15                 // String equations
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #23                 // class Solution$Some
       9: dup
      10: invokespecial #24                 // Method Solution$Some."<init>":()V
      13: astore_2
      14: iconst_0
      15: istore_3
      16: aload_1
      17: arraylength
      18: istore        4
      20: iload_3
      21: iload         4
      23: if_icmpge     70
      26: aload_1
      27: iload_3
      28: aaload
      29: astore        5
      31: aload         5
      33: iconst_1
      34: invokevirtual #30                 // Method java/lang/String.charAt:(I)C
      37: bipush        61
      39: if_icmpne     64
      42: aload_2
      43: aload         5
      45: iconst_0
      46: invokevirtual #30                 // Method java/lang/String.charAt:(I)C
      49: bipush        97
      51: isub
      52: aload         5
      54: iconst_3
      55: invokevirtual #30                 // Method java/lang/String.charAt:(I)C
      58: bipush        97
      60: isub
      61: invokevirtual #34                 // Method Solution$Some.union:(II)V
      64: iinc          3, 1
      67: goto          20
      70: iconst_0
      71: istore_3
      72: aload_1
      73: arraylength
      74: istore        4
      76: iload_3
      77: iload         4
      79: if_icmpge     143
      82: aload_1
      83: iload_3
      84: aaload
      85: astore        5
      87: aload         5
      89: iconst_1
      90: invokevirtual #30                 // Method java/lang/String.charAt:(I)C
      93: bipush        33
      95: if_icmpne     137
      98: aload_2
      99: aload         5
     101: iconst_0
     102: invokevirtual #30                 // Method java/lang/String.charAt:(I)C
     105: bipush        97
     107: isub
     108: invokevirtual #38                 // Method Solution$Some.find:(I)I
     111: istore        6
     113: aload_2
     114: aload         5
     116: iconst_3
     117: invokevirtual #30                 // Method java/lang/String.charAt:(I)C
     120: bipush        97
     122: isub
     123: invokevirtual #38                 // Method Solution$Some.find:(I)I
     126: istore        7
     128: iload         6
     130: iload         7
     132: if_icmpne     137
     135: iconst_0
     136: ireturn
     137: iinc          3, 1
     140: goto          76
     143: iconst_1
     144: ireturn
}

Compiled from "Solution.kt"
public final class Solution$Some {
  private final int[] parent;

  private final int[] rank;

  public Solution$Some();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: aload_0
       5: iconst_0
       6: istore_1
       7: bipush        26
       9: newarray       int
      11: astore_2
      12: astore        4
      14: iload_1
      15: bipush        26
      17: if_icmpge     32
      20: iload_1
      21: istore_3
      22: aload_2
      23: iload_3
      24: iload_3
      25: iastore
      26: iinc          1, 1
      29: goto          14
      32: aload         4
      34: aload_2
      35: putfield      #12                 // Field parent:[I
      38: aload_0
      39: iconst_0
      40: istore_1
      41: bipush        26
      43: newarray       int
      45: astore_2
      46: astore        4
      48: iload_1
      49: bipush        26
      51: if_icmpge     66
      54: iload_1
      55: istore_3
      56: aload_2
      57: iload_3
      58: iload_3
      59: iastore
      60: iinc          1, 1
      63: goto          48
      66: aload         4
      68: aload_2
      69: putfield      #15                 // Field rank:[I
      72: return

  public final int[] getParent();
    Code:
       0: aload_0
       1: getfield      #12                 // Field parent:[I
       4: areturn

  public final int[] getRank();
    Code:
       0: aload_0
       1: getfield      #15                 // Field rank:[I
       4: areturn

  public final void union(int, int);
    Code:
       0: aload_0
       1: iload_1
       2: invokevirtual #28                 // Method find:(I)I
       5: istore_3
       6: aload_0
       7: iload_2
       8: invokevirtual #28                 // Method find:(I)I
      11: istore        4
      13: aload_0
      14: getfield      #15                 // Field rank:[I
      17: iload_1
      18: iaload
      19: aload_0
      20: getfield      #15                 // Field rank:[I
      23: iload_2
      24: iaload
      25: if_icmple     61
      28: aload_0
      29: getfield      #12                 // Field parent:[I
      32: iload         4
      34: iload_3
      35: iastore
      36: aload_0
      37: getfield      #15                 // Field rank:[I
      40: astore        5
      42: aload         5
      44: iload_3
      45: aload         5
      47: iload_3
      48: iaload
      49: aload_0
      50: getfield      #15                 // Field rank:[I
      53: iload         4
      55: iaload
      56: iadd
      57: iastore
      58: goto          92
      61: aload_0
      62: getfield      #12                 // Field parent:[I
      65: iload_3
      66: iload         4
      68: iastore
      69: aload_0
      70: getfield      #15                 // Field rank:[I
      73: astore        5
      75: aload         5
      77: iload         4
      79: aload         5
      81: iload         4
      83: iaload
      84: aload_0
      85: getfield      #15                 // Field rank:[I
      88: iload_3
      89: iaload
      90: iadd
      91: iastore
      92: return

  public final int find(int);
    Code:
       0: aload_0
       1: getfield      #12                 // Field parent:[I
       4: iload_1
       5: iaload
       6: istore_2
       7: iload_2
       8: aload_0
       9: getfield      #12                 // Field parent:[I
      12: iload_2
      13: iaload
      14: if_icmpeq     44
      17: aload_0
      18: getfield      #12                 // Field parent:[I
      21: iload_2
      22: aload_0
      23: getfield      #12                 // Field parent:[I
      26: aload_0
      27: getfield      #12                 // Field parent:[I
      30: iload_2
      31: iaload
      32: iaload
      33: iastore
      34: aload_0
      35: getfield      #12                 // Field parent:[I
      38: iload_2
      39: iaload
      40: istore_2
      41: goto          7
      44: iload_2
      45: ireturn
}


jamesrweb__advent-of-code__1180a7f/2022/05 - Supply Stacks/src/Main.kt

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

data class Crate constructor(val value: String)
data class Stacks constructor(val list: HashMap<Int, MutableList<Crate>>) {
    fun viewResult(): String {
        return this.list.tops().joinToString("")
    }

    companion object Static {
        fun fromCrates(crates: String): Stacks {
            val stacksList = hashMapOf<Int, MutableList<Crate>>()
            val stackKeys = crates.lines().last().filterNot { it.isWhitespace() }.map { it.digitToInt() }

            crates.lines().dropLast(1).map { line ->
                line.chunked(4).toMutableList().insertWhile({ chunk -> chunk.size < stackKeys.size }, "").map { item ->
                    if (item.trim() == "") {
                        Optional.empty<Crate>()
                    } else {
                        val char = item.replace("[", "").replace("]", "").trim().take(1)
                        val crate = Crate(char)
                        Optional.of<Crate>(crate)
                    }
                }
            }.forEach {
                it.forEachIndexed { index, optional ->
                    if (optional.isPresent) {
                        stacksList.getOrPut(index + 1) { mutableListOf() }.add(optional.get())
                    }
                }
            }

            return Stacks(stacksList)
        }
    }
}

fun executeMoves(moves: List<String>, stacks: Stacks, retainOrder: Boolean): Stacks {
    moves.forEach { line ->
        val regex = Regex("move (\\d+) from (\\d+) to (\\d+)")
        val result = regex.find(line)?.destructured
        val count = result?.component1()?.toInt()
        val from = result?.component2()?.toInt()
        val to = result?.component3()?.toInt()

        if (count == null || from == null || to == null) {
            throw Exception("Something went wrong. count = $count, from = $from, to = $to")
        }

        val lastFrom = stacks.list.getOrDefault(from, mutableListOf())
        val nextFrom = lastFrom.drop(count).toMutableList()
        val nextTo = stacks.list.getOrDefault(to, mutableListOf())

        if (retainOrder) {
            nextTo.prependAll(lastFrom.take(count))
        } else {
            nextTo.prependAll(lastFrom.take(count).reversed())
        }

        stacks.list[to] = nextTo.toMutableList()
        stacks.list[from] = nextFrom
    }

    return stacks
}

fun main() {
    val path = System.getProperty("user.dir")
    val contents = File("${path}/src/input.txt").readText(Charsets.UTF_8)
    val (crates, instructions) = contents.split("\n\n")
    val moves = instructions.lines().filterNot { it.trim() == "" }
    val partOne = executeMoves(moves, Stacks.fromCrates(crates), false)
    val partTwo = executeMoves(moves, Stacks.fromCrates(crates), true)

    println("Part One: ${partOne.viewResult()}")
    println("Part Two: ${partTwo.viewResult()}")
}

private fun <T> MutableList<T>.prependAll(elements: List<T>) {
    addAll(0, elements)
}

private fun <K> HashMap<K, MutableList<Crate>>.tops(): List<String> {
    return this.values.flatMap { it.take(1) }.map { it.value }
}

private fun <E> MutableList<E>.insertWhile(transform: (MutableList<E>) -> Boolean, value: E): MutableList<E> {
    while (transform(this)) {
        this.add(this.size, value)
    }

    return this
}

Compiled from "Main.kt"
public final class MainKt {
  public static final Stacks executeMoves(java.util.List<java.lang.String>, Stacks, boolean);
    Code:
       0: aload_0
       1: ldc           #10                 // String moves
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #18                 // String stacks
       9: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: checkcast     #20                 // class java/lang/Iterable
      16: astore_3
      17: iconst_0
      18: istore        4
      20: aload_3
      21: invokeinterface #24,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      26: astore        5
      28: aload         5
      30: invokeinterface #30,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      35: ifeq          455
      38: aload         5
      40: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      45: astore        6
      47: aload         6
      49: checkcast     #36                 // class java/lang/String
      52: astore        7
      54: iconst_0
      55: istore        8
      57: new           #38                 // class kotlin/text/Regex
      60: dup
      61: ldc           #40                 // String move (\\d+) from (\\d+) to (\\d+)
      63: invokespecial #44                 // Method kotlin/text/Regex."<init>":(Ljava/lang/String;)V
      66: astore        9
      68: aload         9
      70: aload         7
      72: checkcast     #46                 // class java/lang/CharSequence
      75: iconst_0
      76: iconst_2
      77: aconst_null
      78: invokestatic  #50                 // Method kotlin/text/Regex.find$default:(Lkotlin/text/Regex;Ljava/lang/CharSequence;IILjava/lang/Object;)Lkotlin/text/MatchResult;
      81: dup
      82: ifnull        93
      85: invokeinterface #56,  1           // InterfaceMethod kotlin/text/MatchResult.getDestructured:()Lkotlin/text/MatchResult$Destructured;
      90: goto          95
      93: pop
      94: aconst_null
      95: astore        10
      97: aload         10
      99: dup
     100: ifnull        133
     103: invokevirtual #62                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     106: invokeinterface #66,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     111: iconst_1
     112: invokeinterface #72,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     117: checkcast     #36                 // class java/lang/String
     120: dup
     121: ifnull        133
     124: invokestatic  #78                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     127: invokestatic  #82                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     130: goto          135
     133: pop
     134: aconst_null
     135: astore        11
     137: aload         10
     139: dup
     140: ifnull        173
     143: invokevirtual #62                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     146: invokeinterface #66,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     151: iconst_2
     152: invokeinterface #72,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     157: checkcast     #36                 // class java/lang/String
     160: dup
     161: ifnull        173
     164: invokestatic  #78                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     167: invokestatic  #82                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     170: goto          175
     173: pop
     174: aconst_null
     175: astore        12
     177: aload         10
     179: dup
     180: ifnull        213
     183: invokevirtual #62                 // Method kotlin/text/MatchResult$Destructured.getMatch:()Lkotlin/text/MatchResult;
     186: invokeinterface #66,  1           // InterfaceMethod kotlin/text/MatchResult.getGroupValues:()Ljava/util/List;
     191: iconst_3
     192: invokeinterface #72,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
     197: checkcast     #36                 // class java/lang/String
     200: dup
     201: ifnull        213
     204: invokestatic  #78                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
     207: invokestatic  #82                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     210: goto          215
     213: pop
     214: aconst_null
     215: astore        13
     217: aload         11
     219: ifnull        232
     222: aload         12
     224: ifnull        232
     227: aload         13
     229: ifnonnull     280
     232: new           #84                 // class java/lang/Exception
     235: dup
     236: new           #86                 // class java/lang/StringBuilder
     239: dup
     240: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
     243: ldc           #91                 // String Something went wrong. count =
     245: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     248: aload         11
     250: invokevirtual #98                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     253: ldc           #100                // String , from =
     255: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     258: aload         12
     260: invokevirtual #98                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     263: ldc           #102                // String , to =
     265: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     268: aload         13
     270: invokevirtual #98                 // Method java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
     273: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     276: invokespecial #107                // Method java/lang/Exception."<init>":(Ljava/lang/String;)V
     279: athrow
     280: aload_1
     281: invokevirtual #113                // Method Stacks.getList:()Ljava/util/HashMap;
     284: aload         12
     286: new           #115                // class java/util/ArrayList
     289: dup
     290: invokespecial #116                // Method java/util/ArrayList."<init>":()V
     293: checkcast     #68                 // class java/util/List
     296: invokevirtual #122                // Method java/util/HashMap.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     299: dup
     300: ldc           #124                // String getOrDefault(...)
     302: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     305: checkcast     #68                 // class java/util/List
     308: astore        14
     310: aload         14
     312: checkcast     #20                 // class java/lang/Iterable
     315: aload         11
     317: invokevirtual #131                // Method java/lang/Integer.intValue:()I
     320: invokestatic  #137                // Method kotlin/collections/CollectionsKt.drop:(Ljava/lang/Iterable;I)Ljava/util/List;
     323: checkcast     #139                // class java/util/Collection
     326: invokestatic  #143                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     329: astore        15
     331: aload_1
     332: invokevirtual #113                // Method Stacks.getList:()Ljava/util/HashMap;
     335: aload         13
     337: new           #115                // class java/util/ArrayList
     340: dup
     341: invokespecial #116                // Method java/util/ArrayList."<init>":()V
     344: checkcast     #68                 // class java/util/List
     347: invokevirtual #122                // Method java/util/HashMap.getOrDefault:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     350: dup
     351: ldc           #124                // String getOrDefault(...)
     353: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     356: checkcast     #68                 // class java/util/List
     359: astore        16
     361: iload_2
     362: ifeq          386
     365: aload         16
     367: aload         14
     369: checkcast     #20                 // class java/lang/Iterable
     372: aload         11
     374: invokevirtual #131                // Method java/lang/Integer.intValue:()I
     377: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     380: invokestatic  #150                // Method prependAll:(Ljava/util/List;Ljava/util/List;)V
     383: goto          410
     386: aload         16
     388: aload         14
     390: checkcast     #20                 // class java/lang/Iterable
     393: aload         11
     395: invokevirtual #131                // Method java/lang/Integer.intValue:()I
     398: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
     401: checkcast     #20                 // class java/lang/Iterable
     404: invokestatic  #154                // Method kotlin/collections/CollectionsKt.reversed:(Ljava/lang/Iterable;)Ljava/util/List;
     407: invokestatic  #150                // Method prependAll:(Ljava/util/List;Ljava/util/List;)V
     410: aload_1
     411: invokevirtual #113                // Method Stacks.getList:()Ljava/util/HashMap;
     414: checkcast     #156                // class java/util/Map
     417: aload         13
     419: aload         16
     421: checkcast     #139                // class java/util/Collection
     424: invokestatic  #143                // Method kotlin/collections/CollectionsKt.toMutableList:(Ljava/util/Collection;)Ljava/util/List;
     427: invokeinterface #159,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     432: pop
     433: aload_1
     434: invokevirtual #113                // Method Stacks.getList:()Ljava/util/HashMap;
     437: checkcast     #156                // class java/util/Map
     440: aload         12
     442: aload         15
     444: invokeinterface #159,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     449: pop
     450: nop
     451: nop
     452: goto          28
     455: nop
     456: aload_1
     457: areturn

  public static final void main();
    Code:
       0: ldc           #186                // String user.dir
       2: invokestatic  #192                // Method java/lang/System.getProperty:(Ljava/lang/String;)Ljava/lang/String;
       5: astore_0
       6: new           #194                // class java/io/File
       9: dup
      10: new           #86                 // class java/lang/StringBuilder
      13: dup
      14: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
      17: aload_0
      18: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      21: ldc           #196                // String /src/input.txt
      23: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      26: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      29: invokespecial #197                // Method java/io/File."<init>":(Ljava/lang/String;)V
      32: getstatic     #203                // Field kotlin/text/Charsets.UTF_8:Ljava/nio/charset/Charset;
      35: invokestatic  #209                // Method kotlin/io/FilesKt.readText:(Ljava/io/File;Ljava/nio/charset/Charset;)Ljava/lang/String;
      38: astore_1
      39: aload_1
      40: checkcast     #46                 // class java/lang/CharSequence
      43: iconst_1
      44: anewarray     #36                 // class java/lang/String
      47: astore_3
      48: aload_3
      49: iconst_0
      50: ldc           #211                // String \n\n
      52: aastore
      53: aload_3
      54: iconst_0
      55: iconst_0
      56: bipush        6
      58: aconst_null
      59: invokestatic  #217                // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      62: astore_2
      63: aload_2
      64: iconst_0
      65: invokeinterface #72,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      70: checkcast     #36                 // class java/lang/String
      73: astore_3
      74: aload_2
      75: iconst_1
      76: invokeinterface #72,  2           // InterfaceMethod java/util/List.get:(I)Ljava/lang/Object;
      81: checkcast     #36                 // class java/lang/String
      84: astore        4
      86: aload         4
      88: checkcast     #46                 // class java/lang/CharSequence
      91: invokestatic  #221                // Method kotlin/text/StringsKt.lines:(Ljava/lang/CharSequence;)Ljava/util/List;
      94: checkcast     #20                 // class java/lang/Iterable
      97: astore        6
      99: iconst_0
     100: istore        7
     102: aload         6
     104: astore        8
     106: new           #115                // class java/util/ArrayList
     109: dup
     110: invokespecial #116                // Method java/util/ArrayList."<init>":()V
     113: checkcast     #139                // class java/util/Collection
     116: astore        9
     118: iconst_0
     119: istore        10
     121: aload         8
     123: invokeinterface #24,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     128: astore        11
     130: aload         11
     132: invokeinterface #30,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     137: ifeq          191
     140: aload         11
     142: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     147: astore        12
     149: aload         12
     151: checkcast     #36                 // class java/lang/String
     154: astore        13
     156: iconst_0
     157: istore        14
     159: aload         13
     161: checkcast     #46                 // class java/lang/CharSequence
     164: invokestatic  #225                // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
     167: invokevirtual #226                // Method java/lang/Object.toString:()Ljava/lang/String;
     170: ldc           #228                // String
     172: invokestatic  #232                // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     175: ifne          130
     178: aload         9
     180: aload         12
     182: invokeinterface #236,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     187: pop
     188: goto          130
     191: aload         9
     193: checkcast     #68                 // class java/util/List
     196: nop
     197: astore        5
     199: aload         5
     201: getstatic     #240                // Field Stacks.Static:LStacks$Static;
     204: aload_3
     205: invokevirtual #246                // Method Stacks$Static.fromCrates:(Ljava/lang/String;)LStacks;
     208: iconst_0
     209: invokestatic  #248                // Method executeMoves:(Ljava/util/List;LStacks;Z)LStacks;
     212: astore        6
     214: aload         5
     216: getstatic     #240                // Field Stacks.Static:LStacks$Static;
     219: aload_3
     220: invokevirtual #246                // Method Stacks$Static.fromCrates:(Ljava/lang/String;)LStacks;
     223: iconst_1
     224: invokestatic  #248                // Method executeMoves:(Ljava/util/List;LStacks;Z)LStacks;
     227: astore        7
     229: new           #86                 // class java/lang/StringBuilder
     232: dup
     233: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
     236: ldc           #250                // String Part One:
     238: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     241: aload         6
     243: invokevirtual #253                // Method Stacks.viewResult:()Ljava/lang/String;
     246: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     249: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     252: getstatic     #257                // Field java/lang/System.out:Ljava/io/PrintStream;
     255: swap
     256: invokevirtual #263                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     259: new           #86                 // class java/lang/StringBuilder
     262: dup
     263: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
     266: ldc_w         #265                // String Part Two:
     269: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     272: aload         7
     274: invokevirtual #253                // Method Stacks.viewResult:()Ljava/lang/String;
     277: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     280: invokevirtual #106                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     283: getstatic     #257                // Field java/lang/System.out:Ljava/io/PrintStream;
     286: swap
     287: invokevirtual #263                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     290: return

  private static final <T> void prependAll(java.util.List<T>, java.util.List<? extends T>);
    Code:
       0: aload_0
       1: iconst_0
       2: aload_1
       3: checkcast     #139                // class java/util/Collection
       6: invokeinterface #285,  3          // InterfaceMethod java/util/List.addAll:(ILjava/util/Collection;)Z
      11: pop
      12: return

  private static final <K> java.util.List<java.lang.String> tops(java.util.HashMap<K, java.util.List<Crate>>);
    Code:
       0: aload_0
       1: invokevirtual #294                // Method java/util/HashMap.values:()Ljava/util/Collection;
       4: dup
       5: ldc_w         #296                // String <get-values>(...)
       8: invokestatic  #127                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      11: checkcast     #20                 // class java/lang/Iterable
      14: astore_1
      15: iconst_0
      16: istore_2
      17: aload_1
      18: astore_3
      19: new           #115                // class java/util/ArrayList
      22: dup
      23: invokespecial #116                // Method java/util/ArrayList."<init>":()V
      26: checkcast     #139                // class java/util/Collection
      29: astore        4
      31: iconst_0
      32: istore        5
      34: aload_3
      35: invokeinterface #24,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      40: astore        6
      42: aload         6
      44: invokeinterface #30,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      49: ifeq          101
      52: aload         6
      54: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      59: astore        7
      61: aload         7
      63: checkcast     #68                 // class java/util/List
      66: astore        8
      68: iconst_0
      69: istore        9
      71: aload         8
      73: invokestatic  #299                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      76: aload         8
      78: checkcast     #20                 // class java/lang/Iterable
      81: iconst_1
      82: invokestatic  #146                // Method kotlin/collections/CollectionsKt.take:(Ljava/lang/Iterable;I)Ljava/util/List;
      85: checkcast     #20                 // class java/lang/Iterable
      88: astore        8
      90: aload         4
      92: aload         8
      94: invokestatic  #302                // Method kotlin/collections/CollectionsKt.addAll:(Ljava/util/Collection;Ljava/lang/Iterable;)Z
      97: pop
      98: goto          42
     101: aload         4
     103: checkcast     #68                 // class java/util/List
     106: nop
     107: checkcast     #20                 // class java/lang/Iterable
     110: astore_1
     111: nop
     112: iconst_0
     113: istore_2
     114: aload_1
     115: astore_3
     116: new           #115                // class java/util/ArrayList
     119: dup
     120: aload_1
     121: bipush        10
     123: invokestatic  #306                // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     126: invokespecial #309                // Method java/util/ArrayList."<init>":(I)V
     129: checkcast     #139                // class java/util/Collection
     132: astore        4
     134: iconst_0
     135: istore        5
     137: aload_3
     138: invokeinterface #24,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     143: astore        6
     145: aload         6
     147: invokeinterface #30,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     152: ifeq          195
     155: aload         6
     157: invokeinterface #34,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     162: astore        7
     164: aload         4
     166: aload         7
     168: checkcast     #311                // class Crate
     171: astore        8
     173: astore        10
     175: iconst_0
     176: istore        9
     178: aload         8
     180: invokevirtual #314                // Method Crate.getValue:()Ljava/lang/String;
     183: aload         10
     185: swap
     186: invokeinterface #236,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     191: pop
     192: goto          145
     195: aload         4
     197: checkcast     #68                 // class java/util/List
     200: nop
     201: areturn

  private static final <E> java.util.List<E> insertWhile(java.util.List<E>, kotlin.jvm.functions.Function1<? super java.util.List<E>, java.lang.Boolean>, E);
    Code:
       0: aload_1
       1: aload_0
       2: invokeinterface #338,  2          // InterfaceMethod kotlin/jvm/functions/Function1.invoke:(Ljava/lang/Object;)Ljava/lang/Object;
       7: checkcast     #340                // class java/lang/Boolean
      10: invokevirtual #343                // Method java/lang/Boolean.booleanValue:()Z
      13: ifeq          32
      16: aload_0
      17: aload_0
      18: invokeinterface #346,  1          // InterfaceMethod java/util/List.size:()I
      23: aload_2
      24: invokeinterface #349,  3          // InterfaceMethod java/util/List.add:(ILjava/lang/Object;)V
      29: goto          0
      32: aload_0
      33: areturn

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

  public static final java.util.List access$tops(java.util.HashMap);
    Code:
       0: aload_0
       1: invokestatic  #361                // Method tops:(Ljava/util/HashMap;)Ljava/util/List;
       4: areturn

  public static final java.util.List access$insertWhile(java.util.List, kotlin.jvm.functions.Function1, java.lang.Object);
    Code:
       0: aload_0
       1: aload_1
       2: aload_2
       3: invokestatic  #365                // Method insertWhile:(Ljava/util/List;Lkotlin/jvm/functions/Function1;Ljava/lang/Object;)Ljava/util/List;
       6: areturn
}


import java.util.Scanner
import java.util.*

//FloydWarshall
fun main(args: Array<String>){
  println("FloydWarshall");
  var capacity = Array<IntArray>(51, {IntArray(51)})
  var flow = Array<IntArray>(51, {IntArray(51)})
  var visited = IntArray(51){0}
  val V = 5;

//V : number of vertices
//E : number of edges
  capacity[1][2] = 3;
  //There is pipe between 1 and 2 that has 2 unit of capcity.
  capacity[2][3] = 3;
  capacity[3][4] = 5;
  capacity[4][5] = 4;
  capacity[2][5] = 6;
  capacity[2][1] = 3;
  capacity[3][2] = 3;
  capacity[4][3] = 5;
  capacity[5][4] = 4;
  capacity[5][2] = 6;
  val start: Int = 1;
  val end: Int = 5;

  var q: Queue<Int> = LinkedList();
  var maxflow: Int = 0;

  while(true){
      for(i in 1..V){
          visited[i] = 0
      }

      q.add(start)
      while(!q.isEmpty()){
          val front = q.poll();
          for(i in 1..V){

              if(front != i && capacity[front][i] != 0){
                  if(capacity[front][i] - flow[front][i] > 0 && visited[i] == 0){
                      q.add(i)
                      visited[i] = front;
                      if(i == end){
                          break;
                      }
                  }
              }

          }

      }//end of while(q empty)
      if(visited[end] == 0)
      	break; //there is no possible way anymore

      //find minimum of capacity on the way
      var allowable_flow: Int = 99999999
      var prev = end;
      while(true){
          if(allowable_flow > (capacity[visited[prev]][prev] - flow[visited[prev]][prev])){
            allowable_flow = capacity[visited[prev]][prev] - flow[visited[prev]][prev];
          }

          prev = visited[prev]
          if(prev == start)
          	break;
      }
      prev = end;
      //update the flow (current flowing amount)
      while(true){
          flow[visited[prev]][prev] += allowable_flow
          flow[prev][visited[prev]] += allowable_flow
          prev = visited[prev]
          if(prev == start)
          	break;
      }
      maxflow = maxflow + allowable_flow
  }
  println(maxflow)

}

Compiled from "EdmondsKarp.kt"
public final class EdmondsKarpKt {
  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           #17                 // String FloydWarshall
       8: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
      11: swap
      12: invokevirtual #29                 // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      15: iconst_0
      16: istore_2
      17: bipush        51
      19: anewarray     #31                 // class "[I"
      22: astore_3
      23: iload_2
      24: bipush        51
      26: if_icmpge     46
      29: iload_2
      30: istore        4
      32: aload_3
      33: iload         4
      35: bipush        51
      37: newarray       int
      39: aastore
      40: iinc          2, 1
      43: goto          23
      46: aload_3
      47: astore_1
      48: iconst_0
      49: istore_3
      50: bipush        51
      52: anewarray     #31                 // class "[I"
      55: astore        4
      57: iload_3
      58: bipush        51
      60: if_icmpge     81
      63: iload_3
      64: istore        5
      66: aload         4
      68: iload         5
      70: bipush        51
      72: newarray       int
      74: aastore
      75: iinc          3, 1
      78: goto          57
      81: aload         4
      83: astore_2
      84: iconst_0
      85: istore        4
      87: bipush        51
      89: newarray       int
      91: astore        5
      93: iload         4
      95: bipush        51
      97: if_icmpge     116
     100: iload         4
     102: istore        6
     104: aload         5
     106: iload         6
     108: iconst_0
     109: iastore
     110: iinc          4, 1
     113: goto          93
     116: aload         5
     118: astore_3
     119: iconst_5
     120: istore        4
     122: aload_1
     123: iconst_1
     124: aaload
     125: iconst_2
     126: iconst_3
     127: iastore
     128: aload_1
     129: iconst_2
     130: aaload
     131: iconst_3
     132: iconst_3
     133: iastore
     134: aload_1
     135: iconst_3
     136: aaload
     137: iconst_4
     138: iconst_5
     139: iastore
     140: aload_1
     141: iconst_4
     142: aaload
     143: iconst_5
     144: iconst_4
     145: iastore
     146: aload_1
     147: iconst_2
     148: aaload
     149: iconst_5
     150: bipush        6
     152: iastore
     153: aload_1
     154: iconst_2
     155: aaload
     156: iconst_1
     157: iconst_3
     158: iastore
     159: aload_1
     160: iconst_3
     161: aaload
     162: iconst_2
     163: iconst_3
     164: iastore
     165: aload_1
     166: iconst_4
     167: aaload
     168: iconst_3
     169: iconst_5
     170: iastore
     171: aload_1
     172: iconst_5
     173: aaload
     174: iconst_4
     175: iconst_4
     176: iastore
     177: aload_1
     178: iconst_5
     179: aaload
     180: iconst_2
     181: bipush        6
     183: iastore
     184: iconst_1
     185: istore        5
     187: iconst_5
     188: istore        6
     190: new           #33                 // class java/util/LinkedList
     193: dup
     194: invokespecial #37                 // Method java/util/LinkedList."<init>":()V
     197: checkcast     #39                 // class java/util/Queue
     200: astore        7
     202: iconst_0
     203: istore        8
     205: nop
     206: iconst_1
     207: istore        9
     209: aload_3
     210: iload         9
     212: iconst_0
     213: iastore
     214: iload         9
     216: iload         4
     218: if_icmpeq     227
     221: iinc          9, 1
     224: goto          209
     227: aload         7
     229: iload         5
     231: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     234: invokeinterface #49,  2           // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     239: pop
     240: aload         7
     242: invokeinterface #53,  1           // InterfaceMethod java/util/Queue.isEmpty:()Z
     247: ifne          381
     250: aload         7
     252: invokeinterface #57,  1           // InterfaceMethod java/util/Queue.poll:()Ljava/lang/Object;
     257: checkcast     #41                 // class java/lang/Integer
     260: astore        9
     262: iconst_1
     263: istore        10
     265: aload         9
     267: iload         10
     269: istore        11
     271: dup
     272: ifnonnull     279
     275: pop
     276: goto          287
     279: invokevirtual #61                 // Method java/lang/Integer.intValue:()I
     282: iload         11
     284: if_icmpeq     368
     287: aload_1
     288: aload         9
     290: invokestatic  #64                 // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
     293: aload         9
     295: invokevirtual #61                 // Method java/lang/Integer.intValue:()I
     298: aaload
     299: iload         10
     301: iaload
     302: ifeq          368
     305: aload_1
     306: aload         9
     308: invokevirtual #61                 // Method java/lang/Integer.intValue:()I
     311: aaload
     312: iload         10
     314: iaload
     315: aload_2
     316: aload         9
     318: invokevirtual #61                 // Method java/lang/Integer.intValue:()I
     321: aaload
     322: iload         10
     324: iaload
     325: isub
     326: ifle          368
     329: aload_3
     330: iload         10
     332: iaload
     333: ifne          368
     336: aload         7
     338: iload         10
     340: invokestatic  #45                 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     343: invokeinterface #49,  2           // InterfaceMethod java/util/Queue.add:(Ljava/lang/Object;)Z
     348: pop
     349: aload_3
     350: iload         10
     352: aload         9
     354: invokevirtual #61                 // Method java/lang/Integer.intValue:()I
     357: iastore
     358: iload         10
     360: iload         6
     362: if_icmpne     368
     365: goto          240
     368: iload         10
     370: iload         4
     372: if_icmpeq     240
     375: iinc          10, 1
     378: goto          265
     381: aload_3
     382: iload         6
     384: iaload
     385: ifne          391
     388: goto          542
     391: ldc           #65                 // int 99999999
     393: istore        9
     395: iload         6
     397: istore        10
     399: nop
     400: iload         9
     402: aload_1
     403: aload_3
     404: iload         10
     406: iaload
     407: aaload
     408: iload         10
     410: iaload
     411: aload_2
     412: aload_3
     413: iload         10
     415: iaload
     416: aaload
     417: iload         10
     419: iaload
     420: isub
     421: if_icmple     445
     424: aload_1
     425: aload_3
     426: iload         10
     428: iaload
     429: aaload
     430: iload         10
     432: iaload
     433: aload_2
     434: aload_3
     435: iload         10
     437: iaload
     438: aaload
     439: iload         10
     441: iaload
     442: isub
     443: istore        9
     445: aload_3
     446: iload         10
     448: iaload
     449: istore        10
     451: iload         10
     453: iload         5
     455: if_icmpne     399
     458: goto          461
     461: iload         6
     463: istore        10
     465: nop
     466: aload_2
     467: aload_3
     468: iload         10
     470: iaload
     471: aaload
     472: astore        11
     474: iload         10
     476: istore        12
     478: aload         11
     480: iload         12
     482: aload         11
     484: iload         12
     486: iaload
     487: iload         9
     489: iadd
     490: iastore
     491: aload_2
     492: iload         10
     494: aaload
     495: astore        11
     497: aload_3
     498: iload         10
     500: iaload
     501: istore        12
     503: aload         11
     505: iload         12
     507: aload         11
     509: iload         12
     511: iaload
     512: iload         9
     514: iadd
     515: iastore
     516: aload_3
     517: iload         10
     519: iaload
     520: istore        10
     522: iload         10
     524: iload         5
     526: if_icmpne     465
     529: goto          532
     532: iload         8
     534: iload         9
     536: iadd
     537: istore        8
     539: goto          205
     542: getstatic     #23                 // Field java/lang/System.out:Ljava/io/PrintStream;
     545: iload         8
     547: invokevirtual #68                 // Method java/io/PrintStream.println:(I)V
     550: return
}


import kotlin.math.absoluteValue

data class Spreadsheet(private val rows: List<Row>) {
    companion object {
        fun from(s: String): Spreadsheet = Spreadsheet(
                s.split("\n")
                        .filter { it.isNotBlank() }
                        .map { Row.from(it) }
        )
    }

    fun checksum(rowCalculation: (Row) -> Int) = rows.map(rowCalculation).sum()
}

data class Row(val cells: List<Cell>) {
    companion object {
        fun from(s: String): Row = Row(
                s.split(" ")
                        .map(Integer::parseInt)
                        .sorted()
                        .map { Cell(it) }
        )
    }

    val difference: Int
        get() = (cells.first().value - cells.last().value).absoluteValue
    val division: Int
        get() = permutations()
                .first { (a, b) -> a.value.rem(b.value) == 0 }
                .run { first.value / second.value }
}

data class Cell(val value: Int)

fun Row.permutations(): List<Pair<Cell, Cell>> = cells
        .associate { key -> key to cells.filter { it != key } }
        .map { (cell, others) -> others.map { Pair(cell, it) } }
        .flatten()

Compiled from "Day2.kt"
public final class Day2Kt {
  public static final java.util.List<kotlin.Pair<Cell, Cell>> permutations(Row);
    Code:
       0: aload_0
       1: ldc           #10                 // String <this>
       3: invokestatic  #16                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #22                 // Method Row.getCells:()Ljava/util/List;
      10: checkcast     #24                 // class java/lang/Iterable
      13: astore_1
      14: nop
      15: iconst_0
      16: istore_2
      17: aload_1
      18: bipush        10
      20: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      23: invokestatic  #36                 // Method kotlin/collections/MapsKt.mapCapacity:(I)I
      26: bipush        16
      28: invokestatic  #42                 // Method kotlin/ranges/RangesKt.coerceAtLeast:(II)I
      31: istore_3
      32: aload_1
      33: astore        4
      35: new           #44                 // class java/util/LinkedHashMap
      38: dup
      39: iload_3
      40: invokespecial #48                 // Method java/util/LinkedHashMap."<init>":(I)V
      43: checkcast     #50                 // class java/util/Map
      46: astore        5
      48: iconst_0
      49: istore        6
      51: aload         4
      53: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      58: astore        7
      60: aload         7
      62: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      67: ifeq          232
      70: aload         7
      72: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      77: astore        8
      79: aload         5
      81: astore        9
      83: aload         8
      85: checkcast     #66                 // class Cell
      88: astore        10
      90: iconst_0
      91: istore        11
      93: aload         10
      95: aload_0
      96: invokevirtual #22                 // Method Row.getCells:()Ljava/util/List;
      99: checkcast     #24                 // class java/lang/Iterable
     102: astore        12
     104: astore        13
     106: iconst_0
     107: istore        14
     109: aload         12
     111: astore        15
     113: new           #68                 // class java/util/ArrayList
     116: dup
     117: invokespecial #71                 // Method java/util/ArrayList."<init>":()V
     120: checkcast     #73                 // class java/util/Collection
     123: astore        16
     125: iconst_0
     126: istore        17
     128: aload         15
     130: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     135: astore        18
     137: aload         18
     139: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     144: ifeq          197
     147: aload         18
     149: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     154: astore        19
     156: aload         19
     158: checkcast     #66                 // class Cell
     161: astore        20
     163: iconst_0
     164: istore        21
     166: aload         20
     168: aload         10
     170: invokestatic  #77                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     173: ifne          180
     176: iconst_1
     177: goto          181
     180: iconst_0
     181: ifeq          137
     184: aload         16
     186: aload         19
     188: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     193: pop
     194: goto          137
     197: aload         16
     199: checkcast     #83                 // class java/util/List
     202: nop
     203: aload         13
     205: swap
     206: invokestatic  #89                 // Method kotlin/TuplesKt.to:(Ljava/lang/Object;Ljava/lang/Object;)Lkotlin/Pair;
     209: astore        10
     211: aload         9
     213: aload         10
     215: invokevirtual #94                 // Method kotlin/Pair.getFirst:()Ljava/lang/Object;
     218: aload         10
     220: invokevirtual #97                 // Method kotlin/Pair.getSecond:()Ljava/lang/Object;
     223: invokeinterface #101,  3          // InterfaceMethod java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     228: pop
     229: goto          60
     232: aload         5
     234: nop
     235: astore_1
     236: nop
     237: iconst_0
     238: istore_2
     239: aload_1
     240: astore_3
     241: new           #68                 // class java/util/ArrayList
     244: dup
     245: aload_1
     246: invokeinterface #105,  1          // InterfaceMethod java/util/Map.size:()I
     251: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
     254: checkcast     #73                 // class java/util/Collection
     257: astore        4
     259: iconst_0
     260: istore        5
     262: aload_3
     263: invokeinterface #110,  1          // InterfaceMethod java/util/Map.entrySet:()Ljava/util/Set;
     268: invokeinterface #113,  1          // InterfaceMethod java/util/Set.iterator:()Ljava/util/Iterator;
     273: astore        6
     275: aload         6
     277: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     282: ifeq          452
     285: aload         6
     287: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     292: checkcast     #115                // class java/util/Map$Entry
     295: astore        7
     297: aload         4
     299: aload         7
     301: astore        8
     303: astore        22
     305: iconst_0
     306: istore        9
     308: aload         8
     310: invokeinterface #118,  1          // InterfaceMethod java/util/Map$Entry.getKey:()Ljava/lang/Object;
     315: checkcast     #66                 // class Cell
     318: astore        10
     320: aload         8
     322: invokeinterface #121,  1          // InterfaceMethod java/util/Map$Entry.getValue:()Ljava/lang/Object;
     327: checkcast     #83                 // class java/util/List
     330: astore        11
     332: aload         11
     334: checkcast     #24                 // class java/lang/Iterable
     337: astore        12
     339: iconst_0
     340: istore        13
     342: aload         12
     344: astore        14
     346: new           #68                 // class java/util/ArrayList
     349: dup
     350: aload         12
     352: bipush        10
     354: invokestatic  #30                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
     357: invokespecial #106                // Method java/util/ArrayList."<init>":(I)V
     360: checkcast     #73                 // class java/util/Collection
     363: astore        15
     365: iconst_0
     366: istore        16
     368: aload         14
     370: invokeinterface #54,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
     375: astore        17
     377: aload         17
     379: invokeinterface #60,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
     384: ifeq          433
     387: aload         17
     389: invokeinterface #64,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
     394: astore        18
     396: aload         15
     398: aload         18
     400: checkcast     #66                 // class Cell
     403: astore        19
     405: astore        20
     407: iconst_0
     408: istore        21
     410: new           #91                 // class kotlin/Pair
     413: dup
     414: aload         10
     416: aload         19
     418: invokespecial #124                // Method kotlin/Pair."<init>":(Ljava/lang/Object;Ljava/lang/Object;)V
     421: aload         20
     423: swap
     424: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     429: pop
     430: goto          377
     433: aload         15
     435: checkcast     #83                 // class java/util/List
     438: nop
     439: nop
     440: aload         22
     442: swap
     443: invokeinterface #81,  2           // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
     448: pop
     449: goto          275
     452: aload         4
     454: checkcast     #83                 // class java/util/List
     457: nop
     458: checkcast     #24                 // class java/lang/Iterable
     461: invokestatic  #128                // Method kotlin/collections/CollectionsKt.flatten:(Ljava/lang/Iterable;)Ljava/util/List;
     464: areturn
}