package com.shamlou.bases.dataStructure

import java.util.*

/**
 * (In the following comparisons, it is assumed that the keys are of length k
 * and the data structure contains n members.)
 */
class RadixTree<T>(private val root: Node<T> = Node(false)) {

    /**
     * checks whether tree is empty or not
     */
    fun isEmpty(): Boolean = root.edges.isEmpty()

    /**
     * compare two strings and will return first index which two strings differ
     */
    private fun getFirstMismatchLetter(word: String, edgeWord: String): Int {
        for (i in 1 until word.length.coerceAtMost(edgeWord.length)) {
            if (word[i] != edgeWord[i]) return i
        }
        return NO_MISMATCH
    }

    /**
     * get list of objects and will insert them all into radix tree
     */
    fun insertAll(items : List<Item<T>>){
        items.map { insert(it) }
    }
    /**
     * get an object and will insert it to radix tree
     */
    fun insert(item: Item<T>) {

        var current = root
        var currIndex = 0

        //Iterative approach
        while (currIndex < item.label.length) {
            val transitionChar = item.label.lowercase()[currIndex]
            val curEdge = current.getTransition(transitionChar)
            //Updated version of the input word
            val currStr = item.label.lowercase().substring(currIndex)

            //There is no associated edge with the first character of the current string
            //so simply add the rest of the string and finish
            if (curEdge == null) {
                current.addEdge(transitionChar,Edge(currStr, Node(true, item)))
                break
            }
            var splitIndex = getFirstMismatchLetter(currStr, curEdge.label)
            if (splitIndex == NO_MISMATCH) {
                //The edge and leftover string are the same length
                //so finish and update the next node as a word node
                if (currStr.length == curEdge.label.length) {
                    curEdge.next.isLeaf = true
                    curEdge.next.item = item
                    break
                } else if (currStr.length < curEdge.label.length) {
                    //The leftover word is a prefix to the edge string, so split
                    val suffix = curEdge.label.substring(currStr.length)
                    curEdge.label = currStr
                    val newNext = Node<T>(true, item)
                    val afterNewNext = curEdge.next
                    curEdge.next = newNext
                    newNext.addEdge(suffix, afterNewNext)
                    break
                } else {
                    //There is leftover string after a perfect match
                    splitIndex = curEdge.label.length
                }
            } else {
                //The leftover string and edge string differed, so split at point
                val suffix = curEdge.label.substring(splitIndex)
                curEdge.label = curEdge.label.substring(0, splitIndex)
                val prevNext = curEdge.next
                curEdge.next = Node(false)
                curEdge.next.addEdge(suffix, prevNext)
            }

            //Traverse the tree
            current = curEdge.next
            currIndex += splitIndex
        }
    }

    /**
     * searches for a prefix in radix tree
     * first of all search for particular node and then calls [getAllChildren]
     * and it will get all children of that node which is found data
     */
    fun search(word: String): List<T> {

        if(word.isEmpty())return emptyList()
        var current = root
        var currIndex = 0
        while (currIndex < word.length) {
            val transitionChar = word.lowercase()[currIndex]
            val edge = current.getTransition(transitionChar) ?: kotlin.run {
                return listOf()
            }
            currIndex += edge.label.length
            current = edge.next
        }
        return current.getAllChildren(word.lowercase())
    }

    companion object {
        private const val NO_MISMATCH = -1
    }

}

/**
 * represents edges of a node, containts the lable
 * of edge and the node the edge is referring to
 */
class Edge<T>(var label: String, var next: Node<T>)

/**
 * holds item and the key that radix tree works with
 */
class Item<T>(var label: String, var item: T)

/**
 * represents node of the radix tree, contains group
 * of edges that are hold a tree map so it's sorted
 * alphanumeric all the time so whenever we call [getAllChildren]
 * we get a list of <T> which is in alphanumeric order
 */
class Node<T>(var isLeaf: Boolean, var item: Item<T>? = null) {

    // i used TreeMap so it can keep everything sorted
    var edges: TreeMap<Char, Edge<T>> = TreeMap()

    /**
     * get the edge that a Char is referring in treemap
     */
    fun getTransition(transitionChar: Char): Edge<T>? {
        return edges[transitionChar]
    }

    /**
     * adds a edge in edges treemap
     */
    fun addEdge(label: String, next: Node<T>) {
        edges[label[0]] = Edge(label, next)
    }
    /**
     * adds a edge in edges treemap
     */
    fun addEdge(char : Char , edge: Edge<T>){
        edges[char] = edge
    }

    /**
     * gets a node in radix tree and the prefix text of that node
     * recursively calls itself until it reaches leaves and then
     * it will add them to a list
     */
    fun getAllChildren(tillNow: String): List<T> {

        val list = mutableListOf<T>()
        if (isLeaf && item?.label?.lowercase()?.startsWith(tillNow) == true && item?.item != null) {
            item?.item?.let { return listOf(it) }
        }
        edges.map {
            if (it.value.next.isLeaf) list.add(it.value.next.item!!.item)
            else list.addAll(
                it.value.next.getAllChildren(
                    StringBuilder()
                        .append(tillNow)
                        .append(it.value.label)
                        .toString()
                )
            )
        }
        return list
    }
}

Compiled from "RadixTree.kt"
public final class com.shamlou.bases.dataStructure.RadixTree<T> {
  public static final com.shamlou.bases.dataStructure.RadixTree$Companion Companion;

  private final com.shamlou.bases.dataStructure.Node<T> root;

  private static final int NO_MISMATCH;

  public com.shamlou.bases.dataStructure.RadixTree(com.shamlou.bases.dataStructure.Node<T>);
    Code:
       0: aload_1
       1: ldc           #11                 // String root
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokespecial #20                 // Method java/lang/Object."<init>":()V
      10: aload_0
      11: aload_1
      12: putfield      #23                 // Field root:Lcom/shamlou/bases/dataStructure/Node;
      15: return

  public com.shamlou.bases.dataStructure.RadixTree(com.shamlou.bases.dataStructure.Node, int, kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: iload_2
       1: iconst_1
       2: iand
       3: ifeq          18
       6: new           #28                 // class com/shamlou/bases/dataStructure/Node
       9: dup
      10: iconst_0
      11: aconst_null
      12: iconst_2
      13: aconst_null
      14: invokespecial #31                 // Method com/shamlou/bases/dataStructure/Node."<init>":(ZLcom/shamlou/bases/dataStructure/Item;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
      17: astore_1
      18: aload_0
      19: aload_1
      20: invokespecial #33                 // Method "<init>":(Lcom/shamlou/bases/dataStructure/Node;)V
      23: return

  public final boolean isEmpty();
    Code:
       0: aload_0
       1: getfield      #23                 // Field root:Lcom/shamlou/bases/dataStructure/Node;
       4: invokevirtual #39                 // Method com/shamlou/bases/dataStructure/Node.getEdges:()Ljava/util/TreeMap;
       7: invokevirtual #43                 // Method java/util/TreeMap.isEmpty:()Z
      10: ireturn

  private final int getFirstMismatchLetter(java.lang.String, java.lang.String);
    Code:
       0: iconst_1
       1: istore_3
       2: aload_1
       3: invokevirtual #51                 // Method java/lang/String.length:()I
       6: aload_2
       7: invokevirtual #51                 // Method java/lang/String.length:()I
      10: invokestatic  #57                 // Method kotlin/ranges/RangesKt.coerceAtMost:(II)I
      13: istore        4
      15: iload_3
      16: iload         4
      18: if_icmpge     42
      21: aload_1
      22: iload_3
      23: invokevirtual #61                 // Method java/lang/String.charAt:(I)C
      26: aload_2
      27: iload_3
      28: invokevirtual #61                 // Method java/lang/String.charAt:(I)C
      31: if_icmpeq     36
      34: iload_3
      35: ireturn
      36: iinc          3, 1
      39: goto          15
      42: iconst_m1
      43: ireturn

  public final void insertAll(java.util.List<com.shamlou.bases.dataStructure.Item<T>>);
    Code:
       0: aload_1
       1: ldc           #71                 // String items
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #73                 // class java/lang/Iterable
      10: astore_2
      11: iconst_0
      12: istore_3
      13: aload_2
      14: astore        4
      16: new           #75                 // class java/util/ArrayList
      19: dup
      20: aload_2
      21: bipush        10
      23: invokestatic  #81                 // Method kotlin/collections/CollectionsKt.collectionSizeOrDefault:(Ljava/lang/Iterable;I)I
      26: invokespecial #84                 // Method java/util/ArrayList."<init>":(I)V
      29: checkcast     #86                 // class java/util/Collection
      32: astore        5
      34: iconst_0
      35: istore        6
      37: aload         4
      39: invokeinterface #90,  1           // InterfaceMethod java/lang/Iterable.iterator:()Ljava/util/Iterator;
      44: astore        7
      46: aload         7
      48: invokeinterface #95,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      53: ifeq          99
      56: aload         7
      58: invokeinterface #99,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      63: astore        8
      65: aload         5
      67: aload         8
      69: checkcast     #101                // class com/shamlou/bases/dataStructure/Item
      72: astore        9
      74: astore        11
      76: iconst_0
      77: istore        10
      79: aload_0
      80: aload         9
      82: invokevirtual #105                // Method insert:(Lcom/shamlou/bases/dataStructure/Item;)V
      85: aload         11
      87: getstatic     #111                // Field kotlin/Unit.INSTANCE:Lkotlin/Unit;
      90: invokeinterface #115,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      95: pop
      96: goto          46
      99: aload         5
     101: checkcast     #117                // class java/util/List
     104: nop
     105: pop
     106: return

  public final void insert(com.shamlou.bases.dataStructure.Item<T>);
    Code:
       0: aload_1
       1: ldc           #133                // String item
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: getfield      #23                 // Field root:Lcom/shamlou/bases/dataStructure/Node;
      10: astore_2
      11: iconst_0
      12: istore_3
      13: iload_3
      14: aload_1
      15: invokevirtual #137                // Method com/shamlou/bases/dataStructure/Item.getLabel:()Ljava/lang/String;
      18: invokevirtual #51                 // Method java/lang/String.length:()I
      21: if_icmpge     354
      24: aload_1
      25: invokevirtual #137                // Method com/shamlou/bases/dataStructure/Item.getLabel:()Ljava/lang/String;
      28: getstatic     #143                // Field java/util/Locale.ROOT:Ljava/util/Locale;
      31: invokevirtual #147                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
      34: dup
      35: ldc           #149                // String toLowerCase(...)
      37: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      40: iload_3
      41: invokevirtual #61                 // Method java/lang/String.charAt:(I)C
      44: istore        4
      46: aload_2
      47: iload         4
      49: invokevirtual #156                // Method com/shamlou/bases/dataStructure/Node.getTransition:(C)Lcom/shamlou/bases/dataStructure/Edge;
      52: astore        5
      54: nop
      55: aload_1
      56: invokevirtual #137                // Method com/shamlou/bases/dataStructure/Item.getLabel:()Ljava/lang/String;
      59: getstatic     #143                // Field java/util/Locale.ROOT:Ljava/util/Locale;
      62: invokevirtual #147                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
      65: dup
      66: ldc           #149                // String toLowerCase(...)
      68: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      71: iload_3
      72: invokevirtual #160                // Method java/lang/String.substring:(I)Ljava/lang/String;
      75: dup
      76: ldc           #162                // String substring(...)
      78: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      81: astore        6
      83: aload         5
      85: ifnonnull     115
      88: aload_2
      89: iload         4
      91: new           #164                // class com/shamlou/bases/dataStructure/Edge
      94: dup
      95: aload         6
      97: new           #28                 // class com/shamlou/bases/dataStructure/Node
     100: dup
     101: iconst_1
     102: aload_1
     103: invokespecial #167                // Method com/shamlou/bases/dataStructure/Node."<init>":(ZLcom/shamlou/bases/dataStructure/Item;)V
     106: invokespecial #170                // Method com/shamlou/bases/dataStructure/Edge."<init>":(Ljava/lang/String;Lcom/shamlou/bases/dataStructure/Node;)V
     109: invokevirtual #174                // Method com/shamlou/bases/dataStructure/Node.addEdge:(CLcom/shamlou/bases/dataStructure/Edge;)V
     112: goto          354
     115: aload_0
     116: aload         6
     118: aload         5
     120: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     123: invokespecial #177                // Method getFirstMismatchLetter:(Ljava/lang/String;Ljava/lang/String;)I
     126: istore        7
     128: iload         7
     130: iconst_m1
     131: if_icmpne     265
     134: aload         6
     136: invokevirtual #51                 // Method java/lang/String.length:()I
     139: aload         5
     141: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     144: invokevirtual #51                 // Method java/lang/String.length:()I
     147: if_icmpne     171
     150: aload         5
     152: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     155: iconst_1
     156: invokevirtual #185                // Method com/shamlou/bases/dataStructure/Node.setLeaf:(Z)V
     159: aload         5
     161: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     164: aload_1
     165: invokevirtual #188                // Method com/shamlou/bases/dataStructure/Node.setItem:(Lcom/shamlou/bases/dataStructure/Item;)V
     168: goto          354
     171: aload         6
     173: invokevirtual #51                 // Method java/lang/String.length:()I
     176: aload         5
     178: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     181: invokevirtual #51                 // Method java/lang/String.length:()I
     184: if_icmpge     252
     187: aload         5
     189: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     192: aload         6
     194: invokevirtual #51                 // Method java/lang/String.length:()I
     197: invokevirtual #160                // Method java/lang/String.substring:(I)Ljava/lang/String;
     200: dup
     201: ldc           #162                // String substring(...)
     203: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     206: astore        8
     208: aload         5
     210: aload         6
     212: invokevirtual #192                // Method com/shamlou/bases/dataStructure/Edge.setLabel:(Ljava/lang/String;)V
     215: new           #28                 // class com/shamlou/bases/dataStructure/Node
     218: dup
     219: iconst_1
     220: aload_1
     221: invokespecial #167                // Method com/shamlou/bases/dataStructure/Node."<init>":(ZLcom/shamlou/bases/dataStructure/Item;)V
     224: astore        9
     226: aload         5
     228: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     231: astore        10
     233: aload         5
     235: aload         9
     237: invokevirtual #195                // Method com/shamlou/bases/dataStructure/Edge.setNext:(Lcom/shamlou/bases/dataStructure/Node;)V
     240: aload         9
     242: aload         8
     244: aload         10
     246: invokevirtual #197                // Method com/shamlou/bases/dataStructure/Node.addEdge:(Ljava/lang/String;Lcom/shamlou/bases/dataStructure/Node;)V
     249: goto          354
     252: aload         5
     254: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     257: invokevirtual #51                 // Method java/lang/String.length:()I
     260: istore        7
     262: goto          340
     265: aload         5
     267: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     270: iload         7
     272: invokevirtual #160                // Method java/lang/String.substring:(I)Ljava/lang/String;
     275: dup
     276: ldc           #162                // String substring(...)
     278: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     281: astore        8
     283: aload         5
     285: aload         5
     287: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
     290: iconst_0
     291: iload         7
     293: invokevirtual #200                // Method java/lang/String.substring:(II)Ljava/lang/String;
     296: dup
     297: ldc           #162                // String substring(...)
     299: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     302: invokevirtual #192                // Method com/shamlou/bases/dataStructure/Edge.setLabel:(Ljava/lang/String;)V
     305: aload         5
     307: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     310: astore        9
     312: aload         5
     314: new           #28                 // class com/shamlou/bases/dataStructure/Node
     317: dup
     318: iconst_0
     319: aconst_null
     320: iconst_2
     321: aconst_null
     322: invokespecial #31                 // Method com/shamlou/bases/dataStructure/Node."<init>":(ZLcom/shamlou/bases/dataStructure/Item;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
     325: invokevirtual #195                // Method com/shamlou/bases/dataStructure/Edge.setNext:(Lcom/shamlou/bases/dataStructure/Node;)V
     328: aload         5
     330: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     333: aload         8
     335: aload         9
     337: invokevirtual #197                // Method com/shamlou/bases/dataStructure/Node.addEdge:(Ljava/lang/String;Lcom/shamlou/bases/dataStructure/Node;)V
     340: aload         5
     342: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     345: astore_2
     346: iload_3
     347: iload         7
     349: iadd
     350: istore_3
     351: goto          13
     354: return

  public final java.util.List<T> search(java.lang.String);
    Code:
       0: aload_1
       1: ldc           #216                // String word
       3: invokestatic  #17                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: checkcast     #218                // class java/lang/CharSequence
      10: invokeinterface #219,  1          // InterfaceMethod java/lang/CharSequence.length:()I
      15: ifne          22
      18: iconst_1
      19: goto          23
      22: iconst_0
      23: ifeq          30
      26: invokestatic  #223                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      29: areturn
      30: aload_0
      31: getfield      #23                 // Field root:Lcom/shamlou/bases/dataStructure/Node;
      34: astore_2
      35: iconst_0
      36: istore_3
      37: iload_3
      38: aload_1
      39: invokevirtual #51                 // Method java/lang/String.length:()I
      42: if_icmpge     104
      45: aload_1
      46: getstatic     #143                // Field java/util/Locale.ROOT:Ljava/util/Locale;
      49: invokevirtual #147                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
      52: dup
      53: ldc           #149                // String toLowerCase(...)
      55: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
      58: iload_3
      59: invokevirtual #61                 // Method java/lang/String.charAt:(I)C
      62: istore        4
      64: aload_2
      65: iload         4
      67: invokevirtual #156                // Method com/shamlou/bases/dataStructure/Node.getTransition:(C)Lcom/shamlou/bases/dataStructure/Edge;
      70: dup
      71: ifnonnull     82
      74: pop
      75: iconst_0
      76: istore        6
      78: invokestatic  #223                // Method kotlin/collections/CollectionsKt.emptyList:()Ljava/util/List;
      81: areturn
      82: astore        5
      84: iload_3
      85: aload         5
      87: invokevirtual #175                // Method com/shamlou/bases/dataStructure/Edge.getLabel:()Ljava/lang/String;
      90: invokevirtual #51                 // Method java/lang/String.length:()I
      93: iadd
      94: istore_3
      95: aload         5
      97: invokevirtual #181                // Method com/shamlou/bases/dataStructure/Edge.getNext:()Lcom/shamlou/bases/dataStructure/Node;
     100: astore_2
     101: goto          37
     104: aload_2
     105: aload_1
     106: getstatic     #143                // Field java/util/Locale.ROOT:Ljava/util/Locale;
     109: invokevirtual #147                // Method java/lang/String.toLowerCase:(Ljava/util/Locale;)Ljava/lang/String;
     112: dup
     113: ldc           #149                // String toLowerCase(...)
     115: invokestatic  #152                // Method kotlin/jvm/internal/Intrinsics.checkNotNullExpressionValue:(Ljava/lang/Object;Ljava/lang/String;)V
     118: invokevirtual #226                // Method com/shamlou/bases/dataStructure/Node.getAllChildren:(Ljava/lang/String;)Ljava/util/List;
     121: areturn

  public com.shamlou.bases.dataStructure.RadixTree();
    Code:
       0: aload_0
       1: aconst_null
       2: iconst_1
       3: aconst_null
       4: invokespecial #230                // Method "<init>":(Lcom/shamlou/bases/dataStructure/Node;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
       7: return

  static {};
    Code:
       0: new           #233                // class com/shamlou/bases/dataStructure/RadixTree$Companion
       3: dup
       4: aconst_null
       5: invokespecial #236                // Method com/shamlou/bases/dataStructure/RadixTree$Companion."<init>":(Lkotlin/jvm/internal/DefaultConstructorMarker;)V
       8: putstatic     #240                // Field Companion:Lcom/shamlou/bases/dataStructure/RadixTree$Companion;
      11: return
}

Compiled from "RadixTree.kt"
public final class com.shamlou.bases.dataStructure.RadixTree$Companion {
  private com.shamlou.bases.dataStructure.RadixTree$Companion();
    Code:
       0: aload_0
       1: invokespecial #8                  // Method java/lang/Object."<init>":()V
       4: return

  public com.shamlou.bases.dataStructure.RadixTree$Companion(kotlin.jvm.internal.DefaultConstructorMarker);
    Code:
       0: aload_0
       1: invokespecial #12                 // Method "<init>":()V
       4: return
}


package year2018.dec.level6

fun ktchallenge1(s: String): Int {
    val expression: List<String> = s.trim().split(" ")
    return evaluate(expression)
}

private enum class Ops(val symbol: String) {
    ADD("+"),
    MINUS("-"),
    MULTIPLY("*"),
    DIVIDE("/"),
}

private fun evaluate(expression: List<String>): Int {
    var total = 0
    var currentOp = Ops.ADD

    for (value in expression) {
        try {
            val current = value.toInt()

            when (currentOp) {
                Ops.ADD -> total += current
                Ops.MINUS -> total -= current
                Ops.MULTIPLY -> total *= current
                Ops.DIVIDE -> total /= current
            }
        } catch (e: Exception) {
            when (value) {
                Ops.ADD.symbol -> currentOp = Ops.ADD
                Ops.MINUS.symbol -> currentOp = Ops.MINUS
                Ops.MULTIPLY.symbol -> currentOp = Ops.MULTIPLY
                Ops.DIVIDE.symbol -> currentOp = Ops.DIVIDE
                else -> e.printStackTrace()
            }
        }

    }
    return total
}

fun ktchallenge2(array: IntArray, a: Int): IntArray {
    val result = IntArray(2)

    for (i in 0 until array.size) {
        for (j in i+1 until  array.size) {
            when (a) {
                array[i] + array[j]-> {
                    result[0] = i
                    result[1] = j
                }
            }
        }
    }

    return result
}

fun ktchallenge3(array1: IntArray, array2: IntArray): Int = (reverseArray(array1).sum() + reverseArray(array2).sum())

private fun reverseArray(array: IntArray): IntArray {
    return array.
            map { it.toString().reversed().toInt() }.
            toIntArray()
}

fun <T> ktchallenge4(c: Class<T>, a: Double, b: Double): T? {
    return null
}

fun ktchallenge5(s: String, a: Int): Int {

    var text = s

    // replace ops with op with spaces
    // for this case only
    text = text.replace("+", " + ")
    // Index of "r" in return
    val returnIndex = text.indexOf("return")
    val semiIndex = text.indexOf(";")

    // replace i with a (this will do it for all, but it doesn't matter
    text = text.replace("i", a.toString())

    val expression = text.slice(returnIndex+6 until semiIndex )

    return ktchallenge1(expression)
}

Compiled from "ktSolutions.kt"
public final class year2018.dec.level6.KtSolutionsKt {
  public static final int ktchallenge1(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String s
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: checkcast     #17                 // class java/lang/CharSequence
      10: invokestatic  #23                 // Method kotlin/text/StringsKt.trim:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      13: invokevirtual #27                 // Method java/lang/Object.toString:()Ljava/lang/String;
      16: checkcast     #17                 // class java/lang/CharSequence
      19: iconst_1
      20: anewarray     #29                 // class java/lang/String
      23: astore_2
      24: aload_2
      25: iconst_0
      26: ldc           #31                 // String
      28: aastore
      29: aload_2
      30: iconst_0
      31: iconst_0
      32: bipush        6
      34: aconst_null
      35: invokestatic  #35                 // Method kotlin/text/StringsKt.split$default:(Ljava/lang/CharSequence;[Ljava/lang/String;ZIILjava/lang/Object;)Ljava/util/List;
      38: astore_1
      39: aload_1
      40: invokestatic  #39                 // Method evaluate:(Ljava/util/List;)I
      43: ireturn

  private static final int evaluate(java.util.List<java.lang.String>);
    Code:
       0: iconst_0
       1: istore_1
       2: getstatic     #51                 // Field year2018/dec/level6/Ops.ADD:Lyear2018/dec/level6/Ops;
       5: astore_2
       6: aload_0
       7: invokeinterface #57,  1           // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
      12: astore_3
      13: aload_3
      14: invokeinterface #63,  1           // InterfaceMethod java/util/Iterator.hasNext:()Z
      19: ifeq          218
      22: aload_3
      23: invokeinterface #67,  1           // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
      28: checkcast     #29                 // class java/lang/String
      31: astore        4
      33: nop
      34: aload         4
      36: invokestatic  #72                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      39: istore        5
      41: aload_2
      42: getstatic     #78                 // Field year2018/dec/level6/KtSolutionsKt$WhenMappings.$EnumSwitchMapping$0:[I
      45: swap
      46: invokevirtual #82                 // Method year2018/dec/level6/Ops.ordinal:()I
      49: iaload
      50: tableswitch   { // 1 to 4
                     1: 80
                     2: 88
                     3: 96
                     4: 104
               default: 112
          }
      80: iload_1
      81: iload         5
      83: iadd
      84: istore_1
      85: goto          13
      88: iload_1
      89: iload         5
      91: isub
      92: istore_1
      93: goto          13
      96: iload_1
      97: iload         5
      99: imul
     100: istore_1
     101: goto          13
     104: iload_1
     105: iload         5
     107: idiv
     108: istore_1
     109: goto          13
     112: new           #84                 // class kotlin/NoWhenBranchMatchedException
     115: dup
     116: invokespecial #88                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
     119: athrow
     120: astore        5
     122: aload         4
     124: astore        6
     126: aload         6
     128: getstatic     #51                 // Field year2018/dec/level6/Ops.ADD:Lyear2018/dec/level6/Ops;
     131: invokevirtual #91                 // Method year2018/dec/level6/Ops.getSymbol:()Ljava/lang/String;
     134: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     137: ifeq          147
     140: getstatic     #51                 // Field year2018/dec/level6/Ops.ADD:Lyear2018/dec/level6/Ops;
     143: astore_2
     144: goto          13
     147: aload         6
     149: getstatic     #98                 // Field year2018/dec/level6/Ops.MINUS:Lyear2018/dec/level6/Ops;
     152: invokevirtual #91                 // Method year2018/dec/level6/Ops.getSymbol:()Ljava/lang/String;
     155: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     158: ifeq          168
     161: getstatic     #98                 // Field year2018/dec/level6/Ops.MINUS:Lyear2018/dec/level6/Ops;
     164: astore_2
     165: goto          13
     168: aload         6
     170: getstatic     #101                // Field year2018/dec/level6/Ops.MULTIPLY:Lyear2018/dec/level6/Ops;
     173: invokevirtual #91                 // Method year2018/dec/level6/Ops.getSymbol:()Ljava/lang/String;
     176: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     179: ifeq          189
     182: getstatic     #101                // Field year2018/dec/level6/Ops.MULTIPLY:Lyear2018/dec/level6/Ops;
     185: astore_2
     186: goto          13
     189: aload         6
     191: getstatic     #104                // Field year2018/dec/level6/Ops.DIVIDE:Lyear2018/dec/level6/Ops;
     194: invokevirtual #91                 // Method year2018/dec/level6/Ops.getSymbol:()Ljava/lang/String;
     197: invokestatic  #95                 // Method kotlin/jvm/internal/Intrinsics.areEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
     200: ifeq          210
     203: getstatic     #104                // Field year2018/dec/level6/Ops.DIVIDE:Lyear2018/dec/level6/Ops;
     206: astore_2
     207: goto          13
     210: aload         5
     212: invokevirtual #107                // Method java/lang/Exception.printStackTrace:()V
     215: goto          13
     218: iload_1
     219: ireturn
    Exception table:
       from    to  target type
          33   120   120   Class java/lang/Exception

  public static final int[] ktchallenge2(int[], int);
    Code:
       0: aload_0
       1: ldc           #118                // String array
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: iconst_2
       7: newarray       int
       9: astore_2
      10: iconst_0
      11: istore_3
      12: aload_0
      13: arraylength
      14: istore        4
      16: iload_3
      17: iload         4
      19: if_icmpge     71
      22: iload_3
      23: iconst_1
      24: iadd
      25: istore        5
      27: aload_0
      28: arraylength
      29: istore        6
      31: iload         5
      33: iload         6
      35: if_icmpge     65
      38: iload_1
      39: aload_0
      40: iload_3
      41: iaload
      42: aload_0
      43: iload         5
      45: iaload
      46: iadd
      47: if_icmpne     59
      50: aload_2
      51: iconst_0
      52: iload_3
      53: iastore
      54: aload_2
      55: iconst_1
      56: iload         5
      58: iastore
      59: iinc          5, 1
      62: goto          31
      65: iinc          3, 1
      68: goto          16
      71: aload_2
      72: areturn

  public static final int ktchallenge3(int[], int[]);
    Code:
       0: aload_0
       1: ldc           #127                // String array1
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #129                // String array2
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: invokestatic  #133                // Method reverseArray:([I)[I
      16: invokestatic  #139                // Method kotlin/collections/ArraysKt.sum:([I)I
      19: aload_1
      20: invokestatic  #133                // Method reverseArray:([I)[I
      23: invokestatic  #139                // Method kotlin/collections/ArraysKt.sum:([I)I
      26: iadd
      27: ireturn

  private static final int[] reverseArray(int[]);
    Code:
       0: aload_0
       1: astore_1
       2: nop
       3: iconst_0
       4: istore_2
       5: aload_1
       6: astore_3
       7: new           #141                // class java/util/ArrayList
      10: dup
      11: aload_1
      12: arraylength
      13: invokespecial #144                // Method java/util/ArrayList."<init>":(I)V
      16: checkcast     #146                // class java/util/Collection
      19: astore        4
      21: iconst_0
      22: istore        5
      24: iconst_0
      25: istore        6
      27: aload_3
      28: arraylength
      29: istore        7
      31: iload         6
      33: iload         7
      35: if_icmpge     92
      38: aload_3
      39: iload         6
      41: iaload
      42: istore        8
      44: aload         4
      46: iload         8
      48: istore        9
      50: astore        11
      52: iconst_0
      53: istore        10
      55: nop
      56: iload         9
      58: invokestatic  #150                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      61: checkcast     #17                 // class java/lang/CharSequence
      64: invokestatic  #153                // Method kotlin/text/StringsKt.reversed:(Ljava/lang/CharSequence;)Ljava/lang/CharSequence;
      67: invokevirtual #27                 // Method java/lang/Object.toString:()Ljava/lang/String;
      70: invokestatic  #72                 // Method java/lang/Integer.parseInt:(Ljava/lang/String;)I
      73: nop
      74: invokestatic  #156                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      77: aload         11
      79: swap
      80: invokeinterface #160,  2          // InterfaceMethod java/util/Collection.add:(Ljava/lang/Object;)Z
      85: pop
      86: iinc          6, 1
      89: goto          31
      92: aload         4
      94: checkcast     #53                 // class java/util/List
      97: nop
      98: checkcast     #146                // class java/util/Collection
     101: invokestatic  #166                // Method kotlin/collections/CollectionsKt.toIntArray:(Ljava/util/Collection;)[I
     104: areturn

  public static final <T> T ktchallenge4(java.lang.Class<T>, double, double);
    Code:
       0: aload_0
       1: ldc           #181                // String c
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aconst_null
       7: areturn

  public static final int ktchallenge5(java.lang.String, int);
    Code:
       0: aload_0
       1: ldc           #9                  // String s
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: astore_2
       8: aload_2
       9: ldc           #188                // String +
      11: ldc           #190                // String  +
      13: iconst_0
      14: iconst_4
      15: aconst_null
      16: invokestatic  #194                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      19: astore_2
      20: aload_2
      21: checkcast     #17                 // class java/lang/CharSequence
      24: ldc           #196                // String return
      26: iconst_0
      27: iconst_0
      28: bipush        6
      30: aconst_null
      31: invokestatic  #200                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      34: istore_3
      35: aload_2
      36: checkcast     #17                 // class java/lang/CharSequence
      39: ldc           #202                // String ;
      41: iconst_0
      42: iconst_0
      43: bipush        6
      45: aconst_null
      46: invokestatic  #200                // Method kotlin/text/StringsKt.indexOf$default:(Ljava/lang/CharSequence;Ljava/lang/String;IZILjava/lang/Object;)I
      49: istore        4
      51: aload_2
      52: ldc           #203                // String i
      54: iload_1
      55: invokestatic  #150                // Method java/lang/String.valueOf:(I)Ljava/lang/String;
      58: iconst_0
      59: iconst_4
      60: aconst_null
      61: invokestatic  #194                // Method kotlin/text/StringsKt.replace$default:(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;ZILjava/lang/Object;)Ljava/lang/String;
      64: astore_2
      65: aload_2
      66: iload_3
      67: bipush        6
      69: iadd
      70: iload         4
      72: invokestatic  #209                // Method kotlin/ranges/RangesKt.until:(II)Lkotlin/ranges/IntRange;
      75: invokestatic  #213                // Method kotlin/text/StringsKt.slice:(Ljava/lang/String;Lkotlin/ranges/IntRange;)Ljava/lang/String;
      78: astore        5
      80: aload         5
      82: invokestatic  #215                // Method ktchallenge1:(Ljava/lang/String;)I
      85: ireturn
}

Compiled from "ktSolutions.kt"
public final class year2018.dec.level6.KtSolutionsKt$WhenMappings {
  public static final int[] $EnumSwitchMapping$0;

  static {};
    Code:
       0: invokestatic  #14                 // Method year2018/dec/level6/Ops.values:()[Lyear2018/dec/level6/Ops;
       3: arraylength
       4: newarray       int
       6: astore_0
       7: nop
       8: aload_0
       9: getstatic     #18                 // Field year2018/dec/level6/Ops.ADD:Lyear2018/dec/level6/Ops;
      12: invokevirtual #22                 // Method year2018/dec/level6/Ops.ordinal:()I
      15: iconst_1
      16: iastore
      17: goto          21
      20: astore_1
      21: nop
      22: aload_0
      23: getstatic     #25                 // Field year2018/dec/level6/Ops.MINUS:Lyear2018/dec/level6/Ops;
      26: invokevirtual #22                 // Method year2018/dec/level6/Ops.ordinal:()I
      29: iconst_2
      30: iastore
      31: goto          35
      34: astore_1
      35: nop
      36: aload_0
      37: getstatic     #28                 // Field year2018/dec/level6/Ops.MULTIPLY:Lyear2018/dec/level6/Ops;
      40: invokevirtual #22                 // Method year2018/dec/level6/Ops.ordinal:()I
      43: iconst_3
      44: iastore
      45: goto          49
      48: astore_1
      49: nop
      50: aload_0
      51: getstatic     #31                 // Field year2018/dec/level6/Ops.DIVIDE:Lyear2018/dec/level6/Ops;
      54: invokevirtual #22                 // Method year2018/dec/level6/Ops.ordinal:()I
      57: iconst_4
      58: iastore
      59: goto          63
      62: astore_1
      63: aload_0
      64: putstatic     #35                 // Field $EnumSwitchMapping$0:[I
      67: return
    Exception table:
       from    to  target type
           7    17    20   Class java/lang/NoSuchFieldError
          21    31    34   Class java/lang/NoSuchFieldError
          35    45    48   Class java/lang/NoSuchFieldError
          49    59    62   Class java/lang/NoSuchFieldError
}


package com.mxr.example

import kotlin.system.measureNanoTime

/**
 * For learning purposes
 *
 * Two solutions:
 * 1. create Leveinshtein class
 * 2. extend CharSequence functionality
 */
class Leveinshtein {

    fun leveinshteinDistance(lhs: String, rhs: String): Int {
        if (lhs === rhs) return 0
        if (lhs.isEmpty()) return rhs.length
        if (rhs.isEmpty()) return lhs.length

        val res = Array(lhs.length){ IntArray(rhs.length)}

        for (i in 0 until lhs.length)
            res[i][0] = i

        for (j in 0 until rhs.length)
            res[0][j] = j

        var subst = 0
        for (j in 1 until rhs.length) {
            for (i in 1 until lhs.length) {
                subst = if (lhs[i] == rhs[j]) 0 else 1

                val deletion = res[i-1][j] + 1
                val insertion = res[i][j-1] +1
                val substitution = res[i-1][j-1] + subst
                res[i][j] = Math.min(Math.min(deletion, insertion), substitution)
            }
        }

        return res[lhs.length-1][rhs.length-1]
    }

    private fun cost(a: Char, b: Char ): Int = if (a == b) 0 else 1
}

/**
 * Extend the CharSequence
 */

fun CharSequence.leveinshtein(lhs: String): Int{
    if (this === lhs) return 0
    if (lhs.isEmpty()) return this.length
    if (this.isEmpty()) return lhs.length

    val res = Array(lhs.length){ IntArray(this.length)}

    for (i in 0 until lhs.length)
        res[i][0] = i

    for (j in 0 until this.length)
        res[0][j] = j

    var subst = 0
    for (j in 1 until this.length) {
        for (i in 1 until lhs.length) {
            subst = if (lhs[i] == this[j]) 0 else 1

            val deletion = res[i-1][j] + 1
            val insertion = res[i][j-1] +1
            val substitution = res[i-1][j-1] + subst
            res[i][j] = Math.min(Math.min(deletion, insertion), substitution)
        }
    }

    return res[lhs.length-1][this.length-1]
}

fun main(args: Array<String>) {
    val lev = Leveinshtein()

    var time = measureNanoTime {
        println(lev.leveinshteinDistance("rosettacode", "raisethysword"))
    }

    println("time: $time")

    time = measureNanoTime {
       println("rosettacode".leveinshtein("raisethysword"))
    }
    println("time: $time")
}

Compiled from "leveinshtein.kt"
public final class com.mxr.example.LeveinshteinKt {
  public static final int leveinshtein(java.lang.CharSequence, java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String <this>
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_1
       7: ldc           #17                 // String lhs
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_0
      13: aload_1
      14: if_acmpne     19
      17: iconst_0
      18: ireturn
      19: aload_1
      20: checkcast     #19                 // class java/lang/CharSequence
      23: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      28: ifne          35
      31: iconst_1
      32: goto          36
      35: iconst_0
      36: ifeq          46
      39: aload_0
      40: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      45: ireturn
      46: aload_0
      47: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      52: ifne          59
      55: iconst_1
      56: goto          60
      59: iconst_0
      60: ifeq          68
      63: aload_1
      64: invokevirtual #26                 // Method java/lang/String.length:()I
      67: ireturn
      68: iconst_0
      69: istore_3
      70: aload_1
      71: invokevirtual #26                 // Method java/lang/String.length:()I
      74: istore        4
      76: iload         4
      78: anewarray     #28                 // class "[I"
      81: astore        5
      83: iload_3
      84: iload         4
      86: if_icmpge     111
      89: iload_3
      90: istore        6
      92: aload         5
      94: iload         6
      96: aload_0
      97: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     102: newarray       int
     104: aastore
     105: iinc          3, 1
     108: goto          83
     111: aload         5
     113: astore_2
     114: iconst_0
     115: istore_3
     116: aload_1
     117: invokevirtual #26                 // Method java/lang/String.length:()I
     120: istore        4
     122: iload_3
     123: iload         4
     125: if_icmpge     140
     128: aload_2
     129: iload_3
     130: aaload
     131: iconst_0
     132: iload_3
     133: iastore
     134: iinc          3, 1
     137: goto          122
     140: iconst_0
     141: istore_3
     142: aload_0
     143: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     148: istore        4
     150: iload_3
     151: iload         4
     153: if_icmpge     168
     156: aload_2
     157: iconst_0
     158: aaload
     159: iload_3
     160: iload_3
     161: iastore
     162: iinc          3, 1
     165: goto          150
     168: iconst_0
     169: istore_3
     170: iconst_1
     171: istore        4
     173: aload_0
     174: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     179: istore        5
     181: iload         4
     183: iload         5
     185: if_icmpge     299
     188: iconst_1
     189: istore        6
     191: aload_1
     192: invokevirtual #26                 // Method java/lang/String.length:()I
     195: istore        7
     197: iload         6
     199: iload         7
     201: if_icmpge     293
     204: aload_1
     205: iload         6
     207: invokevirtual #32                 // Method java/lang/String.charAt:(I)C
     210: aload_0
     211: iload         4
     213: invokeinterface #33,  2           // InterfaceMethod java/lang/CharSequence.charAt:(I)C
     218: if_icmpne     225
     221: iconst_0
     222: goto          226
     225: iconst_1
     226: istore_3
     227: aload_2
     228: iload         6
     230: iconst_1
     231: isub
     232: aaload
     233: iload         4
     235: iaload
     236: iconst_1
     237: iadd
     238: istore        8
     240: aload_2
     241: iload         6
     243: aaload
     244: iload         4
     246: iconst_1
     247: isub
     248: iaload
     249: iconst_1
     250: iadd
     251: istore        9
     253: aload_2
     254: iload         6
     256: iconst_1
     257: isub
     258: aaload
     259: iload         4
     261: iconst_1
     262: isub
     263: iaload
     264: iload_3
     265: iadd
     266: istore        10
     268: aload_2
     269: iload         6
     271: aaload
     272: iload         4
     274: iload         8
     276: iload         9
     278: invokestatic  #39                 // Method java/lang/Math.min:(II)I
     281: iload         10
     283: invokestatic  #39                 // Method java/lang/Math.min:(II)I
     286: iastore
     287: iinc          6, 1
     290: goto          197
     293: iinc          4, 1
     296: goto          181
     299: aload_2
     300: aload_1
     301: invokevirtual #26                 // Method java/lang/String.length:()I
     304: iconst_1
     305: isub
     306: aaload
     307: aload_0
     308: invokeinterface #23,  1           // InterfaceMethod java/lang/CharSequence.length:()I
     313: iconst_1
     314: isub
     315: iaload
     316: ireturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #56                 // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #58                 // class com/mxr/example/Leveinshtein
       9: dup
      10: invokespecial #62                 // Method com/mxr/example/Leveinshtein."<init>":()V
      13: astore_1
      14: iconst_0
      15: istore        4
      17: invokestatic  #68                 // Method java/lang/System.nanoTime:()J
      20: lstore        5
      22: iconst_0
      23: istore        7
      25: aload_1
      26: ldc           #70                 // String rosettacode
      28: ldc           #72                 // String raisethysword
      30: invokevirtual #76                 // Method com/mxr/example/Leveinshtein.leveinshteinDistance:(Ljava/lang/String;Ljava/lang/String;)I
      33: istore        8
      35: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
      38: iload         8
      40: invokevirtual #86                 // Method java/io/PrintStream.println:(I)V
      43: nop
      44: nop
      45: invokestatic  #68                 // Method java/lang/System.nanoTime:()J
      48: lload         5
      50: lsub
      51: lstore_2
      52: new           #88                 // class java/lang/StringBuilder
      55: dup
      56: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
      59: ldc           #91                 // String time:
      61: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
      64: lload_2
      65: invokevirtual #98                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
      68: invokevirtual #102                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
      71: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
      74: swap
      75: invokevirtual #105                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
      78: iconst_0
      79: istore        4
      81: invokestatic  #68                 // Method java/lang/System.nanoTime:()J
      84: lstore        5
      86: iconst_0
      87: istore        7
      89: ldc           #70                 // String rosettacode
      91: checkcast     #19                 // class java/lang/CharSequence
      94: ldc           #72                 // String raisethysword
      96: invokestatic  #107                // Method leveinshtein:(Ljava/lang/CharSequence;Ljava/lang/String;)I
      99: istore        8
     101: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     104: iload         8
     106: invokevirtual #86                 // Method java/io/PrintStream.println:(I)V
     109: nop
     110: nop
     111: invokestatic  #68                 // Method java/lang/System.nanoTime:()J
     114: lload         5
     116: lsub
     117: lstore_2
     118: new           #88                 // class java/lang/StringBuilder
     121: dup
     122: invokespecial #89                 // Method java/lang/StringBuilder."<init>":()V
     125: ldc           #91                 // String time:
     127: invokevirtual #95                 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
     130: lload_2
     131: invokevirtual #98                 // Method java/lang/StringBuilder.append:(J)Ljava/lang/StringBuilder;
     134: invokevirtual #102                // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
     137: getstatic     #80                 // Field java/lang/System.out:Ljava/io/PrintStream;
     140: swap
     141: invokevirtual #105                // Method java/io/PrintStream.println:(Ljava/lang/Object;)V
     144: return
}

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

  public final int leveinshteinDistance(java.lang.String, java.lang.String);
    Code:
       0: aload_1
       1: ldc           #15                 // String lhs
       3: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_2
       7: ldc           #23                 // String rhs
       9: invokestatic  #21                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload_1
      13: aload_2
      14: if_acmpne     19
      17: iconst_0
      18: ireturn
      19: aload_1
      20: checkcast     #25                 // class java/lang/CharSequence
      23: invokeinterface #29,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      28: ifne          35
      31: iconst_1
      32: goto          36
      35: iconst_0
      36: ifeq          44
      39: aload_2
      40: invokevirtual #32                 // Method java/lang/String.length:()I
      43: ireturn
      44: aload_2
      45: checkcast     #25                 // class java/lang/CharSequence
      48: invokeinterface #29,  1           // InterfaceMethod java/lang/CharSequence.length:()I
      53: ifne          60
      56: iconst_1
      57: goto          61
      60: iconst_0
      61: ifeq          69
      64: aload_1
      65: invokevirtual #32                 // Method java/lang/String.length:()I
      68: ireturn
      69: iconst_0
      70: istore        4
      72: aload_1
      73: invokevirtual #32                 // Method java/lang/String.length:()I
      76: istore        5
      78: iload         5
      80: anewarray     #34                 // class "[I"
      83: astore        6
      85: iload         4
      87: iload         5
      89: if_icmpge     113
      92: iload         4
      94: istore        7
      96: aload         6
      98: iload         7
     100: aload_2
     101: invokevirtual #32                 // Method java/lang/String.length:()I
     104: newarray       int
     106: aastore
     107: iinc          4, 1
     110: goto          85
     113: aload         6
     115: astore_3
     116: iconst_0
     117: istore        4
     119: aload_1
     120: invokevirtual #32                 // Method java/lang/String.length:()I
     123: istore        5
     125: iload         4
     127: iload         5
     129: if_icmpge     146
     132: aload_3
     133: iload         4
     135: aaload
     136: iconst_0
     137: iload         4
     139: iastore
     140: iinc          4, 1
     143: goto          125
     146: iconst_0
     147: istore        4
     149: aload_2
     150: invokevirtual #32                 // Method java/lang/String.length:()I
     153: istore        5
     155: iload         4
     157: iload         5
     159: if_icmpge     176
     162: aload_3
     163: iconst_0
     164: aaload
     165: iload         4
     167: iload         4
     169: iastore
     170: iinc          4, 1
     173: goto          155
     176: iconst_0
     177: istore        4
     179: iconst_1
     180: istore        5
     182: aload_2
     183: invokevirtual #32                 // Method java/lang/String.length:()I
     186: istore        6
     188: iload         5
     190: iload         6
     192: if_icmpge     306
     195: iconst_1
     196: istore        7
     198: aload_1
     199: invokevirtual #32                 // Method java/lang/String.length:()I
     202: istore        8
     204: iload         7
     206: iload         8
     208: if_icmpge     300
     211: aload_1
     212: iload         7
     214: invokevirtual #38                 // Method java/lang/String.charAt:(I)C
     217: aload_2
     218: iload         5
     220: invokevirtual #38                 // Method java/lang/String.charAt:(I)C
     223: if_icmpne     230
     226: iconst_0
     227: goto          231
     230: iconst_1
     231: istore        4
     233: aload_3
     234: iload         7
     236: iconst_1
     237: isub
     238: aaload
     239: iload         5
     241: iaload
     242: iconst_1
     243: iadd
     244: istore        9
     246: aload_3
     247: iload         7
     249: aaload
     250: iload         5
     252: iconst_1
     253: isub
     254: iaload
     255: iconst_1
     256: iadd
     257: istore        10
     259: aload_3
     260: iload         7
     262: iconst_1
     263: isub
     264: aaload
     265: iload         5
     267: iconst_1
     268: isub
     269: iaload
     270: iload         4
     272: iadd
     273: istore        11
     275: aload_3
     276: iload         7
     278: aaload
     279: iload         5
     281: iload         9
     283: iload         10
     285: invokestatic  #44                 // Method java/lang/Math.min:(II)I
     288: iload         11
     290: invokestatic  #44                 // Method java/lang/Math.min:(II)I
     293: iastore
     294: iinc          7, 1
     297: goto          204
     300: iinc          5, 1
     303: goto          188
     306: aload_3
     307: aload_1
     308: invokevirtual #32                 // Method java/lang/String.length:()I
     311: iconst_1
     312: isub
     313: aaload
     314: aload_2
     315: invokevirtual #32                 // Method java/lang/String.length:()I
     318: iconst_1
     319: isub
     320: iaload
     321: ireturn

  private final int cost(char, char);
    Code:
       0: iload_1
       1: iload_2
       2: if_icmpne     9
       5: iconst_0
       6: goto          10
       9: iconst_1
      10: ireturn
}


package algorithmic_toolbox.week6

import java.util.*
import kotlin.math.max
import kotlin.math.min

fun getMaximValue(exp: String): Long {
    val n = exp.length / 2 + 1
    var min = Array(n){ LongArray(n) }
    var max = Array(n){ LongArray(n) }

    for (i in 0 until n) {
        min[i][i] = (exp[i * 2] - '0').toLong()
        max[i][i] = (exp[i * 2] - '0').toLong()
    }

    for (s in 1 until n ) {
        for (z in 0 .. n -1 -s) {
            val j = s + z
            val minAndMax = getMinAndMax(exp, z, j, min, max)
            min[z][j] = minAndMax[0]
            max[z][j] = minAndMax[1]
        }
    }

    return max[0][n - 1]
}

fun getMinAndMax(exp: String, i: Int, j: Int,
                 w: Array<LongArray>, W: Array<LongArray> ): LongArray {
    var minAndMax = longArrayOf(Long.MAX_VALUE, Long.MIN_VALUE)
    for (k in i until j) {
        val op = exp[k * 2 + 1]
        val a = eval(w[i][k], w[k+1][j], op)
        val b = eval(w[i][k], W[k+1][j], op)
        val c = eval(W[i][k], w[k+1][j], op)
        val d = eval(W[i][k], W[k+1][j], op)

        minAndMax[0] = min(a, min(b, min(c, min(d, minAndMax[0]))))
        minAndMax[1] = max(a, max(b, max(c, max(d, minAndMax[1]))))

    }
    return minAndMax
}

fun eval(a: Long, b: Long, op: Char): Long = when (op) {
    '+' -> a + b
    '-' -> a - b
    '*' -> a * b
    else -> {
        assert(false)
        0
    }
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val exp = scanner.next()
    println(getMaximValue(exp))
}

Compiled from "PlacingParentheses.kt"
public final class algorithmic_toolbox.week6.PlacingParenthesesKt {
  public static final long getMaximValue(java.lang.String);
    Code:
       0: aload_0
       1: ldc           #9                  // String exp
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_0
       7: invokevirtual #21                 // Method java/lang/String.length:()I
      10: iconst_2
      11: idiv
      12: iconst_1
      13: iadd
      14: istore_1
      15: iconst_0
      16: istore_3
      17: iload_1
      18: anewarray     #23                 // class "[J"
      21: astore        4
      23: iload_3
      24: iload_1
      25: if_icmpge     45
      28: iload_3
      29: istore        5
      31: aload         4
      33: iload         5
      35: iload_1
      36: newarray       long
      38: aastore
      39: iinc          3, 1
      42: goto          23
      45: aload         4
      47: astore_2
      48: iconst_0
      49: istore        4
      51: iload_1
      52: anewarray     #23                 // class "[J"
      55: astore        5
      57: iload         4
      59: iload_1
      60: if_icmpge     81
      63: iload         4
      65: istore        6
      67: aload         5
      69: iload         6
      71: iload_1
      72: newarray       long
      74: aastore
      75: iinc          4, 1
      78: goto          57
      81: aload         5
      83: astore_3
      84: iconst_0
      85: istore        4
      87: iload         4
      89: iload_1
      90: if_icmpge     137
      93: aload_2
      94: iload         4
      96: aaload
      97: iload         4
      99: aload_0
     100: iload         4
     102: iconst_2
     103: imul
     104: invokevirtual #27                 // Method java/lang/String.charAt:(I)C
     107: bipush        48
     109: isub
     110: i2l
     111: lastore
     112: aload_3
     113: iload         4
     115: aaload
     116: iload         4
     118: aload_0
     119: iload         4
     121: iconst_2
     122: imul
     123: invokevirtual #27                 // Method java/lang/String.charAt:(I)C
     126: bipush        48
     128: isub
     129: i2l
     130: lastore
     131: iinc          4, 1
     134: goto          87
     137: iconst_1
     138: istore        4
     140: iload         4
     142: iload_1
     143: if_icmpge     224
     146: iconst_0
     147: istore        5
     149: iload_1
     150: iconst_1
     151: isub
     152: iload         4
     154: isub
     155: istore        6
     157: iload         5
     159: iload         6
     161: if_icmpgt     218
     164: iload         4
     166: iload         5
     168: iadd
     169: istore        7
     171: aload_0
     172: iload         5
     174: iload         7
     176: aload_2
     177: aload_3
     178: invokestatic  #31                 // Method getMinAndMax:(Ljava/lang/String;II[[J[[J)[J
     181: astore        8
     183: aload_2
     184: iload         5
     186: aaload
     187: iload         7
     189: aload         8
     191: iconst_0
     192: laload
     193: lastore
     194: aload_3
     195: iload         5
     197: aaload
     198: iload         7
     200: aload         8
     202: iconst_1
     203: laload
     204: lastore
     205: iload         5
     207: iload         6
     209: if_icmpeq     218
     212: iinc          5, 1
     215: goto          164
     218: iinc          4, 1
     221: goto          140
     224: aload_3
     225: iconst_0
     226: aaload
     227: iload_1
     228: iconst_1
     229: isub
     230: laload
     231: lreturn

  public static final long[] getMinAndMax(java.lang.String, int, int, long[][], long[][]);
    Code:
       0: aload_0
       1: ldc           #9                  // String exp
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: aload_3
       7: ldc           #45                 // String w
       9: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      12: aload         4
      14: ldc           #47                 // String W
      16: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
      19: iconst_2
      20: newarray       long
      22: astore        6
      24: aload         6
      26: iconst_0
      27: ldc2_w        #48                 // long 9223372036854775807l
      30: lastore
      31: aload         6
      33: iconst_1
      34: ldc2_w        #50                 // long -9223372036854775808l
      37: lastore
      38: aload         6
      40: astore        5
      42: iload_1
      43: istore        6
      45: iload         6
      47: iload_2
      48: if_icmpge     213
      51: aload_0
      52: iload         6
      54: iconst_2
      55: imul
      56: iconst_1
      57: iadd
      58: invokevirtual #27                 // Method java/lang/String.charAt:(I)C
      61: istore        7
      63: aload_3
      64: iload_1
      65: aaload
      66: iload         6
      68: laload
      69: aload_3
      70: iload         6
      72: iconst_1
      73: iadd
      74: aaload
      75: iload_2
      76: laload
      77: iload         7
      79: invokestatic  #55                 // Method eval:(JJC)J
      82: lstore        8
      84: aload_3
      85: iload_1
      86: aaload
      87: iload         6
      89: laload
      90: aload         4
      92: iload         6
      94: iconst_1
      95: iadd
      96: aaload
      97: iload_2
      98: laload
      99: iload         7
     101: invokestatic  #55                 // Method eval:(JJC)J
     104: lstore        10
     106: aload         4
     108: iload_1
     109: aaload
     110: iload         6
     112: laload
     113: aload_3
     114: iload         6
     116: iconst_1
     117: iadd
     118: aaload
     119: iload_2
     120: laload
     121: iload         7
     123: invokestatic  #55                 // Method eval:(JJC)J
     126: lstore        12
     128: aload         4
     130: iload_1
     131: aaload
     132: iload         6
     134: laload
     135: aload         4
     137: iload         6
     139: iconst_1
     140: iadd
     141: aaload
     142: iload_2
     143: laload
     144: iload         7
     146: invokestatic  #55                 // Method eval:(JJC)J
     149: lstore        14
     151: aload         5
     153: iconst_0
     154: lload         8
     156: lload         10
     158: lload         12
     160: lload         14
     162: aload         5
     164: iconst_0
     165: laload
     166: invokestatic  #60                 // Method java/lang/Math.min:(JJ)J
     169: invokestatic  #60                 // Method java/lang/Math.min:(JJ)J
     172: invokestatic  #60                 // Method java/lang/Math.min:(JJ)J
     175: invokestatic  #60                 // Method java/lang/Math.min:(JJ)J
     178: lastore
     179: aload         5
     181: iconst_1
     182: lload         8
     184: lload         10
     186: lload         12
     188: lload         14
     190: aload         5
     192: iconst_1
     193: laload
     194: invokestatic  #62                 // Method java/lang/Math.max:(JJ)J
     197: invokestatic  #62                 // Method java/lang/Math.max:(JJ)J
     200: invokestatic  #62                 // Method java/lang/Math.max:(JJ)J
     203: invokestatic  #62                 // Method java/lang/Math.max:(JJ)J
     206: lastore
     207: iinc          6, 1
     210: goto          45
     213: aload         5
     215: areturn

  public static final long eval(long, long, char);
    Code:
       0: iload         4
       2: tableswitch   { // 42 to 45
                    42: 44
                    43: 32
                    44: 50
                    45: 38
               default: 50
          }
      32: lload_0
      33: lload_2
      34: ladd
      35: goto          71
      38: lload_0
      39: lload_2
      40: lsub
      41: goto          71
      44: lload_0
      45: lload_2
      46: lmul
      47: goto          71
      50: getstatic     #76                 // Field kotlin/_Assertions.ENABLED:Z
      53: ifeq          70
      56: ldc           #78                 // String Assertion failed
      58: astore        5
      60: new           #80                 // class java/lang/AssertionError
      63: dup
      64: aload         5
      66: invokespecial #84                 // Method java/lang/AssertionError."<init>":(Ljava/lang/Object;)V
      69: athrow
      70: lconst_0
      71: lreturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #88                 // String args
       3: invokestatic  #15                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #90                 // class java/util/Scanner
       9: dup
      10: getstatic     #96                 // Field java/lang/System.in:Ljava/io/InputStream;
      13: invokespecial #99                 // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      16: astore_1
      17: aload_1
      18: invokevirtual #103                // Method java/util/Scanner.next:()Ljava/lang/String;
      21: astore_2
      22: aload_2
      23: invokestatic  #106                // Method kotlin/jvm/internal/Intrinsics.checkNotNull:(Ljava/lang/Object;)V
      26: aload_2
      27: invokestatic  #108                // Method getMaximValue:(Ljava/lang/String;)J
      30: lstore_3
      31: getstatic     #112                // Field java/lang/System.out:Ljava/io/PrintStream;
      34: lload_3
      35: invokevirtual #118                // Method java/io/PrintStream.println:(J)V
      38: return
}


package algorithmic_toolbox.week2

import java.util.*

fun calcFib(n: Long): Long {
    return if (n <= 1) n else calcFib(n - 1) + calcFib(n - 2)
}

fun power(n: Long, x: Int = 2): Long {
    if (x == 0)
        return n

    return power(n * n, x - 1)
}

fun lastDigitOfNumber(n: Long): Long {
    var fibAList = LongArray((n+1).toInt())

    fibAList[0] = 0
    fibAList[1] = 1

    if ( n < 2) return n

    for (i in 2..n) {
        fibAList[i.toInt()] = (fibAList[(i-1).toInt()] + fibAList[(i-2).toInt()]) % 10
    }

    return fibAList[n.toInt()]
}

fun getPisanoPeriod(m: Long): Long {
    var period = 0L
    var previous = 0L
    var current = 1L

    for (i in 2 until m*m) {
        val tmpPrevious = previous
        previous = current
        current = (tmpPrevious+current) % m

        if (previous == 0L && current == 1L){
            period = i - 1
            break
        }
    }
    return period
}

fun calcFibMod(n: Long, m: Long): Long {
    if ( n <= 1)
        return n

    val pisanoPeriod = getPisanoPeriod(m)
    val remainder = n % pisanoPeriod
    var previous = 0L
    var current = 1L

    for (i in 0 until remainder-1) {
        val tmpPrevious = previous
        previous = current
        current = (tmpPrevious+current) % m
    }

    return current % m
}

fun calcLastDigitOfTheSumFibonacci(n: Long): Long {
    if (n <= 2) return n
    var fibAList = LongArray((n + 1).toInt())

    fibAList[0] = 0L
    fibAList[1] = 1L

    for (i in 2..n) {
        fibAList[i.toInt()] = (fibAList[(i - 1).toInt()] + fibAList[(i - 2).toInt()]) % 10
    }

    return fibAList.sum() % 10
}

fun calcLastDigitOfTheSumFibonacci(m: Long, n: Long): Long {
    val pisanoPeriod = 60 // pisanoPeriod(10) = 60
    var fibAList = LongArray(pisanoPeriod - 1)

    fibAList[0] = 0L
    fibAList[1] = 1L

    for (i in 2 until pisanoPeriod - 1) {
        fibAList[i] = (fibAList[i-1] + fibAList[i-2]) % 10
    }

    var begin = m % pisanoPeriod
    var end = n % pisanoPeriod

    if (end < begin) end += pisanoPeriod

    var result = 0L
    for (i in begin..end) {
        result += fibAList[(i % pisanoPeriod).toInt()]
    }

    return result % 10
}

fun calcLastDigitOfTheSumOfSquaresFibonacci(n: Long): Long {
    val pisanoPeriod = 60
    val horizontal = lastDigitOfNumber((n +1) % pisanoPeriod)
    val vertical = lastDigitOfNumber( n % pisanoPeriod)
    return (horizontal * vertical) % 10
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextLong()

    println(calcFib(n))
}

Compiled from "FibonnaciWarmup.kt"
public final class algorithmic_toolbox.week2.FibonnaciWarmupKt {
  public static final long calcFib(long);
    Code:
       0: lload_0
       1: lconst_1
       2: lcmp
       3: ifgt          10
       6: lload_0
       7: goto          24
      10: lload_0
      11: lconst_1
      12: lsub
      13: invokestatic  #8                  // Method calcFib:(J)J
      16: lload_0
      17: iconst_2
      18: i2l
      19: lsub
      20: invokestatic  #8                  // Method calcFib:(J)J
      23: ladd
      24: lreturn

  public static final long power(long, int);
    Code:
       0: iload_2
       1: ifne          6
       4: lload_0
       5: lreturn
       6: lload_0
       7: lload_0
       8: lmul
       9: iload_2
      10: iconst_1
      11: isub
      12: invokestatic  #14                 // Method power:(JI)J
      15: lreturn

  public static long power$default(long, int, int, java.lang.Object);
    Code:
       0: iload_3
       1: iconst_2
       2: iand
       3: ifeq          8
       6: iconst_2
       7: istore_2
       8: lload_0
       9: iload_2
      10: invokestatic  #14                 // Method power:(JI)J
      13: lreturn

  public static final long lastDigitOfNumber(long);
    Code:
       0: lload_0
       1: lconst_1
       2: ladd
       3: l2i
       4: newarray       long
       6: astore_2
       7: aload_2
       8: iconst_0
       9: lconst_0
      10: lastore
      11: aload_2
      12: iconst_1
      13: lconst_1
      14: lastore
      15: lload_0
      16: ldc2_w        #20                 // long 2l
      19: lcmp
      20: ifge          25
      23: lload_0
      24: lreturn
      25: ldc2_w        #20                 // long 2l
      28: lstore_3
      29: lload_3
      30: lload_0
      31: lcmp
      32: ifgt          70
      35: aload_2
      36: lload_3
      37: l2i
      38: aload_2
      39: lload_3
      40: lconst_1
      41: lsub
      42: l2i
      43: laload
      44: aload_2
      45: lload_3
      46: iconst_2
      47: i2l
      48: lsub
      49: l2i
      50: laload
      51: ladd
      52: bipush        10
      54: i2l
      55: lrem
      56: lastore
      57: lload_3
      58: lload_0
      59: lcmp
      60: ifeq          70
      63: lload_3
      64: lconst_1
      65: ladd
      66: lstore_3
      67: goto          35
      70: aload_2
      71: lload_0
      72: l2i
      73: laload
      74: lreturn

  public static final long getPisanoPeriod(long);
    Code:
       0: lconst_0
       1: lstore_2
       2: lconst_0
       3: lstore        4
       5: lconst_1
       6: lstore        6
       8: ldc2_w        #20                 // long 2l
      11: lstore        8
      13: lload_0
      14: lload_0
      15: lmul
      16: lstore        10
      18: lload         8
      20: lload         10
      22: lcmp
      23: ifge          74
      26: lload         4
      28: lstore        12
      30: lload         6
      32: lstore        4
      34: lload         12
      36: lload         6
      38: ladd
      39: lload_0
      40: lrem
      41: lstore        6
      43: lload         4
      45: lconst_0
      46: lcmp
      47: ifne          65
      50: lload         6
      52: lconst_1
      53: lcmp
      54: ifne          65
      57: lload         8
      59: lconst_1
      60: lsub
      61: lstore_2
      62: goto          74
      65: lload         8
      67: lconst_1
      68: ladd
      69: lstore        8
      71: goto          18
      74: lload_2
      75: lreturn

  public static final long calcFibMod(long, long);
    Code:
       0: lload_0
       1: lconst_1
       2: lcmp
       3: ifgt          8
       6: lload_0
       7: lreturn
       8: lload_2
       9: invokestatic  #35                 // Method getPisanoPeriod:(J)J
      12: lstore        4
      14: lload_0
      15: lload         4
      17: lrem
      18: lstore        6
      20: lconst_0
      21: lstore        8
      23: lconst_1
      24: lstore        10
      26: lconst_0
      27: lstore        12
      29: lload         6
      31: lconst_1
      32: lsub
      33: lstore        14
      35: lload         12
      37: lload         14
      39: lcmp
      40: ifge          69
      43: lload         8
      45: lstore        16
      47: lload         10
      49: lstore        8
      51: lload         16
      53: lload         10
      55: ladd
      56: lload_2
      57: lrem
      58: lstore        10
      60: lload         12
      62: lconst_1
      63: ladd
      64: lstore        12
      66: goto          35
      69: lload         10
      71: lload_2
      72: lrem
      73: lreturn

  public static final long calcLastDigitOfTheSumFibonacci(long);
    Code:
       0: lload_0
       1: ldc2_w        #20                 // long 2l
       4: lcmp
       5: ifgt          10
       8: lload_0
       9: lreturn
      10: lload_0
      11: lconst_1
      12: ladd
      13: l2i
      14: newarray       long
      16: astore_2
      17: aload_2
      18: iconst_0
      19: lconst_0
      20: lastore
      21: aload_2
      22: iconst_1
      23: lconst_1
      24: lastore
      25: ldc2_w        #20                 // long 2l
      28: lstore_3
      29: lload_3
      30: lload_0
      31: lcmp
      32: ifgt          70
      35: aload_2
      36: lload_3
      37: l2i
      38: aload_2
      39: lload_3
      40: lconst_1
      41: lsub
      42: l2i
      43: laload
      44: aload_2
      45: lload_3
      46: iconst_2
      47: i2l
      48: lsub
      49: l2i
      50: laload
      51: ladd
      52: bipush        10
      54: i2l
      55: lrem
      56: lastore
      57: lload_3
      58: lload_0
      59: lcmp
      60: ifeq          70
      63: lload_3
      64: lconst_1
      65: ladd
      66: lstore_3
      67: goto          35
      70: aload_2
      71: invokestatic  #44                 // Method kotlin/collections/ArraysKt.sum:([J)J
      74: bipush        10
      76: i2l
      77: lrem
      78: lreturn

  public static final long calcLastDigitOfTheSumFibonacci(long, long);
    Code:
       0: bipush        60
       2: istore        4
       4: iload         4
       6: iconst_1
       7: isub
       8: newarray       long
      10: astore        5
      12: aload         5
      14: iconst_0
      15: lconst_0
      16: lastore
      17: aload         5
      19: iconst_1
      20: lconst_1
      21: lastore
      22: iconst_2
      23: istore        6
      25: iload         4
      27: iconst_1
      28: isub
      29: istore        7
      31: iload         6
      33: iload         7
      35: if_icmpge     68
      38: aload         5
      40: iload         6
      42: aload         5
      44: iload         6
      46: iconst_1
      47: isub
      48: laload
      49: aload         5
      51: iload         6
      53: iconst_2
      54: isub
      55: laload
      56: ladd
      57: bipush        10
      59: i2l
      60: lrem
      61: lastore
      62: iinc          6, 1
      65: goto          31
      68: lload_0
      69: iload         4
      71: i2l
      72: lrem
      73: lstore        6
      75: lload_2
      76: iload         4
      78: i2l
      79: lrem
      80: lstore        8
      82: lload         8
      84: lload         6
      86: lcmp
      87: ifge          98
      90: lload         8
      92: iload         4
      94: i2l
      95: ladd
      96: lstore        8
      98: lconst_0
      99: lstore        10
     101: lload         6
     103: lstore        12
     105: lload         8
     107: lstore        14
     109: lload         12
     111: lload         14
     113: lcmp
     114: ifgt          149
     117: lload         10
     119: aload         5
     121: lload         12
     123: iload         4
     125: i2l
     126: lrem
     127: l2i
     128: laload
     129: ladd
     130: lstore        10
     132: lload         12
     134: lload         14
     136: lcmp
     137: ifeq          149
     140: lload         12
     142: lconst_1
     143: ladd
     144: lstore        12
     146: goto          117
     149: lload         10
     151: bipush        10
     153: i2l
     154: lrem
     155: lreturn

  public static final long calcLastDigitOfTheSumOfSquaresFibonacci(long);
    Code:
       0: bipush        60
       2: istore_2
       3: lload_0
       4: lconst_1
       5: ladd
       6: iload_2
       7: i2l
       8: lrem
       9: invokestatic  #50                 // Method lastDigitOfNumber:(J)J
      12: lstore_3
      13: lload_0
      14: iload_2
      15: i2l
      16: lrem
      17: invokestatic  #50                 // Method lastDigitOfNumber:(J)J
      20: lstore        5
      22: lload_3
      23: lload         5
      25: lmul
      26: bipush        10
      28: i2l
      29: lrem
      30: lreturn

  public static final void main(java.lang.String[]);
    Code:
       0: aload_0
       1: ldc           #57                 // String args
       3: invokestatic  #63                 // Method kotlin/jvm/internal/Intrinsics.checkNotNullParameter:(Ljava/lang/Object;Ljava/lang/String;)V
       6: new           #65                 // class java/util/Scanner
       9: dup
      10: getstatic     #71                 // Field java/lang/System.in:Ljava/io/InputStream;
      13: invokespecial #75                 // Method java/util/Scanner."<init>":(Ljava/io/InputStream;)V
      16: astore_1
      17: aload_1
      18: invokevirtual #79                 // Method java/util/Scanner.nextLong:()J
      21: lstore_2
      22: lload_2
      23: invokestatic  #8                  // Method calcFib:(J)J
      26: lstore        4
      28: getstatic     #83                 // Field java/lang/System.out:Ljava/io/PrintStream;
      31: lload         4
      33: invokevirtual #89                 // Method java/io/PrintStream.println:(J)V
      36: return
}